ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 11 Apr 2019 03:03:27 -0500Coefficients of inversed polynomialhttps://ask.sagemath.org/question/46080/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])/(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.Wed, 10 Apr 2019 15:28:16 -0500https://ask.sagemath.org/question/46080/coefficients-of-inversed-polynomial/Answer by slelievre for <p>I want to lazily compute coefficients of inversed integer based polynomial.</p>
<p>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 $$</p>
<p>But actually, I would like to get the n-th coefficient of it.</p>
<p>How can I do it?</p>
<p>P.S: I tried the following code, but it computes only 20 coefficients:</p>
<pre><code>sage:> F.<x> = PowerSeriesRing(ZZ); F
sage:> F([1])/(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)
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/46080/coefficients-of-inversed-polynomial/?answer=46084#post-id-46084The 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"](https://trac.sagemath.org/query?order=id&desc=1&summary=~lazy), the most relevant are:
- [#27347: Lazy Laurent series](https://trac.sagemath.org/ticket/27347)
- [#15673: major improvements to lazy power series](https://trac.sagemath.org/ticket/15673)
- [#15249: In lazy power series rings, 0 + a and 0 - a return 0](https://trac.sagemath.org/ticket/15249)
- [#15248: Calling a lazy power series ring twice summons demons from hell](https://trac.sagemath.org/ticket/15248)
- [#14685: error in the computing of the approximate order in LazyPowerSeries](https://trac.sagemath.org/ticket/14685)
- [#13433: Lazy power series: fix bad handling of base ring and categorification](https://trac.sagemath.org/ticket/13433)
- [#10084: Lazy power series: fix bad handling of base ring and categorification](https://trac.sagemath.org/ticket/10084)
- [#6800: formal/lazy/infinite powerseries](https://trac.sagemath.org/ticket/6800)
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[800]
1
A related interesting package is `ore_algebra`, see
- [http://www.kauers.de/software.html](http://www.kauers.de/software.html)
- [https://www.risc.jku.at/research/combinat/software/ore_algebra/](https://www.risc.jku.at/research/combinat/software/ore_algebra/)
- [https://www.risc.jku.at/research/combinat/software/ore_algebra/main.pdf](https://www.risc.jku.at/research/combinat/software/ore_algebra/main.pdf)Wed, 10 Apr 2019 19:51:27 -0500https://ask.sagemath.org/question/46080/coefficients-of-inversed-polynomial/?answer=46084#post-id-46084Comment by PaulRa for <p>The appropriate object would be a "lazy power series".</p>
<p>One can define a <code>LazyPowerSeriesRing</code> in Sage,
but it does not seem very capable so far, and in particular
cannot compute $1 / (1 - x)$.</p>
<p>From the <a href="https://trac.sagemath.org/query?order=id&desc=1&summary=~lazy">list of tickets whose summary contains "lazy"</a>, the most relevant are:</p>
<ul>
<li><a href="https://trac.sagemath.org/ticket/27347">#27347: Lazy Laurent series</a></li>
<li><a href="https://trac.sagemath.org/ticket/15673">#15673: major improvements to lazy power series</a></li>
<li><a href="https://trac.sagemath.org/ticket/15249">#15249: In lazy power series rings, 0 + a and 0 - a return 0</a></li>
<li><a href="https://trac.sagemath.org/ticket/15248">#15248: Calling a lazy power series ring twice summons demons from hell</a></li>
<li><a href="https://trac.sagemath.org/ticket/14685">#14685: error in the computing of the approximate order in LazyPowerSeries</a></li>
<li><a href="https://trac.sagemath.org/ticket/13433">#13433: Lazy power series: fix bad handling of base ring and categorification</a></li>
<li><a href="https://trac.sagemath.org/ticket/10084">#10084: Lazy power series: fix bad handling of base ring and categorification</a></li>
<li><a href="https://trac.sagemath.org/ticket/6800">#6800: formal/lazy/infinite powerseries</a></li>
</ul>
<p>Many seem stalled but #27347 seems promising.</p>
<p><strong>Edit</strong>: With #27347 (now closed and hopefully making it into Sage 8.8.beta3), one can now do:</p>
<pre><code>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[800]
1
</code></pre>
<p>A related interesting package is <code>ore_algebra</code>, see</p>
<ul>
<li><a href="http://www.kauers.de/software.html">http://www.kauers.de/software.html</a></li>
<li><a href="https://www.risc.jku.at/research/combinat/software/ore_algebra/">https://www.risc.jku.at/research/combinat/software/ore_algebra/</a></li>
<li><a href="https://www.risc.jku.at/research/combinat/software/ore_algebra/main.pdf">https://www.risc.jku.at/research/combinat/software/ore_algebra/main.pdf</a></li>
</ul>
https://ask.sagemath.org/question/46080/coefficients-of-inversed-polynomial/?comment=46091#post-id-46091Thanks.
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).Thu, 11 Apr 2019 03:03:27 -0500https://ask.sagemath.org/question/46080/coefficients-of-inversed-polynomial/?comment=46091#post-id-46091