Note: this article is noticeably more difficult than the previous instalments. The reader is advised to be completely comfortable with generating functions before proceeding.

We’ve already seen how generating functions can be used to solve some combinatorial problems. The nice thing is that even if a sequence has no nice closed form, generating functions allow us to efficiently compute a large number of terms in the sequence. With modern computers, such computations are often a cakewalk.

Here, we shall look at a different type of generating functions. Given a sequence , let us define:

.

This is called the exponential generating function (EGF) of the sequence an. Here’re some easy examples.

The EGF for an = 1 is given by ; that’s why there’s an “exponential” attached to the name.

The EGF for an = n! is given by .

The EGF for an = rn is given by .

When do we use this and not the standard generating function? Generally speaking, the EGF is useful for counting the number of combinatorial objects for a labeled set, while the standard generating function is useful for an unlabeled set. Here’s why, roughly.

Suppose, to get a structure A on n identical balls, we need to split the set of n balls into two disjoint subsets and impose structure B on the first subset, and structure C on the second subset. Under this assumption, if an (resp. bn, cn) denotes the number of structures of type A (resp. B, C) on the set of n balls, then we have , since we need to consider the case where the first subset has 0, 1, 2, …, or n balls.

Now consider the same problem, except that the n identical balls are replaced by the set {1, 2, …, n}. To count an, suppose we choose a k-subset ; there are possible choices for S. Then we impose a structure B on S; there are bk ways of doing this. And finally, we choose a structure C on the remaining ; there are cn-k ways of doing this. This gives , or , thus their EGFs multiply to give the final EGF.

Solution. Any beginning student of combinatorics knows the solution: rn. But let’s derive this using EGF. Corresponding to each f, we take the inverse image which are subsets of {1, 2, …, n}. Let ; then we get a partition of {1, 2, …, n} into r disjoint subsets:

Hence, to find a function f, we only need to state an ordered partition into r subsets (“ordered” here means that swapping S1 and S2 changes the partition). If r is fixed, and an denotes the number of f, then the EGF for (an) is the product of r copies of the sequence (1, 1, 1, … ):

Solution. Fix n and s. Let be the number of f whose image has size r. If we consider the case im(f) = {1, 2, …, r}, then the number of such f is n! times the coefficient of in . Hence, is exactly times this number. So we need to look at:

(*)

Thus it really suffices to simplify . This can be achieved by differentiating the binomial expansion:

.

So our sum simplifies to . Upon substituting , the sum (*) simplifies to . This gives . Dividing by the total number of possible functions (), the mean image size is , which is very close to s-1 for large s. ♦

Exercise 1. Find the number of r-letter words you can form with the letters ‘a’, ‘b’ and ‘c’, where ‘a’ occurs an odd number of times and ‘b’ occurs an even number of times.

Exercise 2.The Stirling number of the second kind is the number of partitions of {1, 2, …, n} into r disjoint non-empty subsets. Write down an expression for by computing its EGF or otherwise. Also write down an expression for the Bell number, which is the number of partitions of {1, 2, …, n}. [ Note: the partitions here are unordered, i.e. and are considered identical partitions. ]

Exercise 3. (Comtet’s square). Let be the number of ways to partition {1, 2, …, n} such that (i) the number of parts is X; and (ii) the size of each part is Y, where X, Y are elements of {“unrestrained”, “even”, “odd”}. Find the EGF for . Since there’re 9 possible ordered pairs for (X, Y), you should get 9 answers in all.

Throughout this section, we shall require the reader to be somewhat acquainted with the concept of permutations. A permutation of order n is a bijective map from {1, 2, …, n} to itself. For example, we can express a permutation of order 9 via the following diagram:

Such a permutation p would map 1 to 3, 2 to 5, 3 to 9, … . Or one can also express the same permutation in the form of cycles:

which is clearer and one immediately knows how the successive powers act on the numbers 1, …, 9. For example, since the three cycles have lengths 1, 3, and 5, the smallest n for which is n = lcm(1,3,5) = 15. We say that the order of the permutation is 15.

