Example #1
0
    def taylor_term(n, x, *previous_terms):
        from sympy import bernoulli
        if n == 0:
            return 1 / sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            B = bernoulli(n + 1)
            F = factorial(n + 1)

            return 2**(n + 1) * B / F * x**n
Example #2
0
    def taylor_term(n, x, *previous_terms):
        from sympy import bernoulli
        if n == 0:
            return 1 / sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            B = bernoulli(n + 1)
            F = factorial(n + 1)

            return 2**(n + 1) * B/F * x**n
Example #3
0
    def taylor_term(n, x, *previous_terms):
        """
        Returns the next term in the Taylor series expansion
        """
        from sympy import bernoulli
        if n == 0:
            return 1 / sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            B = bernoulli(n + 1)
            F = factorial(n + 1)

            return 2 * (1 - 2**n) * B / F * x**n
Example #4
0
    def taylor_term(n, x, *previous_terms):
        """
        Returns the next term in the Taylor series expansion
        """
        from sympy import bernoulli
        if n == 0:
            return 1/sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            B = bernoulli(n + 1)
            F = factorial(n + 1)

            return 2 * (1 - 2**n) * B/F * x**n
Example #5
0
def gammaln_asymptotic_coefficient(k):
    return bernoulli(2 * k + 2) / (2 * (k + 1) * (2 * k + 1))
Example #6
0
def tetragamma_asymptotic_coefficient(k):
    if k == 0:
        return S(0)
    return -(2 * k - 1) * bernoulli(2 * k - 2)
Example #7
0
def trigamma_asymptotic_coefficient(k):
    if k == 0:
        return S(0)
    return bernoulli(2 * k)
Example #8
0
def test_bernoulli():
    assert bernoulli(0) == 1
    assert bernoulli(1) == Rational(-1, 2)
    assert bernoulli(2) == Rational(1, 6)
    assert bernoulli(3) == 0
    assert bernoulli(4) == Rational(-1, 30)
    assert bernoulli(5) == 0
    assert bernoulli(6) == Rational(1, 42)
    assert bernoulli(7) == 0
    assert bernoulli(8) == Rational(-1, 30)
    assert bernoulli(10) == Rational(5, 66)
    assert bernoulli(1000001) == 0

    assert bernoulli(0, x) == 1
    assert bernoulli(1, x) == x - Rational(1, 2)
    assert bernoulli(2, x) == x**2 - x + Rational(1, 6)
    assert bernoulli(3, x) == x**3 - (3*x**2)/2 + x/2

    # Should be fast; computed with mpmath
    b = bernoulli(1000)
    assert b.p % 10**10 == 7950421099
    assert b.q == 342999030

    b = bernoulli(10**6, evaluate=False).evalf()
    assert str(b) == '-2.23799235765713e+4767529'
Example #9
0
def test_bernoulli():
    assert bernoulli(0) == 1
    assert bernoulli(1) == Rational(-1, 2)
    assert bernoulli(2) == Rational(1, 6)
    assert bernoulli(3) == 0
    assert bernoulli(4) == Rational(-1, 30)
    assert bernoulli(5) == 0
    assert bernoulli(6) == Rational(1, 42)
    assert bernoulli(7) == 0
    assert bernoulli(8) == Rational(-1, 30)
    assert bernoulli(10) == Rational(5, 66)
    assert bernoulli(1000001) == 0

    assert bernoulli(0, x) == 1
    assert bernoulli(1, x) == x - Rational(1, 2)
    assert bernoulli(2, x) == x**2 - x + Rational(1, 6)
    assert bernoulli(3, x) == x**3 - (3 * x**2) / 2 + x / 2

    # Should be fast; computed with mpmath
    b = bernoulli(1000)
    assert b.p % 10**10 == 7950421099
    assert b.q == 342999030

    b = bernoulli(10**6, evaluate=False).evalf()
    assert str(b) == '-2.23799235765713e+4767529'
Example #10
0
def test_J1():
    assert bernoulli(16) == R(-3617, 510)
Example #11
0
def digamma_asymptotic_coefficient(k):
    if k == 0:
        return 0.0
    return bernoulli(2 * k) / (2 * k)
Example #12
0
def test_J1():
    assert bernoulli(16) == R(-3617, 510)
Example #13
0
t1 = edka.subs(sympy.besselk(2, k / t), sympy.Symbol('b2'))
t2 = t1.subs(sympy.besselk(3, k / t), sympy.Symbol('b3'))
print('edka = ' + str(sympy.simplify(t2).collect('b2')))
print('')

print('------------------------------------------------------')
print('Degenerate expansion')
print('')

z = sympy.Symbol('z', positive=True)
x = sympy.Symbol('x', positive=True)
pi = sympy.Symbol('pi', positive=True)
t = sympy.Symbol('t')
fz = (z * (2 + z))**(sympy.Rational(3, 2)) / 3

fz1 = sympy.diff(fz, z) * pi**2 * t**2 / 6
print(1, sympy.simplify(fz1.subs(z, x)))
print('')

fzt = fz1
for i in range(0, 6):
    fzt = sympy.diff(fzt, z)
    fzt = sympy.diff(fzt, z)
    n = sympy.Rational(i + 2, 1)
    term = (fzt.subs(z, x) * pi**(2 * n) * t**(2 * n) *
            sympy.bernoulli(2 * n) * 2 * (2**(2 * n - 1) - 1) /
            sympy.factorial(2 * n))
    term = sympy.simplify(term)
    print(i + 2, term)
    print('')
Example #14
0
#! /bin/python
from sympy import N, bernoulli, binomial

n = int(input())

for i in range(0, n + 1):
    print(N(pow(-1, i) * bernoulli(i) * binomial(n + 1, i) / (n + 1)))