Skip to content
The Lumenary
First-year graduateGraduate 150 min

Measure-theoretic probability

Kolmogorov's axioms turn chance into measure — "almost surely" becomes a precise statement, a conditional expectation becomes a random variable, and the great limit theorems become theorems.

Formally verified · 13 LeanComputationally tested · 3 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

What does “almost surely” mean?

Toss a fair coin forever and record the proportion of heads after nn tosses. In 1909 Émile Borel proved that this proportion tends to 12\tfrac12 "with probability one". What can that mean? The sequence HHHH… is a perfectly possible outcome, and so are uncountably many other sequences whose proportion of heads tends to 13\tfrac13, or oscillates forever. The claim is that all these exceptional sequences together form an event of probability zero — not an empty event, but a negligible one.

To say this we need a probability on the space {0,1}N\{0, 1\}^{\N} of all infinite toss sequences, an uncountable set on which every single sequence has probability 00. The event "the proportion converges to 12\tfrac12" is built from infinitely many tosses by countably many unions and intersections, so the probability must be countably additive. This is precisely measure theory.

A second puzzle concerns conditioning on events of probability zero. Choose a point uniformly on the Earth's surface and condition on its lying on the Greenwich meridian (an event of probability 00). Is its latitude then uniformly distributed? Computed as a limit of thin longitude wedges the answer is "no, it has density proportional to cos⁡(latitude)\cos(\text{latitude})"; computed with thin bands of constant width around the meridian, "yes". This is the Borel–Kolmogorov paradox. Kolmogorov's way out (1933) was to condition not on single events but on σ-algebras — on information — and to define the conditional expectation as a random variable, determined up to null sets by the Radon–Nikodym theorem. This lesson builds that theory and proves with it the three pillars of classical probability: the strong law of large numbers, the martingale convergence theorem and the central limit theorem.

IntuitionH

A dictionary, and σ-algebras as information

Kolmogorov's Grundbegriffe der Wahrscheinlichkeitsrechnung (1933) is a translation table. Every probabilistic notion is a measure-theoretic one with a new name — and the probabilist's interest lies in the questions the new names suggest.

ProbabilityMeasure theory
sample space Ω\Omega, events F\mathcal Fa set with a σ-algebra
probability PPa measure with P(Ω)=1P(\Omega) = 1
random variable XXa measurable function Ω→R\Omega \to \R
law (distribution) of XXthe pushforward measure μX=P∘X−1\mu_X = P \circ X^{-1} on R\R
expectation E[X]\mathbb E[X]the integral ∫ΩX dP\int_\Omega X \, dP
independenceproduct measure
almost surely (a.s.)almost everywhere
conditional expectation E[X∣G]\mathbb E[X \mid \mathcal G]a Radon–Nikodym derivative; an orthogonal projection in L2L^2

The genuinely new idea is to read a sub-σ-algebra G⊆F\mathcal G \subseteq \mathcal F as information: the events whose occurrence an observer can decide. A random variable is G\mathcal G-measurable when the observer can compute its value. As time passes, information grows: a filtration F0⊆F1⊆⋯\mathcal F_0 \subseteq \mathcal F_1 \subseteq \cdots. The conditional expectation E[X∣G]\mathbb E[X \mid \mathcal G] is the observer's best guess of XX — itself a random quantity, because it depends on what the observer has seen.

DefinitionsH

Definitions

Definition— probability space, random variable, law

A probability space is a measure space (Ω,F,P)(\Omega, \mathcal F, P) with P(Ω)=1P(\Omega) = 1. A random variable is a measurable X:Ω→RX : \Omega \to \R; its law is the Borel probability measure μX(B)=P(X∈B)\mu_X(B) = P(X \in B) and its distribution function is FX(x)=P(X≤x)F_X(x) = P(X \le x). The expectation of an integrable XX is E[X]=∫X dP\mathbb E[X] = \int X \, dP, and for Borel gg with g(X)g(X) integrable, E[g(X)]=∫Rg dμX\mathbb E[g(X)] = \int_\R g \, d\mu_X (change of variables).

Definition— independence

Sub-σ-algebras G1,…,Gn⊆F\mathcal G_1, \dots, \mathcal G_n \subseteq \mathcal F are independent if P(A1∩⋯∩An)=P(A1)⋯P(An)P(A_1 \cap \dots \cap A_n) = P(A_1) \cdots P(A_n) for all Ai∈GiA_i \in \mathcal G_i; an infinite family is independent if every finite subfamily is. Random variables are independent if the σ-algebras σ(Xi)={Xi−1(B)}\sigma(X_i) = \{X_i^{-1}(B)\} are; events are independent if their indicators are. By Dynkin's π–λ theorem it suffices to check the product rule on generating π-systems, so X1,…,XnX_1, \dots, X_n are independent if and only if P(X1≤x1,…,Xn≤xn)=∏iFXi(xi)P(X_1 \le x_1, \dots, X_n \le x_n) = \prod_i F_{X_i}(x_i), i.e. if and only if their joint law is the product measure μX1⊗⋯⊗μXn\mu_{X_1} \otimes \cdots \otimes \mu_{X_n}.

Definition— modes of convergence

Let X,X1,X2,…X, X_1, X_2, \dots be random variables. Then Xn→XX_n \to X

  • almost surely if P({ω:Xn(ω)→X(ω)})=1P(\{\omega : X_n(\omega) \to X(\omega)\}) = 1;
  • in probability if P(∣Xn−X∣>ε)→0P(|X_n - X| > \varepsilon) \to 0 for every ε>0\varepsilon > 0;
  • in LpL^p (p≥1p \ge 1) if E∣Xn−X∣p→0\mathbb E|X_n - X|^p \to 0;
  • in distribution (or weakly) if E[f(Xn)]→E[f(X)]\mathbb E[f(X_n)] \to \mathbb E[f(X)] for every bounded continuous f:R→Rf : \R \to \R; equivalently, FXn(x)→FX(x)F_{X_n}(x) \to F_X(x) at every point xx where FXF_X is continuous.

The first three need the variables to live on one probability space; convergence in distribution is a statement about the laws μXn\mu_{X_n} only.

Definition— characteristic function

The characteristic function of XX is φX(t)=E[eitX]=∫Reitx dμX(x)\varphi_X(t) = \mathbb E[e^{itX}] = \int_\R e^{itx} \, d\mu_X(x) for t∈Rt \in \R — the Fourier transform of its law, defined for every random variable since ∣eitX∣=1|e^{itX}| = 1.

Definition— conditional expectation

Let XX be integrable and G⊆F\mathcal G \subseteq \mathcal F a sub-σ-algebra. A conditional expectation of XX given G\mathcal G is a random variable YY such that

  1. YY is G\mathcal G-measurable and integrable, and
  2. ∫GY dP=∫GX dP\displaystyle \int_G Y \, dP = \int_G X \, dP for every G∈GG \in \mathcal G.

It exists and is unique up to almost-sure equality (theorem below); we write Y=E[X∣G]Y = \mathbb E[X \mid \mathcal G], and E[X∣Z]=E[X∣σ(Z)]\mathbb E[X \mid Z] = \mathbb E[X \mid \sigma(Z)]. Conditional probability is P(A∣G)=E[1A∣G]P(A \mid \mathcal G) = \mathbb E[\mathbf 1_A \mid \mathcal G].

Definition— filtration, martingale, stopping time

A filtration is an increasing sequence F0⊆F1⊆⋯⊆F\mathcal F_0 \subseteq \mathcal F_1 \subseteq \cdots \subseteq \mathcal F. A process (Mn)(M_n) is adapted if each MnM_n is Fn\mathcal F_n-measurable. An adapted process of integrable variables is a martingale if E[Mn+1∣Fn]=Mn\mathbb E[M_{n+1} \mid \mathcal F_n] = M_n a.s. for all nn, a supermartingale if E[Mn+1∣Fn]≤Mn\mathbb E[M_{n+1} \mid \mathcal F_n] \le M_n, and a submartingale if ≥\ge. A stopping time is a random variable T:Ω→{0,1,2,… }∪{∞}T : \Omega \to \{0, 1, 2, \dots\} \cup \{\infty\} with {T=n}∈Fn\{T = n\} \in \mathcal F_n for every nn: whether to stop now can be decided from the information available now. A process (Hn)n≥1(H_n)_{n \ge 1} is predictable if each HnH_n is Fn−1\mathcal F_{n-1}-measurable.

By the tower property (below), the martingale condition for one step implies E[Mm∣Fn]=Mn\mathbb E[M_m \mid \mathcal F_n] = M_n for all m≥nm \ge n; this is Mathlib's definition.

Worked examplesH

Examples and counterexamples

Example— Infinitely many coin tosses are Lebesgue measure

Let Ω=[0,1)\Omega = [0, 1) with Lebesgue measure and let dn(ω)∈{0,1}d_n(\omega) \in \{0, 1\} be the nn-th binary digit of ω\omega (choosing the expansion not ending in 11s). The event {d1=a1,…,dn=an}\{d_1 = a_1, \dots, d_n = a_n\} is a dyadic interval of length 2−n2^{-n}, so P(d1=a1,…,dn=an)=2−n=∏k≤nP(dk=ak)P(d_1 = a_1, \dots, d_n = a_n) = 2^{-n} = \prod_{k \le n} P(d_k = a_k): the digits are independent fair coin tosses. So the infinite product of fair coins exists, and Borel's theorem says that almost every real number has asymptotically half its binary digits equal to 11. (In general, infinite products of probability spaces exist by the Kolmogorov extension theorem.)

Example— The modes of convergence are different

On Ω=[0,1)\Omega = [0, 1) with Lebesgue measure:

  • Xn=n 1(0,1/n)→0X_n = n \, \mathbf 1_{(0, 1/n)} \to 0 almost surely (at every point) but not in L1L^1: EXn=1\mathbb E X_n = 1.
  • The "typewriter" indicators of [0,1),[0,12),[12,1),[0,14),…[0, 1), [0, \tfrac12), [\tfrac12, 1), [0, \tfrac14), \dots tend to 00 in L1L^1 and in probability, but converge at no point.
  • If XX is standard normal and Xn=−XX_n = -X, then Xn→XX_n \to X in distribution (they have the same law) but P(∣Xn−X∣>1)=P(∣X∣>12)P(|X_n - X| > 1) = P(|X| > \tfrac12) does not tend to 00.

A cleaner probabilistic example of convergence in probability without almost-sure convergence uses independence: if A1,A2,…A_1, A_2, \dots are independent with P(An)=1/nP(A_n) = 1/n, then 1An→0\mathbf 1_{A_n} \to 0 in probability, but by the second Borel–Cantelli lemma (below) infinitely many AnA_n occur almost surely, so 1An↛0\mathbf 1_{A_n} \not\to 0 a.s.

Example— Conditioning on a partition

Let G\mathcal G be generated by a partition Ω=B1⊔⋯⊔Bk\Omega = B_1 \sqcup \dots \sqcup B_k with P(Bi)>0P(B_i) > 0. Every G\mathcal G-measurable function is constant on each BiB_i, and condition 2 with G=BiG = B_i forces the constant:

E[X∣G]=∑i=1kE[X1Bi]P(Bi) 1Bi,\mathbb E[X \mid \mathcal G] = \sum_{i=1}^k \frac{\mathbb E[X \mathbf 1_{B_i}]}{P(B_i)} \, \mathbf 1_{B_i},

the elementary conditional expectations "glued together". For two fair dice X1,X2X_1, X_2, E[X1+X2∣X1]=X1+72\mathbb E[X_1 + X_2 \mid X_1] = X_1 + \tfrac72: a random variable, equal to 152\tfrac{15}{2} on the event {X1=4}\{X_1 = 4\}. With a joint density f(x,y)f(x, y), E[X∣Y]=h(Y)\mathbb E[X \mid Y] = h(Y) where h(y)=∫xf(x,y) dx/∫f(x,y) dxh(y) = \int x f(x, y)\, dx \big/ \int f(x, y) \, dx wherever the denominator is positive; changing hh on a μY\mu_Y-null set changes nothing. That freedom is exactly what dissolves the Borel–Kolmogorov paradox: conditioning on the null event {Y=y}\{Y = y\} is meaningful only through the whole family y↦h(y)y \mapsto h(y), which depends on the σ-algebra (the variable YY), not on the event alone.

