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


Python sympy.product函数代码示例

本文整理汇总了Python中sympy.product函数的典型用法代码示例。如果您正苦于以下问题:Python product函数的具体用法?Python product怎么用?Python product使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test__eval_product

def test__eval_product():
    from sympy.abc import i, n
    # issue 4809
    a = Function('a')
    assert product(2*a(i), (i, 1, n)) == 2**n * Product(a(i), (i, 1, n))
    # issue 4810
    assert product(2**i, (i, 1, n)) == 2**(n/2 + n**2/2)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:7,代码来源:test_products.py

示例2: test_rational_products

def test_rational_products():
    assert simplify(product(1 + 1/n, (n, a, b))) == (1 + b)/a
    assert simplify(product(n + 1, (n, a, b))) == gamma(2 + b)/gamma(1 + a)
    assert simplify(product((n + 1)/(n - 1), (n, a, b))) == b*(1 + b)/(a*(a - 1))
    assert simplify(product(n/(n + 1)/(n + 2), (n, a, b))) == \
        a*gamma(a + 2)/(b + 1)/gamma(b + 3)
    assert simplify(product(n*(n + 1)/(n - 1)/(n - 2), (n, a, b))) == \
        b**2*(b - 1)*(1 + b)/(a - 1)**2/(a*(a - 2))
开发者ID:JoenyBui,项目名称:sympy,代码行数:8,代码来源:test_sums_products.py

示例3: test_special_products

def test_special_products():
    # Wallis product
    assert product((4*k)**2 / (4*k**2 - 1), (k, 1, n)) == \
        4**n*factorial(n)**2/rf(Rational(1, 2), n)/rf(Rational(3, 2), n)

    # Euler's product formula for sin
    assert product(1 + a/k**2, (k, 1, n)) == \
        rf(1 - sqrt(-a), n)*rf(1 + sqrt(-a), n)/factorial(n)**2
开发者ID:A-turing-machine,项目名称:sympy,代码行数:8,代码来源:test_products.py

示例4: test__eval_product

def test__eval_product():
    from sympy.abc import i, n

    # 1710
    a = Function("a")
    assert product(2 * a(i), (i, 1, n)) == 2 ** n * Product(a(i), (i, 1, n))
    # 1711
    assert product(2 ** i, (i, 1, n)) == 2 ** (n / 2 + n ** 2 / 2)
开发者ID:Narsil,项目名称:sympy,代码行数:8,代码来源:test_products.py

示例5: test_multiple_products

def test_multiple_products():
    assert product(x, (n, 1, k), (k, 1, m)) == x**(m**2/2 + m/2)
    assert product(f(n), (n, 1, m), (m, 1, k)) == Product(f(n), (n, 1, m), (m, 1, k)).doit()
    assert Product(f(n), (m, 1, k), (n, 1, k)).doit() == \
        Product(Product(f(n), (m, 1, k)), (n, 1, k)).doit() == \
        product(f(n), (m, 1, k), (n, 1, k)) == \
        product(product(f(n), (m, 1, k)), (n, 1, k)) == \
        Product(f(n)**k, (n, 1, k))
    assert Product(x, (x, 1, k), (k, 1, n)).doit() == Product(factorial(k), (k, 1, n))
开发者ID:ALGHeArT,项目名称:sympy,代码行数:9,代码来源:test_products.py

示例6: test_simple_products

def test_simple_products():
    assert Product(S.NaN, (x, 1, 3)) is S.NaN
    assert product(S.NaN, (x, 1, 3)) is S.NaN
    assert Product(x, (n, a, a)).doit() == x
    assert Product(x, (x, a, a)).doit() == a
    assert Product(x, (y, 1, a)).doit() == x**a
    lo, hi = 1, 2
    s1 = Product(n, (n, lo, hi))
    s2 = Product(n, (n, hi, lo))
    assert s1 != s2
    assert s1.doit() == s2.doit() == 2
    lo, hi = x, x + 1
    s1 = Product(n, (n, lo, hi))
    s2 = Product(n, (n, hi, lo))
    assert s1 != s2
    assert s1.doit() == s2.doit() == x*(x + 1)
    assert Product(Integral(2*x, (x, 1, y)) + 2*x, (x, 1, 2)).doit() == \
        (y**2 + 1)*(y**2 + 3)
    assert product(2, (n, a, b)) == 2**(b - a + 1)
    assert product(n, (n, 1, b)) == factorial(b)
    assert product(n**3, (n, 1, b)) == factorial(b)**3
    assert product(3**(2 + n), (n, a, b)) \
        == 3**(2*(1 - a + b) + b/2 + (b**2)/2 + a/2 - (a**2)/2)
    assert product(cos(n), (n, 3, 5)) == cos(3)*cos(4)*cos(5)
    assert product(cos(n), (n, x, x + 2)) == cos(x)*cos(x + 1)*cos(x + 2)
    assert isinstance(product(cos(n), (n, x, x + S.Half)), Product)
    # If Product managed to evaluate this one, it most likely got it wrong!
    assert isinstance(Product(n**n, (n, 1, b)), Product)
