Skip to content

Commit 05af26b

Browse files
feat: central limit theorem (leanprover-community#36208)
Prove the central limit theorem in dimension 1. Co-authored-by: @hanwenzhu Co-authored-by: Remy Degenne <remydegenne@gmail.com> Co-authored-by: Rémy Degenne <remydegenne@gmail.com>
1 parent 82fd896 commit 05af26b

8 files changed

Lines changed: 213 additions & 4 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5996,6 +5996,7 @@ public import Mathlib.Order.Zorn
59965996
public import Mathlib.Order.ZornAtoms
59975997
public import Mathlib.Probability.BorelCantelli
59985998
public import Mathlib.Probability.CDF
5999+
public import Mathlib.Probability.CentralLimitTheorem
59996000
public import Mathlib.Probability.Combinatorics.BinomialRandomGraph.Defs
60006001
public import Mathlib.Probability.CondVar
60016002
public import Mathlib.Probability.ConditionalExpectation

Mathlib/Analysis/SpecialFunctions/Complex/LogBounds.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ lemma tendsto_one_add_div_pow_exp (t : ℂ) :
364364
Tendsto (fun n : ℕ ↦ (1 + t / n) ^ n) atTop (𝓝 (exp t)) :=
365365
tendsto_one_add_div_cpow_exp t |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp)
366366

367-
set_option backward.isDefEq.respectTransparency false
368367
/-- `(1 + t/n + o(1/n)) ^ n → exp t` for `t ∈ ℂ`. -/
369368
lemma tendsto_pow_exp_of_isLittleO_sub_add_div {f : ℕ → ℂ} (t : ℂ)
370369
(hf : (fun n ↦ f n - (1 + t / n)) =o[atTop] fun n ↦ 1 / (n : ℂ)) :

Mathlib/MeasureTheory/Function/ConvergenceInDistribution.lean

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Rémy Degenne
66
module
77

88
public import Mathlib.MeasureTheory.Measure.Portmanteau
9+
public import Mathlib.Probability.IdentDistrib
910

1011
/-!
1112
# Convergence in distribution
@@ -42,7 +43,7 @@ and convergence in distribution.
4243

4344
@[expose] public section
4445

45-
open Filter
46+
open Filter ProbabilityTheory
4647
open scoped Topology
4748

