Вы находитесь на странице: 1из 20

Generating Functions

Definitions

In this handout, we introduce generating functions and discuss their uses and applications. Generating
functions are powerful tools, as they provide a compact way of working with sequences, and can reduce
combinatorial problems to mere algebra.
Given a sequence a0 , a1 , a2 , . . . of real numbers, the generating function of this sequence is defined as
a0 + a1 x + a2 x2 + .
We treat this function as a formal power series in x, meaning that we can add, subtract, and multiply (and
even divide) such power series, but we do not worry if the series converges for any particular value of x.
Given a generating function A(x), let [xn ]A(x) denote the coefficient of xn in A(x). Hence, if
A(x) = a0 + a1 x + a2 x2 + ,
then [xn ]A(x) = an .

Sums and Products of Generating Functions

Given two sequences (an ) and (bn ), let A(x) and B(x) denote their generating functions, respectively, so
A(x) = a0 + a1 x + a2 x2 + ,
B(x) = b0 + b1 x + b2 x2 + .
If we take the sum of A(x) and B(x), then we get
A(x) + B(x) = (a0 + b0 ) + (a1 + b1 )x + (a2 + b2 )x2 + ,
so A(x) + B(x) is the generating function of the sequence (an + bn ). More generally, c1 A(x) + c2 B(x) is the
generating function of the sequence (c1 an + c2 bn ), for any constants c1 and c2 .
However, if we take the product of A(x) and B(x), then we get
A(x)B(x) = a0 b0 + (a0 b1 + a1 b0 )x + (a0 b2 + a1 b1 + a2 b0 )x2 +
n

X
X

=
ak bnk xn .

n=0

k=0

The sequence of coefficients in A(x)B(x) is known as the convolution of the sequences (an ) and (bn ), which we
will discuss in more detail in Section 5.
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
3

Linearly Recurrent Sequences

If a sequence satisfies a linear recurrence, then we can write down its generating function, and in certain
cases, use the generating function to solve the sequence.
Problem 3.1. Find the generating function of the geometric sequence an = arn .

Solution: In this geometric sequence, each term is obtained by multiplying the previous term by r. We use
this property to find a closed form of the generating function as follows. (The same technique is used to
find the formula for a geometric series.)
Let
A(x) = a0 + a1 x + a2 x2 +
= a + arx + ar2 x2 +
= a(1 + rx + r2 x2 + ).
Then
rxA(x) = rx a(1 + rx + r2 x2 + )
= a(rx + r2 x2 + r3 x3 + ).
Subtracting these equations, we get

A(x) rxA(x) = a,

so

a
.
1 rx
In other words, the generating function of the geometric sequence (arn ) is given by
A(x) =

a + arx + ar2 x2 + =

a
.
1 rx

In particular, taking a = 1 and r = 1, we get


1 + x + x2 + =

1
.
1x


Problem 3.2. Find the generating function of the Fibonacci sequence (Fn ).

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
Solution: Recall that the Fibonacci sequence is defined by F0 = 0, F1 = 1, and Fn = Fn1 + Fn2 for all n 2.
We use the recurrence to find a closed form of the generating function as follows. Let
F(x) = F0 + F1 x + F2 x2 + F3 x3 + .
Then
xF(x) = F0 x + F1 x2 + F2 x3 + F3 x4 + ,
x2 F(x) = F0 x2 + F1 x3 + F2 x4 + F3 x5 + ,
so
F(x) xF(x) x2 F(x) = F0 + (F1 F0 )x + (F2 F1 F0 )x2 + (F3 F2 F1 )x3 +
= x.
Hence,
F(x) =

x
.
1 x x2

We can use this generating function to find an explicit formula for Fn . First, we factor the denominator as
1 x x2 = (1 x)(1 x),
which expands as

1 x x2 = 1 ( + )x + x2 ,

so + = 1 and
= 1. By Vietas
formulas, and are the roots of the quadratic equation t2 t 1 = 0,

which are

1 5
2 .

