Casting symbolic fractions to fraction field of polynomial ring?
This is a follow-up to question 25305 which was a follow-up to question 25285. Please consider:
from sage.calculus.calculus import symbolic_sum
x, j = SR.var('x, j')
assume(x>0)
M = [1, j, j^2 + 1, j^3 + 3*j, j^4 + 6*j^2 + 2]
MS = []
for m in M:
p = symbolic_sum(x^j*m, j, 0, oo)
MS.append(p)
print MS
x = polygen(QQ)
M = [-1/(x - 1), x/(x^2 - 2*x + 1), -(2*x^2 - x + 1)/(x^3 - 3*x^2 + 3*x - 1),
2*(2*x^3 - x^2 + 2*x)/(x^4 - 4*x^3 + 6*x^2 - 4*x + 1),
-(9*x^4 - 3*x^3 + 17*x^2 - x + 2)/(x^5 - 5*x^4 + 10*x^3 - 10*x^2 + 5*x - 1)]
print M
for k, m in enumerate(M):
F = m.partial_fraction_decomposition()
print [F[1][j].numerator() for j in (0..k)]
which gives the output
[-1/(x - 1), x/(x^2 - 2*x + 1), -(2*x^2 - x + 1)/(x^3 - 3*x^2 + 3*x - 1), 2*(2*x^3 - x^2 + 2*x)/(x^4 - 4*x^3 + 6*x^2 - 4*x + 1), -(9*x^4 - 3*x^3 + 17*x^2 - x + 2)/(x^5 - 5*x^4 + 10*x^3 - 10*x^2 + 5*x - 1)]
[-1/(x - 1), x/(x^2 - 2*x + 1), (-2*x^2 + x - 1)/(x^3 - 3*x^2 + 3*x - 1), (4*x^3 - 2*x^2 + 4*x)/(x^4 - 4*x^3 + 6*x^2 - 4*x + 1), (-9*x^4 + 3*x^3 - 17*x^2 + x - 2)/(x^5 - 5*x^4 + 10*x^3 - 10*x^2 + 5*x - 1)]
[-1]
[1, 1]
[-2, -3, -2]
[4, 10, 12, 6]
[-9, -33, -62, -60, -24]
Thus the integer triangle could be created without SR(1) and without the '+y'-trick provided the list of fractions MS could be 'casted' to the type of the list M.
Question: Is this possible?
Edit
Yes it is, as rws shows below. So the solution to all my questions is this code:
from sage.calculus.calculus import symbolic_sum
x, j = SR.var('x, j')
assume(abs(x)<1)
M = [1, j, j^2 + 1, j^3 + 3*j, j^4 + 6*j^2 + 2]
for k, m in enumerate(M):
p = symbolic_sum(x^j*m, j, 0, oo)
q = p.numerator().polynomial(ZZ)/p.denominator().polynomial(ZZ)
f = q.partial_fraction_decomposition()
print [f[1][n].numerator() for n in (0..k)]
which gives
[-1]
[1, 1]
[-2, -3, -2]
[4, 10, 12, 6]
[-9, -33, -62, -60, -24]
Let's hope that someone looks at the tickets 4039 (which is six years old) and 17539 in the near future.