Ask Your Question
0

Casting symbolic fractions to fraction field of polynomial ring?

asked 2014-12-22 21:56:28 +0100

Peter Luschny gravatar image

updated 2014-12-23 11:43:03 +0100

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-12-23 08:00:26 +0100

rws gravatar image

updated 2014-12-23 08:14:38 +0100

Conversion from symbolic fraction to fraction field element:

sage: ex=(x+1)/(x-1); ex
(x + 1)/(x - 1)
sage: ex.numerator().polynomial(ZZ)/ex.denominator().polynomial(ZZ)
(x + 1)/(x - 1)
sage: type(_)
<type 'sage.rings.fraction_field_element.FractionFieldElement'>

The / operator applied to polynomial elements automagically creates the right fraction field. I admit that having a fraction conversion method for expressions (like the polynomial conversion) would be worthwhile.

This is now trac ticket #17539.

edit flag offensive delete link more

Comments

Note that in my previous questions I used partial_fraction() but here I use partial_fraction_decomposition(). Is this related to ticket 4039 where jason remarked: "An added bonus would be if they gave similar output (currently one gives a list, the other gives an expression)"?

Peter Luschny gravatar imagePeter Luschny ( 2014-12-23 11:17:42 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-12-22 21:56:28 +0100

Seen: 396 times

Last updated: Dec 23 '14