Пример #1
0
def test_sympyissue_8601():
    n = Symbol('n', integer=True, negative=True)

    assert catalan(n - 1) == 0
    assert catalan(Rational(-1, 2)) == zoo
    assert catalan(-1) == Rational(-1, 2)
    c1 = catalan(-5.6).evalf(strict=False)
    assert str(c1) == '6.93334070531408e-5'
    c2 = catalan(-35.4).evalf(strict=False)
    assert str(c2) == '-4.14189164517449e-24'
Пример #2
0
def test_issue_8601():
    n = Symbol('n', integer=True, negative=True)

    assert catalan(n - 1) == S.Zero
    assert catalan(-S.Half) == S.ComplexInfinity
    assert catalan(-S.One) == -S.Half
    c1 = catalan(-5.6).evalf()
    assert str(c1) == '6.93334070531408e-5'
    c2 = catalan(-35.4).evalf()
    assert str(c2) == '-4.14189164517449e-24'
Пример #3
0
def test_sympyissue_8601():
    n = Symbol('n', integer=True, negative=True)

    assert catalan(n - 1) == 0
    assert catalan(Rational(-1, 2)) == zoo
    assert catalan(-1) == Rational(-1, 2)
    c1 = catalan(-5.6).evalf(strict=False)
    assert str(c1) == '6.93334070531408e-5'
    c2 = catalan(-35.4).evalf(strict=False)
    assert str(c2) == '-4.14189164517449e-24'
Пример #4
0
def test_issue_8496():
    n = Symbol("n")
    k = Symbol("k")

    pytest.raises(TypeError, lambda: catalan(n, k))
    pytest.raises(TypeError, lambda: euler(n, k))
Пример #5
0
def test_catalan():
    n = Symbol('n', integer=True)
    m = Symbol('n', integer=True, positive=True)

    catalans = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786]
    for i, c in enumerate(catalans):
        assert catalan(i) == c
        assert catalan(n).rewrite(factorial).subs(n, i) == c
        assert catalan(n).rewrite(Product).subs(n, i).doit() == c

    assert catalan(x) == catalan(x)
    assert catalan(2 *
                   x).rewrite(binomial) == binomial(4 * x, 2 * x) / (2 * x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8 / (3 * pi)
    assert catalan(Rational(1, 2)).rewrite(factorial).rewrite(gamma) ==\
        8 / (3 * pi)
    assert catalan(3 * x).rewrite(gamma) == 4**(
        3 * x) * gamma(3 * x + Rational(1, 2)) / (sqrt(pi) * gamma(3 * x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2, ), 1)

    assert catalan(n).rewrite(factorial) == factorial(
        2 * n) / (factorial(n + 1) * factorial(n))
    assert isinstance(catalan(n).rewrite(Product), catalan)
    assert isinstance(catalan(m).rewrite(Product), Product)

    assert diff(catalan(x), x) == (polygamma(0, x + Rational(1, 2)) -
                                   polygamma(0, x + 2) + log(4)) * catalan(x)

    assert catalan(x).evalf() == catalan(x)
    c = catalan(S.Half).evalf()
    assert str(c) == '0.848826363156775'
    c = catalan(I).evalf(3)
    assert sstr((re(c), im(c))) == '(0.398, -0.0209)'
Пример #6
0
def test_sympyissue_8496():
    n = Symbol("n")
    k = Symbol("k")

    pytest.raises(TypeError, lambda: catalan(n, k))
    pytest.raises(TypeError, lambda: euler(n, k))
Пример #7
0
def test_catalan():
    n = Symbol('n', integer=True)
    m = Symbol('n', integer=True, positive=True)

    catalans = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786]
    for i, c in enumerate(catalans):
        assert catalan(i) == c
        assert catalan(n).rewrite(factorial).subs({n: i}) == c
        assert catalan(n).rewrite(Product).subs({n: i}).doit() == c

    assert catalan(x) == catalan(x)
    assert catalan(2*x).rewrite(binomial) == binomial(4*x, 2*x)/(2*x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8/(3*pi)
    assert catalan(Rational(1, 2)).rewrite(factorial).rewrite(gamma) ==\
        8 / (3 * pi)
    assert catalan(3*x).rewrite(gamma) == 4**(
        3*x)*gamma(3*x + Rational(1, 2))/(sqrt(pi)*gamma(3*x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2,), 1)

    assert catalan(n).rewrite(factorial) == factorial(2*n) / (factorial(n + 1)
                                                              * factorial(n))
    assert isinstance(catalan(n).rewrite(Product), catalan)
    assert isinstance(catalan(m).rewrite(Product), Product)

    assert diff(catalan(x), x) == (polygamma(
        0, x + Rational(1, 2)) - polygamma(0, x + 2) + log(4))*catalan(x)

    assert catalan(x).evalf() == catalan(x)
    c = catalan(Rational(1, 2)).evalf()
    assert str(c) == '0.848826363156775'
    c = catalan(I).evalf(3)
    assert sstr((re(c), im(c))) == '(0.398, -0.0209)'