GF
GF
GF
f (x) =
n=0
an xn
f (x) =
n=0
an
xn n!
Generating functions are formal power series which form a ring under the natural addition and multiplication rules. For ordinary generating functions we get:
an xn +
n=0 n=0
bn xn =
n=0
(an + bn )xn
an xn
n=0 n=0
bn xn =
n=0
dn xn
where dn = n ai bni . i=0 Similarly, we can add and multiply two exponential generating functions.
n=0
xn + an n!
n=0
xn bn = n!
(an + bn )
n=0
xn n!
an
n=0 n n i=0 i
xn n!
bn
n=0
xn = n!
dn
n=0
xn n!
ai bni . where dn = The last operation we will mention explicitly here is dierentiation. For a generating func n1 . For two generating n tion f (x) = n=0 nan x n=0 an x , the derivative is f (x) = functions f and g, usual laws of derivation hold: (f + g) = f + g (f g) = f g + f g f (g(x)) = g f (g(x))
1
0.1. Determining a generating function from a recurrence. Given a sequence an , we want to determine a closed form for a generating function of a n . Example 1. Let an be the constant all ones sequence (1, 1, 1, . . .). Then the ordinary 1 generating function for an is n0 xn which we know to be 1x . Knowing certain basic relations such as in the last example will be very helpful in working with generating functions. In particular we note the following: m m+1 2 2 1 n+k1 k k ax + a x + ... + a x + ... m =1+ 1 ax 1 2 k Example 2. Let an be dened by a0 = a1 = 1, an = an1 + an2 for n 2. In order to determine f (x) = n0 an xn , we start by expanding the rst few terms of f (x). Then we substitute in our recurrence on the coecients. Finally we look for shifted versions of our original generating function. f (x) = 1 + x + n2 an xn = 1 + x + n2 (an1 + an2 )xn = 1 + x + x n2 an1 xn1 + x2 n2 an2 xn2 = 1 + x + x(f (x) 1) + x2 f (x) 1 = 1xx2 0.2. Recover a recurrence from a generating function. Next we simply want to turn around the goal from the last section. Given the closed form of a generating function for a sequence, we would like to know the recurrence of the sequence. If we are given the generating function as a rational function of polynomials, we use the technique of equating coecients on both sides. Example 3. Suppose we have a sequence an whose ordinary generating function is: 1x 1 3x x2 + x3 Let P (x) = 1 x and Q(x) = 1 3x x2 + x3 . Then Q(x)f (x) = P (x). For n 3 we equate coecients on both sides of this equation. f (x) = f (x)(1 3x x2 + x3 ) = 1 x The coecient of xn for n 3 is 0 (as is easy to see from the right hand side). We must consider how from the left hand side, we contribute to the coecient of x n . We have the following terms: (an xn )1, (an1 xn1 )(3x), (an2 xn2 )(x2 ), and (an3 xn3 )(x3 ). These terms must add to zero, therefore an 3an1 an2 + an3 = 0, which gives a recurrence on our sequence. The only thing left to determine is a0 , a1 , and a2 . We can use the same method
as above for each of these terms. The constant term on the right hand side is 1, hence the constant term of f (x) must be 1. The coecient of x is 1 hence (a0 )(3) + (a1 )(1) = 1. Since we already know a0 = 1, we can solve to nd a1 = 2. Similarly we nd a2 = 7. 0.3. Solving a recursion. Here we show an example of how to use a generating function to solve a recursion. In particular, we are given a recursion but would like to have a non-recursive formula for the sequence. Example 4. Suppose we are given the sequence dened by the recursion: an = 3an1 . Let f (x) be its ordinary generating function. f (x) 3xf (x) 3x 3xf (x) f (x) 3xf (x) f (x) = = = = = = = a 0 + a 1 x + a 2 x2 + . . . a0 3x + a1 3x2 + a2 3x3 + . . . a0 + (a1 3a0 )x + (a2 3a1 )x2 + . . . a0 (The relation ai 3ai1 = 0 is exactly our recurrance) a0 (1 + 3x + + . . .) a0 + 3a0 x + 32 a0 x2 + . . .
a0 13x 3 2 x2 + 3 3 x3
Hence an = 3n a0 . 0.4. Using generating functions in counting. Example 5. Let tn be the number of spanning trees of K2,n , the complete bipartite graph with |V1 | = 2 and |V2 | = n. We want to determine a formula for tn . First we set up a recursion. Clearly, t1 = 1. For arbitrary n, consider one vertex of V2 , say v. If this vertex is connected to only one of the vertices in V1 , then the number of spanning trees is 2tn1 . If v is connected to both vertices of V1 , then the number of spanning trees is 2n1 because no other vertex from V2 can be connected to both vertices of V1 . Hence tn satises tn = 2tn1 + 2n1 for n 2. Now we solve our recursion. Let t(x) be the ordinary generating function for tn . t(x) 2xt(x) t(x) 2xt(x) t(x) 2xt(x) t(x) 2xt(x) t(x) t(x) t(x) = t 0 + t 1 x + t 2 x2 + . . . = 2t0 x + 2t1 x2 + 2t2 x3 + . . . = t0 + (t1 2t0 )x + (t2 2t1 )x2 + . . . = x + 2x2 + 22 x3 + . . . x = 12x x = (12x)2 = = x(1 + 2(2)x + 3(22 )x2 + . . .) n2n1