Hence, let =

1+ 5
2

and =

1 5
2 .

By the method of partial fractions, there exist constants A and B such that
x
A
B
=
+
.
(1 x)(1 x) 1 x 1 x
Multiplying both sides by (1 x)(1 x), we get
x = A(1 x) + B(1 x) = (A + B) (A + B)x.
Hence, we obtain the system of equations
A + B = 0,
A + B = 1.
From the first equation, B = A. Substituting into the second equation, we get A A = ( )A = 1, so
1
A =
= 1 . Then B = 1 . Therefore,
5



1
1
1

.
F(x) =
5 1 x 1 x
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
By the generating function of a geometric sequence,
1
= 1 + x + 2 x2 + ,
1 x
1
= 1 + x + 2 x2 + ,
1 x
so


1
1
1

F(x) =
5 1 x 1 x
1
= [(1 + x + 2 x2 + ) (1 + x + 2 x2 + )]
5

2 2
3 3
= x + x2 + x3 + .
5
5
5
Thus, the coefficient of xn in F(x) is equal to

!n
!n
1 5
n n
1 1 + 5

Fn =
=
.
2
2
5
5

Problem 3.3. Let

3 x2
= a0 + a1 x + a2 x2 + .
1 x2 x3

Find a10 .
Solution: From the given expression,
3 x2 = (1 x2 x3 )(a0 + a1 x + a2 x2 + )
= a0 + a1 x + (a2 a0 )x2 + (a3 a1 a0 )x3 + (a4 a2 a1 )x4 + .
Hence, a0 = 3, a1 = 0, a2 a0 = 1, and an an2 an3 = 0 for all n 3. We see that a2 = a0 1 = 2. Using
the recurrence, we find a10 = 17.

Another way to find the first few coefficients, which serve as the initial terms of the recurrence, is as follows:
3 x2
3 x2
=
1 x2 x3
1 (x2 + x3 )
= (3 x2 )[1 + (x2 + x3 ) + (x2 + x3 )2 + ]
= (3 x2 )(1 + x2 + x3 + 2x4 + )
= 3 + 2x2 + 3x3 + 2x4 + .
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
More generally, suppose a sequence (an ) is defined by the linear recurrence
an = c1 an1 + c2 ank + + ck ank .
Then the polynomial
xk c1 xk1 c2 xk2 ck
is the characteristic polynomial of the sequence (an ), and the generating function of the sequence (an ) is of the
form
P(x)
,
a0 + a1 x + a2 x2 + =
1 c1 x c2 x2 ck xk
where P(x) is a polynomial. This result tells us that the generating function for a linearly recurrent sequence
is a rational function. Likewise we can show that every rational function is the generating function for
some linearly recurrent sequence. The characteristic polynomial of the sequence is the denominator with
its coefficients reversed and changing the numerator changes the sequences initial conditions.

Exercises
3.1.

Let

1
1+x+

x2

x3

+ x4 + x5 + x6

= a0 + a1 x + a2 x2 + .

Find an .
3.2. The sequence (an ) is defined by a0 = 0, a1 = 1, and an = 5an1 6an2 for all n 2. Find the generating
function of this sequence, and use it to solve for an .

Partial Sums and Finite Differences

In Section 2, we saw that


(a0 + a1 x + a2 x2 + )(b0 + b1 x + b2 x2 + )
= a0 b0 + (a0 b1 + a1 b0 )x + (a0 b2 + a1 b1 + a2 b0 )x2 + .
If we set each bi equal to 1, then we get
(a0 + a1 x + a2 x2 + )(1 + x + x2 + )
= a0 + (a0 + a1 )x + (a0 + a1 + a2 )x2 + .
The sequence a0 , a0 + a1 , a0 + a1 + a2 , . . . is known as the sequence of partial sums of the sequence a0 , a1 , a2 ,
. . . . Thus, if the generating function of the sequence (an ) is
a0 + a1 x + a2 x2 + = A(x),
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
then the generating function of the sequence of partial sums is given by
a0 + (a0 + a1 )x + (a0 + a1 + a2 )x2 + = A(x)(1 + x + x2 + ) =

