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


Python sympy.zeta函数代码示例

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


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

示例1: test_gruntz_eval_special_fail

def test_gruntz_eval_special_fail():
    # TODO exponential integral Ei
    assert gruntz(
        (Ei(x - exp(-exp(x))) - Ei(x)) *exp(-x)*exp(exp(x))*x, x, oo) == -1

    # TODO zeta function series
    assert gruntz(
        exp((log(2) + 1)*x) * (zeta(x + exp(-x)) - zeta(x)), x, oo) == -log(2)
开发者ID:agamdua,项目名称:sympy,代码行数:8,代码来源:test_gruntz.py

示例2: test_issue_14177

def test_issue_14177():
    n = Symbol('n', positive=True, integer=True)

    assert zeta(2*n) == (-1)**(n + 1)*2**(2*n - 1)*pi**(2*n)*bernoulli(2*n)/factorial(2*n)
    assert zeta(-n) == (-1)**(-n)*bernoulli(n + 1)/(n + 1)

    n = Symbol('n')

    assert zeta(2*n) == zeta(2*n) # As sign of z (= 2*n) is not determined
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:9,代码来源:test_zeta_functions.py

示例3: test_derivatives

def test_derivatives():
    from sympy import Derivative
    assert zeta(x, a).diff(x) == Derivative(zeta(x, a), x)
    assert zeta(x, a).diff(a) == -x*zeta(x + 1, a)
    assert lerchphi(z, s, a).diff(z) == (lerchphi(z, s-1, a) - a*lerchphi(z, s, a))/z
    assert lerchphi(z, s, a).diff(a) == -s*lerchphi(z, s+1, a)
    assert polylog(s, z).diff(z) == polylog(s - 1, z)/z

    b = randcplx()
    c = randcplx()
    assert td(zeta(b, x), x)
    assert td(polylog(b, z), z)
    assert td(lerchphi(c, b, x), x)
    assert td(lerchphi(x, b, c), x)
开发者ID:ALGHeArT,项目名称:sympy,代码行数:14,代码来源:test_zeta_functions.py

示例4: eval

    def eval(cls, n, m=None):
        from sympy import zeta
        if m is S.One:
            return cls(n)
        if m is None:
            m = S.One

        if m.is_zero:
            return n

        if n is S.Infinity and m.is_Number:
            # TODO: Fix for symbolic values of m
            if m.is_negative:
                return S.NaN
            elif LessThan(m, S.One):
                return S.Infinity
            elif StrictGreaterThan(m, S.One):
                return zeta(m)
            else:
                return cls

        if n.is_Integer and n.is_nonnegative and m.is_Integer:
            if n == 0:
                return S.Zero
            if not m in cls._functions:
                @recurrence_memo([0])
                def f(n, prev):
                    return prev[-1] + S.One / n**m
                cls._functions[m] = f
            return cls._functions[m](int(n))
开发者ID:SungSingSong,项目名称:sympy,代码行数:30,代码来源:numbers.py

示例5: test_harmonic

def test_harmonic():
    n = Symbol("n")

    assert harmonic(n, 0) == n
    assert harmonic(n, 1) == harmonic(n)

    assert harmonic(0, 1) == 0
    assert harmonic(1, 1) == 1
    assert harmonic(2, 1) == Rational(3, 2)
    assert harmonic(3, 1) == Rational(11, 6)
    assert harmonic(4, 1) == Rational(25, 12)
    assert harmonic(0, 2) == 0
    assert harmonic(1, 2) == 1
    assert harmonic(2, 2) == Rational(5, 4)
    assert harmonic(3, 2) == Rational(49, 36)
    assert harmonic(4, 2) == Rational(205, 144)
    assert harmonic(0, 3) == 0
    assert harmonic(1, 3) == 1
    assert harmonic(2, 3) == Rational(9, 8)
    assert harmonic(3, 3) == Rational(251, 216)
    assert harmonic(4, 3) == Rational(2035, 1728)

    assert harmonic(oo, -1) == S.NaN
    assert harmonic(oo, 0) == oo
    assert harmonic(oo, S.Half) == oo
    assert harmonic(oo, 1) == oo
    assert harmonic(oo, 2) == (pi**2)/6
    assert harmonic(oo, 3) == zeta(3)
开发者ID:B-Rich,项目名称:sympy,代码行数:28,代码来源:test_comb_numbers.py

示例6: test_evalf_fast_series_issue998

