# Coefficients of inversed polynomial

I want to lazily compute coefficients of inversed integer based polynomial.

For example, I have: $$P = 1 - x$$ and I want to get formal power series of it's inverse: $$\frac{1}{P} = \frac{1}{1-x} = 1 + x + x^2 + \dots$$

But actually, I would like to get the n-th coefficient of it.

How can I do it?

P.S: I tried the following code, but it computes only 20 coefficients:

sage:> F.<x> = PowerSeriesRing(ZZ); F
sage:> F()/(1-x)
1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20)


I think I can change precision every time I want to get a coefficient bigger than default 20, but it requires recomputing of that power series, so I want to know is there another way.

edit retag close merge delete

Sort by » oldest newest most voted

The appropriate object would be a "lazy power series".

One can define a LazyPowerSeriesRing in Sage, but it does not seem very capable so far, and in particular cannot compute $1 / (1 - x)$.

From the list of tickets whose summary contains "lazy", the most relevant are:

Many seem stalled but #27347 seems promising.

Edit: With #27347 (now closed and hopefully making it into Sage 8.8.beta3), one can now do:

sage: from sage.rings.lazy_laurent_series_ring import LazyLaurentSeriesRing
sage: L = LazyLaurentSeriesRing(ZZ, 'x')
sage: x = L.gen()
sage: f = ~(1 - x)
sage: f
1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + ...
sage: f
1


A related interesting package is ore_algebra, see

more

Thanks.

Maybe I can at least divide 1 by polynomial and get quotient and remainder? I can compute these coefficients by myself this way, but quo_rem method returns the trivial answer (0, 1).