Ask Your Question
2

generating series

asked 2010-09-22 16:32:42 +0100

ben122684 gravatar image

updated 2015-10-16 19:15:38 +0100

FrédéricC gravatar image

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!!!!!!!!!

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
4

answered 2010-09-22 18:35:59 +0100

Jason Bandlow gravatar image

First, 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.

edit flag offensive delete link more

Comments

that'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.html

niles gravatar imageniles ( 2010-09-23 06:32:43 +0100 )edit
1

answered 2010-09-22 16:53:17 +0100

niles gravatar image

This 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.

edit flag offensive delete link more
0

answered 2010-09-22 17:00:37 +0100

ben122684 gravatar image

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

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.

edit flag offensive delete link more

Comments

Hi Ben, if you select a "best answer" (the check-mark), someone gets a lot of karma. :-)

ccanonc gravatar imageccanonc ( 2010-09-23 22:52:52 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2010-09-22 16:32:42 +0100

Seen: 2,498 times

Last updated: Sep 22 '10