Example— Martingales

  1. Sums. If ξ1,ξ2,…\xi_1, \xi_2, \dots are independent and integrable with mean 00, and Fn=σ(ξ1,…,ξn)\mathcal F_n = \sigma(\xi_1, \dots, \xi_n), then Sn=ξ1+⋯+ξnS_n = \xi_1 + \dots + \xi_n is a martingale: E[Sn+1∣Fn]=Sn+E[ξn+1]=Sn\mathbb E[S_{n+1} \mid \mathcal F_n] = S_n + \mathbb E[\xi_{n+1}] = S_n. If moreover Eξi2=σ2\mathbb E \xi_i^2 = \sigma^2, then Sn2−nσ2S_n^2 - n\sigma^2 is a martingale.
  2. Products. If ξi≥0\xi_i \ge 0 are independent with Eξi=1\mathbb E \xi_i = 1, then Mn=ξ1⋯ξnM_n = \xi_1 \cdots \xi_n is a martingale (likelihood ratios in statistics are of this form).
  3. Doob martingales. For integrable XX and any filtration, Mn=E[X∣Fn]M_n = \mathbb E[X \mid \mathcal F_n] is a martingale — the sequence of ever better guesses of XX.
  4. Pólya's urn. An urn holds one red and one blue ball; repeatedly draw a ball and return it together with another of the same colour. If RnR_n is the number of red balls after nn draws, the fraction Mn=Rn/(n+2)M_n = R_n/(n + 2) satisfies E[Mn+1∣Fn]=Rnn+2⋅Rn+1n+3+n+2−Rnn+2⋅Rnn+3=Rnn+2\mathbb E[M_{n+1} \mid \mathcal F_n] = \frac{R_n}{n+2} \cdot \frac{R_n + 1}{n+3} + \frac{n + 2 - R_n}{n+2} \cdot \frac{R_n}{n+3} = \frac{R_n}{n+2}: a martingale.
ProofH

Borel–Cantelli, the zero–one law and the laws of large numbers

For events AnA_n, the event "infinitely many AnA_n occur" is lim sup⁡nAn=⋂n≥1⋃k≥nAk\limsup_n A_n = \bigcap_{n \ge 1} \bigcup_{k \ge n} A_k.

Theorem— First Borel–Cantelli lemma

If ∑nP(An)<∞\sum_n P(A_n) < \infty, then P(lim sup⁡nAn)=0P(\limsup_n A_n) = 0: almost surely only finitely many of the AnA_n occur.

Proof

For every nn, lim sup⁡kAk⊆⋃k≥nAk\limsup_k A_k \subseteq \bigcup_{k \ge n} A_k, so by countable subadditivity P(lim sup⁡kAk)≤∑k≥nP(Ak)P(\limsup_k A_k) \le \sum_{k \ge n} P(A_k). The right side is the tail of a convergent series and tends to 00 as n→∞n \to \infty.

∎

Theorem— Second Borel–Cantelli lemma

If the events AnA_n are independent and ∑nP(An)=∞\sum_n P(A_n) = \infty, then P(lim sup⁡nAn)=1P(\limsup_n A_n) = 1.

Proof

It suffices to show P(⋂k≥nAkc)=0P\big(\bigcap_{k \ge n} A_k^c\big) = 0 for each nn, since the complement of lim sup⁡Ak\limsup A_k is ⋃n⋂k≥nAkc\bigcup_n \bigcap_{k \ge n} A_k^c. The complements AkcA_k^c are independent too, so for N≥nN \ge n, using 1−x≤e−x1 - x \le e^{-x},

P(⋂k=nNAkc)=∏k=nN(1−P(Ak))≤exp⁡(−∑k=nNP(Ak))→N→∞0.P\Big(\bigcap_{k=n}^N A_k^c\Big) = \prod_{k=n}^N \big(1 - P(A_k)\big) \le \exp\Big(-\sum_{k=n}^N P(A_k)\Big) \xrightarrow[N \to \infty]{} 0.

By continuity from above, P(⋂k≥nAkc)=lim⁡NP(⋂k=nNAkc)=0P\big(\bigcap_{k \ge n} A_k^c\big) = \lim_N P\big(\bigcap_{k=n}^N A_k^c\big) = 0.

∎

Independence cannot be dropped: if An=AA_n = A for a single event with P(A)=12P(A) = \tfrac12, the sum diverges but P(lim sup⁡An)=12P(\limsup A_n) = \tfrac12. In the second lemma, lim sup⁡An\limsup A_n is a tail event: it does not depend on any finitely many of the AnA_n. That its probability is 00 or 11 is no accident.

Theorem— Kolmogorov's zero–one law

Let F1,F2,…\mathcal F_1, \mathcal F_2, \dots be independent σ-algebras and T=⋂nσ(Fn,Fn+1,… )\mathcal T = \bigcap_n \sigma(\mathcal F_n, \mathcal F_{n+1}, \dots) the tail σ-algebra. Then P(T)∈{0,1}P(T) \in \{0, 1\} for every T∈TT \in \mathcal T.

Proof

For each nn, σ(F1,…,Fn)\sigma(\mathcal F_1, \dots, \mathcal F_n) is independent of σ(Fn+1,… )⊇T\sigma(\mathcal F_{n+1}, \dots) \supseteq \mathcal T. Hence T\mathcal T is independent of the union ⋃nσ(F1,…,Fn)\bigcup_n \sigma(\mathcal F_1, \dots, \mathcal F_n), a π-system generating σ(F1,F2,… )\sigma(\mathcal F_1, \mathcal F_2, \dots), and by the π–λ theorem of the whole of σ(F1,F2,… )⊇T\sigma(\mathcal F_1, \mathcal F_2, \dots) \supseteq \mathcal T. So TT is independent of itself: P(T)=P(T∩T)=P(T)2P(T) = P(T \cap T) = P(T)^2.

∎

For independent XnX_n the events "∑Xn\sum X_n converges" and "1n∑k≤nXk\frac1n \sum_{k \le n} X_k converges" are tail events, so each has probability 00 or 11; the laws of large numbers say which.

Theorem— Relations between the modes of convergence

(a) Almost-sure convergence implies convergence in probability. (b) Convergence in probability implies almost-sure convergence of a subsequence. (c) Convergence in LpL^p implies convergence in probability. (d) Convergence in probability implies convergence in distribution.

Proof

(a) Fix ε>0\varepsilon > 0 and let En=⋃m≥n{∣Xm−X∣>ε}E_n = \bigcup_{m \ge n} \{|X_m - X| > \varepsilon\}. These decrease to a subset of {Xm↛X}\{X_m \not\to X\}, which is null; by continuity from above P(∣Xn−X∣>ε)≤P(En)→0P(|X_n - X| > \varepsilon) \le P(E_n) \to 0.

(b) Choose n1<n2<⋯n_1 < n_2 < \cdots with P(∣Xnk−X∣>2−k)≤2−kP(|X_{n_k} - X| > 2^{-k}) \le 2^{-k}. By the first Borel–Cantelli lemma, almost surely ∣Xnk−X∣≤2−k|X_{n_k} - X| \le 2^{-k} for all large kk, so Xnk→XX_{n_k} \to X a.s.

(c) Markov's inequality: P(∣Xn−X∣>ε)≤ε−p E∣Xn−X∣pP(|X_n - X| > \varepsilon) \le \varepsilon^{-p} \, \mathbb E|X_n - X|^p.

(d) Let ff be bounded and continuous, and suppose Ef(Xn)↛Ef(X)\mathbb E f(X_n) \not\to \mathbb E f(X); pass to a subsequence along which ∣Ef(Xn)−Ef(X)∣≥δ>0|\mathbb E f(X_n) - \mathbb E f(X)| \ge \delta > 0. By (b) a further subsequence converges a.s., so f(Xn)→f(X)f(X_n) \to f(X) a.s. along it, and dominated convergence (with the bound sup⁡∣f∣\sup |f|) gives Ef(Xn)→Ef(X)\mathbb E f(X_n) \to \mathbb E f(X) — a contradiction.

∎

Theorem— Weak law of large numbers (Chebyshev)

Let X1,X2,…X_1, X_2, \dots be pairwise independent with EXi=μ\mathbb E X_i = \mu and Var⁡Xi=σ2<∞\operatorname{Var} X_i = \sigma^2 < \infty, and Xˉn=1n(X1+⋯+Xn)\bar X_n = \frac1n (X_1 + \dots + X_n). Then P(∣Xˉn−μ∣≥ε)≤σ2nε2P(|\bar X_n - \mu| \ge \varepsilon) \le \dfrac{\sigma^2}{n \varepsilon^2}, so Xˉn→μ\bar X_n \to \mu in probability.

Proof

Pairwise independent square-integrable variables are uncorrelated, so Var⁡(X1+⋯+Xn)=∑iVar⁡Xi=nσ2\operatorname{Var}(X_1 + \dots + X_n) = \sum_i \operatorname{Var} X_i = n\sigma^2 and Var⁡Xˉn=σ2/n\operatorname{Var} \bar X_n = \sigma^2/n. Chebyshev's inequality P(∣Y−EY∣≥ε)≤Var⁡Y/ε2P(|Y - \mathbb E Y| \ge \varepsilon) \le \operatorname{Var} Y/\varepsilon^2 (Markov applied to (Y−EY)2(Y - \mathbb E Y)^2) finishes the proof.

∎

Theorem— Strong law of large numbers (fourth-moment version)

Let X1,X2,…X_1, X_2, \dots be independent and identically distributed with EX14<∞\mathbb E X_1^4 < \infty and EX1=μ\mathbb E X_1 = \mu. Then Xˉn→μ\bar X_n \to \mu almost surely.

Proof

Replacing XiX_i by Xi−μX_i - \mu we may assume μ=0\mu = 0. Expand ESn4=∑i,j,k,l≤nE[XiXjXkXl]\mathbb E S_n^4 = \sum_{i, j, k, l \le n} \mathbb E[X_i X_j X_k X_l]. By independence and EXi=0\mathbb E X_i = 0, every term in which some index appears exactly once vanishes. What remains are the nn terms EXi4\mathbb E X_i^4 and, for each of the (n2)\binom{n}{2} pairs i≠ji \ne j, the (42)=6\binom42 = 6 arrangements of Xi2Xj2X_i^2 X_j^2:

ESn4=n EX14+3n(n−1)(EX12)2≤Cn2,\mathbb E S_n^4 = n \, \mathbb E X_1^4 + 3n(n-1) \big(\mathbb E X_1^2\big)^2 \le C n^2,

where C=EX14+3(EX12)2C = \mathbb E X_1^4 + 3 (\mathbb E X_1^2)^2 is finite (note (EX12)2≤EX14(\mathbb E X_1^2)^2 \le \mathbb E X_1^4). By Markov's inequality applied to Sn4S_n^4,

P(∣Sn/n∣>ε)=P(Sn4>ε4n4)≤Cn2ε4n4=Cε4n2,P\big(|S_n/n| > \varepsilon\big) = P\big(S_n^4 > \varepsilon^4 n^4\big) \le \frac{C n^2}{\varepsilon^4 n^4} = \frac{C}{\varepsilon^4 n^2},

which is summable. By the first Borel–Cantelli lemma, almost surely ∣Sn/n∣≤ε|S_n/n| \le \varepsilon for all large nn. Intersecting these almost-sure events over ε=1,12,13,…\varepsilon = 1, \frac12, \frac13, \dots gives Sn/n→0S_n/n \to 0 almost surely.

∎

