Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Generating Functions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Generating Functions

Wintercamp 2020

1 Motivating Example
In many problems, especially in recurrence relations, we encounter a sequence of numbers a0 , a1 , . . . , an , . . .,
indexed by the natural numbers. It turns out to be very convenient to be able to put all these num-
bers together in one object, like a laundry line. We can do this by making them the coefficients of
a formal power series:

X
2 n
f (x) = a0 + a1 x + a2 x + · · · + an x + · · · = ai x i .
n=0

We will generally not worry about the convergence of this series and usually the x’s are just there
as place holders. However, we will encounter a couple of problems and some techniques where it
does become important that we can substitute values for x, so don’t completely forget about this.
The idea will be that we can manipulate the power series in ways that will help us find a closed
formula for the an as a function of n. This will usually happen by recognizing the power series
as representing well-known functions that we can easily manipulate. For instance, we know that
n+1
1 + r + r2 + · · · + rn = 1−r
1−r
. When we assume that |r| < 1, this implies that

2
X 1
1 + x + x + ··· = xn =
n=0
1−x
This is one of the basic series we will be working with and derive others from it.
Here is a first problem to warm up to some of the basic ideas.

Example 1. Let an = 5an−1 − 6an−2 with a0 = 2 and a1 = 5. Find a closed formula for an as a
function of n.

2 Some Results on Infinite Series


One of the things that makes generating functions very useful, is the fact that they connect se-
quences to functions and one can easily multiply functions. The result for sequences may at first
be surprising:
A(x) = n≥0 an xn , B(x) = n≥0 bn xn , their product
P P
Definition 1. Given two generating functionsP
A(x)B(x) is the generating function C(x) = n≥0 cn xn with coefficients
n
X X
cn = ak bn−k = ai b j .
k=0 i+j=n

1
The sequence (cn ) is called the Cauchy product of (an ) and (bn ).

It will often be convenient to recognize a sequence as a Cauchy product of two other sequences
and use the generating functions directly to obtain a solution. One general type of situation where
this occurs is:

Proposition 1. If A is a family of sets and ak is the number of sets of “weight” k in A and B is


a family of sets and bk is the number of sets of “weight” k is in B, then cn is the number of pairs
of a set from A and set from B of total “weight” n. We can therefore write
X X X
A(x) = x|a| , B(x) = x|b| , C(x) = x|c|
a∈A b∈B c=(a,b)∈A×B

where |a| is the weight of a, and |c| = |a| + |b|.

Example 2. Find the number an of ways n dollars can be changed into 1 or 2 dollar coins (regardless
of order). For example, when n = 3, there are two ways, namely three 1 dollar coins or one 1 dollar
coin and one 2 dollar coin.

Example 3. (1998 IMO Shortlisted Problem) Let a0 , a1 , a2 , . . . be an increasing sequence of nonneg-


tive integers such that every nonnegatve integer can be expressed uniquely in the form ai +2aj +4ak ,
where i, j and k are not necessarily distinct. Determine a1998 .

Here are two other natural operations on sequences: taking partial sums gives us a new sequence
for which the generating function can be expressed in terms of the original generating function. The
reverse operation is that of taking finite differences.

Proposition 2. Let A(x) = n≥0 an xn be the generating function of (an ) and define sn = a0 +
P
a1 + · · · + an . Then the generating function for (sn ) is
X A(x) X
S(x) = s n xn = = A(x)(1 + x + x2 + · · · ) = A(x) xn .
n≥0
1−x n≥0

Corollary 1. Define d0 = a0 , dn = an − an−1 . Then


X
D(x) = dn xn = (1 − x)A(x).
n≥0

Example 4. Derivatives and antiderivatives can be very helpful in creating new generating func-
tions.

1. Given that A(x) = n≥0 an xn , what is the generating function for bn = nan ?
P

2. For any polyomial p(x), what is the generating function for bn = p(n)an ? In particular, what
is the generating function for bn = p(n)?

