Пример #1
0
def test_assoc_laguerre():
    # generalized Laguerre polynomials:
    assert assoc_laguerre(0, alpha, x) == 1
    assert assoc_laguerre(1, alpha, x) == -x + alpha + 1
    assert assoc_laguerre(2, alpha, x).expand() == \
        (x**2/2 - (alpha + 2)*x + (alpha + 2)*(alpha + 1)/2).expand()
    assert assoc_laguerre(3, alpha, x).expand() == \
        (-x**3/6 + (alpha + 3)*x**2/2 - (alpha + 2)*(alpha + 3)*x/2 +
         (alpha + 1)*(alpha + 2)*(alpha + 3)/6).expand()

    # Test the lowest 10 polynomials with laguerre_poly, to make sure it works:
    for i in range(10):
        assert assoc_laguerre(i, 0, x).expand() == laguerre_poly(i, x)

    X = assoc_laguerre(n, m, x)
    assert isinstance(X, assoc_laguerre)

    assert assoc_laguerre(n, 0, x) == laguerre(n, x)
    assert assoc_laguerre(n, alpha, 0) == binomial(alpha + n, alpha)

    p = Symbol('p', positive=True)
    assert assoc_laguerre(p, alpha, oo) == (-1)**p*oo
    assert assoc_laguerre(p, alpha, -oo) == oo

    assert diff(assoc_laguerre(n, alpha, x), x) == \
        -assoc_laguerre(n - 1, alpha + 1, x)

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

    assert conjugate(assoc_laguerre(n, alpha, x)) == \
        assoc_laguerre(n, conjugate(alpha), conjugate(x))

    pytest.raises(ValueError, lambda: assoc_laguerre(-2.1, alpha, x))

    # issue sympy/sympy#10961
    X = assoc_laguerre(Rational(5, 2), alpha, x)
    assert isinstance(X, assoc_laguerre)

    assert (diff(assoc_laguerre(n, alpha, x), alpha) ==
            Sum(assoc_laguerre(k, alpha, x)/(-alpha + n), (k, 0, n - 1)))
Пример #2
0
def test_assoc_laguerre():
    # generalized Laguerre polynomials:
    assert assoc_laguerre(0, alpha, x) == 1
    assert assoc_laguerre(1, alpha, x) == -x + alpha + 1
    assert assoc_laguerre(2, alpha, x).expand() == \
        (x**2/2 - (alpha + 2)*x + (alpha + 2)*(alpha + 1)/2).expand()
    assert assoc_laguerre(3, alpha, x).expand() == \
        (-x**3/6 + (alpha + 3)*x**2/2 - (alpha + 2)*(alpha + 3)*x/2 +
         (alpha + 1)*(alpha + 2)*(alpha + 3)/6).expand()

    # Test the lowest 10 polynomials with laguerre_poly, to make sure it works:
    for i in range(10):
        assert assoc_laguerre(i, 0, x).expand() == laguerre_poly(i, x)

    X = assoc_laguerre(n, m, x)
    assert isinstance(X, assoc_laguerre)

    assert assoc_laguerre(n, 0, x) == laguerre(n, x)
    assert assoc_laguerre(n, alpha, 0) == binomial(alpha + n, alpha)

    p = Symbol('p', positive=True)
    assert assoc_laguerre(p, alpha, oo) == (-1)**p*oo
    assert assoc_laguerre(p, alpha, -oo) == oo

    assert diff(assoc_laguerre(n, alpha, x), x) == \
        -assoc_laguerre(n - 1, alpha + 1, x)

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

    assert conjugate(assoc_laguerre(n, alpha, x)) == \
        assoc_laguerre(n, conjugate(alpha), conjugate(x))

    pytest.raises(ValueError, lambda: assoc_laguerre(-2.1, alpha, x))

    # issue sympy/sympy#10961
    X = assoc_laguerre(Rational(5, 2), alpha, x)
    assert isinstance(X, assoc_laguerre)
Пример #3
0
def test_laguerre_poly():
    pytest.raises(ValueError, lambda: laguerre_poly(-1, x))

    assert laguerre_poly(1, x, polys=True) == (-x + 1).as_poly()

    assert laguerre_poly(0, x) == 1
    assert laguerre_poly(1, x) == -x + 1
    assert laguerre_poly(2, x) == x**2 / 2 - 2 * x + 1
    assert laguerre_poly(3, x) == -x**3 / 6 + 3 * x**2 / 2 - 3 * x + 1
    assert laguerre_poly(4,
                         x) == x**4 / 24 - 2 * x**3 / 3 + 3 * x**2 - 4 * x + 1
    assert laguerre_poly(5, x) == (-x**5 / 120 + 5 * x**4 / 24 - 5 * x**3 / 3 +
                                   5 * x**2 - 5 * x + 1)
    assert laguerre_poly(6, x) == (x**6 / 720 - x**5 / 20 + 5 * x**4 / 8 -
                                   10 * x**3 / 3 + 15 * x**2 / 2 - 6 * x + 1)

    assert laguerre_poly(0, x, a) == 1
    assert laguerre_poly(1, x, a) == -x + a + 1
    assert laguerre_poly(
        2, x, a) == x**2 / 2 + (-a - 2) * x + a**2 / 2 + 3 * a / 2 + 1
    assert laguerre_poly(3, x,
                         a) == (-x**3 / 6 + (a / 2 + Rational(3, 2)) * x**2 +
                                (-a**2 / 2 - 5 * a / 2 - 3) * x + a**3 / 6 +
                                a**2 + 11 * a / 6 + 1)

    assert laguerre_poly(1, x) == 1 - x
    assert laguerre_poly(1, polys=True) == (-x + 1).as_poly()