本文整理汇总了Python中mpmath.mpmathify函数的典型用法代码示例。如果您正苦于以下问题:Python mpmathify函数的具体用法?Python mpmathify怎么用?Python mpmathify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mpmathify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:27,代码来源:rpnInput.py
示例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
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:25,代码来源:rpnUnitClasses.py
示例3: stringExpressionValid
def stringExpressionValid(str):
try:
mpmath.mpmathify(str)
return True
except Exception as err:
print(err)
return False
开发者ID:lainwir3d,项目名称:sailfish-rpn-calculator,代码行数:7,代码来源:rpncalc_mpmath_backend.py
示例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)
开发者ID:bastikr,项目名称:pyqo,代码行数:26,代码来源:coherent_basis.py
示例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 ) ]
开发者ID:flawr,项目名称:rpn,代码行数:7,代码来源:rpnAstronomy.py
示例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
开发者ID:kentgorday,项目名称:Heidelberg_15,代码行数:7,代码来源:MAWS.py
示例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
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:25,代码来源:rpnComputer.py
示例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( '' )
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:35,代码来源:rpnTestUtils.py
示例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( )
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:12,代码来源:rpnAstronomy.py
示例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)
开发者ID:andrejdvornik,项目名称:Halo-model,代码行数:14,代码来源:longdouble_utils.py
示例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
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:26,代码来源:rpnCombinatorics.py
示例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)
开发者ID:bastikr,项目名称:pyqo,代码行数:30,代码来源:coherent_basis.py
示例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( ',' ) ]
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:29,代码来源:rpnSpecial.py
示例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
开发者ID:flawr,项目名称:rpn,代码行数:35,代码来源:rpnBase.py
示例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
开发者ID:tpudlik,项目名称:sbf,代码行数:9,代码来源:sbf_mp.py
示例16: sph_h2n_exact
def sph_h2n_exact(n, z):
"""Return the value of h^{(2)}_n computed using the exact formula.
The expression used is http://dlmf.nist.gov/10.49.E7 .
"""
zm = mpmathify(z)
s = sum(mpc(0,-1)**(k-n-1)*_a(k, n)/zm**(k+1) for k in xrange(n+1))
return exp(mpc(0,-1)*zm)*s
开发者ID:tpudlik,项目名称:sbf,代码行数:9,代码来源:sbf_mp.py
示例17: __init__
def __init__( self, value, units = RPNUnits( ) ):
if isinstance( value, str ):
self.value = mpmathify( value )
self.units = RPNUnits( units )
elif isinstance( value, RPNMeasurement ):
self.value = value.value
self.units = RPNUnits( value.units )
else:
self.value = value
self.units = RPNUnits( units )
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:10,代码来源:rpnMeasurement.py
示例18: sph_yn_exact
def sph_yn_exact(n, z):
"""Return the value of y_n computed using the exact formula.
The expression used is http://dlmf.nist.gov/10.49.E4 .
"""
zm = mpmathify(z)
s1 = sum((-1)**k*_a(2*k, n)/zm**(2*k+1) for k in xrange(0, int(n/2) + 1))
s2 = sum((-1)**k*_a(2*k+1, n)/zm**(2*k+2) for k in xrange(0, int((n-1)/2) + 1))
return -cos(zm - n*pi/2)*s1 + sin(zm - n*pi/2)*s2
开发者ID:tpudlik,项目名称:sbf,代码行数:10,代码来源:sbf_mp.py
示例19: sph_i2n_exact
def sph_i2n_exact(n, z):
"""Return the value of i^{(2)}_n computed using the exact formula.
The expression used is http://dlmf.nist.gov/10.49.E10 .
"""
zm = mpmathify(z)
s1 = sum(mpc(-1,0)**k * _a(k, n)/zm**(k+1) for k in xrange(n+1))
s2 = sum(_a(k, n)/zm**(k+1) for k in xrange(n+1))
return exp(zm)/2 * s1 + mpc(-1,0)**n*exp(-zm)/2 * s2
开发者ID:tpudlik,项目名称:sbf,代码行数:10,代码来源:sbf_mp.py
示例20: formatOutput
def formatOutput( output ):
# filter out text strings
for c in output:
if c in '+-.':
continue
# anything with embedded whitespace is a string
if c in string.whitespace or c in string.punctuation:
return output
#print( )
#print( 'formatOutput 1:', output )
# override settings with temporary settings if needed
# if g.tempCommaMode:
# comma = True
# else:
# comma = g.comma
# output settings, which may be overrided by temp settings
outputRadix = g.outputRadix
integerGrouping = g.integerGrouping
leadingZero = g.leadingZero
if g.tempHexMode:
integerGrouping = 4
leadingZero = True
outputRadix = 16
if g.tempLeadingZeroMode:
leadingZero = True
if g.tempOctalMode:
integerGrouping = 3
leadingZero = True
outputRadix = 8
mpOutput = mpmathify( output )
imaginary = im( mpOutput )
real = re( mpOutput )
result, negative = formatNumber( real, outputRadix, leadingZero, integerGrouping )
if negative:
result = '-' + result
if imaginary != 0:
strImaginary, negativeImaginary = formatNumber( imaginary, outputRadix, leadingZero )
result = '( ' + result + ( ' - ' if negativeImaginary else ' + ' ) + strImaginary + 'j )'
#print( 'formatOutput 2:', output )
#print( )
return result
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:55,代码来源:rpnOutput.py
注:本文中的mpmath.mpmathify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论