2
an
3. Given that A(x) = n≥0 an xn , what is the generating function for cn =
P
n+1
?

4. Compute nk=0 k+11 n


P 
k
.
Here are two other common generating functions:
X r 
r
1. Generalized binomial coefficients (1 + x) = xk for any real number r (if r is not
k≥0
k
 
r r(r − 1) · · · (r − k + 1)
a non-negative integer, assume that |x| < 1). Here = for k > 0
  k k!
r
and = 1.
0
X 1
2. The exponential function ex = xk
k≥0
k!

From these you can derive the following:


1 X  k + m
1. m+1
= xk
(1 − x) k≥0
m

xm Xk
2. m+1
= xk
(1 − x) k≥0
m

1 X 2k 
3. √ = xk
1 − 4x k≥0 k

1 X xn
4. ln =
1 − x n≥1 n

3 Linear Recurrence Relations


Homogeneous linear recurrence relations, i.e., recurrence relations of the form an = b1 an−1 +b2 an−2 +
· · · + bk an−k with initial values a0 , a1 , . . . , ak−1 can be solved very nicely using generating functions.
We saw this in our first example. (Although you may sometimes need to use complex numbers.)
If the denominator of the generating function does not have repeated factors, the general solution
is of the form an = c1 (α1 )n + · · · + ck (αk )n . Both the ci and αi can be found as we did in that
example, but you can also find the αi as roots of the characteristic polynomial:

xk − b1 xk−1 − b2 xk−2 − · · · − bk = 0

You can then find the ci by solving a system of linear equations to ensure that the first k values,
a0 , a1 , . . . , ak−1 are correct.

3
If there is a repeated root in this polynomial (or equivalently, there is a repeated factor in the
denominator of the generating function), say β has multiplicity m (this would mean that (1 − βx)m
is a factor of the denominator of the generating function), then we need to add c1 β n + c2 nβ n +
· · · + cm nm−1 β n to the sum for the solution. We see that in our partial fractions approach as well,
because we have to use fractions with all powers (1 − βx)` with 1 ≤ ` ≤ m. In particular, here we
see that we can just treat the generating functions as usual and we will get our solution.
Recurrence relations of the form an = b1 an−1 + b2 an−2 + · · · + bk an−k + f (n) are still linear,
but not homogeneous. In this case, we need to find one special solution for this system (not
thinking about the initial conditions at this point) and then the general solution can be obtained
by taking the special solution and adding the general solution of the homogeneous equation an =
b1 an−1 + b2 an−2 + · · · + bk an−k . If you do this with the generating functions, you will get the answer
in the usual way.
Here are some examples:

Example 5. Towers of Hanoi There are three pegs and there are n disks of all different sizes. At
the beginning of the game these disks are all stacked on one peg in order of decreasing size, with
the largest on the bottom. The goal of the game is to transfer all disks onto one of the other pegs,
but at no time can we put a larger disk on top of a smaller one. The third peg can be used to take
the extra steps needed to avoid this.
Let hn be the number of moves required to transfer n disks. Obviously, h0 = 0 andh1 = 1,
and it is not hard to check that h2 = 3. It s not hard to develop a recurrence relation for hn :
if we can the top transfer n − 1 disks to another peg, then move our largest disk to the empty
peg and then move the other n − 1 disks again, we will have them all in the right spot. So
hn = 2hn−1 + 1 for n ≥ 1 and h0 = 0. We could find a formula for hn by iteration. You may check
n −1
that hn = 2n−1 + · · · + 22 + 2 + 1 = 22−1 = 2n − 1.
However, things don’t always work so nicely, so it is useful to see how our more general method
can work here. Let g(x) = n≥0 hn xn . Then
P

g(x) = h0 + h1 x + h2 x2 + · · · + hn xn + · · ·
2xg(x) = 2h0 x + 2h1 x2 + · · · + 2hn−1 xn + · · ·

