Exemplo n.º 1
0
def test_jacobi():
    assert jacobi(0, a, b, x) == 1
    assert jacobi(1, a, b, x) == a / 2 - b / 2 + x * (a / 2 + b / 2 + 1)
    assert (jacobi(2, a, b, x) == a**2 / 8 - a * b / 4 - a / 8 + b**2 / 8 -
            b / 8 + x**2 * (a**2 / 8 + a * b / 4 + 7 * a / 8 + b**2 / 8 +
                            7 * b / 8 + Rational(3, 2)) + x *
            (a**2 / 4 + 3 * a / 4 - b**2 / 4 - 3 * b / 4) - S.Half)

    assert jacobi(n, a, a, x) == RisingFactorial(a + 1, n) * gegenbauer(
        n, a + Rational(1, 2), x) / RisingFactorial(2 * a + 1, n)
    assert jacobi(n, a, -a,
                  x) == ((-1)**a * (-x + 1)**(-a / 2) * (x + 1)**(a / 2) *
                         assoc_legendre(n, a, x) * factorial(-a + n) *
                         gamma(a + n + 1) / (factorial(a + n) * gamma(n + 1)))
    assert jacobi(n, -b, b, x) == ((-x + 1)**(b / 2) * (x + 1)**(-b / 2) *
                                   assoc_legendre(n, b, x) *
                                   gamma(-b + n + 1) / gamma(n + 1))
    assert jacobi(n, 0, 0, x) == legendre(n, x)
    assert jacobi(n, S.Half, S.Half, x) == RisingFactorial(Rational(
        3, 2), n) * chebyshevu(n, x) / factorial(n + 1)
    assert jacobi(n, -S.Half, -S.Half, x) == RisingFactorial(
        Rational(1, 2), n) * chebyshevt(n, x) / factorial(n)

    X = jacobi(n, a, b, x)
    assert isinstance(X, jacobi)

    assert jacobi(n, a, b, -x) == (-1)**n * jacobi(n, b, a, x)
    assert jacobi(n, a, b, 0) == 2**(-n) * gamma(a + n + 1) * hyper(
        (-b - n, -n), (a + 1, ), -1) / (factorial(n) * gamma(a + 1))
    assert jacobi(n, a, b, 1) == RisingFactorial(a + 1, n) / factorial(n)

    m = Symbol("m", positive=True)
    assert jacobi(m, a, b, oo) == oo * RisingFactorial(a + b + m + 1, m)

    assert conjugate(jacobi(m, a, b, x)) == \
        jacobi(m, conjugate(a), conjugate(b), conjugate(x))

    assert diff(jacobi(n, a, b, x), n) == Derivative(jacobi(n, a, b, x), n)
    assert diff(jacobi(n, a, b, x), x) == \
        (a/2 + b/2 + n/2 + Rational(1, 2))*jacobi(n - 1, a + 1, b + 1, x)

    # XXX see issue sympy/sympy#5539
    assert str(jacobi(n, a, b, x).diff(a)) == \
        ("Sum((jacobi(n, a, b, x) + (a + b + 2*_k + 1)*RisingFactorial(b + "
         "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + "
         "b + _k + 1, n - _k)))/(a + b + n + _k + 1), (_k, 0, n - 1))")
    assert str(jacobi(n, a, b, x).diff(b)) == \
        ("Sum(((-1)**(n - _k)*(a + b + 2*_k + 1)*RisingFactorial(a + "
         "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + "
         "b + _k + 1, n - _k)) + jacobi(n, a, b, x))/(a + b + n + "
         "_k + 1), (_k, 0, n - 1))")

    assert jacobi_normalized(n, a, b, x) == \
           (jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)
                                    / ((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1))))

    pytest.raises(ValueError, lambda: jacobi(-2.1, a, b, x))
    pytest.raises(ValueError,
                  lambda: jacobi(Dummy(positive=True, integer=True), 1, 2, oo))
    pytest.raises(ArgumentIndexError, lambda: jacobi(n, a, b, x).fdiff(5))