The fourth moment is a convenience, not a necessity. Kolmogorov (1930) proved the strong law for i.i.d. integrable variables, and Etemadi (1981) found a short proof that needs only pairwise independence: truncate XiX_i at level ii, prove convergence along the geometric subsequence nk=⌊αk⌋n_k = \lfloor \alpha^k \rfloor with Chebyshev and Borel–Cantelli, and interpolate using Xi≥0X_i \ge 0 (Durrett, §2.4). Integrability is necessary: if E∣X1∣=∞\mathbb E|X_1| = \infty, then ∑nP(∣Xn∣>n)=∞\sum_n P(|X_n| > n) = \infty, so by the second Borel–Cantelli lemma ∣Xn∣>n|X_n| > n infinitely often and Xˉn\bar X_n diverges almost surely. Mathlib proves Etemadi's version (see the formal section).

ProofH

Conditional expectation

Theorem— Existence and uniqueness of conditional expectation

For every integrable XX and every sub-σ-algebra G⊆F\mathcal G \subseteq \mathcal F there is a conditional expectation E[X∣G]\mathbb E[X \mid \mathcal G], and any two agree almost surely.

Proof

Existence. First let X≥0X \ge 0. On the measurable space (Ω,G)(\Omega, \mathcal G) define ν(G)=∫GX dP\nu(G) = \int_G X \, dP for G∈GG \in \mathcal G. It is a finite measure (countable additivity is monotone convergence), and it is absolutely continuous with respect to the restriction P∣GP|_{\mathcal G}: if P(G)=0P(G) = 0 then ν(G)=0\nu(G) = 0. By the Radon–Nikodym theorem on (Ω,G)(\Omega, \mathcal G) there is a G\mathcal G-measurable Y≥0Y \ge 0 with ν(G)=∫GY dP\nu(G) = \int_G Y \, dP for all G∈GG \in \mathcal G, and ∫Y dP=ν(Ω)=EX<∞\int Y \, dP = \nu(\Omega) = \mathbb E X < \infty. For general XX apply this to X+X^+ and X−X^- and subtract.

Uniqueness. Let Y,Y′Y, Y' both satisfy the definition and Gk={Y−Y′>1/k}∈GG_k = \{Y - Y' > 1/k\} \in \mathcal G. Then 0=∫Gk(Y−Y′) dP≥P(Gk)/k0 = \int_{G_k} (Y - Y') \, dP \ge P(G_k)/k, so P(Gk)=0P(G_k) = 0 and P(Y>Y′)=P(⋃kGk)=0P(Y > Y') = P\big(\bigcup_k G_k\big) = 0. By symmetry Y=Y′Y = Y' a.s.

∎

The point of the construction is that E[X∣G]\mathbb E[X \mid \mathcal G] is the density of the measure "XX restricted to the information G\mathcal G" — it is measurable with respect to G\mathcal G, not F\mathcal F, which is why the Radon–Nikodym theorem is applied on the smaller σ-algebra.

Theorem— Properties of conditional expectation

Let X,X′X, X' be integrable and G,H⊆F\mathcal G, \mathcal H \subseteq \mathcal F sub-σ-algebras. Almost surely:

  1. (linearity) E[aX+bX′∣G]=a E[X∣G]+b E[X′∣G]\mathbb E[aX + bX' \mid \mathcal G] = a \, \mathbb E[X \mid \mathcal G] + b \, \mathbb E[X' \mid \mathcal G];
  2. (positivity) if X≥0X \ge 0 then E[X∣G]≥0\mathbb E[X \mid \mathcal G] \ge 0; hence ∣E[X∣G]∣≤E[∣X∣∣G]|\mathbb E[X \mid \mathcal G]| \le \mathbb E[|X| \mid \mathcal G];
  3. E[E[X∣G]]=EX\mathbb E\big[\mathbb E[X \mid \mathcal G]\big] = \mathbb E X, and E[X∣G]=X\mathbb E[X \mid \mathcal G] = X if XX is G\mathcal G-measurable;
  4. (tower) if H⊆G\mathcal H \subseteq \mathcal G then E[E[X∣G]∣H]=E[X∣H]\mathbb E\big[\mathbb E[X \mid \mathcal G] \mid \mathcal H\big] = \mathbb E[X \mid \mathcal H];
  5. (taking out what is known) if ZZ is G\mathcal G-measurable and ZXZX is integrable, then E[ZX∣G]=Z E[X∣G]\mathbb E[ZX \mid \mathcal G] = Z \, \mathbb E[X \mid \mathcal G];
  6. (independence) if σ(X)\sigma(X) is independent of G\mathcal G, then E[X∣G]=EX\mathbb E[X \mid \mathcal G] = \mathbb E X;
  7. (conditional Jensen) if ϕ\phi is convex and ϕ(X)\phi(X) is integrable, then ϕ(E[X∣G])≤E[ϕ(X)∣G]\phi\big(\mathbb E[X \mid \mathcal G]\big) \le \mathbb E[\phi(X) \mid \mathcal G].

Proof

Each identity is proved by checking that the right side is measurable for the right σ-algebra and has the right integrals, and then invoking uniqueness.

(1) The right side is G\mathcal G-measurable and its integral over G∈GG \in \mathcal G is a∫GX+b∫GX′a \int_G X + b \int_G X'. (2) If Y=E[X∣G]Y = \mathbb E[X \mid \mathcal G] and G={Y<0}G = \{Y < 0\}, then 0≤∫GX=∫GY≤00 \le \int_G X = \int_G Y \le 0, so P(G)=0P(G) = 0. (3) Take G=ΩG = \Omega; and XX itself satisfies the definition when it is G\mathcal G-measurable.

(4) The left side is H\mathcal H-measurable, and for H∈H⊆GH \in \mathcal H \subseteq \mathcal G: ∫HE[E[X∣G]∣H]=∫HE[X∣G]=∫HX\int_H \mathbb E[\mathbb E[X \mid \mathcal G] \mid \mathcal H] = \int_H \mathbb E[X \mid \mathcal G] = \int_H X.

(5) For Z=1BZ = \mathbf 1_B with B∈GB \in \mathcal G and any G∈GG \in \mathcal G: ∫G1B E[X∣G]=∫G∩BE[X∣G]=∫G∩BX=∫G1BX\int_G \mathbf 1_B \, \mathbb E[X \mid \mathcal G] = \int_{G \cap B} \mathbb E[X \mid \mathcal G] = \int_{G \cap B} X = \int_G \mathbf 1_B X, since G∩B∈GG \cap B \in \mathcal G. By linearity the identity holds for simple G\mathcal G-measurable ZZ. For X≥0X \ge 0 and Z≥0Z \ge 0 take simple Zk↑ZZ_k \uparrow Z and use monotone convergence on both sides (the conditional version follows from the defining integrals); the general case follows by splitting ZZ and XX into positive and negative parts.

(6) The constant EX\mathbb E X is G\mathcal G-measurable, and for G∈GG \in \mathcal G, independence gives ∫GX=E[X1G]=EX⋅P(G)=∫GEX\int_G X = \mathbb E[X \mathbf 1_G] = \mathbb E X \cdot P(G) = \int_G \mathbb E X.

(7) A convex ϕ\phi is the supremum of countably many affine functions ℓk(x)=akx+bk\ell_k(x) = a_k x + b_k with ℓk≤ϕ\ell_k \le \phi. By (1) and (2), E[ϕ(X)∣G]≥akE[X∣G]+bk\mathbb E[\phi(X) \mid \mathcal G] \ge a_k \mathbb E[X \mid \mathcal G] + b_k almost surely for each kk; take the supremum over the countably many kk.

∎

Theorem— Conditional expectation is an orthogonal projection

If X∈L2(Ω,F,P)X \in L^2(\Omega, \mathcal F, P), then E[X∣G]\mathbb E[X \mid \mathcal G] is the orthogonal projection of XX onto the closed subspace L2(Ω,G,P)L^2(\Omega, \mathcal G, P). In particular it minimises E(X−Z)2\mathbb E(X - Z)^2 over all G\mathcal G-measurable square-integrable ZZ, and

Var⁡X=E[Var⁡(X∣G)]+Var⁡(E[X∣G]),Var⁡(X∣G):=E[(X−E[X∣G])2∣G].\operatorname{Var} X = \mathbb E\big[\operatorname{Var}(X \mid \mathcal G)\big] + \operatorname{Var}\big(\mathbb E[X \mid \mathcal G]\big), \qquad \operatorname{Var}(X \mid \mathcal G) := \mathbb E\big[(X - \mathbb E[X \mid \mathcal G])^2 \mid \mathcal G\big].

Proof

Let Y=E[X∣G]Y = \mathbb E[X \mid \mathcal G]. By conditional Jensen with ϕ(x)=x2\phi(x) = x^2, Y2≤E[X2∣G]Y^2 \le \mathbb E[X^2 \mid \mathcal G], so EY2≤EX2\mathbb E Y^2 \le \mathbb E X^2 and Y∈L2(G)Y \in L^2(\mathcal G). (That subspace is closed because L2(G)L^2(\mathcal G) is complete by Riesz–Fischer.) For bounded G\mathcal G-measurable ZZ, by (3) and (5),

E[(X−Y)Z]=E[E[(X−Y)Z∣G]]=E[Z (E[X∣G]−Y)]=0.\mathbb E[(X - Y) Z] = \mathbb E\big[\mathbb E[(X - Y) Z \mid \mathcal G]\big] = \mathbb E\big[Z \, (\mathbb E[X \mid \mathcal G] - Y)\big] = 0.

Bounded functions are dense in L2(G)L^2(\mathcal G), so X−Y⊥L2(G)X - Y \perp L^2(\mathcal G): YY is the orthogonal projection, and for any Z∈L2(G)Z \in L^2(\mathcal G) Pythagoras gives E(X−Z)2=E(X−Y)2+E(Y−Z)2\mathbb E(X - Z)^2 = \mathbb E(X - Y)^2 + \mathbb E(Y - Z)^2. Taking Z=EXZ = \mathbb E X (a constant) gives Var⁡X=E(X−Y)2+Var⁡Y\operatorname{Var} X = \mathbb E(X - Y)^2 + \operatorname{Var} Y, and E(X−Y)2=E[Var⁡(X∣G)]\mathbb E(X - Y)^2 = \mathbb E[\operatorname{Var}(X \mid \mathcal G)] by (3).

∎

This is in fact how Mathlib constructs conditional expectation: first as the orthogonal projection on L2L^2, then extended by continuity to L1L^1 — the Radon–Nikodym route and the Hilbert-space route give the same object.

ProofH

Martingales: stopping and convergence

Fix a filtration (Fn)(\mathcal F_n). For a martingale (Mn)(M_n) and a predictable process (Hn)(H_n), the martingale transform is

(H⋅M)n=∑k=1nHk(Mk−Mk−1),(H⋅M)0=0.(H \cdot M)_n = \sum_{k=1}^n H_k (M_k - M_{k-1}), \qquad (H \cdot M)_0 = 0.

Think of Mk−Mk−1M_k - M_{k-1} as the outcome of the kk-th fair game and HkH_k as the stake, chosen with the information available before the game.

Theorem— You cannot beat a fair game

If (Mn)(M_n) is a martingale and (Hn)(H_n) is predictable and bounded, then (H⋅M)(H \cdot M) is a martingale; in particular E(H⋅M)n=0\mathbb E (H \cdot M)_n = 0. If (Mn)(M_n) is a supermartingale and 0≤Hn≤c0 \le H_n \le c, then (H⋅M)(H \cdot M) is a supermartingale and E(H⋅M)n≤0\mathbb E (H \cdot M)_n \le 0.

Proof

(H⋅M)n(H \cdot M)_n is adapted and integrable (as HH is bounded). Taking out what is known, E[Hn+1(Mn+1−Mn)∣Fn]=Hn+1(E[Mn+1∣Fn]−Mn)\mathbb E[H_{n+1}(M_{n+1} - M_n) \mid \mathcal F_n] = H_{n+1} \big(\mathbb E[M_{n+1} \mid \mathcal F_n] - M_n\big), which is 00 for a martingale and ≤0\le 0 for a supermartingale with Hn+1≥0H_{n+1} \ge 0.

∎

A martingale has constant expectation, EMn=EM0\mathbb E M_n = \mathbb E M_0 (take expectations in E[Mn+1∣Fn]=Mn\mathbb E[M_{n+1} \mid \mathcal F_n] = M_n). Can a cleverly chosen random time do better?