A(x)
.
1x

On the other hand, suppose we multiply the function A(x) by 1 x instead of divide by 1 x:
(1 x)A(x) = (1 x)(a0 + a1 x + a2 x2 + )
= a0 + (a1 a0 )x + (a2 a1 )x2 + .
The sequence a1 a0 , a2 a1 , a3 a2 , . . . is known as the sequence of finite differences of the sequence a0 , a1 ,
a2 , . . . . Hence, the generating function of the sequence of finite differences is given by
(a1 a0 )x + (a2 a1 )x2 + (a3 a2 )x3 + = (1 x)A(x) A(0).
This is a particularly useful formula when an is a polynomial in n, because in such a case, the sequence of
finite differences is another polynomial in n, whose degree is one less.
Problem 4.1. Find the generating function of the sequence an = n2 .
Solution: . Let
A(x) =

n2 xn = 02 + 12 x + 22 x2 + 32 x3 + .

n=0

Then
(1 x)A(x) = (1 x)(02 + 12 x + 22 x2 + 32 x3 + + n2 xn + )
= 02 + (12 02 )x + (22 12 )x2 + (32 22 )x3 + + [n2 (n 1)2 ]xn +
= x + 3x2 + 5x3 + + (2n 1)xn + ,
and
(1 x)2 A(x) = (1 x)[x + 3x2 + 5x3 + 7x4 + + (2n 1)xn + ]
= x + (3 1)x2 + (5 3)x3 + (7 5)x4 + + [(2n 1) (2n 3)]xn +
= x + 2x2 + 2x3 + 2x4 +
= x + 2x2 (1 + x + x2 + )
2x2
1x
x + x2
=
.
1x
=x+

Hence,
A(x) =

n2 xn =

n=0

x + x2
.
(1 x)3


www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
Exercises
4.1.

Find the generating function of the sequence an = n3 .

4.2. Let Fn denote the nth Fibonacci number where F0 = 0 and F1 = 1. Show that F0 + F1 + + Fn = Fn+2 1
for all nonnegative integers n.

Generating Functions and Combinatorics

To describe how generating functions relate to problems in combinatorics, we start with a simple example.
Problem 5.1. Matt has a basket containing 4 apples and 5 bananas. Matt wants an even number of
apples and at least two bananas. In how many ways can Matt choose 6 pieces of fruit? (The apples are
distinguishable, as are the bananas.)
Solution: Matt can choose 2 apples and 4 bananas, or 4 apples and 2 bananas. Hence, Matt can choose 6
pieces of fruit in
! !
! !
4 5
4 5
+
= 40
2 4
4 2
ways.
What if we wanted to find the number of ways Matt could choose n pieces of fruit? To make things more

definite, let ai be the number of ways Matt can choose i apples, so ai = 4i if 0 i 4 and i is even, and

ai = 0 otherwise. Let bi be the number of ways Matt can choose i bananas, so bi = 5i if 2 i 5, and bi = 0
otherwise. Let cn be the number of ways Matt can choose n pieces of fruit. If Matt chooses k apples, then he
also chooses n k bananas, which he can do in a total of ak bnk ways. Summing over 0 k n, we find
cn = a0 bn + a1 bn1 + a2 bn2 + + a0 bn .
We recognize the sum in the right-hand side as the nth term in the convolution of the two sequences (an )
and (bn ). Hence, if we let A(x), B(x), and C(x) be the generating functions of the sequences (an ), (bn ), and (cn ),
respectively, then C(x) = A(x)B(x). These generating functions are
!
!
!
4
4 2
4 4
A(x) =
+
x +
x
0
2
4
= 1 + 6x2 + x4 ,
!
!
!
!
5 2
5 3
5 4
5 5
B(x) =
x +
x +
x +
x
2
3
4
5
= 10x2 + 10x3 + 5x4 + x5 ,
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
and so
C(x) = A(x)B(x)
= (1 + 6x2 + x4 )(10x2 + 10x3 + 5x4 + x5 )
= 10x2 + 10x3 + 65x4 + 61x5 + 40x6 + 16x7 + 5x8 + x9 .
This generating function tells us exactly how many ways Matt can choose n pieces of fruit. For example,
the number of ways that Matt can choose 6 pieces of fruit is 40, the coefficient of x6 , as computed above. 
More generally, we have the following result.
Theorem 5.2. (The Product Formula) We are given two disjoint sets A and B. We are also given that
the number of ways to choose n elements from A is an , and the number of ways to choose n elements
from B is bn . Let cn be the number of ways to choose n elements (as a subset) from A B.
Let A(x), B(x), and C(x) be the generating functions of the sequences (an ), (bn ), and (cn ), respectively.
Then C(x) = A(x)B(x).

