BDD library: Exchangeability Contractability
DefinitionExchangeability_Contractabilityprobability
Core definitions and structural lemmas of the binary decision diagram library (Exchangeability_Contractability), machine-checked in Lean 4 against Mathlib. See the linked source module.
Definition code
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
import Mathlib.MeasureTheory.Measure.Typeclasses.Probability
import Definitions.Def_Exchangeability_Probability_InfiniteProduct
import Definitions.Def_Exchangeability_Util_StrictMono
set_option autoImplicit true
namespace MeasureTheory
end MeasureTheory
namespace ProbabilityTheory
end ProbabilityTheory
namespace Util.StrictMono
end Util.StrictMono
/-
Copyright (c) 2025 Cameron Freer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Cameron Freer
-/
/-!
# Contractability and Exchangeability
This file establishes the relationship between **exchangeability** and **contractability**
for infinite sequences of random variables, following Kallenberg's "Probabilistic
Symmetries and Invariance Principles" (2005).
## Main definitions
* `Exchangeable μ X`: The sequence `X` is exchangeable under measure `μ` if its
finite-dimensional distributions are invariant under finite permutations.
* `FullyExchangeable μ X`: The sequence is fully exchangeable if invariant under
*all* permutations of ℕ (not just finite ones).
* `Contractable μ X`: The sequence is contractable if all strictly increasing
subsequences of equal length have the same distribution.
## Main results
* `FullyExchangeable.exchangeable`: Full exchangeability implies (finite) exchangeability.
* `contractable_of_exchangeable`: **Exchangeable ⇒ contractable** (via permutation extension).
* `exists_perm_extending_strictMono`: Key combinatorial lemma showing that any strictly
monotone function `k : Fin m → ℕ` can be extended to a permutation of `Fin n`.
## The de Finetti-Ryll-Nardzewski equivalence
The full theorem establishes the equivalence for infinite sequences:
**contractable ↔ exchangeable ↔ conditionally i.i.d.**
This file proves the implication **exchangeable → contractable** using a permutation
extension argument.
### The complete picture
- **Exchangeable → contractable** (this file): Any strictly increasing subsequence
can be realized as the image of the first m coordinates under some permutation.
- **Contractable → exchangeable** (`Exchangeability/DeFinetti/Theorem.lean`): Uses ergodic
theory and the martingale convergence approach.
- **Exchangeable ↔ fully exchangeable** (`Exchangeability/Exchangeability.lean`):
Uses π-system uniqueness and finite approximation of infinite permutations.
- **Conditionally i.i.d. → exchangeable** (`Exchangeability/ConditionallyIID.lean`):
Directly from the definition.
## Implementation notes
The key technical challenge is constructing permutations that extend strictly monotone
selections. Given `k : Fin m → ℕ` with `k(0) < k(1) < ... < k(m-1)`, we construct
a permutation `σ : Perm (Fin n)` such that `σ(i) = k(i)` for `i < m`. This is a thin
wrapper around mathlib's `Equiv.Perm.exists_extending_pair`.
## References
* Kallenberg, "Probabilistic Symmetries and Invariance Principles" (2005), Theorem 1.1
* Kallenberg, "Foundations of Modern Probability" (2002), Theorem 11.10
-/
open MeasureTheory ProbabilityTheory
variable {Ω α : Type*} [MeasurableSpace Ω] [MeasurableSpace α]
namespace Exchangeability
/--
A sequence of random variables is **exchangeable** if permuting finitely many indices
preserves the joint distribution.
Formally, for every `n` and every permutation `σ` of `Fin n`, the distribution of
`(X_{σ(0)}, ..., X_{σ(n-1)})` equals the distribution of `(X_0, ..., X_{n-1})`.
This is the central notion in de Finetti's theorem.
-/
def Exchangeable (μ : Measure Ω) (X : ℕ → Ω → α) : Prop :=
∀ n (σ : Equiv.Perm (Fin n)),
Measure.map (fun ω => fun i : Fin n => X (σ i) ω) μ =
Measure.map (fun ω => fun i : Fin n => X i ω) μ
/--
A sequence is **fully exchangeable** if permuting *any* indices preserves the distribution.
This is stronger than `Exchangeable` because it requires invariance under *all*
permutations of ℕ, not just finite ones. However, `Exchangeability.lean` proves
that these notions are equivalent for probability measures.
Formally, for every permutation `π : Perm ℕ`, the distribution of the reindexed
sequence `(X_{π(0)}, X_{π(1)}, ...)` equals the distribution of `(X_0, X_1, ...)`.
-/
def FullyExchangeable (μ : Measure Ω) (X : ℕ → Ω → α) : Prop :=
∀ (π : Equiv.Perm ℕ),
Measure.map (fun ω => fun i : ℕ => X (π i) ω) μ =
Measure.map (fun ω => fun i : ℕ => X i ω) μ
/--
Extend a finite permutation to a permutation of ℕ by fixing points ≥ n.
Given a permutation `σ` of `Fin n`, this produces a permutation of ℕ that acts
as σ on `{0, ..., n-1}` and fixes all `i ≥ n`.
This is used to connect full exchangeability with finite exchangeability.
-/
def extendFinPerm {n : ℕ} (σ : Equiv.Perm (Fin n)) : Equiv.Perm ℕ where
toFun i := if h : i < n then (σ ⟨i, h⟩).1 else i
invFun i := if h : i < n then (σ.symm ⟨i, h⟩).1 else i
left_inv i := by
by_cases h : i < n <;> simp [h, Fin.eta, Equiv.symm_apply_apply]
right_inv i := by
by_cases h : i < n <;> simp [h, Fin.eta, Equiv.apply_symm_apply]
/-- Exchangeability at a specific dimension n. -/
def ExchangeableAt (μ : Measure Ω) (X : ℕ → Ω → α) (n : ℕ) : Prop :=
∀ (σ : Equiv.Perm (Fin n)),
Measure.map (fun ω => fun i : Fin n => X (σ i) ω) μ =
Measure.map (fun ω => fun i : Fin n => X i ω) μ
/--
Full exchangeability implies exchangeability.
If a sequence is invariant under all permutations of ℕ, it is certainly invariant
under finite permutations. The proof uses `extendFinPerm` to view a finite
permutation as an infinite one.
-/
lemma FullyExchangeable.exchangeable {μ : Measure Ω} {X : ℕ → Ω → α}
(hX_meas : ∀ i, Measurable (X i)) (hX : FullyExchangeable μ X) : Exchangeable μ X := by
classical
intro n σ
let π := extendFinPerm σ
have hπ := hX π
let proj : (ℕ → α) → (Fin n → α) := fun f i => f i.val
have hproj_meas : Measurable proj := by fun_prop
have hmap₁ :=
Measure.map_map (μ:=μ)
(f:=fun ω => fun i : ℕ => X (π i) ω)
(g:=proj)
hproj_meas
(by fun_prop)
have hmap₂ :=
Measure.map_map (μ:=μ)
(f:=fun ω => fun i : ℕ => X i ω)
(g:=proj)
hproj_meas
(by fun_prop)
have hprojσ :
proj ∘ (fun ω => fun i : ℕ => X (π i) ω)
= fun ω => fun i : Fin n => X (σ i) ω := by
funext ω i
simp [Function.comp, proj, π, extendFinPerm, Fin.is_lt]
-- Project both laws to the first n coordinates and compare
calc Measure.map (fun ω i => X (σ i).val ω) μ
= Measure.map (proj ∘ fun ω i => X (π i) ω) μ := by rw [hprojσ]
_ = Measure.map proj (Measure.map (fun ω i => X (π i) ω) μ) := hmap₁.symm
_ = Measure.map proj (Measure.map (fun ω i => X i ω) μ) := by rw [hπ]
_ = Measure.map (proj ∘ fun ω i => X i ω) μ := hmap₂
_ = Measure.map (fun ω i => X i.val ω) μ := rfl
/-- Exchangeability is preserved under composition of permutations. -/
lemma Exchangeable.comp {μ : Measure Ω} {X : ℕ → Ω → α} {n : ℕ}
(hX : Exchangeable μ X) (σ τ : Equiv.Perm (Fin n)) :
Measure.map (fun ω i => X ((σ.trans τ) i).val ω) μ =
Measure.map (fun ω i => X i.val ω) μ :=
hX n (σ.trans τ)
/-- The identity permutation preserves the distribution (trivially). -/
lemma Exchangeable.refl {μ : Measure Ω} {X : ℕ → Ω → α} (n : ℕ) :
Measure.map (fun ω (i : Fin n) => X (Equiv.refl (Fin n) i).val ω) μ =
Measure.map (fun ω (i : Fin n) => X i.val ω) μ := by
congr
/--
A sequence is **contractable** if all strictly increasing subsequences of equal
length have the same distribution.
**Definition:** For any `m` and any strictly increasing function `k : Fin m → ℕ`,
the distribution of `(X_{k(0)}, ..., X_{k(m-1)})` equals the distribution of
`(X_0, ..., X_{m-1})`.
**Intuition:** Contractability is weaker than exchangeability. While exchangeability
requires invariance under all permutations, contractability only requires invariance
under "order-preserving selections" - we can choose any m indices as long as they
are in increasing order.
**Example:** For i.i.d. sequences, any increasing subsequence has the same
distribution as the initial segment, so contractability holds.
This is a key property in de Finetti's theorem, equivalent to both exchangeability
and conditional independence.
-/
def Contractable (μ : Measure Ω) (X : ℕ → Ω → α) : Prop :=
∀ (m : ℕ) (k : Fin m → ℕ), StrictMono k →
Measure.map (fun ω i => X (k i) ω) μ =
Measure.map (fun ω i => X i.val ω) μ
/-- Contractability is preserved under prefix: if X is contractable, so is any finite prefix. -/
lemma Contractable.prefix {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (n : ℕ) :
∀ (m : ℕ) (k : Fin m → Fin n), StrictMono k →
Measure.map (fun ω i => X (k i).val ω) μ =
Measure.map (fun ω i => X i.val ω) μ := by
intro m k hk_mono
exact hX m (fun i => (k i).val) (fun i j hij => hk_mono hij)
/-- Exchangeable at dimension n means permuting the first n indices preserves distribution. -/
lemma ExchangeableAt.apply {μ : Measure Ω} {X : ℕ → Ω → α} {n : ℕ}
(hX : ExchangeableAt μ X n) (σ : Equiv.Perm (Fin n)) :
Measure.map (fun ω i => X (σ i).val ω) μ = Measure.map (fun ω i => X i.val ω) μ :=
hX σ
/--
Contractability implies any strictly increasing subsequence matches the initial segment.
This is just a restatement of the definition for clarity.
-/
lemma Contractable.subsequence_eq {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (m : ℕ) (k : Fin m → ℕ) (hk : StrictMono k) :
Measure.map (fun ω i => X (k i) ω) μ = Measure.map (fun ω i => X i.val ω) μ :=
hX m k hk
/-- Contractability is symmetric: if (X_{k(0)}, ..., X_{k(m-1)}) has the same distribution
as the initial segment, then the converse also holds. -/
lemma Contractable.symm {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (m : ℕ) (k : Fin m → ℕ) (hk : StrictMono k) :
Measure.map (fun ω i => X i.val ω) μ = Measure.map (fun ω i => X (k i) ω) μ :=
(hX m k hk).symm
-- Re-export StrictMono utilities for backward compatibility
open Util.StrictMono (strictMono_Fin_ge_id)
/--
Any strictly increasing function can be extended to a permutation.
**Statement:** Given a strictly increasing `k : Fin m → ℕ` with all values `< n`
and `m ≤ n`, there exists a permutation `σ : Perm (Fin n)` such that
`σ(i) = k(i)` for all `i < m`.
**Intuition:** We want to build a permutation that "realizes" the selection `k`
as the image of the first `m` positions. Since `k` is strictly increasing, it's
injective, so its image has cardinality `m`. We can extend this to a full
permutation by arbitrarily pairing up the remaining elements.
**Construction:** Thin wrapper around mathlib's `Equiv.Perm.exists_extending_pair`,
applied to `f = Fin.castLE hmn` (initial-segment inclusion) and
`g i = ⟨k i, hk_bound i⟩` (strictly monotone embedding via `k`).
This is the key combinatorial lemma enabling `contractable_of_exchangeable`:
any strictly increasing subsequence can be realized via a permutation.
-/
lemma exists_perm_extending_strictMono {m n : ℕ} (k : Fin m → ℕ)
(hk_mono : StrictMono k) (hk_bound : ∀ i, k i < n) (hmn : m ≤ n) :
∃ (σ : Equiv.Perm (Fin n)), ∀ (i : Fin m),
(σ ⟨i.val, Nat.lt_of_lt_of_le i.isLt hmn⟩).val = k i := by
-- Wrap mathlib's `Equiv.Perm.exists_extending_pair`: given injective `f g : Fin m → Fin n`,
-- there is a permutation of `Fin n` sending `f` to `g`. Take `f` = initial-segment inclusion
-- and `g` = the strictly monotone embedding via `k`.
let f : Fin m → Fin n := Fin.castLE hmn
let g : Fin m → Fin n := fun i => ⟨k i, hk_bound i⟩
obtain ⟨σ, hσ⟩ := Equiv.Perm.exists_extending_pair f g (Fin.castLE_injective hmn)
(fun i j hij => hk_mono.injective (Fin.mk.inj hij))
exact ⟨σ, fun i => congrArg Fin.val (hσ i)⟩
/- Helper: relabeling coordinates by a finite permutation is measurable as a map
from (Fin n → α) to itself (with product σ-algebra). -/
/-- Contractability implies the first m variables have the same joint distribution
regardless of which m consecutive variables we pick (starting from position k). -/
lemma Contractable.shift_segment_eq {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (m k : ℕ) :
Measure.map (fun ω (i : Fin m) => X (k + i.val) ω) μ =
Measure.map (fun ω (i : Fin m) => X i.val ω) μ :=
hX m (fun i => k + i.val) (fun _ _ hij => Nat.add_lt_add_left hij k)
/-- Contractable sequences are invariant under taking strictly increasing subsequences
with offsets. -/
lemma Contractable.shift_and_select {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (m : ℕ) (k : Fin m → ℕ) (offset : ℕ) (hk : StrictMono k) :
Measure.map (fun ω i => X (offset + k i) ω) μ =
Measure.map (fun ω i => X i.val ω) μ :=
hX m (fun i => offset + k i) (fun _ _ hij => Nat.add_lt_add_left (hk hij) offset)
/-- **Marginal law equality.** For a contractable sequence, the law of any
coordinate `X i` equals the law of `X 0`.
Proof: instantiate the contractability axiom at the length-1 singleton
subsequence `{i}`, then push forward by the evaluation map `g ↦ g 0`. -/
lemma Contractable.map_single
{μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (hX_meas : ∀ i, Measurable (X i)) (i : ℕ) :
Measure.map (X i) μ = Measure.map (X 0) μ := by
have hk : StrictMono (fun _ : Fin 1 => i) := fun a b hab => by
simp_all [Fin.eq_zero a, Fin.eq_zero b]
have h_map := hX 1 (fun _ => i) hk
have e := congrArg (Measure.map (fun g : Fin 1 → α => g 0)) h_map
rwa [Measure.map_map (measurable_pi_apply 0) (by fun_prop : Measurable fun ω _ => X i ω),
Measure.map_map (measurable_pi_apply 0)
(by fun_prop : Measurable fun ω (j : Fin 1) => X j.val ω)] at e
/-- **Bivariate marginal equality.** For a contractable sequence and any pair
`i < j`, the joint law of `(X i, X j)` equals the joint law of `(X 0, X 1)`.
Proof: instantiate the contractability axiom at the two-point subsequence
`k(0) = i, k(1) = j`, then push forward by the evaluation map `g ↦ (g 0, g 1)`. -/
lemma Contractable.map_pair
{μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Contractable μ X) (hX_meas : ∀ i, Measurable (X i))
{i j : ℕ} (hij : i < j) :
Measure.map (fun ω => (X i ω, X j ω)) μ =
Measure.map (fun ω => (X 0 ω, X 1 ω)) μ := by
classical
let k : Fin 2 → ℕ := fun t => if t.val = 0 then i else j
have hk : StrictMono k := by
intro a b hab; fin_cases a <;> fin_cases b <;> simp_all [k]
have h_map := hX 2 k hk
have h_eval_meas : Measurable (fun g : Fin 2 → α => (g 0, g 1)) :=
(measurable_pi_apply 0).prodMk (measurable_pi_apply 1)
have e := congrArg (Measure.map (fun g : Fin 2 → α => (g 0, g 1))) h_map
rwa [Measure.map_map h_eval_meas
(by fun_prop : Measurable fun ω => fun t : Fin 2 => X (k t) ω),
Measure.map_map h_eval_meas
(by fun_prop : Measurable fun ω => fun t : Fin 2 => X t.val ω)] at e
/-- **Contractability is preserved under measurable postcomposition.**
If `X` is a contractable sequence and `f : α → β` is measurable, then the
sequence `fun n ω => f (X n ω)` is also contractable.
Proof: contractability says any strictly monotone reindexing leaves the joint
law unchanged. Push the equality forward through `Φ g i := f (g i)`. -/
lemma Contractable.comp
{μ : Measure Ω} {X : ℕ → Ω → α} {β : Type*} [MeasurableSpace β]
(hX : Contractable μ X) (hX_meas : ∀ i, Measurable (X i))
(f : α → β) (hf : Measurable f) :
Contractable μ (fun n ω => f (X n ω)) := by
classical
intro n k hk
have h_base := hX n k hk
have hΦ_meas : Measurable (fun g : Fin n → α => fun i => f (g i)) := by fun_prop
have e := congrArg (Measure.map (fun g : Fin n → α => fun i => f (g i))) h_base
rwa [Measure.map_map hΦ_meas
(by fun_prop : Measurable fun ω => fun i : Fin n => X (k i) ω),
Measure.map_map hΦ_meas
(by fun_prop : Measurable fun ω => fun i : Fin n => X i.val ω)] at e
/--
Helper lemma: All values of a strictly monotone function are bounded by its last value plus one.
Given `k : Fin m → ℕ` strictly monotone, all `k(i)` are less than `k(last) + 1`.
This follows from monotonicity and the fact that any `i` is at most `last`.
-/
private lemma strictMono_all_lt_succ_last {m : ℕ} (k : Fin m → ℕ) (hk : StrictMono k)
(i : Fin m) (last : Fin m) (h_last : ∀ j, j ≤ last) :
k i ≤ k last :=
hk.monotone (h_last i)
/--
Helper lemma: The length of the domain is bounded by the maximum value plus one.
For a strictly monotone function `k : Fin m → ℕ`, we have `m ≤ k(m-1) + 1`.
This uses the fact that strictly monotone functions satisfy `i ≤ k(i)` for all `i`.
-/
private lemma strictMono_length_le_max_succ {m : ℕ} (k : Fin m → ℕ) (hk : StrictMono k)
(last : Fin m) (h_last_is_max : last.val + 1 = m) :
m ≤ k last + 1 := by
calc m = last.val + 1 := h_last_is_max.symm
_ ≤ k last + 1 := Nat.add_le_add_right (strictMono_Fin_ge_id hk last) 1
/--
**Main theorem:** Every exchangeable sequence is contractable.
**Statement:** If `X` is exchangeable, then any strictly increasing subsequence
has the same distribution as the initial segment.
**Proof strategy:**
1. Given a strictly increasing `k : Fin m → ℕ`, choose `n` large enough to
contain all `k(i)` values.
2. Use `exists_perm_extending_strictMono` to construct a permutation `σ : Perm (Fin n)`
such that `σ(i) = k(i)` for `i < m`.
3. Apply exchangeability: the distributions under `σ` and the identity are equal.
4. Project both sides to the first `m` coordinates to conclude that
`(X_{k(0)}, ..., X_{k(m-1)})` has the same distribution as `(X_0, ..., X_{m-1})`.
**Mathematical significance:** This shows that exchangeability (invariance under
all finite permutations) implies contractability (invariance under increasing
selections). The converse requires ergodic theory and is much deeper.
This is one direction of de Finetti's theorem.
-/
theorem contractable_of_exchangeable {μ : Measure Ω} {X : ℕ → Ω → α}
(hX : Exchangeable μ X) (hX_meas : ∀ i, Measurable (X i)) : Contractable μ X := by
intro m k hk_mono
-- Special case: m = 0 is trivial
cases m with
| zero =>
-- Both sides map to (Fin 0 → α), which has a unique element
congr; ext ω i; exact Fin.elim0 i
| succ m' =>
-- Choose n large enough to contain all k(i): n = k(last) + 1
let last : Fin (m' + 1) := ⟨m', Nat.lt_succ_self m'⟩
let n := k last + 1
-- All k(i) < n since k is monotone and bounded by k(last)
have hk_bound : ∀ i : Fin (m' + 1), k i < n := by
intro i
have : k i ≤ k last := strictMono_all_lt_succ_last k hk_mono i last Fin.le_last
omega
-- The domain size is bounded: m ≤ n
have hmn : m' + 1 ≤ n := strictMono_length_le_max_succ k hk_mono last rfl
-- Construct permutation σ extending k to Fin n
obtain ⟨σ, hσ⟩ := exists_perm_extending_strictMono k hk_mono hk_bound hmn
-- Apply exchangeability at dimension n
have hexch := hX n σ
-- Define embedding and projection
let ι : Fin (m' + 1) → Fin n := Fin.castLE hmn
let proj : (Fin n → α) → (Fin (m' + 1) → α) := fun f i => f (ι i)
have hproj_meas : Measurable proj := by
fun_prop
-- Project both sides to the first m' + 1 coordinates
have hproj_eq : Measure.map (proj ∘ fun ω j => X (σ j).val ω) μ =
Measure.map (proj ∘ fun ω j => X j.val ω) μ := by
rw [← Measure.map_map hproj_meas (by fun_prop),
← Measure.map_map hproj_meas (by fun_prop)]
exact congrArg (Measure.map proj) hexch
-- The projected functions match our desired subsequences
have hlhs_eq : (proj ∘ fun ω j => X (σ j).val ω) = (fun ω i => X (k i) ω) := by
ext ω i
have hσi : (σ (ι i)).val = k i := by
simpa [ι] using hσ i
simp [proj, Function.comp_apply, hσi]
have hrhs_eq : (proj ∘ fun ω j => X j.val ω) = (fun ω i => X i.val ω) := rfl
rwa [hlhs_eq, hrhs_eq] at hproj_eq
end Exchangeability
Source