and using the recurrence relation we get


x
(1 − 2x)g(x) = x + x2 + · · · + xn + · · · = .
1−x
So we see that
x
g(x) =
(1 − x)(1 − 2x)

4
Using partial fractions we find
1 1
g(x) = −
1 − 2x 1 − x
X X
= (2x)n − xn
n≥0 n≥0
X
= (2 − 1)xn .
n

n≥0

And so we find again that hn = 2n − 1.


Below are two problems where you may have to work with particular solutions. The particular
solutions will look a lot like the function f (n). Here are two special cases:
• if f (n) is a polynomial of degree k in n, try for your special solution to find a polynomial of
degree k in n as well: find coefficients p0 , p1 , . . . , pk such that hn = p0 + p1 n + · · · + pk nk is a
solution.
• if f (n) = dn , find a coefficient p such that hn = pdn is a solution.
Example 6. 1. Solve hn = 3hn−1 − 4n for n ≥ 1 and h0 = 2.
2. Solve hn = 2hn−1 + 3n for n ≥ 1 and h0 = 2.
Problems 1. 1. Words of length n, using only the three letters a, b and c are to be transmit-
ted over a communication channel subject to the condition that no work in which two a’s
appear consecutively is to be transmitted. Determine the number of words allowed by the
communication channel.
2. Find the general solution of the recurrence relation
hn − 4hn−1 + 4hn−2 = 0 for (n ≥ 2).

4 Products and Partitions


One place where products of generating functions are very useful is in counting the number of
partitions of a positive integer n. A partition of n is a sequence a1 ≤ a2 ≤ · · · ≤ ak such that
P k
i=1 ai = n. A partition is uniquely determined by the number of 1s, the number of 2s, the
number of 3s etc., so the repetition number of each of the numbers used. We can use this to build
a generating function. We devote one factor to each integer:
∞ X
Y ∞
2 3 2 4 6 k 2k 3k
(1 + x + x + x + · · · )(1 + x + x + x + · · · ) · · · (1 + x + x +x + ···)··· = xik
k=1 i=0

Y 1
= k
.
k=1
1 − x

5
When we expand this product, we pick one term from each factor in all possible ways, but only a
finite number of terms that are not a 1. If we take an x4 from the first factor, an x2 from the second
factor and an x25 from the fifth factor, this means that we have taken four 1’s, one 2, and five 5’s.
So we have the partition 1 + 1 + 1 + 1 + 2 + 5 + 5 + 5 + 5 + 5 = 31. We see that the coefficient for
xk gives the number of partitions of k. Note that although this is an infinite product, in practice
we only need a finite number of factorsand a finite number of terms to find a particular pn .
Example 7. Find p8 , the number of partitions of 8.
We can further manipulate the generating function above to obtain other generating functions.
Do this to solve the following problem.
Example 8. Find the generating function for partitions into all distinct parts, and the generating
function for partitions into odd parts. Show that for any positive integer n, the number of partitions
into distinct parts is the same as the number of partitions into odd parts.
Problems 2. 1. Find the number hn of bags of fruit that can be made out of apples, bananas,
oranges and pears, where, in each bag, the number of apples is even, the number of bananas
is a multiple of 5, the number of oranges is at most 4, and the number of pears is 0 or 1.
2. Let kn denote the number of nonnegative integral solutions of the equation
3e1 + 4e2 + 2e3 + 5e4 = n
Find the generating function g(x) for the hn .
3. There is available an unlimited number of pennies, nickles, dimes, quarters and half-dollar
pieces. Determine the generating funciton g(x) for the number fn of ways of making n cents
with these pieces.
4. Let hn denote the number of ways of dividing a convex polygonal region with n + 1 sides into
triangles be inserting diagonals that do not intersect in the interior of the region. Find both
the generating function and a closed formula for the hn . Note that these are the Catalan
numbers.