def test_evalf_fast_series_issue998():
    # Catalan's constant
    assert NS(
        Sum(
            (-1) ** (n - 1)
            * 2 ** (8 * n)
            * (40 * n ** 2 - 24 * n + 3)
            * fac(2 * n) ** 3
            * fac(n) ** 2
            / n ** 3
            / (2 * n - 1)
            / fac(4 * n) ** 2,
            (n, 1, oo),
        )
        / 64,
        100,
    ) == NS(Catalan, 100)
    astr = NS(zeta(3), 100)
    assert NS(5 * Sum((-1) ** (n - 1) * fac(n) ** 2 / n ** 3 / fac(2 * n), (n, 1, oo)) / 2, 100) == astr
    assert (
        NS(
            Sum(
                (-1) ** (n - 1) * (56 * n ** 2 - 32 * n + 5) / (2 * n - 1) ** 2 * fac(n - 1) ** 3 / fac(3 * n),
                (n, 1, oo),
            )
            / 4,
            100,
        )
        == astr
    )
开发者ID:rpmuller,项目名称:sympy,代码行数:30,代码来源:test_sums_products.py

示例7: test_evalf_fast_series

def test_evalf_fast_series():
    # Euler transformed series for sqrt(1+x)
    assert NS(Sum(
        fac(2*n + 1)/fac(n)**2/2**(3*n + 1), (n, 0, oo)), 100) == NS(sqrt(2), 100)

    # Some series for exp(1)
    estr = NS(E, 100)
    assert NS(Sum(1/fac(n), (n, 0, oo)), 100) == estr
    assert NS(1/Sum((1 - 2*n)/fac(2*n), (n, 0, oo)), 100) == estr
    assert NS(Sum((2*n + 1)/fac(2*n), (n, 0, oo)), 100) == estr
    assert NS(Sum((4*n + 3)/2**(2*n + 1)/fac(2*n + 1), (n, 0, oo))**2, 100) == estr

    pistr = NS(pi, 100)
    # Ramanujan series for pi
    assert NS(9801/sqrt(8)/Sum(fac(
        4*n)*(1103 + 26390*n)/fac(n)**4/396**(4*n), (n, 0, oo)), 100) == pistr
    assert NS(1/Sum(
        binomial(2*n, n)**3 * (42*n + 5)/2**(12*n + 4), (n, 0, oo)), 100) == pistr
    # Machin's formula for pi
    assert NS(16*Sum((-1)**n/(2*n + 1)/5**(2*n + 1), (n, 0, oo)) -
        4*Sum((-1)**n/(2*n + 1)/239**(2*n + 1), (n, 0, oo)), 100) == pistr

    # Apery's constant
    astr = NS(zeta(3), 100)
    P = 126392*n**5 + 412708*n**4 + 531578*n**3 + 336367*n**2 + 104000* \
        n + 12463
    assert NS(Sum((-1)**n * P / 24 * (fac(2*n + 1)*fac(2*n)*fac(
        n))**3 / fac(3*n + 2) / fac(4*n + 3)**3, (n, 0, oo)), 100) == astr
    assert NS(Sum((-1)**n * (205*n**2 + 250*n + 77)/64 * fac(n)**10 /
              fac(2*n + 1)**5, (n, 0, oo)), 100) == astr
开发者ID:Maihj,项目名称:sympy,代码行数:30,代码来源:test_sums_products.py

示例8: test_polylog_expansion

def test_polylog_expansion():
    from sympy import factor, log
    assert polylog(s, 0) == 0
    assert polylog(s, 1) == zeta(s)
    assert polylog(s, -1) == dirichlet_eta(s)

    assert myexpand(polylog(1, z), -log(1 + exp_polar(-I*pi)*z))
    assert myexpand(polylog(0, z), z/(1 - z))
    assert myexpand(polylog(-1, z), z**2/(1 - z)**2 + z/(1 - z))
    assert myexpand(polylog(-5, z), None)
开发者ID:Abhityagi16,项目名称:sympy,代码行数:10,代码来源:test_zeta_functions.py

示例9: test_latex_functions