Remarks: The number of ways to choose elements from a set can be the traditional nk formula, but it can
be completely arbitrary. For example, in the problem above, Matt may decide that if he chooses 4 bananas,

then there are only 2 sets of 4 bananas that he likes. In this case, b4 = 2 instead of b4 = 54 = 5.
Problem 5.3. Paige has a collection of two algebra books (which are identical) and three geometry
books (which are identical). Let cn be the number of ways Paige can choose n of her books. Find the
generating function of (cn ).

Solution: Since both algebra books are identical, there is only one way to choose i algebra books, for
0 i 2. Hence, the generating function corresponding to the algebra books is 1 + x + x2 . Similarly,
the generating function corresponding to the geometry books is 1 + x + x2 + x3 . Therefore, the generating
function of (cn ) is
(1 + x + x2 )(1 + x + x2 + x3 ) = 1 + 2x + 3x2 + 3x3 + 2x4 + x5 .

To verify the coefficients in the generating function, we list the possible combinations of algebra books and
geometry books in the following table:

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
n
0
1
2

3
4
5

Combinations of n books
No books
One algebra book,
one geometry book
Two algebra books,
one algebra book and one geometry book,
two geometry books
Two algebra books and one geometry book,
one algebra book and two geometry books,
three geometry books
Two algebra books and two geometry books,
one algebra book and three geometry books,
Two algebra books and three geometry books

Number of Combinations
1
2
3

3
2
1

Problem 5.4. Let sn denote the number of ways to obtain a sum of n by rolling two standard six-sided
dice. What is the generating function of (sn )?
Solution: . The generating function of a single die is x + x2 + x3 + x4 + x5 + x6 , so the generating function for
the sum of two dice is
(x + x2 + x3 + x4 + x5 + x6 )2
= x2 + 2x3 + 3x4 + 4x5 + 5x6 + 6x7 + 5x8 + 4x9 + 3x10 + 2x11 + x12 .
For example, the number of ways to obtain the sum 10 is 3, the coefficient of x10 . (These three ways are
rolling a 4 and a 6, a 5 and a 5, and a 6 and a 4.)

Problem 5.5. We have three pennies, four nickels, and two quarters. Find the generating function of
the number of ways we can make change for n cents.

Solution: We assume that the coins of each denomination are indistinguishable, so for example, when
considering the combinations of pennies, only the number of pennies is relevant. Hence, there is only one
way to form i cents from the three pennies, for 0 i 3, and there are no ways otherwise, so the generating
function corresponding to the pennies is 1 + x + x2 + x3 .
Similarly, there is only one way to form i cents from the four nickels if 0 i 20 and i is divisible
by 5, and there are no ways otherwise, so the generating function corresponding to the four nickels is
1 + x5 + x10 + x15 + x20 . Finally, the generating function corresponding to the two quarters is 1 + x25 + x50 .
Therefore, the generating function of the number of ways we can make change for n cents is
(1 + x + x2 + x3 )(1 + x5 + x10 + x15 + x20 )(1 + x25 + x50 ).

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

