本文整理汇总了Python中mpmath.fsub函数的典型用法代码示例。如果您正苦于以下问题:Python fsub函数的具体用法?Python fsub怎么用?Python fsub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fsub函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getNthNonagonalOctagonalNumber
def getNthNonagonalOctagonalNumber( n ):
sqrt6 = sqrt( 6 )
sqrt7 = sqrt( 7 )
return nint( floor( fdiv( fmul( fsub( fmul( 11, sqrt7 ), fmul( 9, sqrt6 ) ),
power( fadd( sqrt6, sqrt7 ), fsub( fmul( 8, real_int( n ) ), 5 ) ) ),
672 ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:7,代码来源:rpnPolytope.py
示例2: 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
示例3: getNthOctagonalTriangularNumber
def getNthOctagonalTriangularNumber( n ):
sign = power( -1, real( n ) )
return nint( floor( fdiv( fmul( fsub( 7, fprod( [ 2, sqrt( 6 ), sign ] ) ),
power( fadd( sqrt( 3 ), sqrt( 2 ) ),
fsub( fmul( 4, real_int( n ) ), 2 ) ) ),
96 ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:7,代码来源:rpnPolytope.py
示例4: cont_frac_expansion_sqrt
def cont_frac_expansion_sqrt(n):
"""
n is NOT square
e.g. 2 --> (1,2) (2 repeats)
"""
if is_square(n):
return 0
seq = []
r = mp.sqrt(n,prec=1000) # DOESNT MATTER?
a = floor(r)
fls = [r]
seq.append(int(a))
r = mp.fdiv(1.,mp.fsub(r,a,prec=1000),prec=1000)
a = floor(r)
fls.append(r)
seq.append(int(a))
r = mp.fdiv(1.,mp.fsub(r,a,prec=1000),prec=1000) #THESE TWO MATTER!!!
a = floor(r)
fls.append(r)
seq.append(int(a))
while not close(r, fls[1]):
r = mp.fdiv(1.,mp.fsub(r,a,prec=1000),prec=1000) #THESE TWO MATTER!!!
a = floor(r)
fls.append(r)
seq.append(int(a))
# print seq
seq.pop()
return seq
开发者ID:domspad,项目名称:euler,代码行数:28,代码来源:p66.py
示例5: _findLeaving
def _findLeaving(self, enteringPos):
increase = mp.fsub(mp.inf,'1')
idx = mp.inf
pos = -1
# find the variable with the smaller upper bound to the increase in the entering variable
# if there are multiple choices, set the one with the smaller index on the list of basic indexes
for i in range(self.m):
upperBound = self._getUpperBound(self.b[i], self.A[i, enteringPos])
# if this variable impose more constraint on the increase of the entering variable
# than the current leaving variable, then this is the new leaving variable
if upperBound <= mp.fsub(increase, self.tolerance):
idx = self.basicIdx[i]
pos = i
increase = upperBound
# if this variable impose the same constraint on the increase of the entering variable
# than the current leaving variable (considering the tolerance) but has a lower index,
# then this is the new leaving variable
elif mp.almosteq(upperBound, increase, self.tolerance) and self.basicIdx[i] < idx:
idx = self.basicIdx[i]
pos = i
if pos >= 0:
return idx, pos
else:
return Dictionary.UNBOUNDEDCODE, Dictionary.UNBOUNDED
开发者ID:rafaellc28,项目名称:ILPSover-in-Python,代码行数:27,代码来源:Dictionary.py
示例6: getSigma
def getSigma( target ):
'''
Returns the sum of the divisors of n, including 1 and n.
http://math.stackexchange.com/questions/22721/is-there-a-formula-to-calculate-the-sum-of-all-proper-divisors-of-a-number
'''
n = floor( target )
if real( n ) == 0:
return 0
elif n == 1:
return 1
factors = getECMFactors( n ) if g.ecm else getFactors( n )
result = 1
for factor in factors:
numerator = fsub( power( factor[ 0 ], fadd( factor[ 1 ], 1 ) ), 1 )
denominator = fsub( factor[ 0 ], 1 )
#debugPrint( 'sigma', numerator, denominator )
result = fmul( result, fdiv( numerator, denominator ) )
if result != floor( result ):
raise ValueError( 'insufficient precision for \'sigma\', increase precision (-p))' )
return result
开发者ID:flawr,项目名称:rpn,代码行数:27,代码来源:rpnNumberTheory.py
示例7: getEulerPhi
def getEulerPhi( n ):
if real( n ) < 2:
return n
if g.ecm:
return reduce( fmul, ( fmul( fsub( i[ 0 ], 1 ), power( i[ 0 ], fsub( i[ 1 ], 1 ) ) ) for i in getECMFactors( n ) ) )
else:
return reduce( fmul, ( fmul( fsub( i[ 0 ], 1 ), power( i[ 0 ], fsub( i[ 1 ], 1 ) ) ) for i in getFactors( n ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:8,代码来源:rpnNumberTheory.py
示例8: getNthDecagonalHeptagonalNumber
def getNthDecagonalHeptagonalNumber( n ):
sqrt10 = sqrt( 10 )
return nint( floor( fdiv( fprod( [ fsub( 11,
fmul( fmul( 2, sqrt10 ),
power( -1, real_int( n ) ) ) ),
fadd( 1, sqrt10 ),
power( fadd( 3, sqrt10 ),
fsub( fmul( 4, n ), 3 ) ) ] ), 320 ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:9,代码来源:rpnPolytope.py
示例9: getNthNonagonalPentagonalNumber
def getNthNonagonalPentagonalNumber( n ):
sqrt21 = sqrt( 21 )
sign = power( -1, real_int( n ) )
return nint( floor( fdiv( fprod( [ fadd( 25, fmul( 4, sqrt21 ) ),
fsub( 5, fmul( sqrt21, sign ) ),
power( fadd( fmul( 2, sqrt( 7 ) ), fmul( 3, sqrt( 3 ) ) ),
fsub( fmul( 4, n ), 4 ) ) ] ),
336 ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:9,代码来源:rpnPolytope.py
示例10: subtract
def subtract( self, other ):
if isinstance( other, RPNMeasurement ):
if self.units == other.units:
return RPNMeasurement( fsub( self.value, other.value ), self.units )
else:
return RPNMeasurement( fsub( self.value, other.convertValue( self ) ), self.units )
else:
return RPNMeasurement( fsub( self.value, other ), self.units )
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:9,代码来源:rpnMeasurement.py
示例11: getNthNonagonalTriangularNumber
def getNthNonagonalTriangularNumber( n ):
a = fmul( 3, sqrt( 7 ) )
b = fadd( 8, a )
c = fsub( 8, a )
return nint( fsum( [ fdiv( 5, 14 ),
fmul( fdiv( 9, 28 ), fadd( power( b, real_int( n ) ), power( c, n ) ) ),
fprod( [ fdiv( 3, 28 ),
sqrt( 7 ),
fsub( power( b, n ), power( c, n ) ) ] ) ] ) )
开发者ID:flawr,项目名称:rpn,代码行数:10,代码来源:rpnPolytope.py
示例12: getNthSquareTriangularNumber
def getNthSquareTriangularNumber( n ):
neededPrecision = int( real_int( n ) * 3.5 ) # determined by experimentation
if mp.dps < neededPrecision:
setAccuracy( neededPrecision )
sqrt2 = sqrt( 2 )
return nint( power( fdiv( fsub( power( fadd( 1, sqrt2 ), fmul( 2, n ) ),
power( fsub( 1, sqrt2 ), fmul( 2, n ) ) ),
fmul( 4, sqrt2 ) ), 2 ) )
开发者ID:flawr,项目名称:rpn,代码行数:11,代码来源:rpnPolytope.py
示例13: getNthDecagonalCenteredSquareNumber
def getNthDecagonalCenteredSquareNumber( n ):
sqrt10 = sqrt( 10 )
dps = 7 * int( real_int( n ) )
if mp.dps < dps:
mp.dps = dps
return nint( floor( fsum( [ fdiv( 1, 8 ),
fmul( fdiv( 7, 16 ), power( fsub( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ),
fmul( fmul( fdiv( 1, 8 ), power( fsub( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ), sqrt10 ),
fmul( fmul( fdiv( 1, 8 ), power( fadd( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ), sqrt10 ),
fmul( fdiv( 7, 16 ), power( fadd( 721, fmul( 228, sqrt10 ) ), fsub( n, 1 ) ) ) ] ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:13,代码来源:rpnPolytope.py
示例14: getStandardDeviation
def getStandardDeviation( args ):
if isinstance( args, RPNGenerator ):
return getStandardDeviation( list( args ) )
elif isinstance( args[ 0 ], ( list, RPNGenerator ) ):
return [ getStandardDeviation( arg ) for arg in args ]
if len( args ) < 2:
return 0
mean = fsum( args ) / len( args )
dev = [ power( fsub( i, mean ), 2 ) for i in args ]
return sqrt( fdiv( fsum( dev ), fsub( len( dev ), 1 ) ) )
开发者ID:ConceptJunkie,项目名称:rpn,代码行数:13,代码来源:rpnList.py
示例15: getNthNonagonalSquareNumber
def getNthNonagonalSquareNumber( n ):
if real( n ) < 0:
ValueError( '' )
p = fsum( [ fmul( 8, sqrt( 7 ) ), fmul( 9, sqrt( 14 ) ), fmul( -7, sqrt( 2 ) ), -28 ] )
q = fsum( [ fmul( 7, sqrt( 2 ) ), fmul( 9, sqrt( 14 ) ), fmul( -8, sqrt( 7 ) ), -28 ] )
sign = power( -1, real_int( n ) )
index = fdiv( fsub( fmul( fadd( p, fmul( q, sign ) ),
power( fadd( fmul( 2, sqrt( 2 ) ), sqrt( 7 ) ), n ) ),
fmul( fsub( p, fmul( q, sign ) ),
power( fsub( fmul( 2, sqrt( 2 ) ), sqrt( 7 ) ), fsub( n, 1 ) ) ) ), 112 )
return nint( power( nint( index ), 2 ) )
开发者ID:flawr,项目名称:rpn,代码行数:14,代码来源:rpnPolytope.py
示例16: solveQuadraticPolynomial
def solveQuadraticPolynomial( a, b, c ):
if a == 0:
if b == 0:
raise ValueError( 'invalid expression, no variable coefficients' )
else:
# linear equation, one root
return [ fdiv( fneg( c ), b ) ]
else:
d = sqrt( fsub( power( b, 2 ), fmul( 4, fmul( a, c ) ) ) )
x1 = fdiv( fadd( fneg( b ), d ), fmul( 2, a ) )
x2 = fdiv( fsub( fneg( b ), d ), fmul( 2, a ) )
return [ x1, x2 ]
开发者ID:flawr,项目名称:rpn,代码行数:14,代码来源:rpnPolynomials.py
示例17: interval_bisection
def interval_bisection(equation, lower, upper) -> str:
""" Calculate the root of the equation using
`Interval Bisection` method.
Examples:
>>> interval_bisection([1, 0, -3, -4], 2, 3)[0]
'2.19582335'
>>> interval_bisection([1, 0, 1, -6], 1, 2)[0]
'1.63436529'
>>> interval_bisection([1, 0, 3, -12], 1, 2)[0]
'1.85888907'
"""
# Counts the number of iteration
counter = 0
equation = mpfiy(equation)
lower, upper = mpf(lower), mpf(upper)
index_length = len(equation)
x = mean(lower, upper)
previous_alpha = alpha = None
delta = fsub(upper, lower)
while delta > power(10, -10) or previous_alpha is None:
ans = mpf(0)
# Summing the answer
for i in range(index_length):
index_power = index_length - i - 1
ans = fadd(ans, fmul(equation[i], power(x, index_power)))
if ans > mpf(0):
upper = x
else:
lower = x
x = mean(lower, upper)
previous_alpha, alpha = alpha, x
if previous_alpha is None:
continue
elif previous_alpha == alpha:
break
delta = abs(fsub(alpha, previous_alpha))
counter += 1
return str(near(alpha, lower, upper)), counter
开发者ID:red2awn,项目名称:Newton,代码行数:49,代码来源:numerical_method.py
示例18: findNthPolygonalNumber
def findNthPolygonalNumber( n, k ):
if real_int( k ) < 3:
raise ValueError( 'the number of sides of the polygon cannot be less than 3,' )
return nint( fdiv( fsum( [ sqrt( fsum( [ power( k, 2 ), fprod( [ 8, k, real( n ) ] ),
fneg( fmul( 8, k ) ), fneg( fmul( 16, n ) ), 16 ] ) ),
k, -4 ] ), fmul( 2, fsub( k, 2 ) ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:7,代码来源:rpnPolytope.py
示例19: getNthPadovanNumber
def getNthPadovanNumber( arg ):
n = fadd( real( arg ), 4 )
a = root( fsub( fdiv( 27, 2 ), fdiv( fmul( 3, sqrt( 69 ) ), 2 ) ), 3 )
b = root( fdiv( fadd( 9, sqrt( 69 ) ), 2 ), 3 )
c = fadd( 1, fmul( mpc( 0, 1 ), sqrt( 3 ) ) )
d = fsub( 1, fmul( mpc( 0, 1 ), sqrt( 3 ) ) )
e = power( 3, fdiv( 2, 3 ) )
r = fadd( fdiv( a, 3 ), fdiv( b, e ) )
s = fsub( fmul( fdiv( d, -6 ), a ), fdiv( fmul( c, b ), fmul( 2, e ) ) )
t = fsub( fmul( fdiv( c, -6 ), a ), fdiv( fmul( d, b ), fmul( 2, e ) ) )
return nint( re( fsum( [ fdiv( power( r, n ), fadd( fmul( 2, r ), 3 ) ),
fdiv( power( s, n ), fadd( fmul( 2, s ), 3 ) ),
fdiv( power( t, n ), fadd( fmul( 2, t ), 3 ) ) ] ) ) )
开发者ID:flawr,项目名称:rpn,代码行数:16,代码来源:rpnNumberTheory.py
示例20: convertToFibBase
def convertToFibBase( value ):
result = ''
n = value
if n >= 1:
a = 1
b = 1
c = fadd( a, b ) # next Fibonacci number
fibs = [ b ] # list of Fibonacci numbers, starting with F(2), each <= n
while n >= c:
fibs.append( c ) # add next Fibonacci number to end of list
a = b
b = c
c = fadd( a, b )
for fibnum in reversed( fibs ):
if n >= fibnum:
n = fsub( n, fibnum )
result = result + '1'
else:
result = result + '0'
return result
开发者ID:flawr,项目名称:rpn,代码行数:26,代码来源:rpnBase.py
注:本文中的mpmath.fsub函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论