Exemplo n.º 2
0
def test_jacobi():
    assert jacobi(0, a, b, x) == 1
    assert jacobi(1, a, b, x) == a/2 - b/2 + x*(a/2 + b/2 + 1)
    assert (jacobi(2, a, b, x) == a**2/8 - a*b/4 - a/8 + b**2/8 - b/8 +
            x**2*(a**2/8 + a*b/4 + 7*a/8 + b**2/8 + 7*b/8 + Rational(3, 2)) +
            x*(a**2/4 + 3*a/4 - b**2/4 - 3*b/4) - Rational(1, 2))

    assert jacobi(n, a, a, x) == RisingFactorial(
        a + 1, n)*gegenbauer(n, a + Rational(1, 2), x)/RisingFactorial(2*a + 1, n)
    assert jacobi(n, a, -a, x) == ((-1)**a*(-x + 1)**(-a/2)*(x + 1)**(a/2)*assoc_legendre(n, a, x) *
                                   factorial(-a + n)*gamma(a + n + 1)/(factorial(a + n)*gamma(n + 1)))
    assert jacobi(n, -b, b, x) == ((-x + 1)**(b/2)*(x + 1)**(-b/2)*assoc_legendre(n, b, x) *
                                   gamma(-b + n + 1)/gamma(n + 1))
    assert jacobi(n, 0, 0, x) == legendre(n, x)
    assert jacobi(n, Rational(1, 2), Rational(1, 2), x) == RisingFactorial(
        Rational(3, 2), n)*chebyshevu(n, x)/factorial(n + 1)
    assert jacobi(n, Rational(-1, 2), Rational(-1, 2), x) == RisingFactorial(
        Rational(1, 2), n)*chebyshevt(n, x)/factorial(n)

    X = jacobi(n, a, b, x)
    assert isinstance(X, jacobi)

    assert jacobi(n, a, b, -x) == (-1)**n*jacobi(n, b, a, x)
    assert jacobi(n, a, b, 0) == 2**(-n)*gamma(a + n + 1)*hyper(
        (-b - n, -n), (a + 1,), -1)/(factorial(n)*gamma(a + 1))
    assert jacobi(n, a, b, 1) == RisingFactorial(a + 1, n)/factorial(n)

    m = Symbol("m", positive=True)
    assert jacobi(m, a, b, oo) == oo*RisingFactorial(a + b + m + 1, m)
    assert jacobi(n, a, b, oo) == jacobi(n, a, b, oo, evaluate=False)

    assert conjugate(jacobi(m, a, b, x)) == \
        jacobi(m, conjugate(a), conjugate(b), conjugate(x))

    assert diff(jacobi(n, a, b, x), n) == Derivative(jacobi(n, a, b, x), n)
    assert diff(jacobi(n, a, b, x), x) == \
        (a/2 + b/2 + n/2 + Rational(1, 2))*jacobi(n - 1, a + 1, b + 1, x)

    # XXX see issue sympy/sympy#5539
    assert str(jacobi(n, a, b, x).diff(a)) == \
        ("Sum((jacobi(n, a, b, x) + (a + b + 2*_k + 1)*RisingFactorial(b + "
         "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + "
         "b + _k + 1, n - _k)))/(a + b + n + _k + 1), (_k, 0, n - 1))")
    assert str(jacobi(n, a, b, x).diff(b)) == \
        ("Sum(((-1)**(n - _k)*(a + b + 2*_k + 1)*RisingFactorial(a + "
         "_k + 1, n - _k)*jacobi(_k, a, b, x)/((n - _k)*RisingFactorial(a + "
         "b + _k + 1, n - _k)) + jacobi(n, a, b, x))/(a + b + n + "
         "_k + 1), (_k, 0, n - 1))")

    assert jacobi_normalized(n, a, b, x) == \
        (jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)
                                 / ((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1))))

    pytest.raises(ValueError, lambda: jacobi(-2.1, a, b, x))
    pytest.raises(ValueError, lambda: jacobi(Dummy(positive=True, integer=True), 1, 2, oo))
    pytest.raises(ArgumentIndexError, lambda: jacobi(n, a, b, x).fdiff(5))