Generating Functions
What if the coins are distinguishable? If the coins are distinguishable, then for the pennies, for example, the
question is not how many pennies are present, but whether each penny is present or not (since we can tell
them apart). The generating function for each penny is 1 + x, and there are three pennies, so the generating
function corresponding to the pennies is now (1 + x)3 . Similarly, the generating function corresponding to
the nickels is (1 + x5 )4 , and the generating function corresponding to the quarters is (1 + x25 )2 . Therefore, if
the coins are distinguishable, then the generating function of the number of ways we can make change for
n cents is
(1 + x)3 (1 + x5 )4 (1 + x25 )2 .

Exercises
5.1. Find the number of ways to collect $15 from 20 people if each of the first 19 people can give a dollar
or nothing, and the twentieth person can give either $1, $5, or nothing.
5.2.

Show that the generating function of the number of integer solutions to


x1 + x2 + x3 + x4 = n,

where 0 x1 x2 x3 x4 , is

1
(1 x)(1

x2 )(1

x3 )(1 x4 )

The Binomial Theorem

Consider the product

(1 + x)n = (1 + x)(1 + x) (1 + x),


|
{z
}
n factors
k

where n is a positive integer. The coefficient of x in this product is the number of ways we can choose a
term from each of the n factors, such that their product is equal to xk . We see that k of these terms must be
equal to x and the remaining
n k of these terms must be equal to 1. The number of ways to choose k xs

among n xs is simply nk , so
!
!
!
!
n
n
n 2
n n
n
(1 + x) =
+
x+
x + +
x .
0
1
2
n

This is, of course, the Binomial Theorem. Hence, we can view (1 + x)n as the generating function of nk ,
where n is fixed integer.
We can generalize this result: The Generalized Binomial Theorem states that
!
!
!

2
(1 + x) =
+
x+
x + ,
0
1
2
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

10

Generating Functions
where

!
( 1)( 2) ( k + 1)

,
=
k!
k


and can be any real number. One could take either of these as a definition for k and prove the other. The
Binomial Theorem is the case where is a positive integer. We will soon outline a proof of the theorem for
negative integer exponents.

As an example, the generating function of 1 + x = (1 + x)1/2 is


!
!
!
!
1
1
1
1
2
2
2 2
2 3
+
x+
x +
x +
0
2
3
1
=1+

1
2

x+

1 1
2(2

1)

x2 +

1 1
2(2

1!
2!
1
1 3
1
= 1 + x x + x4 .
2
8
16
Can we derive the generating function of
can.

n
k ,

1)( 21 2)
3!

x3 +

where k is a fixed integer? The next problem shows that we

Problem 6.1. Let n be a nonnegative integer. Show that


!
!
!
1
n
n+1
n+2 2
=
+
x+
x + .
n
n
n
(1 x)n+1
Solution: Consider the product
1
= (1 + x + x2 + )(1 + x + x2 + ) (1 + x + x2 + ) .
(1 x)n+1 |
{z
}
n + 1 factors

The coefficient of x is the number of ways we can choose a term from each of the n + 1 factors, such that
their product is equal to xk . If the n + 1 terms we choose are xa1 , xa2 , . . . , xan+1 , then
k

a1 + a2 + + an+1 = k.
k

Hence, the coefficient of x is the number of solutions to this equation in nonnegative integers.
To count the number of solutions, we represent each solution as a string of symbols (stars) and | symbols
(bars). (This is known as a stars-and-bars argument.) For example, for n = 4 and k = 9, the solution
2 + 0 + 3 + 1 + 3 = 9 becomes the string
|| | | .
Hence, for each solution, we obtain a string consisting of k stars and n bars. Furthermore, every arrangement

of k stars and n bars corresponds to a different solution, so the number of solutions is n+k
n , which is also the
coefficient of xk .

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

11

Generating Functions
Problem 6.2. Derive a formula for the sum 12 + 22 + + n2 .
Solution: In a previous problem, we derived that
12 x + 22 x2 + 32 x3 + =