5 Cyclotomic Polynomials and Roots of Unity


When working with the polynomials of the form 1 + x + · · · + xn is is often useful to remember
that this is a factor of xn+1 − 1 = (x − 1)(1 + x + · · · + xn ). Further factors are useful to recognize
as well. Note that by the fact that the roots of xn − 1 are the n-th roots of unity (e2kπi/n ), we see
that xm − 1 divides xn − 1 if and only if m divides n. For specific values of n this can lead to some
unexpected relations between generating functions. Here is a nice example.
1. Give the generating function n≥0 pn,d xn for the probability pn,d of rolling a
P
Example 9.
sum of n with d ordinary six-sided dice.

6
2. Use this to show that the probability distribution of rolling two normal six-sided dice is the
same as the probability distribution of rolling a die with sides 1, 2, 2, 3, 3, 4 and a die with
sides 1, 3, 4, 5, 6, 8.
Roots of unity have yet another role to play here. Let m be any positive integer and let λ be
an m-th root of unity other than 1. When we consider a power series
X
B(x) = bn x n
n≥0

we are sometimes interested in finding the sum of the coefficients that have an index that is a
multiple of m (for instance, we may consider the sum of the even-indexed coefficients),
bm + b2m + b3m + · · ·
Here is we can use the following
1 − λmj
1 + λj + λ2j + · · · + λ(m−1)j = =0
1 − λj
for any j that is not divisible by m (since λm = 1). On the other hand, if j is a multiple of m, we
see that
1 + λj + λ2j + · · · + λ(m−1)j = m
So we get that
m−1
1 X
B(λj ) = bm + b2m + b3m + · · ·
m j=0
so evaluating the generating function at this sum of m-th roots of unity allows us to filter out the
sum of coefficients indexed by the multiples of m.
For odd m, we have a further useful factorization:
1 + tm = (1 + t)(1 + λt)(1 + λ2 t) · · · (1 + λm−1 t)
since both polynomials are monic of degree m and have roots −1/λi for i = 0, 1, 2, . . . , m − 1.
Problems 3. 1. Can the set N of all positive integers be partitioned into morethan one, but still
a finite number of arithmetic progressions with no two having the same common differences?
2. (IMO 1995) Let p be an odd prime number. Find the number of subsets A of the set
{1, 2, . . . , 2p} such that
(a) A has exactly p elements, and
(b) the sum of all the elements in A is divisible by p.
3. An a × b rectangle can be tiled by a number of p × 1 and 1 × q types of rectangles, where
a, b, p, q are fixed positive integers. When we tile with these rectangles the orientation is fixed,
so a k × 1 and a 1 × k rectangle are different for this purpose. Prove that a is divisible by p
or b is divisible by q.

7
6 Further Problems
1. Let Fn be the n-th Fibonacci number. Show that
X Fn
=2
n≥1
2n

2. Prove that for any positive integer n,


       
n n n n
+2 +3 + ··· + n = n2n−1 .
1 2 3 n

3. Show that      
2n 2n 1 2n
− =
n n+1 n+1 n
4. Prove that for any positive integer n,
 2  2  2  2  
n n n n 2n
+ + + ··· + =
0 1 2 n n

5. (Putnam 1992, B2) For nonnegative integers n and k, define Q(n, k) to be the coefficient of
xk in the expansion of (1 + x + x2 + x3 )n . Prove that
k   
X n n
Q(n, k) = .
j=0
j k − 2j

6. Let a0 = 1 and a1 = 1 and an = 4an−1 − 4an−2 for n ≥ 2. Find a formula for an in terms of n.
7. Let n be a positive integer. Find the number an of polynomials P (x) with coefficients in
{0, 1, 2, 3} such that P (2) = n.
8. Consider a 1-by-n chessboard, suppose that we colour each square of the chessboard with one
of the two colours red and blue. Let hn be the number of colourings in which no two squares
that are coloured red are adjacent. Find and verify a recurrence relation that hn satisfies.
Then derive a formula for hn .
9. Find a recursion for the number of ways to place flags on an n foot pole, where we have red
flags that are 2 feet high, blue flags that are 1 foot high and yellow flags that are 1 foot high.
The heights of the flags must add up to n. Solve the recursion.
10. Find a recurrence for the sequence (un ) such that un is the number of pairs (a, b) of nonnegative
numbers such that
2a + 5b = n

