本文整理汇总了Python中mpmath.mpmathify函数的典型用法代码示例。如果您正苦于以下问题:Python mpmathify函数的具体用法?Python mpmathify怎么用?Python mpmathify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mpmathify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convertToBase10
def convertToBase10( integer, mantissa, inputRadix ):
result = mpmathify( 0 )
base = mpmathify( 1 )
validNumerals = g.numerals[ : inputRadix ]
for i in range( len( integer ) - 1, -1, -1 ):
digit = validNumerals.find( integer[ i ] )
if digit == -1:
raise ValueError( 'invalid numeral \'%c\' for base %d' % ( integer[ i ], inputRadix ) )
result += digit * base
base *= inputRadix
base = fdiv( 1, inputRadix )
for i in range( 0, len( mantissa ) ):
digit = validNumerals.find( mantissa[ i ] )
if digit == -1:
raise ValueError( 'invalid numeral \'%c\' for base %d' % ( mantissa[ i ], inputRadix ) )
result += digit * base
base /= inputRadix
return result
示例2: combineUnits
def combineUnits( self, units ):
if not g.unitConversionMatrix:
loadUnitConversionMatrix( )
newUnits = RPNUnits( self )
factor = mpmathify( 1 )
for unit2 in units:
if unit2 in newUnits:
newUnits[ unit2 ] += units[ unit2 ]
else:
for unit1 in self:
if unit1 == unit2:
newUnits[ unit2 ] += units[ unit2 ]
break
elif getUnitType( unit1 ) == getUnitType( unit2 ):
factor = fdiv( factor, pow( mpmathify( g.unitConversionMatrix[ ( unit1, unit2 ) ] ), units[ unit2 ] ) )
newUnits[ unit1 ] += units[ unit2 ]
break
else:
newUnits[ unit2 ] = units[ unit2 ]
#print( 'newUnits', newUnits )
return factor, newUnits
示例3: stringExpressionValid
def stringExpressionValid(str):
try:
mpmath.mpmathify(str)
return True
except Exception as err:
print(err)
return False
示例4: create_hexagonal_grid_nearestN
def create_hexagonal_grid_nearestN(origin, d, point, N):
"""
Create a new coherent basis with basis states on a hexagonal grid.
As basis states the nearest N grid points to the center are choosen.
*Arguments*
* *origin*
A complex number defining the origin of the grid.
* *d*
A real number defining the lattice constant.
* *point*
A complex number used as reference point to which the nearest
N lattice points are selected.
* *N*
An integer giving the number of basis states.
"""
origin = mpmath.mpmathify(origin)
point = mpmath.mpmathify(point)
d = mpmath.mpf(d)
lat = lattice.HexagonalLattice(d, origin, dtype=mpmath.mpf)
lat.select_nearestN(point, N)
return CoherentBasis(lat)
示例5: getSkyLocation
def getSkyLocation( n, k ):
if not isinstance( n, ephem.Body ) or not isinstance( k, RPNDateTime ):
raise ValueError( '\'sky_location\' expects an astronomical object and a date-time' )
n.compute( k.to( 'utc' ).format( ) )
return [ fdiv( fmul( mpmathify( n.ra ), 180 ), pi ), fdiv( fmul( mpmathify( n.dec ), 180 ), pi ) ]
示例6: times_a
def times_a(array1, array2):
from mpmath import mp as math
math.prec = 200
a1 = list(array1)
a2 = list(array2)
output = [math.fmul(math.mpmathify(a1[i]),math.mpmathify(a2[i])) for i in range(len(a1))]
return output
示例7: getInvertedBits
def getInvertedBits( n ):
value = real_int( n )
# determine how many groups of bits we will be looking at
if value == 0:
groupings = 1
else:
groupings = int( fadd( floor( fdiv( ( log( value, 2 ) ), g.bitwiseGroupSize ) ), 1 ) )
placeValue = mpmathify( 1 << g.bitwiseGroupSize )
multiplier = mpmathify( 1 )
remaining = value
result = mpmathify( 0 )
for i in range( 0, groupings ):
# Let's let Python do the actual inverting
group = fmod( ~int( fmod( remaining, placeValue ) ), placeValue )
result += fmul( group, multiplier )
remaining = floor( fdiv( remaining, placeValue ) )
multiplier = fmul( multiplier, placeValue )
return result
示例8: expectResult
def expectResult( command, expected ):
if g.testFilter:
if g.testFilter not in command:
return
if g.timeIndividualTests:
startTime = time.process_time( )
print( 'rpn', command )
result = rpn( shlex.split( command + ' -I' ) )[ 0 ]
compare = None
if isinstance( expected, list ):
compare = [ ]
for i in expected:
if isinstance( i, ( int, float, complex ) ):
compare.append( mpmathify( i ) )
else:
compare.append( i )
else:
if isinstance( expected, ( int, float, complex ) ):
compare = mpmathify( expected )
else:
compare = expected
compareResults( result, compare )
print( ' test passed!' )
if g.timeIndividualTests:
print( 'Test complete. Time elapsed: {:.3f} seconds'.format( time.process_time( ) - startTime ) )
print( '' )
示例9: getAzimuthAndAltitude
def getAzimuthAndAltitude( self, location=None, date=None ):
if location and date:
if isinstance( location, str ):
location = getLocation( location )
location.observer.date = date.to( 'utc' ).format( )
self.object.compute( location.observer )
return RPNMeasurement( mpmathify( self.object.az ), 'radians' ), \
RPNMeasurement( mpmathify( self.object.alt ), 'radians' )
return self.getAzimuthAndAltitude( )
示例10: doubledouble2string
def doubledouble2string(doubdoub,n=19):
"""
Convert a double-double tuple into a string with n decimal digits of precision. Default is n=19,
which is the maximum precision that this longdouble-based double-double format can provide.
min_fixed is the position of the leading digit such that any number with a leading
digit less than or equal to min_fixed will be written in exponential format.
e.g., 0.00123 has its leading digit in the -3 place, so if min_fixed>=-3
it will be printed as 1.23e-3, and if min_fixed<=-4 it will be printed as 0.00123.
"""
mpmath.mp.prec=105
hi=mpmath.mpmathify(doubdoub[0])
lo=mpmath.mpmathify(doubdoub[1])
tot=mpmath.fadd(hi,lo)
return mpmath.nstr(tot,n)
示例11: OLDgetPartitionNumber
def OLDgetPartitionNumber( n ):
if n < 0:
return 0
if n < 2:
return 1
result = mpmathify( 0 )
for k in arange( 1, n + 1 ):
#n1 = n - k * ( 3 * k - 1 ) / 2
n1 = fsub( n, fdiv( fmul( k, fsub( fmul( 3, k ), 1 ) ), 2 ) )
#n2 = n - k * ( 3 * k + 1 ) / 2
n2 = fsub( n, fdiv( fmul( k, fadd( fmul( 3, k ), 1 ) ), 2 ) )
result = fadd( result, fmul( power( -1, fadd( k, 1 ) ), fadd( getPartitionNumber( n1 ), getPartitionNumber( n2 ) ) ) )
if n1 <= 0:
break
#old = NOT_QUITE_AS_OLDgetPartitionNumber( n )
#
#if ( old != result ):
# raise ValueError( "It's broke." )
return result
示例12: create_hexagonal_grid_rings
def create_hexagonal_grid_rings(center, d, rings):
"""
Create a new coherent basis with basis states on a hexagonal grid.
The basis states are choosen in rings around the center on a hexagonal
grid with lattice constant d.
*Arguments*
* *center*
A complex number defining the center of the rings.
* *d*
A real number defining the lattice constant.
* *rings*
An integer giving the number of rings.
"""
center = mpmath.mpmathify(center)
d = mpmath.mpf(d)
lat = lattice.HexagonalLattice(d, center, dtype=mpmath.mpf)
for i in range(-rings,rings+1):
if i<0:
start = -rings-i
end = rings
else:
start = -rings
end = rings-i
for j in range(start,end+1):
lat.select((i, j))
return CoherentBasis(lat)
示例13: downloadOEISSequence
def downloadOEISSequence( id ):
'''Downloads and formats data from oeis.org.'''
keywords = downloadOEISText( id, 'K' ).split( ',' )
# If oeis.org isn't available, just punt everything
if keywords == [ '' ]:
return 0
result, success = downloadOEISTable( id )
if success:
return result
if 'nonn' in keywords:
result = downloadOEISText( id, 'S' )
result += downloadOEISText( id, 'T' )
result += downloadOEISText( id, 'U' )
else:
result = downloadOEISText( id, 'V' )
result += downloadOEISText( id, 'W' )
result += downloadOEISText( id, 'X' )
if 'cons' in keywords:
offset = int( downloadOEISText( id, 'O' ).split( ',' )[ 0 ] )
result = ''.join( result.split( ',' ) )
return mpmathify( result[ : offset ] + '.' + result[ offset : ] )
else:
#return [ mpmathify( i ) for i in result.split( ',' ) ]
return [ int( i ) for i in result.split( ',' ) ]
示例14: convertToBaseN
def convertToBaseN( value, base, outputBaseDigits, numerals ):
if outputBaseDigits:
if ( base < 2 ):
raise ValueError( 'base must be greater than 1' )
else:
if not ( 2 <= base <= len( numerals ) ):
raise ValueError( 'base must be from 2 to {0}'.format( len( numerals ) ) )
if value == 0:
return 0
if value < 0:
return '-' + convertToBaseN( fneg( value ), base, outputBaseDigits, numerals )
if base == 10:
return str( value )
if outputBaseDigits:
result = [ ]
else:
result = ''
leftDigits = mpmathify( value )
while leftDigits > 0:
modulo = fmod( leftDigits, base )
if outputBaseDigits:
result.insert( 0, int( modulo ) )
else:
result = numerals[ int( modulo ) ] + result
leftDigits = floor( fdiv( leftDigits, base ) )
return result
示例15: sph_kn_exact
def sph_kn_exact(n, z):
"""Return the value of k_n computed using the exact formula.
The expression used is http://dlmf.nist.gov/10.49.E12 .
"""
zm = mpmathify(z)
s = sum(_a(k, n)/zm**(k+1) for k in xrange(n+1))
return pi*exp(-zm)/2*s