本文整理汇总了Python中sympy.core.C.factorial方法的典型用法代码示例。如果您正苦于以下问题:Python C.factorial方法的具体用法?Python C.factorial怎么用?Python C.factorial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.C
的用法示例。
在下文中一共展示了C.factorial方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: monomial_count
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def monomial_count(V, N):
r"""
Computes the number of monomials.
The number of monomials is given by the following formula:
.. math::
\frac{(\#V + N)!}{\#V! N!}
where `N` is a total degree and `V` is a set of variables.
**Examples**
>>> from sympy import monomials, monomial_count
>>> from sympy.abc import x, y
>>> monomial_count(2, 2)
6
>>> M = monomials([x, y], 2)
>>> sorted(M)
[1, x, y, x**2, y**2, x*y]
>>> len(M)
6
"""
return C.factorial(V + N) / C.factorial(V) / C.factorial(N)
示例2: monomial_count
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def monomial_count(V, N):
r"""
Computes the number of monomials.
The number of monomials is given by the following formula:
.. math::
\frac{(\#V + N)!}{\#V! N!}
where `N` is a total degree and `V` is a set of variables.
Examples
========
>>> from sympy.polys.monomials import itermonomials, monomial_count
>>> from sympy.polys.orderings import monomial_key
>>> from sympy.abc import x, y
>>> monomial_count(2, 2)
6
>>> M = itermonomials([x, y], 2)
>>> sorted(M, key=monomial_key('grlex', [y, x]))
[1, x, y, x**2, x*y, y**2]
>>> len(M)
6
"""
return C.factorial(V + N) / C.factorial(V) / C.factorial(N)
示例3: _eval_aseries
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def _eval_aseries(self, n, args0, x, logx):
if args0[0] != S.Infinity:
return super(_erfs, self)._eval_aseries(n, args0, x, logx)
z = self.args[0]
l = [ 1/sqrt(S.Pi) * C.factorial(2*k)*(-S(4))**(-k)/C.factorial(k) * (1/z)**(2*k+1) for k in xrange(0,n) ]
o = C.Order(1/z**(2*n+1), x)
# It is very inefficient to first add the order and then do the nseries
return (Add(*l))._eval_nseries(x, n, logx) + o
示例4: eval
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def eval(cls, z, a=S.One):
z, a = map(sympify, (z, a))
if a.is_Number:
if a is S.NaN:
return S.NaN
elif a is S.Zero:
return cls(z)
if z.is_Number:
if z is S.NaN:
return S.NaN
elif z is S.Infinity:
return S.One
elif z is S.Zero:
if a.is_negative:
return S.Half - a - 1
else:
return S.Half - a
elif z is S.One:
return S.ComplexInfinity
elif z.is_Integer:
if a.is_Integer:
if z.is_negative:
zeta = (-1)**z * C.bernoulli(-z+1)/(-z+1)
elif z.is_even:
B, F = C.bernoulli(z), C.factorial(z)
zeta = 2**(z-1) * abs(B) * pi**z / F
else:
return
if a.is_negative:
return zeta + C.harmonic(abs(a), z)
else:
return zeta - C.harmonic(a-1, z)
示例5: eval
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def eval(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
elif arg is S.Infinity:
return S.Infinity
elif arg.is_Integer:
if arg.is_positive:
return C.factorial(arg - 1)
else:
return S.ComplexInfinity
elif arg.is_Rational:
if arg.q == 2:
n = abs(arg.p) // arg.q
if arg.is_positive:
k, coeff = n, S.One
else:
n = k = n + 1
if n & 1 == 0:
coeff = S.One
else:
coeff = S.NegativeOne
for i in range(3, 2 * k, 2):
coeff *= i
if arg.is_positive:
return coeff * sqrt(S.Pi) / 2 ** n
else:
return 2 ** n * sqrt(S.Pi) / coeff
示例6: _eval_expand_func
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def _eval_expand_func(self, **hints):
n, z = self.args
if n.is_Integer and n.is_nonnegative:
if z.is_Add:
coeff = z.args[0]
if coeff.is_Integer:
e = -(n + 1)
if coeff > 0:
tail = Add(*[C.Pow(z - i, e) for i in xrange(1, int(coeff) + 1)])
else:
tail = -Add(*[C.Pow(z + i, e) for i in xrange(0, int(-coeff))])
return polygamma(n, z - coeff) + (-1) ** n * C.factorial(n) * tail
elif z.is_Mul:
coeff, z = z.as_two_terms()
if coeff.is_Integer and coeff.is_positive:
tail = [polygamma(n, z + C.Rational(i, coeff)) for i in xrange(0, int(coeff))]
if n == 0:
return Add(*tail) / coeff + log(coeff)
else:
return Add(*tail) / coeff ** (n + 1)
z *= coeff
return polygamma(n, z)
示例7: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def taylor_term(n, x, *previous_terms):
if n<0: return S.Zero
if n==0: return S.One
x = sympify(x)
if previous_terms:
p = previous_terms[-1]
if p is not None:
return p * x / n
return x**n/C.factorial()(n)
示例8: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [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))
示例9: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def taylor_term(n, x, *previous_terms):
if n < 0 or n % 2 == 1:
return S.Zero
else:
x = sympify(x)
if len(previous_terms) > 2:
p = previous_terms[-2]
return p * x**2 / (n*(n-1))
else:
return x**(n)/C.factorial(n)
示例10: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def taylor_term(n, x, *previous_terms):
"""
Calculates the next term in the Taylor series expansion.
"""
if n<0: return S.Zero
if n==0: return S.One
x = sympify(x)
if previous_terms:
p = previous_terms[-1]
if p is not None:
return p * x / n
return x**n/C.factorial()(n)
示例11: taylor_term
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def taylor_term(n, x, *previous_terms):
"""
Returns the next term in the Taylor series expansion
"""
if n == 0:
return 1/sympify(x)
elif n < 0 or n % 2 == 0:
return S.Zero
else:
x = sympify(x)
B = C.bernoulli(n + 1)
F = C.factorial(n + 1)
return 2 * (1 - 2**n) * B/F * x**n
示例12: eval
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def eval(cls, z, a_=None):
if a_ is None:
z, a = list(map(sympify, (z, 1)))
else:
z, a = list(map(sympify, (z, a_)))
if a.is_Number:
if a is S.NaN:
return S.NaN
elif a is S.One and a_ is not None:
return cls(z)
# TODO Should a == 0 return S.NaN as well?
if z.is_Number:
if z is S.NaN:
return S.NaN
elif z is S.Infinity:
return S.One
elif z is S.Zero:
if a.is_negative:
return S.Half - a - 1
else:
return S.Half - a
elif z is S.One:
return S.ComplexInfinity
elif z.is_Integer:
if a.is_Integer:
if z.is_negative:
zeta = (-1)**z * C.bernoulli(-z + 1)/(-z + 1)
elif z.is_even:
B, F = C.bernoulli(z), C.factorial(z)
zeta = 2**(z - 1) * abs(B) * pi**z / F
else:
return
if a.is_negative:
return zeta + C.harmonic(abs(a), z)
else:
return zeta - C.harmonic(a - 1, z)
示例13: eval
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def eval(cls, n, z):
n, z = map(sympify, (n, z))
if n.is_integer:
if n.is_negative:
return loggamma(z)
else:
if z.is_Number:
if z is S.NaN:
return S.NaN
elif z is S.Infinity:
if n.is_Number:
if n is S.Zero:
return S.Infinity
else:
return S.Zero
elif z.is_Integer:
if z.is_nonpositive:
return S.ComplexInfinity
else:
if n is S.Zero:
return -S.EulerGamma + C.harmonic(z-1, 1)
elif n.is_odd:
return (-1)**(n+1)*C.factorial(n)*zeta(n+1, z)
示例14: _eval_rewrite_as_factorial
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def _eval_rewrite_as_factorial(self, n, k):
return C.factorial(n)/(C.factorial(k)*C.factorial(n - k))
示例15: _eval_rewrite_as_harmonic
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import factorial [as 别名]
def _eval_rewrite_as_harmonic(self, n, z):
if n.is_integer:
if n == S.Zero:
return harmonic(z - 1) - S.EulerGamma
else:
return S.NegativeOne ** (n + 1) * C.factorial(n) * (C.zeta(n + 1) - harmonic(z - 1, n + 1))