x + x2
.
(1 x)3

We can obtain the sequence of partial sums by dividing by 1 x:


12 x + (12 + 22 )x2 + (12 + 22 + 32 )x3 + =

x + x2
.
(1 x)4

c
We want to express this fraction as the sum of fractions of the form (1x)
k . We can use the method of partial
fractions, or we can use a substitution: Let y = 1 x. Then x = 1 y, and

(1 y) + (1 y)2
x + x2
=
(1 x)4
y4
y2 3y + 2
y4
1
3
2
= 2 3+ 4
y
y
y
1
3
2
=

+
.
(1 x)2 (1 x)3 (1 x)4
=

By the previous result,


1
3
2

+
=
2
3
(1 x)
(1 x)
(1 x)4

" !
!
!
#
1
2
3 2
+
x+
x +
1
1
1
" !
!
!
#
2
3
4 2
3
+
x+
x +
2
2
2
" !
!
!
#
3
4
5 2
+2
+
x+
x + .
3
3
3

The coefficient of xn in this expression is


!
!
!
(n + 2)(n + 1)
(n + 3)(n + 2)(n + 1)
n+1
n+2
n+3
3
+2
=n+13
+2
1
2
3
2
6
n3 n2 n
+
+
3
2
6
n(n + 1)(2n + 1)
=
.
6
=


www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

12

Generating Functions
Exercises
6.1. The sequence (an ) is defined by a0 = 0, a1 = 2, and an = 4an1 4an2 for all n 2. Find the generating
function of this sequence, and use it to solve for an .
6.2. How many solutions in positive integers are there to the equation y1 + y2 + y3 + y4 = 30 such that no
yi is greater than 12?
Let n be a positive integer. Show that

6.3.

Fn =

!
!
!
n1
n2
n3
+
+
+ ,
0
1
2

where Fn denotes the nth Fibonacci number.


Hint:

6.4.

1
= 1 + (x + x2 ) + (x + x2 )2 + .
1 x x2
Expand
1
= (1 x)n1
(1 x)n+1

using the Generalized Binomial Theorem.

Roots of Unity Filter

We begin with an example.


Problem 7.1. An unfair coin has a 2/3 probability of turning up heads. If this coin is tossed 50 times,
what is the probability that the total number of heads is even? (AHSME, 1992)
Solution: Let p = 2/3 and q = 1/3. We wish to compute
!
!
50 48 2
50 47 4
p50 +
p q +
p q + + q50 .
2
4
This is the set of terms with even expoents from the Binomial Theorem expression
!
!
50 49
50 48 2
(p + q)50 = p50 +
p q+
p q + + q50 .
1
2
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

13

Generating Functions
Now we need to find a way to eliminate the odd terms. We can find a similar expression by making the
sign on q negative, as in
!
!
!
50 49
50 48 2
50 47 3
50
50
(p q) = p
p q+
p q
p q + + q50 .
1
2
3
Now were done. When we add these equations and dividing by 2, we find
!
!


1
1
50 48 2
50 47 4
1
50
1 + 50 .
p +
p q +
p q + + q50 = [(p + q)50 + (p q)50 ] =
2
4
2
2
3

This is reasonable since it is very close to 21 . We can make this a little fancier by adding a variable to our
Binomial Theorem expression.
Solution: Let p = 2/3 and q = 1/3. We wish to compute
!
!
50 48 2
50 47 4
50
p +
p q +
p q + + q50 .
2
4
By the Binomial Theorem,
(p + qx)

50

!
!
50 49
50 48 2 2
=p +
p qx +
p q x + + q50 x50 .
1
2
50

Taking x = 1, we get
(p + q)

50

!
!
50 49
50 48 2
=p +
p q+
p q + + q50 .
1
2

(p q)

50

!
!
50 49
50 48 2
=p
p q+
p q + + q50 .
1
2

50

Taking x = 1, we get
50

Adding these equations and dividing by 2, we find


!
!