An element i for which p(i) = i is called a fixed point of the permutation p. In the above example, the only fixed point is 4.

Problem 4. Let be the number of permutations p of {1, 2, …, n} such that . [ Such a permutation is called an involution. ] Find the exponential generating function of .

Proof. If we write p as a product of cycles as above, then p is an involution iff all the cycles have lengths 1 or 2. If there are exactly r cycles (where r is fixed), then the number of permutations has exponential generating function in n given by: , right?

No! Since swapping the cycles has no discernible effect on the permutation (e.g. (1, 2)(4, 5)3 = (1, 2)3(4, 5)), we should divide it by r!. Hence, we should look at instead. Summing over all r, we get:

This allows us to express as a sum:

♦

Problem 5. Find the number of permutations p of {1, 2, …, n}, where p is a product of an even number of disjoint cycles.

Solution. As in the previous problem, we consider the case of r cycles. Given the set {1, 2, …, s}, how many cycles p of length s can we form? To answer that, for any such cycle we can start from 1 and obtain a unique sequence of s-1 numbers via which is a permutation of {2, 3, …, s}. Hence the number is (s-1)!, which gives the EGF:

To find the number of p where p is a product of r cycles, we have to take n! times the coefficient of in . [ As before, the factor of is included since swapping cycles does not change the permutation. ] Hence to find the EGF for , we sum over all even r:

where is the hyperbolic cosine function. Hence the above simplifies to . In conclusion:

When n = 0, .

When n = 1, (obviously!).

When n ≥ 2, . ♦

Note : considering how nice the answer is, one naturally wonders if there is a nice combinatorial argument for this. There is, actually. If p is any permutation of {1, 2, …, n}, where , we compose it with (1, 2) to give . If 1 and 2 belong to the same cycle of p, the composed permutation q would split them up into two cycles; conversely, if 1 and 2 belong to disjoint cycles, then q merges the two cycles into one. The proof is left as an exercise.

But that’s how things are; one often discovers such patterns through heavy machinery before finding a simpler combinatorial proof.

Exercise 4. A derangement is a permutation without a fixed point (i.e. for all i, p(i) ≠ i). Prove that the number of derangements of {1, 2, …, n} is .

Exercise 5. Prove that the number of permutations p of {1, 2, …, 2n} having only even cycle lengths, is given by .

Exercise 6. Generalise the above two problems as follows. Let be two subsets. We wish to enumerate the number of permutations of {1, 2, …, n} for which

the number of cycles is an element of B; and

the length of each cycle is an element of A.

Prove that the EGF of the sequence can be expressed in the form , where α(x) (resp. β(x)) is a power series which depends solely on A (resp. B). Find these power series.

Exercise 7. Prove that the number of permutations of {1, 2, …, n} containing an even number of even-length cycles is exactly when n ≥ 2. For extra challenge, go for two proofs: one combinatorial and one via EGF.

Exercise 8. Prove that the expected number of cycles of a random permutation of {1, 2, …, n} is given by , which is very close to log(n).

Exercise 9. (New: bonus question)* A permutations p of {1, 2, …, n} is said to be alternating if p(1) < p(2), p(2) > p(3), p(3) < p(4), p(4) > p(5), etc. If f(x) denotes the EGF of the number of alternating permutations of {1, 2, …, n}, find a relation between f(x) and its derivative f’(x). Hence prove that f(x) = tan(x).

This concludes our discussion of EGF. Though the article is rather long, we’ve barely scratched the surface of what generating functions are capable of. In particular, one can look at combinatorial species, where an equality not only establishes that , but an actual bijection between the associated combinatorial structures. The best way to understand this is via category theory, but that’s really another story for another day.

Hi. I know there appears to be a huge step there, but refer to the earlier explanation where we’re trying to count the number of ways to impose a structure A on a set S. In problem 1, the structure is simply the “empty structure”, i.e. present S as it is. Hence for each set, there’s exactly one way to impose such a structure, which accounts for (1, 1, 1, …).

For the second problem, the structure is to “throw the set away if it’s empty, otherwise present the set as it is”. So the corresponding sequence is (0, 1, 1, … ).