Combinatorics (Fall 2010)/Generating functions
Contents
Generating Functions
In Stanley's magnificent book Enumerative Combinatorics, he comments the generating function as "the most useful but most difficult to understand method (for counting)".
The solution to a counting problem is usually represented as some depending a parameter . Sometimes this is called a counting function as it is a function of the parameter . can also be treated as a infinite series:
The ordinary generating function (OGF) defined by is
So . An expression in this form is called a formal power series, and is the sequence of coefficients.
Furthermore, the generating function can be expanded as
 G(x)=
so it indeed "generates" all the possible instances of the objects we want to count.
Usually, we do not evaluate the generating function on any particular value. remains as a formal variable without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence
 .
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.
Combinations
Suppose we wish to enumerate all subsets of an set. To construct a subset, we specifies for every element of the set whether the element is chosen or not. Let us denote the choice to omit an element by , and the choice to include it by . Using "" to represent "OR", and using the multiplication to denote "AND", the choices of subsets of the set are expressed as
 .
For example, when , we have
 .
So it "generate" all subsets of the 3set. Writing for and for , we have . The coefficient of is the number of subsets of a 3element set.
In general, has the coefficients which are the number of subsets of fixed sizes of an element set.
Suppose that we have twelve balls: 3 red, 4 blue, and 5 green. Balls with the same color are indistinguishable.
We want to determine the number of ways to select balls from these twelve balls, for some .
The generating function of this sequence is
The coefficient of gives the number of ways to select balls.
Fibonacci numbers
Consider the following counting problems.
 Count the number of ways that the nonnegative integer can be written as a sum of ones and twos (in order).
 The problem asks for the number of compositions of with summands from . Formally, we are counting the number of tuples for some such that and .
 Let be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of ; or starts with a 2, in which case the rest is a composition of . So we have the recursion for that
 .
 Count the ways to completely cover a rectangle with dominos without any overlaps.
 Dominos are identical rectangles, so that only their orientations  vertical or horizontal matter.
 Let be the solution. It also holds that . The proof is left as an exercise.
In both problems, the solution is given by which satisfies the following recursion.
is called the Fibonacci number.
Theorem  ,
 where and .
The quantity is the socalled golden ratio, a constant with some significance in mathematics and aesthetics.
We now prove this theorem by using generating functions. The ordinary generating function for the Fibonacci number is
 .
We have that for , thus
For generating functions, there are general ways to generate and , or the coefficients with any smaller indices.
So we have
 ,
hence
 .
The value of is the coefficient of in the Taylor series for this formular, which is . Although this expansion works in principle, the detailed calculus is rather painful.
It is easier to expand the generating function by breaking it into two geometric series.
Proposition  Let and . It holds that
 .
 Let and . It holds that
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.

Note that the expression has a well known geometric expansion:
 .
Therefore, can be expanded as
So the th Fibonacci number is given by
 .
Solving recurrences
The following steps describe a general methodology of solving recurrences by generating functions.
 1. Give a recursion that computes . In the case of Fibonacci sequence
 .
 2. Multiply both sides of the equation by and sum over all . This gives the generating function
 .
 And manipulate the right hand side of the equation so that it becomes some other expression involving .
 .
 3. Solve the resulting equation to derive an explicit formula for .
 .
 4. Expand into a power series and read off the coefficient of , which is a closed form for .
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.
The second and the forth steps need some nontrivial analytic techniques.
Algebraic operations on generating functions
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of , which is easy; and then manipulating the resulting formal power series to express it in terms of , which is more difficult (because it works backwards).
We can apply several natural algebraic operations on the formal power series.
Generating function manipulation  Let and .
When manipulating generating functions, these rules are applied backwards; that is, from the righthandside to the lefthandside.
Expanding generating functions
The last step of solving recurrences by generating function is expanding the closed form generating function to evaluate its th coefficient. In principle, we can always use the Taylor series
 ,
where is the value of the th derivative of evaluated at .
Some interesting special cases are very useful.
Geometric sequence
In the example of Fibonacci numbers, we use the well known geometric series:
 .
It is useful when we can express the generating function in the form of . The coefficient of in such is .
Binomial theorem
The th derivative of for some real is
 .
By Taylor series, we get a generalized version of the binomial theorem known as Newton's formula:
Newton's formular (generalized binomial theorem) If , then
 ,
where is the generalized binomial coefficient defined by
 .
Example: multisets
In the last lecture we gave a combinatorial proof of the number of multisets on an set. Now we give a generating function approach to the problem.
Let be an element set. We have
 ,
where each species a possible multiset on with multiplicity function .
Let all . Then
The last equation is due to the the definition of . Our task is to evaluate .
Due to the geometric sequence and the Newton's formula
So
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of as the combinatorial proof.
Catalan Number
We now introduce a class of counting problems, all with the same solution, called Catalan number.
The th Catalan number is denoted as . In Volume 2 of Stanley's Enumerative Combinatorics, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.
 C_{n} is the number of Dyck words of length 2n. A Dyck word is a string consisting of n X's and n Y's such that no initial segment of the string has more Y's than X's (see also Dyck language). For example, the following are the Dyck words of length 6:
 Reinterpreting the symbol X as an open parenthesis and Y as a close parenthesis, C_{n} counts the number of expressions containing n pairs of parentheses which are correctly matched:
 C_{n} is the number of different ways n + 1 factors can be completely parenthesized (or the number of ways of associating n applications of a binary operator). For n = 3, for example, we have the following five different parenthesizations of four factors:
 Successive applications of a binary operator can be represented in terms of a full binary tree. (A rooted binary tree is full if every vertex has either two children or no children.) It follows that C_{n} is the number of full binary trees with n + 1 leaves:
 C_{n} is the number of monotonic paths along the edges of a grid with n × n square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for "move right" and Y stands for "move up". The following diagrams show the case n = 4:
 C_{n} is the number of different ways a convex polygon with n + 2 sides can be cut into triangles by connecting vertices with straight lines. The following hexagons illustrate the case n = 4:
 C_{n} is the number of stacksortable permutations of {1, ..., n}. A permutation w is called stacksortable if S(w) = (1, ..., n), where S(w) is defined recursively as follows: write w = unv where n is the largest element in w and u and v are shorter sequences, and set S(w) = S(u)S(v)n, with S being the identity for oneelement sequences.
 C_{n} is the number of ways to tile a stairstep shape of height n with n rectangles. The following figure illustrates the case n = 4:
Solving the Catalan numbers
Recurrence relation for Catalan numbers  , and for ,
 .
 , and for ,
Let be the generating function. Then
Due to the recurrence,
 .
Solving , we obtain
 .
Only one of these functions can be the generating function for , and it must satisfy
 .
It is easy to check that the correct function is
 .
Expanding by Newton's formula,
Then, we have
Thus,
So we prove the following closed form for Catalan number.
Theorem  .
Reference
 Graham, Knuth, and Patashnik, Concrete Mathematics: A Foundation for Computer Science, Chapter 7.
 Cameron, Combinatorics: Topics, Techniques, Algorithms, Chapter 4.
 van Lin and Wilson, A course in combinatorics, Chapter 14.