50 48 2
50 47 4
1
1
1
50
1 + 50 .
p +
p q +
p q + + q50 = [(p + q)50 + (p q)50 ] =
2
4
2
2
3

Suppose for example that we are given a generating function


A(x) = a0 + a1 x + a2 x2 + a3 x3 + ,
and we want to extract the series

a0 + a3 x3 + a6 x6 + .

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

14

Generating Functions
We can do so using a roots of unity filter.
Let = e2i/3 , so 3 = 1 and , 1. Then
A(x) =

an xn = a0 + a1 x + a2 x2 + a3 x3 + ,

n=0

A(x) =

n an xn = a0 + a1 x + 2 a2 x2 + 3 a3 x3 + ,

n=0

A(2 x) =

2n an xn = a0 + 2 a1 x + 4 a2 x2 + 6 a3 x3 + .

n=0

Hence,
A(x) + A(x) + A(2 x) =

(1 + n + 2n )an xn .

n=0

If n is divisible by 3, then 1 + +
n

2n

= 1 + 1 + 1 = 3. Otherwise, n , 1 and
1 + n + 2n =

Therefore,

3n 1
= 0.
n 1

A(x) + A(x) + A(2 x) = 3a0 + 3a3 x3 + 3a6 x6 + ,

which means
a0 + a3 x3 + a6 x6 + =

1
[A(x) + A(x) + A(2 x)].
3

More generally, we can use the nth roots of unity to extract every nth term of a generating function.
Problem 7.2. For a nonnegative integer n, let
Sn =

!
!
!
n
n
n
+
+
+ .
0
3
6

(a) Show that


Sn =



1 n
n
2 + 2 cos
3
3

for all n 0.
Solution: (a) Let = e2i/3 , so 3 = 1 and , 1. Then 3 1 = 0, which factors as
( 1)(2 + + 1) = 0.
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

15

Generating Functions
Since 1 , 0, satisfies the equation 2 + + 1 = 0.
By the Binomial Theorem,
(1 + x)n =

!
!
!
!
n 3
n 2
n
n
x + .
x +
x+
+
3
2
1
0

Then from our work above,


Sn =

!
!
!
n
n
n
1
+
+
+ = [(1 + 1)n + (1 + )n + (1 + 2 )n ].
0
3
6
3

Since 2 + + 1 = 0, we have that


1 + = 2 = e4i/3 = ei e4i/3 = e7i/3 = ei/3 ,
and

1 + 2 = = e2i/3 = ei e2i/3 = e5i/3 = ei/3 ,

so
1 n
(2 + eni/3 + eni/3 )
3


1 n
n
n
n
n
=
2 + cos
+ i sin
+ cos
i sin
3
3
3
3
3


1 n
n
=
2 + 2 cos
.
3
3

Sn =

Exercises
7.1.

Given A(x) = a0 + a1 x + a2 x2 + a3 x3 + , express


a1 x + a4 x4 + a7 x7 +

in terms of A(x).
7.2.

Show that

and that

!
!
!
!
n
n
n
n
n
,

+ = 2n/2 cos
4
0
2
4
6
!
!
!
!
n
n
n
n
n

+ = 2n/2 sin
.
1
3
5
7
4

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

16

Generating Functions
7.3.

Consider Sn from Problem ?? Find polynomials p(x) and q(x) with integer coefficients such that

p(x) X
=
Sn xn .
q(x) n=0

Partitions

Given a positive integer n, a partition of n is an unordered sum of positive integers that sum to n. For
example, there are five partitions of the number 4, namely 4, 3 + 1, 2 + 2, 2 + 1 + 1, and 1 + 1 + 1 + 1. Since the
order does not matter, the sums 3 + 1 and 1 + 3 represent the same partition. Let p(n) denote the number of
partitions of n. The generating function of the partition function p(n) is
p(0) + p(1)x + p(2)x2 +
= (1 + x + x2 + x3 + )(1 + x2 + x4 + x6 + )(1 + x3 + x6 + x9 + )
1
.
=
(1 x)(1 x2 )(1 x3 )
There is no simple closed formula for p(n), but we can still derive many interesting partition identities using
generating functions.
Problem 8.1. Prove that the number of partitions of n with distinct parts is equal to the number of
partitions of n with only odd parts.

