/- 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.Krieger.Coding.Estimates public import ErgodicTheory.Krieger.Coding.EntropyBookkeeping /-! # The coding step and Krieger's finite generator theorem Fix a stage `(c₀, F₀)`, a code `q : α → Fin n`, the pair code `p = (q, m₀)` with the marked code `m₀ = markedCode c₀ F₀`, and a coding setup (`CodingSetup`): a tower base `B` of height `N` whose points have `p`-cylinders of measure at least `a`, a bound `K` on the number of such names with a given `m₀`-name, an injective encoding `enc` of (offset, name index) pairs into `D` digits, and a slot bound `J > D` with every slot `j < J` inside every column. The column data of a base `b` is the encoding of the offset of its marker and of the index of its `p`-name among the names of measure at least `a` with the same `m₀`-name. The stage code of `ErgodicTheory.Krieger.Coding.StageCode` with these data gives (`codingSetup_spec`): * a measurable code `c = c₀` off `F₀` and a measurable free set `F ⊆ F₀`, robustly decodable; * `μ(F) ≥ (J - D) μ(B)`; * for every code agreeing with `c` off `F`, a function measurable for its two-sided itinerary that equals `q` on the tower over `B`, up to a null set. `exists_codingSetup` chooses the parameters (marker length `r`, tolerance `η`, height `N`, name bound `K`, digit count `D`, slot bound `J`) so that the capacity used and the error are as small as required. This proves `krieger_coding_step`, hence `krieger_stage_lemma`, and Krieger's finite generator theorem `krieger_finite_generator`. ## Main results * `ErgodicTheory.Krieger.krieger_coding_step`, `ErgodicTheory.Krieger.krieger_stage_lemma`. * `ErgodicTheory.Krieger.krieger_finite_generator`: an ergodic aperiodic measure-preserving automorphism of a standard Borel probability space with `h(e) < log k` has a two-sided generator with `k` cells, mod 0. -/ @[expose] public section open MeasureTheory Function Set Filter MeasurableSpace open scoped ENNReal namespace ErgodicTheory.Krieger open ErgodicTheory.Entropy variable {α : Type*} [MeasurableSpace α] {μ : Measure α} {k n : ℕ} /-- The `m₀`-component of a name of the pair code. -/ def mOf {N : ℕ} (w : Fin N → Fin (n * (k + 1))) : Fin N → Fin (k + 1) := fun i => (finProdFinEquiv.symm (w i)).2 /-- A coding setup for the stage `(c₀, F₀)` and the code `q`. -/ structure CodingSetup (μ : Measure α) (e : α ≃ᵐ α) (k : ℕ) (c₀ : α → Fin k) (F₀ : Set α) (q : α → Fin n) where /-- The block length (height of the Rokhlin tower). -/ N : ℕ /-- The slot spacing of the marker positions. -/ r : ℕ /-- The length of the code words. -/ D : ℕ /-- The bound on the number of typical names per marker pattern. -/ K : ℕ /-- The number of available slots in each block. -/ J : ℕ /-- The typicality threshold on the measure of a name. -/ a : ℝ /-- The base of the Rokhlin tower. -/ B : Set α hk : 2 ≤ k hn : 0 < n hN : 0 < N hK : 0 < K hr : 2 ≤ r hB : MeasurableSet B htower : TowerDisjoint e B N /-- The injective encoding of (position, name index) pairs by code words. -/ enc : Fin N × Fin K ↪ (Fin D → Fin k) htyp : ∀ b ∈ B, a ≤ (μ {y | blockName e (pairCode q (markedCode c₀ F₀)) N y = blockName e (pairCode q (markedCode c₀ F₀)) N b}).toReal hcard : ∀ b ∈ B, ((Finset.univ.filter fun w : Fin N → Fin (n * (k + 1)) => a ≤ (μ {y | blockName e (pairCode q (markedCode c₀ F₀)) N y = w}).toReal ∧ mOf w = mOf (blockName e (pairCode q (markedCode c₀ F₀)) N b)).card ≤ K) hJ : ∀ b ∈ B, ∀ j < J, slotPos r j < cnt (actWord e F₀ b) 0 N hDJ : D < J namespace CodingSetup variable {e : α ≃ᵐ α} {c₀ : α → Fin k} {F₀ : Set α} {q : α → Fin n} (S : CodingSetup μ e k c₀ F₀ q) /-- The pair code. -/ noncomputable def p (_S : CodingSetup μ e k c₀ F₀ q) : α → Fin (n * (k + 1)) := pairCode q (markedCode c₀ F₀) /-- The symbol `0`. -/ def z : Fin k := ⟨0, by have := S.hk; omega⟩ /-- The marker symbol `1`. -/ def o : Fin k := ⟨1, by have := S.hk; omega⟩ lemma o_ne_z : S.o ≠ S.z := by simp [o, z, Fin.ext_iff] open Classical in /-- The names of measure at least `a` with a given `m₀`-name. -/ noncomputable def W (m : Fin S.N → Fin (k + 1)) : Finset (Fin S.N → Fin (n * (k + 1))) := Finset.univ.filter fun w => S.a ≤ (μ {y | blockName e S.p S.N y = w}).toReal ∧ mOf w = m /-- The `p`-name of `b`. -/ noncomputable def pName (b : α) : Fin S.N → Fin (n * (k + 1)) := blockName e S.p S.N b open Classical in /-- The index of the `p`-name of `b` among the typical names with its `m₀`-name; `0` (a default value) if the name is not typical. -/ noncomputable def idxOf (b : α) : ℕ := if h : S.pName b ∈ S.W (mOf (S.pName b)) then ((S.W (mOf (S.pName b))).equivFin ⟨_, h⟩ : ℕ) else 0 open Classical in /-- Decoding a name from its `m₀`-name and its index; the constant name `0` (a default value) if the index is out of range. -/ noncomputable def nameDec (m : Fin S.N → Fin (k + 1)) (j : ℕ) : Fin S.N → Fin (n * (k + 1)) := if h : j < (S.W m).card then ((S.W m).equivFin.symm ⟨j, h⟩ : Fin S.N → Fin (n * (k + 1))) else fun _ => ⟨0, Nat.mul_pos S.hn (Nat.succ_pos k)⟩ /-- The offset of the marker of the column over `b`. -/ noncomputable def offsetOf (b : α) : ℕ := (vpos S.N (actWord e F₀ b) 0 1).toNat open Classical in /-- The column data: the code word of (marker offset, name index), and the constant word `z` (a default value) if either is out of range. -/ noncomputable def dataOf (b : α) : Fin S.D → Fin k := if h : S.offsetOf b < S.N ∧ S.idxOf b < S.K then S.enc (⟨S.offsetOf b, h.1⟩, ⟨S.idxOf b, h.2⟩) else fun _ => S.z /-- Decoding the column data: the left inverse `Function.invFun` of the injective encoding `S.enc`; its value off the range of `S.enc` is unspecified and never used. -/ noncomputable def decPair (d : Fin S.D → Fin k) : ℕ × ℕ := haveI : Nonempty (Fin S.N × Fin S.K) := ⟨(⟨0, S.hN⟩, ⟨0, S.hK⟩)⟩ ((Function.invFun S.enc d).1, (Function.invFun S.enc d).2) /-- The stage code. -/ noncomputable def code : α → Fin k := stageCode e F₀ S.B c₀ S.N S.r S.D S.z S.o S.dataOf /-- The new free set. -/ def free : Set α := stageFree e F₀ S.B S.N S.r S.D lemma nameDec_idxOf {b : α} (hb : b ∈ S.B) : S.nameDec (mOf (S.pName b)) (S.idxOf b) = S.pName b := by classical have hmem : S.pName b ∈ S.W (mOf (S.pName b)) := by simp only [W, Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨S.htyp b hb, trivial⟩ unfold nameDec idxOf rw [dite_eq_left hmem, dite_eq_left (Fin.is_lt _)] simp lemma idxOf_lt {b : α} (hb : b ∈ S.B) : S.idxOf b < S.K := by classical have hmem : S.pName b ∈ S.W (mOf (S.pName b)) := by simp only [W, Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨S.htyp b hb, trivial⟩ unfold idxOf rw [dite_eq_left hmem] exact lt_of_lt_of_le (Fin.is_lt _) (S.hcard b hb) lemma marker_exists {b : α} (hb : b ∈ S.B) : ∃ u : ℤ, 0 ≤ u ∧ u < S.N ∧ actWord e F₀ b u = true ∧ cnt (actWord e F₀ b) 0 u = 1 := by have h := S.hJ b hb 0 (by have := S.hDJ; omega) have h2 := slotPos_ge S.hr 0 obtain ⟨u, h1, h3, h4, h5⟩ := exists_cnt_eq (s := actWord e F₀ b) (a := 0) S.N (v := 1) (by simp only [zero_add]; omega) exact ⟨u, h1, by simpa using h3, h4, h5⟩ lemma offsetOf_eq {b : α} {u : ℤ} (hu0 : 0 ≤ u) (huN : u < S.N) (hs : actWord e F₀ b u = true) (hc : cnt (actWord e F₀ b) 0 u = 1) : (S.offsetOf b : ℤ) = u := by unfold offsetOf rw [vpos_spec S.N hu0 (by simpa using huN) hs hc, Int.toNat_of_nonneg hu0] lemma decPair_dataOf {b : α} (hb : b ∈ S.B) : S.decPair (S.dataOf b) = (S.offsetOf b, S.idxOf b) := by classical obtain ⟨u, hu0, huN, hs, hc⟩ := S.marker_exists hb have hoff : S.offsetOf b < S.N := by have := S.offsetOf_eq hu0 huN hs hc; omega have h : S.offsetOf b < S.N ∧ S.idxOf b < S.K := ⟨hoff, S.idxOf_lt hb⟩ have : Nonempty (Fin S.N × Fin S.K) := ⟨(⟨0, S.hN⟩, ⟨0, S.hK⟩)⟩ unfold decPair dataOf rw [dite_eq_left h, Function.leftInverse_invFun S.enc.injective] lemma hroom : ∀ b ∈ S.B, slotPos S.r S.D ≤ cnt (actWord e F₀ b) 0 S.N := fun b hb => (S.hJ b hb S.D S.hDJ).le lemma offsetData (x : α) : OffsetData S.N S.decPair (actWord e F₀ x) {t | ziter e t x ∈ S.B} (fun t => S.dataOf (ziter e t x)) := by intro t ht u htu huN hs hc rw [Set.mem_ofPred_eq] at ht rw [S.decPair_dataOf ht] refine S.offsetOf_eq (by omega) (by omega) ?_ ?_ · rw [actWord_ziter]; simpa using hs · rw [cnt_actWord_ziter]; simpa using hc lemma columnWord {c' : α → Fin k} (hc' : ∀ y ∉ S.free, c' y = S.code y) (x : α) : ColumnWord S.N S.r S.D S.z S.o (actWord e F₀ x) (symWord e c' x) {t | ziter e t x ∈ S.B} (fun t => S.dataOf (ziter e t x)) := columnWord_of_agree (c₀ := c₀) S.htower S.hroom hc' x lemma code_of_not_mem {y : α} (hy : y ∉ F₀) : S.code y = c₀ y := by simp [code, stageCode, hy] lemma free_subset : S.free ⊆ F₀ := fun _ hy => hy.1 /-- **The free set is decoded exactly.** -/ lemma mem_free_iff {c' : α → Fin k} (hc' : ∀ y ∉ S.free, c' y = S.code y) (x : α) : x ∈ S.free ↔ freeDec S.N S.r S.D S.o S.decPair (actWord e F₀ x) (symWord e c' x) := by classical rw [freeDec_iff S.hr S.o_ne_z (S.columnWord hc' x) (S.offsetData x)] have hs0 : actWord e F₀ x 0 = true ↔ x ∈ F₀ := by simp [actWord] constructor · rintro ⟨hxF, j, hj, hrole⟩ have hT : InTower e S.B S.N x := by by_contra hT rw [not_inTower hT] at hrole cases hrole obtain ⟨i, hi, hxi⟩ := hT obtain ⟨hr1, -⟩ := roleAt_ziter (F₀ := F₀) (r := S.r) (x := x) S.htower hxi (j := 0) (by omega) (by omega) simp only [ziter_zero, id_eq] at hr1 refine ⟨hs0.mpr hxF, -(i : ℤ), hxi, by omega, by omega, j, hj, ?_⟩ rw [← hr1]; exact hrole · rintro ⟨hs, t, ht, ht0, htN, j, hj, hrole⟩ obtain ⟨hr1, -⟩ := roleAt_ziter (F₀ := F₀) (r := S.r) (x := x) S.htower ht (j := 0) ht0 htN simp only [ziter_zero, id_eq] at hr1 exact ⟨hs0.mp hs, j, hj, hr1.trans hrole⟩ /-- The `m₀`-name read off a word from position `b`. -/ def mWord (s : ℤ → Bool) (w : ℤ → Fin k) (b : ℤ) : Fin S.N → Fin (k + 1) := fun i => if s (b + i) = true then Fin.last k else (w (b + i)).castSucc /-- **The decoder of `q`** on words. -/ noncomputable def qWordDec (s : ℤ → Bool) (w : ℤ → Fin k) : Fin n := match payloadDec S.N S.r S.D S.o S.decPair s w with | some (b, j) => if h : 0 ≤ -b ∧ -b < S.N then (finProdFinEquiv.symm (S.nameDec (S.mWord s w b) j ⟨(-b).toNat, by omega⟩)).1 else ⟨0, S.hn⟩ | none => ⟨0, S.hn⟩ lemma qWordDec_congr {s s' : ℤ → Bool} {w w' : ℤ → Fin k} (h : AgreeOn s s' w w' (-(2 * S.N : ℤ)) (2 * S.N)) : S.qWordDec s w = S.qWordDec s' w' := by unfold qWordDec rw [payloadDec_congr S.hN h] rcases payloadDec S.N S.r S.D S.o S.decPair s' w' with _ | ⟨b, j⟩ · rfl · simp only split_ifs with hb · have : S.mWord s w b = S.mWord s' w' b := by funext i have := h (b + i) (by omega) (by omega) simp only [mWord, this.1, this.2] rw [this] · rfl /-- **The decoder recovers `q` on the tower.** -/ lemma qWordDec_eq {c' : α → Fin k} (hc' : ∀ y ∉ S.free, c' y = S.code y) {x : α} {i : ℕ} (hi : i < S.N) (hxi : ziter e (-(i : ℤ)) x ∈ S.B) : S.qWordDec (actWord e F₀ x) (symWord e c' x) = q x := by classical set β := ziter e (-(i : ℤ)) x with hβ have hpay := payloadDec_eq_some S.hr S.o_ne_z (S.columnWord hc' x) (S.offsetData x) (b := -(i : ℤ)) hxi (by omega) (by omega) rw [S.decPair_dataOf hxi] at hpay have hiter : ∀ l : ℕ, ziter e (-(i : ℤ) + l) x = (e : α → α)^[l] β := by intro l rw [hβ, ← ziter_natCast, ziter_ziter, add_comm] have hm : S.mWord (actWord e F₀ x) (symWord e c' x) (-(i : ℤ)) = mOf (S.pName β) := by funext l simp only [mWord, mOf, pName, blockName, p, pairCode, Equiv.symm_apply_apply, actWord, symWord, hiter] by_cases hF : (e : α → α)^[l] β ∈ F₀ · simp [hF, markedCode] · have hnf : (e : α → α)^[l] β ∉ S.free := fun h => hF (S.free_subset h) simp [hF, markedCode, hc' _ hnf, S.code_of_not_mem hF] unfold qWordDec rw [hpay] simp only rw [dite_eq_left (show 0 ≤ -(-(i : ℤ)) ∧ -(-(i : ℤ)) < S.N by omega), hm, S.nameDec_idxOf hxi] simp only [pName, blockName, p, pairCode, Equiv.symm_apply_apply] congr 2 rw [← ziter_natCast, hβ, ziter_ziter] simp lemma measurable_p (hF₀ : MeasurableSet F₀) (hc₀ : Measurable c₀) (hq : Measurable q) : Measurable S.p := measurable_pairCode hq (measurable_markedCode hc₀ hF₀) lemma measurable_offsetOf (hF₀ : MeasurableSet F₀) : Measurable S.offsetOf := by have hw : Measurable fun s : ℤ → Bool => (vpos S.N s 0 1).toNat := measurable_of_window S.N fun s s' h => by rw [vpos_congr (N := S.N) 1 fun j hj1 hj2 => h j (by omega) (by omega)] exact hw.comp (measurable_actWord e hF₀) open Classical in lemma measurable_dataOf (hF₀ : MeasurableSet F₀) (hc₀ : Measurable c₀) (hq : Measurable q) : Measurable S.dataOf := by let idx' : (Fin S.N → Fin (n * (k + 1))) → ℕ := fun w => if h : w ∈ S.W (mOf w) then ((S.W (mOf w)).equivFin ⟨w, h⟩ : ℕ) else 0 let ψ : ℕ × (Fin S.N → Fin (n * (k + 1))) → (Fin S.D → Fin k) := fun pr => if h : pr.1 < S.N ∧ idx' pr.2 < S.K then S.enc (⟨pr.1, h.1⟩, ⟨idx' pr.2, h.2⟩) else fun _ => S.z have : S.dataOf = ψ ∘ fun b => (S.offsetOf b, S.pName b) := rfl rw [this] exact (measurable_of_countable ψ).comp ((S.measurable_offsetOf hF₀).prodMk (measurable_blockName e (S.measurable_p hF₀ hc₀ hq) S.N)) lemma agree_off_F₀ {c' : α → Fin k} (hc' : ∀ y ∉ S.free, c' y = S.code y) : ∀ y ∉ F₀, c' y = c₀ y := fun y hy => (hc' y fun h => hy (S.free_subset h)).trans (S.code_of_not_mem hy) /-- **Properties of the stage code of a coding setup.** -/ theorem spec (he : MeasurePreserving (e : α → α) μ μ) (hF₀ : MeasurableSet F₀) (hc₀ : Measurable c₀) (hq : Measurable q) (hdec : RobustlyDecodes e μ c₀ F₀) : Measurable S.code ∧ MeasurableSet S.free ∧ RobustlyDecodes e μ S.code S.free ∧ ∀ (c' : α → Fin k) (hc' : Measurable c'), (∀ x ∉ S.free, c' x = S.code x) → ∃ q' : α → Fin n, Measurable[twoSidedSat e (codePartition (μ := μ) c' hc')] q' ∧ μ {x | q' x ≠ q x} ≤ μ {x | ∃ i : ℕ, i < S.N ∧ ziter e (-(i : ℤ)) x ∈ S.B}ᶜ := by classical have : NeZero k := ⟨by have := S.hk; omega⟩ have hwin : ∀ ω ω' : ℤ → Bool × Fin k, (∀ j, -((2 * S.N : ℕ) : ℤ) ≤ j → j < ((2 * S.N : ℕ) : ℤ) → ω j = ω' j) → AgreeOn (fun j => (ω j).1) (fun j => (ω' j).1) (fun j => (ω j).2) (fun j => (ω' j).2) (-(2 * S.N : ℤ)) (2 * S.N) := by intro ω ω' h j hj1 hj2 have := h j (by push_cast; omega) (by push_cast; omega) exact ⟨congrArg Prod.fst this, congrArg Prod.snd this⟩ refine ⟨measurable_stageCode hF₀ S.hB hc₀ (S.measurable_dataOf hF₀ hc₀ hq), measurableSet_stageFree hF₀ S.hB, ?_, ?_⟩ · intro c' hc' hag have hmeas := measurable_completion_of_window (μ := μ) he hdec hc' (S.agree_off_F₀ hag) (2 * S.N) (f := fun ω => decide (freeDec S.N S.r S.D S.o S.decPair (fun j => (ω j).1) (fun j => (ω j).2))) (fun ω ω' h => by rw [freeDec_congr S.hN (hwin ω ω' h)]) convert hmeas (measurableSet_singleton true) using 1 ext x simp only [Set.mem_preimage, Set.mem_singleton_iff, decide_eq_true_eq] exact S.mem_free_iff hag x · intro c' hc' hag have hmeas := measurable_completion_of_window (μ := μ) he hdec hc' (S.agree_off_F₀ hag) (2 * S.N) (f := fun ω => S.qWordDec (fun j => (ω j).1) (fun j => (ω j).2)) (fun ω ω' h => S.qWordDec_congr (hwin ω ω' h)) obtain ⟨q', hq', hae⟩ := exists_measurable_ae_eq_of_completion ⟨0, S.hn⟩ hmeas refine ⟨q', hq', measure_mono_ae ?_⟩ filter_upwards [hae] with x hx hxq simp only [Set.mem_compl_iff, Set.mem_ofPred_eq] rintro ⟨i, hi, hxi⟩ exact hxq (hx.trans (S.qWordDec_eq hag hi hxi)) end CodingSetup /-! ### Choice of the parameters -/ /-- Real bound on a natural division. -/ lemma natCast_div_ge (X r : ℕ) (hr : 0 < r) : (X : ℝ) / r - 1 ≤ ((X / r : ℕ) : ℝ) := by have h1 : X < (X / r + 1) * r := by have := Nat.lt_div_mul_add (a := X) hr nlinarith [Nat.div_add_mod X r, Nat.mod_lt X hr] have hr' : (0 : ℝ) < r := by exact_mod_cast hr rw [div_sub_one hr'.ne', div_le_iff₀ hr'] have : (X : ℝ) < ((X / r : ℕ) + 1) * r := by exact_mod_cast h1 linarith /-- Upper bound on `Nat.clog`. -/ lemma clog_le_real {k x : ℕ} (hk : 1 < k) (hx : 1 ≤ x) : (Nat.clog k x : ℝ) ≤ 1 + Real.log x / Real.log k := by have hL : 0 < Real.log k := Real.log_pos (by exact_mod_cast hk) rcases hx.eq_or_lt with rfl | hx1 · rw [Nat.clog_of_right_le_one le_rfl]; simp · have h := Nat.pow_pred_clog_lt_self k hx1 have h' : ((k : ℝ)) ^ (Nat.clog k x).pred < x := by exact_mod_cast h have hlog := Real.log_lt_log (by positivity) h' rw [Real.log_pow] at hlog have hD : (Nat.clog k x : ℝ) ≤ ((Nat.clog k x).pred : ℕ) + 1 := by have := Nat.le_succ_of_pred_le (le_refl (Nat.clog k x).pred) exact_mod_cast this have h2 : (((Nat.clog k x).pred : ℕ) : ℝ) < Real.log x / Real.log k := by rw [lt_div_iff₀ hL]; exact hlog linarith /-- The key capacity estimate (pure arithmetic). -/ lemma capacity_key {N L θ η r H₁ H₂ ε' J D A : ℝ} (hL : 0 < L) (hN : 0 < N) (hr : 0 < r) (hJ : (N * (θ - η) - (r + 3)) * (r - 1) / r - 1 ≤ J) (hD : D ≤ 1 + (Real.log N + N * (H₁ - H₂ + 2 * η)) / L) (hsplit : (N * (θ - η) - (r + 3)) * (r - 1) / r ≥ N * (θ - η) - (r + 3) - N * θ / r) (hlogN : (r + 5) * L + Real.log N < N * (ε' / 8)) (hrb : θ * L / r < ε' / 8) (hη : η * (L + 2) = ε' / 16) (hA : A = θ * L - (H₁ - H₂)) (hε' : 0 ≤ ε') : (J - D) * L ≥ N * (A - ε' / 2) := by set Z := Real.log N + N * (H₁ - H₂ + 2 * η) have h0 : J - D ≥ N * (θ - η) - (r + 3) - N * θ / r - 2 - Z / L := by linarith have h1 : (J - D) * L ≥ (N * (θ - η) - (r + 3) - N * θ / r - 2 - Z / L) * L := mul_le_mul_of_nonneg_right h0 hL.le have h2 : (N * (θ - η) - (r + 3) - N * θ / r - 2 - Z / L) * L = N * θ * L - N * (η * (L + 2)) - ((r + 5) * L + Real.log N) - N * (θ * L / r) - N * (H₁ - H₂) := by simp only [Z]; field_simp; ring have h3 : N * (θ * L / r) ≤ N * (ε' / 8) := mul_le_mul_of_nonneg_left hrb.le hN.le have h4 : N * (η * (L + 2)) = N * (ε' / 16) := by rw [hη] rw [h2] at h1 rw [hA] have h6 : 0 ≤ N * ε' := mul_nonneg hN.le hε' have h7 : N * (θ * L - (H₁ - H₂) - ε' / 2) = N * θ * L - N * (H₁ - H₂) - N * ε' / 2 := by ring have h8 : N * (ε' / 8) = N * ε' / 8 := by ring have h9 : N * (ε' / 16) = N * ε' / 16 := by ring rw [h7] linarith /-- The final capacity inequality (pure arithmetic). -/ lemma capacity_lt {N L A ε' ε δ₁ J D μB μT θH : ℝ} (hN : 0 < N) (hTB : μT = N * μB) (hkey : (J - D) * L ≥ N * (A - ε' / 2)) (hT : 1 - 2 * δ₁ < μT) (hε'A : ε' ≤ A) (hε'ε : ε' ≤ ε) (hδ₁L : 2 * δ₁ * L < ε' / 8) (hAL : A ≤ L) (hδ₁ : 0 < δ₁) (hθH : θH = A) (hε'0 : 0 ≤ ε') (hμT : 0 ≤ μT) : θH - ε < (J - D) * μB * L := by rw [hθH] have hP : A - ε' / 2 ≤ (J - D) * L / N := by rw [le_div_iff₀ hN]; linarith [mul_comm N (A - ε' / 2)] have hP0 : 0 ≤ A - ε' / 2 := by linarith have hprod : (J - D) * μB * L = ((J - D) * L / N) * μT := by rw [hTB]; field_simp rw [hprod] have h1 : (A - ε' / 2) * (1 - 2 * δ₁) ≤ ((J - D) * L / N) * μT := by rcases le_total 0 (1 - 2 * δ₁) with h | h · exact mul_le_mul hP hT.le h (le_trans hP0 hP) · exact le_trans (mul_nonpos_of_nonneg_of_nonpos hP0 h) (mul_nonneg (le_trans hP0 hP) hμT) have h2 : (A - ε' / 2) * (2 * δ₁) ≤ L * (2 * δ₁) := mul_le_mul_of_nonneg_right (by linarith) (by linarith) have h3 : (A - ε' / 2) * (1 - 2 * δ₁) = (A - ε' / 2) - (A - ε' / 2) * (2 * δ₁) := by ring have h4 : L * (2 * δ₁) = 2 * δ₁ * L := by ring linarith variable [IsProbabilityMeasure μ] in /-- The tower over the typical part of a typical tower base still covers most of the space. -/ lemma measure_tower_inter_ge {e : α ≃ᵐ α} (he : MeasurePreserving (e : α → α) μ μ) {N : ℕ} {B₀ G : Set α} (hB₀ : MeasurableSet B₀) (hG : MeasurableSet G) {δ₁ : ℝ} (hcov : 1 - ENNReal.ofReal δ₁ < μ {y | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) y ∈ B₀}) (hbad : (N : ℝ≥0∞) * μ (B₀ \ G) ≤ μ Gᶜ) (hG' : μ Gᶜ < ENNReal.ofReal δ₁) : 1 - 2 * δ₁ < (μ {x | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) x ∈ B₀ ∩ G}).toReal := by set T := {x | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) x ∈ B₀ ∩ G} have hδ₁ : 0 < δ₁ := by by_contra h; push Not at h rw [ENNReal.ofReal_of_nonpos h] at hG'; exact absurd hG' (not_lt.mpr bot_le) have hT₀ : μ {x | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) x ∈ B₀} ≤ μ T + μ Gᶜ := by have hsub : {x | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) x ∈ B₀} ⊆ T ∪ ⋃ i : Fin N, ziter e (-(i : ℤ)) ⁻¹' (B₀ \ G) := by rintro x ⟨i, hi, hx⟩ by_cases hGx : ziter e (-(i : ℤ)) x ∈ G · exact Or.inl ⟨i, hi, hx, hGx⟩ · exact Or.inr (Set.mem_iUnion.mpr ⟨⟨i, hi⟩, hx, hGx⟩) calc _ ≤ μ (T ∪ ⋃ i : Fin N, ziter e (-(i : ℤ)) ⁻¹' (B₀ \ G)) := measure_mono hsub _ ≤ μ T + ∑ i : Fin N, μ (ziter e (-(i : ℤ)) ⁻¹' (B₀ \ G)) := (measure_union_le _ _).trans (by gcongr; exact measure_iUnion_fintype_le _ _) _ = μ T + N * μ (B₀ \ G) := by simp only [(measurePreserving_ziter e he _).measure_preimage (hB₀.diff hG).nullMeasurableSet, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] _ ≤ μ T + μ Gᶜ := by gcongr have h1 : 1 - ENNReal.ofReal δ₁ < μ T + ENNReal.ofReal δ₁ := lt_of_lt_of_le hcov (hT₀.trans (add_le_add le_rfl hG'.le)) have h2 : (1 : ℝ≥0∞) < μ T + ENNReal.ofReal δ₁ + ENNReal.ofReal δ₁ := by have := ENNReal.lt_add_of_sub_lt_right (Or.inl ENNReal.one_ne_top) h1 simpa [add_assoc] using this have h3 : (1 : ℝ) < (μ T).toReal + δ₁ + δ₁ := by have := ENNReal.toReal_strict_mono (by simp [measure_ne_top]) h2 rwa [ENNReal.toReal_add (by simp [measure_ne_top]) ENNReal.ofReal_ne_top, ENNReal.toReal_add (measure_ne_top _ _) ENNReal.ofReal_ne_top, ENNReal.toReal_ofReal hδ₁.le, ENNReal.toReal_one] at this linarith section Main variable [StandardBorelSpace α] [IsProbabilityMeasure μ] {e : α ≃ᵐ α} {c₀ : α → Fin k} {F₀ : Set α} {q : α → Fin n} omit [StandardBorelSpace α] in lemma ksEntropy_markedCode_le_pair (he : MeasurePreserving (e : α → α) μ μ) (hm : Measurable (markedCode c₀ F₀)) (hq : Measurable q) : ksEntropyPartition he (codePartition (μ := μ) (markedCode c₀ F₀) hm) ≤ ksEntropyPartition he (codePartition (μ := μ) (pairCode q (markedCode c₀ F₀)) (measurable_pairCode hq hm)) := ksEntropyPartition_le_of_refines he _ _ (fun v => (finProdFinEquiv.symm v).2) fun v => Eventually.of_forall fun x hx => by simp only [codePartition_cells, Set.mem_preimage, Set.mem_singleton_iff] at hx ⊢ rw [← hx]; simp [pairCode] /-- **Existence of a coding setup with the required capacity and error.** -/ theorem exists_codingSetup (he : MeasurePreserving (e : α → α) μ μ) (herg : Ergodic (e : α → α) μ) (hap : Aperiodic e μ) (hc₀ : Measurable c₀) (hF₀ : MeasurableSet F₀) (hq : Measurable q) (hcap : ksEntropyPartition he (codePartition (μ := μ) (pairCode q (markedCode c₀ F₀)) (measurable_pairCode hq (measurable_markedCode hc₀ hF₀))) < ksEntropyPartition he (codePartition (μ := μ) (markedCode c₀ F₀) (measurable_markedCode hc₀ hF₀)) + (μ F₀).toReal * Real.log k) {ε : ℝ} (hε : 0 < ε) : ∃ S : CodingSetup μ e k c₀ F₀ q, (μ F₀).toReal * Real.log k - (ksEntropyPartition he (codePartition (μ := μ) (pairCode q (markedCode c₀ F₀)) (measurable_pairCode hq (measurable_markedCode hc₀ hF₀))) - ksEntropyPartition he (codePartition (μ := μ) (markedCode c₀ F₀) (measurable_markedCode hc₀ hF₀))) - ε < ((S.J - S.D : ℕ) : ℝ) * (μ S.B).toReal * Real.log k ∧ μ {x | ∃ i : ℕ, i < S.N ∧ ziter e (-(i : ℤ)) x ∈ S.B}ᶜ < ENNReal.ofReal ε := by classical have : Nonempty α := nonempty_of_isProbabilityMeasure μ have hn : 0 < n := (q (Classical.arbitrary α)).pos have hm₀ : Measurable (markedCode c₀ F₀) := measurable_markedCode hc₀ hF₀ have hp : Measurable (pairCode q (markedCode c₀ F₀)) := measurable_pairCode hq hm₀ set H₁ := ksEntropyPartition he (codePartition (μ := μ) (pairCode q (markedCode c₀ F₀)) hp) set H₂ := ksEntropyPartition he (codePartition (μ := μ) (markedCode c₀ F₀) hm₀) set θ := (μ F₀).toReal set L := Real.log k have hH : H₂ ≤ H₁ := ksEntropy_markedCode_le_pair he hm₀ hq have hθ0 : 0 ≤ θ := ENNReal.toReal_nonneg have hθ1 : θ ≤ 1 := ENNReal.toReal_le_of_le_ofReal zero_le_one (by simp [prob_le_one]) have hθL : 0 < θ * L := by linarith have hL : 0 < L := by by_contra h; push Not at h; nlinarith have hk : 2 ≤ k := by by_contra h; push Not at h have : (k : ℝ) ≤ 1 := by exact_mod_cast (show k ≤ 1 by omega) have := Real.log_nonpos (Nat.cast_nonneg k) this linarith have : NullSingletonClass μ := nullSingletonClass_of_aperiodic he hap set A := θ * L - (H₁ - H₂) with hA have hApos : 0 < A := by linarith have hAL : A ≤ L := by nlinarith set ε' := min ε A with hε' have hε'pos : 0 < ε' := lt_min hε hApos have hε'ε : ε' ≤ ε := min_le_left _ _ have hε'A : ε' ≤ A := min_le_right _ _ -- the parameters `r`, `η`, `δ₁` set r := ⌈8 * θ * L / ε'⌉₊ + 2 with hr_def have hr : 2 ≤ r := by omega have hrpos : (0 : ℝ) < r := by positivity have hrbound : θ * L / r < ε' / 8 := by have h1 : 8 * θ * L / ε' < r := by have := Nat.le_ceil (8 * θ * L / ε'); push_cast [hr_def]; linarith rw [div_lt_iff₀ hrpos] rw [div_lt_iff₀ hε'pos] at h1 nlinarith set η := ε' / (16 * (L + 2)) with hη_def have hηpos : 0 < η := by positivity have hηbound : η * (L + 2) = ε' / 16 := by rw [hη_def]; field_simp set δ₁ := ε' / (16 * (L + 1)) with hδ₁_def have hδ₁pos : 0 < δ₁ := by positivity have hδ₁eq : δ₁ * (L + 1) = ε' / 16 := by rw [hδ₁_def]; field_simp have hδ₁L : 2 * δ₁ * L < ε' / 8 := by nlinarith have hδ₁ε : 2 * δ₁ < ε' := by nlinarith have hδ₁1 : 2 * δ₁ < 1 := by nlinarith -- choice of `N` have hT1 := tendsto_measure_compl_typicalSet (μ := μ) herg hp hm₀ hF₀ hηpos have hT2 : Tendsto (fun N : ℕ => (((r : ℝ) + 5) * L + Real.log N) / N) atTop (nhds 0) := by have h1 := tendsto_const_div_atTop_nhds_zero_nat (((r : ℝ) + 5) * L) have h2 := (Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 one_ne_zero).comp tendsto_natCast_atTop_atTop have h3 := h1.add h2 simp only [add_zero, pow_one, one_mul, Function.comp_def] at h3 refine h3.congr' (Eventually.of_forall fun N => ?_) simp only [add_div] obtain ⟨N, hN1, hNG, hNlog⟩ : ∃ N : ℕ, 1 ≤ N ∧ μ (typicalSet e μ (pairCode q (markedCode c₀ F₀)) (markedCode c₀ F₀) F₀ N H₁ H₂ η)ᶜ < ENNReal.ofReal δ₁ ∧ (((r : ℝ) + 5) * L + Real.log N) / N < ε' / 8 := ((eventually_ge_atTop 1).and (((tendsto_order.1 hT1).2 _ (ENNReal.ofReal_pos.mpr hδ₁pos)).and ((tendsto_order.1 hT2).2 _ (by positivity)))).exists.imp fun N h => ⟨h.1, h.2.1, h.2.2⟩ -- the typical set and the tower set p := pairCode q (markedCode c₀ F₀) with hp_def set m₀ := markedCode c₀ F₀ with hm₀_def set G := typicalSet e μ p m₀ F₀ N H₁ H₂ η with hG_def have hGm : MeasurableSet G := measurableSet_typicalSet e hp hm₀ hF₀ N H₁ H₂ η obtain ⟨B₀, hB₀, htow₀, hcov₀, hbad⟩ := exists_typical_tower e he herg hN1 hδ₁pos hGm set B := B₀ ∩ G with hB_def have hBm : MeasurableSet B := hB₀.inter hGm have htowB : TowerDisjoint e B N := fun b hb d hd0 hdN hdb => htow₀ b hb.1 d hd0 hdN hdb.1 have hNpos : (0 : ℝ) < N := by exact_mod_cast hN1 set a := Real.exp (-(N * (H₁ + η))) with ha_def have hapos : 0 < a := Real.exp_pos _ have hexp0 : 0 ≤ (N : ℝ) * (H₁ - H₂ + 2 * η) := mul_nonneg hNpos.le (by linarith) set K := ⌊Real.exp (N * (H₁ - H₂ + 2 * η))⌋₊ with hK_def have hK1 : 1 ≤ K := Nat.le_floor (by simpa using Real.one_le_exp hexp0) have hKle : (K : ℝ) ≤ Real.exp (N * (H₁ - H₂ + 2 * η)) := Nat.floor_le (Real.exp_pos _).le set D := Nat.clog k (N * K) with hD_def set ν₀ := ⌈(N : ℝ) * (θ - η)⌉₊ with hν₀_def set X := (ν₀ - (r + 3)) * (r - 1) with hX_def set J := X / r with hJ_def obtain ⟨enc⟩ := Function.Embedding.nonempty_of_card_le (α := Fin N × Fin K) (β := Fin D → Fin k) (by simp only [Fintype.card_prod, Fintype.card_fin, Fintype.card_fun] exact Nat.le_pow_clog (by omega) _) have htyp : ∀ b ∈ G, a ≤ (μ {y | blockName e p N y = blockName e p N b}).toReal ∧ (μ {y | blockName e m₀ N y = blockName e m₀ N b}).toReal ≤ Real.exp (-(N * (H₂ - η))) ∧ (N : ℝ) * (θ - η) ≤ visitCount e F₀ N b := fun b hb => ⟨hb.1.1, hb.1.2, hb.2⟩ have hcard : ∀ b ∈ B, ((Finset.univ.filter fun w : Fin N → Fin (n * (k + 1)) => a ≤ (μ {y | blockName e p N y = w}).toReal ∧ mOf w = mOf (blockName e p N b)).card ≤ K) := by intro b hb obtain ⟨h1, h2, -⟩ := htyp b hb.2 have hπ : (fun v : Fin (n * (k + 1)) => (finProdFinEquiv.symm v).2) ∘ p = m₀ := by funext y; simp only [Function.comp_apply, hp_def, pairCode, Equiv.symm_apply_apply] have hmOf : mOf (blockName e p N b) = blockName e m₀ N b := by funext i; simp only [mOf, blockName, hp_def, pairCode, Equiv.symm_apply_apply] have hc := card_filter_mul_le (μ := μ) e hp (fun v : Fin (n * (k + 1)) => (finProdFinEquiv.symm v).2) (Finset.univ.filter fun w : Fin N → Fin (n * (k + 1)) => a ≤ (μ {y | blockName e p N y = w}).toReal) (a := a) (b := Real.exp (-(N * (H₂ - η)))) (mOf (blockName e p N b)) (fun w hw => (Finset.mem_filter.mp hw).2) (by rw [hπ, hmOf]; exact h2) rw [Finset.filter_filter] at hc have hc' : ((Finset.univ.filter fun w : Fin N → Fin (n * (k + 1)) => a ≤ (μ {y | blockName e p N y = w}).toReal ∧ mOf w = mOf (blockName e p N b)).card : ℝ) ≤ Real.exp (N * (H₁ - H₂ + 2 * η)) := by have heq : Real.exp (-(N * (H₂ - η))) / a = Real.exp (N * (H₁ - H₂ + 2 * η)) := by rw [ha_def, ← Real.exp_sub]; congr 1; ring rw [← heq, le_div_iff₀ hapos] exact hc exact Nat.le_floor hc' have hvis : ∀ b ∈ B, ν₀ ≤ cnt (actWord e F₀ b) 0 N := by intro b hb rw [cnt_actWord_eq_visitCount] exact Nat.ceil_le.mpr (htyp b hb.2).2.2 have hJslot : ∀ b ∈ B, ∀ j < J, slotPos r j < cnt (actWord e F₀ b) 0 N := by intro b hb j hj have hXpos : 0 < X := by by_contra h0; push Not at h0 have : J = 0 := by rw [hJ_def, Nat.le_zero.mp h0, Nat.zero_div] omega have hν : r + 3 ≤ ν₀ := by by_contra h; push Not at h have : ν₀ - (r + 3) = 0 := by omega rw [hX_def, this, zero_mul] at hXpos; omega have hjr : j * r ≤ X := by have h1 : (j + 1) * r ≤ X := (Nat.mul_le_mul_right r (Nat.succ_le_of_lt hj)).trans (Nat.div_mul_le_self X r) nlinarith exact (slotPos_lt_of_mul_le hr hν hjr).trans_le (hvis b hb) -- numeric estimates have hXreal : ((N : ℝ) * (θ - η) - (r + 3)) * (r - 1) ≤ X := by have h1 : (N : ℝ) * (θ - η) - (r + 3) ≤ ((ν₀ - (r + 3) : ℕ) : ℝ) := by have hc := Nat.le_ceil ((N : ℝ) * (θ - η)) rcases le_total (r + 3) ν₀ with h | h · rw [Nat.cast_sub h]; push_cast; linarith · rw [Nat.sub_eq_zero_of_le h] have : (ν₀ : ℝ) ≤ r + 3 := by exact_mod_cast h push_cast; linarith have h2 : ((r - 1 : ℕ) : ℝ) = r - 1 := by rw [Nat.cast_sub (by omega)]; simp rw [hX_def]; push_cast [h2] exact mul_le_mul_of_nonneg_right h1 (by linarith [show (2 : ℝ) ≤ r by exact_mod_cast hr]) have hJreal : ((N : ℝ) * (θ - η) - (r + 3)) * (r - 1) / r - 1 ≤ J := by have := natCast_div_ge X r (by omega) have h3 : ((N : ℝ) * (θ - η) - (r + 3)) * (r - 1) / r ≤ (X : ℝ) / r := div_le_div_of_nonneg_right hXreal hrpos.le linarith have hDreal : (D : ℝ) ≤ 1 + (Real.log N + N * (H₁ - H₂ + 2 * η)) / L := by have h1 := clog_le_real (k := k) (x := N * K) (by omega) (Nat.one_le_iff_ne_zero.mpr (Nat.mul_ne_zero (by omega) (by omega))) have h2 : Real.log ((N * K : ℕ) : ℝ) ≤ Real.log N + N * (H₁ - H₂ + 2 * η) := by push_cast rw [Real.log_mul hNpos.ne' (by positivity)] have := Real.log_le_log (by positivity) hKle rw [Real.log_exp] at this linarith have h3 : Real.log ((N * K : ℕ) : ℝ) / L ≤ (Real.log N + N * (H₁ - H₂ + 2 * η)) / L := div_le_div_of_nonneg_right h2 hL.le linarith have hsplit : ((N : ℝ) * (θ - η) - (r + 3)) * (r - 1) / r ≥ (N : ℝ) * (θ - η) - (r + 3) - N * θ / r := by have h1 : ((N : ℝ) * (θ - η) - (r + 3)) * (r - 1) / r = ((N : ℝ) * (θ - η) - (r + 3)) - ((N : ℝ) * (θ - η) - (r + 3)) / r := by field_simp have h2 : ((N : ℝ) * (θ - η) - (r + 3)) / r ≤ N * θ / r := div_le_div_of_nonneg_right (by nlinarith) hrpos.le linarith have hlogN : (((r : ℝ) + 5) * L + Real.log N) < N * (ε' / 8) := by rw [div_lt_iff₀ hNpos] at hNlog; linarith have hkey : ((J : ℝ) - D) * L ≥ N * (A - ε' / 2) := capacity_key hL hNpos hrpos hJreal hDreal hsplit hlogN hrbound hηbound hA hε'pos.le have hJD : D < J := by have h1 : (0 : ℝ) < ((J : ℝ) - D) * L := lt_of_lt_of_le (mul_pos hNpos (by linarith)) hkey have : (0 : ℝ) < (J : ℝ) - D := (mul_pos_iff_of_pos_right hL).mp h1 exact_mod_cast (show (D : ℝ) < J by linarith) -- the setup let S : CodingSetup μ e k c₀ F₀ q := { N := N, r := r, D := D, K := K, J := J, a := a, B := B, hk := hk, hn := hn, hN := hN1, hK := hK1, hr := hr, hB := hBm, htower := htowB, enc := enc, htyp := fun b hb => (htyp b hb.2).1, hcard := hcard, hJ := hJslot, hDJ := hJD } -- the measure of the tower set T := {x | ∃ i : ℕ, i < N ∧ ziter e (-(i : ℤ)) x ∈ B} with hT_def have hTm : MeasurableSet T := by rw [hT_def, tower_eq_iUnion] exact MeasurableSet.iUnion fun i => measurable_ziter e _ hBm have hTreal : 1 - 2 * δ₁ < (μ T).toReal := measure_tower_inter_ge he hB₀ hGm hcov₀ hbad hNG have hTB : (μ T).toReal = N * (μ B).toReal := by rw [hT_def, measure_tower_eq he htowB hBm, ENNReal.toReal_mul]; simp refine ⟨S, ?_, ?_⟩ · change θ * L - (H₁ - H₂) - ε < ((J - D : ℕ) : ℝ) * (μ B).toReal * L rw [Nat.cast_sub hJD.le] exact capacity_lt hNpos hTB hkey hTreal hε'A hε'ε hδ₁L hAL hδ₁pos hA.symm hε'pos.le ENNReal.toReal_nonneg · change μ Tᶜ < ENNReal.ofReal ε rw [prob_compl_eq_one_sub hTm] have : (1 : ℝ≥0∞) - μ T = ENNReal.ofReal (1 - (μ T).toReal) := by rw [ENNReal.ofReal_sub _ ENNReal.toReal_nonneg, ENNReal.ofReal_one, ENNReal.ofReal_toReal (measure_ne_top _ _)] rw [this] exact (ENNReal.ofReal_lt_ofReal_iff hε).mpr (by linarith) end Main universe u /-- **Krieger's coding step.** -/ theorem krieger_coding_step : KriegerCodingStep.{u} := by intro α _ _ μ _ e he herg hap k c₀ hc₀ F₀ hF₀ hdec n q hq hcap ε hε obtain ⟨S, hcapS, herr⟩ := exists_codingSetup he herg hap hc₀ hF₀ hq hcap hε obtain ⟨hcode, hfree, hdecS, happ⟩ := S.spec he hF₀ hc₀ hq hdec refine ⟨S.code, hcode, S.free, hfree, S.free_subset, fun x hx => S.code_of_not_mem hx, hdecS, ?_, fun c' hc' hag => ?_⟩ · have hF : ((S.J - S.D : ℕ) : ℝ≥0∞) * μ S.B ≤ μ S.free := measure_stageFree_ge he S.htower S.hB hF₀ S.hr S.hJ have hF' : ((S.J - S.D : ℕ) : ℝ) * (μ S.B).toReal ≤ (μ S.free).toReal := by have := ENNReal.toReal_mono (measure_ne_top μ _) hF rwa [ENNReal.toReal_mul, ENNReal.toReal_natCast] at this have hL : 0 ≤ Real.log k := Real.log_natCast_nonneg k have := mul_le_mul_of_nonneg_right hF' hL linarith · obtain ⟨q', hq', hle⟩ := happ c' hc' hag exact ⟨q', hq', lt_of_le_of_lt hle herr⟩ /-- **Krieger's stage lemma.** -/ theorem krieger_stage_lemma : KriegerStageLemma.{u} := kriegerStageLemma_of_codingStep krieger_coding_step /-- **Krieger's finite generator theorem.** Let `e : α ≃ᵐ α` be an ergodic, aperiodic, measure-preserving automorphism of a standard Borel probability space `(α, μ)` whose Kolmogorov–Sinai entropy satisfies `h(e) < log k` (an inequality in `EReal`, so infinite entropy is excluded). Then `e` has a two-sided generator with `k` cells, mod 0. -/ theorem krieger_finite_generator {α : Type u} [MeasurableSpace α] [StandardBorelSpace α] {μ : Measure α} [IsProbabilityMeasure μ] {e : α ≃ᵐ α} (he : MeasurePreserving (e : α → α) μ μ) (herg : Ergodic (e : α → α) μ) (hap : Aperiodic e μ) {k : ℕ} (hk : ksEntropy he < ((Real.log k : ℝ) : EReal)) : ∃ P : MeasurePartition μ (Fin k), IsGeneratingTwoSidedMod0 e P := krieger_finite_generator_of_stageLemma krieger_stage_lemma he herg hap hk /-- **Krieger's finite generator theorem on a non-atomic space**: aperiodicity follows from ergodicity (`aperiodic_of_ergodic`). -/ theorem krieger_finite_generator_of_nullSingleton {α : Type u} [MeasurableSpace α] [StandardBorelSpace α] {μ : Measure α} [IsProbabilityMeasure μ] [NullSingletonClass μ] {e : α ≃ᵐ α} (he : MeasurePreserving (e : α → α) μ μ) (herg : Ergodic (e : α → α) μ) {k : ℕ} (hk : ksEntropy he < ((Real.log k : ℝ) : EReal)) : ∃ P : MeasurePartition μ (Fin k), IsGeneratingTwoSidedMod0 e P := krieger_finite_generator he herg (aperiodic_of_ergodic he herg) hk end ErgodicTheory.Krieger