Theorem— Optional stopping theorem (bounded stopping times)

If (Mn)(M_n) is a martingale and TT is a stopping time with T≤NT \le N for a constant NN, then EMT=EM0\mathbb E M_T = \mathbb E M_0. For a supermartingale, EMT≤EM0\mathbb E M_T \le \mathbb E M_0.

Proof

Write MT−M0=∑k=1N1{T≥k}(Mk−Mk−1)M_T - M_0 = \sum_{k=1}^N \mathbf 1_{\{T \ge k\}} (M_k - M_{k-1}). The stake Hk=1{T≥k}=1−1{T≤k−1}H_k = \mathbf 1_{\{T \ge k\}} = 1 - \mathbf 1_{\{T \le k - 1\}} is Fk−1\mathcal F_{k-1}-measurable because TT is a stopping time. So MT−M0=(H⋅M)NM_T - M_0 = (H \cdot M)_N has expectation 00 (respectively ≤0\le 0) by the previous theorem.

∎

Example— Gambler's ruin

A simple symmetric random walk SnS_n starts at a∈{1,…,N−1}a \in \{1, \dots, N - 1\} and stops at the first time TT it hits 00 or NN. Both SnS_n and Sn2−nS_n^2 - n are martingales. One checks ET<∞\mathbb E T < \infty (from any state, NN consecutive steps up end the game, so P(T>kN)≤(1−2−N)kP(T > kN) \le (1 - 2^{-N})^k). Apply optional stopping at the bounded times T∧nT \wedge n and let n→∞n \to \infty: ∣ST∧n∣≤N|S_{T \wedge n}| \le N allows dominated convergence, and T∧n↑TT \wedge n \uparrow T allows monotone convergence. From EST=a\mathbb E S_T = a we get P(ST=N)=a/NP(S_T = N) = a/N, and from E[ST2−T]=a2\mathbb E[S_T^2 - T] = a^2 we get ET=N2⋅aN−a2=a(N−a)\mathbb E T = N^2 \cdot \frac aN - a^2 = a(N - a). Without some such control, optional stopping fails: the walk started at 00 and stopped when it first hits 11 stops almost surely, at ST=1≠0S_T = 1 \ne 0 — but ET=∞\mathbb E T = \infty.

Now let a<ba \lt b and let UN[a,b]U_N[a, b] be the number of upcrossings of [a,b][a, b] completed by M0,…,MNM_0, \dots, M_N: the number of times the path passes from below aa to above bb.

Theorem— Doob's upcrossing inequality

If (Mn)(M_n) is a supermartingale, then (b−a) E UN[a,b]≤E[(MN−a)−](b - a) \, \mathbb E\, U_N[a, b] \le \mathbb E\big[(M_N - a)^-\big].

Proof

Use the strategy "buy when the price drops below aa, hold until it rises above bb, then sell": H1=1{M0<a}H_1 = \mathbf 1_{\{M_0 \lt a\}} and Hn=1{Hn−1=1, Mn−1≤b}+1{Hn−1=0, Mn−1<a}H_n = \mathbf 1_{\{H_{n-1} = 1,\, M_{n-1} \le b\}} + \mathbf 1_{\{H_{n-1} = 0,\, M_{n-1} \lt a\}}. It is predictable with values in {0,1}\{0, 1\}. Each completed upcrossing earns at least b−ab - a, and the last, possibly incomplete, holding period loses at most (MN−a)−(M_N - a)^-. So

(H⋅M)N≥(b−a) UN[a,b]−(MN−a)−.(H \cdot M)_N \ge (b - a) \, U_N[a, b] - (M_N - a)^-.

Since E(H⋅M)N≤0\mathbb E (H \cdot M)_N \le 0 for a supermartingale, the inequality follows.

∎

Theorem— Doob's martingale convergence theorem

If (Mn)(M_n) is a supermartingale (in particular, a martingale) with sup⁡nE∣Mn∣<∞\sup_n \mathbb E|M_n| \lt \infty, then MnM_n converges almost surely to a finite limit M∞M_\infty with E∣M∞∣<∞\mathbb E|M_\infty| \lt \infty.

Proof

For rationals a<ba \lt b, UN[a,b]↑U∞[a,b]U_N[a, b] \uparrow U_\infty[a, b], and by monotone convergence and the upcrossing inequality

(b−a) E U∞[a,b]≤sup⁡NE(MN−a)−≤sup⁡NE∣MN∣+∣a∣<∞,(b - a) \, \mathbb E \, U_\infty[a, b] \le \sup_N \mathbb E (M_N - a)^- \le \sup_N \mathbb E |M_N| + |a| \lt \infty,

so U∞[a,b]<∞U_\infty[a, b] \lt \infty almost surely. On the event {lim inf⁡Mn<a<b<lim sup⁡Mn}\{\liminf M_n \lt a \lt b \lt \limsup M_n\} the path crosses [a,b][a, b] upwards infinitely often, so this event is null. The union over the countably many rational pairs is null, hence lim inf⁡Mn=lim sup⁡Mn\liminf M_n = \limsup M_n almost surely: the limit M∞M_\infty exists in [−∞,∞][-\infty, \infty]. By Fatou's lemma E∣M∞∣≤lim inf⁡E∣Mn∣<∞\mathbb E|M_\infty| \le \liminf \mathbb E |M_n| \lt \infty, so M∞M_\infty is finite a.s.

∎

Three remarks. First, a non-negative supermartingale is automatically L1L^1-bounded (E∣Mn∣=EMn≤EM0\mathbb E|M_n| = \mathbb E M_n \le \mathbb E M_0), so it always converges. Second, convergence need not hold in L1L^1: if ξi\xi_i are independent with P(ξi=0)=P(ξi=2)=12P(\xi_i = 0) = P(\xi_i = 2) = \tfrac12, the product martingale Mn=ξ1⋯ξnM_n = \xi_1 \cdots \xi_n is 00 from the first zero onwards, so Mn→0M_n \to 0 a.s., while EMn=1\mathbb E M_n = 1. L1L^1 convergence holds exactly when the martingale is uniformly integrable, and then Mn=E[M∞∣Fn]M_n = \mathbb E[M_\infty \mid \mathcal F_n]. Third, Lévy's upward theorem: for integrable XX, E[X∣Fn]→E[X∣F∞]\mathbb E[X \mid \mathcal F_n] \to \mathbb E[X \mid \mathcal F_\infty] almost surely and in L1L^1, where F∞=σ(⋃nFn)\mathcal F_\infty = \sigma\big(\bigcup_n \mathcal F_n\big).

Example— Pólya's urn converges to a uniform limit

The urn fraction Mn∈[0,1]M_n \in [0, 1] is a bounded martingale, so it converges almost surely to some M∞M_\infty. Its law is uniform on [0,1][0, 1]: by induction, P(Rn=k)=1n+1P(R_n = k) = \frac{1}{n+1} for k=1,…,n+1k = 1, \dots, n + 1, because P(Rn+1=k)=1n+1(k−1n+2+n+2−kn+2)=1n+2P(R_{n+1} = k) = \frac{1}{n+1}\Big(\frac{k - 1}{n+2} + \frac{n + 2 - k}{n + 2}\Big) = \frac{1}{n+2}. So MnM_n is uniform on {1n+2,…,n+1n+2}\{\frac{1}{n+2}, \dots, \frac{n+1}{n+2}\}, and the almost-sure limit (hence the limit in distribution) is uniform. The limit is genuinely random: each urn settles down, but different urns settle at different values.

Example— Random signs

Let εk=±1\varepsilon_k = \pm 1 be independent fair signs. Then Sn=∑k≤nεk/kS_n = \sum_{k \le n} \varepsilon_k / k is a martingale with ESn2=∑k≤n1/k2≤π2/6\mathbb E S_n^2 = \sum_{k \le n} 1/k^2 \le \pi^2/6, hence L1L^1-bounded (Cauchy–Schwarz). So the random harmonic series ∑±1/k\sum \pm 1/k converges almost surely — although ∑1/k\sum 1/k diverges.

ProofH

Characteristic functions and the central limit theorem

Characteristic functions have the following properties (Durrett, §3.3): φX(0)=1\varphi_X(0) = 1, ∣φX∣≤1|\varphi_X| \le 1 and φX\varphi_X is uniformly continuous; φaX+b(t)=eitbφX(at)\varphi_{aX + b}(t) = e^{itb} \varphi_X(at); if XX and YY are independent, φX+Y=φXφY\varphi_{X + Y} = \varphi_X \varphi_Y (because eitXe^{itX} and eitYe^{itY} are independent); φX\varphi_X determines the law of XX (an inversion formula recovers μX\mu_X); and if E∣X∣k<∞\mathbb E|X|^k \lt \infty then φX\varphi_X is kk times continuously differentiable with φX(k)(0)=ik EXk\varphi_X^{(k)}(0) = i^k \, \mathbb E X^k. For a standard Gaussian ZZ, φZ(t)=e−t2/2\varphi_Z(t) = e^{-t^2/2}: differentiating under the integral and integrating by parts gives φZ′(t)=−tφZ(t)\varphi_Z'(t) = -t \varphi_Z(t) with φZ(0)=1\varphi_Z(0) = 1.

Theorem— Lévy's continuity theorem

Random variables XnX_n converge in distribution to XX if and only if φXn(t)→φX(t)\varphi_{X_n}(t) \to \varphi_X(t) for every t∈Rt \in \R.

"Only if" is immediate, since x↦eitxx \mapsto e^{itx} is bounded and continuous. For "if", one shows that the laws are tight (the behaviour of φXn\varphi_{X_n} near 00 controls P(∣Xn∣>K)P(|X_n| > K)), extracts weakly convergent subsequences by Prokhorov's theorem, and identifies every subsequential limit through its characteristic function (Durrett, §3.3; Billingsley, §26). We use the theorem without proof here; Mathlib proves it (formal section).

Theorem— Lemma (Taylor bounds)

For real xx: ∣eix−(1+ix−x22)∣≤min⁡(∣x∣36,x2)\big|e^{ix} - \big(1 + ix - \tfrac{x^2}{2}\big)\big| \le \min\big(\tfrac{|x|^3}{6}, x^2\big). And for complex numbers with ∣zk∣,∣wk∣≤1|z_k|, |w_k| \le 1: ∣∏k=1nzk−∏k=1nwk∣≤∑k=1n∣zk−wk∣\big|\prod_{k=1}^n z_k - \prod_{k=1}^n w_k\big| \le \sum_{k=1}^n |z_k - w_k|.

Proof

Integrating by parts, eix−∑k=0m(ix)kk!=im+1m!∫0x(x−s)meis dse^{ix} - \sum_{k=0}^m \frac{(ix)^k}{k!} = \frac{i^{m+1}}{m!} \int_0^x (x - s)^m e^{is} \, ds, whose modulus is at most ∣x∣m+1/(m+1)!|x|^{m+1}/(m+1)!. With m=2m = 2 this gives the bound ∣x∣3/6|x|^3/6. With m=1m = 1, ∣eix−1−ix∣≤x2/2|e^{ix} - 1 - ix| \le x^2/2, so ∣eix−1−ix+x2/2∣≤x2/2+x2/2=x2|e^{ix} - 1 - ix + x^2/2| \le x^2/2 + x^2/2 = x^2. For the products, induct on nn: ∏k≤nzk−∏k≤nwk=zn(∏k<nzk−∏k<nwk)+(zn−wn)∏k<nwk\prod_{k \le n} z_k - \prod_{k \le n} w_k = z_n \big(\prod_{k \lt n} z_k - \prod_{k \lt n} w_k\big) + (z_n - w_n) \prod_{k \lt n} w_k, and every factor outside the brackets has modulus at most 11.

∎

Theorem— Central limit theorem

Let X1,X2,…X_1, X_2, \dots be independent and identically distributed with EX1=0\mathbb E X_1 = 0 and EX12=1\mathbb E X_1^2 = 1. Then Sn/n→ZS_n/\sqrt n \to Z in distribution, where ZZ is standard normal: P(Sn/n≤x)→Φ(x)=12π∫−∞xe−s2/2 dsP(S_n/\sqrt n \le x) \to \Phi(x) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^x e^{-s^2/2} \, ds for every xx.