4849
namespace MeasureTheory
@@ -74,6 +75,26 @@ lemma tendstoInDistribution_const [OpensMeasurableSpace E] (hZ : AEMeasurable Z
7475
forall_aemeasurable := fun _ ↦ by fun_prop
7576
tendsto := tendsto_const_nhds
7677

78+
lemma tendstoInDistribution_of_identDistrib [OpensMeasurableSpace E] (i : ι)
79+
(hX : ∀ j, IdentDistrib (X i) (X j) (μ i) (μ j)) (hZ : IdentDistrib (X i) Z (μ i) μ') :
80+
TendstoInDistribution X l Z μ μ' where
81+
forall_aemeasurable j := (hX j).aemeasurable_snd
82+
aemeasurable_limit := hZ.aemeasurable_snd
83+
tendsto := by
84+
convert tendsto_const_nhds with j
85+
exact (hX j).map_eq.symm.trans hZ.map_eq
86+
87+
protected lemma TendstoInDistribution.congr [OpensMeasurableSpace E] {T : Ω' → E}
88+
(hXY : ∀ i, X i =ᵐ[μ i] Y i) (hZT : Z =ᵐ[μ'] T) (h : TendstoInDistribution X l Z μ μ') :
89+
TendstoInDistribution Y l T μ μ' where
90+
forall_aemeasurable i := (h.forall_aemeasurable i).congr (hXY i)
91+
aemeasurable_limit := h.aemeasurable_limit.congr hZT
92+
tendsto := by
93+
convert h.tendsto using 2 with n
94+
· simpa using Measure.map_congr (hXY n).symm
95+
· rw! [Measure.map_congr hZT]
96+
rfl
97+
7798
@[simp]
7899
lemma tendstoInDistribution_of_isEmpty [IsEmpty E] :
79100
TendstoInDistribution X l Z μ μ' where

Mathlib/MeasureTheory/Measure/CharacteristicFunction/TaylorExpansion.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public section
3131

3232

3333
open ProbabilityTheory Complex Set VectorFourier
34-
open scoped Nat RealInnerProductSpace
34+
open scoped Nat RealInnerProductSpace Topology
3535

3636
namespace MeasureTheory
3737

@@ -150,6 +150,17 @@ lemma taylorWithinEval_charFun_two_zero' (hX : AEMeasurable X P)
150150
any_goals fun_prop
151151
simp [← Pi.pow_apply, h1]
152152

153+
lemma taylor_charFun_two (hX : AEMeasurable X P) (h0 : P[X] = 0) (h1 : P[X ^ 2] = 1) :
154+
(fun t ↦ charFun (P.map X) t - (1 - t ^ 2 / 2)) =o[𝓝 0] fun t ↦ t ^ 2 := by
155+
simp_rw [← taylorWithinEval_charFun_two_zero' (by fun_prop) h0 h1]
156+
convert taylor_isLittleO_univ ?_
157+
· simp
158+
refine contDiff_charFun <|
159+
(memLp_two_iff_integrable_sq (by fun_prop)).2 (.of_integral_ne_zero ?_)
160+
rw [integral_map]
161+
any_goals fun_prop
162+
simp_all
163+
153164
end Real
154165

155166
end MeasureTheory
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/-
2+
Copyright (c) 2024 Thomas Zhu. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Thomas Zhu, Etienne Marion
5+
-/
6+
module
7+
8+
public import Mathlib.Probability.Distributions.Gaussian.Real
9+
public import Mathlib.MeasureTheory.Function.ConvergenceInDistribution
10+
11+
import Mathlib.MeasureTheory.Measure.CharacteristicFunction.TaylorExpansion
12+
import Mathlib.MeasureTheory.Measure.LevyConvergence
13+
import Mathlib.Probability.Independence.CharacteristicFunction
14+
15+
/-!
16+
# Central limit theorem
17+
18+
We prove the central limit theorem in dimension 1.
19+
20+
## Main statement
21+
22+
* `tendstoInDistribution_inv_sqrt_mul_sum_sub`: Given a sequence of random variables
23+
`X : ℕ → Ω → ℝ` that are independent, identically distributed with mean `μ` and variance `v`,
24+
and a random variable `Y : Ω' → ℝ` following `gaussianReal 0 v`, the sequence
25+
`n ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution.
26+
27+
## Tags
28+
29+
central limit theorem
30+
-/
31+
32+
public section
33+
34+
noncomputable section
35+
36+
open MeasureTheory ProbabilityTheory Complex Filter
37+
open scoped Real Topology
38+
39+
namespace ProbabilityTheory
40+
41+
variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'}
42+
{P : Measure Ω} {P' : Measure Ω'} {X : ℕ → Ω → ℝ} {Y : Ω' → ℝ}
43+
44+
lemma charFun_inv_sqrt_mul_sum (hindep : iIndepFun X P)
45+
(hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) {n : ℕ} {t : ℝ} :
46+
charFun (P.map (fun ω ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k ω)) t =
47+
(charFun (P.map (X 0)) ((√n)⁻¹ * t)) ^ n := by
48+
have mX n := (hident n).aemeasurable_fst
49+
rw [charFun_map_mul_comp, (hindep.restrict _).charFun_map_fun_finset_sum_eq_prod (fun _ _↦ mX _)]
50+
· simp [fun i ↦ (hident i).map_eq]
51+
· exact Finset.aemeasurable_fun_sum _ fun _ _ ↦ mX _
52+
53+
variable [IsProbabilityMeasure P]
54+
55+
lemma tendsto_charFun_inv_sqrt_mul_pow {X : Ω → ℝ}
56+
(hX : AEMeasurable X P) (h0 : P[X] = 0) (h1 : P[X ^ 2] = 1) (t : ℝ) :
57+
Tendsto (fun (n : ℕ) ↦ (charFun (P.map X) ((√n)⁻¹ * t)) ^ n) atTop (𝓝 (exp (- t ^ 2 / 2))) := by
58+
apply tendsto_pow_exp_of_isLittleO_sub_add_div
59+
suffices (fun (n : ℕ) ↦ charFun (Measure.map X P) ((√n)⁻¹ * t) -
60+
(1 + (-(((√n)⁻¹ * t) ^ 2 / 2) : ℂ))) =o[atTop] fun n ↦ ((√n)⁻¹ * t) ^ 2 by
61+
have aux : (fun (n : ℕ) ↦ ‖(1 / n : ℂ)‖) = fun (n : ℕ) ↦ ‖(1 / n : ℝ)‖ := by simp
62+
rw [← Asymptotics.isLittleO_norm_right, aux, Asymptotics.isLittleO_norm_right]
63+
refine .of_const_mul_right (c := t ^ 2) ?_
64+
convert this using 4 with n <;> norm_cast <;> simp [field]
65+
have : Tendsto (fun (n : ℕ) ↦ (√n)⁻¹ * t) atTop (𝓝 0) := by
66+
rw [← zero_mul t]
67+
exact .mul_const t (tendsto_inv_atTop_zero.comp <| Real.tendsto_sqrt_atTop.comp <|
68+
tendsto_natCast_atTop_atTop)
69+
convert (taylor_charFun_two hX h0 h1).comp_tendsto this using 2
70+
simp
71+
ring
72+
73+
variable [IsProbabilityMeasure P']
74+
75+
/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are
76+
independent, identically distributed, centered and with variance `1` and a random variable
77+
`Y : Ω' → ℝ` following `gaussianReal 0 1`, the sequence
78+
`n ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k` converges to `Y` in distribution. -/
79+
theorem tendstoInDistribution_inv_sqrt_mul_sum (hY : HasLaw Y (gaussianReal 0 1) P')
80+
(h0 : P[X 0] = 0) (h1 : P[X 0 ^ 2] = 1) (hindep : iIndepFun X P)
81+
(hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) :
82+
TendstoInDistribution (fun (n : ℕ) ω ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k ω) atTop Y
83+
(fun _ ↦ P) P' where
84+
forall_aemeasurable n :=
85+
.const_mul (Finset.aemeasurable_fun_sum _ fun _ _ ↦ (hident _).aemeasurable_fst) _
86+
tendsto := by
87+
refine ProbabilityMeasure.tendsto_iff_tendsto_charFun.2 fun t ↦ ?_
88+
rw! [hY.map_eq]
89+
simpa [charFun_inv_sqrt_mul_sum hindep hident, charFun_gaussianReal, neg_div] using
90+
tendsto_charFun_inv_sqrt_mul_pow (hident 0).aemeasurable_fst h0 h1 t
91+
92+
/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are
93+
independent, identically distributed with mean `μ` and non-zero variance `v`, and a random variable
94+
`Y : Ω' → ℝ` following `gaussianReal 0 1`, the sequence
95+
`n ↦ (√(n * v)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution. -/
96+
private theorem tendstoInDistribution_inv_sqrt_mul_var_mul_sum_sub
97+
(hY : HasLaw Y (gaussianReal 0 1) P')
98+
(hX : Var[X 0; P] ≠ 0) (hindep : iIndepFun X P)
99+
(hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) :
100+
TendstoInDistribution
101+
(fun (n : ℕ) ω ↦ (√(n * Var[X 0; P]))⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0]))
102+
atTop Y (fun _ ↦ P) P' := by
103+
have mX0 := (hident 0).aemeasurable_fst
104+
have intX0 : Integrable (X 0) P := memLp_one_iff_integrable.1 <|
105+
(memLp_two_of_variance_ne_zero mX0.aestronglyMeasurable hX).mono_exponent (by simp)
106+
have this (n : ℕ) ω : (√(n * Var[X 0; P]))⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0]) =
107+
(√n)⁻¹ * ∑ k ∈ Finset.range n, (X k ω - P[X 0]) / √Var[X 0; P] := by
108+
rw [← Finset.sum_div, Finset.sum_sub_distrib]
109+
simp [field]
110+
simp_rw [this]
111+
convert tendstoInDistribution_inv_sqrt_mul_sum hY ?_ ?_ ?_ ?_
112+
· rw [integral_div, integral_sub intX0 (by simp)]
113+
simp
114+
· simp only [Pi.pow_apply, div_pow]
115+
rw [integral_div, ← variance_eq_integral mX0, Real.sq_sqrt (variance_nonneg _ _), div_self hX]
116+
· exact hindep.comp (fun _ x ↦ (x - P[X 0]) / √Var[X 0; P]) (by fun_prop)
117+
· convert fun n ↦ (hident n).comp (u := fun x ↦ (x - P[X 0]) / √Var[X 0; P]) (by fun_prop)
118+
119+
/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are
120+
independent, identically distributed with mean `μ` and variance `v`, and a random variable
121+
`Y : Ω' → ℝ` following `gaussianReal 0 v`, the sequence
122+
`n ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution. -/
123+
theorem tendstoInDistribution_inv_sqrt_mul_sum_sub
124+
(hY : HasLaw Y (gaussianReal 0 Var[X 0; P].toNNReal) P')
125+
(hX : MemLp (X 0) 2 P) (hindep : iIndepFun X P)
126+
(hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) :
127+
TendstoInDistribution
128+
(fun (n : ℕ) ω ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0]))
129+
atTop Y (fun _ ↦ P) P' := by
130+
obtain h | h := eq_or_ne Var[X 0; P] 0
131+
· have : ∀ᵐ ω ∂P, ∀ n, X n ω = P[X 0] := by
132+
refine ae_all_iff.2 fun n ↦ ?_
133+
convert (ae_eq_integral_of_variance_eq_zero ((hident n).memLp_iff.2 hX)) ?_ using 3
134+
· rw [(hident n).integral_eq]
135+
· rwa [(hident n).variance_eq]
136+
have mX (n : ℕ) := (hident n).aemeasurable_fst
137+
refine tendstoInDistribution_of_identDistrib 0 (fun n ↦ ?_) ?_
138+
· refine ⟨by fun_prop, by fun_prop, Measure.map_congr ?_⟩
139+
filter_upwards [this] with ω hω
140+
simp [hω]
141+
· exact ⟨by fun_prop, by fun_prop, by simp [hY.map_eq, h]⟩
142+
have : HasLaw (fun ω ↦ Y ω / √Var[X 0; P]) (gaussianReal 0 1) P' := by
143+
convert gaussianReal_div_const hY _
144+
· simp
145+
· ext; simp [h]
146+
convert (tendstoInDistribution_inv_sqrt_mul_var_mul_sum_sub this h hindep hident).continuous_comp
147+
(g := (√Var[X 0; P] * ·)) (by fun_prop)
148+
· simp [field] -- simp [field, hX] triggers the unused simp arguments linter
149+
field_simp [h]
150+
· ext
151+
simp [field] -- simp [field, hX] triggers the unused simp arguments linter
152+
field_simp [h]
153+
154+
end ProbabilityTheory

Mathlib/Probability/Moments/Variance.lean

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ lemma variance_of_not_memLp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ
132132
(hX_not : ¬ MemLp X 2 μ) :
133133
variance X μ = 0 := by simp [variance, (evariance_eq_top_iff hX).mpr hX_not]
134134

135+
lemma memLp_two_of_variance_ne_zero [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ)
136+
(h : Var[X; μ] ≠ 0) : MemLp X 2 μ := by
137+
contrapose! h
138+
exact variance_of_not_memLp hX h
139+
135140
theorem ofReal_variance [IsFiniteMeasure μ] (hX : MemLp X 2 μ) :
136141
.ofReal (variance X μ) = evariance X μ := by
137142
rw [variance, ENNReal.ofReal_toReal]
@@ -150,6 +155,19 @@ lemma variance_eq_integral (hX : AEMeasurable X μ) : Var[X; μ] = ∫ ω, (X ω
150155
simp [variance, evariance, toReal_enorm, ← integral_toReal ((hX.sub_const _).enorm.pow_const _) <|
151156
.of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top]
152157

158+
/-- A random variable with variance `0` is almost surely constant. -/
159+
lemma ae_eq_integral_of_variance_eq_zero [IsFiniteMeasure μ] (hX : MemLp X 2 μ)
160+
(h : Var[X; μ] = 0) :
161+
∀ᵐ ω ∂μ, X ω = μ[X] := by
162+
rw [variance_eq_integral hX.aemeasurable, integral_eq_zero_iff_of_nonneg] at h
163+
· filter_upwards [h] with ω hω
164+
simp at hω
165+
grind
166+
· exact fun _ ↦ by positivity
167+
· simp_rw [sub_sq]
168+
exact (hX.integrable_sq.sub (((hX.integrable (by simp)).const_mul _).mul_const _)).add
169+
(integrable_const _)
170+
153171
lemma variance_of_integral_eq_zero (hX : AEMeasurable X μ) (hXint : μ[X] = 0) :
154172
variance X μ = ∫ ω, X ω ^ 2 ∂μ := by
155173
simp [variance_eq_integral hX, hXint]
@@ -179,6 +197,7 @@ lemma covariance_self {X : Ω → ℝ} (hX : AEMeasurable X μ) :
179197
congr with x
180198
ring
181199

200+
@[simp]
182201
theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ :=
183202
ENNReal.toReal_nonneg
184203

docs/100.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
authors: Thomas Zhu
194194
47:
195195
title : The Central Limit Theorem
196+
decl : ProbabilityTheory.tendstoInDistribution_inv_sqrt_mul_sum_sub
197+
authors: Thomas Zhu, Rémy Degenne, Etienne Marion
196198
48:
197199
title : Dirichlet’s Theorem
198200
decl : Nat.infinite_setOf_prime_and_eq_mod

docs/1000.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ Q190391X:
135135

136136
Q190391:
137137
title: Central limit theorem
138-
# in 100.yaml also
138+
decl: ProbabilityTheory.tendstoInDistribution_inv_sqrt_mul_sum_sub
139+
authors: Thomas Zhu, Rémy Degenne, Etienne Marion
140+
date: 2026
139141

140142
Q190556:
141143
title: De Moivre's theorem

0 commit comments

Comments
 (0)