ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Sep 2010 22:52:52 +0200generating serieshttps://ask.sagemath.org/question/7706/generating-series/Hi. I want to create a function which will pick out the coefficients of a generating series. In particular, I have a generating series $\sum_{k=0}^\infty a_kt^k$ defined by an infinite product $\prod_{k=1}^\infty P_k(t)$. How do I just pick out the coefficients a_k?
I'm using Sage 4.5.3 on Mac OS X 10.6.4.
Thanks for the help!!!!!!!!!Wed, 22 Sep 2010 16:32:42 +0200https://ask.sagemath.org/question/7706/generating-series/Answer by ben122684 for <p>Hi. I want to create a function which will pick out the coefficients of a generating series. In particular, I have a generating series $\sum_{k=0}^\infty a_kt^k$ defined by an infinite product $\prod_{k=1}^\infty P_k(t)$. How do I just pick out the coefficients a_k?</p>
<p>I'm using Sage 4.5.3 on Mac OS X 10.6.4.</p>
<p>Thanks for the help!!!!!!!!!</p>
https://ask.sagemath.org/question/7706/generating-series/?answer=11688#post-id-11688Thanks for the response! Actually, part of my problem (which I forgot to state above) is how to represent the infinite product. To be honest, I've used Sage for about a year, but have not programmed more than a one-line function. So most of the use has been extremely rudimentary. Is there a way to represent an infinite product? Naively, I expected something like
prod(P(t,k) for k >= 1) == sum(a(k)*t^k for k >= 0)
and then be able to read off the a(k) somehow.Wed, 22 Sep 2010 17:00:37 +0200https://ask.sagemath.org/question/7706/generating-series/?answer=11688#post-id-11688Comment by ccanonc for <p>Thanks for the response! Actually, part of my problem (which I forgot to state above) is how to represent the infinite product. To be honest, I've used Sage for about a year, but have not programmed more than a one-line function. So most of the use has been extremely rudimentary. Is there a way to represent an infinite product? Naively, I expected something like</p>
<p>prod(P(t,k) for k >= 1) == sum(a(k)*t^k for k >= 0)</p>
<p>and then be able to read off the a(k) somehow.</p>
https://ask.sagemath.org/question/7706/generating-series/?comment=22601#post-id-22601Hi Ben, if you select a "best answer" (the check-mark), someone gets a lot of karma. :-)Thu, 23 Sep 2010 22:52:52 +0200https://ask.sagemath.org/question/7706/generating-series/?comment=22601#post-id-22601Answer by niles for <p>Hi. I want to create a function which will pick out the coefficients of a generating series. In particular, I have a generating series $\sum_{k=0}^\infty a_kt^k$ defined by an infinite product $\prod_{k=1}^\infty P_k(t)$. How do I just pick out the coefficients a_k?</p>
<p>I'm using Sage 4.5.3 on Mac OS X 10.6.4.</p>
<p>Thanks for the help!!!!!!!!!</p>
https://ask.sagemath.org/question/7706/generating-series/?answer=11687#post-id-11687This is an interesting question. For a power series `f`, the method `f.padded_list()` returns a list of coefficients, and you can return a single coefficient using list notation: `f[k]`. How are you representing the infinite product in sage though? If you're just multiplying a (large) finite number of polynomials or power series, then the methods above will probably do what you need; but maybe you're asking something more subtle?
Note: here is the documentation for [power series](http://www.sagemath.org/doc/reference/sage/rings/power_series_ring_element.html).Wed, 22 Sep 2010 16:53:17 +0200https://ask.sagemath.org/question/7706/generating-series/?answer=11687#post-id-11687Answer by Jason Bandlow for <p>Hi. I want to create a function which will pick out the coefficients of a generating series. In particular, I have a generating series $\sum_{k=0}^\infty a_kt^k$ defined by an infinite product $\prod_{k=1}^\infty P_k(t)$. How do I just pick out the coefficients a_k?</p>
<p>I'm using Sage 4.5.3 on Mac OS X 10.6.4.</p>
<p>Thanks for the help!!!!!!!!!</p>
https://ask.sagemath.org/question/7706/generating-series/?answer=11690#post-id-11690First, I'll mention that I prefer LazyPowerSeriesRing to PowerSeriesRing. Here is an example of using it.
sage: P.<t> = LazyPowerSeriesRing(QQ) # Creates the power series ring QQ[[t]]
sage: f = (t + (1/2)*t^2).exponential # In latex, $f = e^{t + \frac{t^2}{2}}$
sage: f[20]*factorial(20) # f[20] is the coefficient of t^20
23758664096
It's an unfortunate fact the interface here is a little bit flaky. For example, using
sage: f = (t + t^2/2).exponential()
gives an error. Even worse is that I only know to define f=1/(1-t) with the following sequence of commands.
sage: f = P() # Prepare to define f by a functional equation
sage: f.define(1 + t*f) # This defines f by the functional equation f = 1 + t*f
sage: f[20] # Coefficient of t^20
1
However, this does has a facility for dealing with infinite products. For example, the generating functions for partitions is the infinite product \prod_{i \ge 1} 1/(1-t^i). We can do this in sage as follows. First we define a function that will return any given factor.
sage: def factor(i):
f = P()
f.define(1+t^i*f) # f = 1/(1-t^i)
return f
Now we define a generator that represents the infinite product without needing to compute it.
sage: def gen():
i = 1 # product starts here
while True: # product continues forever
yield factor(i) # return the i^th factor
i += 1
Now we can define what we want.
sage: g = P.product_generator(gen())
sage: g.compute_coefficients(8) # Compute the first 8 coefficients
sage: g
1 + t + 2*t^2 + 3*t^3 + 5*t^4 + 7*t^5 + 11*t^6 + 15*t^7 + 22*t^8 + O(x^9)
sage: g[20]
627
sage: number_of_partitions(20)
627
As I said, there are definitely problems with the interface here, but the structure is quite powerful. Please ask for more specific help if this answer isn't enough for you to solve your problem.
Wed, 22 Sep 2010 18:35:59 +0200https://ask.sagemath.org/question/7706/generating-series/?answer=11690#post-id-11690Comment by niles for <p>First, I'll mention that I prefer LazyPowerSeriesRing to PowerSeriesRing. Here is an example of using it.</p>
<pre><code>sage: P.<t> = LazyPowerSeriesRing(QQ) # Creates the power series ring QQ[[t]]
sage: f = (t + (1/2)*t^2).exponential # In latex, $f = e^{t + \frac{t^2}{2}}$
sage: f[20]*factorial(20) # f[20] is the coefficient of t^20
23758664096
</code></pre>
<p>It's an unfortunate fact the interface here is a little bit flaky. For example, using </p>
<pre><code>sage: f = (t + t^2/2).exponential()
</code></pre>
<p>gives an error. Even worse is that I only know to define f=1/(1-t) with the following sequence of commands.</p>
<pre><code>sage: f = P() # Prepare to define f by a functional equation
sage: f.define(1 + t*f) # This defines f by the functional equation f = 1 + t*f
sage: f[20] # Coefficient of t^20
1
</code></pre>
<p>However, this does has a facility for dealing with infinite products. For example, the generating functions for partitions is the infinite product \prod_{i \ge 1} 1/(1-t^i). We can do this in sage as follows. First we define a function that will return any given factor.</p>
<pre><code>sage: def factor(i):
f = P()
f.define(1+t^i*f) # f = 1/(1-t^i)
return f
</code></pre>
<p>Now we define a generator that represents the infinite product without needing to compute it.</p>
<pre><code>sage: def gen():
i = 1 # product starts here
while True: # product continues forever
yield factor(i) # return the i^th factor
i += 1
</code></pre>
<p>Now we can define what we want.</p>
<pre><code>sage: g = P.product_generator(gen())
sage: g.compute_coefficients(8) # Compute the first 8 coefficients
sage: g
1 + t + 2*t^2 + 3*t^3 + 5*t^4 + 7*t^5 + 11*t^6 + 15*t^7 + 22*t^8 + O(x^9)
sage: g[20]
627
sage: number_of_partitions(20)
627
</code></pre>
<p>As I said, there are definitely problems with the interface here, but the structure is quite powerful. Please ask for more specific help if this answer isn't enough for you to solve your problem.</p>
https://ask.sagemath.org/question/7706/generating-series/?comment=22602#post-id-22602that's amazing! It's too bad the section of the reference manual on power series doesn't have at least a pointer to the documentation for LazyPowerSeriesRing :(
http://www.sagemath.org/doc/reference/sage/combinat/species/series.htmlThu, 23 Sep 2010 06:32:43 +0200https://ask.sagemath.org/question/7706/generating-series/?comment=22602#post-id-22602