Generating Functions
A generating function encodes a sequence as the coefficients of a formal power series , turning sequence operations into algebra. Key result: counting, recurrences, and convolutions become multiplication, differentiation, and substitution of functions. Used across combinatorics, probability, number theory, and analysis of algorithms. Introduced by Abraham de Moivre (1730) and developed extensively by Euler and Laplace.
A sequence is hard to manipulate term-by-term, but the whole sequence at once, viewed as a power series, lives in a ring where you can add, multiply, invert, differentiate, and compose. The clothesline metaphor (Wilf): a generating function is a clothesline on which we hang up the terms of a sequence for display. The power of is just a label remembering position ; the coefficient is the datum. Combinatorial operations on objects (disjoint union, pairing, sequencing) correspond exactly to algebraic operations on their generating functions.
Formal Statement
Given a sequence of numbers (in a commutative ring , typically , , or ), its ordinary generating function is the formal power series
Derivation hint: This is a definition; is a formal indeterminate, not a number, and convergence is not required. Here denotes the coefficient extraction operator: returns the coefficient of .
The exponential generating function of is
Derivation hint: The weighting is chosen so that labelled-structure operations (where order of labels matters) become clean products. EGFs are preferred for labelled combinatorial structures (permutations, labelled graphs); OGFs for unlabelled ones (partitions, integer compositions).
The set of all formal power series over forms a commutative ring under coefficientwise addition and Cauchy-product multiplication:
Derivation hint: Collect all products contributing to ; the inner sum is the convolution . A series is invertible in if and only if is a unit of (e.g. when is a field).
If and are OGFs, then the product is the OGF of the convolution sequence . For EGFs, the product is the EGF of the binomial convolution:
Derivation hint: Multiply by , set , and multiply and divide by to recover the binomial coefficient.
For OGFs, the following correspondences hold (with ):
Derivation hint: Shift by reindexing ; the factor comes from ; the partial-sum identity is convolution of with the all-ones sequence .
Why It Holds / Derivation
We derive the closed form of the Fibonacci numbers .
Step 1. Define .
Step 2. Encode the recurrence. Multiply (valid for ) by and sum:
Step 3. Express each sum via . The left side is . The first right sum is . The second is .
Step 4. Assemble: , hence
Derivation hint: Collect terms on the left and factor.
Step 5. Partial fractions. Factor where , . Decompose:
Step 6. Expand each geometric series and read off coefficients:
Derivation hint: ; subtract the two geometric expansions termwise.
∎Though de Moivre first used generating functions to solve recurrences, Euler made them a central tool of analysis and number theory. His 1748 Introductio in analysin infinitorum used the product as the generating function for partitions, leading to the Pentagonal Number Theorem and deep partition identities. Euler treated formal series with a fearless algebraic spirit—manipulating divergent series and infinite products to extract finite truths—anticipating the rigorous formal-power-series framework formalized only in the 20th century.
Building Intuition
Think of as a box labelled , and as the number of marbles in that box. The series is the entire shelf of boxes. Multiplying two generating functions is like asking: in how many ways can I pick a marble from 's box and one from 's box so the labels add to ? That's exactly a convolution, which is how counting "split this object into two parts" works. The variable "remembers size by exponent and adds sizes by multiplication"—it is a size-tracking accountant. You never plug in a number unless you want a value (e.g. setting to sum the sequence, or differentiating then setting to get a weighted sum/expectation).
Worked Examples
Given. How many ways can a positive integer be written as an ordered sum of positive integers (compositions)? E.g. , so ways.
Step 1. A single positive part has OGF (one object of each size ).
Step 2. A composition is a sequence of parts. The "sequence of one or more " construction gives
Step 3. Expand: , so for .
Answer. (e.g. ✓, dimensionless count).
Given. Roll a fair die; let be the outcome. Find using the probability generating function .
Step 1. Each face has probability , so
Step 2. Use the identity .
Step 3. Evaluate at :
Answer. (dimensionless; matches direct computation). Note: variance follows from .
Common Misconceptions
Generating functions are formal, not analytic—by default. You do not need to converge anywhere for the algebra to be valid. The series has radius of convergence , yet is a perfectly good element of on which you may add, multiply, and invert. Convergence is required only when you actually substitute a numerical value of (e.g. setting , or applying analytic methods like singularity analysis to estimate ). Confusing the formal and analytic viewpoints leads to false statements about "the value" of a divergent generating function.
Multiplication is not always valid for two-sided or Laurent series. The Cauchy product requires each coefficient to be a finite sum. If you allow doubly-infinite series , the convolution can become an infinite sum with no formal meaning. For example, formally multiplying by gives a coefficient of equal to . Thus the ring structure relies crucially on series being bounded below in degree.
Connections
Generating functions sit at a crossroads of many fields. The OGF dictionary is the engine of Analytic Combinatorics, where the location and nature of singularities of control the asymptotic growth of (Flajolet–Sedgewick). In probability, the Probability Generating Function and Moment Generating Function are specializations giving moments and supporting limit theorems. The EGF formalism is the species-theoretic shadow of Exponential Formula for labelled structures. Number theory uses Dirichlet Series —a "multiplicative" cousin where convolution corresponds to Dirichlet rather than Cauchy product. The recurrence-solving method generalizes via the Z-transform in signal processing and the Laplace Transform in the continuous setting.
Real-World Applications
Historical Development
Subtleties & Limits
Generating functions are most powerful when they have a nice closed form, but classifying which sequences admit which kind of GF is deep. A sequence is D-finite (holonomic) iff its OGF satisfies a linear ODE with polynomial coefficients; algebraic iff the OGF satisfies a polynomial equation; and these classes are properly nested. Determining whether a given combinatorially defined OGF is algebraic, D-finite, or "wild" can be extremely hard. Famous open territory: many sequences in enumerative combinatorics (e.g. certain self-avoiding-walk and lattice-animal counts) are conjectured to be non-D-finite, but proving non-holonomicity is notoriously difficult. The automatic/transcendence classification of multivariate generating functions, and effective asymptotics from implicit functional equations, remain active research areas.
See Also
Power Series · Recurrence Relations · Probability Generating Function · Moment Generating Function · Analytic Combinatorics · Partition Theory · Dirichlet Series · Z-transform · Catalan Numbers · Exponential Formula