本文整理汇总了Python中sympy.ntheory.multiplicity函数的典型用法代码示例。如果您正苦于以下问题:Python multiplicity函数的具体用法?Python multiplicity怎么用?Python multiplicity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了multiplicity函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_multiplicity
def test_multiplicity():
for b in range(2,20):
for i in range(100):
assert multiplicity(b, b**i) == i
assert multiplicity(b, (b**i) * 23) == i
assert multiplicity(b, (b**i) * 1000249) == i
# Should be fast
assert multiplicity(10, 10**10023) == 10023
开发者ID:smichr,项目名称:sympy-live,代码行数:8,代码来源:test_ntheory.py
示例2: test_multiplicity
def test_multiplicity():
for b in range(2, 20):
for i in range(100):
assert multiplicity(b, b**i) == i
assert multiplicity(b, (b**i) * 23) == i
assert multiplicity(b, (b**i) * 1000249) == i
# Should be fast
assert multiplicity(10, 10**10023) == 10023
# Should exit quickly
assert multiplicity(10**10, 10**10) == 1
# Should raise errors for bad input
raises(ValueError, 'multiplicity(1, 1)')
raises(ValueError, 'multiplicity(1, 2)')
raises(ValueError, 'multiplicity(1.3, 2)')
开发者ID:BDGLunde,项目名称:sympy,代码行数:14,代码来源:test_ntheory.py
示例3: eval
def eval(cls, arg, base=None):
from sympy import unpolarify
if base is not None:
base = sympify(base)
if arg.is_positive and arg.is_Integer and \
base.is_positive and base.is_Integer:
base = int(base)
arg = int(arg)
n = multiplicity(base, arg)
return S(n) + log(arg // base ** n) / log(base)
if base is not S.Exp1:
return cls(arg)/cls(base)
else:
return cls(arg)
arg = sympify(arg)
if arg.is_Number:
if arg is S.Zero:
return S.ComplexInfinity
elif arg is S.One:
return S.Zero
elif arg is S.Infinity:
return S.Infinity
elif arg is S.NegativeInfinity:
return S.Infinity
elif arg is S.NaN:
return S.NaN
elif arg.is_negative:
return S.Pi * S.ImaginaryUnit + cls(-arg)
elif arg.is_Rational:
if arg.q != 1:
return cls(arg.p) - cls(arg.q)
# remove perfect powers automatically
p = perfect_power(int(arg))
if p is not False:
return p[1]*cls(p[0])
elif arg is S.ComplexInfinity:
return S.ComplexInfinity
elif arg is S.Exp1:
return S.One
elif arg.func is exp and arg.args[0].is_real:
return arg.args[0]
elif arg.func is exp_polar:
return unpolarify(arg.exp)
#don't autoexpand Pow or Mul (see the issue 252):
elif not arg.is_Add:
coeff = arg.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if coeff is S.Infinity:
return S.Infinity
elif coeff is S.NegativeInfinity:
return S.Infinity
elif coeff.is_Rational:
if coeff.is_nonnegative:
return S.Pi * S.ImaginaryUnit * S.Half + cls(coeff)
else:
return -S.Pi * S.ImaginaryUnit * S.Half + cls(-coeff)
开发者ID:ENuge,项目名称:sympy,代码行数:60,代码来源:exponential.py
示例4: eval
def eval(cls, arg, base=None):
if base is not None:
base = sympify(base)
if arg.is_positive and arg.is_Integer and \
base.is_positive and base.is_Integer:
base = int(base)
arg = int(arg)
n = multiplicity(base, arg)
return S(n) + log(arg // base ** n) / log(base)
if base is not S.Exp1:
return cls(arg)/cls(base)
else:
return cls(arg)
arg = sympify(arg)
if arg.is_Number:
if arg is S.Zero:
return S.ComplexInfinity
elif arg is S.One:
return S.Zero
elif arg is S.Infinity:
return S.Infinity
elif arg is S.NegativeInfinity:
return S.Infinity
elif arg is S.NaN:
return S.NaN
elif arg.is_negative:
return S.Pi * S.ImaginaryUnit + cls(-arg)
elif arg is S.ComplexInfinity:
return S.ComplexInfinity
elif arg is S.Exp1:
return S.One
#this doesn't work due to caching: :(
#elif arg.func is exp and arg.args[0].is_real:
#using this one instead:
elif arg.func is exp and arg.args[0].is_real:
return arg.args[0]
#this shouldn't happen automatically (see the issue 252):
#elif arg.is_Pow:
# if arg.exp.is_Number or arg.exp.is_NumberSymbol or \
# arg.exp.is_number:
# return arg.exp * self(arg.base)
#elif arg.is_Mul and arg.is_real:
# return Add(*[self(a) for a in arg])
elif not arg.is_Add:
coeff = arg.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if coeff is S.Infinity:
return S.Infinity
elif coeff is S.NegativeInfinity:
return S.Infinity
elif coeff.is_Rational:
if coeff.is_nonnegative:
return S.Pi * S.ImaginaryUnit * S.Half + cls(coeff)
else:
return -S.Pi * S.ImaginaryUnit * S.Half + cls(-coeff)
开发者ID:jegerjensen,项目名称:sympy,代码行数:59,代码来源:exponential.py
示例5: eval
def eval(cls, arg, base=None):
from sympy import unpolarify
arg = sympify(arg)
if base is not None:
base = sympify(base)
if base == 1:
if arg == 1:
return S.NaN
else:
return S.ComplexInfinity
try:
# handle extraction of powers of the base now
# or else expand_log in Mul would have to handle this
n = multiplicity(base, arg)
if n:
den = base**n
if den.is_Integer:
return n + log(arg // den) / log(base)
else:
return n + log(arg / den) / log(base)
else:
return log(arg)/log(base)
except ValueError:
pass
if base is not S.Exp1:
return cls(arg)/cls(base)
else:
return cls(arg)
if arg.is_Number:
if arg is S.Zero:
return S.ComplexInfinity
elif arg is S.One:
return S.Zero
elif arg is S.Infinity:
return S.Infinity
elif arg is S.NegativeInfinity:
return S.Infinity
elif arg is S.NaN:
return S.NaN
elif arg.is_negative:
return S.Pi * S.ImaginaryUnit + cls(-arg)
elif arg.is_Rational:
if arg.q != 1:
return cls(arg.p) - cls(arg.q)
elif arg is S.ComplexInfinity:
return S.ComplexInfinity
elif arg is S.Exp1:
return S.One
elif arg.func is exp and arg.args[0].is_real:
return arg.args[0]
elif arg.func is exp_polar:
return unpolarify(arg.exp)
#don't autoexpand Pow or Mul (see the issue 252):
elif not arg.is_Add:
coeff = arg.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if coeff is S.Infinity:
return S.Infinity
elif coeff is S.NegativeInfinity:
return S.Infinity
elif coeff.is_Rational:
if coeff.is_nonnegative:
return S.Pi * S.ImaginaryUnit * S.Half + cls(coeff)
else:
return -S.Pi * S.ImaginaryUnit * S.Half + cls(-coeff)
开发者ID:AALEKH,项目名称:sympy,代码行数:68,代码来源:exponential.py
示例6: test_multiplicity
def test_multiplicity():
for b in range(2, 20):
for i in range(100):
assert multiplicity(b, b**i) == i
assert multiplicity(b, (b**i) * 23) == i
assert multiplicity(b, (b**i) * 1000249) == i
# Should be fast
assert multiplicity(10, 10**10023) == 10023
# Should exit quickly
assert multiplicity(10**10, 10**10) == 1
# Should raise errors for bad input
raises(ValueError, lambda: multiplicity(1, 1))
raises(ValueError, lambda: multiplicity(1, 2))
raises(ValueError, lambda: multiplicity(1.3, 2))
raises(ValueError, lambda: multiplicity(2, 0))
raises(ValueError, lambda: multiplicity(1.3, 0))
# handles Rationals
assert multiplicity(10, Rational(30, 7)) == 0
assert multiplicity(Rational(2, 7), Rational(4, 7)) == 1
assert multiplicity(Rational(1, 7), Rational(3, 49)) == 2
assert multiplicity(Rational(2, 7), Rational(7, 2)) == -1
assert multiplicity(3, Rational(1, 9)) == -2
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:23,代码来源:test_ntheory.py
示例7: eval
def eval(cls, arg, base=None):
from sympy import unpolarify
from sympy.calculus import AccumBounds
from sympy.sets.setexpr import SetExpr
arg = sympify(arg)
if base is not None:
base = sympify(base)
if base == 1:
if arg == 1:
return S.NaN
else:
return S.ComplexInfinity
try:
# handle extraction of powers of the base now
# or else expand_log in Mul would have to handle this
n = multiplicity(base, arg)
if n:
den = base**n
if den.is_Integer:
return n + log(arg // den) / log(base)
else:
return n + log(arg / den) / log(base)
else:
return log(arg)/log(base)
except ValueError:
pass
if base is not S.Exp1:
return cls(arg)/cls(base)
else:
return cls(arg)
if arg.is_Number:
if arg is S.Zero:
return S.ComplexInfinity
elif arg is S.One:
return S.Zero
elif arg is S.Infinity:
return S.Infinity
elif arg is S.NegativeInfinity:
return S.Infinity
elif arg is S.NaN:
return S.NaN
elif arg.is_Rational and arg.p == 1:
return -cls(arg.q)
if arg is S.ComplexInfinity:
return S.ComplexInfinity
if isinstance(arg, exp) and arg.args[0].is_real:
return arg.args[0]
elif isinstance(arg, exp_polar):
return unpolarify(arg.exp)
elif isinstance(arg, AccumBounds):
if arg.min.is_positive:
return AccumBounds(log(arg.min), log(arg.max))
else:
return
elif isinstance(arg, SetExpr):
return arg._eval_func(cls)
if arg.is_number:
if arg.is_negative:
return S.Pi * S.ImaginaryUnit + cls(-arg)
elif arg is S.ComplexInfinity:
return S.ComplexInfinity
elif arg is S.Exp1:
return S.One
# don't autoexpand Pow or Mul (see the issue 3351):
if not arg.is_Add:
coeff = arg.as_coefficient(S.ImaginaryUnit)
if coeff is not None:
if coeff is S.Infinity:
return S.Infinity
elif coeff is S.NegativeInfinity:
return S.Infinity
elif coeff.is_Rational:
if coeff.is_nonnegative:
return S.Pi * S.ImaginaryUnit * S.Half + cls(coeff)
else:
return -S.Pi * S.ImaginaryUnit * S.Half + cls(-coeff)
开发者ID:cmarqu,项目名称:sympy,代码行数:83,代码来源:exponential.py
注:本文中的sympy.ntheory.multiplicity函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论