Exemple #1
0
def test_to_Sequence_Initial_Coniditons():
    x = symbols('x')
    R, Dx = DifferentialOperators(QQ.old_poly_ring(x), 'Dx')
    n = symbols('n', integer=True)
    _, Sn = RecurrenceOperators(QQ.old_poly_ring(n), 'Sn')
    p = HolonomicFunction(Dx - 1, x, 0, 1).to_sequence()
    q = [(HolonomicSequence(-1 + (n + 1) * Sn, 1), 0)]
    assert p == q
    p = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).to_sequence()
    q = [(HolonomicSequence(1 + (n**2 + 3 * n + 2) * Sn**2, [0, 1]), 0)]
    assert p == q
    p = HolonomicFunction(Dx**2 + 1 + x**3 * Dx, x, 0, [2, 3]).to_sequence()
    q = [(HolonomicSequence(n + Sn**2 + (n**2 + 7 * n + 12) * Sn**4,
                            [2, 3, -1, -1 / 2, 1 / 12]), 1)]
    assert p == q
    p = HolonomicFunction(x**3 * Dx**5 + 1 + Dx, x).to_sequence()
    q = [(HolonomicSequence(1 + (n + 1) * Sn +
                            (n**5 - 5 * n**3 + 4 * n) * Sn**2), 0, 3)]
    assert p == q
    C_0, C_1, C_2, C_3 = symbols('C_0, C_1, C_2, C_3')
    p = expr_to_holonomic(log(1 + x**2))
    q = [(HolonomicSequence(n**2 + (n**2 + 2 * n) * Sn**2, [0, 0, C_2]), 0, 1)]
    assert p.to_sequence() == q
    p = p.diff()
    q = [(HolonomicSequence((n + 2) + (n + 2) * Sn**2, [C_0, 0]), 1, 0)]
    assert p.to_sequence() == q
    p = expr_to_holonomic(erf(x) + x).to_sequence()
    q = [(HolonomicSequence(
        (2 * n**2 - 2 * n) + (n**3 + 2 * n**2 - n - 2) * Sn**2,
        [0, 1 + 2 / sqrt(pi), 0, C_3]), 0, 2)]
    assert p == q
Exemple #2
0
def test_to_Sequence():
    x = symbols('x')
    R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx')
    n = symbols('n', integer=True)
    _, Sn = RecurrenceOperators(ZZ.old_poly_ring(n), 'Sn')
    p = HolonomicFunction(x**2 * Dx**4 + x + Dx, x).to_sequence()
    q = [(HolonomicSequence(1 + (n + 2) * Sn**2 +
                            (n**4 + 6 * n**3 + 11 * n**2 + 6 * n) * Sn**3), 0,
          1)]
    assert p == q
    p = HolonomicFunction(x**2 * Dx**4 + x**3 + Dx**2, x).to_sequence()
    q = [
        (HolonomicSequence(1 + (n**4 + 14 * n**3 + 72 * n**2 + 163 * n + 140) *
                           Sn**5), 0, 0)
    ]
    assert p == q
    p = HolonomicFunction(x**3 * Dx**4 + 1 + Dx**2, x).to_sequence()
    q = [(HolonomicSequence(1 + (n**4 - 2 * n**3 - n**2 + 2 * n) * Sn +
                            (n**2 + 3 * n + 2) * Sn**2), 0, 0)]
    assert p == q
    p = HolonomicFunction(3 * x**3 * Dx**4 + 2 * x * Dx + x * Dx**3,
                          x).to_sequence()
    q = [(HolonomicSequence(2 * n +
                            (3 * n**4 - 6 * n**3 - 3 * n**2 + 6 * n) * Sn +
                            (n**3 + 3 * n**2 + 2 * n) * Sn**2), 0, 1)]
    assert p == q
Exemple #3
0
def test_RecurrenceOperator():
    n = symbols('n', integer=True)
    R, Sn = RecurrenceOperators(QQ.old_poly_ring(n), 'Sn')
    assert Sn * n == (n + 1) * Sn
    assert Sn * n**2 == (n**2 + 1 + 2 * n) * Sn
    assert Sn**2 * n**2 == (n**2 + 4 * n + 4) * Sn**2
    p = (Sn**3 * n**2 + Sn * n)**2
    q = (n**2 + 3*n + 2)*Sn**2 + (2*n**3 + 19*n**2 + 57*n + 52)*Sn**4 + (n**4 + 18*n**3 + \
        117*n**2 + 324*n + 324)*Sn**6
    assert p == q
Exemple #4
0
def test_RecurrenceOperatorEqPoly():
    n = symbols('n', integer=True)
    R, Sn = RecurrenceOperators(QQ.old_poly_ring(n), 'Sn')
    rr = RecurrenceOperator([n**2, 0, 0], R)
    rr2 = RecurrenceOperator([n**2, 1, n], R)
    assert not rr == rr2

    # polynomial comparison issue, see https://github.com/sympy/sympy/pull/15799
    # should work once that is solved
    # d = rr.listofpoly[0]
    # assert rr == d

    d2 = rr2.listofpoly[0]
    assert not rr2 == d2
Exemple #5
0
def test_to_Sequence_Initial_Coniditons():
    x = symbols('x')
    R, Dx = DifferentialOperators(QQ.old_poly_ring(x), 'Dx')
    n = symbols('n', integer=True)
    _, Sn = RecurrenceOperators(QQ.old_poly_ring(n), 'Sn')
    p = HolonomicFunction(Dx - 1, x, 0, 1).to_sequence()
    q = HolonomicSequence(-1 + (n + 1)*Sn, 1)
    assert p == q
    p = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).to_sequence()
    q = HolonomicSequence(1 + (n**2 + 3*n + 2)*Sn**2, [0, 1])
    assert p == q
    p = HolonomicFunction(Dx**2 + 1 + x**3*Dx, x, 0, [2, 3]).to_sequence()
    q = HolonomicSequence(n + Sn**2 + (n**2 + 7*n + 12)*Sn**4, [2, 3, -1, -1/2])
    assert p == q
    p = HolonomicFunction(x**3*Dx**5 + 1 + Dx, x).to_sequence()
    q = HolonomicSequence(1 + (n + 1)*Sn + (n**5 - 5*n**3 + 4*n)*Sn**2)
    assert p == q