Proof

Let φ=φX1\varphi = \varphi_{X_1}. By the lemma with x=tX1x = tX_1, taking expectations,

∣φ(t)−(1−t22)∣≤Emin⁡(∣t∣3∣X1∣36,t2X12)=t2 Emin⁡(∣t∣ ∣X1∣36,X12).\Big|\varphi(t) - \Big(1 - \frac{t^2}{2}\Big)\Big| \le \mathbb E \min\Big(\frac{|t|^3 |X_1|^3}{6}, t^2 X_1^2\Big) = t^2 \, \mathbb E \min\Big(\frac{|t| \, |X_1|^3}{6}, X_1^2\Big).

As t→0t \to 0 the random variable inside the last expectation tends to 00 and is dominated by X12X_1^2, which is integrable; so by dominated convergence φ(t)=1−t22+o(t2)\varphi(t) = 1 - \frac{t^2}{2} + o(t^2). (This uses only a finite second moment.)

By independence φSn/n(t)=φ(t/n)n\varphi_{S_n/\sqrt n}(t) = \varphi(t/\sqrt n)^n. Fix tt and take n≥t2/2n \ge t^2/2, so that ∣1−t2/(2n)∣≤1|1 - t^2/(2n)| \le 1. The product lemma gives

∣φ(t/n)n−(1−t22n)n∣≤n ∣φ(t/n)−1+t22n∣=n⋅o(t2n)→n→∞0,\Big|\varphi\big(t/\sqrt n\big)^n - \Big(1 - \frac{t^2}{2n}\Big)^n\Big| \le n \, \Big|\varphi\big(t/\sqrt n\big) - 1 + \frac{t^2}{2n}\Big| = n \cdot o\Big(\frac{t^2}{n}\Big) \xrightarrow[n \to \infty]{} 0,

and (1−t2/(2n))n→e−t2/2=φZ(t)(1 - t^2/(2n))^n \to e^{-t^2/2} = \varphi_Z(t). By Lévy's continuity theorem Sn/n→ZS_n/\sqrt n \to Z in distribution. Since Φ\Phi is continuous, the distribution functions converge at every xx.

∎