def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1)+exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == '\\operatorname{f}{\\left (x \\right )}'

    beta = Function('beta')

    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
    r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
    r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2,inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2),inv_trig_style="power",fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2,k)) == r"{\binom{2}{k}}"

    assert latex(FallingFactorial(3,k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3,k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Abs(x)) == r"\lvert{x}\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x+y)) == r"\Re {\left (x + y \right )}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma\left(x\right)"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x,y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta{\left (x \right )}'
开发者ID:songuke,项目名称:sympy,代码行数:55,代码来源:test_latex.py

示例10: test_Sum_doit

def test_Sum_doit():
    f = Function('f')
    assert Sum(n*Integral(a**2), (n, 0, 2)).doit() == a**3
    assert Sum(n*Integral(a**2), (n, 0, 2)).doit(deep=False) == \
        3*Integral(a**2)
    assert summation(n*Integral(a**2), (n, 0, 2)) == 3*Integral(a**2)

    # test nested sum evaluation
    s = Sum( Sum( Sum(2,(z,1,n+1)), (y,x+1,n)), (x,1,n))
    assert 0 == (s.doit() - n*(n+1)*(n-1)).factor()

    assert Sum(KroneckerDelta(m, n), (m, -oo, oo)).doit() == Piecewise((1, And(-oo < n, n < oo)), (0, True))
    assert Sum(x*KroneckerDelta(m, n), (m, -oo, oo)).doit() == Piecewise((x, And(-oo < n, n < oo)), (0, True))
    assert Sum(Sum(KroneckerDelta(m, n), (m, 1, 3)), (n, 1, 3)).doit() == 3
    assert Sum(Sum(KroneckerDelta(k, m), (m, 1, 3)), (n, 1, 3)).doit() == \
           3 * Piecewise((1, And(S(1) <= k, k <= 3)), (0, True))
    assert Sum(f(n) * Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, 3)).doit() == \
           f(1) + f(2) + f(3)
    assert Sum(f(n) * Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, oo)).doit() == \
           Sum(Piecewise((f(n), And(Le(0, n), n < oo)), (0, True)), (n, 1, oo))
    l = Symbol('l', integer=True, positive=True)
    assert Sum(f(l) * Sum(KroneckerDelta(m, l), (m, 0, oo)), (l, 1, oo)).doit() == \
           Sum(f(l), (l, 1, oo))

    # issue 2597
    nmax = symbols('N', integer=True, positive=True)
    pw = Piecewise((1, And(S(1) <= n, n <= nmax)), (0, True))
    assert Sum(pw, (n, 1, nmax)).doit() == Sum(pw, (n, 1, nmax))

    q, s = symbols('q, s')
    assert summation(1/n**(2*s), (n, 1, oo)) == Piecewise((zeta(2*s), 2*s > 1),
        (Sum(n**(-2*s), (n, 1, oo)), True))
    assert summation(1/(n+1)**s, (n, 0, oo)) == Piecewise((zeta(s), s > 1),
        (Sum((n + 1)**(-s), (n, 0, oo)), True))
    assert summation(1/(n+q)**s, (n, 0, oo)) == Piecewise(
        (zeta(s, q), And(q > 0, s > 1)),
        (Sum((n + q)**(-s), (n, 0, oo)), True))
    assert summation(1/(n+q)**s, (n, q, oo)) == Piecewise(
        (zeta(s, 2*q), And(2*q > 0, s > 1)),
        (Sum((n + q)**(-s), (n, q, oo)), True))
    assert summation(1/n**2, (n, 1, oo)) == zeta(2)
    assert summation(1/n**s, (n, 0, oo)) == Sum(n**(-s), (n, 0, oo))
开发者ID:sympy,项目名称:sympy,代码行数:42,代码来源:test_sums_products.py

示例11: test_polylog_expansion

def test_polylog_expansion():
    from sympy import log
    assert polylog(s, 0) == 0
    assert polylog(s, 1) == zeta(s)
    assert polylog(s, -1) == -dirichlet_eta(s)
    assert polylog(s, exp_polar(4*I*pi/3)) == polylog(s, exp(4*I*pi/3))
    assert polylog(s, exp_polar(I*pi)/3) == polylog(s, exp(I*pi)/3)

    assert myexpand(polylog(1, z), -log(1 - z))
    assert myexpand(polylog(0, z), z/(1 - z))
    assert myexpand(polylog(-1, z), z/(1 - z)**2)
    assert ((1-z)**3 * expand_func(polylog(-2, z))).simplify() == z*(1 + z)
    assert myexpand(polylog(-5, z), None)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:13,代码来源:test_zeta_functions.py

示例12: test_lerchphi_expansion

