Contents / Combinatorics / Generating Functions
Chapter 3
Generating Functions
Formal power series as a bookkeeping device for counting, and the recurrences they solve in closed form.
Introduction
Formal power series as a bookkeeping device for counting, and the recurrences they solve in closed form.
3.1Formal Power Series and Ordinary Generating Functions
Before any counting, we need the objects we will be computing with. The temptation is to think of as a function of a real variable , defined where the series converges. That reading is available, and much later it becomes useful, but as a foundation it is a mistake: it makes every algebraic step conditional on an analytic question that has nothing to do with the combinatorics.
Definition 3.1 (Formal power series). Let be a field (for us almost always , or ). A formal power series over is an infinite sequence
written suggestively as . The set of all such series is written . Two series are equal exactly when their coefficient sequences are equal, term by term. We write for the coefficient-extraction operator.
The symbol is a placeholder — a bookkeeping device that records which coefficient is which. Nothing is ever substituted into it, so nothing needs to converge. Addition and multiplication are defined directly on coefficients.
Definition 3.2 (The ring operations). For and in ,
The second is the Cauchy product, or convolution, of the two coefficient sequences.
Observe that the product is well defined with no limiting process at all: the coefficient of is a finite sum of terms. This is the whole reason formal power series work. Each coefficient of the answer is determined by finitely much of the input.
Theorem 3.3 ( is a commutative ring). With the operations of the definition of the ring operations, is a commutative ring with additive identity and multiplicative identity . Moreover it is an integral domain: if and then .
Proof. Commutativity and associativity of addition are inherited coefficientwise from . For the product, commutativity is the substitution in the convolution. For associativity, both and have
a finite sum over ordered triples, so they agree. Distributivity is likewise immediate coefficientwise.
For the integral-domain claim, let be least with and least with — these exist because and are non-zero. Then
because every other term has either (so ) or , forcing (so ). Since is a field and , we get , so .∎
The index appearing in that proof is worth a name.
Definition 3.4 (Order and valuation). The order of a non-zero is the least with ; we set . The proof above shows .
Remark (Why convergence is not the point). The series converges for no real except . As a formal power series it is a perfectly ordinary element of : it is the sequence , it can be added to and multiplied by anything, and it has a multiplicative inverse (the Units Theorem). Its coefficients answer a genuine counting question — how many permutations of an -element set there are — and no analytic statement about it is needed to do that counting. Insisting on convergence would discard a legitimate and useful object for a reason external to the problem.
Conversely, when a generating function does converge near , that is a bonus: it opens the door to estimating by studying the singularities of the analytic function. That subject — singularity analysis, the analytic combinatorics of Flajolet and Sedgewick — is beyond this chapter, and we will flag the one or two places where we lean on it.
Division needs an argument, and the argument is the reason the geometric series identity is true rather than merely suggestive.
Theorem 3.5 (Units of ). A formal power series has a multiplicative inverse in if and only if . The inverse is unique.
Proof. () If then comparing constant terms gives , so .
() Suppose . We must produce with . For this forces , which exists because is a field. For the condition reads
The right-hand side involves only , so this recursion determines uniquely from the previously determined coefficients. By induction every exists and is unique, and the resulting satisfies .∎
Corollary 3.6 (The geometric series). In ,
for any .
Proof. By the Units Theorem the series has a unique inverse, so it suffices to check that works. Its product with has
so the product is . Uniqueness of inverses finishes it.∎
Intuition. The verification above is the entire content of "the geometric series". We are not summing infinitely many numbers; we are exhibiting the sequence as the unique sequence whose convolution with is . Every coefficient check is a one-line finite cancellation. That is why the identity holds "for all ", including , where the numerical series diverges wildly: there is no .
Pitfall (Do not evaluate a formal series at a number). Writing is not a clever formal-series fact; it is a category error. A formal power series is an element of , not a function. The one substitution that is always legitimate is , which reads off the constant term. Substituting another series is legitimate under a condition given in the Composition Theorem below.
With the ring in place we can finally say what a generating function is.
Definition 3.7 (Ordinary generating function). The ordinary generating function (OGF) of a sequence is the formal power series
If is a set of combinatorial objects equipped with a size function taking each value finitely often, the OGF of the class is
The second formulation — sum over the objects themselves — is the one to keep in mind, because it makes the product rule obvious later. The exponent marks the parameter being counted, and the coefficient of is the answer to the counting question at size .
Intuition. Think of as a filing cabinet with one drawer per size. Drawer contains the number , and the symbol is the label on the drawer. Algebra on generating functions is a way of manipulating the whole cabinet at once: multiplying two cabinets combines their contents in every way whose sizes add up, which is exactly the "choose one of these and one of those" step that counting arguments are made of.
Example 3.8 (The OGF of a finite class). Find the generating function that counts the subsets of an -element set by their size.
Solution. Let be the class of subsets with its cardinality. Then
the last step being the binomial theorem. Read backwards this is a proof of the binomial theorem by generating functions: a subset is built by deciding, independently for each of the elements, to exclude it (contributing ) or include it (contributing ), so the class is a product of two-element classes each with generating function .
The generating function here is a polynomial — a formal power series that happens to have finitely many non-zero coefficients. Polynomials are exactly the elements of of that shape, and nothing about the theory changes.□
Two more pieces of infrastructure are needed before the dictionary of operations: infinite sums and substitution. Both are legitimate in under a finiteness condition.
Definition 3.9 (Summable family). A family of formal power series is summable if for every only finitely many have . Its sum is then defined coefficientwise:
a finite sum for each .
Theorem 3.10 (Composition of formal power series). Let and let with . Then the family is summable, so
is a well-defined element of . If and infinitely many are non-zero, the family is in general not summable and the composition is undefined.
Proof. Since we have , hence by the order of a product. So for fixed , every term with contributes to , leaving at most contributing terms: the family is summable.
For the failure case, take (so ) and . Then for every , and every one of them contributes to ; the constant term would be an infinite sum of 's, which is not an element of .∎
This is the precise reason for a condition that will recur constantly: constructions like require . It is not a convergence scruple imported from analysis; it is the difference between a defined and an undefined expression in .
Example 3.11 (A first counting problem). In how many ways can cents be paid using only 1-cent coins? Write the OGF and identify it in closed form.
Solution. For each there is exactly one such payment (use pennies), so for all and
by the geometric series identity. Equivalently, and more usefully for what follows: the class of payments is the class of finite multisets of pennies, one object of each size, and .
The closed form is not an answer in itself — the answer was and we knew it. Its value is that is a factor we can multiply by other factors, which is what makes the two-coin and ten-coin versions of the question tractable.□
3.2The Algebra of Generating Functions
Everything in this chapter rests on a dictionary: a table translating operations on sequences into operations on their generating functions, and combinatorial constructions into algebra. This section states the dictionary and proves it.
Theorem 3.12 (Dictionary of coefficient operations). Let and and let , . Then:
- Linear combination. is the OGF of .
- Product. is the OGF of the convolution .
- Right shift. is the OGF of the sequence that is for and for .
- Left shift. is the OGF of .
- Rescaling. is the OGF of , and is the OGF of the sequence with in position and elsewhere.
- Multiplication by . is the OGF of , where is the formal derivative.
- Partial sums. is the OGF of .
Proof. (1) and (2) are the definition of the ring operations restated. (3) is immediate: , and reindexing gives coefficient in position .
(4) The numerator has order at least , so it equals ; dividing by — which is exact, no inverse required — gives .
(5) by the Composition Theorem applied to , which has ; similarly for .
(6) , and the missing term is .
(7) By (2), , using the geometric series identity to write .∎
Notation (The formal derivative). is defined by that formula, not by a limit. It satisfies the usual rules — and when the composition is defined — each provable by comparing coefficients, and we use them freely. In characteristic , if and only if is a constant.
The product rule deserves its own statement, because it is the rule that turns combinatorics into algebra.
Theorem 3.13 (Product rule for combinatorial classes). Let and be classes with OGFs and , and let be the class of ordered pairs with size . Then
Consequently, if a class admits an unambiguous decomposition — a bijection between its objects and pairs from that adds sizes — then .
Proof. Using the object-sum form of the definition of an OGF,
where the middle equality is legitimate because for each only finitely many pairs have (each class has finitely many objects of each size, and there are finitely many splits ). Comparing coefficients of gives precisely .∎
Intuition. The convolution is the sentence "to build an object of size , choose how much of the size goes to the first component — say — then choose one of the first components and, independently, one of the second components; sum over because the choices of are disjoint." Multiplication of series is the mechanised version of that sentence. Every time you would have written a case analysis with a sum over a split point, you can instead write a product.
The word "unambiguous" is load-bearing. Each object of must arise from exactly one pair. If some object can be split in two different ways, the product over-counts.
Theorem 3.14 (Sequence construction). Let be a class with (no objects of size ) and OGF . Let be the class of finite sequences , , of objects from , with size the sum of the component sizes. Then
Proof. Sequences of length exactly form the class , whose OGF is by applications of the Product Rule. The classes of different lengths are disjoint, and since we have , so the family is summable (summability) and the class union has OGF .
It remains to see that this sum is the inverse of . Write . Then
where the rearrangement is valid coefficientwise because each coefficient involves only finitely many terms. Since has constant term it is a unit (the Units Theorem) with unique inverse, so .∎
Pitfall (The condition is not optional). If contained an object of size , a "sequence" could contain arbitrarily many copies of it without growing, so there would be infinitely many sequences of size and no generating function at all — the class is not admissible. On the algebraic side the family fails to be summable and is undefined, exactly as in the Composition Theorem. The symptom is an infinite constant term; the cause is a combinatorial construction that produces infinitely many objects of one size.
For coefficient extraction, one identity does most of the work. It is the binomial theorem, generalised so that the exponent need not be a non-negative integer.
Definition 3.15 (Generalised binomial coefficient). For (or ) and ,
with . When is a non-negative integer this is the usual binomial coefficient and vanishes for ; otherwise it is non-zero for every .
Definition 3.16 (The series ). For we define
That is a definition, so nothing is yet proved; what has to be proved is that the notation is honest — that this series behaves like a power.
Theorem 3.17 (Generalised binomial theorem). For all (char ):
and . In particular is the inverse of , and for a positive integer the definition of agrees with the ordinary -fold product.
Proof. The product identity is equivalent, on comparing coefficients of , to the Vandermonde convolution
Both sides are polynomials in and of degree at most in each. For non-negative integers the identity is the standard combinatorial Vandermonde identity: choosing elements from a set of elements split into blocks of sizes and amounts to choosing from the first and from the second. A polynomial in two variables that vanishes at all pairs of non-negative integers is identically zero (fix integral and note a one-variable polynomial with infinitely many roots is zero; then repeat in ). Hence the identity holds for all .
The cases are immediate from the definition of . The derivative claim follows from , which is a direct computation from the definition. Finally, for a positive integer is a product of copies of by the first identity and induction.∎
Corollary 3.18 (Negative exponents). For an integer ,
Proof. By the Generalised Binomial Theorem, is the inverse of . Substituting (valid by the Composition Theorem) gives . Now compute
since the factors each contribute one sign. The two binomial forms agree by symmetry.∎
Intuition. the negative-exponent corollary has a purely combinatorial reading, and it is worth seeing both. is the product of copies of , so by the Product Rule its -th coefficient counts the ways to write with each — the number of ways to distribute identical balls into labelled boxes. Stars and bars says that number is . So the algebra and the combinatorics prove the same identity from opposite ends.
Example 3.19 (Two unlimited supplies). An unlimited supply of identical apples and an unlimited supply of identical oranges are available. In how many ways can one hold a total of fruit?
Solution. Holdings of apples form a class with one object of each size, OGF ; likewise for oranges. A holding is an ordered pair (apple part, orange part) with sizes adding, so by the Product Rule the OGF is
By the negative-exponent corollary with , the coefficient of is .
Check directly: choose apples and take the remaining as oranges — choices, as computed.□
Example 3.20 (Coefficients of a rational function). Find .
Solution. Split the numerator and use linearity together with the right-shift rule (the Dictionary of Coefficient Operations, parts 1 and 3):
By the negative-exponent corollary with these are and , so
For this predicts ; expanding and multiplying by gives , as claimed. (The answer is the sum of the first odd numbers — a pleasant check, since and is the OGF of the odd numbers.)□
3.3Solving Counting Problems with Generating Functions
We now put the dictionary to work. The pattern is always the same: describe the objects by an unambiguous construction, translate the construction into an equation between generating functions, and then extract coefficients by whatever algebraic means are available.
Method 3.21 (The generating-function method).
- Specify. Describe the class by a decomposition built out of disjoint unions, products and sequences, in a way that produces each object exactly once.
- Translate. Apply Theorems the Product Rule and the Sequence Construction theorem to get a formula or an equation for the OGF.
- Solve. If the translation gave an equation (rather than a formula), solve it algebraically for the unknown series.
- Extract. Recover by partial fractions, the generalised binomial theorem, or a convolution.
- Check. Expand the first few coefficients by hand and compare against a direct count.
Example 3.22 (Compositions of an integer). A composition of is an ordered tuple of positive integers summing to ; for instance gives four compositions. Find the number of compositions of .
Solution. Specify. A composition is a sequence of parts, each part a positive integer. The class of parts has exactly one object of each size , so its OGF is , with as required.
Translate. By the Sequence Construction theorem,
Extract. Write . By the geometric series identity and the shift rule, the coefficient of is for , and .
Check. , matching the four compositions listed. The answer also has a one-line bijective proof (insert or omit a divider in each of the gaps between units), which is a reminder that generating functions are one tool among several — but the method above needed no cleverness at all.□
Example 3.23 (Compositions with restricted parts). How many compositions of use only parts equal to or ?
Solution. The part class is now with OGF , so the composition class has OGF
Its coefficients satisfy — we prove this properly in the Rationality Theorem — with : the Fibonacci numbers. So the number of such compositions of is in the indexing .
For : , , , , , which is .□
Example 3.24 (Making change). In how many ways can cents be paid using pennies, nickels and dimes (, and cents), the coins of each denomination being identical? Evaluate at .
Solution. Specify. A payment is determined by the number of pennies, the number of nickels and the number of dimes — an ordered triple of independent choices whose values add to . The class of penny-piles has one object of each size , OGF ; nickel-piles have one object of each size , OGF ; dime-piles, .
Translate.
Extract. Rather than partial-fraction a degree- denominator, note that the pennies simply absorb whatever the other coins leave, so the count is the number of pairs (nickels, dimes) with total at most . For : with dimes we may use nickels ( ways); with dime, nickels ( ways); with dimes, nickels ( way). Total .
Check. The same reasoning at gives payments: ten pennies, one nickel and five pennies, two nickels, one dime. Correct.□
Remark (The generating function as a data structure). The last example makes a point about what a generating function is for. It gave us no slick closed form — denumerants genuinely do not have one for general denominations — but it gave us an object we can compute with mechanically: multiply the three series out to order and read off the coefficient, an operation per factor. When a problem has no closed form, "the coefficient of in this explicit rational function" is still a complete and usable answer, and it is the form in which computer algebra systems prefer to receive it.
Partitions are the classical proving ground, and Euler's product is the classical result.
Definition 3.25 (Integer partition). A partition of is a multiset of positive integers summing to ; equivalently a weakly decreasing tuple with . The number of partitions of is , with (the empty partition).
Order does not matter for a partition, which is exactly what distinguishes it from a composition — and it is why the sequence construction is the wrong tool and a product over part sizes is the right one.
Theorem 3.26 (Euler's product formula). As formal power series,
Proof. First, the infinite product is meaningful in : the partial products satisfy , and has order . So the coefficient of in is the same for all , and we define to be that stable value.
Now fix and expand the finite product. By the geometric series identity applied with in place of ,
the sum over all tuples of non-negative integers; the regrouping is the Product Rule applied times. A tuple contributing to is exactly a choice of how many parts of each size to use, with the sizes totalling — that is, exactly a partition of into parts of size at most . Since , no partition of has a part larger than , so these are all the partitions of . Hence , and the stable value is .∎
Intuition. Each factor is a little machine that decides, independently of the others, how many parts of size the partition will have: choosing the term means "use parts of size ". Multiplying the machines forces their contributions to add to . Compare the factor , which offers only "use a part of size or do not" — that one counts partitions into distinct parts.
Theorem 3.27 (Euler: distinct parts and odd parts). For every , the number of partitions of into pairwise distinct parts equals the number of partitions of into odd parts.
Proof. By the reasoning of Euler's Product Formula, partitions into distinct parts have OGF — each part size is used at most once — and partitions into odd parts have OGF . It suffices to show the two products are equal.
Use , valid in since is a unit. Then, taking the product over ,
In the denominator split the factors into even and odd . The even ones, , cancel against the matching factors of the numerator, leaving
Every remaining numerator factor has the form with , so it differs from only in degrees exceeding . Comparing coefficients of for any fixed and taking , those factors are invisible, and we get
for every , which is the claim.∎
Example 3.28 (Computing for small ). Compute from Euler's product.
Solution. We only need parts of size at most , so work modulo and multiply in the factors one at a time. Write for the product of the first factors.
Multiplying by means "add to each coefficient the coefficient two places earlier", so .
Similarly, multiplying by adds the coefficient three places earlier: .
By : . By : . By : .
So . Listing them confirms it: ; ; ; ; ; ; ; ; ; ; .
Note the "multiply by " step is just the partial-sum rule of the Dictionary of Coefficient Operations(7) with in place of , which is why it is an in-place update and not a full convolution. That observation is the standard algorithm for tabulating .□
Proposition 3.29 (Parts of bounded size versus boundedly many parts). The number of partitions of into at most parts equals the number of partitions of into parts of size at most ; both have OGF .
Proof. Represent a partition by its Young diagram: row consists of cells. Reflecting the diagram in its main diagonal — replacing rows by columns — produces the diagram of another partition of the same , the conjugate, and conjugation is an involution, hence a bijection. The number of rows of is the size of the first column, which is the largest part of ; so has at most parts if and only if has all parts at most . The generating function for the second family is the argument of Euler's Product Formula truncated at .∎
3.4Exponential Generating Functions
Ordinary generating functions are the right bookkeeping for unlabelled objects — piles of identical coins, partitions, tilings — where the only thing an object contributes is its size. They are the wrong bookkeeping for objects built on a set of distinguishable atoms: people, numbered positions, vertices of a labelled graph. For those, the number of structures grows factorially, and a different weighting is needed.
Definition 3.31 (Labelled class). A labelled class assigns, to each finite set of labels, a finite set of structures on , in such a way that relabelling along a bijection carries bijectively onto . Consequently depends only on , and we write .
Permutations, set partitions, labelled graphs, functions from to , and rooted labelled trees are all labelled classes in this sense.
Definition 3.32 (Exponential generating function). The exponential generating function (EGF) of a sequence — equivalently, of a labelled class — is
To recover the count, multiply back: .
Notation (Hats). Where both bookkeepings are in play we write for an OGF and for an EGF of the same sequence. Elsewhere in this chapter, and in most of the literature, the hat is dropped and the reader is expected to know from context which is meant; the two are different series, and confusing them is the classic error of the subject.
Why divide by ? Because of what happens when labelled structures are combined. If we place an -structure on part of a label set and a -structure on the rest, we must first choose which labels go where, and that choice contributes a binomial coefficient. The in the denominator is engineered to absorb it.
Definition 3.33 (Labelled product). For labelled classes , the labelled product has, on the label set , all triples where , and . In words: split the labels into two blocks, put an -structure on one and a -structure on the other.
Theorem 3.34 (Product rule for EGFs). If then
The second form is the binomial convolution.
Proof. Counting directly: choose the block of size in ways, then an -structure on it in ways (a number depending only on , by the definition of a labelled class), then a -structure on the complementary labels in ways. Summing over gives , and the choices are distinct for distinct , so nothing is double counted.
Now translate. The coefficient of in is, by the Cauchy product,
which is exactly .∎
Intuition. The is a normalisation that makes the factorials cancel at exactly the right moment. Multiplying OGFs performs the plain convolution , which answers "split the size"; multiplying EGFs performs the binomial convolution , which answers "split the labels". Both are "do one thing and then another", but for labelled objects the splitting is a choice of subset, not merely a choice of number, and the binomial coefficient is the price of that choice.
Proposition 3.35 (Dictionary for EGFs). Let . Then:
- is the EGF of the shifted sequence .
- is the EGF of (with the term ).
- is the EGF of , extended by at .
- is the EGF of the constant sequence , and is the EGF of .
Proof. (1) .
(2) .
(3) is (1) read backwards. (4) , so ; and , so .∎
Remark ( as a formal object). We define , , and so on by their coefficient sequences, exactly as with . The identities we need — for of positive order, as the inverse function of under composition, — are then formal identities, provable by coefficient comparison or by the formal chain rule. None of this appeals to analysis; we are working inside throughout.
Example 3.36 (Permutations). Find the EGF for the number of permutations (linear orderings) of an -element labelled set, and recover .
Solution. There are orderings of . Hence
Recovering: , as it should be.
Contrast the OGF of the same sequence, , which has no closed form of any standard kind (its formal inverse is computable but unilluminating). This is the first evidence of the general principle: for labelled objects, the EGF is the series with the simple closed form.□
Example 3.37 (Words over an alphabet). Let be the number of ways to colour labelled objects with available colours. Find the EGF.
Solution. Colouring the objects means choosing, independently for each of the labels, one of colours: . So
The factorisation is itself the statement being proved: a colouring is a labelled product of blocks (the colour classes), each of which is an arbitrary set of labels carrying no further structure, and "an arbitrary set of labels" has EGF since there is exactly one such structure on each label set. The EGF product rule then multiplies the factors.□
Pitfall (The coefficient is not the count). is , not . Forgetting the multiplier is the single most common slip with EGFs, and it is silent: is usually a plausible-looking rational number. Whenever you finish an EGF computation, the last line should be "multiply by ".
3.5Labelled Structures and the Exponential Formula
The payoff of the normalisation is a dictionary of constructions as clean as the ordinary one, and one theorem — the exponential formula — that has no ordinary analogue of comparable simplicity.
Theorem 3.38 (Constructions on labelled classes). Let be a labelled class with (no structure on the empty label set) and EGF . Then:
- Sequence. The class of sequences , , of -structures on the blocks of an ordered set partition of the labels has EGF .
- Set. The class whose structures are sets of -structures on the blocks of an (unordered) set partition of the labels has EGF .
- Cycle. The class of cyclic arrangements of -structures has EGF .
Proof. (1) Sequences of exactly components form the -fold labelled product , with EGF by the EGF product rule and induction. Since we have , so is summable and, exactly as in the ordinary Sequence Construction theorem, .
(2) A set of components is an ordered -tuple of components with the ordering forgotten. The components occupy disjoint, non-empty blocks of labels, so they are pairwise distinct as (block, structure) pairs, and each set of components arises from exactly of the ordered tuples. Hence the EGF for sets of exactly components is — division by the integer is legitimate since we work over — and summing over gives , the family again being summable.
(3) A cyclic arrangement of components is an ordered -tuple up to cyclic rotation, and the rotations of a tuple of distinct components are distinct, so the EGF for -cycles of components is for . Summing, , by the definition of the logarithm series.∎
Corollary 3.39 (Cycles of atoms). The number of ways to arrange labelled elements () in a single cycle is , and the EGF of cyclic arrangements is .
Proof. Take to be the class of single atoms, ; part (3) of the constructions theorem gives . The count is therefore , in agreement with the direct argument that a cycle on elements is one of the linear orders, with each cycle arising from exactly of them.∎
Theorem 3.40 (The exponential formula). Let be a labelled class of "connected" structures with and EGF , and let be the class whose structures on are the ways of partitioning into non-empty blocks and placing a -structure on each block. Then
Equivalently, in coefficients,
Proof. This is part (2) of the constructions theorem applied to ; the coefficient form is obtained by expanding and reading off of the -th term, the multinomial coefficient being the number of ways to distribute the labels into the ordered blocks of sizes .∎
Intuition. The exponential formula says: if you know how to count the connected pieces, exponentiating counts everything. Graphs are the archetype — every graph is a set of connected graphs on the blocks of a partition of its vertices — and the same sentence covers permutations (a permutation is a set of cycles), set partitions (a partition is a set of blocks), and forests (a forest is a set of trees). Nothing in the proof knows what "connected" means; it only needs that every structure decomposes uniquely into pieces sitting on the blocks of a partition.
Read in the other direction, the formula is equally useful: defines the connected count from the total count, which is how one counts connected labelled graphs.
Example 3.41 (Permutations as sets of cycles). Derive the EGF of permutations from the exponential formula, and confirm it against the direct count.
Solution. Every permutation of a finite set decomposes uniquely into cycles, and the cycles sit on the blocks of a partition of the label set — so permutations are . By the cycles corollary the cycle EGF is , so
whose -th count is . Correct, and derived rather than assumed.□
Example 3.42 (Set partitions and the Bell numbers). Find the EGF of the Bell numbers (the number of partitions of an -set into non-empty blocks), and use it to prove the recurrence .
Solution. A block is a non-empty set of labels with no further structure, one structure per non-empty label set, so the block EGF is (the removing the empty block). A partition is a set of blocks, so by the exponential formula
Differentiate, using the formal chain rule: . By part (1) of the EGF dictionary, is the EGF of , and by the EGF product rule the right-hand side is the binomial convolution of the sequence (EGF ) with . Comparing coefficients of :
From this gives , , , , .
The combinatorial reading of the recurrence is also worth having: in a partition of , look at the block containing ; it contains of the other elements for some , chosen in ways, and the remaining elements are partitioned in ways.□
Example 3.43 (Stirling numbers of the second kind). Let be the number of partitions of into exactly non-empty blocks. Find and deduce the explicit formula.
Solution. Partitions into exactly blocks are sets of exactly blocks, so by the proof of the constructions theorem the EGF is
Expand the -th power with the ordinary binomial theorem:
and . Therefore
which is the inclusion–exclusion formula for surjections divided by — as it must be, since a partition into labelled blocks is a surjection and forgetting the block labels divides by .
Check: , and indeed .□
Example 3.44 (Involutions). An involution of is a permutation with . Find the EGF of the number of involutions and the recurrence it satisfies.
Solution. A permutation is an involution exactly when all its cycles have length or . The class of such cycles has EGF (one fixed point per singleton; one transposition per pair, and agrees with ). By the exponential formula,
Differentiating, . The left side is the EGF of ; the right side is the EGF of by parts (1) and (2) of the EGF dictionary. Hence
with , giving . The combinatorial reading: either is fixed, or it is paired with one of the other elements.□
3.6Choosing Between OGFs and EGFs
The two bookkeepings are two ways of storing the same sequence, so neither carries more information than the other. The difference is entirely in which constructions become clean algebra.
Proposition 3.45 (The two bookkeepings compared). Let be classes and a class built from them. Then:
| construction | OGF | EGF |
|---|---|---|
| disjoint union | ||
| product (split the size / split the labels) | ||
| sequence of components | ||
| set / multiset of components | ||
| cycle of components |
In both columns the sequence, set and cycle rows require the component class to have no object of size .
Proof. The union, product and sequence rows are the Product Rule, the Sequence Construction theorem and their EGF counterparts. The set row in the EGF column is part (2) of the constructions theorem. We prove the multiset row in the OGF column, which is the one genuinely new statement; the unlabelled cycle row (Pólya's cycle-index computation, using Euler's totient ) is proved the same way and we state it without carrying out the details.
A multiset of -objects records, for each object , a multiplicity , with only finitely many non-zero. The size is , so, by the same expansion used for Euler's Product Formula,
the product being well defined because makes every factor of order at least . Now take formal logarithms — legitimate since each factor has constant term — and use :
the interchange being valid coefficientwise (for a fixed power of , only finitely many pairs contribute). Exponentiating gives the stated formula.∎
Intuition. Look at the two "set" rows. In the labelled world, — one clean exponential. In the unlabelled world, , the extra terms compensating for repeated components, which in the labelled world can never occur because distinct components carry distinct labels. That asymmetry is the whole reason for having two theories. Labels break symmetry, and broken symmetry is what makes the algebra simple.
The practical rule. If the objects are built on distinguishable atoms and the construction involves distributing those atoms, use an EGF. If the objects are anonymous and the construction involves distributing size, use an OGF.
Proposition 3.46 (When labelling is free). Suppose every object of size in a labelled class has trivial symmetry — that is, no non-identity relabelling of fixes it. Then the number of unlabelled objects (relabelling classes) of size satisfies , so is the OGF of .
Proof. Relabelling acts on ; two structures are the same unlabelled object exactly when they lie in the same orbit. By the orbit–stabiliser theorem every orbit has size under the triviality hypothesis, so the structures fall into orbits.∎
Example 3.47 (Derangements). A derangement is a permutation with no fixed point. Find the EGF of the number of derangements of and the closed form, then evaluate .
Solution. A derangement is a permutation all of whose cycles have length at least . Deleting the length- term from the cycle EGF leaves , so by the exponential formula
Extract the coefficient by the Cauchy product, using and :
At : .
The closed form is exactly what inclusion–exclusion over the set of fixed points gives, and the factor is where the alternating signs came from: multiplying by is the generating-function form of inclusion–exclusion on labelled structures.□
Remark (Sums with no closed form, and the transform between the two). The OGF of the derangement numbers is , and since it converges nowhere but and has no elementary closed form. That is the general situation: for labelled classes the OGF is usually intractable and the EGF is usually clean, while for partitions and other unlabelled classes it is the reverse.
There is a transform between them — the Borel transform, in one direction the coefficientwise division by , in the other the Laplace-type integral — but the integral form is an analytic statement requiring convergence hypotheses we have deliberately avoided, and it is out of scope here. In practice one never converts; one chooses the right bookkeeping at the start.
3.7Linear Recurrences with Constant Coefficients
A recurrence defines a sequence by expressing each term in terms of earlier ones. Recurrences are how counting problems usually present themselves — condition on the last step, on the first return, on the block containing the largest element — and generating functions are how they get solved. The two halves of this chapter meet here.
Definition 3.48 (Linear recurrence with constant coefficients). A sequence satisfies a linear homogeneous recurrence with constant coefficients of order if there are constants with such that
"Linear" means each occurs to the first power with no products between terms; "homogeneous" means there is no extra additive term. The values are the initial conditions, and together with the recurrence they determine the sequence uniquely.
The single fact from which everything else follows is that such sequences are exactly the ones with a rational generating function.
Theorem 3.49 (Rationality). Let and let be the OGF of . Then satisfies the recurrence for all if and only if
for some polynomial with . In that case is determined by the initial conditions, namely
Proof. Compute the product coefficientwise. With the convention for ,
For this expression is precisely "left-hand side minus right-hand side" of the recurrence at index . Hence the recurrence holds for all if and only if every coefficient of in degree vanishes, i.e. if and only if is a polynomial of degree . Since , is a unit (the Units Theorem), so may be rewritten as . The displayed formula for is the same coefficient computation for , where the terms with negative index drop out.∎
Intuition. The theorem is a genuine equivalence, and both directions get used. Left to right: if you have a recurrence, you instantly have a closed-form rational generating function — no work, just read off from the coefficients and from the initial conditions. Right to left: if a generating function turns out to be rational, its coefficients must satisfy a linear recurrence, and the denominator tells you which one. That is often the quickest way to prove a recurrence you would otherwise have to fight for combinatorially.
Extracting coefficients from is then a matter of partial fractions, which is where the roots enter.
Theorem 3.50 (Partial fractions and the closed form). Let with and . Factor over as
Then there are constants with
and consequently
where is a polynomial of degree at most . Conversely every sequence of that shape satisfies the recurrence with denominator .
Proof. The partial fraction decomposition of a rational function whose denominator factors as above is standard algebra over a field: the for , , are elements spanning the -dimensional space of rational functions with denominator dividing and numerator of degree , and they are linearly independent, so they form a basis.
For the coefficients, the negative-exponent corollary applied with in place of gives
Now is a polynomial in of degree exactly . Summing over produces a polynomial of degree at most multiplying , as claimed. The converse follows because each such term has rational generating function with denominator , and the Rationality Theorem applies to the sum.∎
Remark (The characteristic equation). The characteristic polynomial of the recurrence is
and it is the reverse of : . Hence if and only if — the roots of the characteristic equation are exactly the reciprocals of the roots of , and they are the appearing in the closed form. This recovers the familiar recipe: solve ; for a simple root take a term ; for a root of multiplicity take ; fix the constants from the initial conditions. The generating-function proof explains why the polynomial factors appear for repeated roots — they come from — where the guess-and-verify derivation can only assert them.
Example 3.51 (Fibonacci in closed form). Let , and . Find the generating function and prove Binet's formula.
Solution. Generating function. Here , , so . By the Rationality Theorem, , so
Factor the denominator. If then expanding gives and , so are the roots of :
(As predicted by the characteristic-equation remark, is the reverse of .)
Partial fractions. Since
we get
Extract. By the geometric series identity, , so
Check. , and . Both correct.
Note what the formula says: , so and is the nearest integer to — an exact statement about growth extracted from the position of the smallest root of the denominator, which is the first hint of how singularities govern asymptotics.□
Example 3.53 (A repeated root). Solve with , .
Solution. , a double root . By the Rationality Theorem, , so
Write . Matching the terms gives , so ; matching constants gives , so . Hence
and by the negative-exponent corollary,
Check. ; ; , and the recurrence gives . The linear factor in the answer is exactly the from the squared denominator.□
Example 3.54 (Pell numbers). Solve with , .
Solution. and , so . The characteristic polynomial has roots , with , so the same partial-fraction computation as for Fibonacci gives
Check. , matching . Also .□
Theorem 3.55 (Inhomogeneous recurrences). Suppose for , where has OGF . Then, with and as in the Rationality Theorem,
where . In particular, if is rational then so is , and the closed form is again a sum of terms — now including the roots contributed by the denominator of .
Proof. The computation in the Rationality Theorem proof now gives for and the same initial data below , so ; divide by the unit .∎
Example 3.56 (Doubling with an increment). Solve for , with . (This is the Tower of Hanoi recurrence.)
Solution. Here , , , and for , so . By the inhomogeneous theorem,
Partial fractions: write , i.e. . Setting gives , so ; setting gives , so . Hence
Check. , , , ; and . The extra root in the closed form came entirely from the denominator of the forcing term's generating function, exactly as the theorem predicts.□
3.8Combinatorial Recurrences and Functional Equations
Not every recurrence that arises from counting is linear with constant coefficients. Two other shapes are common: convolution recurrences, in which the terms multiply two earlier values, and recurrences with polynomial coefficients. Generating functions handle both — the first by producing an algebraic equation, the second by producing a differential equation.
Definition 3.57 (Catalan numbers). is the number of balanced strings of pairs of parentheses (equivalently: binary trees with internal nodes; triangulations of a convex -gon; lattice paths from to by unit right and up steps that never rise above the diagonal). By convention , the empty string.
Proposition 3.58 (The Catalan recurrence). For ,
Proof. Let be a non-empty balanced string. Its first character is an opening parenthesis; let its matching closing parenthesis be at position . Then factors uniquely as where is the (balanced) substring strictly inside the matching pair, with pairs, and is the balanced remainder, with pairs. The factorisation is unique because the matching partner of the first character is determined by ; conversely, every choice of , and produces a distinct balanced string with pairs. Summing over from to gives the identity.∎
Theorem 3.60 (The Catalan generating function). satisfies the functional equation , and
Here in the sense of the generalised binomial theorem.
Proof. The functional equation. By the Product Rule, , which by the Catalan recurrence is for . So and agree in every degree , and they differ in degree by . Hence .
Solving. Write . By the generalised binomial theorem with we have ; the substitution is legitimate since has zero constant term. Regard as a quadratic: , so
as one checks by expanding: . Since is an integral domain, forces . Comparing constant terms: has constant term , while has constant term . So the sign must be , giving and
a legitimate power series because has zero constant term and is therefore divisible by in .
Coefficients. By the definition of ,
For compute the coefficient. The numerator of is a product of halves,
so, using and ,
Complete the odd product to a factorial using :
(Sanity check at small : gives , and directly ; gives , and directly ; gives , and directly .)
Hence , and
So , which for gives — matching the recurrence.∎
Pitfall (Choosing the wrong branch). The quadratic formula offers two roots, and only one of them is a formal power series. The test is always the constant term: must be finite and correct, whereas has a numerator with constant term , so it is not divisible by and is not an element of at all. Never choose the branch by plugging in a small number and seeing which "looks right" — check the order of the numerator.
Intuition. Look at what the functional equation says: a balanced string is either empty, or it is a pair of parentheses (the , contributing size ) wrapping one balanced string, followed by another balanced string. The equation is the decomposition, transcribed. Deriving the recurrence first and then the equation, as we did, is the careful route; with practice one writes the functional equation directly from the decomposition and never mentions the recurrence at all.
Example 3.61 (Motzkin numbers). counts lattice paths from to using steps , and that never go below the horizontal axis. Find the functional equation for .
Solution. Decompose a non-empty path by its first step. If it is , the rest is an arbitrary Motzkin path of length , contributing . If it is , the path must return to the axis for the first time by some step; between them lies a Motzkin path (shifted up by one), and after the lies another Motzkin path. That contributes , the accounting for the and the . The decomposition is unambiguous, so
Solving as before (and taking the branch with the correct constant term) gives
whose coefficients begin . Equating coefficients in the functional equation instead gives the recurrence , which is the fastest way to tabulate them.□
Theorem 3.62 (Recurrences with polynomial coefficients). If a sequence satisfies a recurrence whose coefficients are polynomials in , its generating function satisfies a linear differential equation with polynomial coefficients, obtained by translating and a shift. Sequences of this kind are called holonomic (or -recursive), and the differential equation is often solvable in closed form even when the recurrence is not.
Proof. Each occurrence of contributes up to finitely many initial terms (the shift rule), and each factor of multiplying a coefficient contributes the operator (part 6 of the Dictionary of Coefficient Operations). Since the recurrence is a finite linear combination of such terms with polynomial coefficients, the result is a finite linear combination of , , , … with polynomial coefficients equated to a polynomial. That the operator translation is valid is exactly the two dictionary entries; no convergence is involved because the formal derivative is defined coefficientwise.∎
Example 3.63 (Involutions again, from the recurrence). Solve , , using an exponential generating function.
Solution. Let . Setting makes the recurrence valid for every , since at it reads . Multiply by and sum over : by part (1) of the EGF dictionary the left side is the EGF of , namely ; the first term on the right is ; and by part (2) the term has EGF . So
This is a first-order linear differential equation in . Writing with — legitimate since has constant term — the formal chain rule turns it into , so and
confirming the exponential-formula derivation from the labelled-structures section by a completely different route. Expanding to order : , and multiplying by gives , as before.□
Remark (When the answer is not a closed form). It would be misleading to suggest every combinatorial recurrence yields a formula. The partition numbers satisfy no linear recurrence with constant coefficients (their generating function is not rational — it has infinitely many singularities on the unit circle), and their exact asymptotic is the Hardy–Ramanujan theorem, proved by the circle method and far beyond this chapter. What a generating function reliably buys is a finite description of the whole sequence, plus the machinery to compute any term. A closed form is a bonus that appears when the series turns out to be rational or algebraic.
3.9Method: Solving Recurrences by Generating Function
This section gathers the methods into procedures, and adds two techniques that do not follow from the dictionary alone.
Method 3.64 (Solving a recurrence with an ordinary generating function).
- Decide the range of for which the recurrence is valid, and set for if that makes it valid further down.
- Multiply the recurrence by and sum over that range.
- Rewrite each sum in terms of using the shift rules, being careful about the finitely many initial terms that the shift adds or removes.
- Solve the resulting equation for — linear if the recurrence was linear, quadratic if it was a convolution.
- Extract coefficients: partial fractions for rational , the generalised binomial theorem for algebraic , a convolution if is a product of two known series.
- Verify the first three or four coefficients against a direct count.
Method 3.65 (Solving a recurrence with an exponential generating function). Use this when the recurrence contains binomial coefficients in a convolution, or polynomial factors in .
- Multiply by and sum.
- Translate: , , .
- Solve the resulting differential equation; first-order linear equations are solved by the formal substitution when .
- Recover .
Example 3.66 (A recurrence needing care with initial terms). Let , and for . Derive from scratch.
Solution. Multiply by and sum over :
The left side is . Reindexing the right-hand sums with and ,
Hence ; the terms cancel and
Compare with the Rationality Theorem, which gives the same answer in one line: and . The point of doing it by hand once is step 3 — the term , not — which is where sign and off-by-one errors live.
Since , the Fibonacci computation gives .□
Theorem 3.67 (Lagrange inversion). Let with . Then there is a unique with satisfying , and for
for any .
Proof. We do not prove this here. The standard proof runs through the formal residue on formal Laurent series, together with the two facts that for every formal Laurent series and that residues transform correctly under a change of variable of positive order; it is a page of careful bookkeeping and is carried out in Stanley's Enumerative Combinatorics and in Wilf's generatingfunctionology. We use the statement as a black box. Existence and uniqueness of , by contrast, is the same coefficient-by-coefficient recursion as in the Units Theorem.∎
Example 3.68 (Cayley's formula for labelled rooted trees). Let be the number of rooted trees on the labelled vertex set . Use Lagrange inversion to show .
Solution. Specify. A rooted labelled tree is a root vertex together with a set of rooted labelled subtrees hanging from it, the subtrees sitting on the blocks of a partition of the remaining labels. By the exponential formula and the labelled product rule, the EGF satisfies
the factor being the root atom.
Invert. This is with , which has . Lagrange inversion gives, for ,
Recover the count.
Check. , (either vertex may be the root), : three choices of root times three unrooted trees on labelled vertices... more carefully, there are unrooted labelled trees on (the three paths) and choices of root, giving . Dividing by gives Cayley's formula for unrooted labelled trees.□
The last technique goes the other way round: it uses generating functions to evaluate a sum, by summing over the free index rather than the bound one. Wilf calls it the snake oil method.
Lemma 3.69 (A shifted binomial series). For each fixed ,
Proof. Substituting (the terms with vanish) turns the sum into , and by the negative-exponent corollary with in place of the remaining sum is .∎
Example 3.70 (The snake oil method). Prove that , the Fibonacci numbers with , .
Solution. Call the sum and form its generating function, then exchange the order of summation — legitimate because for each power of only finitely many terms contribute:
In the inner sum substitute :
by the shifted binomial lemma. Now sum the geometric series in , whose ratio has zero constant term so the sum is defined:
That is the generating function of , as computed earlier. Comparing coefficients gives .
Check. : . The identity is the statement that the shallow diagonals of Pascal's triangle sum to Fibonacci numbers, and the proof above never had to see that picture.□
Summary (The whole method in one page).
- A generating function is an element of ; equality means equality of coefficients, and no substitution of numbers occurs.
- is invertible iff ; and require order at least for the inner series.
- Disjoint union is , product is , sequence is — for OGFs with sizes adding, for EGFs with labels distributed.
- Sets and cycles of labelled components are and ; the first is the exponential formula and is the workhorse of labelled enumeration.
- A sequence satisfies a linear constant-coefficient recurrence iff its OGF is rational; partial fractions then gives .
- A convolution recurrence gives an algebraic equation (Catalan, Motzkin); a polynomial-coefficient recurrence gives a differential equation (involutions, Bell).
- Coefficients come out by the generalised binomial theorem, by partial fractions, by convolution, or by Lagrange inversion for equations of the form .
- Always verify the first few coefficients by hand.
- Reading a formal series as a convergent function. is a legitimate formal power series and holds with no reference to . Convergence becomes relevant only when you want asymptotics.
- Applying when has a non-zero constant term. The construction is then undefined, not merely divergent (the Composition Theorem); combinatorially it means your class has infinitely many objects of some size.
- Forgetting the term. The empty object contributes the constant to almost every generating function, and dropping it shifts every subsequent coefficient.
- Confusing "any number of" with "at most one". Unlimited copies of an item of size give the factor ; a single optional copy gives . Euler's distinct-equals-odd theorem is exactly the statement that the difference matters.
- Using a product when the decomposition is ambiguous. the Product Rule requires each object to arise from exactly one pair. Over-counting here is the single most common source of a wrong generating function.
- Marking the wrong parameter. The exponent of must be the statistic you are counting by. If a problem tracks two statistics, you need two variables, and a bivariate generating function.
- Reporting as the answer. For an EGF the count is .
- Using an EGF for unlabelled objects. Partitions of an integer, tilings and coin problems have no labels to distribute; the then normalises by a symmetry that is not there, and the constructions theorem does not apply.
- Swapping "set of" and "sequence of". is ; is . They differ by exactly the orderings of the components.
- Using when components may be empty. All three labelled constructions require , for the same summability reason as in the ordinary case.
- Forgetting that here is a formal series. , and are defined by their coefficients; their identities are proved formally, and no value is ever substituted for .
- Mistaking an EGF for a probability generating function. A PGF is with and is evaluated at real ; the of an EGF is a labelling correction, not a probability.
- Mishandling the initial terms when shifting. is , not . Almost every wrong generating function for a recurrence is wrong here.
- Omitting the initial conditions. A recurrence of order describes a -parameter family of sequences; the numerator is where the initial conditions live, and without them there is no single answer.
- Ignoring root multiplicity. A root of multiplicity contributes with , not just ; the polynomial factor comes from in the expansion of .
- Sign errors in the characteristic polynomial. Bring everything to one side first: gives , the reverse of the denominator .
- Taking the wrong root of a quadratic functional equation. Only one branch is a formal power series; decide by comparing constant terms, never by evaluating at a number.
- Assuming every recurrence is linear with constant coefficients. Convolution recurrences and polynomial-coefficient recurrences are common and have their own machinery; a rational generating function is not the only good outcome.
- Skipping the check. Expanding the first four coefficients of the final answer and comparing against a hand count catches essentially every algebra slip, and costs a minute.