本文整理汇总了Python中sympy.C.binomial方法的典型用法代码示例。如果您正苦于以下问题:Python C.binomial方法的具体用法?Python C.binomial怎么用?Python C.binomial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.C
的用法示例。
在下文中一共展示了C.binomial方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _calc_bernoulli
# 需要导入模块: from sympy import C [as 别名]
# 或者: from sympy.C import binomial [as 别名]
def _calc_bernoulli(n):
s = 0
a = int(C.binomial(n+3, n-6))
for j in xrange(1, n//6+1):
s += a * bernoulli(n - 6*j)
# Avoid computing each binomial coefficient from scratch
a *= _product(n-6 - 6*j + 1, n-6*j)
a //= _product(6*j+4, 6*j+9)
if n % 6 == 4:
s = -Rational(n+3, 6) - s
else:
s = Rational(n+3, 3) - s
return s / C.binomial(n+3, n)
示例2: _eval_rewrite_as_Sum
# 需要导入模块: from sympy import C [as 别名]
# 或者: from sympy.C import binomial [as 别名]
def _eval_rewrite_as_Sum(self, arg):
if arg.is_even:
k = C.Dummy("k", integer=True)
j = C.Dummy("j", integer=True)
n = self.args[0] / 2
Em = (S.ImaginaryUnit * C.Sum( C.Sum( C.binomial(k,j) * ((-1)**j * (k-2*j)**(2*n+1)) /
(2**k*S.ImaginaryUnit**k * k), (j,0,k)), (k, 1, 2*n+1)))
return Em
示例3: eval
# 需要导入模块: from sympy import C [as 别名]
# 或者: from sympy.C import binomial [as 别名]
def eval(cls, n, sym=None):
if n.is_Number:
if n.is_Integer and n.is_nonnegative:
if n is S.Zero:
return S.One
elif n is S.One:
if sym is None:
return -S.Half
else:
return sym - S.Half
# Bernoulli numbers
elif sym is None:
if n.is_odd:
return S.Zero
n = int(n)
# Use mpmath for enormous Bernoulli numbers
if n > 500:
p, q = bernfrac(n)
return Rational(int(p), int(q))
case = n % 6
highest_cached = cls._highest[case]
if n <= highest_cached:
return cls._cache[n]
# To avoid excessive recursion when, say, bernoulli(1000) is
# requested, calculate and cache the entire sequence ... B_988,
# B_994, B_1000 in increasing order
for i in xrange(highest_cached + 6, n + 6, 6):
b = cls._calc_bernoulli(i)
cls._cache[i] = b
cls._highest[case] = i
return b
# Bernoulli polynomials
else:
n, result = int(n), []
for k in xrange(n + 1):
result.append(C.binomial(n, k)*cls(k)*sym**(n - k))
return Add(*result)
else:
raise ValueError("Bernoulli numbers are defined only"
" for nonnegative integer indices.")
示例4: _eval_rewrite_as_binomial
# 需要导入模块: from sympy import C [as 别名]
# 或者: from sympy.C import binomial [as 别名]
def _eval_rewrite_as_binomial(self,n):
return C.binomial(2*n,n)/(n + 1)