Exemplo n.º 3
0
def test_chebyshev():
    assert chebyshevt(0, x) == 1
    assert chebyshevt(1, x) == x
    assert chebyshevt(2, x) == 2 * x**2 - 1
    assert chebyshevt(3, x) == 4 * x**3 - 3 * x

    for n in range(1, 4):
        for k in range(n):
            z = chebyshevt_root(n, k)
            assert chebyshevt(n, z) == 0
        pytest.raises(ValueError, lambda: chebyshevt_root(n, n))

    for n in range(1, 4):
        for k in range(n):
            z = chebyshevu_root(n, k)
            assert chebyshevu(n, z) == 0
        pytest.raises(ValueError, lambda: chebyshevu_root(n, n))

    n = Symbol("n")
    X = chebyshevt(n, x)
    assert isinstance(X, chebyshevt)
    assert chebyshevt(n, -x) == (-1)**n * chebyshevt(n, x)
    assert chebyshevt(-n, x) == chebyshevt(n, x)

    assert chebyshevt(n, oo) == oo
    assert chebyshevt(n, 0) == cos(pi * n / 2)
    assert chebyshevt(n, 1) == 1

    assert conjugate(chebyshevt(n, x)) == chebyshevt(n, conjugate(x))

    assert diff(chebyshevt(n, x), x) == n * chebyshevu(n - 1, x)

    pytest.raises(ArgumentIndexError, lambda: chebyshevt(n, x).fdiff(1))

    X = chebyshevu(n, x)
    assert isinstance(X, chebyshevu)

    assert chebyshevu(n, -x) == (-1)**n * chebyshevu(n, x)
    assert chebyshevu(-n, x) == -chebyshevu(n - 2, x)

    assert chebyshevu(n, oo) == oo
    assert chebyshevu(n, 0) == cos(pi * n / 2)
    assert chebyshevu(n, 1) == n + 1

    assert conjugate(chebyshevu(n, x)) == chebyshevu(n, conjugate(x))

    assert diff(chebyshevu(n, x), x) == \
        (-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1)

    pytest.raises(ArgumentIndexError, lambda: chebyshevu(n, x).fdiff(1))
Exemplo n.º 4
0
def test_chebyshev():
    assert chebyshevt(0, x) == 1
    assert chebyshevt(1, x) == x
    assert chebyshevt(2, x) == 2*x**2 - 1
    assert chebyshevt(3, x) == 4*x**3 - 3*x
    assert chebyshevt(-2, x) == 2*x**2 - 1

    for n in range(1, 4):
        for k in range(n):
            z = chebyshevt_root(n, k)
            assert chebyshevt(n, z) == 0
        pytest.raises(ValueError, lambda: chebyshevt_root(n, n))

    for n in range(1, 4):
        for k in range(n):
            z = chebyshevu_root(n, k)
            assert chebyshevu(n, z) == 0
        pytest.raises(ValueError, lambda: chebyshevu_root(n, n))

    n = Symbol("n")
    X = chebyshevt(n, x)
    assert isinstance(X, chebyshevt)
    assert chebyshevt(n, -x) == (-1)**n*chebyshevt(n, x)
    assert chebyshevt(-n, x) == chebyshevt(n, x)

    assert chebyshevt(n, oo) == oo
    assert chebyshevt(n, 0) == cos(pi*n/2)
    assert chebyshevt(n, 1) == 1

    assert conjugate(chebyshevt(n, x)) == chebyshevt(n, conjugate(x))

    assert diff(chebyshevt(n, x), x) == n*chebyshevu(n - 1, x)

    pytest.raises(ArgumentIndexError, lambda: chebyshevt(n, x).fdiff(1))

    X = chebyshevu(n, x)
    assert isinstance(X, chebyshevu)

    assert chebyshevu(n, -x) == (-1)**n*chebyshevu(n, x)
    assert chebyshevu(-n, x) == -chebyshevu(n - 2, x)

    assert chebyshevu(n, oo) == oo
    assert chebyshevu(n, 0) == cos(pi*n/2)
    assert chebyshevu(n, 1) == n + 1
    assert chebyshevu(-1, x) == 0
    assert chebyshevu(-2, x) == -1

    assert conjugate(chebyshevu(n, x)) == chebyshevu(n, conjugate(x))

    assert diff(chebyshevu(n, x), x) == \
        (-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1)

    pytest.raises(ArgumentIndexError, lambda: chebyshevu(n, x).fdiff(1))