Solution: If we have a partition with distinct parts, then each part appears at most once, so the generating
function of the number of partitions of n with distinct parts is
(1 + x)(1 + x2 )(1 + x3 ) .
The generating function of the number of partitions of n with only odd parts is
(1 + x + x2 + x3 + )(1 + x3 + x6 + x9 + )(1 + x5 + x10 + x15 + )
1
=
.
(1 x)(1 x3 )(1 x5 )

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

17

Generating Functions
To make this generating function look more like the first generating function, we multiply the numerator
and denominator by (1 x2 )(1 x4 )(1 x6 ) :
1
(1 x)(1 x3 )(1 x5 )
(1 x2 )(1 x4 )(1 x6 )
=
(1 x)(1 x2 )(1 x3 )
(1 + x)(1 x)(1 + x2 )(1 x2 )(1 + x3 )(1 x3 )
=
(1 x)(1 x2 )(1 x3 )
= (1 + x)(1 + x2 )(1 + x3 ) .
Thus, the two generating functions coincide, which means that the number of such partitions is equal.

Exercises
8.1.

Find a simple expression for

(1 + x2 ) = (1 + x)(1 + x2 )(1 + x4 )(1 + x8 ) .

k=0

8.2. Prove that the number of partitions of n into odd parts greater than 1 equals the number of partitions
of n into distinct parts that are not powers of 2.

Review Problems
1.

(Vandermondes Identity) Let m, n, and k be nonnegative integers such that k m and k n. Prove that
!
! !
!
!
!
!
! !
m+n
m n
m
n
m
n
m n
=
+
+
+ +
.
k
0 k
1 k1
2 k2
k 0

2.

If the expansion in powers of x of the function


1
(1 ax)(1 bx)

is given by c0 + c1 x + c2 x2 + c3 x3 + , prove that the expansion in powers of x of the function


1 + abx
(1 abx)(1 a2 x)(1 b2 x)
www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

18

Generating Functions
is given by c20 + c21 x + c22 x2 + c23 x3 + . (Putnam, 1939)
3.

(Hockey Stick Identity) Let n and k be nonnegative integers, with n k. Prove that
!
!
!
!
!
k
k+1
k+2
n
n+1
+
+
+ +
=
.
k
k
k
k
k+1

4.

Let

X
1
=
an,m xn ym .
1 x xy n,m=0

Find an,m .
5.

Find the sequence (an ) if a0 = 1 and

n
X

ak ank = 1

k=0

for all n 0.

Challenge Problems
6.

The sequences (an ) and (bn ) are defined by a0 = 1, b0 = 0, and


an = 3an1 + 4bn1 ,
bn = 2an1 + 3bn1

for all n 1. Find the generating functions of these sequences, and use them to solve for an and bn .
7.

Consider the power series expansion

X
1
=
an xn .
1 2x x2 n=0
Prove that, for each integer n 0, there is an integer m such that a2n + a2n+1 = am . (Putnam, 1999)
8.

Let

1996
Y
n
(1 + nx3 ) = 1 + a1 xk1 + a2 xk2 + + am xkm ,
n=1

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

19

Generating Functions
where a1 , a2 , . . . , am are nonzero and k1 < k2 < < km . Find a1996 . (Turkey, 1996)
9.

Let

(1 + x + x2 + x3 + x4 )496 = a0 + a1 x + a2 x2 + + a1984 x1984 .

Determine gcd(a3 , a8 , a13 , . . . , a1983 ). (IMO Proposal, 1983)

www.artofproblemsolving.com
Sponsored by the D.E. Shaw group, Two Sigma Investments LLC, Jane Street Capital, Citadel LLC, and Dropbox

20

Вам также может понравиться