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 generating function is a formal device that packages an infinite sequence into a single object—the formal power series (ordinary type) or (exponential type). The "function" is a bookkeeping tool: we manipulate it algebraically and then read off coefficients, often without ever evaluating it at a number. This matters because difficult problems about sequences—solving recurrences, counting structures, computing convolutions—translate into routine operations on functions like addition, multiplication, and differentiation. The surprising fact is that a closed-form function can compress infinitely many combinatorial facts: for instance, contains every Fibonacci number, and its partial fraction decomposition instantly yields Binet's formula.

The Core Insight

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

Ordinary Generating Function (OGF)

Given a sequence of numbers (in a commutative ring , typically , , or ), its ordinary generating function is the formal power series

1
⟳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 .

Exponential Generating Function (EGF)

The exponential generating function of is

2
⟳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 Ring of Formal Power Series

The set of all formal power series over forms a commutative ring under coefficientwise addition and Cauchy-product multiplication:

3
⟳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).

Convolution Theorem

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:

4
⟳Multiply by , set , and multiply and divide by to recover the binomial coefficient.

Fundamental Operations Dictionary

For OGFs, the following correspondences hold (with ):

5
⟳Shift by reindexing ; the factor comes from ; the partial-sum identity is convolution of with the all-ones sequence .

Why It Holds / Derivation

Solving a Linear Recurrence via OGF: the Fibonacci case

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
6
⟳Collect terms on the left and factor.
Step 5. Partial fractions. Factor where , . Decompose:
Step 6. Expand each geometric series and read off coefficients:
7
⟳; subtract the two geometric expansions termwise.

Leonhard Euler | 1707–1783

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).

OGF as a shelf of labelled coefficient-boxes; product = convolution

A(x) = a₀ + a₁x + a₂x² + a₃x³ + … a₀ a₁ a₂ a₃ x⁰ x¹ x² x³ Coefficient of xⁿ in A(x)B(x): cₙ = Σₖ aₖ b₍ₙ₋ₖ₎ (convolution) labels add to n

Worked Examples

Counting compositions of an integer

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).

Mean of a probability distribution via PGF

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

  1. Algorithm analysis. Average-case running times (e.g. of Quicksort, hashing, binary search trees) are extracted from generating functions of cost; Knuth's The Art of Computer Programming and Flajolet–Sedgewick's Analytic Combinatorics systematize this.
  2. Coding theory. The weight enumerator polynomial of an error-correcting code is a generating function over codeword weights; the MacWilliams identity relates a code's enumerator to its dual's.
  3. Statistical mechanics. The partition function is literally a generating function over energy states; derivatives give energy, heat capacity, and other thermodynamic quantities.
  4. Queueing theory & reliability. PGFs of queue lengths and busy-period lengths (e.g. in the M/G/1 queue) are obtained via generating-function functional equations.
  5. Genetics & branching processes. Galton–Watson extinction probabilities are computed as fixed points of the offspring PGF.
  6. Cryptography & combinatorial enumeration. Counting Latin squares, lattice paths, and configurations underpins randomness and design analysis.
  7. Financial mathematics. Compound-distribution aggregate-loss models in actuarial science use PGFs (Panjer recursion) to compute claim-total distributions.

Historical Development

  • 1730 — Abraham de Moivre, in Miscellanea Analytica, introduces generating functions to solve linear recurrences, including a closed form for Fibonacci-type sequences.
  • 1748 — Euler publishes Introductio in analysin infinitorum, using infinite products as generating functions for partitions; foundation of partition theory.
  • 1750s — Euler discovers the Pentagonal Number Theorem, expressing as a sparse signed series.
  • 1782 — Pierre-Simon Laplace systematizes "fonctions génératrices" in his probability work, coining the modern term and applying them to difference equations.
  • 1812 — Laplace's Théorie analytique des probabilités makes generating functions (and the Laplace transform) central to probability.
  • 1900s–1930s — Formal power series receive rigorous algebraic foundations; the ring is studied abstractly.
  • 1960s — Donald Knuth popularizes generating functions for rigorous algorithm analysis.
  • 1970s–1980s — Gian-Carlo Rota, Joyal's theory of species, and the umbral calculus give combinatorics a structural, functorial language for generating functions.
  • 1990s–2009 — Philippe Flajolet and Robert Sedgewick develop Analytic Combinatorics, linking singularities of generating functions to coefficient asymptotics; Wilf's generatingfunctionology becomes a standard text.

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

Before this

Where this leads