Skip to content

Commit f9cb3f9

Browse files
committed
feat: independence and uncurrying (#30184)
Consider `((Xᵢⱼ)ⱼ)ᵢ` a family of families of random variables. Assume that for any `i`, the random variables `(Xᵢⱼ)ⱼ` are independent. Assume furthermore that the random variables `((Xᵢⱼ)ⱼ)ᵢ` are independent. Then the random variables `(Xᵢⱼ)` indexed by pairs `(i, j)` are independent. This PR also drops the `IsProbabilityMeasure` assumption from [MeasureTheory.Measure.infinitePi](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Probability/ProductMeasure.html#MeasureTheory.Measure.infinitePi) to avoid weird errors with `congr`.
1 parent f4dee01 commit f9cb3f9

File tree

2 files changed

+131
-32
lines changed

2 files changed

+131
-32
lines changed

Mathlib/Probability/Independence/InfinitePi.lean

Lines changed: 116 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,35 @@ import Mathlib.Probability.Independence.Basic
77
import Mathlib.Probability.ProductMeasure
88

99
/-!
10-
# Random variables are independent iff their joint distribution is the product measure.
10+
# Independence of an infinite family of random variables
11+
12+
In this file we provide several results about independence of arbitrary families of random
13+
variables, relying on `Measure.infinitePi`.
14+
15+
## Implementation note
1116
1217
There are several possible measurability assumptions:
1318
* The map `ω ↦ (Xᵢ(ω))ᵢ` is measurable.
1419
* For all `i`, the map `ω ↦ Xᵢ(ω)` is measurable.
1520
* The map `ω ↦ (Xᵢ(ω))ᵢ` is almost everywhere measurable.
1621
* For all `i`, the map `ω ↦ Xᵢ(ω)` is almost everywhere measurable.
1722
Although the first two options are equivalent, the last two are not if the index set is not
18-
countable. Therefore we first prove the third case `iIndepFun_iff_map_fun_eq_infinitePi_map₀`,
19-
then deduce the fourth case in `iIndepFun_iff_map_fun_eq_infinitePi_map₀'` (assuming the index
20-
type is countable), and we prove the first case in `iIndepFun_iff_map_fun_eq_infinitePi_map`.
23+
countable.
2124
-/
2225

2326
open MeasureTheory Measure ProbabilityTheory
2427

2528
namespace ProbabilityTheory
2629

27-
variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ]
30+
variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P]
2831
{𝓧 : ι → Type*} {m𝓧 : ∀ i, MeasurableSpace (𝓧 i)} {X : Π i, Ω → 𝓧 i}
2932

3033
/-- Random variables are independent iff their joint distribution is the product measure. This
3134
is a version where the random variable `ω ↦ (Xᵢ(ω))ᵢ` is almost everywhere measurable.
3235
See `iIndepFun_iff_map_fun_eq_infinitePi_map₀'` for a version which only assumes that
3336
each `Xᵢ` is almost everywhere measurable and that `ι` is countable. -/
34-
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀ (mX : AEMeasurable (fun ω i ↦ X i ω) μ) :
35-
haveI _ i := isProbabilityMeasure_map (mX.eval i)
36-
iIndepFun X μ ↔ μ.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ μ.map (X i)) where
37+
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀ (mX : AEMeasurable (fun ω i ↦ X i ω) P) :
38+
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) where
3739
mp h := by
3840
have _ i := isProbabilityMeasure_map (mX.eval i)
3941
refine eq_infinitePi _ fun s t ht ↦ ?_
@@ -43,12 +45,13 @@ lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀ (mX : AEMeasurable (fun ω i
4345
· have : s.restrict ∘ (fun ω i ↦ X i ω) = fun ω i ↦ s.restrict X i ω := by ext; simp
4446
rw [this, (iIndepFun_iff_map_fun_eq_pi_map ?_).1 (h s), pi_pi]
4547
· simp only [Finset.restrict]
46-
rw [s.prod_coe_sort fun i ↦ μ.map (X i) (t i)]
48+
rw [s.prod_coe_sort fun i ↦ P.map (X i) (t i)]
4749
exact fun i ↦ mX.eval i
4850
any_goals fun_prop
4951
· exact mX
5052
· exact .univ_pi fun i ↦ ht i i.2
5153
mpr h := by
54+
have _ i := isProbabilityMeasure_map (mX.eval i)
5255
rw [iIndepFun_iff_finset]
5356
intro s
5457
rw [iIndepFun_iff_map_fun_eq_pi_map]
@@ -62,29 +65,117 @@ lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀ (mX : AEMeasurable (fun ω i
6265
/-- Random variables are independent iff their joint distribution is the product measure. This is
6366
an `AEMeasurable` version of `iIndepFun_iff_map_fun_eq_infinitePi_map`, which is why it requires
6467
`ι` to be countable. -/
65-
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀' [Countable ι] (mX : ∀ i, AEMeasurable (X i) μ) :
66-
haveI _ i := isProbabilityMeasure_map (mX i)
67-
iIndepFun X μ ↔ μ.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ μ.map (X i)) :=
68+
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀' [Countable ι] (mX : ∀ i, AEMeasurable (X i) P) :
69+
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) :=
6870
iIndepFun_iff_map_fun_eq_infinitePi_map₀ <| aemeasurable_pi_iff.2 mX
6971

7072
/-- Random variables are independent iff their joint distribution is the product measure. -/
7173
lemma iIndepFun_iff_map_fun_eq_infinitePi_map (mX : ∀ i, Measurable (X i)) :
72-
haveI _ i := isProbabilityMeasure_map (μ := μ) (mX i).aemeasurable
73-
iIndepFun X μ ↔ μ.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ μ.map (X i)) :=
74+
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) :=
7475
iIndepFun_iff_map_fun_eq_infinitePi_map₀ <| measurable_pi_iff.2 mX |>.aemeasurable
7576

