当前位置: 首页>>代码示例>>Python>>正文


Python C.binomial方法代码示例

本文整理汇总了Python中sympy.core.C.binomial方法的典型用法代码示例。如果您正苦于以下问题:Python C.binomial方法的具体用法?Python C.binomial怎么用?Python C.binomial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.core.C的用法示例。


在下文中一共展示了C.binomial方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _calc_bernoulli

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.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)
开发者ID:Zulko,项目名称:sympy,代码行数:15,代码来源:numbers.py

示例2: _eval_rewrite_as_Sum

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.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
开发者ID:Zulko,项目名称:sympy,代码行数:11,代码来源:numbers.py

示例3: _stirling1

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import binomial [as 别名]
def _stirling1(n, k):
    if n == k == 0:
        return S.One
    if 0 in (n, k):
        return S.Zero
    n1 = n - 1

    # some special values
    if n == k:
        return S.One
    elif k == 1:
        return factorial(n1)
    elif k == n1:
        return C.binomial(n, 2)
    elif k == n - 2:
        return (3*n - 1)*C.binomial(n, 3)/4
    elif k == n - 3:
        return C.binomial(n, 2)*C.binomial(n, 4)

    # general recurrence
    return n1*_stirling1(n1, k) + _stirling1(n1, k - 1)
开发者ID:Zulko,项目名称:sympy,代码行数:23,代码来源:numbers.py

示例4: _stirling2

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import binomial [as 别名]
def _stirling2(n, k):
    if n == k == 0:
        return S.One
    if 0 in (n, k):
        return S.Zero
    n1 = n - 1

    # some special values
    if k == n1:
        return C.binomial(n, 2)
    elif k == 2:
        return 2**n1 - 1

    # general recurrence
    return k*_stirling2(n1, k) + _stirling2(n1, k - 1)
开发者ID:Zulko,项目名称:sympy,代码行数:17,代码来源:numbers.py

示例5: eval

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.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 range(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 range(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.")

        if sym is None:
            if n.is_odd and (n - 1).is_positive:
                return S.Zero
开发者ID:artcompiler,项目名称:artcompiler.github.com,代码行数:46,代码来源:numbers.py

示例6: RGS_enum

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import binomial [as 别名]
def RGS_enum(m):
    """
    RGS_enum computes the total number of restricted growth strings
    possible for a superset of size m.

    Examples
    ========

    >>> from sympy.combinatorics.partitions import RGS_enum
    >>> from sympy.combinatorics.partitions import Partition
    >>> RGS_enum(4)
    15
    >>> RGS_enum(5)
    52
    >>> RGS_enum(6)
    203

    We can check that the enumeration is correct by actually generating
    the partitions. Here, the 15 partitions of 4 items are generated:

    >>> a = Partition([range(4)])
    >>> s = set()
    >>> for i in range(20):
    ...     s.add(a)
    ...     a += 1
    ...
    >>> assert len(s) == 15
    """
    if (m < 1):
        return 0
    elif (m == 1):
        return 1
    else:
        m += 1
        b = [1] * (m)
        for j in xrange(1, m):
            for i in xrange(1, j):
                b[j] += C.binomial(j - 1, i) * b[i]

        nrgf = b[m - 1]
    return nrgf
开发者ID:dyao-vu,项目名称:meta-core,代码行数:43,代码来源:partitions.py

示例7: _eval_rewrite_as_binomial

# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import binomial [as 别名]
 def _eval_rewrite_as_binomial(self, n):
     return C.binomial(2*n, n)/(n + 1)
开发者ID:Zulko,项目名称:sympy,代码行数:4,代码来源:numbers.py


注:本文中的sympy.core.C.binomial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。