def test_lerchphi_expansion():
    assert myexpand(lerchphi(1, s, a), zeta(s, a))
    assert myexpand(lerchphi(z, s, 1), polylog(s, z) / z)

    # direct summation
    assert myexpand(lerchphi(z, -1, a), a / (1 - z) + z / (1 - z) ** 2)
    assert myexpand(lerchphi(z, -3, a), None)
    # polylog reduction
    assert myexpand(
        lerchphi(z, s, S(1) / 2),
        2 ** (s - 1) * (polylog(s, sqrt(z)) / sqrt(z) - polylog(s, polar_lift(-1) * sqrt(z)) / sqrt(z)),
    )
    assert myexpand(lerchphi(z, s, 2), -1 / z + polylog(s, z) / z ** 2)
    assert myexpand(lerchphi(z, s, S(3) / 2), None)
    assert myexpand(lerchphi(z, s, S(7) / 3), None)
    assert myexpand(lerchphi(z, s, -S(1) / 3), None)
    assert myexpand(lerchphi(z, s, -S(5) / 2), None)

    # hurwitz zeta reduction
    assert myexpand(lerchphi(-1, s, a), 2 ** (-s) * zeta(s, a / 2) - 2 ** (-s) * zeta(s, (a + 1) / 2))
    assert myexpand(lerchphi(I, s, a), None)
    assert myexpand(lerchphi(-I, s, a), None)
    assert myexpand(lerchphi(exp(2 * I * pi / 5), s, a), None)
开发者ID:scopatz,项目名称:sympy,代码行数:23,代码来源:test_zeta_functions.py

示例13: test_hypersum

def test_hypersum():
    from sympy import simplify, sin, hyper
    assert simplify(summation(x**n/fac(n), (n, 1, oo))) == -1 + exp(x)
    assert summation((-1)**n * x**(2*n) / fac(2*n), (n, 0, oo)) == cos(x)
    assert simplify(summation((-1)**n*x**(2*n+1)/factorial(2*n+1),
                              (n, 3, oo))) \
           == -x + sin(x) + x**3/6 - x**5/120

    assert summation(1/(n+2)**3, (n, 1, oo)) == \
           -S(9)/8 + zeta(3)
    assert summation(1/n**4, (n, 1, oo)) == pi**4/90

    s = summation(x**n*n, (n, -oo, 0))
    assert s.is_Piecewise
    assert s.args[0].args[0] == -1/(x*(1 - 1/x)**2)
    assert s.args[0].args[1] == (abs(1/x) < 1)
开发者ID:Anxuiz,项目名称:sympy,代码行数:16,代码来源:test_sums_products.py

示例14: test_rewriting

def test_rewriting():
    assert dirichlet_eta(x).rewrite(zeta) == (1 - 2 ** (1 - x)) * zeta(x)
    assert zeta(x).rewrite(dirichlet_eta) == dirichlet_eta(x) / (1 - 2 ** (1 - x))
    assert tn(dirichlet_eta(x), dirichlet_eta(x).rewrite(zeta), x)
    assert tn(zeta(x), zeta(x).rewrite(dirichlet_eta), x)

    assert zeta(x, a).rewrite(lerchphi) == lerchphi(1, x, a)
    assert polylog(s, z).rewrite(lerchphi) == lerchphi(z, s, 1) * z

    assert lerchphi(1, x, a).rewrite(zeta) == zeta(x, a)
    assert z * lerchphi(z, s, 1).rewrite(polylog) == polylog(s, z)
开发者ID:scopatz,项目名称:sympy,代码行数:11,代码来源:test_zeta_functions.py

示例15: test_hypersum

def test_hypersum():
    from sympy import simplify, sin, hyper
    assert simplify(summation(x**n/fac(n), (n, 1, oo))) == -1 + exp(x)
    assert summation((-1)**n * x**(2*n) / fac(2*n), (n, 0, oo)) == cos(x)
    assert simplify(summation((-1)**n*x**(2*n + 1) /
        factorial(2*n + 1), (n, 3, oo))) == -x + sin(x) + x**3/6 - x**5/120

    assert summation(1/(n + 2)**3, (n, 1, oo)) == -S(9)/8 + zeta(3)
    assert summation(1/n**4, (n, 1, oo)) == pi**4/90

    s = summation(x**n*n, (n, -oo, 0))
    assert s.is_Piecewise
    assert s.args[0].args[0] == -1/(x*(1 - 1/x)**2)
    assert s.args[0].args[1] == (abs(1/x) < 1)

    m = Symbol('n', integer=True, positive=True)
    assert summation(binomial(m, k), (k, 0, m)) == 2**m
开发者ID:Maihj,项目名称:sympy,代码行数:17,代码来源:test_sums_products.py


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