Generating functions
A generating function packs an entire distribution into one function: hangs every probability on the coefficient of , like laundry on a clothesline, and hard operations on distributions become easy operations on functions: convolution becomes multiplication, random sums become composition, recursions become algebra. This chapter builds the PGF toolkit, factorises dice, finds branching-process extinction as a fixed point, situates MGFs and characteristic functions, and closes by solving a Fibonacci-flavoured coin-flip recursion in three lines.
A discrete distribution is an infinite list of numbers, and lists are clumsy: adding two independent random variables forces you to convolve them — , a fresh sum for every . The generating function trades the list for the single object , and the dummy variable does the bookkeeping: multiplying power series automatically convolves coefficients, because . Everything here is that idea worn four ways: encode the distribution so that summing, mixing, compounding, or recursing becomes algebra on .
The clothesline: definition and first properties#
For a random variable taking values in , the probability generating function is
convergent there since the coefficients are probabilities. Three facts fall out immediately:
- Normalisation: — every PGF passes through .
- Recovery: — Taylor’s theorem reads probabilities back off the clothesline; in particular , which the branching-process section leans on hard.
- Uniqueness: a power series determines its coefficients, so forces — to prove two distributions equal, match their PGFs.
Moments come from derivatives at — the second derivative delivers the factorial moment, since differentiating twice produces , and the variance formula repairs the difference:
Bernoulli(): with — a one-rung clothesline. Binomial(): by the binomial theorem — or wait one section and get it for free from independence. Geometric() on (trials to first success): ; check , the familiar mean from common distributions. Poisson(): ; then and give — index gymnastics replaced by a one-line differentiation.
Independence means multiply#
The theorem that earns the whole machine: for independent and ,
because independence factorises the expectation of . Compare the convolution slog of transformations of random variables: there, a sum cost a fresh summation for every value; here, one multiplication for all values at once. Two showpieces:
- Binomial = product of Bernoullis. A Binomial() count is a sum of independent Bernoullis, so its PGF is — no binomial theorem needed.
- Sum of independent Poissons is Poisson. , the Poisson() PGF — uniqueness finishes the proof. The direct convolution route needs a Vandermonde-style binomial sum; the PGF route adds two exponents. This additivity is why two independent order-flow streams merge into one Poisson stream at the summed rate.
The implication runs from independence to factorisation, not back — and the PGF of a sum records the sum’s distributiononly, forgetting joint structure. Two portfolios can have identical P&L distributions with wildly different co-movement; keep joint distributions in the toolkit.
The dice factorisation showpiece#
Generating functions turn dice questions into polynomial questions — and polynomial factorisation is a solved subject. Two classics, worked fully.
Can you load two six-sided dice (any face probabilities) so that the sum is uniform on , each sum with probability ? Writing the dice PGFs , , uniformity demands
Reaching sums 2 and 12 forces , so , with real polynomials of degree exactly 5, and . The killer observation: has odd degree, and every real polynomial of odd degree has a real root. But the roots of are the eleventh roots of unity other than 1 — none of them real. Contradiction. A fact about all possible dice, proved by looking at eleven complex numbers on a circle.
The standard die has face polynomial (PGF times 6), which factorises over the integers as
Two standard dice give the sum polynomial — each factor twice. Any pair with the same sum distribution must split these eight factors into two polynomials with non-negative coefficients, value 6 at (six faces), and no constant term (positive faces). At the factors evaluate to , so each die takes one , one , one ; the only freedom is where the two factors go. One each recovers the standard dice; both on one die gives
Faces and — the Sicherman dice, the unique non-standard pair of positive-integer-faced dice whose sum matches two ordinary dice. Sum-7 check: six of 36 pairs, , exactly the standard count. Distribution problems became factor bookkeeping.
Random sums: composition#
Sum a random number of terms: , the i.i.d. with PGF , an independent count with PGF — losses over a random number of claims, fills over a random number of child orders:
Condition on and apply the tower property from conditional expectation:
where the middle equality uses independence — given , the inner expectation is — and the last is the definition of evaluated at the number . Differentiate at with the chain rule, using : — Wald’s identity in one stroke. Compare the stopping-time proof in martingales & optional stopping, which allows to depend on the summands. A second differentiation gives .
Branching processes and extinction#
The deepest application of composition. A branching process starts with one individual (); each independently produces offspring with PGF and mean . Generation sizes obey — a random sum — so the PGF of is the -fold composition . Does the line die out? Since , extinction by generation is literally iterating from 0.
The events increase (an extinct line stays extinct), so , the extinction probability, by continuity of probability; and since with continuous, . It is the smallest fixed point in : for any , induction with the monotonicity of (non-negative coefficients) gives , so .
The trichotomy comes from convexity: , so the curve crosses the diagonal at most twice, always passing through with slope . If (subcritical or critical) the curve stays above the diagonal on and : extinction is certain — even at , where the population is a martingale yet still dies (excluding the degenerate one-child-always case). If (supercritical), the curve dips below the diagonal near 1 and picks up a second crossing at some : survival has positive probability .
For Poisson() offspring, and : supercritical. The fixed-point equation has no closed form, but iterating from 0 converges fast: , , … . Each iterate is a probability — extinct by generation — so the staircase below is the population’s life history, one generation per step.

