Inconsistent formulas when solving recurrent equations using sympy.rsolve_poly

39 Views Asked by At

I am getting inconsistent formulas when using sympy.rsolve_poly to solve recurrent equations.

This first piece of code solves $a(n+1) = a(n) + 4n^3$ with $a(0) = 0$

from sympy import rsolve_poly, symbols
n = symbols('n',integer=True)
formula = rsolve_poly([-1, 1], 4*n**3, n)
print(formula)
# output:
# C0 + n**4 - 2*n**3 + n**2

This formula correctly calculates:

a(0)=0
a(1)=0
a(2)=4
a(3)=36
a(4)=144

However, when adding a little change: $a(n+1) = 2a(n) + 4n^3$ with $a(0) = 0$ with the following code to get the formula:

from sympy import rsolve_poly, symbols
n = symbols('n',integer=True)
formula = rsolve_poly([-2, 1], 4*n**3, n)
print(formula)
# output:
# -4*n**3 - 12*n**2 - 36*n - 52

This is completely wrong. I have been struggling to figure it out to no avail.