/- Copyright (c) 2026 Marcel Morgenstern. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Marcel Morgenstern -/ module public import ErgodicTheory.Entropy.Relative.MovingLimit public import ErgodicTheory.Entropy.Generator public import ErgodicTheory.Entropy.KolmogorovSinai.Mono public import Mathlib.Probability.Kernel.Condexp /-! # The Kolmogorov–Sinai generator theorem `h(T) = h(T, P)` This file proves the Kolmogorov–Sinai generator theorem: for a measure-preserving transformation `T` of a standard Borel probability space and a *one-sided generating* finite partition `P` (`IsGenerating μ T P`, i.e. the forward-`T`-saturated σ-algebra generated by `P` is the ambient σ-algebra `mα`), the entropy of the system is already attained on `P`: `h(T) = h(T, P)`. The proof uses the partition-level Abramov–Rokhlin identity. The theorem is proved for generators mod 0 (`IsGeneratingMod0`), which is the form relevant to the measure algebra; the literal form is a special case. ## Proof outline `le_antisymm` of two inequalities: * `h(T, P) ≤ h(T)` holds by definition (`le_ksEntropy`). * `h(T) ≤ h(T, P)`. Since `ksEntropy hT = ⨆ over finite partitions`, by `iSup_le` it reduces to `∀ m (Q : MeasurePartition μ (Fin m)), h(T, Q) ≤ h(T, P)`. For this, apply the Abramov–Rokhlin partition identity `abramovRokhlin_partition` to the refined partition `R := joinPartition Q P` over the factor `P`, conditioning on the forward saturation `𝒢 := ⨆ n σ(P-join n)` (which is forward invariant and saturated by construction): `h(R, T) = h(P, T) + h(R, T | 𝒢)`. The relative term is at most `H(R | 𝒢)`, which vanishes because every cell of `R` is measurable for the `μ`-completion of `𝒢` — this is exactly the mod-0 generating hypothesis (`condEntropy_eq_zero_of_ae_measurable`). Together with `h(Q, T) ≤ h(R, T)` (`ksEntropyPartition_le_join`) this gives `h(Q, T) ≤ h(P, T)`. ## Main results * `ErgodicTheory.Entropy.condEntropy_full_eq_zero`: `H(R | mα) = 0` for the full σ-algebra. * `ErgodicTheory.Entropy.condEntropy_eq_zero_of_ae_measurable`: `H(R | 𝒜) = 0` when every cell of `R` is measurable for the `μ`-completion of `𝒜`. * `ErgodicTheory.Entropy.ksEntropyPartition_le_of_generatingMod0`: `h(T, Q) ≤ h(T, P)` for `P` generating mod 0 and any finite partition `Q`. * `ErgodicTheory.Entropy.ksEntropy_eq_ksEntropyPartition_of_generatingMod0`: the generator theorem `h(T) = h(T, P)` for a generator mod 0, and its literal case `ksEntropy_eq_ksEntropyPartition_of_generating`. ## References * François Le Maître, *Notes on the Kolmogorov–Sinai theorem* (2017), §2. * Peter Walters, *An Introduction to Ergodic Theory*, GTM **79**, Springer (1982), Ch. 4. -/ @[expose] public section open MeasureTheory Function Filter Topology ProbabilityTheory MeasurableSpace namespace ErgodicTheory.Entropy -- The conditioning σ-algebra `𝒜` is declared before the ambient `mα`, so that instance resolution -- picks `mα` for `Measure α`, `MeasurePartition μ ι` and `StandardBorelSpace α`. variable {α : Type*} {ι : Type*} {𝒜 : MeasurableSpace α} [mα : MeasurableSpace α] [StandardBorelSpace α] [Fintype ι] /-- **The conditional Shannon entropy against the full σ-algebra vanishes.** `condEntropy μ mα R.cells = 0` for any finite measurable partition `R`. A measurable function is its own conditional expectation with respect to the full σ-algebra `mα` (`condExp_of_stronglyMeasurable` with `hm = le_rfl`). Hence for each cell the regular-conditional kernel mass `(condExpKernel μ mα ω).real (R.cells i)` equals the indicator `𝟙_{R.cells i} ω` `μ`-a.e. (`condExpKernel_ae_eq_condExp`), which is `0` or `1`; the Shannon term `negMulLog` is then `negMulLog 0 = 0` or `negMulLog 1 = 0`. The whole integrand vanishes `μ`-a.e., so the integral is `0`. -/ lemma condEntropy_full_eq_zero {μ : Measure α} [IsProbabilityMeasure μ] (R : MeasurePartition μ ι) : condEntropy μ mα R.cells = 0 := by have hσ : SigmaFinite (μ.trim (le_refl mα)) := by rw [trim_eq_self]; infer_instance rw [condEntropy_def] -- The integrand is `μ`-a.e. zero. refine integral_eq_zero_of_ae ?_ -- For each cell `i`, the kernel mass equals the indicator `μ`-a.e. have hcell : ∀ i : ι, (fun ω => (@condExpKernel α mα _ μ _ mα ω (R.cells i)).toReal) =ᵐ[μ] (R.cells i).indicator (fun _ => (1 : ℝ)) := by intro i -- `(condExpKernel μ mα ω).real (R.cells i) =ᵐ μ⟦R.cells i | mα⟧`. have h1 : (fun ω => (@condExpKernel α mα _ μ _ mα ω (R.cells i)).toReal) =ᵐ[μ] μ⟦R.cells i | mα⟧ := condExpKernel_ae_eq_condExp le_rfl (R.measurable i) -- `μ⟦R.cells i | mα⟧ = 𝟙_{R.cells i}` (a measurable function is its own conditional -- expectation w.r.t. the full σ-algebra). have h2 : μ⟦R.cells i | mα⟧ = (R.cells i).indicator (fun _ => (1 : ℝ)) := condExp_of_stronglyMeasurable le_rfl ((stronglyMeasurable_const.indicator (R.measurable i))) ((integrable_const (1 : ℝ)).indicator (R.measurable i)) rw [h2] at h1 exact h1 -- The pointwise sum of `negMulLog` of `{0, 1}`-valued indicators is `0`, `μ`-a.e. filter_upwards [ae_all_iff.mpr hcell] with ω hω refine Finset.sum_eq_zero fun i _ => ?_ rw [hω i] -- `negMulLog` of an indicator value (`0` or `1`) is `0`. by_cases hmem : ω ∈ R.cells i · rw [Set.indicator_of_mem hmem, Real.negMulLog_one] · rw [Set.indicator_of_notMem hmem, Real.negMulLog_zero] omit [StandardBorelSpace α] in /-- **Structural refinement of the `(Q ∨ P)`-join over the `P`-join.** Each cell of the `n`-fold join of `joinPartition Q P` is contained in the `n`-fold join cell of `P` indexed by the second-coordinate projection: with `g n f := fun k => (f k).2`, `(ksJoin hT (joinPartition Q P) n).cells f ⊆ (ksJoin hT P n).cells (g n f)`. Each `(Q ∨ P)`-join cell is `⋂ₖ T⁻ᵏ(Q_{(f k).1} ∩ P_{(f k).2})`, contained in `⋂ₖ T⁻ᵏ(P_{(f k).2})`, the `P`-join cell at `k ↦ (f k).2`. -/ lemma ksJoin_joinPartition_subset {κ : Type*} [Fintype κ] {μ : Measure α} {T : α → α} (hT : MeasurePreserving T μ μ) (Q : MeasurePartition μ κ) (P : MeasurePartition μ ι) (n : ℕ) (f : Fin n → κ × ι) : (ksJoin hT (joinPartition Q P) n).cells f ⊆ (ksJoin hT P n).cells (fun k => (f k).2) := by rw [ksJoin_cells, ksJoin_cells, ksJoinCells_apply, ksJoinCells_apply] refine Set.iInter_mono fun k => ?_ -- `T⁻ᵏ((Q ∨ P)_{f k}) = T⁻ᵏ(Q_{(f k).1} ∩ P_{(f k).2}) ⊆ T⁻ᵏ(P_{(f k).2})`. rw [joinPartition_cells, joinCells_apply] exact Set.preimage_mono Set.inter_subset_right /-- **Conditional entropy of a partition measured mod 0 by the conditioning σ-algebra vanishes.** If every cell of `R` agrees `μ`-a.e. with an `𝒜`-measurable set (i.e. is measurable for the `μ`-completion of `𝒜`), then `condEntropy μ 𝒜 R.cells = 0`: the conditional cell probability `μ⟦Rᵢ | 𝒜⟧` is a.e. the indicator of `Rᵢ`, so every `negMulLog` term vanishes a.e. -/ lemma condEntropy_eq_zero_of_ae_measurable {μ : Measure α} [IsProbabilityMeasure μ] (h𝒜 : 𝒜 ≤ mα) (R : MeasurePartition μ ι) (hR : ∀ i, MeasurableSet[eventuallyMeasurableSpace 𝒜 (ae μ)] (R.cells i)) : condEntropy μ 𝒜 R.cells = 0 := by have : SigmaFinite (μ.trim h𝒜) := inferInstance rw [condEntropy_def] refine integral_eq_zero_of_ae ?_ have hcell : ∀ i : ι, (fun ω => (@condExpKernel α mα _ μ _ 𝒜 ω (R.cells i)).toReal) =ᵐ[μ] (R.cells i).indicator (fun _ => (1 : ℝ)) := by intro i obtain ⟨S, hS, hRS⟩ := hR i have h1 : (fun ω => (@condExpKernel α mα _ μ _ 𝒜 ω (R.cells i)).toReal) =ᵐ[μ] μ⟦R.cells i | 𝒜⟧ := condExpKernel_ae_eq_condExp h𝒜 (R.measurable i) have hind : (R.cells i).indicator (fun _ => (1 : ℝ)) =ᵐ[μ] S.indicator (fun _ => (1 : ℝ)) := indicator_ae_eq_of_ae_eq_set hRS have h2 : μ⟦R.cells i | 𝒜⟧ =ᵐ[μ] μ⟦S | 𝒜⟧ := condExp_congr_ae hind have hfm : StronglyMeasurable[𝒜] (S.indicator (fun _ => (1 : ℝ))) := stronglyMeasurable_const.indicator hS have hfi : Integrable (S.indicator (fun _ => (1 : ℝ))) μ := (integrable_const (1 : ℝ)).indicator (h𝒜 _ hS) have h3 : μ⟦S | 𝒜⟧ = S.indicator (fun _ => (1 : ℝ)) := condExp_of_stronglyMeasurable h𝒜 hfm hfi rw [h3] at h2 exact h1.trans (h2.trans hind.symm) filter_upwards [ae_all_iff.mpr hcell] with ω hω refine Finset.sum_eq_zero fun i _ => ?_ rw [hω i] by_cases hmem : ω ∈ R.cells i · rw [Set.indicator_of_mem hmem, Real.negMulLog_one] · rw [Set.indicator_of_notMem hmem, Real.negMulLog_zero] omit [StandardBorelSpace α] in /-- The forward saturation `⨆ k, σ(⋁ₖ T⁻ʲ P)` of the iterated joins of `P` is forward-`T`-invariant: `comap T (⨆ k, σ(P-join k)) ≤ ⨆ k, σ(P-join k)`. Through `iSup_generatedSigmaAlgebra_ksJoin_eq` it is `⨆ k, comap (T^[k]) σ(P)`, and pulling back by `T` shifts the index `k ↦ k + 1`. -/ lemma comap_iSup_generatedSigmaAlgebra_ksJoin_le {μ : Measure α} {T : α → α} (hT : MeasurePreserving T μ μ) (P : MeasurePartition μ ι) : MeasurableSpace.comap T (⨆ k, generatedSigmaAlgebra μ (ksJoin hT P k)) ≤ ⨆ k, generatedSigmaAlgebra μ (ksJoin hT P k) := by rw [iSup_generatedSigmaAlgebra_ksJoin_eq hT P, MeasurableSpace.comap_iSup] refine iSup_le fun k => ?_ have hcomp : T^[k] ∘ T = T^[k + 1] := (Function.iterate_succ T k).symm rw [MeasurableSpace.comap_comp, hcomp] exact le_iSup (fun k => MeasurableSpace.comap (T^[k]) (generatedSigmaAlgebra μ P)) (k + 1) /-- **The generator inequality, mod 0.** For a partition `P` generating mod 0 and *any* finite partition `Q`, `h(T, Q) ≤ h(T, P)`. Work with the join `R := joinPartition Q P` and the forward saturation `𝒢 := ⨆ k, σ(⋁ⱼ₌₀ᵏ⁻¹ T⁻ʲ P)`, which is forward-`T`-invariant. Monotonicity under refinement gives `h(Q, T) ≤ h(R, T)` (`ksEntropyPartition_le_join`). The Abramov–Rokhlin partition identity `abramovRokhlin_partition`, applied to `R` over the factor `P` and conditioning on `𝒢` (saturated by construction), splits `h(R, T) = h(P, T) + h(R, T | 𝒢)`. The relative term is at most `H(R | 𝒢)`, which vanishes because every cell of `R` is measurable for the `μ`-completion of `𝒢` (this is the mod-0 generating hypothesis; `condEntropy_eq_zero_of_ae_measurable`). -/ lemma ksEntropyPartition_le_of_generatingMod0 {μ : Measure α} [IsProbabilityMeasure μ] {T : α → α} (hT : MeasurePreserving T μ μ) {n : ℕ} (P : MeasurePartition μ (Fin n)) (hgen : IsGeneratingMod0 μ T P) {m : ℕ} (Q : MeasurePartition μ (Fin m)) : ksEntropyPartition hT Q ≤ ksEntropyPartition hT P := by set R : MeasurePartition μ (Fin m × Fin n) := joinPartition Q P with hR have hne : Nonempty (Fin m × Fin n) := R.index_nonempty have hm : (⨆ k, generatedSigmaAlgebra μ (ksJoin hT P k)) ≤ mα := iSup_le fun k => generatedSigmaAlgebra_le _ have hinv := comap_iSup_generatedSigmaAlgebra_ksJoin_le hT P have hrefine : ∀ k (f : Fin k → Fin m × Fin n), (ksJoin hT R k).cells f ≤ᵐ[μ] (ksJoin hT P k).cells (fun j => (f j).2) := by intro k f exact LE.le.eventuallySubset (hR ▸ ksJoin_joinPartition_subset hT Q P k f) have hAR := abramovRokhlin_partition hm hT hinv P R (fun _ f j => (f j).2) hrefine rfl -- Every cell of `R` is measurable for the completion of the saturation. have hgen' : mα ≤ eventuallyMeasurableSpace (⨆ k, generatedSigmaAlgebra μ (ksJoin hT P k)) (ae μ) := by rw [iSup_generatedSigmaAlgebra_ksJoin_eq hT P]; exact hgen have hzero : condEntropy μ (⨆ k, generatedSigmaAlgebra μ (ksJoin hT P k)) R.cells = 0 := condEntropy_eq_zero_of_ae_measurable hm R fun i => hgen' _ (R.measurable i) have hrel_le := condKsEntropyPartition_le_condEntropy hm hT hinv R rw [hzero] at hrel_le have hrel : condKsEntropyPartition hm hT hinv R = 0 := le_antisymm hrel_le (condKsEntropyPartition_nonneg hm hT hinv R) calc ksEntropyPartition hT Q ≤ ksEntropyPartition hT R := ksEntropyPartition_le_join hT Q P _ = ksEntropyPartition hT P := by rw [hAR, hrel, add_zero] /-- **The generator inequality.** For a generating partition `P` and *any* finite partition `Q`, `h(T, Q) ≤ h(T, P)`; the literal case of `ksEntropyPartition_le_of_generatingMod0`. -/ lemma ksEntropyPartition_le_of_generating {μ : Measure α} [IsProbabilityMeasure μ] {T : α → α} (hT : MeasurePreserving T μ μ) {n : ℕ} (P : MeasurePartition μ (Fin n)) (hgen : IsGenerating μ T P) {m : ℕ} (Q : MeasurePartition μ (Fin m)) : ksEntropyPartition hT Q ≤ ksEntropyPartition hT P := ksEntropyPartition_le_of_generatingMod0 hT P hgen.isGeneratingMod0 Q /-- **The Kolmogorov–Sinai generator theorem, mod 0.** For a finite partition `P` of a standard Borel probability space that generates mod 0 (`IsGeneratingMod0 μ T P`: every measurable set agrees `μ`-a.e. with a set determined by the forward `P`-itinerary), the Kolmogorov–Sinai entropy of the system equals the partition-relative entropy of `P`: `h(T) = h(T, P)`. `le_antisymm` of the bound `h(T, P) ≤ h(T)` (`le_ksEntropy`) and the reverse, which unfolds the supremum defining `ksEntropy` and reduces by `iSup_le` to `ksEntropyPartition_le_of_generatingMod0`. No ergodicity is needed. -/ theorem ksEntropy_eq_ksEntropyPartition_of_generatingMod0 {μ : Measure α} [IsProbabilityMeasure μ] {T : α → α} (hT : MeasurePreserving T μ μ) {n : ℕ} (P : MeasurePartition μ (Fin n)) (hgen : IsGeneratingMod0 μ T P) : ksEntropy hT = ((ksEntropyPartition hT P : ℝ) : EReal) := by refine le_antisymm ?_ (le_ksEntropy hT P) refine iSup_le fun m => iSup_le fun Q => ?_ rw [EReal.coe_le_coe_iff] exact ksEntropyPartition_le_of_generatingMod0 hT P hgen Q /-- **The Kolmogorov–Sinai generator theorem**: for a one-sided generating finite partition `P` of a standard Borel probability space, `h(T) = h(T, P)`. This is the literal case of `ksEntropy_eq_ksEntropyPartition_of_generatingMod0`. -/ theorem ksEntropy_eq_ksEntropyPartition_of_generating {μ : Measure α} [IsProbabilityMeasure μ] {T : α → α} (hT : MeasurePreserving T μ μ) {n : ℕ} (P : MeasurePartition μ (Fin n)) (hgen : IsGenerating μ T P) : ksEntropy hT = ((ksEntropyPartition hT P : ℝ) : EReal) := ksEntropy_eq_ksEntropyPartition_of_generatingMod0 hT P hgen.isGeneratingMod0 end ErgodicTheory.Entropy