Branching arithmetic runs anything that spreads by replication. An order-book message cascade — one aggressive order triggers algos whose reactions trigger more — has offspring mean = average follow-on messages per message: at bursts die fast; near 1 cascade sizes grow heavy tails; past 1 you get flash-crash dynamics that need not damp. Default contagion reads the same way, and — a lighter analogy — a trading edge spawning copycats each “generation” dies out with certainty when but crowds permanently with probability when . The moral is the trichotomy itself: the qualitative fate of the whole system is decided by a first derivative crossing 1.
import numpy as np
rng = np.random.default_rng(42)
lam = 1.5 # Poisson offspring mean (supercritical: m = 1.5 > 1)
# Fixed point of s = exp(lam*(s-1)): iterate G from 0.
q = 0.0
for _ in range(200):
q = np.exp(lam * (q - 1.0))
def goes_extinct(max_gen=100, cap=10_000):
z = 1
for _ in range(max_gen):
z = rng.poisson(lam, size=z).sum()
if z == 0:
return True
if z > cap: # this large essentially never dies
return False
return False
freq = np.mean([goes_extinct() for _ in range(20_000)])
print(f"simulated extinction frequency : {freq:.4f}")
print(f"fixed point of s = e^(lam(s-1)) : {q:.4f}")
# Expected: both extinction numbers near 0.4172.MGFs, Chernoff, and characteristic functions#
The moment generating function is the PGF in different clothes — substitute — but works for continuous and negative-valued variables too. Expanding the exponential, : the clothesline now hangs moments, , and independence still multiplies: .
For , write and compute for standard :
since and the shifted Gaussian still integrates to 1. Hence : sums of independent normals are normal (exponents add), and every normal moment is a coefficient — the coefficient gives .
The MGF is also the Chernoff engine: Markov’s inequality applied to gives for any , and optimising over produces exponentially decaying tail bounds — worked in full in inequalities & tail bounds. One caveat: MGFs can fail to exist — is infinite for every when is lognormal (see common distributions): tails heavier than exponential kill the integral. One repair: the characteristic function always exists ( is bounded) and keeps every virtue — uniqueness, multiplication under independence, moments from derivatives. It is how the CLT is actually proved: the sketch in LLN & CLT is a second-order Taylor expansion of raised to the -th power.
Solving recursions: no two heads in a row#
The last hat generating functions wear: solving recursions. How many length- H/T sequences contain no two consecutive heads? Condition the count on the last flip: ending in T leaves any valid string of length ; ending in H forces a preceding T, leaving length . So with (set ): Fibonacci in disguise, . Multiply by , sum over , and solve for :
Partial fractions over the roots of give with — surviving fair flips without HH decays like . Now the pivot to waiting times: if is the flip on which HH first completes, is exactly “no HH in the first flips,” so , and the tail-sum formula from random variables & moments evaluates the expectation as the generating function at a point:
Six flips on average to see HH — agreeing, by a completely different route, with the overlap formula from the ABRACADABRA argument in martingales & optional stopping. The full distribution comes too: inverts to — check , — the clothesline, fully loaded.
Practice problems#
Five problems to test understanding — each turns into algebra once you write the right generating function.
Write the PGF of one fair die and of the sum of dice; compute .
Solution. One die: ; dice: by independence. For we need the coefficient of , over 216: gives , the term with gives , so . The machinery replaced enumerating 27 ordered triples — and scales to 10 dice, where enumeration does not.
Show via PGFs that the sum of independent Geometric() variables is negative binomial, and read off its pmf.
Solution. Multiply PGFs: . Expand with the generalised binomial series : the coefficient of (with ) is — the negative binomial pmf: the first trials hold successes, and trial is the -th. The PGF proves in two lines what convolution proves in a page — the combinatorial reading falls out of the algebra.
Claims arrive as ; each claim size is independently Geometric() on . Find the PGF of the total , then and .
Solution. Composition: , so . Wald: . Atoms: — exactly , since every claim is at least 1; and , agreeing with . Composition turned a two-layer random object into function evaluation.
A branching process has offspring distribution . Find the extinction probability.
Solution. , mean : supercritical. Solve : multiplying by 4, , roots and 1; the extinction probability is the smallest root, ( is always a root, so factor it out first). A coin-flip fate for a population growing 25% per generation on average — expectation says explode, the fixed point says half of all lines still die.
A fair coin is flipped 10 times. What is the probability that no two consecutive flips are both heads?
Solution. The recursion , runs , so — or extract the coefficient of . Probability: — equivalently for the first-HH waiting time. The takeaway generalises: pattern-avoidance counts satisfy linear recursions, their generating functions are rational, and survival probabilities decay geometrically at a rate set by the dominant root.
Next:from packing distributions into functions to reading probabilities off pictures — lengths, areas, and volumes as probability measures, Buffon’s needle, and the art of choosing the right “uniform”: Geometric probability.