开发者ID:Maihj,项目名称:sympy,代码行数:28,代码来源:test_sums_products.py

示例7: test_simple_products

def test_simple_products():
    assert product(2, (k, a, n)) == 2**(n-a+1)
    assert product(k, (k, 1, n)) == factorial(n)
    assert product(k**3, (k, 1, n)) == factorial(n)**3

    assert product(k+1, (k, 0, n-1)) == factorial(n)
    assert product(k+1, (k, a, n-1)) == rf(1+a, n-a)

    assert product(cos(k), (k, 0, 5)) == cos(1)*cos(2)*cos(3)*cos(4)*cos(5)
    assert product(cos(k), (k, 3, 5)) == cos(3)*cos(4)*cos(5)
    assert product(cos(k), (k, 1, Rational(5, 2))) == cos(1)*cos(2)

    assert isinstance(product(k**k, (k, 1, n)), Product)
开发者ID:Grahack,项目名称:geophar,代码行数:13,代码来源:test_products.py

示例8: to_sympy

 def to_sympy(self, expr, **kwargs):
     if expr.has_form('Product', 2) and expr.leaves[1].has_form('List', 3):
         index = expr.leaves[1]
         try:
             return sympy.product(expr.leaves[0].to_sympy(), (
                 index.leaves[0].to_sympy(), index.leaves[1].to_sympy(),
                 index.leaves[2].to_sympy()))
         except ZeroDivisionError:
             pass
开发者ID:0xffea,项目名称:Mathics,代码行数:9,代码来源:arithmetic.py

示例9: test_simple_products

def test_simple_products():
    assert product(2, (k, a, n)) == 2**(n - a + 1)
    assert product(k, (k, 1, n)) == factorial(n)
    assert product(k**3, (k, 1, n)) == factorial(n)**3

    assert product(k + 1, (k, 0, n - 1)) == factorial(n)
    assert product(k + 1, (k, a, n - 1)) == rf(1 + a, n - a)

    assert product(cos(k), (k, 0, 5)) == cos(1)*cos(2)*cos(3)*cos(4)*cos(5)
    assert product(cos(k), (k, 3, 5)) == cos(3)*cos(4)*cos(5)
    assert product(cos(k), (k, 1, Rational(5, 2))) != cos(1)*cos(2)

    assert isinstance(product(k**k, (k, 1, n)), Product)

    assert Product(x**k, (k, 1, n)).variables == [k]

    raises(ValueError, lambda: Product(n))
    raises(ValueError, lambda: Product(n, k))
    raises(ValueError, lambda: Product(n, k, 1))
    raises(ValueError, lambda: Product(n, k, 1, 10))
    raises(ValueError, lambda: Product(n, (k, 1)))
开发者ID:Abhityagi16,项目名称:sympy,代码行数:21,代码来源:test_products.py

示例10: test_evalf_mul

def test_evalf_mul():
    # sympy should not try to expand this; it should be handled term-wise
    # in evalf through mpmath
    assert NS(product(1 + sqrt(n)*I, (n, 1, 500)), 1) == '5.e+567 + 2.e+568*I'
开发者ID:QuaBoo,项目名称:sympy,代码行数:4,代码来源:test_evalf.py

示例11: maxima_product

 def maxima_product(a1, a2, a3, a4):
     return product(a1, (a2, a3, a4))
开发者ID:jenshnielsen,项目名称:sympy,代码行数:2,代码来源:maxima.py

示例12: test_product_pow

def test_product_pow():
    # issue 4817
    assert product(2**f(k), (k, 1, n)) == 2**Sum(f(k), (k, 1, n))
    assert product(2**(2*f(k)), (k, 1, n)) == 2**Sum(2*f(k), (k, 1, n))
开发者ID:A-turing-machine,项目名称:sympy,代码行数:4,代码来源:test_products.py

示例13: test_F4

def test_F4():
    assert combsimp((2**n * factorial(n) * product(2*k - 1, (k, 1, n)))) == factorial(2*n)
开发者ID:batya239,项目名称:sympy,代码行数:2,代码来源:test_wester.py

示例14: test_issue_9983

def test_issue_9983():
    n = Symbol('n', integer=True, positive=True)
    p = Product(1 + 1/n**(S(2)/3), (n, 1, oo))
    assert p.is_convergent() is S.false
    assert product(1 + 1/n**(S(2)/3), (n, 1, oo)) == p.doit()
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:5,代码来源:test_products.py

示例15: test_Product_doit

def test_Product_doit():
    assert Product(n*Integral(a**2), (n, 1, 3)).doit() == 2 * a**9 / 9
    assert Product(n*Integral(a**2), (n, 1, 3)).doit(deep=False) == \
        6*Integral(a**2)**3
    assert product(n*Integral(a**2), (n, 1, 3)) == 6*Integral(a**2)**3
开发者ID:Maihj,项目名称:sympy,代码行数:5,代码来源:test_sums_products.py


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