76-
variable {Ω : ι → Type*} {mΩ : ∀ i, MeasurableSpace (Ω i)}
77-
{μ : (i : ι) → Measure (Ω i)} [∀ i, IsProbabilityMeasure (μ i)] {X : (i : ι) → Ω i → 𝓧 i}
78-
7977
/-- Given random variables `X i : Ω i → 𝓧 i`, they are independent when viewed as random
8078
variables defined on the product space `Π i, Ω i`. -/
81-
lemma iIndepFun_infinitePi (mX : ∀ i, Measurable (X i)) :
82-
iIndepFun (fun i ω ↦ X i (ω i)) (infinitePi μ) := by
83-
refine iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop) |>.2 ?_
84-
rw [infinitePi_map_pi _ mX]
85-
congr
86-
ext i : 1
87-
rw [← (measurePreserving_eval_infinitePi μ i).map_eq, map_map (mX i) (by fun_prop),
88-
Function.comp_def]
79+
lemma iIndepFun_infinitePi {Ω : ι → Type*} {mΩ : ∀ i, MeasurableSpace (Ω i)}
80+
{P : (i : ι) → Measure (Ω i)} [∀ i, IsProbabilityMeasure (P i)] {X : (i : ι) → Ω i → 𝓧 i}
81+
(mX : ∀ i, Measurable (X i)) :
82+
iIndepFun (fun i ω ↦ X i (ω i)) (infinitePi P) := by
83+
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop), infinitePi_map_pi _ mX]
84+
congrm infinitePi fun i ↦ ?_
85+
rw [← infinitePi_map_eval P i, map_map (mX i) (by fun_prop), Function.comp_def]
86+
87+
section curry
88+
89+
omit [IsProbabilityMeasure P]
90+
91+
section dependent
92+
93+
variable {κ : ι → Type*} {𝓧 : (i : ι) → κ i → Type*} {m𝓧 : ∀ i j, MeasurableSpace (𝓧 i j)}
94+
95+
/-- Consider `((Xᵢⱼ)ⱼ)ᵢ` a family of families of random variables.
96+
Assume that for any `i`, the random variables `(Xᵢⱼ)ⱼ` are independent.
97+
Assume furthermore that the random variables `((Xᵢⱼ)ⱼ)ᵢ` are independent.
98+
Then the random variables `(Xᵢⱼ)` indexed by pairs `(i, j)` are independent.
99+
100+
This is a dependent version of `iIndepFun_uncurry'`. -/
101+
lemma iIndepFun_uncurry {X : (i : ι) → (j : κ i) → Ω → 𝓧 i j} (mX : ∀ i j, Measurable (X i j))
102+
(h1 : iIndepFun (fun i ω ↦ (X i · ω)) P) (h2 : ∀ i, iIndepFun (X i) P) :
103+
iIndepFun (fun (p : (i : ι) × (κ i)) ω ↦ X p.1 p.2 ω) P := by
104+
have := h1.isProbabilityMeasure
105+
have : ∀ i j, IsProbabilityMeasure (P.map (X i j)) :=
106+
fun i j ↦ isProbabilityMeasure_map (mX i j).aemeasurable
107+
have : ∀ i, IsProbabilityMeasure (P.map (fun ω ↦ (X i · ω))) :=
108+
fun i ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
109+
have : (MeasurableEquiv.piCurry 𝓧) ∘ (fun ω p ↦ X p.1 p.2 ω) = fun ω i j ↦ X i j ω := by
110+
ext; simp [Sigma.curry]
111+
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop),
112+
← (MeasurableEquiv.piCurry 𝓧).map_measurableEquiv_injective.eq_iff,
113+
map_map (by fun_prop) (by fun_prop), this,
114+
(iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)).1 h1,
115+
infinitePi_map_piCurry (fun i j ↦ P.map (X i j))]
116+
congrm infinitePi fun i ↦ ?_
117+
rw [(iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)).1 (h2 i)]
118+
119+
/-- Given random variables `X i j : Ω i j → 𝓧 i j`, they are independent when viewed as random
120+
variables defined on the product space `Π i, Π j, Ω i j`. -/
121+
lemma iIndepFun_uncurry_infinitePi {Ω : (i : ι) → κ i → Type*} {mΩ : ∀ i j, MeasurableSpace (Ω i j)}
122+
{X : (i : ι) → (j : κ i) → Ω i j → 𝓧 i j}
123+
(μ : (i : ι) → (j : κ i) → Measure (Ω i j)) [∀ i j, IsProbabilityMeasure (μ i j)]
124+
(mX : ∀ i j, Measurable (X i j)) :
125+
iIndepFun (fun (p : (i : ι) × κ i) (ω : Π i, Π j, Ω i j) ↦ X p.1 p.2 (ω p.1 p.2))
126+
(infinitePi (fun i ↦ infinitePi (μ i))) := by
127+
refine iIndepFun_uncurry (P := infinitePi (fun i ↦ infinitePi (μ i)))
128+
(X := fun i j ω ↦ X i j (ω i j)) (by fun_prop) ?_ fun i ↦ ?_
129+
· exact iIndepFun_infinitePi (P := fun i ↦ infinitePi (μ i))
130+
(X := fun i u j ↦ X i j (u j)) (by fun_prop)
131+
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)]
132+
change map ((fun f ↦ f i) ∘ (fun ω i j ↦ X i j (ω i j)))
133+
(infinitePi fun i ↦ infinitePi (μ i)) = _
134+
rw [← map_map (by fun_prop) (by fun_prop),
135+
infinitePi_map_pi (X := fun i ↦ (j : κ i) → Ω i j) (μ := fun i ↦ infinitePi (μ i))
136+
(f := fun i f j ↦ X i j (f j)), @infinitePi_map_eval .., infinitePi_map_pi]
137+
· congrm infinitePi fun j ↦ ?_
138+
change _ = map (((fun f ↦ f j) ∘ (fun f ↦ f i)) ∘ (fun ω i j ↦ X i j (ω i j)))
139+
(infinitePi fun i ↦ infinitePi (μ i))
140+
rw [← map_map (by fun_prop) (by fun_prop), infinitePi_map_pi (X := fun i ↦ (j : κ i) → Ω i j)
141+
(μ := fun i ↦ infinitePi (μ i)) (f := fun i f j ↦ X i j (f j)),
142+
← map_map (by fun_prop) (by fun_prop),
143+
@infinitePi_map_eval .., infinitePi_map_pi, @infinitePi_map_eval ..]
144+
any_goals fun_prop
145+
· exact fun _ ↦ isProbabilityMeasure_map (by fun_prop)
146+
· exact fun _ ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
147+
any_goals fun_prop
148+
exact fun _ ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
149+
150+
end dependent
151+
152+
section nondependent
153+
154+
variable {κ : Type*} {𝓧 : ι → κ → Type*} {m𝓧 : ∀ i j, MeasurableSpace (𝓧 i j)}
155+
156+
/-- Consider `((Xᵢⱼ)ⱼ)ᵢ` a family of families of random variables.
157+
Assume that for any `i`, the random variables `(Xᵢⱼ)ⱼ` are independent.
158+
Assume furthermore that the random variables `((Xᵢⱼ)ⱼ)ᵢ` are independent.
159+
Then the random variables `(Xᵢⱼ)` indexed by pairs `(i, j)` are independent.
160+
161+
This is a non-dependent version of `iIndepFun_uncurry`. -/
162+
lemma iIndepFun_uncurry' {X : (i : ι) → (j : κ) → Ω → 𝓧 i j} (mX : ∀ i j, Measurable (X i j))
163+
(h1 : iIndepFun (fun i ω ↦ (X i · ω)) P) (h2 : ∀ i, iIndepFun (X i) P) :
164+
iIndepFun (fun (p : ι × κ) ω ↦ X p.1 p.2 ω) P :=
165+
(iIndepFun_uncurry mX h1 h2).of_precomp (Equiv.sigmaEquivProd ι κ).surjective
166+
167+
/-- Given random variables `X i j : Ω i j → 𝓧 i j`, they are independent when viewed as random
168+
variables defined on the product space `Π i, Π j, Ω i j`. -/
169+
lemma iIndepFun_uncurry_infinitePi' {Ω : ι → κ → Type*} {mΩ : ∀ i j, MeasurableSpace (Ω i j)}
170+
{X : (i : ι) → (j : κ) → Ω i j → 𝓧 i j}
171+
(μ : (i : ι) → (j : κ) → Measure (Ω i j)) [∀ i j, IsProbabilityMeasure (μ i j)]
172+
(mX : ∀ i j, Measurable (X i j)) :
173+
iIndepFun (fun (p : ι × κ) (ω : Π i, Π j, Ω i j) ↦ X p.1 p.2 (ω p.1 p.2))
174+
(infinitePi (fun i ↦ infinitePi (μ i))) :=
175+
(iIndepFun_uncurry_infinitePi μ mX).of_precomp (Equiv.sigmaEquivProd ι κ).surjective
176+
177+
end nondependent
178+
179+
end curry
89180

