# How convert a polynomial in a power series?

Consider the following situation:

R.<x> = PowerSeriesRing(ZZ)
f = x^2 - x + 1
print f, f.parent()

g = cyclotomic_polynomial(6)
print g, g.parent()


which gives

1 - x + x^2 Power Series Ring in x over Integer Ring
x^2 - x + 1 Univariate Polynomial Ring in x over Integer Ring


Question: How can I convert a polynomial in a power series?

In the example above I would like to input a cyclotomic polynomial and get as output it's inverse when interpreted as a power series.

cyclotomic_polynomial(6).as_ps().inverse().list()
[1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1]


In the pseudo code above "as_ps()" indicates the missing link.

edit retag close merge delete

Sort by » oldest newest most voted

You can try to convert g as an element of the ring R by calling R(g) (it is a general syntax):

sage: G = R(g)
sage: G
1 - x + x^2
sage: G.parent()
Power Series Ring in x over Integer Ring
sage: G.inverse()
1 + x - x^3 - x^4 + x^6 + x^7 - x^9 - x^10 + x^12 + x^13 - x^15 - x^16 + x^18 + x^19 + O(x^20)
sage: G.inverse().list()
[1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1]

more