# simplify coefficients of laurent series?

I am working with a Laurent series f. My goal is to calculate the principal part of f^3. The code I am using is this:

R.<u> = LaurentSeriesRing(SR, 'u'); R

b2, b1, a0, a1, a2, a3, a4 = var('b2 b1 a0 a1 a2 a3 a4')

f = b2*u^-2 + b1*u^-1 + a0 + a1*u + a2*u^2 + a3*u^3 + a4*u^4 + O(u^5)

f^3


b2^3*u^-6 + 3*b1*b2^2*u^-5 + (a0*b2^2 + 2*b1^2*b2 + (2*a0*b2 + b1^2)*b2)*u^-4 + (2*a0*b1*b2 + a1*b2^2 + (2*a0*b2 + b1^2)*b1 + 2*(a0*b1 + a1*b2)*b2)*u^-3 + (2*a1*b1*b2 + a2*b2^2 + (2*a0*b2 + b1^2)*a0 + 2*(a0*b1 + a1*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b2)*u^-2 + (2*a2*b1*b2 + a3*b2^2 + (2*a0*b2 + b1^2)*a1 + 2*(a0*b1 + a1*b2)*a0 + 2*(a0*a1 + a2*b1 + a3*b2)*b2 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b1)*u^-1 + (2*a3*b1*b2 + a4*b2^2 + (2*a0*b2 + b1^2)*a2 + 2*(a0*b1 + a1*b2)*a1 + 2*(a0*a1 + a2*b1 + a3*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*a0 + (2*a0*a2 + a1^2 + 2*a3*b1 + 2*a4*b2)*b2) + O(u)


SAGE does not simplify the coefficients of the result. Is there some command that I can enter that will allow me to simultaneously simplify the coefficients of each power of u and output the result up to O(u)? The simplify command does not seem to work.

edit retag close merge delete

Sort by » oldest newest most voted

In this case, I think it would be better to work with coefficients in a polynomial ring

sage: K = QQ['b2,b1,a0,a1,a2,a3,a4']
sage: K.inject_variables()
Defining b2, b1, a0, a1, a2, a3, a4
sage: R = K[['u']]
sage: u = R.gen()
sage: f = b2*u^-2 + b1*u^-1 + a0 + a1*u + a2*u^2 + a3*u^3 + a4*u^4 + O(u^5)
sage: f^3
b2^3*u^-6 + 3*b2^2*b1*u^-5 + (3*b2*b1^2 + 3*b2^2*a0)*u^-4 + (b1^3 + 6*b2*b1*a0 + 3*b2^2*a1)*u^-3 + (3*b1^2*a0 + 3*b2*a0^2 + 6*b2*b1*a1 + 3*b2^2*a2)*u^-2 + (3*b1*a0^2 + 3*b1^2*a1 + 6*b2*a0*a1 + 6*b2*b1*a2 + 3*b2^2*a3)*u^-1 + (a0^3 + 6*b1*a0*a1 + 3*b2*a1^2 + 3*b1^2*a2 + 6*b2*a0*a2 + 6*b2*b1*a3 + 3*b2^2*a4) + O(u)

more

Yep, see the coefficients() method:

...
sage: g = f^3
sage: g.coefficients()
[b2^3, 3*b1*b2^2, a0*b2^2 + 2*b1^2*b2 + (2*a0*b2 + b1^2)*b2, 2*a0*b1*b2 + a1*b2^2 + (2*a0*b2 + b1^2)*b1 + 2*(a0*b1 + a1*b2)*b2, 2*a1*b1*b2 + a2*b2^2 + (2*a0*b2 + b1^2)*a0 + 2*(a0*b1 + a1*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b2, 2*a2*b1*b2 + a3*b2^2 + (2*a0*b2 + b1^2)*a1 + 2*(a0*b1 + a1*b2)*a0 + 2*(a0*a1 + a2*b1 + a3*b2)*b2 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b1, 2*a3*b1*b2 + a4*b2^2 + (2*a0*b2 + b1^2)*a2 + 2*(a0*b1 + a1*b2)*a1 + 2*(a0*a1 + a2*b1 + a3*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*a0 + (2*a0*a2 + a1^2 + 2*a3*b1 + 2*a4*b2)*b2]


--- edit

Sorry, I answered the wrong question. If you want to simplify the coefficients, you can map the simplify function over your list:

sage: g = f^3
sage: map(simplify, g.coefficients())
[b2^3,
3*b1*b2^2,
a0*b2^2 + 2*b1^2*b2 + (2*a0*b2 + b1^2)*b2,
2*a0*b1*b2 + a1*b2^2 + (2*a0*b2 + b1^2)*b1 + 2*(a0*b1 + a1*b2)*b2,
2*a1*b1*b2 + a2*b2^2 + (2*a0*b2 + b1^2)*a0 + 2*(a0*b1 + a1*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b2,
2*a2*b1*b2 + a3*b2^2 + (2*a0*b2 + b1^2)*a1 + 2*(a0*b1 + a1*b2)*a0 + 2*(a0*a1 + a2*b1 + a3*b2)*b2 + (a0^2 + 2*a1*b1 + 2*a2*b2)*b1,
2*a3*b1*b2 + a4*b2^2 + (2*a0*b2 + b1^2)*a2 + 2*(a0*b1 + a1*b2)*a1 + 2*(a0*a1 + a2*b1 + a3*b2)*b1 + (a0^2 + 2*a1*b1 + 2*a2*b2)*a0 + (2*a0*a2 + a1^2 + 2*a3*b1 + 2*a4*b2)*b2]


But, if you look at the resulting list you'll see that it's identical to g.coefficients(), so the coefficients are "simplified". Maybe what you really want is to expand the coefficients (which is less simple that the factored form by some definition):

sage: map(expand, g.coefficients())
[b2^3,
3*b1*b2^2,
3*a0*b2^2 + 3*b1^2*b2,
6*a0*b1*b2 + 3*a1*b2^2 + b1^3,
3*a0^2*b2 + 3*a0*b1^2 + 6*a1*b1*b2 + 3*a2*b2^2,
3*a0^2*b1 + 6*a0*a1*b2 + 3*a1*b1^2 + 6*a2*b1*b2 + 3*a3*b2^2,
a0^3 + 6*a0*a1*b1 + 6*a0*a2*b2 + 3*a1^2*b2 + 3*a2*b1^2 + 6*a3*b1*b2 + 3*a4*b2^2]


If you're curious about other powerful list operations, check out map, reduce, and filter here.

more

The coefficients command doesn't simplify the coefficients, it only puts them in a list. If you notice, for instance, the third coefficient in your answer (a0*b2^2 + 2*b1^2*b2 + (2*a0*b2 + b1^2)*b2) is not in a simplified form. Perhaps there is a command that simplifies all entries in a list?

( 2013-02-21 23:22:54 -0600 )edit

You can do a little better: [SR(gx).full_simplify() for gx in g.coefficients()].

( 2013-02-22 07:36:32 -0600 )edit

Thanks everyone!

( 2013-02-23 09:38:23 -0600 )edit