Example #1
0
def test_genocchi():
    genocchis = [1, -1, 0, 1, 0, -3, 0, 17]
    for n, g in enumerate(genocchis):
        assert genocchi(n + 1) == g

    assert genocchi(Symbol('z', zero=True) + 1) == 1
    pytest.raises(ValueError, lambda: genocchi(Rational(1, 2)))

    m = Symbol('m', integer=True)
    n = Symbol('n', integer=True, positive=True)

    assert genocchi(2 * n + 1) == 0
    assert genocchi(m) == genocchi(m)
    assert genocchi(n).rewrite(bernoulli) == 2 * (1 - 2**n) * bernoulli(n)
    assert genocchi(x).rewrite(bernoulli) == genocchi(x)

    assert genocchi(2 * n).is_odd
    assert genocchi(2 * n + 1, evaluate=False).is_odd is None
    assert genocchi(4 * n).is_positive
    # This should work for 4 * n - 2, but fails due to some variation of issue
    # 8632 ((4*n-2).is_positive returns None)
    assert genocchi(4 * n + 2).is_negative
    assert genocchi(2 * n + 1, evaluate=False).is_negative is None

    assert genocchi(m).is_odd is None
    assert genocchi(m).is_negative is None
Example #2
0
def test_evalf_bernoulli():
    pytest.raises(ValueError, lambda: bernoulli(0.5, evaluate=False).evalf())

    assert bernoulli(3, evaluate=False).evalf() == 0
Example #3
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.numerator % 10**10 == 7950421099
    assert b.denominator == 342999030

    b = bernoulli(10**6, evaluate=False).evalf()
    assert str(b) == '-2.23799235765713e+4767529'

    # Issue sympy/sympy#8527
    l = Symbol('l', integer=True)
    m = Symbol('m', integer=True, nonnegative=True)
    n = Symbol('n', integer=True, positive=True)
    assert isinstance(bernoulli(2 * l + 1), bernoulli)
    assert isinstance(bernoulli(2 * m + 1), bernoulli)
    assert bernoulli(2 * n + 1) == 0

    pytest.raises(ValueError, lambda: bernoulli(-20))
    assert isinstance(bernoulli(l, x), bernoulli)
Example #4
0
def test_evalf_bernoulli():
    pytest.raises(ValueError, lambda: bernoulli(0.5, evaluate=False).evalf())

    assert bernoulli(3, evaluate=False).evalf() == 0