# Revision history [back]

Try this.

sage: f(x)= x+ x^2 + x^3 + x^4
sage: g = f.power_series(ZZ)
sage: g
x + x^2 + x^3 + x^4 + O(x^5)
sage: g.truncate(3)
x^2 + x


I learned something, because I wasn't sure if one could make this work nicely, but it does. Note that you must provide a ring for the power series command, and the truncation works in the sense of the 3 meaning +O(x^3).

I thought about whether this should be a once-off method, but I think it's better to require the sending to power series, because generic symbolic expressions don't have a meaningful sense for 'truncation'.

Try this.

sage: f(x)= x+ x^2 + x^3 + x^4
sage: g = f.power_series(ZZ)
sage: g
x + x^2 + x^3 + x^4 + O(x^5)
sage: g.truncate(3)
x^2 + x


I learned something, because I wasn't sure if one could make this work nicely, but it does. Note that you must provide a ring for the power series command, and the truncation works in the sense of the 3 meaning +O(x^3).

Or, if you need that, you can use the following similar command.

sage: g.truncate_powerseries(3)
x + x^2 + O(x^3)


I thought about whether this should be a once-off method, but I think it's better to require the sending to power series, because generic symbolic expressions don't have a meaningful sense for 'truncation'.