本文整理汇总了Python中sympy.core.C.floor方法的典型用法代码示例。如果您正苦于以下问题:Python C.floor方法的具体用法?Python C.floor怎么用?Python C.floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.C
的用法示例。
在下文中一共展示了C.floor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: real_root
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import floor [as 别名]
def real_root(arg, n=None):
"""Return the real nth-root of arg if possible. If n is omitted then
all instances of (-n)**(1/odd) will be changed to -n**(1/odd); this
will only create a real root of a principle root -- the presence of
other factors may cause the result to not be real.
Examples
========
>>> from sympy import root, real_root, Rational
>>> from sympy.abc import x, n
>>> real_root(-8, 3)
-2
>>> root(-8, 3)
2*(-1)**(1/3)
>>> real_root(_)
-2
If one creates a non-principle root and applies real_root, the
result will not be real (so use with caution):
>>> root(-8, 3, 2)
-2*(-1)**(2/3)
>>> real_root(_)
-2*(-1)**(2/3)
See Also
========
sympy.polys.rootoftools.RootOf
sympy.core.power.integer_nthroot
root, sqrt
"""
if n is not None:
try:
n = as_int(n)
arg = sympify(arg)
if arg.is_positive or arg.is_negative:
rv = root(arg, n)
else:
raise ValueError
except ValueError:
return root(arg, n)*C.Piecewise(
(S.One, ~C.Equality(C.im(arg), 0)),
(C.Pow(S.NegativeOne, S.One/n)**(2*C.floor(n/2)), C.And(
C.Equality(n % 2, 1),
arg < 0)),
(S.One, True))
else:
rv = sympify(arg)
n1pow = Transform(lambda x: -(-x.base)**x.exp,
lambda x:
x.is_Pow and
x.base.is_negative and
x.exp.is_Rational and
x.exp.p == 1 and x.exp.q % 2)
return rv.xreplace(n1pow)
示例2: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import floor [as 别名]
def taylor_term(n, x, *previous_terms):
if n < 0 or n % 2 == 0:
return S.Zero
else:
x = sympify(x)
k = C.floor((n - 1)/S(2))
if len(previous_terms) > 2:
return -previous_terms[-2] * x**2 * (n - 2)/(n*k)
else:
return 2*(-1)**k * x**n/(n*C.factorial(k)*sqrt(S.Pi))