8
11. How many positive numbers are there less than 10, 000, 000 whose digits sum to 10?

12. Let
1 · 3 · 5 · · · (2n − 1)
an = .
2n n!
Show that a0 , a1 , a2 , . . . is the unique sequence satisfying a0 = 1 and
n
X
a)kan−k = 1
k=0

13. (HMMT 2007) Let S denote the set of triples (i, j, k) of positive integers where i + j + k = 17.
Compute X
ijk.
(i,j,k)∈S

14. Let Sn be the number of triples (a, b, c) of nonnegative integers such that a + 2b + 3c = n.
Compute the sum

X Sn
n=0
3n

15. (Putnam 2003, A6) For a set S of nonnegative integers, let rS (n) denote the number of ordered
pairs (s1 , s2 ) such that s1 , s2 ∈ S, s1 6= s2 and s1 + s2 = n. Let A be the set of nonnegative
integers that have an odd number of ones in their binary representation, and let B be the set
of nonnegative integers that have an even number of ones in their binary representation.Show
that rA (n) = rB (n) for all n.

16. (IMO2008, problem 5) Let n and k be positive integers with k ≥ n and k − n an even number.
Let 2n lamps labelled 1, 2, . . . , 2n be given, each of which can be either on or off. Initially all
lamps are off. we consider sequences of steps: at each step one of hte lamps is switched (from
on to off or from off to on).
Let N be the number of such sequences consisting of k steps and resulting in the state where
the lamps 1 through n are all on, and lamps n + 1 through 2n are all off.
Let M be the number of such sequences consisting of k steps, resulting in the state where
lamps 1 through n are all on, and lamps n + 1 through 2n are all off, but where none of the
lamps n + 1 through 2n is ever switched on.
Determine the ratio M/N .

17. (Leningrad Mathematical Olympiad, 1991) A finite sequence a1 , a2 , . . . , an is called p-balanced


if any sum of the form ak + ak+p + ak+2p + · · · is the same for any k = 1, 2, . . . , p. Prove that
if a sequence with 50 members is p-balanced for p = 3, 5, 7, 11, 13, 17, then all its members are
equal to zero.

9
18. Let hn denote the number of regions into which a convex polygonal region with n + 2 sides
is divided by its diagonals, assuming that no three diagonals have a common point. Define
h0 = 0. Show that  
n+1
hn = hn−1 + + n, (n ≥ 1).
3
Then determine the generating function for hn and obtain a formula for hn .

19. A partition of a set S is a S collection of non-empty subsets Ai ⊆ S, 1 ≤ i ≤ k (the parts


of the partition), such that ki=1 Ai = S and for every i 6= j, Ai ∩ Aj = ∅. For example, a
partitiion of {1, 2, 3, 4, 5} is {{1, 3}, {4}, {2, 5}}.
Suppose the integers 1, 2, 3, . . . , n are arranged on a circle, in order around the circle. A
partition of {1, 2, 3, . . . , n} is a non-crossing partition if it satisfies the additioinal property:
if w and v are in some part Ai and x and y are in a different part Aj , then the line joining w and
v does not cross the line joining x and y. The partition in the example is not a non-crossing
partition: the line 1 − 3 crosses the line 2 − 5.
Find the number of non-crossing partitions of {1, 2, 3, . . . , n}.

20. Consider a set of 2n people sitting around a table. In how many ways can we arrange for each
person to shake hands with another person at the table such that no two handshakes cross?

10

You might also like