For general mean μ\mu and variance σ2∈(0,∞)\sigma^2 \in (0, \infty), apply the theorem to (Xi−μ)/σ(X_i - \mu)/\sigma. The Lindeberg–Feller theorem drops identical distribution: for independent triangular arrays it suffices that no single summand carries a non-negligible share of the variance (Lindeberg's condition). The Berry–Esseen theorem quantifies the speed: sup⁡x∣P(Sn/n≤x)−Φ(x)∣≤C E∣X1∣3/n\sup_x |P(S_n/\sqrt n \le x) - \Phi(x)| \le C \, \mathbb E|X_1|^3/\sqrt n with an absolute constant C<0.48C \lt 0.48 (Shevtsova, 2011); for fair ±1\pm1 steps the rate 1/n1/\sqrt n is attained (see the computation below).

Formal mathematicsF

Probability in Lean and Mathlib

Mathlib's probability library is built exactly on Kolmogorov's dictionary: a probability space is a MeasureSpace with IsProbabilityMeasure, a random variable is a measurable function, μ[X] is the integral, and independence (iIndepFun, X ⟂ᵢ[μ] Y) is phrased through σ-algebras. Our first theorem mirrors the human proof of the first Borel–Cantelli lemma line by line — limsup inside a tail union, subadditivity, tails of a convergent series tend to 00:

borel_cantelli_firstLean 4Proved here from basic factsFormally verified
/-- **First Borel–Cantelli lemma.** If `∑ P(Aₙ) < ∞`, then almost surely only finitely many of
the events `Aₙ` occur: `P(limsup Aₙ) = 0`. No independence is needed. Proof (as in the lesson):
for every `n`, the event "infinitely many `Aₖ` occur" lies inside `⋃ₖ A_{k+n}`, whose probability
is at most the tail `∑ₖ P(A_{k+n})` of a convergent series, and the tails tend to `0`
(`ENNReal.tendsto_sum_nat_add`). Mathlib's version is `measure_limsup_atTop_eq_zero`. -/
theorem borel_cantelli_first {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) {A : ℕ → Set Ω}
    (hA : ∑' n, μ (A n) ≠ ∞) : μ (limsup A atTop) = 0 := by
  -- `limsup A = ⋂ n, ⋃ k, A (k + n)`, so it lies in each tail union.
  have hsub : ∀ n, limsup A atTop ⊆ ⋃ k, A (k + n) := fun n => by
    rw [limsup_eq_iInf_iSup_of_nat']
    exact iInf_le (fun n => ⋃ k, A (k + n)) n
  -- Each tail union has probability at most the tail of the series.
  have hle : ∀ n, μ (limsup A atTop) ≤ ∑' k, μ (A (k + n)) := fun n =>
    (measure_mono (hsub n)).trans (measure_iUnion_le _)
  -- The tails of a convergent series tend to zero.
  exact le_antisymm (ge_of_tendsto' (ENNReal.tendsto_sum_nat_add _ hA) hle) (by simp)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

The second lemma and Kolmogorov's zero–one law are Mathlib theorems. Note how the hypotheses mirror the statements above: iIndepSet for independence of the events, iIndep for independence of σ-algebras, and MeasurableSet[limsup 𝓕 atTop] T for membership in the tail σ-algebra.

borel_cantelli_secondLean 4Applies a library theoremFormally verified
/-- **Second Borel–Cantelli lemma.** If the events `Aₙ` are independent and `∑ P(Aₙ) = ∞`,
then almost surely infinitely many of them occur: `P(limsup Aₙ) = 1`. Independence cannot be
dropped (take `Aₙ = A` for one event with `0 < P(A) < 1`). This is Mathlib's
`ProbabilityTheory.measure_limsup_eq_one`. -/
theorem borel_cantelli_second {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω}
    {A : ℕ → Set Ω} (hmeas : ∀ n, MeasurableSet (A n)) (hindep : iIndepSet A μ)
    (hdiv : ∑' n, μ (A n) = ∞) : μ (limsup A atTop) = 1 :=
  measure_limsup_eq_one hmeas hindep hdiv
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
zero_one_lawLean 4Applies a library theoremFormally verified
/-- **Kolmogorov's zero–one law.** If `(𝓕ₙ)` is an independent sequence of sub-σ-algebras, every
event in the tail σ-algebra `limsup 𝓕ₙ = ⋂ₙ σ(𝓕ₙ, 𝓕ₙ₊₁, …)` has probability `0` or `1`. The event
"the sample means converge" is such a tail event. This is Mathlib's
`ProbabilityTheory.measure_zero_or_one_of_measurableSet_limsup_atTop`. -/
theorem zero_one_law {Ω : Type*} [m0 : MeasurableSpace Ω] {μ : Measure Ω}
    {𝓕 : ℕ → MeasurableSpace Ω} (hle : ∀ n, 𝓕 n ≤ m0) (hindep : iIndep 𝓕 μ) {T : Set Ω}
    (htail : MeasurableSet[limsup 𝓕 atTop] T) : μ T = 0 ∨ μ T = 1 :=
  measure_zero_or_one_of_measurableSet_limsup_atTop hle hindep htail
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

The weak law with Chebyshev's explicit rate is proved here from two library facts — the variance of a sum of pairwise independent variables is the sum of the variances, and Chebyshev's inequality — exactly as in the human proof. Etemadi's strong law is a large Mathlib development (truncation, geometric subsequences, interpolation); we cite it for real-valued variables:

weak_lawLean 4Proved here from basic factsFormally verified
/-- **Weak law of large numbers, with Chebyshev's rate.** Let `X₀, X₁, …` be pairwise independent
square-integrable random variables with common variance `σ²`, and let `Ȳₙ = (X₀ + ⋯ + X_{n-1})/n`.
Then `P(|Ȳₙ − E Ȳₙ| ≥ ε) ≤ σ² / (n ε²)`. Proof: by pairwise independence the variance of the sum
is the sum of the variances (`IndepFun.variance_sum`), so `Var Ȳₙ = n σ² / n² = σ²/n`; then apply
Chebyshev's inequality (`meas_ge_le_variance_div_sq`). The bound tends to `0` as `n → ∞`, which is
convergence in probability. -/
theorem weak_law {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]
    {X : ℕ → Ω → ℝ} (hL2 : ∀ i, MemLp (X i) 2 μ) (hindep : Pairwise fun i j => X i ⟂ᵢ[μ] X j)
    {σ2 : ℝ} (hvar : ∀ i, Var[X i; μ] = σ2) {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) :
    μ {ω | ε ≤ |(n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω -
        μ[fun ω => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω]|}
      ≤ ENNReal.ofReal (σ2 / (n * ε ^ 2)) := by
  have hsum : MemLp (∑ i ∈ Finset.range n, X i) 2 μ := memLp_finsetSum' _ fun i _ => hL2 i
  have hY : MemLp (fun ω => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω) 2 μ := by
    have := hsum.const_mul (n : ℝ)⁻¹
    convert this using 2 with ω
    simp [Finset.sum_apply]
  have hvarY : Var[fun ω => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω; μ] = σ2 / n := by
    have heq : (fun ω => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω)
        = fun ω => (n : ℝ)⁻¹ * (∑ i ∈ Finset.range n, X i) ω := by
      ext ω
      simp [Finset.sum_apply]
    rw [heq, variance_const_mul,
      IndepFun.variance_sum (fun i _ => hL2 i) (fun i _ j _ hij => hindep hij)]
    simp only [hvar, Finset.sum_const, Finset.card_range, nsmul_eq_mul]
    have hn' : (n : ℝ) ≠ 0 := by positivity
    field_simp
  calc _ ≤ ENNReal.ofReal (Var[fun ω => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω; μ] / ε ^ 2) :=
        meas_ge_le_variance_div_sq hY hε
    _ = ENNReal.ofReal (σ2 / (n * ε ^ 2)) := by
        rw [hvarY, div_div]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
strong_lawLean 4Applies a library theoremFormally verified
/-- **Strong law of large numbers** (Etemadi's version: pairwise independence suffices). If the
`Xᵢ` are pairwise independent, identically distributed and integrable, then almost surely the
sample means `(X₀ + ⋯ + X_{n-1})/n` converge to `E[X₀]`. This is Mathlib's
`ProbabilityTheory.strong_law_ae`, specialised to real-valued variables. -/
theorem strong_law {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]
    (X : ℕ → Ω → ℝ) (hint : Integrable (X 0) μ) (hindep : Pairwise fun i j => X i ⟂ᵢ[μ] X j)
    (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) :
    ∀ᵐ ω ∂μ, Tendsto (fun n : ℕ => (n : ℝ)⁻¹ * ∑ i ∈ Finset.range n, X i ω) atTop
      (𝓝 μ[X 0]) := by
  simpa [smul_eq_mul] using strong_law_ae X hint hindep hident
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

Mathlib writes μ[X | 𝒢] for the conditional expectation. It is a function Ω → ℝ, not a number, and identities between conditional expectations hold =ᵐ[μ], almost everywhere — the formal statements cannot fall into the misconception that a conditional expectation is a number. The defining property, the tower property, taking out what is known, and independence:

cond_exp_set_integralLean 4Applies a library theoremFormally verified
/-- **The defining property of conditional expectation.** For a sub-σ-algebra `𝒢 ≤ 𝓕` and an
integrable `X`, the random variable `μ[X | 𝒢]` (it is a function on `Ω`, not a number) is
`𝒢`-measurable and has the same integral as `X` over every `𝒢`-measurable set. Mathlib
constructs it by extending the orthogonal projection of `L²` onto `L²(𝒢)` to `L¹`, and proves
this property as `setIntegral_condExp`. -/
theorem cond_exp_set_integral {Ω : Type*} {𝒢 m0 : MeasurableSpace Ω} {μ : Measure Ω}
    [IsFiniteMeasure μ] (h𝒢 : 𝒢 ≤ m0) {X : Ω → ℝ} (hX : Integrable X μ) {G : Set Ω}
    (hG : MeasurableSet[𝒢] G) : ∫ ω in G, (μ[X | 𝒢]) ω ∂μ = ∫ ω in G, X ω ∂μ :=
  setIntegral_condExp h𝒢 hX hG
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
cond_exp_towerLean 4Applies a library theoremFormally verified
/-- **Tower property.** Conditioning first on the finer σ-algebra `𝒢₂` and then on the coarser
`𝒢₁ ≤ 𝒢₂` is the same as conditioning on `𝒢₁` directly (almost surely). This is Mathlib's
`condExp_condExp_of_le`. -/
theorem cond_exp_tower {Ω : Type*} {𝒢₁ 𝒢₂ m0 : MeasurableSpace Ω} {μ : Measure Ω}
    [IsFiniteMeasure μ] (h₁₂ : 𝒢₁ ≤ 𝒢₂) (h₂ : 𝒢₂ ≤ m0) (X : Ω → ℝ) :
    μ[μ[X | 𝒢₂] | 𝒢₁] =ᵐ[μ] μ[X | 𝒢₁] :=
  condExp_condExp_of_le h₁₂ h₂
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
cond_exp_pull_outLean 4Applies a library theoremFormally verified
/-- **Taking out what is known.** If `Z` is `𝒢`-measurable and `Z · X` and `X` are integrable,
then `E[Z X | 𝒢] = Z · E[X | 𝒢]` almost surely. This is Mathlib's
`condExp_mul_of_stronglyMeasurable_left`. -/
theorem cond_exp_pull_out {Ω : Type*} {𝒢 m0 : MeasurableSpace Ω} {μ : Measure Ω}
    {Z X : Ω → ℝ} (hZ : StronglyMeasurable[𝒢] Z) (hZX : Integrable (Z * X) μ)
    (hX : Integrable X μ) : μ[Z * X | 𝒢] =ᵐ[μ] Z * μ[X | 𝒢] :=
  condExp_mul_of_stronglyMeasurable_left hZ hZX hX
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
cond_exp_indepLean 4Applies a library theoremFormally verified
/-- **Independent information is useless.** If `X` is measurable with respect to a σ-algebra
`𝓗` that is independent of `𝒢`, then `E[X | 𝒢] = E[X]`, a constant, almost surely. This is
Mathlib's `ProbabilityTheory.condExp_indep_eq`. -/
theorem cond_exp_indep {Ω : Type*} {𝓗 𝒢 m0 : MeasurableSpace Ω} {μ : Measure Ω}
    [IsProbabilityMeasure μ] (h𝓗 : 𝓗 ≤ m0) (h𝒢 : 𝒢 ≤ m0) {X : Ω → ℝ}
    (hX : StronglyMeasurable[𝓗] X) (hindep : Indep 𝓗 𝒢 μ) :
    μ[X | 𝒢] =ᵐ[μ] fun _ => μ[X] :=
  condExp_indep_eq h𝓗 h𝒢 hX hindep
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

A martingale (Martingale M 𝓕 μ: adapted, and μ[M j | 𝓕 i] =ᵐ[μ] M i for i ≤ j) has constant expectation; the proof integrates the defining identity. Doob's convergence theorem, proved in Mathlib through the upcrossing inequality as above, is then cited:

martingale_integral_eqLean 4Proved here from basic factsFormally verified
/-- **A martingale has constant expectation.** If `(Mₙ)` is a martingale for the filtration
`(𝓕ₙ)` and `i ≤ j`, then `E[Mⱼ] = E[Mᵢ]`. Proof: integrating the conditional expectation does not
change the integral (`integral_condExp`, the defining property with `G = Ω`), and the martingale
property says `E[Mⱼ | 𝓕ᵢ] = Mᵢ` almost surely. -/
theorem martingale_integral_eq {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω}
    [IsFiniteMeasure μ] {𝓕 : Filtration ℕ m0} {M : ℕ → Ω → ℝ} (hM : Martingale M 𝓕 μ)
    {i j : ℕ} (hij : i ≤ j) : ∫ ω, M j ω ∂μ = ∫ ω, M i ω ∂μ :=
  calc ∫ ω, M j ω ∂μ = ∫ ω, (μ[M j | 𝓕 i]) ω ∂μ := (integral_condExp (𝓕.le i)).symm
    _ = ∫ ω, M i ω ∂μ := integral_congr_ae (hM.condExp_ae_eq hij)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
martingale_convergenceLean 4Applies a library theoremFormally verified
/-- **Doob's martingale convergence theorem.** An `L¹`-bounded martingale (`E|Mₙ| ≤ R` for all
`n`) converges almost surely; its limit is the `limitProcess`, measurable with respect to
`⋁ₙ 𝓕ₙ`. The proof goes through Doob's upcrossing inequality. This is Mathlib's
`Submartingale.ae_tendsto_limitProcess` (every martingale is a submartingale). -/
theorem martingale_convergence {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω}
    [IsFiniteMeasure μ] {𝓕 : Filtration ℕ m0} {M : ℕ → Ω → ℝ} {R : ℝ≥0}
    (hM : Martingale M 𝓕 μ) (hbdd : ∀ n, eLpNorm (M n) 1 μ ≤ R) :
    ∀ᵐ ω ∂μ, Tendsto (fun n => M n ω) atTop (𝓝 (𝓕.limitProcess M μ ω)) :=
  hM.submartingale.ae_tendsto_limitProcess hbdd
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

Finally Lévy's continuity theorem and the central limit theorem, both recent additions to Mathlib. The CLT's proof in Mathlib follows the lesson's: charFun_inv_sqrt_mul_sum computes the characteristic function of the normalised sum as φ(t/n)n\varphi(t/\sqrt n)^n, a second-order Taylor expansion of φ\varphi gives the limit e−t2/2e^{-t^2/2}, and Lévy's theorem concludes.

levy_continuityLean 4Applies a library theoremFormally verified
/-- **Lévy's continuity theorem.** Probability measures on `ℝᵈ` converge weakly if and only if
their characteristic functions `φ(t) = ∫ e^{i⟨t, x⟩} dμ(x)` converge at every `t`. This is
Mathlib's `ProbabilityMeasure.tendsto_iff_tendsto_charFun`. -/
theorem levy_continuity {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
    [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {μ : ℕ → ProbabilityMeasure E}
    {μ₀ : ProbabilityMeasure E} :
    Tendsto μ atTop (𝓝 μ₀) ↔
      ∀ t : E, Tendsto (fun n => charFun (μ n : Measure E) t) atTop
        (𝓝 (charFun (μ₀ : Measure E) t)) :=
  ProbabilityMeasure.tendsto_iff_tendsto_charFun
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor
central_limitLean 4Applies a library theoremFormally verified
/-- **Central limit theorem.** If `X₀, X₁, …` are independent and identically distributed with
mean `0` and variance `1`, then `(X₀ + ⋯ + X_{n-1})/√n` converges in distribution to a standard
Gaussian `Y`. Mathlib proves it as in the lesson: the characteristic function of the normalised
sum is `φ(t/√n)ⁿ`, which tends to `e^{-t²/2}` by the second-order Taylor expansion of `φ`, and
Lévy's continuity theorem concludes. This is
`ProbabilityTheory.tendstoInDistribution_inv_sqrt_mul_sum`. -/
theorem central_limit {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω'] {P : Measure Ω}
    {P' : Measure Ω'} [IsProbabilityMeasure P] [IsProbabilityMeasure P'] {X : ℕ → Ω → ℝ}
    {Y : Ω' → ℝ} (hY : HasLaw Y (gaussianReal 0 1) P') (h0 : P[X 0] = 0)
    (h1 : P[X 0 ^ 2] = 1) (hindep : iIndepFun X P)
    (hident : ∀ i, IdentDistrib (X i) (X 0) P P) :
    TendstoInDistribution (fun (n : ℕ) ω => (√n)⁻¹ * ∑ k ∈ Finset.range n, X k ω) atTop Y
      (fun _ => P) P' :=
  tendstoInDistribution_inv_sqrt_mul_sum hY h0 h1 hindep hident
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MeasureTheoreticProbability.leanTry it in the Lean web editor

Not formalised here: the fourth-moment proof of the strong law (we cite Mathlib's stronger theorem instead), the Radon–Nikodym construction of conditional expectation (Mathlib uses the L2L^2-projection route), optional stopping and the upcrossing inequality (in Mathlib as Submartingale.expected_stoppedValue_mono and Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part), and the Taylor-bound lemma.

ComputationC

Experiments: Borel–Cantelli, Pólya's urn and the CLT

The first experiment compares independent events with P(An)=1/nP(A_n) = 1/n and P(Bn)=1/n2P(B_n) = 1/n^2. The expected number of occurrences in each dyadic block [2k,2k+1)[2^k, 2^{k+1}) is computed exactly: about ln⁡2\ln 2 for the AnA_n, forever, and a geometrically shrinking amount for the BnB_n. Seeded simulations up to n=216n = 2^{16} show the AnA_n still occurring at large nn while the BnB_n stop after a few indices — the two Borel–Cantelli lemmas side by side.

Borel-Cantelli: events that keep happening, and events that stopPythonExact computationStatistical evidenceComputationally tested
"""Borel-Cantelli in action: convergence in probability without a.s. convergence.

Take independent events A_n with P(A_n) = 1/n, and independent events B_n with
P(B_n) = 1/n^2. Both indicator sequences tend to 0 in probability. The second
Borel-Cantelli lemma says infinitely many A_n occur almost surely (the sum of
1/n diverges), while the first says only finitely many B_n occur (the sum of
1/n^2 converges). We compute the exact expected number of occurrences in each
dyadic block [2^k, 2^(k+1)), and simulate a few seeded runs to watch the A_n
keep happening in late blocks while the B_n stop early.
"""

import random
from fractions import Fraction

def block_expectation(k, power):
    """Exact sum of 1/n^power over the dyadic block 2^k <= n < 2^(k+1)."""
    if k < 0 or power < 1:
        raise ValueError("need k >= 0 and power >= 1")
    return sum(Fraction(1, n ** power) for n in range(2 ** k, 2 ** (k + 1)))

def simulate(power, n_max, rng):
    """Indices n <= n_max at which the event with P = 1/n^power occurs."""
    return [n for n in range(1, n_max + 1) if rng.random() < 1.0 / n ** power]

def block_counts(hits, k_max):
    """How many hits fall in each block [2^k, 2^(k+1)) for k = 0..k_max."""
    counts = [0] * (k_max + 1)
    for n in hits:
        k = n.bit_length() - 1
        if k <= k_max:
            counts[k] += 1
    return counts

def main():
    k_max = 15
    print("Exact expected number of occurrences in the block [2^k, 2^(k+1)):")
    print("   k   P(A_n) = 1/n    P(B_n) = 1/n^2")
    for k in [0, 1, 2, 4, 6, 8]:
        a = float(block_expectation(k, 1))
        b = float(block_expectation(k, 2))
        print(f"  {k:>2}   {a:.6f}        {b:.3e}")
    print("The 1/n blocks decrease to ln 2 = 0.693147, so the series diverges;")
    print("the 1/n^2 blocks shrink like 2^-(k+1), so that series converges.")
    print()
    rng = random.Random(1933)
    n_max = 2 ** (k_max + 1) - 1
    print(f"Five seeded runs up to n = {n_max}:")
    for run in range(5):
        a_hits = simulate(1, n_max, rng)
        b_hits = simulate(2, n_max, rng)
        late = sum(block_counts(a_hits, k_max)[10:])
        print(f"  run {run + 1}: {late} of the A_n with n >= 1024 occur,"
              f" last at n = {a_hits[-1]}; last B_n at n = {b_hits[-1]}")
    print("About ln 2 of the A_n are expected in every dyadic block, forever;")
    print("the B_n stop after a few indices. Yet P(A_n) -> 0: the indicators")
    print("of A_n tend to 0 in probability but not almost surely.")
    print()
    print("Epistemic status: the block expectations are exact rational")
    print("arithmetic. The runs are seeded pseudo-random simulations of a")
    print("finite horizon: they illustrate, but cannot prove, the almost-sure")
    print("statements, which are the two Borel-Cantelli lemmas.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The second computes the law of Pólya's urn exactly with fractions (uniform, as proved above), checks the martingale identity for every state up to n=30n = 30, and simulates urns: each settles, at a different random level.

Polya's urn: a martingale with a random limitPythonExact computationStatistical evidenceComputationally tested
"""Polya's urn: a martingale that converges to a random limit.

An urn starts with one red and one blue ball. At each step draw a ball,
return it, and add another of the same colour. The fraction of red balls
M_n = R_n / (n + 2) is a martingale. We verify exactly (with fractions) that
the martingale property holds and that after n draws the number of red balls
is uniformly distributed on {1, ..., n + 1}; so the almost-sure limit of M_n,
which exists by Doob's convergence theorem, is uniform on [0, 1]. A seeded
simulation shows individual urns settling down at different values.
"""

import random
from fractions import Fraction

def red_distribution(n):
    """Exact law of the number of red balls after n draws, as {red: prob}."""
    if n < 0:
        raise ValueError("n must be non-negative")
    dist = {1: Fraction(1)}
    for step in range(n):
        total = step + 2
        new = {}
        for red, p in dist.items():
            up = p * Fraction(red, total)
            new[red + 1] = new.get(red + 1, 0) + up
            new[red] = new.get(red, 0) + p - up
        dist = new
    return dist

def martingale_defect(n, red):
    """E[M_(n+1) | R_n = red] - M_n, exactly (it should be 0)."""
    total = n + 2
    p_up = Fraction(red, total)
    expected = (p_up * Fraction(red + 1, total + 1)
                + (1 - p_up) * Fraction(red, total + 1))
    return expected - Fraction(red, total)

def run_urn(steps, rng):
    """Fractions of red balls after each of the given number of draws."""
    red, total, path = 1, 2, []
    for _ in range(steps):
        if rng.random() < red / total:
            red += 1
        total += 1
        path.append(red / total)
    return path

def main():
    print("Exact law of R_n (number of red balls) after n draws:")
    for n in [1, 2, 3, 10]:
        dist = red_distribution(n)
        values = ", ".join(str(v) for v in sorted(set(dist.values())))
        print(f"  n = {n:>2}: R_n takes each value 1..{n + 1} with prob. {values}")
    worst = max(abs(martingale_defect(n, r))
                for n in range(31) for r in range(1, n + 2))
    print("max |E[M_(n+1) | R_n] - M_n| over n <= 30, all r:", worst)
    print()
    rng = random.Random(1923)
    print("Six urns, fraction of red after 10, 100, 1000, 4000 draws:")
    for i in range(6):
        path = run_urn(4000, rng)
        cells = "  ".join(f"{path[k - 1]:.3f}" for k in [10, 100, 1000, 4000])
        print(f"  urn {i + 1}: {cells}")
    limits = [run_urn(300, rng)[-1] for _ in range(1000)]
    deciles = [0] * 10
    for x in limits:
        deciles[min(int(x * 10), 9)] += 1
    print("1000 urns after 300 draws, counts per tenth of [0, 1]:")
    print("  ", deciles, "(uniform: about 100 each)")
    print()
    print("Epistemic status: the uniform law and the martingale identity are")
    print("exact computations for n <= 30 (the lesson proves them for all n).")
    print("The urn runs are seeded simulations: statistical illustration of")
    print("Doob's theorem (almost-sure convergence), not a proof of it.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The third measures how fast cos⁡(t/n)n\cos(t/\sqrt n)^n, the characteristic function of a normalised sum of fair ±1\pm1 steps, approaches e−t2/2e^{-t^2/2}: the error is about t4e−t2/2/(12n)t^4 e^{-t^2/2}/(12n), as the Taylor expansion log⁡cos⁡s=−s2/2−s4/12+⋯\log \cos s = -s^2/2 - s^4/12 + \cdots predicts. The distribution functions converge more slowly, at the Berry–Esseen rate 1/n1/\sqrt n, because SnS_n is lattice-valued.

The CLT through characteristic functionsPythonNumerical approximationComputationally tested
"""The central limit theorem seen through characteristic functions.

For a fair +-1 coin X, the characteristic function is E[exp(itX)] = cos t, so
the normalised sum S_n / sqrt(n) of n independent coins has characteristic
function cos(t / sqrt(n))^n. We measure how fast it approaches exp(-t^2 / 2),
the characteristic function of the standard normal law, on [-3, 3]; the
error behaves like t^4 exp(-t^2/2) / (12 n). Then we compare the exact
binomial distribution function with the normal one (the Berry-Esseen rate is
1/sqrt(n), slower because the distribution of S_n has jumps).
"""

import math

def charfun_sum(t, n):
    """Characteristic function of S_n / sqrt(n) for fair +-1 steps."""
    if n < 1:
        raise ValueError("n must be positive")
    return math.cos(t / math.sqrt(n)) ** n

def max_charfun_error(n, t_max=3.0, points=601):
    """max over a grid of |phi_n(t) - exp(-t^2/2)| for |t| <= t_max."""
    ts = [-t_max + 2 * t_max * k / (points - 1) for k in range(points)]
    return max(abs(charfun_sum(t, n) - math.exp(-t * t / 2)) for t in ts)

def normal_cdf(x):
    """Standard normal distribution function."""
    return 0.5 * (1 + math.erf(x / math.sqrt(2)))

def binomial_cdf_error(n):
    """sup over the jump points of |P(S_n/sqrt(n) <= x) - Phi(x)|."""
    worst, cum = 0.0, 0.0
    for k in range(n + 1):
        x = (2 * k - n) / math.sqrt(n)
        left = cum
        cum += math.exp(math.lgamma(n + 1) - math.lgamma(k + 1)
                        - math.lgamma(n - k + 1) - n * math.log(2))
        phi = normal_cdf(x)
        worst = max(worst, abs(left - phi), abs(cum - phi))
    return worst

def main():
    print("Characteristic function of S_n/sqrt(n) versus exp(-t^2/2):")
    print("      n   max error on [-3,3]   n * error")
    for n in [1, 2, 5, 10, 100, 1000, 10000]:
        err = max_charfun_error(n)
        print(f"  {n:>5}   {err:.3e}             {n * err:.4f}")
    print("n * error settles at max t^4 exp(-t^2/2)/12 = 16/(12 e^2) = 0.1804")
    print("(at t = 2): the characteristic functions converge at rate 1/n.")
    print()
    print("Exact binomial CDF versus the normal CDF (sup over x):")
    print("      n   sup error    sqrt(n) * error")
    for n in [10, 100, 1000, 4000]:
        err = binomial_cdf_error(n)
        print(f"  {n:>5}   {err:.5f}      {math.sqrt(n) * err:.4f}")
    print("sqrt(n) * error tends to 1/sqrt(2 pi) = 0.3989: the CDFs converge")
    print("only like 1/sqrt(n), because S_n has jumps of size about")
    print("sqrt(2/(pi n)) at 0 (the Berry-Esseen rate is sharp here).")
    print()
    print("Epistemic status: floating-point evaluation on finite grids and for")
    print("finitely many n. It illustrates the rates; the convergence itself is")
    print("the central limit theorem, proved in the lesson from Levy's")
    print("continuity theorem.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

All three are evidence, not proof: exact arithmetic on finitely many cases, seeded simulations of finite horizons, and floating-point evaluation on finite grids.

Explore

Watching the limit theorems

Move the slider: the curve is the characteristic function cos⁡(t/n)n\cos(t/\sqrt n)^n of Sn/nS_n/\sqrt n for fair ±1\pm1 steps, and the dashed comparison is e−t2/2e^{-t^2/2}. Pointwise convergence of these curves is, by Lévy's theorem, the central limit theorem. Notice that for small nn the curve is periodic — the law of Sn/nS_n/\sqrt n lives on a lattice — and that the period 2πn2\pi\sqrt n runs off to infinity.

Characteristic functions converge: the CLT through Fourier eyes

Move the sliders and trace along the curves to read off values.

  • φₙ(t) = cos(t/√n)ⁿ
  • e^(−t²/2)
  • φₙ(t) = cos(t/√n)ⁿ: y = 0.578
  • e^(−t²/2): y = 0.6065

The strong law along one path, and the central limit theorem as a histogram: the running proportion of heads settles at 12\tfrac12 (each run is one ω\omega), and the Galton board's binomial counts take the normal shape.

The strong law and the central limit theorem

Flip a fair coin again and again: the proportion of heads settles towards 1/2. This is the law of large numbers.

00.250.50.75105001,0001,5002,000number of flipsproportion of heads
  • this run
  • exact probability 1/2
  • 1/2 ± 1/√n (about 95% of runs)

968 heads in 2,000 flips: proportion

Simulated0.484

Exact1/2 = 0.5

Simulation of 2,000 flips: 968 heads, proportion 0.484. The exact probability is 1/2.

Evidence, not proofThis is a simulation of 2,000 flips (run 1) using a seeded random number generator. It is evidence, not proof: the exact values come from mathematics, and a new run gives slightly different numbers.

The proportion settles down, but the difference between the number of heads and n/2 typically grows like √n: the law of large numbers is about proportions, not counts.

Exercises

Exercises

1. Measure-theoretic probability

Warm-upHuman

Let X,X1,X2,…X, X_1, X_2, \dots be random variables on one probability space. Which implications hold in general? Select all that apply.

Choose all that apply

2. Measure-theoretic probability

Warm-upHuman

Let X1,X2X_1, X_2 be independent fair dice (values 1,…,61, \dots, 6). The conditional expectation E[X1X2∣X1]\mathbb E[X_1 X_2 \mid X_1] is a random variable. What value does it take on the event {X1=4}\{X_1 = 4\}?

3. Measure-theoretic probability

CoreHuman

Let A1,A2,…A_1, A_2, \dots be events with P(An)=1/n2P(A_n) = 1/n^2. Nothing is assumed about independence. Which statement is true?

Choose one

4. Measure-theoretic probability

CoreHuman

The proof of the second Borel–Cantelli lemma runs: (1) the complement of lim sup⁡Ak\limsup A_k is ⋃n⋂k≥nAkc\bigcup_n \bigcap_{k \ge n} A_k^c; (2) P(⋂k=nNAkc)=∏k=nN(1−P(Ak))P(\bigcap_{k=n}^N A_k^c) = \prod_{k=n}^N (1 - P(A_k)); (3) 1−x≤e−x1 - x \le e^{-x}; (4) continuity from above. Which step uses the independence of the events?

Choose one

5. Measure-theoretic probability

CoreHuman

On Ω=[0,1)\Omega = [0, 1) with Lebesgue measure let X(ω)=ωX(\omega) = \omega and let G\mathcal G be the σ-algebra generated by B1=[0,12)B_1 = [0, \tfrac12) and B2=[12,1)B_2 = [\tfrac12, 1). What is E[X∣G]\mathbb E[X \mid \mathcal G]?

Choose one

6. Measure-theoretic probability

CoreFormal

In Mathlib, Martingale M 𝓕 μ means: M is adapted and μ[M j | 𝓕 i] =ᵐ[μ] M i whenever i ≤ j. Which Lean statement correctly expresses a martingale has constant expectation (with [IsFiniteMeasure μ] and hM : Martingale M 𝓕 μ, hij : i ≤ j)?

Choose one

7. Measure-theoretic probability

CoreHuman

Let X1,…,X4X_1, \dots, X_4 be independent fair signs, P(Xi=1)=P(Xi=−1)=12P(X_i = 1) = P(X_i = -1) = \tfrac12, and S4=X1+X2+X3+X4S_4 = X_1 + X_2 + X_3 + X_4. Compute E[S44]\mathbb E[S_4^4] using the expansion from the proof of the strong law.

8. Measure-theoretic probability

StretchHuman

A simple symmetric random walk starts at 33 and stops at the first time TT it reaches 00 or 1010. Using optional stopping for the martingales SnS_n and Sn2−nS_n^2 - n, compute ET\mathbb E T.

9. Measure-theoretic probability

StretchHuman

Let ξ1,ξ2,…\xi_1, \xi_2, \dots be independent with P(ξi=0)=P(ξi=2)=12P(\xi_i = 0) = P(\xi_i = 2) = \tfrac12 and Mn=ξ1⋯ξnM_n = \xi_1 \cdots \xi_n. Then (Mn)(M_n) is a non-negative martingale with EMn=1\mathbb E M_n = 1, and Mn→0M_n \to 0 almost surely. Why does this not contradict EM∞=lim⁡EMn\mathbb E M_\infty = \lim \mathbb E M_n?

Choose one

10. Measure-theoretic probability

CoreComputational

A finite probability space has outcomes 0,1,…,n−10, 1, \dots, n-1 with probabilities probs, a random variable given by the list X, and a σ-algebra G\mathcal G generated by a partition blocks (a list of lists of outcomes). Write conditional_expectation(probs, X, blocks) returning the list whose ω\omega-th entry is E[X∣G](ω)\mathbb E[X \mid \mathcal G](\omega). Assume every block has positive probability. Use Fraction so the answers are exact.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"Convergence in probability and almost-sure convergence are the same thing." Almost-sure convergence is about individual sample paths: for almost every ω\omega, the sequence of numbers Xn(ω)X_n(\omega) converges. Convergence in probability is about the sequence of numbers P(∣Xn−X∣>ε)P(|X_n - X| > \varepsilon), and says nothing about any single path. Independent events with P(An)=1/nP(A_n) = 1/n give indicators tending to 00 in probability, yet almost every path has infinitely many 11s (second Borel–Cantelli lemma). Almost-sure convergence implies convergence in probability, and convergence in probability implies almost-sure convergence along a subsequence — no more.

Misconception

"A conditional expectation is a number." E[X∣A]\mathbb E[X \mid A] for an event with P(A)>0P(A) > 0 is a number, but E[X∣G]\mathbb E[X \mid \mathcal G] is a G\mathcal G-measurable random variable, defined only up to null sets: E[X1+X2∣X1]=X1+72\mathbb E[X_1 + X_2 \mid X_1] = X_1 + \tfrac72 for two dice. Treating it as a number leads to errors such as E[ZX∣G]=E[Z] E[X∣G]\mathbb E[ZX \mid \mathcal G] = \mathbb E[Z] \, \mathbb E[X \mid \mathcal G] instead of Z E[X∣G]Z \, \mathbb E[X \mid \mathcal G], and to paradoxes when conditioning on events of probability zero.

Misconception

"A martingale that converges almost surely converges in mean." The product martingale of independent ξi∈{0,2}\xi_i \in \{0, 2\} converges to 00 almost surely while EMn=1\mathbb E M_n = 1 for every nn. Uniform integrability is exactly what is missing. Likewise "EMT=EM0\mathbb E M_T = \mathbb E M_0 for every stopping time" is false: the simple random walk stopped at its first visit to 11 has MT=1M_T = 1.

Misconception

"Pairwise independent means independent." Toss two fair coins and let CC be the event that they agree. The events {first is heads}\{\text{first is heads}\}, {second is heads}\{\text{second is heads}\}, CC are pairwise independent, but any two of them determine the third. Chebyshev's weak law and Etemadi's strong law need only pairwise independence; the second Borel–Cantelli lemma as proved here and Kolmogorov's zero–one law need full independence.

Misconception

"Convergence in distribution means the random variables get close." It is a statement about laws only: Xn=−XX_n = -X converges in distribution to a standard normal XX without ever getting close to it. When the limit is a constant cc, however, convergence in distribution does imply convergence in probability to cc.

ViewpointsH

Many ways of seeing

Geometry— Conditioning is projecting

On L2(Ω,F,P)L^2(\Omega, \mathcal F, P), a Hilbert space, E[ ⋅∣G]\mathbb E[\,\cdot \mid \mathcal G] is the orthogonal projection onto the closed subspace of G\mathcal G-measurable functions; constants form the line onto which E\mathbb E projects, and the variance is a squared distance. The law of total variance Var⁡X=EVar⁡(X∣G)+Var⁡E[X∣G]\operatorname{Var} X = \mathbb E \operatorname{Var}(X \mid \mathcal G) + \operatorname{Var} \mathbb E[X \mid \mathcal G] is Pythagoras' theorem, the tower property says that projecting onto a subspace and then onto a smaller one equals projecting onto the smaller one, and a martingale with EMn2\mathbb E M_n^2 bounded is a sequence of projections of one vector onto growing subspaces — whose increments are orthogonal, so EMn2=EM02+∑kE(Mk−Mk−1)2\mathbb E M_n^2 = \mathbb E M_0^2 + \sum_k \mathbb E (M_k - M_{k-1})^2. Least-squares regression and the Kalman filter are this geometry in practice. See functional analysis.

Analysis— Fourier transforms and differentiation theorems

The characteristic function is the Fourier transform of a measure, and the proof of the central limit theorem is Fourier analysis: convolution of laws becomes multiplication, and the Gaussian solves the fixed-point equation φ(t/2)2=φ(t)\varphi(t/\sqrt 2)^2 = \varphi(t) of the normalised convolution square, and among laws with finite variance the centred Gaussians are the only solutions. Martingales, in turn, prove theorems of real analysis. Take f∈L1[0,1)f \in L^1[0, 1) and let Fn\mathcal F_n be generated by the dyadic intervals of length 2−n2^{-n}. Then E[f∣Fn](x)\mathbb E[f \mid \mathcal F_n](x) is the average of ff over the dyadic interval containing xx, a martingale; by Lévy's upward theorem it converges to E[f∣F∞]=f\mathbb E[f \mid \mathcal F_\infty] = f almost everywhere. That is a dyadic Lebesgue differentiation theorem, and Doob's maximal inequality is a dyadic Hardy–Littlewood maximal inequality — the start of a long dialogue with harmonic analysis.

Topology— The space of probability measures

Convergence in distribution is convergence in a topology: the weak (narrow) topology on the set P(S)\mathcal P(S) of Borel probability measures on a metric space SS, in which μn→μ\mu_n \to \mu when ∫f dμn→∫f dμ\int f \, d\mu_n \to \int f \, d\mu for all bounded continuous ff. The portmanteau theorem gives equivalent forms: lim sup⁡μn(F)≤μ(F)\limsup \mu_n(F) \le \mu(F) for closed FF, or lim inf⁡μn(U)≥μ(U)\liminf \mu_n(U) \ge \mu(U) for open UU. On a separable metric space this topology is metrised by the Lévy–Prokhorov metric, and Prokhorov's theorem (1956) says that on a Polish space a family of probability measures is relatively compact if and only if it is tight. When SS is compact, P(S)\mathcal P(S) is itself compact: by the Riesz representation theorem it is a weak-* closed subset of the unit ball of C(S)∗C(S)^*, compact by Banach–Alaoglu. Lévy's continuity theorem is proved exactly by this compactness, and Skorokhod's representation theorem turns weak convergence on a Polish space back into almost-sure convergence of suitably chosen random variables.

Number theory— Normal numbers and the Gaussian law of prime factors

Read the binary digits of a uniformly random x∈[0,1)x \in [0, 1) as coin tosses: the strong law says that almost every real number has asymptotically equal frequencies of 00s and 11s, and applying it to blocks of digits in every base gives Borel's normal number theorem (1909) — almost every real number is normal in every base. Yet no one has proved that 2\sqrt 2, π\pi or ee is normal in any base: "almost all" is not "this one".

Integers behave like random variables too. Let ω(n)\omega(n) be the number of distinct prime factors of nn. Hardy and Ramanujan (1917) showed that ω(n)\omega(n) is usually close to log⁡log⁡n\log \log n, and Turán (1934) reproved it by a Chebyshev-type variance bound, treating divisibility by different primes as nearly independent events. The Erdős–Kac theorem (1940) is a central limit theorem: for nn chosen uniformly from {1,…,N}\{1, \dots, N\}, ω(n)−log⁡log⁡Nlog⁡log⁡N\frac{\omega(n) - \log\log N}{\sqrt{\log\log N}} converges in distribution to a standard normal as N→∞N \to \infty. See analytic number theory.

Logic— Zero–one laws, randomness and the limits of measure

"Probability zero" is not "impossible" — HHHH… is a possible outcome — but logic can say which individual sequences deserve to be called random. Martin-Löf (1966) defined a binary sequence to be random if it avoids every effectively null set (every set covered by a uniformly computable sequence of open sets of measure at most 2−k2^{-k}). Each Martin-Löf random sequence satisfies the strong law of large numbers, the law of the iterated logarithm and every other almost-sure law whose exceptional set is effectively null, although no computable sequence is random.

Logic also shows why probability is defined on a σ-algebra rather than on all subsets. Vitali's construction (using the axiom of choice) gives a subset of [0,1)[0, 1) with no translation-invariant probability. Even without invariance, Banach and Kuratowski (1929) showed under the continuum hypothesis that no countably additive probability on all subsets of [0,1][0, 1] vanishes on points, and Ulam (1930) showed that such a measure would force 2ℵ02^{\aleph_0} to be at least a weakly inaccessible (real-valued measurable) cardinal — so ZFC cannot prove it exists. See the axiom of choice.

Wonder Trails

Wonder Trails

History & global context

History and context

  • Gerolamo Cardano's Liber de ludo aleae (written in the 16th century, printed 1663) and the correspondence of Blaise Pascal and Pierre de Fermat (1654) began the mathematics of chance; Christiaan Huygens (1657) introduced expectation.
  • Jacob Bernoulli's Ars Conjectandi (1713) proved the first weak law of large numbers; Abraham de Moivre (1733) found the normal approximation to the binomial, and Pierre-Simon Laplace (1812) extended it. Pafnuty Chebyshev (1867) proved his inequality and a general weak law; his students Andrey Markov and Aleksandr Lyapunov developed dependent chains and, with characteristic functions, a general central limit theorem (Lyapunov, 1901).
  • Émile Borel (1909) proved the strong law for coin tossing and the normal number theorem; Francesco Paolo Cantelli (1917) proved the lemma now bearing both names, and a strong law under fourth moments. Jarl Waldemar Lindeberg (1922) proved his general central limit theorem; Paul Lévy (1925) developed characteristic functions and the continuity theorem, and studied martingale-like sums in the 1930s.
  • Johann Radon (1913) and Otto Nikodym (1930) proved the theorem behind conditional expectation. Andrey Kolmogorov's Grundbegriffe (1933) gave the axioms, the extension theorem, the definition of conditional expectation and the zero–one law; he had proved the strong law for i.i.d. integrable variables in 1930. Aleksandr Khinchin proved the law of the iterated logarithm (1924) and, with Kolmogorov, convergence criteria for random series.
  • Jean Ville (1939) named martingales, after a betting strategy; Joseph Doob developed their theory, including the upcrossing inequality and the convergence and optional stopping theorems, in Stochastic Processes (1953). Paul Erdős and Mark Kac (1940) brought the central limit theorem into number theory; Yuri Prokhorov (1956) and Anatoliy Skorokhod (1956) laid the foundations of weak convergence; Nasrollah Etemadi (1981) gave the elementary proof of the strong law under pairwise independence.
Further reading

Further reading

  • David Williams, Probability with Martingales (1991) — the shortest route from measure theory to martingales; the upcrossing proof above follows it.
  • Rick Durrett, Probability: Theory and Examples (5th ed., 2019) — the standard graduate text: laws of large numbers, CLT, martingales, Brownian motion.
  • Patrick Billingsley, Probability and Measure (3rd ed., 1995) — measure theory and probability developed together, with weak convergence in depth.
  • Olav Kallenberg, Foundations of Modern Probability (2nd ed., 2002) — a comprehensive, concise reference.
  • Geoffrey Grimmett and David Stirzaker, Probability and Random Processes (3rd ed., 2001) — many worked examples and exercises.
  • A. N. Kolmogorov, Foundations of the Theory of Probability (1933; English translation 1950) — short and still readable.
  • Mark Kac, Statistical Independence in Probability, Analysis and Number Theory (1959) — Rademacher functions, normal numbers and the Erdős–Kac theorem.