1 | initial version |
I am not sure about your ultimate goal, but if you want to do operations between your polynomials, then you will have to truncate again and again. Let me suggest another way : instead of truncating by hand, why not just work in a quotient ring, where you declare that $q^3=0$ (hence every power above 3 will vanish as well). It can be as follows:
sage: R.<q> = PolynomialRing(ZZ)
sage: P = 1+q+2*q^2+3*q^3+4*q^4+5*q^5
sage: S = R.quotient(q^3)
sage: S
Univariate Quotient Polynomial Ring in qbar over Integer Ring with modulus q^3
sage: Q = S(P)
sage: Q
2*qbar^2 + qbar + 1
The good point here is that if you compute, say, the square of Q
, you do not have to truncate again:
sage: Q^2
5*qbar^2 + 2*qbar + 1