90181
end ProbabilityTheory

Mathlib/Probability/ProductMeasure.lean

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,27 @@ theorem isSigmaSubadditive_piContent : (piContent μ).IsSigmaSubadditive := by
340340

341341
namespace Measure
342342

343+
open scoped Classical in
343344
/-- The product measure of an arbitrary family of probability measures. It is defined as the unique
344345
extension of the function which gives to cylinders the measure given by the associated product
345-
measure. -/
346+
measure.
347+
348+
It is defined via an `if ... then ... else` so that it can be manipulated without carrying
349+
a proof that the measures are probability measures. -/
346350
noncomputable def infinitePi : Measure (Π i, X i) :=
347-
(piContent μ).measure isSetSemiring_measurableCylinders
348-
generateFrom_measurableCylinders.ge (isSigmaSubadditive_piContent μ)
351+
if h : ∀ i, IsProbabilityMeasure (μ i) then
352+
(piContent μ).measure isSetSemiring_measurableCylinders
353+
generateFrom_measurableCylinders.ge (isSigmaSubadditive_piContent (hμ := h) μ)
354+
else 0
349355

350356
/-- The product measure is the projective limit of the partial product measures. This ensures
351357
uniqueness and expresses the value of the product measure applied to cylinders. -/
352358
theorem isProjectiveLimit_infinitePi :
353359
IsProjectiveLimit (infinitePi μ) (fun I : Finset ι ↦ (Measure.pi (fun i : I ↦ μ i))) := by
354360
intro I
355361
ext s hs
356-
rw [map_apply (measurable_restrict I) hs, infinitePi, AddContent.measure_eq, ← cylinder,
357-
piContent_cylinder μ hs]
362+
rw [map_apply (measurable_restrict I) hs, infinitePi, dif_pos hμ, AddContent.measure_eq,
363+
← cylinder, piContent_cylinder μ hs]
358364
· exact generateFrom_measurableCylinders.symm
359365
· exact cylinder_mem_measurableCylinders _ _ hs
360366

@@ -408,10 +414,12 @@ lemma _root_.measurePreserving_eval_infinitePi (i : ι) :
408414
rw [this, ← map_map, infinitePi_map_restrict, (measurePreserving_eval _ _).map_eq]
409415
all_goals fun_prop
410416

417+
lemma infinitePi_map_eval (i : ι) :
418+
(infinitePi μ).map (fun x ↦ x i) = μ i :=
419+
(measurePreserving_eval_infinitePi μ i).map_eq
420+
411421
lemma infinitePi_map_pi {Y : ι → Type*} [∀ i, MeasurableSpace (Y i)] {f : (i : ι) → X i → Y i}
412422
(hf : ∀ i, Measurable (f i)) :
413-
haveI (i : ι) : IsProbabilityMeasure ((μ i).map (f i)) :=
414-
isProbabilityMeasure_map (hf i).aemeasurable
415423
(infinitePi μ).map (fun x i ↦ f i (x i)) = infinitePi (fun i ↦ (μ i).map (f i)) := by
416424
have (i : ι) : IsProbabilityMeasure ((μ i).map (f i)) :=
417425
isProbabilityMeasure_map (hf i).aemeasurable

0 commit comments

Comments
 (0)