Ask Your Question

ben122684's profile - activity

2014-03-30 21:51:32 +0200 received badge  Famous Question (source)
2013-05-02 14:45:54 +0200 received badge  Taxonomist
2012-06-20 04:15:11 +0200 received badge  Notable Question (source)
2011-08-25 00:48:36 +0200 received badge  Popular Question (source)
2010-10-14 23:11:12 +0200 received badge  Student (source)
2010-10-14 23:11:11 +0200 received badge  Scholar (source)
2010-10-14 23:11:11 +0200 received badge  Supporter
2010-10-14 23:11:11 +0200 received badge  Editor (source)
2010-10-01 18:58:55 +0200 marked best answer generating series

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

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

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]
sage: number_of_partitions(20)

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.

2010-09-22 17:00:37 +0200 answered a question generating series

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.

2010-09-22 16:32:42 +0200 asked a question 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!!!!!!!!!