import Mathlib /-! # Online Log-Loss Minimax Theory, Contextual Shtarkov–cNML Duality, and Bounded-Memory Rate-Distortion Phase Transitions This self-contained Lean 4 formalization establishes the exact non-asymptotic minimax theory of: 1. **Weighted Contextual Shtarkov Sums & Exact Self-Dual cNML Duality** (Parts 1–2): Exact trajectory-wise KL-excess identity, multi-round adaptive saddle-point theorem, horizon sub-multiplicativity, and periodic-reset bounded-window coding for arbitrary finite stochastic expert classes `F` over arbitrary finite label alphabets `β`. 2. **Stochastic 2-Expert Shtarkov–TV–Bhattacharyya–Jensen–Shannon Exact Duality & Redundancy–Capacity Separation** (Part 3): Exact identity `S_T({f₁, f₂}) = 1 + TV_T^adapt(f₁, f₂)`, sharp multiclass Topsøe–Pinsker inequality `TV(p, q)² ≤ 2 * JS(p, q)`, two-sided Bhattacharyya/Hellinger sandwich, and unbounded separation between individual-sequence Shtarkov regret and minimax KL-redundancy. 3. **Realizable Multiclass Deterministic Classes: Adaptive Sauer–Shelah, Oblivious vs. Adaptive Exponential Separation, & Product Super-Multiplicativity** (Part 4): Exact multiclass adaptive Sauer–Shelah bound `S_T^adapt(V) ≤ ∑_{i ≤ Ldim V} C(T, i) (k - 1)^i`, simultaneous exact tightness on `k`-ary Hamming balls `B_k(T, d)`, exact exponential separation `log(T + 1)` vs. `T * log 2` on 1D thresholds, and strict disjoint-product super-multiplicativity `S_4(thresh4 × sing2) = 13 > 12 = max_{t1+t2=4} S_{t1} * S_{t2}` contrasting with oblivious equality. 4. **Bounded-Memory (Width-`M` Branching Program) Multi-Pass Sequential Log-Loss Phase Transition** (Part 5): Exact universal lower bound `ln |V| + (R - 1) * max(0, ln |V| - ln M)` for EVERY width-`M` (even randomized!) multi-pass online learner, exact sharpness on `r`-ary cubes for `M = r^b`, and sharp bounded-vs-linear-in-`R` phase transition at `M* = |V|`. 5. **Bounded-Memory 0–1 Rate-Distortion vs. Log-Loss Separation via Strict Width-`M` Block-Majority Learners** (Part 6): Exact binary-entropy rate-distortion lower bound `h₂(min(ē_r, 1/2)) ≥ (1 - ln M / (d ln 2)) ln 2`, contrasted with an explicit infinite family (`d = 3t`, strict width `M = 3 * 2^(t-1)` and `M = 2^(t+1)`) of strict width-`M` branching programs achieving `3t / 4` average 0–1 mistakes/pass — beating memorization and the log-loss-in-bits barrier by 25% asymptotically while log-loss cannot be beaten by a single nat. -/ open scoped BigOperators open Finset namespace OnlineLogLossMemoryMinimax /-! ## Part 1: Exact KL-Divergence Properness & Weighted Contextual Shtarkov Operator -/ /-- Safe KL divergence summand `q * log (q / p)` with `0 * log 0 = 0`. -/ noncomputable def klTerm (q p : ℝ) : ℝ := if q = 0 then 0 else q * Real.log (q / p) /-- Kullback–Leibler divergence `D_KL(q ‖ p)` on a finite support `S`. -/ noncomputable def klDiv {β : Type*} (S : Finset β) (q p : β → ℝ) : ℝ := ∑ y ∈ S, klTerm (q y) (p y) /-- Pointwise Gibbs bound `q - p ≤ klTerm q p` whenever `0 ≤ q`, `0 ≤ p`, and `q ≠ 0 → 0 < p`. -/ lemma sub_le_klTerm {q p : ℝ} (hq : 0 ≤ q) (hp : 0 ≤ p) (hsupp : q ≠ 0 → 0 < p) : q - p ≤ klTerm q p := by by_cases hq0 : q = 0 · subst hq0; simp only [klTerm, ↓reduceIte]; linarith · have hq_pos : 0 < q := lt_of_le_of_ne hq (Ne.symm hq0) have hp_pos : 0 < p := hsupp hq0 simp only [klTerm, hq0, ↓reduceIte] have hlog := Real.log_le_sub_one_of_pos (div_pos hp_pos hq_pos) have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt hq_pos) rw [mul_sub, mul_div_cancel₀ _ (ne_of_gt hq_pos), mul_one] at hmul have hinv : Real.log (p / q) = -Real.log (q / p) := by rw [Real.log_div (ne_of_gt hp_pos) (ne_of_gt hq_pos), Real.log_div (ne_of_gt hq_pos) (ne_of_gt hp_pos)]; ring rw [hinv] at hmul; linarith /-- **Gibbs' Inequality (`klDiv ≥ 0`)**: for any probability distributions `q, p` on `S` with `supp q ⊆ supp p`, `0 ≤ klDiv S q p`. -/ theorem klDiv_nonneg {β : Type*} {S : Finset β} {q p : β → ℝ} (hq0 : ∀ y ∈ S, 0 ≤ q y) (hp0 : ∀ y ∈ S, 0 ≤ p y) (hqsum : ∑ y ∈ S, q y = 1) (hpsum : ∑ y ∈ S, p y = 1) (hsupp : ∀ y ∈ S, q y ≠ 0 → 0 < p y) : 0 ≤ klDiv S q p := by have hle : ∑ y ∈ S, (q y - p y) ≤ ∑ y ∈ S, klTerm (q y) (p y) := Finset.sum_le_sum fun y hy => sub_le_klTerm (hq0 y hy) (hp0 y hy) (hsupp y hy) rw [Finset.sum_sub_distrib, hqsum, hpsum, sub_self] at hle exact hle /-- **Strict Propriety of KL Divergence (`klDiv = 0 ↔ p = q` on `S`)**. -/ theorem klDiv_eq_zero_iff {β : Type*} {S : Finset β} {q p : β → ℝ} (hq0 : ∀ y ∈ S, 0 ≤ q y) (hp0 : ∀ y ∈ S, 0 ≤ p y) (hqsum : ∑ y ∈ S, q y = 1) (hpsum : ∑ y ∈ S, p y = 1) (hsupp : ∀ y ∈ S, q y ≠ 0 → 0 < p y) : klDiv S q p = 0 ↔ ∀ y ∈ S, p y = q y := by constructor · intro hzero have hdiff_nn : ∀ y ∈ S, 0 ≤ klTerm (q y) (p y) - (q y - p y) := fun y hy => sub_nonneg.mpr (sub_le_klTerm (hq0 y hy) (hp0 y hy) (hsupp y hy)) have hsum_zero : ∑ y ∈ S, (klTerm (q y) (p y) - (q y - p y)) = 0 := by rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, hqsum, hpsum, sub_self, sub_zero] exact hzero have hall := (Finset.sum_eq_zero_iff_of_nonneg hdiff_nn).mp hsum_zero intro y hy have hy0 := hall y hy by_cases hqy : q y = 0 · simp only [klTerm, hqy, ↓reduceIte] at hy0; linarith · have hq_pos : 0 < q y := lt_of_le_of_ne (hq0 y hy) (Ne.symm hqy) have hp_pos : 0 < p y := hsupp y hy hqy simp only [klTerm, hqy, ↓reduceIte] at hy0 by_contra hne have hratio_ne : p y / q y ≠ 1 := by intro h1; exact hne ((div_eq_one_iff_eq (ne_of_gt hq_pos)).mp h1) have hlt := Real.log_lt_sub_one_of_pos (div_pos hp_pos hq_pos) hratio_ne have hmul := mul_lt_mul_of_pos_left hlt hq_pos rw [mul_sub, mul_div_cancel₀ _ (ne_of_gt hq_pos), mul_one] at hmul have hinv : Real.log (p y / q y) = -Real.log (q y / p y) := by rw [Real.log_div (ne_of_gt hp_pos) (ne_of_gt hq_pos), Real.log_div (ne_of_gt hq_pos) (ne_of_gt hp_pos)]; ring rw [hinv] at hmul; linarith · intro heq refine Finset.sum_eq_zero fun y hy => ?_ rw [heq y hy] by_cases hqy : q y = 0 · simp [klTerm, hqy] · simp [klTerm, hqy] /-- **Exact 1-Step Self-Dual Log-Loss Properness Identity**: Given nonnegative weights `u : β → ℝ` with total `Z = ∑ y ∈ S, u y > 0`, let `p*(y) = u y / Z`. Then for EVERY forecast `p : β → ℝ` with `0 < p y` on `{y ∈ S | 0 < u y}`, `∑_{y ∈ S} p*(y) * (if u y = 0 then 0 else -log (p y) + log (u y)) = log Z + klDiv S p* p`! -/ theorem logLoss_selfDual_kl_identity {β : Type*} {S : Finset β} {u p : β → ℝ} (hu0 : ∀ y ∈ S, 0 ≤ u y) (hZ : 0 < ∑ y ∈ S, u y) (hp_pos : ∀ y ∈ S, u y ≠ 0 → 0 < p y) : let Z := ∑ y ∈ S, u y let pStar : β → ℝ := fun y => u y / Z ∑ y ∈ S, (if u y = 0 then 0 else pStar y * (-Real.log (p y) + Real.log (u y))) = Real.log Z + klDiv S pStar p := by intro Z pStar have hpStar_sum : ∑ y ∈ S, pStar y = 1 := by dsimp only [pStar]; rw [← Finset.sum_div, div_self (ne_of_gt hZ)] have hterm : ∀ y ∈ S, (if u y = 0 then 0 else pStar y * (-Real.log (p y) + Real.log (u y))) = pStar y * Real.log Z + klTerm (pStar y) (p y) := by intro y hy by_cases huy : u y = 0 · have hp0 : pStar y = 0 := by dsimp only [pStar]; rw [huy, zero_div] simp [klTerm, huy, hp0] · have hu_pos : 0 < u y := lt_of_le_of_ne (hu0 y hy) (Ne.symm huy) have hpStar_pos : 0 < pStar y := div_pos hu_pos hZ have hp_y : 0 < p y := hp_pos y hy huy simp only [klTerm, huy, ne_of_gt hpStar_pos, ↓reduceIte] have hlog : Real.log (pStar y / p y) = Real.log (u y) - Real.log Z - Real.log (p y) := by dsimp only [pStar] rw [Real.log_div (ne_of_gt (div_pos hu_pos hZ)) (ne_of_gt hp_y), Real.log_div (ne_of_gt hu_pos) (ne_of_gt hZ)] rw [hlog]; ring rw [Finset.sum_congr rfl hterm, Finset.sum_add_distrib, ← Finset.sum_mul, hpStar_sum, one_mul] rfl /-- A finite stochastic expert class `eval : ι → α → β → ℝ` on index set `F : Finset ι`: each `f ∈ F` maps every context `x : α` to a probability distribution on `β`. -/ def IsStochClass {α β ι : Type*} [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) : Prop := ∀ f ∈ F, ∀ x : α, (∀ y : β, 0 ≤ eval f x y) ∧ ∑ y : β, eval f x y = 1 /-- **Weighted Contextual Shtarkov Operator `S_T(F, w)`** for horizon `T : ℕ`: - `S_0(F, w) = max_{f ∈ F} w f` (or `0` if `F = ∅`), - `S_{T+1}(F, w) = max_{x ∈ α} ∑_{y ∈ β} S_T(F, f ↦ w f * eval f x y)`. -/ noncomputable def ctxShtarkov {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) : ℕ → (ι → ℝ) → ℝ | 0, w => if hF : F.Nonempty then F.sup' hF w else 0 | T + 1, w => Finset.univ.sup' Finset.univ_nonempty fun x : α => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) /-- Standard (unweighted, `w ≡ 1`) Contextual Shtarkov Sum `S_T(F)`. -/ noncomputable def ctxShtarkovUnif {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) (T : ℕ) : ℝ := ctxShtarkov eval F T (fun _ => 1) lemma ctxShtarkov_congr_w {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} : ∀ (T : ℕ) {w₁ w₂ : ι → ℝ}, (∀ f ∈ F, w₁ f = w₂ f) → ctxShtarkov eval F T w₁ = ctxShtarkov eval F T w₂ | 0, w₁, w₂, h => by simp only [ctxShtarkov] split_ifs with hF · exact Finset.sup'_congr hF rfl h · rfl | T + 1, w₁, w₂, h => by simp only [ctxShtarkov] refine Finset.sup'_congr Finset.univ_nonempty rfl fun x _ => ?_ refine Finset.sum_congr rfl fun y _ => ?_ exact ctxShtarkov_congr_w T fun f hf => by rw [h f hf] lemma ctxShtarkov_nonneg {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T : ℕ) {w : ι → ℝ}, (∀ f ∈ F, 0 ≤ w f) → 0 ≤ ctxShtarkov eval F T w | 0, w, hw => by simp only [ctxShtarkov] split_ifs with hF · rcases hF with ⟨f0, hf0⟩ exact le_trans (hw f0 hf0) (Finset.le_sup' w hf0) · exact le_rfl | T + 1, w, hw => by simp only [ctxShtarkov] obtain ⟨x0⟩ := ‹Nonempty α› refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y)) (Finset.mem_univ x0)) exact Finset.sum_nonneg fun y _ => ctxShtarkov_nonneg hS T fun f hf => mul_nonneg (hw f hf) ((hS f hf x0).1 y) lemma ctxShtarkov_mono_w {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T : ℕ) {w₁ w₂ : ι → ℝ}, (∀ f ∈ F, w₁ f ≤ w₂ f) → ctxShtarkov eval F T w₁ ≤ ctxShtarkov eval F T w₂ | 0, w₁, w₂, h => by simp only [ctxShtarkov] split_ifs with hF · exact Finset.sup'_le hF _ fun f hf => le_trans (h f hf) (Finset.le_sup' w₂ hf) · exact le_rfl | T + 1, w₁, w₂, h => by simp only [ctxShtarkov] refine Finset.sup'_le Finset.univ_nonempty _ fun x _ => ?_ refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w₂ f * eval f x y)) (Finset.mem_univ x)) exact Finset.sum_le_sum fun y _ => ctxShtarkov_mono_w hS T fun f hf => mul_le_mul_of_nonneg_right (h f hf) ((hS f hf x).1 y) /-- **Positive Homogeneity of `ctxShtarkov`**: `S_T(F, c * w) = c * S_T(F, w)` for `c ≥ 0`. -/ theorem ctxShtarkov_scale {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} : ∀ (T : ℕ) {c : ℝ} (_hc : 0 ≤ c) (w : ι → ℝ), ctxShtarkov eval F T (fun f => c * w f) = c * ctxShtarkov eval F T w | 0, c, hc, w => by simp only [ctxShtarkov] split_ifs with hF · apply le_antisymm · exact Finset.sup'_le hF _ fun f hf => mul_le_mul_of_nonneg_left (Finset.le_sup' w hf) hc · rcases Finset.exists_mem_eq_sup' hF w with ⟨f0, hf0, heq⟩ rw [heq]; exact Finset.le_sup' (fun f => c * w f) hf0 · ring | T + 1, c, hc, w => by simp only [ctxShtarkov] have hstep : ∀ x : α, (∑ y : β, ctxShtarkov eval F T (fun f => c * w f * eval f x y)) = c * ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) := fun x => by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun y _ => ?_ have heq : (fun f => c * w f * eval f x y) = (fun f => c * (w f * eval f x y)) := by ext f; ring rw [heq, ctxShtarkov_scale T hc] simp_rw [hstep] apply le_antisymm · exact Finset.sup'_le Finset.univ_nonempty _ fun x hx => mul_le_mul_of_nonneg_left (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y)) hx) hc · rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y)) with ⟨x0, hx0, heq⟩ rw [heq] exact Finset.le_sup' (f := fun x => c * ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y)) hx0 /-- **Subadditivity (Convexity) of `ctxShtarkov` in `w`**. -/ theorem ctxShtarkov_add_le {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} : ∀ (T : ℕ) (w₁ w₂ : ι → ℝ), ctxShtarkov eval F T (fun f => w₁ f + w₂ f) ≤ ctxShtarkov eval F T w₁ + ctxShtarkov eval F T w₂ | 0, w₁, w₂ => by simp only [ctxShtarkov] split_ifs with hF · exact Finset.sup'_le hF _ fun f hf => add_le_add (Finset.le_sup' w₁ hf) (Finset.le_sup' w₂ hf) · linarith | T + 1, w₁, w₂ => by simp only [ctxShtarkov] refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ have hstep : ∀ y : β, ctxShtarkov eval F T (fun f => (w₁ f + w₂ f) * eval f x y) ≤ ctxShtarkov eval F T (fun f => w₁ f * eval f x y) + ctxShtarkov eval F T (fun f => w₂ f * eval f x y) := fun y => by have heq : (fun f => (w₁ f + w₂ f) * eval f x y) = (fun f => w₁ f * eval f x y + w₂ f * eval f x y) := by ext f; ring rw [heq]; exact ctxShtarkov_add_le T _ _ calc ∑ y : β, ctxShtarkov eval F T (fun f => (w₁ f + w₂ f) * eval f x y) ≤ ∑ y : β, (ctxShtarkov eval F T (fun f => w₁ f * eval f x y) + ctxShtarkov eval F T (fun f => w₂ f * eval f x y)) := Finset.sum_le_sum fun y _ => hstep y _ = (∑ y : β, ctxShtarkov eval F T (fun f => w₁ f * eval f x y)) + (∑ y : β, ctxShtarkov eval F T (fun f => w₂ f * eval f x y)) := Finset.sum_add_distrib _ ≤ _ := add_le_add (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w₁ f * eval f x y)) hx) (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun f => w₂ f * eval f x y)) hx) /-- **Lower Bound `max_{f ∈ F} w f ≤ ctxShtarkov eval F T w`** (and horizon monotonicity `S_T ≤ S_{T+1}`)! -/ theorem ctxShtarkov_ge_weight {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T : ℕ) (w : ι → ℝ) {f : ι}, f ∈ F → w f ≤ ctxShtarkov eval F T w | 0, w, f, hf => by have hF : F.Nonempty := ⟨f, hf⟩ simp only [ctxShtarkov, hF, ↓reduceDIte] exact Finset.le_sup' w hf | T + 1, w, f, hf => by simp only [ctxShtarkov] obtain ⟨x0⟩ := ‹Nonempty α› refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T (fun g => w g * eval g x y)) (Finset.mem_univ x0)) calc w f = w f * 1 := (mul_one _).symm _ = w f * ∑ y : β, eval f x0 y := by rw [(hS f hf x0).2] _ = ∑ y : β, w f * eval f x0 y := Finset.mul_sum _ _ _ _ ≤ ∑ y : β, ctxShtarkov eval F T (fun g => w g * eval g x0 y) := Finset.sum_le_sum fun y _ => ctxShtarkov_ge_weight hS T (fun g => w g * eval g x0 y) hf lemma ctxShtarkov_pos {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (T : ℕ) {w : ι → ℝ} (hex : ∃ f ∈ F, 0 < w f) : 0 < ctxShtarkov eval F T w := by rcases hex with ⟨f, hf, hpos⟩ exact lt_of_lt_of_le hpos (ctxShtarkov_ge_weight hS T w hf) /-- **Horizon Monotonicity (`S_T(F, w) ≤ S_{T+1}(F, w)`)**. -/ theorem ctxShtarkov_mono_T {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T : ℕ) (w : ι → ℝ), ctxShtarkov eval F T w ≤ ctxShtarkov eval F (T + 1) w | 0, w => by by_cases hF : F.Nonempty · conv_lhs => simp only [ctxShtarkov, hF, ↓reduceDIte] exact Finset.sup'_le hF _ fun f hf => ctxShtarkov_ge_weight hS 1 w hf · simp only [ctxShtarkov, hF, ↓reduceDIte] obtain ⟨x0⟩ := ‹Nonempty α› refine le_trans ?_ (Finset.le_sup' (f := fun x : α => ∑ _y : β, (0 : ℝ)) (Finset.mem_univ x0)) simp | T + 1, w => by simp only [ctxShtarkov] refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ refine le_trans ?_ (Finset.le_sup' _ hx) exact Finset.sum_le_sum fun y _ => ctxShtarkov_mono_T hS T _ /-- **Universal Sum-of-Weights Upper Bound (`S_T(F, w) ≤ ∑_{f ∈ F} w f`)**: in particular `S_T(F, 1) ≤ |F|` and `log S_T(F, 1) ≤ log |F|` for every horizon `T`! -/ theorem ctxShtarkov_le_sum_w {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T : ℕ) {w : ι → ℝ}, (∀ f ∈ F, 0 ≤ w f) → ctxShtarkov eval F T w ≤ ∑ f ∈ F, w f | 0, w, hw => by simp only [ctxShtarkov] split_ifs with hF · exact Finset.sup'_le hF _ fun f hf => Finset.single_le_sum hw hf · rw [Finset.not_nonempty_iff_eq_empty.mp hF, Finset.sum_empty] | T + 1, w, hw => by simp only [ctxShtarkov] refine Finset.sup'_le Finset.univ_nonempty _ fun x _ => ?_ calc ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) ≤ ∑ y : β, ∑ f ∈ F, w f * eval f x y := Finset.sum_le_sum fun y _ => ctxShtarkov_le_sum_w hS T fun f hf => mul_nonneg (hw f hf) ((hS f hf x).1 y) _ = ∑ f ∈ F, ∑ y : β, w f * eval f x y := Finset.sum_comm _ = ∑ f ∈ F, w f * ∑ y : β, eval f x y := Finset.sum_congr rfl fun f _ => (Finset.mul_sum _ _ _).symm _ = ∑ f ∈ F, w f := Finset.sum_congr rfl fun f hf => by rw [(hS f hf x).2, mul_one] theorem ctxShtarkovUnif_le_card {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (T : ℕ) : ctxShtarkovUnif eval F T ≤ (F.card : ℝ) := by have h := ctxShtarkov_le_sum_w hS T (w := fun _ => (1 : ℝ)) (fun _ _ => zero_le_one) simpa [ctxShtarkovUnif] using h /-- **Exact Horizon Sub-Multiplicativity (`S_{T₁ + T₂}(F, w) ≤ S_{T₁}(F, w) * S_{T₂}(F, 1)`)**: hence `log S_T(F)` is subadditive in `T` for EVERY stochastic expert class `F`! -/ theorem ctxShtarkov_submul_horizon {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) : ∀ (T₁ T₂ : ℕ) {w : ι → ℝ}, (∀ f ∈ F, 0 ≤ w f) → ctxShtarkov eval F (T₁ + T₂) w ≤ ctxShtarkov eval F T₁ w * ctxShtarkovUnif eval F T₂ | 0, T₂, w, hw => by rw [zero_add] by_cases hF : F.Nonempty · have hmax_nn : 0 ≤ F.sup' hF w := by rcases hF with ⟨f0, hf0⟩; exact le_trans (hw f0 hf0) (Finset.le_sup' w hf0) have hle : ∀ f ∈ F, w f ≤ (F.sup' hF w) * 1 := fun f hf => by rw [mul_one]; exact Finset.le_sup' w hf calc ctxShtarkov eval F T₂ w ≤ ctxShtarkov eval F T₂ (fun _ => F.sup' hF w * 1) := ctxShtarkov_mono_w hS T₂ hle _ = F.sup' hF w * ctxShtarkov eval F T₂ (fun _ => 1) := ctxShtarkov_scale T₂ hmax_nn _ _ = ctxShtarkov eval F 0 w * ctxShtarkovUnif eval F T₂ := by simp only [ctxShtarkov, hF, ↓reduceDIte, ctxShtarkovUnif] · have hemp : F = ∅ := Finset.not_nonempty_iff_eq_empty.mp hF subst hemp have hzero : ctxShtarkov eval ∅ T₂ w = 0 := by have hle := ctxShtarkov_le_sum_w hS T₂ hw have hge := ctxShtarkov_nonneg hS T₂ hw simp only [Finset.sum_empty] at hle; linarith simp [ctxShtarkov, hzero] | T₁ + 1, T₂, w, hw => by rw [Nat.succ_add] simp only [ctxShtarkov] refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ calc ∑ y : β, ctxShtarkov eval F (T₁ + T₂) (fun f => w f * eval f x y) ≤ ∑ y : β, ctxShtarkov eval F T₁ (fun f => w f * eval f x y) * ctxShtarkovUnif eval F T₂ := Finset.sum_le_sum fun y _ => ctxShtarkov_submul_horizon hS T₁ T₂ fun f hf => mul_nonneg (hw f hf) ((hS f hf x).1 y) _ = (∑ y : β, ctxShtarkov eval F T₁ (fun f => w f * eval f x y)) * ctxShtarkovUnif eval F T₂ := (Finset.sum_mul _ _ _).symm _ ≤ _ := mul_le_mul_of_nonneg_right (Finset.le_sup' (f := fun x => ∑ y : β, ctxShtarkov eval F T₁ (fun f => w f * eval f x y)) hx) (ctxShtarkov_nonneg hS T₂ fun _ _ => zero_le_one) /-! ## Part 2: Exact Multi-Round Adaptive Contextual Log-Loss Game & Self-Dual cNML Saddle-Point -/ /-- A general adaptive probabilistic forecaster for horizon-`T` contextual log-loss: at remaining horizon `T + 1`, history `hist`, and current context `x`, outputs a distribution `pred hist x ∈ Δ(β)`. -/ structure LogForecaster (α β : Type*) [Fintype β] where pred : List (α × β) → α → β → ℝ nonneg : ∀ hist x y, 0 ≤ pred hist x y sum_one : ∀ hist x, ∑ y : β, pred hist x y = 1 /-- A general adaptive randomized adversary for horizon-`T` contextual log-loss: at remaining horizon `T + 1` and history `hist`, chooses a context `query T hist : α` and a label distribution `labelDist T hist ∈ Δ(β)`. -/ structure LogAdversary (α β : Type*) [Fintype β] where query : ℕ → List (α × β) → α labelDist : ℕ → List (α × β) → β → ℝ nonneg : ∀ T hist y, 0 ≤ labelDist T hist y sum_one : ∀ T hist, ∑ y : β, labelDist T hist y = 1 /-- Safe negative log-loss `if ν = 0 then 0 else ν * (-log p)` (avoids `0 * ∞`). -/ noncomputable def weightedNegLog (ν p : ℝ) : ℝ := if ν = 0 then 0 else ν * (-Real.log p) /-- Expected cumulative log-loss regret over `T` remaining rounds with current expert weights `w`, starting from history `hist`: - Base `T = 0`: `log (max_{f ∈ F} w f)` (the negative log-likelihood of the best hindsight expert with positive accumulated weight, negated so regret = `∑_t (-log P_t) - min_f (-log w_T(f))` `= ∑_t (-log P_t) + log (max_f w_T(f))`!). - Step `T + 1`: adversary picks `x = A.query T hist` and `ν = A.labelDist T hist`, expected regret is `∑_y ν y * (-log (P.pred hist x y) + expectedLogRegret T ...)`. -/ noncomputable def expectedLogRegret {α β ι : Type*} [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) (P : LogForecaster α β) (A : LogAdversary α β) : ℕ → List (α × β) → (ι → ℝ) → ℝ | 0, _, w => if hF : F.Nonempty then Real.log (F.sup' hF w) else 0 | T + 1, hist, w => let x := A.query T hist ∑ y : β, if A.labelDist T hist y = 0 then 0 else A.labelDist T hist y * (-Real.log (P.pred hist x y) + expectedLogRegret eval F P A T ((x, y) :: hist) (fun f => w f * eval f x y)) /-- Expected cumulative KL divergence of `P` from the adversary's conditional distributions along `A`. -/ noncomputable def expectedCumKL {α β : Type*} [Fintype β] (P : LogForecaster α β) (A : LogAdversary α β) : ℕ → List (α × β) → ℝ | 0, _ => 0 | T + 1, hist => let x := A.query T hist klDiv Finset.univ (A.labelDist T hist) (P.pred hist x) + ∑ y : β, A.labelDist T hist y * expectedCumKL P A T ((x, y) :: hist) /-- Pathwise expert weight update along a reverse-chronological history `hist`. -/ def histWeight {α β ι : Type*} (eval : ι → α → β → ℝ) (w₀ : ι → ℝ) : List (α × β) → ι → ℝ | [] => w₀ | (x, y) :: rest => fun f => histWeight eval w₀ rest f * eval f x y /-- **Contextual Normalized Maximum Likelihood (cNML) Forecaster** at fixed total horizon `T₀`: at remaining horizon `T + 1 = T₀ - hist.length`, computes the exact Shtarkov-normalized forecast `p*(y | w, x) = S_T(F, w * eval · x y) / ∑_{y'} S_T(F, w * eval · x y')`! -/ noncomputable def cNMLDist {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] (eval : ι → α → β → ℝ) (F : Finset ι) (T : ℕ) (w : ι → ℝ) (x : α) (y : β) : ℝ := let Z := ∑ y' : β, ctxShtarkov eval F T (fun f => w f * eval f x y') if Z = 0 then (1 : ℝ) / (Fintype.card β : ℝ) else ctxShtarkov eval F T (fun f => w f * eval f x y) / Z lemma cNMLDist_nonneg {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (T : ℕ) {w : ι → ℝ} (hw : ∀ f ∈ F, 0 ≤ w f) (x : α) (y : β) : 0 ≤ cNMLDist eval F T w x y := by dsimp only [cNMLDist] split_ifs with hZ · positivity · have hnn : ∀ y' : β, 0 ≤ ctxShtarkov eval F T (fun f => w f * eval f x y') := fun y' => ctxShtarkov_nonneg hS T fun f hf => mul_nonneg (hw f hf) ((hS f hf x).1 y') exact div_nonneg (hnn y) (Finset.sum_nonneg fun y' _ => hnn y') lemma cNMLDist_sum_one {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] (eval : ι → α → β → ℝ) (F : Finset ι) (T : ℕ) (w : ι → ℝ) (x : α) : ∑ y : β, cNMLDist eval F T w x y = 1 := by dsimp only [cNMLDist] split_ifs with hZ · rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one_div_cancel] exact Nat.cast_ne_zero.mpr Fintype.card_ne_zero · rw [← Finset.sum_div, div_self hZ] /-- Horizon-aware cNML forecaster for total horizon `T₀` and initial weight `w₀`. -/ noncomputable def cNMLForecaster {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] (eval : ι → α → β → ℝ) (F : Finset ι) (hS : IsStochClass eval F) (T₀ : ℕ) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) : LogForecaster α β where pred hist x y := cNMLDist eval F (T₀ - 1 - hist.length) (histWeight eval w₀ hist) x y nonneg hist x y := by have hhw : ∀ f ∈ F, 0 ≤ histWeight eval w₀ hist f := by induction hist with | nil => exact hw₀ | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) exact cNMLDist_nonneg hS _ hhw x y sum_one hist x := cNMLDist_sum_one eval F _ _ x /-- **Self-Dual Shtarkov–cNML Adversary**: at remaining horizon `T + 1`, chooses the worst-case maximizing context `x*` achieving `ctxShtarkov eval F (T + 1) w`, and plays the EXACT cNML distribution `ν* = cNMLDist eval F T w x*`! -/ noncomputable def cNMLQuery {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) (T : ℕ) (w : ι → ℝ) : α := (Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x : α => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y))).choose lemma cNMLQuery_spec {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] (eval : ι → α → β → ℝ) (F : Finset ι) (T : ℕ) (w : ι → ℝ) : ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f (cNMLQuery eval F T w) y) = ctxShtarkov eval F (T + 1) w := ((Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x : α => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y))).choose_spec.2).symm noncomputable def cNMLAdversary {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] (eval : ι → α → β → ℝ) (F : Finset ι) (hS : IsStochClass eval F) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) : LogAdversary α β where query T hist := cNMLQuery eval F T (histWeight eval w₀ hist) labelDist T hist y := cNMLDist eval F T (histWeight eval w₀ hist) (cNMLQuery eval F T (histWeight eval w₀ hist)) y nonneg T hist y := by have hhw : ∀ f ∈ F, 0 ≤ histWeight eval w₀ hist f := by induction hist with | nil => exact hw₀ | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) exact cNMLDist_nonneg hS T hhw _ y sum_one T hist := cNMLDist_sum_one eval F T _ _ /-- **Primal Upper Bound (`cNMLForecaster_regret_le`)**: For EVERY finite stochastic expert class `F`, EVERY adaptive adversary `A` (whose active branches on reachable histories keep positive Shtarkov weight), `cNMLForecaster` guarantees expected (and pathwise!) log-loss regret `≤ log (ctxShtarkov eval F T w)`! -/ theorem cNMLForecaster_regret_le {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (hF : F.Nonempty) (T₀ : ℕ) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) (A : LogAdversary α β) : ∀ (T : ℕ) (hist : List (α × β)), hist.length + T = T₀ → 0 < ctxShtarkov eval F T (histWeight eval w₀ hist) → (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T₀ → 0 < ctxShtarkov eval F (k + 1) (histWeight eval w₀ h') → ∀ y : β, A.labelDist k h' y ≠ 0 → 0 < ctxShtarkov eval F k (fun f => histWeight eval w₀ h' f * eval f (A.query k h') y)) → expectedLogRegret eval F (cNMLForecaster eval F hS T₀ w₀ hw₀) A T hist (histWeight eval w₀ hist) ≤ Real.log (ctxShtarkov eval F T (histWeight eval w₀ hist)) | 0, hist, _, _, _ => by simp only [expectedLogRegret, ctxShtarkov, hF, ↓reduceDIte] exact le_rfl | T + 1, hist, hlen, hpos, hA_supp => by simp only [expectedLogRegret] set x := A.query T hist set w := histWeight eval w₀ hist set Z := ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) have hZ_le : Z ≤ ctxShtarkov eval F (T + 1) w := Finset.le_sup' (f := fun x' => ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x' y)) (Finset.mem_univ x) have hT_eq : T₀ - 1 - hist.length = T := by omega have hhw : ∀ f ∈ F, 0 ≤ w f := by clear hlen hpos hA_supp hZ_le hT_eq induction hist with | nil => exact hw₀ | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) have hS_nn : ∀ y : β, 0 ≤ ctxShtarkov eval F T (fun f => w f * eval f x y) := fun y => ctxShtarkov_nonneg hS T fun f hf => mul_nonneg (hhw f hf) ((hS f hf x).1 y) have hZ_pos : 0 < Z := by have hex : ∃ y : β, A.labelDist T hist y ≠ 0 := by by_contra hall; push Not at hall have h0 := A.sum_one T hist simp [hall] at h0 rcases hex with ⟨y0, hy0⟩ have hpos0 := hA_supp T hist hlen hpos y0 hy0 exact lt_of_lt_of_le hpos0 (Finset.single_le_sum (fun y _ => hS_nn y) (Finset.mem_univ y0)) have hterm_le : ∀ y : β, (if A.labelDist T hist y = 0 then 0 else A.labelDist T hist y * (-Real.log ((cNMLForecaster eval F hS T₀ w₀ hw₀).pred hist x y) + expectedLogRegret eval F (cNMLForecaster eval F hS T₀ w₀ hw₀) A T ((x, y) :: hist) (fun f => w f * eval f x y))) ≤ A.labelDist T hist y * Real.log Z := by intro y by_cases hν : A.labelDist T hist y = 0 · simp [hν] · simp only [hν, ↓reduceIte] have hSy_pos : 0 < ctxShtarkov eval F T (fun f => w f * eval f x y) := hA_supp T hist hlen hpos y hν have hih : expectedLogRegret eval F (cNMLForecaster eval F hS T₀ w₀ hw₀) A T ((x, y) :: hist) (fun f => w f * eval f x y) ≤ Real.log (ctxShtarkov eval F T (fun f => w f * eval f x y)) := cNMLForecaster_regret_le hS hF T₀ w₀ hw₀ A T ((x, y) :: hist) (by simp; omega) hSy_pos hA_supp have hpred : (cNMLForecaster eval F hS T₀ w₀ hw₀).pred hist x y = ctxShtarkov eval F T (fun f => w f * eval f x y) / Z := by dsimp only [cNMLForecaster, cNMLDist] rw [hT_eq, if_neg (ne_of_gt hZ_pos)] rw [hpred, Real.log_div (ne_of_gt hSy_pos) (ne_of_gt hZ_pos)] have hν_nn : 0 ≤ A.labelDist T hist y := A.nonneg T hist y have hbr : -(Real.log (ctxShtarkov eval F T (fun f => w f * eval f x y)) - Real.log Z) + expectedLogRegret eval F (cNMLForecaster eval F hS T₀ w₀ hw₀) A T ((x, y) :: hist) (fun f => w f * eval f x y) ≤ Real.log Z := by linarith exact mul_le_mul_of_nonneg_left hbr hν_nn calc ∑ y : β, (if A.labelDist T hist y = 0 then 0 else A.labelDist T hist y * (-Real.log ((cNMLForecaster eval F hS T₀ w₀ hw₀).pred hist x y) + expectedLogRegret eval F (cNMLForecaster eval F hS T₀ w₀ hw₀) A T ((x, y) :: hist) (fun f => w f * eval f x y))) ≤ ∑ y : β, A.labelDist T hist y * Real.log Z := Finset.sum_le_sum fun y _ => hterm_le y _ = (∑ y : β, A.labelDist T hist y) * Real.log Z := (Finset.sum_mul _ _ _).symm _ = Real.log Z := by rw [A.sum_one T hist, one_mul] _ ≤ Real.log (ctxShtarkov eval F (T + 1) w) := Real.log_le_log hZ_pos hZ_le /-- **Exact Self-Dual Trajectory KL-Excess Identity (`cNMLAdversary_exact_kl_excess`)**: Against the self-dual Shtarkov–cNML adversary `A* = cNMLAdversary`, EVERY forecaster `P` (assigning positive probability on reachable active cNML branches) satisfies the EXACT identity: `expectedLogRegret T F P A* = log (ctxShtarkov T F w) + expectedCumKL P A*`! -/ theorem cNMLAdversary_exact_kl_excess {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (hF : F.Nonempty) (T₀ : ℕ) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) (P : LogForecaster α β) : ∀ (T : ℕ) (hist : List (α × β)), hist.length + T = T₀ → 0 < ctxShtarkov eval F T (histWeight eval w₀ hist) → (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T₀ → 0 < ctxShtarkov eval F (k + 1) (histWeight eval w₀ h') → ∀ y : β, (cNMLAdversary eval F hS w₀ hw₀).labelDist k h' y ≠ 0 → 0 < P.pred h' ((cNMLAdversary eval F hS w₀ hw₀).query k h') y) → expectedLogRegret eval F P (cNMLAdversary eval F hS w₀ hw₀) T hist (histWeight eval w₀ hist) = Real.log (ctxShtarkov eval F T (histWeight eval w₀ hist)) + expectedCumKL P (cNMLAdversary eval F hS w₀ hw₀) T hist | 0, hist, _, _, _ => by simp only [expectedLogRegret, expectedCumKL, ctxShtarkov, hF, ↓reduceDIte, add_zero] | T + 1, hist, hlen, hpos, hP_pos => by set A := cNMLAdversary eval F hS w₀ hw₀ set w := histWeight eval w₀ hist set x := A.query T hist set u : β → ℝ := fun y => ctxShtarkov eval F T (fun f => w f * eval f x y) have hZ_eq : ∑ y : β, u y = ctxShtarkov eval F (T + 1) w := cNMLQuery_spec eval F T w have hZ_pos : 0 < ∑ y : β, u y := hZ_eq.symm ▸ hpos have hhw : ∀ f ∈ F, 0 ≤ w f := by clear hlen hpos hP_pos hZ_eq hZ_pos induction hist with | nil => exact hw₀ | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) have hu0 : ∀ y : β, 0 ≤ u y := fun y => ctxShtarkov_nonneg hS T fun f hf => mul_nonneg (hhw f hf) ((hS f hf x).1 y) have hdist_eq : ∀ y : β, A.labelDist T hist y = u y / (∑ y' : β, u y') := fun y => by have hZ_ne : (∑ y' : β, u y') ≠ 0 := ne_of_gt hZ_pos dsimp only [A, cNMLAdversary, cNMLDist] change (if (∑ y' : β, u y') = 0 then (1 : ℝ) / (Fintype.card β : ℝ) else u y / ∑ y' : β, u y') = _ rw [if_neg hZ_ne] have hsupp_P : ∀ y ∈ (Finset.univ : Finset β), u y ≠ 0 → 0 < P.pred hist x y := fun y _ huy => by apply hP_pos T hist hlen hpos y rw [hdist_eq y] exact div_ne_zero huy (ne_of_gt hZ_pos) have hid := logLoss_selfDual_kl_identity (S := Finset.univ) (u := u) (p := P.pred hist x) (fun y _ => hu0 y) hZ_pos hsupp_P dsimp only at hid simp only [expectedLogRegret, expectedCumKL] have hsplit : ∀ y : β, (if A.labelDist T hist y = 0 then 0 else A.labelDist T hist y * (-Real.log (P.pred hist x y) + expectedLogRegret eval F P A T ((x, y) :: hist) (fun f => w f * eval f x y))) = (if u y = 0 then 0 else (u y / ∑ y' : β, u y') * (-Real.log (P.pred hist x y) + Real.log (u y))) + A.labelDist T hist y * expectedCumKL P A T ((x, y) :: hist) := by intro y rw [hdist_eq y] by_cases huy : u y = 0 · simp [huy] · have hdiv_ne : u y / ∑ y' : β, u y' ≠ 0 := div_ne_zero huy (ne_of_gt hZ_pos) have huy_pos : 0 < u y := lt_of_le_of_ne (hu0 y) (Ne.symm huy) have hih : expectedLogRegret eval F P A T ((x, y) :: hist) (fun f => w f * eval f x y) = Real.log (u y) + expectedCumKL P A T ((x, y) :: hist) := cNMLAdversary_exact_kl_excess hS hF T₀ w₀ hw₀ P T ((x, y) :: hist) (by simp; omega) huy_pos hP_pos simp only [hdiv_ne, huy, ↓reduceIte] rw [hih]; ring have hkl_congr : klDiv Finset.univ (fun y => u y / ∑ y' : β, u y') (P.pred hist x) = klDiv Finset.univ (A.labelDist T hist) (P.pred hist x) := Finset.sum_congr rfl fun y _ => by rw [hdist_eq y] rw [Finset.sum_congr rfl fun y _ => hsplit y, Finset.sum_add_distrib, hid, hkl_congr, hZ_eq] ring lemma expectedCumKL_cNML_nonneg {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (T₀ : ℕ) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) (P : LogForecaster α β) : ∀ (T : ℕ) (hist : List (α × β)), hist.length + T = T₀ → 0 < ctxShtarkov eval F T (histWeight eval w₀ hist) → (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T₀ → 0 < ctxShtarkov eval F (k + 1) (histWeight eval w₀ h') → ∀ y : β, (cNMLAdversary eval F hS w₀ hw₀).labelDist k h' y ≠ 0 → 0 < P.pred h' ((cNMLAdversary eval F hS w₀ hw₀).query k h') y) → 0 ≤ expectedCumKL P (cNMLAdversary eval F hS w₀ hw₀) T hist | 0, _, _, _, _ => le_rfl | T + 1, hist, hlen, hpos, hP => by set A := cNMLAdversary eval F hS w₀ hw₀ set w := histWeight eval w₀ hist set x := A.query T hist have hZ_eq : ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) = ctxShtarkov eval F (T + 1) w := cNMLQuery_spec eval F T w have hZ_pos : 0 < ∑ y : β, ctxShtarkov eval F T (fun f => w f * eval f x y) := hZ_eq.symm ▸ hpos simp only [expectedCumKL] refine add_nonneg ?_ ?_ · exact klDiv_nonneg (fun y _ => A.nonneg T hist y) (fun y _ => P.nonneg hist _ y) (A.sum_one T hist) (P.sum_one hist _) (fun y _ h => hP T hist hlen hpos y h) · refine Finset.sum_nonneg fun y _ => ?_ by_cases hdy : A.labelDist T hist y = 0 · rw [hdy, zero_mul] · have huy_pos : 0 < ctxShtarkov eval F T (fun f => w f * eval f x y) := by have hhw : ∀ f ∈ F, 0 ≤ w f := by clear hlen hpos hP hZ_eq hZ_pos hdy induction hist with | nil => exact hw₀ | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) have hnn := ctxShtarkov_nonneg hS T fun f hf => mul_nonneg (hhw f hf) ((hS f hf x).1 y) by_contra hle; push Not at hle have h0 : ctxShtarkov eval F T (fun f => w f * eval f x y) = 0 := le_antisymm hle hnn dsimp only [A, cNMLAdversary, cNMLDist] at hdy change (if (∑ y' : β, ctxShtarkov eval F T (fun f => w f * eval f x y')) = 0 then (1 : ℝ) / (Fintype.card β : ℝ) else ctxShtarkov eval F T (fun f => w f * eval f x y) / ∑ y' : β, ctxShtarkov eval F T (fun f => w f * eval f x y')) ≠ 0 at hdy rw [if_neg (ne_of_gt hZ_pos), h0, zero_div] at hdy exact hdy rfl exact mul_nonneg (A.nonneg T hist y) (expectedCumKL_cNML_nonneg hS T₀ w₀ hw₀ P T ((x, y) :: hist) (by simp; omega) huy_pos hP) /-- **Dual Lower Bound (`cNMLAdversary_regret_ge`)**: Every forecaster `P` suffers expected regret `≥ log (ctxShtarkov T F w)` against `cNMLAdversary`. -/ theorem cNMLAdversary_regret_ge {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (hF : F.Nonempty) (w₀ : ι → ℝ) (hw₀ : ∀ f ∈ F, 0 ≤ w₀ f) (P : LogForecaster α β) (T : ℕ) (hpos : 0 < ctxShtarkov eval F T w₀) (hP_pos : ∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval w₀ h') → ∀ y : β, (cNMLAdversary eval F hS w₀ hw₀).labelDist k h' y ≠ 0 → 0 < P.pred h' ((cNMLAdversary eval F hS w₀ hw₀).query k h') y) : Real.log (ctxShtarkov eval F T w₀) ≤ expectedLogRegret eval F P (cNMLAdversary eval F hS w₀ hw₀) T [] w₀ := by have heq := cNMLAdversary_exact_kl_excess hS hF T w₀ hw₀ P T [] (by simp) hpos hP_pos have hkl := expectedCumKL_cNML_nonneg hS T w₀ hw₀ P T [] (by simp) hpos hP_pos dsimp only [histWeight] at heq linarith /-- **EXACT MULTI-ROUND CONTEXTUAL LOG-LOSS MINIMAX SADDLE-POINT THEOREM (cNML = Self-Dual Value)**: For EVERY finite nonempty stochastic expert class `F` and EVERY horizon `T`: - `cNMLForecaster` achieves regret `≤ log (ctxShtarkovUnif eval F T)` against EVERY admissible adversary `A`, - `cNMLAdversary` forces regret `≥ log (ctxShtarkovUnif eval F T)` against EVERY admissible forecaster `P`, - and at the saddle point `(cNMLForecaster, cNMLAdversary)`, exact equality holds! -/ theorem online_logloss_cNML_minimax_exact {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] [Nonempty β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (hF : F.Nonempty) (T : ℕ) : let PStar := cNMLForecaster eval F hS T (fun _ => 1) (fun _ _ => zero_le_one) let AStar := cNMLAdversary eval F hS (fun _ => 1) (fun _ _ => zero_le_one) (∀ A : LogAdversary α β, (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, A.labelDist k h' y ≠ 0 → 0 < ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (A.query k h') y)) → expectedLogRegret eval F PStar A T [] (fun _ => 1) ≤ Real.log (ctxShtarkovUnif eval F T)) ∧ (∀ P : LogForecaster α β, (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, AStar.labelDist k h' y ≠ 0 → 0 < P.pred h' (AStar.query k h') y) → Real.log (ctxShtarkovUnif eval F T) ≤ expectedLogRegret eval F P AStar T [] (fun _ => 1)) ∧ expectedLogRegret eval F PStar AStar T [] (fun _ => 1) = Real.log (ctxShtarkovUnif eval F T) := by intro PStar AStar have hpos : 0 < ctxShtarkovUnif eval F T := ctxShtarkov_pos hS T (by rcases hF with ⟨f0, hf0⟩; exact ⟨f0, hf0, zero_lt_one⟩) have hAStar_supp : ∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, AStar.labelDist k h' y ≠ 0 → 0 < ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y) := by intro k h' hlen hpos_k y hne have hZ_eq : ∑ y' : β, ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y') = ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') := cNMLQuery_spec eval F k (histWeight eval (fun _ => 1) h') have hZ_pos : 0 < ∑ y' : β, ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y') := hZ_eq.symm ▸ hpos_k have hhw : ∀ f ∈ F, 0 ≤ histWeight eval (fun _ => 1) h' f := by clear hlen hpos_k hne hZ_eq hZ_pos induction h' with | nil => intro _ _; exact zero_le_one | cons p rest ih => intro f hf; exact mul_nonneg (ih f hf) ((hS f hf p.1).1 p.2) have hnn := ctxShtarkov_nonneg hS k fun f hf => mul_nonneg (hhw f hf) ((hS f hf (AStar.query k h')).1 y) by_contra hle; push Not at hle have h0 : ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y) = 0 := le_antisymm hle hnn dsimp only [AStar, cNMLAdversary, cNMLDist] at hne change (if (∑ y' : β, ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y')) = 0 then (1 : ℝ) / (Fintype.card β : ℝ) else ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y) / ∑ y' : β, ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (AStar.query k h') y')) ≠ 0 at hne rw [if_neg (ne_of_gt hZ_pos), h0, zero_div] at hne exact hne rfl have hPStar_pos : ∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, AStar.labelDist k h' y ≠ 0 → 0 < PStar.pred h' (AStar.query k h') y := by intro k h' hlen hpos_k y hne have hT_eq : T - 1 - h'.length = k := by omega have hpred_eq : PStar.pred h' (AStar.query k h') y = AStar.labelDist k h' y := by dsimp only [PStar, AStar, cNMLForecaster, cNMLAdversary]; rw [hT_eq] rw [hpred_eq] exact lt_of_le_of_ne (AStar.nonneg k h' y) (Ne.symm hne) have hup : ∀ A : LogAdversary α β, (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, A.labelDist k h' y ≠ 0 → 0 < ctxShtarkov eval F k (fun f => histWeight eval (fun _ => 1) h' f * eval f (A.query k h') y)) → expectedLogRegret eval F PStar A T [] (fun _ => 1) ≤ Real.log (ctxShtarkovUnif eval F T) := fun A hA => cNMLForecaster_regret_le hS hF T (fun _ => 1) (fun _ _ => zero_le_one) A T [] (by simp) hpos hA have hlo : ∀ P : LogForecaster α β, (∀ (k : ℕ) (h' : List (α × β)), h'.length + (k + 1) = T → 0 < ctxShtarkov eval F (k + 1) (histWeight eval (fun _ => 1) h') → ∀ y : β, AStar.labelDist k h' y ≠ 0 → 0 < P.pred h' (AStar.query k h') y) → Real.log (ctxShtarkovUnif eval F T) ≤ expectedLogRegret eval F P AStar T [] (fun _ => 1) := fun P hP => cNMLAdversary_regret_ge hS hF (fun _ => 1) (fun _ _ => zero_le_one) P T hpos hP exact ⟨hup, hlo, le_antisymm (hup AStar hAStar_supp) (hlo PStar hPStar_pos)⟩ /-- **Iterated Horizon Sub-Multiplicativity & Window-`W` Block-Reset Bound**: `log S_{q * W + r}(F) ≤ q * log S_W(F) + log S_r(F)` for EVERY stochastic expert class `F`, giving the exact block-memory-reset coding guarantee! -/ theorem ctxShtarkovUnif_block_reset_bound {α β ι : Type*} [Fintype α] [Nonempty α] [Fintype β] {eval : ι → α → β → ℝ} {F : Finset ι} (hS : IsStochClass eval F) (hF : F.Nonempty) (W : ℕ) : ∀ (q r : ℕ), Real.log (ctxShtarkovUnif eval F (q * W + r)) ≤ (q : ℝ) * Real.log (ctxShtarkovUnif eval F W) + Real.log (ctxShtarkovUnif eval F r) := by have hpos : ∀ T : ℕ, 0 < ctxShtarkovUnif eval F T := fun T => ctxShtarkov_pos hS T (by rcases hF with ⟨f0, hf0⟩; exact ⟨f0, hf0, zero_lt_one⟩) have hmul : ∀ q r : ℕ, ctxShtarkovUnif eval F (q * W + r) ≤ ctxShtarkovUnif eval F W ^ q * ctxShtarkovUnif eval F r := by intro q induction q with | zero => intro r; simp | succ q ih => intro r have hrew : (q + 1) * W + r = W + (q * W + r) := by ring rw [hrew, pow_succ', mul_assoc] calc ctxShtarkovUnif eval F (W + (q * W + r)) ≤ ctxShtarkovUnif eval F W * ctxShtarkovUnif eval F (q * W + r) := ctxShtarkov_submul_horizon hS W (q * W + r) (fun _ _ => zero_le_one) _ ≤ ctxShtarkovUnif eval F W * (ctxShtarkovUnif eval F W ^ q * ctxShtarkovUnif eval F r) := mul_le_mul_of_nonneg_left (ih r) (le_of_lt (hpos W)) intro q r have hle := Real.log_le_log (hpos _) (hmul q r) rw [Real.log_mul (ne_of_gt (pow_pos (hpos W) q)) (ne_of_gt (hpos r)), Real.log_pow] at hle exact hle /-! ## Part 3: Stochastic 2-Expert Shtarkov–TV–Bhattacharyya–Jensen–Shannon Exact Duality & Redundancy–Capacity Separation -/ /-- Total variation distance `TV(p, q) = (1/2) * ∑_y |p y - q y|`. -/ noncomputable def tvDist {β : Type*} [Fintype β] (p q : β → ℝ) : ℝ := (1 / 2 : ℝ) * ∑ y : β, |p y - q y| /-- Bhattacharyya coefficient `BC(p, q) = ∑_y √(p y * q y)`. -/ noncomputable def bhattCoeff {β : Type*} [Fintype β] (p q : β → ℝ) : ℝ := ∑ y : β, Real.sqrt (p y * q y) /-- Jensen–Shannon divergence `JS(p, q) = (1/2) * (D_KL(p ‖ m) + D_KL(q ‖ m))` where `m = (p + q) / 2`. -/ noncomputable def jsDiv {β : Type*} [Fintype β] (p q : β → ℝ) : ℝ := let m : β → ℝ := fun y => (p y + q y) / 2 (1 / 2 : ℝ) * (klDiv Finset.univ p m + klDiv Finset.univ q m) /-- Two-expert evaluation map indexed by `Bool` (`false ↦ f₁`, `true ↦ f₂`). -/ def twoExpEval {α β : Type*} (f₁ f₂ : α → β → ℝ) : Bool → α → β → ℝ := fun b x y => if b then f₂ x y else f₁ x y /-- Adaptive `T`-round unnormalized total variation between two stochastic experts `f₁, f₂`. -/ noncomputable def adaptTVAux {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f₁ f₂ : α → β → ℝ) : ℕ → ℝ → ℝ → ℝ | 0, a, b => |a - b| | T + 1, a, b => Finset.univ.sup' Finset.univ_nonempty fun x : α => ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) /-- Adaptive `T`-round total variation distance `TV_T^adapt(f₁, f₂) = (1/2) * adaptTVAux T 1 1`. -/ noncomputable def adaptTV {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f₁ f₂ : α → β → ℝ) (T : ℕ) : ℝ := (1 / 2 : ℝ) * adaptTVAux f₁ f₂ T 1 1 /-- Adaptive `T`-round minimum Bhattacharyya coefficient between `f₁` and `f₂`. -/ noncomputable def adaptBC {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f₁ f₂ : α → β → ℝ) : ℕ → ℝ → ℝ → ℝ | 0, a, b => Real.sqrt (a * b) | T + 1, a, b => Finset.univ.inf' Finset.univ_nonempty fun x : α => ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) lemma ctxShtarkov_two_experts_aux {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, (∀ y : β, 0 ≤ f₁ x y) ∧ ∑ y : β, f₁ x y = 1) (hf₂ : ∀ x : α, (∀ y : β, 0 ≤ f₂ x y) ∧ ∑ y : β, f₂ x y = 1) : ∀ (T : ℕ) (a b : ℝ), ctxShtarkov (twoExpEval f₁ f₂) Finset.univ T (fun c => if c then b else a) = (a + b + adaptTVAux f₁ f₂ T a b) / 2 | 0, a, b => by simp only [ctxShtarkov, Finset.univ_nonempty, ↓reduceDIte, adaptTVAux] have hsup : (Finset.univ : Finset Bool).sup' Finset.univ_nonempty (fun c => if c then b else a) = max a b := by apply le_antisymm · refine Finset.sup'_le Finset.univ_nonempty _ fun c _ => ?_ cases c <;> simp · exact max_le (Finset.le_sup' (f := fun c : Bool => if c then b else a) (Finset.mem_univ false)) (Finset.le_sup' (f := fun c : Bool => if c then b else a) (Finset.mem_univ true)) rw [hsup, max_def] split_ifs with h · rw [abs_of_nonpos (sub_nonpos.mpr h)]; ring · rw [abs_of_pos (sub_pos.mpr (not_le.mp h))]; ring | T + 1, a, b => by simp only [ctxShtarkov, adaptTVAux] have hstep : ∀ x : α, (∑ y : β, ctxShtarkov (twoExpEval f₁ f₂) Finset.univ T (fun c => (if c then b else a) * twoExpEval f₁ f₂ c x y)) = (a + b + ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) / 2 := by intro x have hterm : ∀ y : β, ctxShtarkov (twoExpEval f₁ f₂) Finset.univ T (fun c => (if c then b else a) * twoExpEval f₁ f₂ c x y) = (a * f₁ x y + b * f₂ x y + adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) / 2 := fun y => by have hcongr : (fun c : Bool => (if c then b else a) * twoExpEval f₁ f₂ c x y) = (fun c : Bool => if c then b * f₂ x y else a * f₁ x y) := by ext c; cases c <;> simp [twoExpEval] rw [hcongr, ctxShtarkov_two_experts_aux hf₁ hf₂ T] rw [Finset.sum_congr rfl fun y _ => hterm y, ← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, (hf₁ x).2, (hf₂ x).2, mul_one, mul_one] simp_rw [hstep] apply le_antisymm · refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ have hle := Finset.le_sup' (f := fun x : α => ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) hx linarith · rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x : α => ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) with ⟨x0, hx0, heq⟩ rw [heq] exact Finset.le_sup' (f := fun x : α => (a + b + ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) / 2) hx0 /-- **Exact `T`-Round 2-Expert Contextual Shtarkov–TV Identity**: For EVERY `T : ℕ` and ANY two stochastic experts `f₁, f₂`: `ctxShtarkovUnif (twoExpEval f₁ f₂) Finset.univ T = 1 + adaptTV f₁ f₂ T`! -/ theorem ctxShtarkov_two_experts_eq_one_add_adaptTV {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, (∀ y : β, 0 ≤ f₁ x y) ∧ ∑ y : β, f₁ x y = 1) (hf₂ : ∀ x : α, (∀ y : β, 0 ≤ f₂ x y) ∧ ∑ y : β, f₂ x y = 1) (T : ℕ) : ctxShtarkovUnif (twoExpEval f₁ f₂) Finset.univ T = 1 + adaptTV f₁ f₂ T := by have h := ctxShtarkov_two_experts_aux hf₁ hf₂ T 1 1 have hw : (fun c : Bool => if c then (1 : ℝ) else 1) = (fun _ => (1 : ℝ)) := by ext c; cases c <;> rfl rw [hw] at h dsimp only [ctxShtarkovUnif, adaptTV] linarith /-- **Exact 1-Round 2-Expert Shtarkov Formula (`S_1({f₁, f₂}) = 1 + max_x TV(f₁ x, f₂ x)`)**. -/ theorem ctxShtarkov_two_experts_one_round {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, (∀ y : β, 0 ≤ f₁ x y) ∧ ∑ y : β, f₁ x y = 1) (hf₂ : ∀ x : α, (∀ y : β, 0 ≤ f₂ x y) ∧ ∑ y : β, f₂ x y = 1) : ctxShtarkovUnif (twoExpEval f₁ f₂) Finset.univ 1 = 1 + Finset.univ.sup' Finset.univ_nonempty (fun x : α => tvDist (f₁ x) (f₂ x)) := by rw [ctxShtarkov_two_experts_eq_one_add_adaptTV hf₁ hf₂ 1] dsimp only [adaptTV, adaptTVAux, tvDist] simp_rw [one_mul] congr 1 apply le_antisymm · rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x : α => ∑ y : β, |f₁ x y - f₂ x y|) with ⟨x0, hx0, heq⟩ rw [heq]; exact Finset.le_sup' (f := fun x : α => (1 / 2 : ℝ) * ∑ y : β, |f₁ x y - f₂ x y|) hx0 · refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ exact mul_le_mul_of_nonneg_left (Finset.le_sup' (f := fun x : α => ∑ y : β, |f₁ x y - f₂ x y|) hx) (by norm_num) lemma adaptBC_exact_pow {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, ∀ y : β, 0 ≤ f₁ x y) (hf₂ : ∀ x : α, ∀ y : β, 0 ≤ f₂ x y) : ∀ (T : ℕ) {a b : ℝ}, 0 ≤ a → 0 ≤ b → adaptBC f₁ f₂ T a b = Real.sqrt (a * b) * (Finset.univ.inf' Finset.univ_nonempty (fun x : α => bhattCoeff (f₁ x) (f₂ x))) ^ T | 0, a, b, _, _ => by simp [adaptBC] | T + 1, a, b, ha, hb => by set ρ := Finset.univ.inf' Finset.univ_nonempty (fun x : α => bhattCoeff (f₁ x) (f₂ x)) have hρ_nn : 0 ≤ ρ := Finset.le_inf' Finset.univ_nonempty _ fun x _ => Finset.sum_nonneg fun y _ => Real.sqrt_nonneg _ simp only [adaptBC] have hstep : ∀ x : α, (∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) = Real.sqrt (a * b) * bhattCoeff (f₁ x) (f₂ x) * ρ ^ T := by intro x have hterm : ∀ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) = Real.sqrt (a * b) * Real.sqrt (f₁ x y * f₂ x y) * ρ ^ T := fun y => by rw [adaptBC_exact_pow hf₁ hf₂ T (mul_nonneg ha (hf₁ x y)) (mul_nonneg hb (hf₂ x y))] have hmul : a * f₁ x y * (b * f₂ x y) = (a * b) * (f₁ x y * f₂ x y) := by ring rw [hmul, Real.sqrt_mul (mul_nonneg ha hb)] rw [Finset.sum_congr rfl fun y _ => hterm y, ← Finset.sum_mul, ← Finset.mul_sum]; rfl simp_rw [hstep] rw [pow_succ', ← mul_assoc] apply le_antisymm · rcases Finset.exists_mem_eq_inf' Finset.univ_nonempty (fun x : α => bhattCoeff (f₁ x) (f₂ x)) with ⟨x0, hx0, heq⟩ calc Finset.univ.inf' Finset.univ_nonempty (fun x : α => Real.sqrt (a * b) * bhattCoeff (f₁ x) (f₂ x) * ρ ^ T) ≤ Real.sqrt (a * b) * bhattCoeff (f₁ x0) (f₂ x0) * ρ ^ T := Finset.inf'_le _ hx0 _ = Real.sqrt (a * b) * ρ * ρ ^ T := by rw [← heq] · refine Finset.le_inf' Finset.univ_nonempty _ fun x hx => ?_ have hle : ρ ≤ bhattCoeff (f₁ x) (f₂ x) := Finset.inf'_le _ hx exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hle (Real.sqrt_nonneg _)) (pow_nonneg hρ_nn T) lemma adaptTVAux_bhatt_bounds {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, (∀ y : β, 0 ≤ f₁ x y) ∧ ∑ y : β, f₁ x y = 1) (hf₂ : ∀ x : α, (∀ y : β, 0 ≤ f₂ x y) ∧ ∑ y : β, f₂ x y = 1) : ∀ (T : ℕ) {a b : ℝ}, 0 ≤ a → 0 ≤ b → (a + b - 2 * adaptBC f₁ f₂ T a b ≤ adaptTVAux f₁ f₂ T a b) ∧ (adaptTVAux f₁ f₂ T a b ≤ Real.sqrt ((a + b) ^ 2 - 4 * adaptBC f₁ f₂ T a b ^ 2)) ∧ (2 * adaptBC f₁ f₂ T a b ≤ a + b) | 0, a, b, ha, hb => by simp only [adaptBC, adaptTVAux] have hsq : Real.sqrt (a * b) ^ 2 = a * b := Real.sq_sqrt (mul_nonneg ha hb) have ham : 2 * Real.sqrt (a * b) ≤ a + b := by have : 0 ≤ (Real.sqrt a - Real.sqrt b) ^ 2 := sq_nonneg _ have hmul : Real.sqrt (a * b) = Real.sqrt a * Real.sqrt b := Real.sqrt_mul ha b rw [hmul] nlinarith [Real.sq_sqrt ha, Real.sq_sqrt hb] refine ⟨?_, ?_, ham⟩ · rcases le_total a b with h | h · rw [abs_of_nonpos (sub_nonpos.mpr h)] have : a ≤ Real.sqrt (a * b) := by rw [Real.le_sqrt ha (mul_nonneg ha hb)]; nlinarith linarith · rw [abs_of_nonneg (sub_nonneg.mpr h)] have : b ≤ Real.sqrt (a * b) := by rw [Real.le_sqrt hb (mul_nonneg ha hb)]; nlinarith linarith · rw [Real.le_sqrt (abs_nonneg _) (by rw [hsq]; nlinarith [sq_nonneg (a - b)])] rw [sq_abs, hsq]; linarith | T + 1, a, b, ha, hb => by simp only [adaptBC, adaptTVAux] have hsum_bc_le : ∀ x : α, 2 * ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ≤ a + b := fun x => by calc 2 * ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) = ∑ y : β, 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := Finset.mul_sum _ _ _ _ ≤ ∑ y : β, (a * f₁ x y + b * f₂ x y) := Finset.sum_le_sum fun y _ => (adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y))).2.2 _ = a * ∑ y : β, f₁ x y + b * ∑ y : β, f₂ x y := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum] _ = a + b := by rw [(hf₁ x).2, (hf₂ x).2, mul_one, mul_one] have hinf_le : 2 * Finset.univ.inf' Finset.univ_nonempty (fun x : α => ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) ≤ a + b := by obtain ⟨x0⟩ := ‹Nonempty α› exact le_trans (mul_le_mul_of_nonneg_left (Finset.inf'_le _ (Finset.mem_univ x0)) (by norm_num)) (hsum_bc_le x0) have hbc_nn : ∀ x : α, ∀ y : β, 0 ≤ adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := fun x y => by rw [adaptBC_exact_pow (fun x => (hf₁ x).1) (fun x => (hf₂ x).1) T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y))] exact mul_nonneg (Real.sqrt_nonneg _) (pow_nonneg (Finset.le_inf' Finset.univ_nonempty _ fun x' _ => Finset.sum_nonneg fun y' _ => Real.sqrt_nonneg _) T) refine ⟨?_, ?_, hinf_le⟩ · rcases Finset.exists_mem_eq_inf' Finset.univ_nonempty (fun x : α => ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) with ⟨x0, hx0, heq⟩ rw [heq] refine le_trans ?_ (Finset.le_sup' (f := fun x : α => ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) hx0) calc a + b - 2 * ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x0 y) (b * f₂ x0 y) = ∑ y : β, (a * f₁ x0 y + b * f₂ x0 y - 2 * adaptBC f₁ f₂ T (a * f₁ x0 y) (b * f₂ x0 y)) := by rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, (hf₁ x0).2, (hf₂ x0).2, mul_one, mul_one] _ ≤ ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x0 y) (b * f₂ x0 y) := Finset.sum_le_sum fun y _ => (adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x0).1 y)) (mul_nonneg hb ((hf₂ x0).1 y))).1 · refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ set B := ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) have hB_nn : 0 ≤ B := Finset.sum_nonneg fun y _ => hbc_nn x y have hinf_le_B : Finset.univ.inf' Finset.univ_nonempty (fun x' : α => ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x' y) (b * f₂ x' y)) ≤ B := Finset.inf'_le _ hx have hinf_nn : 0 ≤ Finset.univ.inf' Finset.univ_nonempty (fun x' : α => ∑ y : β, adaptBC f₁ f₂ T (a * f₁ x' y) (b * f₂ x' y)) := Finset.le_inf' Finset.univ_nonempty _ fun x' _ => Finset.sum_nonneg fun y _ => hbc_nn x' y -- Cauchy-Schwarz on √(a_y + b_y - 2 c_y) * √(a_y + b_y + 2 c_y)! have hcs_sq : (∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) ^ 2 ≤ (a + b) ^ 2 - 4 * B ^ 2 := by set u : β → ℝ := fun y => Real.sqrt (a * f₁ x y + b * f₂ x y - 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) set v : β → ℝ := fun y => Real.sqrt (a * f₁ x y + b * f₂ x y + 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) have hterm_le : ∀ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ≤ u y * v y := fun y => by have hih := adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y)) have hsub_nn : 0 ≤ a * f₁ x y + b * f₂ x y - 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := by linarith [hih.2.2] have hprod : (a * f₁ x y + b * f₂ x y) ^ 2 - 4 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ^ 2 = (a * f₁ x y + b * f₂ x y - 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) * (a * f₁ x y + b * f₂ x y + 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) := by ring calc adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ≤ Real.sqrt ((a * f₁ x y + b * f₂ x y) ^ 2 - 4 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ^ 2) := hih.2.1 _ = u y * v y := by rw [hprod, Real.sqrt_mul hsub_nn] have htv_nn : ∀ y : β, 0 ≤ adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := fun y => by have hih := adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y)) linarith [hih.1, hih.2.2] have hsum_le : ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) ≤ ∑ y : β, u y * v y := Finset.sum_le_sum fun y _ => hterm_le y have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset β) u v have hu_sq : ∑ y : β, u y ^ 2 = a + b - 2 * B := by have h1 : ∀ y : β, u y ^ 2 = a * f₁ x y + b * f₂ x y - 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := fun y => by have hih := adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y)) exact Real.sq_sqrt (by linarith [hih.2.2]) rw [Finset.sum_congr rfl fun y _ => h1 y, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, (hf₁ x).2, (hf₂ x).2, mul_one, mul_one] have hv_sq : ∑ y : β, v y ^ 2 = a + b + 2 * B := by have h1 : ∀ y : β, v y ^ 2 = a * f₁ x y + b * f₂ x y + 2 * adaptBC f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := fun y => by exact Real.sq_sqrt (by have h1 := mul_nonneg ha ((hf₁ x).1 y) have h2 := mul_nonneg hb ((hf₂ x).1 y) have h3 := hbc_nn x y linarith) rw [Finset.sum_congr rfl fun y _ => h1 y, Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, (hf₁ x).2, (hf₂ x).2, mul_one, mul_one] have hsq_mono : (∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) ^ 2 ≤ (∑ y : β, u y * v y) ^ 2 := by have hnn : 0 ≤ ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := Finset.sum_nonneg fun y _ => htv_nn y exact sq_le_sq' (by linarith) hsum_le calc (∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y)) ^ 2 ≤ (∑ y : β, u y * v y) ^ 2 := hsq_mono _ ≤ (∑ y : β, u y ^ 2) * (∑ y : β, v y ^ 2) := hcs _ = (a + b - 2 * B) * (a + b + 2 * B) := by rw [hu_sq, hv_sq] _ = (a + b) ^ 2 - 4 * B ^ 2 := by ring have htv_sum_nn : 0 ≤ ∑ y : β, adaptTVAux f₁ f₂ T (a * f₁ x y) (b * f₂ x y) := Finset.sum_nonneg fun y _ => by have hih := adaptTVAux_bhatt_bounds hf₁ hf₂ T (mul_nonneg ha ((hf₁ x).1 y)) (mul_nonneg hb ((hf₂ x).1 y)) linarith [hih.1, hih.2.2] rw [Real.le_sqrt htv_sum_nn (by nlinarith [hinf_le, hinf_nn])] nlinarith [hinf_le_B, hinf_nn, hB_nn] /-- **Two-Sided Non-Asymptotic `T`-Round Shtarkov–Bhattacharyya Sandwich**: For EVERY `T : ℕ` and ANY two stochastic experts `f₁, f₂` with `ρ = min_x BC(f₁ x, f₂ x)`: `2 - ρ^T ≤ S_T({f₁, f₂}) ≤ 1 + √(1 - ρ^(2*T))`! -/ theorem ctxShtarkov_two_experts_bhatt_sandwich {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] {f₁ f₂ : α → β → ℝ} (hf₁ : ∀ x : α, (∀ y : β, 0 ≤ f₁ x y) ∧ ∑ y : β, f₁ x y = 1) (hf₂ : ∀ x : α, (∀ y : β, 0 ≤ f₂ x y) ∧ ∑ y : β, f₂ x y = 1) (T : ℕ) : let ρ := Finset.univ.inf' Finset.univ_nonempty (fun x : α => bhattCoeff (f₁ x) (f₂ x)) 2 - ρ ^ T ≤ ctxShtarkovUnif (twoExpEval f₁ f₂) Finset.univ T ∧ ctxShtarkovUnif (twoExpEval f₁ f₂) Finset.univ T ≤ 1 + Real.sqrt (1 - ρ ^ (2 * T)) := by intro ρ rw [ctxShtarkov_two_experts_eq_one_add_adaptTV hf₁ hf₂ T] dsimp only [adaptTV] have hb := adaptTVAux_bhatt_bounds hf₁ hf₂ T zero_le_one zero_le_one have hbc : adaptBC f₁ f₂ T 1 1 = ρ ^ T := by rw [adaptBC_exact_pow (fun x => (hf₁ x).1) (fun x => (hf₂ x).1) T zero_le_one zero_le_one] simp [ρ] rw [hbc] at hb constructor · linarith [hb.1] · have hsqrt : (1 / 2 : ℝ) * Real.sqrt ((1 + 1) ^ 2 - 4 * (ρ ^ T) ^ 2) = Real.sqrt (1 - ρ ^ (2 * T)) := by have h1 : (1 + 1 : ℝ) ^ 2 - 4 * (ρ ^ T) ^ 2 = 4 * (1 - ρ ^ (2 * T)) := by rw [mul_comm 2 T, pow_mul]; ring rw [h1, Real.sqrt_mul (by norm_num : (0 : ℝ) ≤ 4), show Real.sqrt 4 = 2 by rw [show (4 : ℝ) = 2 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)]] ring have hmul := mul_le_mul_of_nonneg_left hb.2.1 (by norm_num : (0 : ℝ) ≤ 1 / 2) linarith /-- Elementary scalar Topsøe–Pinsker lemma: `t^2 ≤ (1 + t) * log (1 + t) + (1 - t) * log (1 - t)` for all `t ∈ (-1, 1)`. -/ private lemma sq_le_bin_kl_sym {t : ℝ} (ht_lo : -1 < t) (ht_hi : t < 1) : t ^ 2 ≤ (1 + t) * Real.log (1 + t) + (1 - t) * Real.log (1 - t) := by suffices hpos : ∀ s : ℝ, 0 ≤ s → s < 1 → s ^ 2 ≤ (1 + s) * Real.log (1 + s) + (1 - s) * Real.log (1 - s) by rcases le_total 0 t with ht | ht · exact hpos t ht ht_hi · have h := hpos (-t) (by linarith) (by linarith) have h1 : (-t) ^ 2 = t ^ 2 := by ring have h2 : 1 + -t = 1 - t := by ring have h3 : 1 - -t = 1 + t := by ring rw [h1, h2, h3] at h; linarith intro s hs0 hs1 set g : ℝ → ℝ := fun u => (1 + u) * Real.log (1 + u) + (1 - u) * Real.log (1 - u) - u ^ 2 set g' : ℝ → ℝ := fun u => Real.log (1 + u) - Real.log (1 - u) - 2 * u have hg'_deriv : ∀ u ∈ Set.Ico (0 : ℝ) 1, HasDerivAt g' (2 * u ^ 2 / (1 - u ^ 2)) u := by intro u ⟨hu0, hu1⟩ have h1 : HasDerivAt (fun z : ℝ => Real.log (1 + z)) (1 / (1 + u)) u := by have hd : HasDerivAt (fun z : ℝ => (1 : ℝ) + z) 1 u := by simpa using (hasDerivAt_id u).const_add 1 simpa using hd.log (by linarith) have h2 : HasDerivAt (fun z : ℝ => Real.log (1 - z)) ((-1) / (1 - u)) u := by have hd : HasDerivAt (fun z : ℝ => (1 : ℝ) - z) (-1) u := HasDerivAt.const_sub 1 (hasDerivAt_id u) simpa using hd.log (by linarith) have h3 : HasDerivAt (fun z : ℝ => 2 * z) 2 u := by simpa using (hasDerivAt_id u).const_mul 2 refine ((h1.fun_sub h2).fun_sub h3).congr_deriv ?_ have h1n : (1 : ℝ) + u ≠ 0 := by linarith have h2n : (1 : ℝ) - u ≠ 0 := by linarith have h3n : (1 : ℝ) - u ^ 2 ≠ 0 := by nlinarith field_simp; ring have hg'_nn : ∀ u ∈ Set.Icc (0 : ℝ) s, 0 ≤ g' u := by intro u ⟨hu0, hus⟩ have hmono : g' 0 ≤ g' u := monotoneOn_of_deriv_nonneg (convex_Icc 0 u) (fun z hz => (hg'_deriv z ⟨hz.1, lt_of_le_of_lt (le_trans hz.2 hus) hs1⟩).continuousAt.continuousWithinAt) (fun z hz => by rw [interior_Icc] at hz exact (hg'_deriv z ⟨le_of_lt hz.1, lt_trans (lt_of_lt_of_le hz.2 hus) hs1⟩).differentiableAt.differentiableWithinAt) (fun z hz => by rw [interior_Icc] at hz have hz1 : z < 1 := lt_trans (lt_of_lt_of_le hz.2 hus) hs1 rw [(hg'_deriv z ⟨le_of_lt hz.1, hz1⟩).deriv] have hden : 0 < 1 - z ^ 2 := by nlinarith [hz.1] positivity) (Set.left_mem_Icc.mpr hu0) (Set.right_mem_Icc.mpr hu0) hu0 have hg'0 : g' 0 = 0 := by simp [g'] linarith have hg_deriv : ∀ u ∈ Set.Ico (0 : ℝ) 1, HasDerivAt g (g' u) u := by intro u ⟨hu0, hu1⟩ have ha1 : HasDerivAt (fun z : ℝ => (1 : ℝ) + z) 1 u := by simpa using (hasDerivAt_id u).const_add 1 have ha2 : HasDerivAt (fun z : ℝ => Real.log (1 + z)) (1 / (1 + u)) u := by simpa using ha1.log (by linarith) have hb1 : HasDerivAt (fun z : ℝ => (1 : ℝ) - z) (-1) u := HasDerivAt.const_sub 1 (hasDerivAt_id u) have hb2 : HasDerivAt (fun z : ℝ => Real.log (1 - z)) ((-1) / (1 - u)) u := by simpa using hb1.log (by linarith) have hc : HasDerivAt (fun z : ℝ => z ^ 2) (2 * u ^ (2 - 1)) u := hasDerivAt_pow 2 u refine (((ha1.mul ha2).fun_add (hb1.mul hb2)).fun_sub hc).congr_deriv ?_ dsimp only [g'] have h1n : (1 : ℝ) + u ≠ 0 := by linarith have h2n : (1 : ℝ) - u ≠ 0 := by linarith field_simp; ring have hg_mono : g 0 ≤ g s := monotoneOn_of_deriv_nonneg (convex_Icc 0 s) (fun z hz => (hg_deriv z ⟨hz.1, lt_of_le_of_lt hz.2 hs1⟩).continuousAt.continuousWithinAt) (fun z hz => by rw [interior_Icc] at hz exact (hg_deriv z ⟨le_of_lt hz.1, lt_trans hz.2 hs1⟩).differentiableAt.differentiableWithinAt) (fun z hz => by rw [interior_Icc] at hz rw [(hg_deriv z ⟨le_of_lt hz.1, lt_trans hz.2 hs1⟩).deriv] exact hg'_nn z ⟨le_of_lt hz.1, le_of_lt hz.2⟩) (Set.left_mem_Icc.mpr hs0) (Set.right_mem_Icc.mpr hs0) hs0 have hg0 : g 0 = 0 := by simp [g] dsimp only [g] at hg_mono; linarith /-- **Sharp Multiclass Topsøe–Pinsker Inequality (`TV(p, q)^2 ≤ 2 * JS(p, q)`)**: holds for ALL probability distributions `p, q` on ANY finite alphabet `β`! -/ theorem tvDist_sq_le_two_mul_jsDiv {β : Type*} [Fintype β] {p q : β → ℝ} (hp0 : ∀ y : β, 0 ≤ p y) (hq0 : ∀ y : β, 0 ≤ q y) (hpsum : ∑ y : β, p y = 1) (hqsum : ∑ y : β, q y = 1) : tvDist p q ^ 2 ≤ 2 * jsDiv p q := by set m : β → ℝ := fun y => (p y + q y) / 2 have hscalar : ∀ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (2 * (p y + q y))) ≤ klTerm (p y) (m y) + klTerm (q y) (m y) := by intro y by_cases hsum0 : p y + q y = 0 · have hpz : p y = 0 := by linarith [hp0 y, hq0 y] have hqz : q y = 0 := by linarith [hp0 y, hq0 y] simp [klTerm, hpz, hqz] · simp only [hsum0, ↓reduceIte] have hpos : 0 < p y + q y := lt_of_le_of_ne (add_nonneg (hp0 y) (hq0 y)) (Ne.symm hsum0) by_cases hpz : p y = 0 · have hq_pos : 0 < q y := by linarith simp only [klTerm, hpz, ne_of_gt hq_pos, ↓reduceIte, zero_add, zero_sub, neg_sq] have hrat : q y / m y = 2 := by dsimp only [m]; rw [hpz, zero_add]; field_simp rw [hrat] have hlog2 := Real.log_two_gt_d9 have h1 : q y ^ 2 / (2 * q y) = q y / 2 := by field_simp [ne_of_gt hq_pos] rw [h1]; nlinarith · by_cases hqz : q y = 0 · have hp_pos : 0 < p y := by linarith simp only [klTerm, hqz, ne_of_gt hp_pos, ↓reduceIte, add_zero, sub_zero] have hrat : p y / m y = 2 := by dsimp only [m]; rw [hqz, add_zero]; field_simp rw [hrat] have hlog2 := Real.log_two_gt_d9 have h1 : p y ^ 2 / (2 * p y) = p y / 2 := by field_simp [ne_of_gt hp_pos] rw [h1]; nlinarith · have hp_pos : 0 < p y := lt_of_le_of_ne (hp0 y) (Ne.symm hpz) have hq_pos : 0 < q y := lt_of_le_of_ne (hq0 y) (Ne.symm hqz) simp only [klTerm, hpz, hqz, ↓reduceIte] set t := (p y - q y) / (p y + q y) have ht_lo : -1 < t := by dsimp only [t]; rw [lt_div_iff₀ hpos]; linarith have ht_hi : t < 1 := by dsimp only [t]; rw [div_lt_iff₀ hpos]; linarith have hsym := sq_le_bin_kl_sym ht_lo ht_hi have h1pt : 1 + t = p y / m y := by dsimp only [t, m]; field_simp [ne_of_gt hpos]; ring have h1mt : 1 - t = q y / m y := by dsimp only [t, m]; field_simp [ne_of_gt hpos]; ring have hmul := mul_le_mul_of_nonneg_left hsym (le_of_lt (half_pos hpos)) have hlhs : (p y + q y) / 2 * t ^ 2 = (p y - q y) ^ 2 / (2 * (p y + q y)) := by dsimp only [t]; field_simp [ne_of_gt hpos] have hrhs : (p y + q y) / 2 * ((1 + t) * Real.log (1 + t) + (1 - t) * Real.log (1 - t)) = p y * Real.log (p y / m y) + q y * Real.log (q y / m y) := by rw [h1pt, h1mt] have hpa : (p y + q y) / 2 * (p y / m y) = p y := by dsimp only [m]; field_simp [ne_of_gt hpos] have hqa : (p y + q y) / 2 * (q y / m y) = q y := by dsimp only [m]; field_simp [ne_of_gt hpos] rw [mul_add, ← mul_assoc, ← mul_assoc, hpa, hqa] linarith -- Sum hscalar over β to get ∑ (p-q)^2 / (p+q) ≤ 4 * JS(p, q), then apply Cauchy-Schwarz! have hsum_chi : ∑ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (p y + q y)) ≤ 4 * jsDiv p q := by have h1 := Finset.sum_le_sum fun y (_ : y ∈ Finset.univ) => hscalar y rw [Finset.sum_add_distrib] at h1 have h2 : ∑ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (2 * (p y + q y))) = (1 / 2 : ℝ) * ∑ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (p y + q y)) := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun y _ => ?_ split_ifs with h0 · ring · field_simp [h0] dsimp only [jsDiv, klDiv] linarith set u : β → ℝ := fun y => if p y + q y = 0 then 0 else |p y - q y| / Real.sqrt (p y + q y) set v : β → ℝ := fun y => Real.sqrt (p y + q y) have habs_eq : ∀ y : β, |p y - q y| = u y * v y := fun y => by dsimp only [u, v] split_ifs with h0 · have hpz : p y = 0 := by linarith [hp0 y, hq0 y] have hqz : q y = 0 := by linarith [hp0 y, hq0 y] simp [hpz, hqz] · have hpos : 0 < p y + q y := lt_of_le_of_ne (add_nonneg (hp0 y) (hq0 y)) (Ne.symm h0) rw [div_mul_cancel₀ _ (ne_of_gt (Real.sqrt_pos.mpr hpos))] have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset β) u v have hu_sq : ∑ y : β, u y ^ 2 = ∑ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (p y + q y)) := by refine Finset.sum_congr rfl fun y _ => ?_ dsimp only [u] split_ifs with h0 · simp · rw [div_pow, sq_abs, Real.sq_sqrt (add_nonneg (hp0 y) (hq0 y))] have hv_sq : ∑ y : β, v y ^ 2 = 2 := by have h1 : ∀ y : β, v y ^ 2 = p y + q y := fun y => Real.sq_sqrt (add_nonneg (hp0 y) (hq0 y)) rw [Finset.sum_congr rfl fun y _ => h1 y, Finset.sum_add_distrib, hpsum, hqsum]; norm_num have htv_sq : (∑ y : β, |p y - q y|) ^ 2 ≤ 8 * jsDiv p q := by rw [Finset.sum_congr rfl fun y _ => habs_eq y] calc (∑ y : β, u y * v y) ^ 2 ≤ (∑ y : β, u y ^ 2) * (∑ y : β, v y ^ 2) := hcs _ = (∑ y : β, (if p y + q y = 0 then 0 else (p y - q y) ^ 2 / (p y + q y))) * 2 := by rw [hu_sq, hv_sq] _ ≤ 4 * jsDiv p q * 2 := mul_le_mul_of_nonneg_right hsum_chi (by norm_num) _ = 8 * jsDiv p q := by ring dsimp only [tvDist]; nlinarith /-- **Exact 1-Round Shtarkov vs. Jensen–Shannon Capacity Sandwich**: for any two distributions `p, q` on `β`: `jsDiv p q ≤ Real.log (1 + tvDist p q) ≤ Real.log (1 + Real.sqrt (2 * jsDiv p q))`! -/ theorem shtarkov_vs_js_capacity_exact_bounds {β : Type*} [Fintype β] {p q : β → ℝ} (hp0 : ∀ y : β, 0 ≤ p y) (hq0 : ∀ y : β, 0 ≤ q y) (hpsum : ∑ y : β, p y = 1) (hqsum : ∑ y : β, q y = 1) : jsDiv p q ≤ Real.log (1 + tvDist p q) ∧ Real.log (1 + tvDist p q) ≤ Real.log (1 + Real.sqrt (2 * jsDiv p q)) := by have htv_nn : 0 ≤ tvDist p q := mul_nonneg (by norm_num) (Finset.sum_nonneg fun _ _ => abs_nonneg _) have htp := tvDist_sq_le_two_mul_jsDiv hp0 hq0 hpsum hqsum have hjs_nn : 0 ≤ jsDiv p q := by nlinarith [sq_nonneg (tvDist p q)] constructor · -- Prove JS(p, q) ≤ log (1 + TV(p, q)) via Gibbs / Shtarkov minimax! -- Since Z = ∑_y max(p y, q y) = 1 + TV(p, q), let r y = max(p y, q y) / Z: -- klDiv p m + klDiv q m = 2 * JS ≤ klDiv p r + klDiv q r = ∑ p log(p/r) + ∑ q log(q/r) -- ≤ 2 * log Z since p y ≤ max(p y, q y) and q y ≤ max(p y, q y)! set Z := 1 + tvDist p q have hZ_pos : 0 < Z := by linarith have hZ_eq : ∑ y : β, max (p y) (q y) = Z := by have hmax : ∀ y : β, max (p y) (q y) = (p y + q y + |p y - q y|) / 2 := fun y => by rw [max_def]; split_ifs with h · rw [abs_of_nonpos (sub_nonpos.mpr h)]; ring · rw [abs_of_pos (sub_pos.mpr (not_le.mp h))]; ring rw [Finset.sum_congr rfl fun y _ => hmax y, ← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib, hpsum, hqsum] dsimp only [Z, tvDist]; ring set m : β → ℝ := fun y => (p y + q y) / 2 set r : β → ℝ := fun y => max (p y) (q y) / Z have hr0 : ∀ y : β, 0 ≤ r y := fun y => div_nonneg (le_trans (hp0 y) (le_max_left _ _)) (le_of_lt hZ_pos) have hrsum : ∑ y : β, r y = 1 := by dsimp only [r]; rw [← Finset.sum_div, hZ_eq, div_self (ne_of_gt hZ_pos)] have hm0 : ∀ y : β, 0 ≤ m y := fun y => by dsimp only [m]; linarith [hp0 y, hq0 y] have hmsum : ∑ y : β, m y = 1 := by dsimp only [m]; rw [← Finset.sum_div, Finset.sum_add_distrib, hpsum, hqsum]; norm_num have hm_supp : ∀ y ∈ (Finset.univ : Finset β), m y ≠ 0 → 0 < r y := fun y _ hm_ne => by have hm_pos : 0 < m y := lt_of_le_of_ne (hm0 y) (Ne.symm hm_ne) have hmax_pos : 0 < max (p y) (q y) := by dsimp only [m] at hm_pos rcases le_total (p y) (q y) with h | h · rw [max_eq_right h]; linarith · rw [max_eq_left h]; linarith exact div_pos hmax_pos hZ_pos -- Exact identity: JS(p, q) + D_KL(m ‖ r) = (1/2) * (D_KL(p ‖ r) + D_KL(q ‖ r))! have hkl_mr_nn : 0 ≤ klDiv Finset.univ m r := klDiv_nonneg (fun y _ => hm0 y) (fun y _ => hr0 y) hmsum hrsum hm_supp have hkl_pr_le : klDiv Finset.univ p r ≤ Real.log Z := by have hterm : ∀ y : β, klTerm (p y) (r y) ≤ p y * Real.log Z := fun y => by by_cases hpz : p y = 0 · simp [klTerm, hpz] · have hp_pos : 0 < p y := lt_of_le_of_ne (hp0 y) (Ne.symm hpz) have hmax_ge : p y ≤ max (p y) (q y) := le_max_left _ _ have hr_pos : 0 < r y := div_pos (lt_of_lt_of_le hp_pos hmax_ge) hZ_pos simp only [klTerm, hpz, ↓reduceIte] have hrat : p y / r y ≤ Z := by dsimp only [r]; rw [div_div_eq_mul_div, div_le_iff₀ (lt_of_lt_of_le hp_pos hmax_ge), mul_comm Z] exact mul_le_mul_of_nonneg_right hmax_ge (le_of_lt hZ_pos) exact mul_le_mul_of_nonneg_left (Real.log_le_log (div_pos hp_pos hr_pos) hrat) (le_of_lt hp_pos) calc klDiv Finset.univ p r ≤ ∑ y : β, p y * Real.log Z := Finset.sum_le_sum fun y _ => hterm y _ = (∑ y : β, p y) * Real.log Z := (Finset.sum_mul _ _ _).symm _ = Real.log Z := by rw [hpsum, one_mul] have hkl_qr_le : klDiv Finset.univ q r ≤ Real.log Z := by have hterm : ∀ y : β, klTerm (q y) (r y) ≤ q y * Real.log Z := fun y => by by_cases hqz : q y = 0 · simp [klTerm, hqz] · have hq_pos : 0 < q y := lt_of_le_of_ne (hq0 y) (Ne.symm hqz) have hmax_ge : q y ≤ max (p y) (q y) := le_max_right _ _ have hr_pos : 0 < r y := div_pos (lt_of_lt_of_le hq_pos hmax_ge) hZ_pos simp only [klTerm, hqz, ↓reduceIte] have hrat : q y / r y ≤ Z := by dsimp only [r]; rw [div_div_eq_mul_div, div_le_iff₀ (lt_of_lt_of_le hq_pos hmax_ge), mul_comm Z] exact mul_le_mul_of_nonneg_right hmax_ge (le_of_lt hZ_pos) exact mul_le_mul_of_nonneg_left (Real.log_le_log (div_pos hq_pos hr_pos) hrat) (le_of_lt hq_pos) calc klDiv Finset.univ q r ≤ ∑ y : β, q y * Real.log Z := Finset.sum_le_sum fun y _ => hterm y _ = (∑ y : β, q y) * Real.log Z := (Finset.sum_mul _ _ _).symm _ = Real.log Z := by rw [hqsum, one_mul] have hpyth : jsDiv p q + klDiv Finset.univ m r = (1 / 2 : ℝ) * (klDiv Finset.univ p r + klDiv Finset.univ q r) := by dsimp only [jsDiv, klDiv] change (1 / 2 : ℝ) * (∑ y : β, klTerm (p y) (m y) + ∑ y : β, klTerm (q y) (m y)) + ∑ y : β, klTerm (m y) (r y) = (1 / 2 : ℝ) * (∑ y : β, klTerm (p y) (r y) + ∑ y : β, klTerm (q y) (r y)) have hcomb : (1 / 2 : ℝ) * (∑ y : β, klTerm (p y) (m y) + ∑ y : β, klTerm (q y) (m y)) + ∑ y : β, klTerm (m y) (r y) = (1 / 2 : ℝ) * ∑ y : β, (klTerm (p y) (m y) + klTerm (q y) (m y) + 2 * klTerm (m y) (r y)) := by rw [Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum]; ring rw [hcomb, ← Finset.sum_add_distrib]; congr 1 refine Finset.sum_congr rfl fun y _ => ?_ by_cases hmz : m y = 0 · have hpz : p y = 0 := by dsimp only [m] at hmz; linarith [hp0 y, hq0 y] have hqz : q y = 0 := by dsimp only [m] at hmz; linarith [hp0 y, hq0 y] simp [klTerm, hmz, hpz, hqz] · have hm_pos : 0 < m y := lt_of_le_of_ne (hm0 y) (Ne.symm hmz) have hr_pos : 0 < r y := hm_supp y (Finset.mem_univ y) hmz have h2m : 2 * m y = p y + q y := by dsimp only [m]; ring have hterm_p : klTerm (p y) (m y) + p y * Real.log (m y / r y) = klTerm (p y) (r y) := by by_cases hpz : p y = 0 · simp [klTerm, hpz] · have hp_pos : 0 < p y := lt_of_le_of_ne (hp0 y) (Ne.symm hpz) simp only [klTerm, hpz, ↓reduceIte] rw [Real.log_div (ne_of_gt hp_pos) (ne_of_gt hm_pos), Real.log_div (ne_of_gt hm_pos) (ne_of_gt hr_pos), Real.log_div (ne_of_gt hp_pos) (ne_of_gt hr_pos)]; ring have hterm_q : klTerm (q y) (m y) + q y * Real.log (m y / r y) = klTerm (q y) (r y) := by by_cases hqz : q y = 0 · simp [klTerm, hqz] · have hq_pos : 0 < q y := lt_of_le_of_ne (hq0 y) (Ne.symm hqz) simp only [klTerm, hqz, ↓reduceIte] rw [Real.log_div (ne_of_gt hq_pos) (ne_of_gt hm_pos), Real.log_div (ne_of_gt hm_pos) (ne_of_gt hr_pos), Real.log_div (ne_of_gt hq_pos) (ne_of_gt hr_pos)]; ring have h2kl : 2 * klTerm (m y) (r y) = (p y + q y) * Real.log (m y / r y) := by simp only [klTerm, hmz, ↓reduceIte]; rw [← mul_assoc, h2m] linarith linarith · exact Real.log_le_log (by linarith) (by linarith [Real.le_sqrt htv_nn (by linarith) |>.mpr htp]) /-- **Unbounded Redundancy–Capacity Separation (`log S_1 / JS → +∞`)**: For EVERY `M > 0`, there exist two binary Bernoulli distributions `p, q` on `Bool` such that `0 < jsDiv p q` AND `M * jsDiv p q < Real.log (1 + tvDist p q)`! (Separating individual-sequence Shtarkov regret from minimax expected KL-redundancy / capacity!) -/ theorem shtarkov_vs_js_capacity_unbounded_ratio (M : ℝ) : ∃ p q : Bool → ℝ, (∀ y, 0 ≤ p y) ∧ (∑ y : Bool, p y = 1) ∧ (∀ y, 0 ≤ q y) ∧ (∑ y : Bool, q y = 1) ∧ 0 < jsDiv p q ∧ M * jsDiv p q < Real.log (1 + tvDist p q) := by set δ : ℝ := min (1 / 2) (1 / (4 * (max M 1))) have hM1 : (1 : ℝ) ≤ max M 1 := le_max_right M 1 have hδ_pos : 0 < δ := lt_min (by norm_num) (by positivity) have hδ_le_half : δ ≤ 1 / 2 := min_le_left _ _ have hδ_le_M : δ ≤ 1 / (4 * max M 1) := min_le_right _ _ set p : Bool → ℝ := fun b => if b then (1 + δ) / 2 else (1 - δ) / 2 set q : Bool → ℝ := fun b => if b then (1 - δ) / 2 else (1 + δ) / 2 have hp0 : ∀ b : Bool, 0 ≤ p b := fun b => by cases b <;> simp only [p, Bool.false_eq_true, ↓reduceIte] <;> linarith have hq0 : ∀ b : Bool, 0 ≤ q b := fun b => by cases b <;> simp only [q, Bool.false_eq_true, ↓reduceIte] <;> linarith have hpsum : ∑ y : Bool, p y = 1 := by simp [p]; ring have hqsum : ∑ y : Bool, q y = 1 := by simp [q]; ring have htv : tvDist p q = δ := by dsimp only [tvDist, p, q] simp only [Fintype.sum_bool, ↓reduceIte, Bool.false_eq_true] have h1 : (1 + δ) / 2 - (1 - δ) / 2 = δ := by ring have h2 : (1 - δ) / 2 - (1 + δ) / 2 = -δ := by ring rw [h1, h2, abs_of_pos hδ_pos, abs_neg, abs_of_pos hδ_pos]; ring have htp := tvDist_sq_le_two_mul_jsDiv hp0 hq0 hpsum hqsum have hjs_pos : 0 < jsDiv p q := by rw [htv] at htp; nlinarith refine ⟨p, q, hp0, hpsum, hq0, hqsum, hjs_pos, ?_⟩ · have hjs_le : jsDiv p q ≤ δ ^ 2 := by dsimp only [jsDiv, klDiv] have hm : ∀ b : Bool, (p b + q b) / 2 = 1 / 2 := fun b => by cases b <;> simp only [p, q, Bool.false_eq_true, ↓reduceIte] <;> ring simp only [Fintype.sum_bool, hm, klTerm, p, q, ↓reduceIte, Bool.false_eq_true] have hne1 : (1 + δ) / 2 ≠ 0 := by linarith have hne2 : (1 - δ) / 2 ≠ 0 := by linarith simp only [hne1, hne2, ↓reduceIte] have hr1 : (1 + δ) / 2 / (1 / 2) = 1 + δ := by ring have hr2 : (1 - δ) / 2 / (1 / 2) = 1 - δ := by ring rw [hr1, hr2] have hlog1 : Real.log (1 + δ) ≤ δ := by have := Real.log_le_sub_one_of_pos (by linarith : 0 < 1 + δ); linarith have hlog2 : Real.log (1 - δ) ≤ -δ := by have := Real.log_le_sub_one_of_pos (by linarith : 0 < 1 - δ); linarith nlinarith have hlog_ge : δ / 2 ≤ Real.log (1 + δ) := by have h1 := Real.log_le_sub_one_of_pos (div_pos one_pos (by linarith : 0 < 1 + δ)) rw [Real.log_div one_ne_zero (by linarith), Real.log_one, zero_sub] at h1 have h2 : δ / 2 ≤ δ / (1 + δ) := by rw [div_le_div_iff₀ (by norm_num) (by linarith)]; nlinarith have h3 : 1 - 1 / (1 + δ) = δ / (1 + δ) := by field_simp [show (1 : ℝ) + δ ≠ 0 by linarith]; ring linarith rw [htv] have hM_le : M ≤ max M 1 := le_max_left M 1 have hMδ : max M 1 * δ ≤ 1 / 4 := by have := (le_div_iff₀ (by positivity : 0 < 4 * max M 1)).mp hδ_le_M; linarith calc M * jsDiv p q ≤ max M 1 * δ ^ 2 := by nlinarith _ = (max M 1 * δ) * δ := by ring _ ≤ (1 / 4) * δ := by nlinarith _ < δ / 2 := by linarith _ ≤ Real.log (1 + δ) := hlog_ge /-! ## Part 4: Realizable Multiclass Deterministic Classes — Multiclass Adaptive Sauer–Shelah, ## Adaptive vs. Oblivious Exponential Separation, & Disjoint-Product Super-Multiplicativity -/ /-- Dirac stochastic expert representation of a deterministic concept `h : α → β`. -/ def detEval {α β : Type*} [DecidableEq β] (h : α → β) (x : α) (y : β) : ℝ := if h x = y then 1 else 0 lemma isStochClass_detEval {α β : Type*} [Fintype β] [DecidableEq β] (V : Finset (α → β)) : IsStochClass detEval V := by intro h _ x refine ⟨fun y => by dsimp only [detEval]; split_ifs <;> norm_num, ?_⟩ simp [detEval] /-- Distinct labels attained by concept class `V` on point `x`. -/ def labels {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) : Finset β := V.image fun h => h x /-- Sub-class of concepts in `V` assigning label `y` to point `x`. -/ def restrict {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) (y : β) : Finset (α → β) := V.filter fun h => h x = y lemma restrict_subset {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) (y : β) : restrict V x y ⊆ V := Finset.filter_subset _ _ lemma restrict_nonempty_iff {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) (y : β) : (restrict V x y).Nonempty ↔ y ∈ labels V x := by simp [restrict, labels, Finset.Nonempty] lemma sum_card_restrict {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) : ∑ y ∈ labels V x, (restrict V x y).card = V.card := by have h := Finset.card_eq_sum_card_fiberwise (f := fun h : α → β => h x) (s := V) (t := labels V x) (fun h hh => Finset.mem_image_of_mem _ hh) exact h.symm /-- **Adaptive Contextual Growth Function (Realizable Horizon-`T` Shtarkov Sum)**: counts the maximum number of realizable leaves of a depth-`T` adaptive query tree on `V`. -/ def adaptGrowth {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ℕ → Finset (α → β) → ℕ | 0, V => if V.Nonempty then 1 else 0 | T + 1, V => Finset.univ.sup' Finset.univ_nonempty fun x : α => ∑ y ∈ labels V x, adaptGrowth T (restrict V x y) lemma adaptGrowth_empty {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ∀ T : ℕ, adaptGrowth (α := α) (β := β) T ∅ = 0 | 0 => by simp [adaptGrowth] | T + 1 => by simp only [adaptGrowth, labels, Finset.image_empty, Finset.sum_empty] apply Nat.eq_zero_of_le_zero exact Finset.sup'_le Finset.univ_nonempty _ fun _ _ => le_rfl lemma adaptGrowth_mono {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ∀ (T : ℕ) {U V : Finset (α → β)}, U ⊆ V → adaptGrowth T U ≤ adaptGrowth T V | 0, U, V, hUV => by simp only [adaptGrowth] split_ifs with hU hV · exact le_rfl · exact absurd (hU.mono hUV) hV · exact Nat.zero_le _ · exact le_rfl | T + 1, U, V, hUV => by simp only [adaptGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ refine le_trans ?_ (Finset.le_sup' (f := fun x : α => ∑ y ∈ labels V x, adaptGrowth T (restrict V x y)) hx) have hlab : labels U x ⊆ labels V x := Finset.image_subset_image hUV calc ∑ y ∈ labels U x, adaptGrowth T (restrict U x y) ≤ ∑ y ∈ labels U x, adaptGrowth T (restrict V x y) := Finset.sum_le_sum fun y _ => adaptGrowth_mono T (Finset.filter_subset_filter _ hUV) _ ≤ ∑ y ∈ labels V x, adaptGrowth T (restrict V x y) := Finset.sum_le_sum_of_subset hlab lemma adaptGrowth_le_card {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ∀ (T : ℕ) (V : Finset (α → β)), adaptGrowth T V ≤ V.card | 0, V => by simp only [adaptGrowth] split_ifs with hV · exact hV.card_pos · exact Nat.zero_le _ | T + 1, V => by simp only [adaptGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun x _ => ?_ calc ∑ y ∈ labels V x, adaptGrowth T (restrict V x y) ≤ ∑ y ∈ labels V x, (restrict V x y).card := Finset.sum_le_sum fun y _ => adaptGrowth_le_card T _ _ = V.card := sum_card_restrict V x lemma adaptGrowth_pos {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ∀ (T : ℕ) {V : Finset (α → β)}, V.Nonempty → 0 < adaptGrowth T V | 0, V, hV => by simp [adaptGrowth, hV] | T + 1, V, hV => by simp only [adaptGrowth] obtain ⟨x0⟩ := ‹Nonempty α› rcases hV with ⟨h0, hh0⟩ have hy0 : h0 x0 ∈ labels V x0 := Finset.mem_image_of_mem _ hh0 have hne : (restrict V x0 (h0 x0)).Nonempty := (restrict_nonempty_iff V x0 (h0 x0)).mpr hy0 have hpos := adaptGrowth_pos T hne have hsum : adaptGrowth T (restrict V x0 (h0 x0)) ≤ ∑ y ∈ labels V x0, adaptGrowth T (restrict V x0 y) := Finset.single_le_sum (f := fun y => adaptGrowth T (restrict V x0 y)) (fun _ _ => Nat.zero_le _) hy0 exact lt_of_lt_of_le hpos (le_trans hsum (Finset.le_sup' (f := fun x => ∑ y ∈ labels V x, adaptGrowth T (restrict V x y)) (Finset.mem_univ x0))) lemma ctxShtarkov_detEval_indicator {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] [DecidableEq β] [DecidableEq (α → β)] (V : Finset (α → β)) : ∀ (T : ℕ) {U : Finset (α → β)}, U ⊆ V → ctxShtarkov detEval V T (fun h => if h ∈ U then 1 else 0) = (adaptGrowth T U : ℝ) | 0, U, hUV => by simp only [ctxShtarkov, adaptGrowth] by_cases hV : V.Nonempty · simp only [hV, ↓reduceDIte] by_cases hU : U.Nonempty · simp only [hU, ↓reduceIte, Nat.cast_one] apply le_antisymm · exact Finset.sup'_le hV _ fun h _ => by split_ifs <;> norm_num · rcases hU with ⟨u0, hu0⟩ have hle := Finset.le_sup' (f := fun h : α → β => if h ∈ U then (1 : ℝ) else 0) (hUV hu0) simp only [hu0, ↓reduceIte] at hle; exact hle · simp only [hU, ↓reduceIte, Nat.cast_zero] have hemp : U = ∅ := Finset.not_nonempty_iff_eq_empty.mp hU subst hemp apply le_antisymm · exact Finset.sup'_le hV _ fun _ _ => by simp · rcases hV with ⟨v0, hv0⟩ have hle := Finset.le_sup' (f := fun h : α → β => if h ∈ (∅ : Finset (α → β)) then (1 : ℝ) else 0) hv0 simp only [Finset.notMem_empty, ↓reduceIte] at hle; exact hle · have hVemp : V = ∅ := Finset.not_nonempty_iff_eq_empty.mp hV subst hVemp have hUemp : U = ∅ := Finset.subset_empty.mp hUV subst hUemp simp | T + 1, U, hUV => by simp only [ctxShtarkov, adaptGrowth] have hstep : ∀ x : α, (∑ y : β, ctxShtarkov detEval V T (fun h => (if h ∈ U then (1 : ℝ) else 0) * detEval h x y)) = ((∑ y ∈ labels U x, adaptGrowth T (restrict U x y) : ℕ) : ℝ) := by intro x have hterm : ∀ y : β, ctxShtarkov detEval V T (fun h => (if h ∈ U then (1 : ℝ) else 0) * detEval h x y) = (adaptGrowth T (restrict U x y) : ℝ) := fun y => by have hcongr : (fun h : α → β => (if h ∈ U then (1 : ℝ) else 0) * detEval h x y) = (fun h => if h ∈ restrict U x y then (1 : ℝ) else 0) := by ext h; simp only [detEval, restrict, Finset.mem_filter]; split_ifs <;> simp_all rw [hcongr] exact ctxShtarkov_detEval_indicator V T (Finset.Subset.trans (restrict_subset U x y) hUV) rw [Finset.sum_congr rfl fun y _ => hterm y, Nat.cast_sum] refine (Finset.sum_subset (Finset.subset_univ (labels U x)) fun y _ hy_not => ?_).symm have hemp : restrict U x y = ∅ := by by_contra hne exact hy_not ((restrict_nonempty_iff U x y).mp (Finset.nonempty_iff_ne_empty.mpr hne)) rw [hemp, adaptGrowth_empty, Nat.cast_zero] simp_rw [hstep] -- Cast preserves sup' on Finset.univ apply le_antisymm · refine Finset.sup'_le Finset.univ_nonempty _ fun x hx => ?_ exact_mod_cast Finset.le_sup' (f := fun x : α => ∑ y ∈ labels U x, adaptGrowth T (restrict U x y)) hx · rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x : α => ∑ y ∈ labels U x, adaptGrowth T (restrict U x y)) with ⟨x0, hx0, heq⟩ rw [heq] exact Finset.le_sup' (f := fun x : α => ((∑ y ∈ labels U x, adaptGrowth T (restrict U x y) : ℕ) : ℝ)) hx0 /-- **Exact Bridge (`ctxShtarkovUnif detEval V T = adaptGrowth T V`)**: for EVERY finite deterministic multiclass concept class `V`, the contextual Shtarkov sum equals the exact adaptive growth function `adaptGrowth T V`! -/ theorem ctxShtarkov_detEval_eq_adaptGrowth {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] [DecidableEq β] [DecidableEq (α → β)] (V : Finset (α → β)) (T : ℕ) : ctxShtarkovUnif detEval V T = (adaptGrowth T V : ℝ) := by have h := ctxShtarkov_detEval_indicator V T (Finset.Subset.refl V) have hcongr : ctxShtarkov detEval V T (fun _ => 1) = ctxShtarkov detEval V T (fun h => if h ∈ V then 1 else 0) := ctxShtarkov_congr_w T fun h hh => by simp [hh] dsimp only [ctxShtarkovUnif]; rw [hcongr, h] /-- Binary-branching multiclass Littlestone shattering tree of depth `d` on `V`. -/ def hasLTree {α β : Type*} [DecidableEq β] : ℕ → Finset (α → β) → Prop | 0, V => V.Nonempty | d + 1, V => ∃ x : α, ∃ y₁ y₂ : β, y₁ ≠ y₂ ∧ hasLTree d (restrict V x y₁) ∧ hasLTree d (restrict V x y₂) lemma hasLTree_mono_V {α β : Type*} [DecidableEq β] : ∀ {d : ℕ} {U V : Finset (α → β)}, U ⊆ V → hasLTree d U → hasLTree d V | 0, _, _, hUV, h => h.mono hUV | _ + 1, _, _, hUV, ⟨x, y₁, y₂, hne, h1, h2⟩ => ⟨x, y₁, y₂, hne, hasLTree_mono_V (Finset.filter_subset_filter _ hUV) h1, hasLTree_mono_V (Finset.filter_subset_filter _ hUV) h2⟩ lemma hasLTree_anti_d {α β : Type*} [DecidableEq β] : ∀ {d : ℕ} {V : Finset (α → β)}, hasLTree (d + 1) V → hasLTree d V | 0, V, ⟨x, y₁, _, _, h1, _⟩ => h1.mono (restrict_subset V x y₁) | _ + 1, _, ⟨x, y₁, y₂, hne, h1, h2⟩ => ⟨x, y₁, y₂, hne, hasLTree_anti_d h1, hasLTree_anti_d h2⟩ lemma hasLTree_of_le {α β : Type*} [DecidableEq β] {d₁ d₂ : ℕ} {V : Finset (α → β)} (hle : d₁ ≤ d₂) (h : hasLTree d₂ V) : hasLTree d₁ V := by induction hle with | refl => exact h | step _ ih => exact ih (hasLTree_anti_d h) lemma hasLTree_card_ge {α β : Type*} [DecidableEq β] : ∀ {d : ℕ} {V : Finset (α → β)}, hasLTree d V → 2 ^ d ≤ V.card | 0, _, h => h.card_pos | d + 1, V, ⟨x, y₁, y₂, hne, h1, h2⟩ => by classical have hc1 := hasLTree_card_ge h1 have hc2 := hasLTree_card_ge h2 have hdisj : Disjoint (restrict V x y₁) (restrict V x y₂) := by rw [Finset.disjoint_left] intro f hf1 hf2 exact hne ((Finset.mem_filter.mp hf1).2.symm.trans (Finset.mem_filter.mp hf2).2) have hsub : restrict V x y₁ ∪ restrict V x y₂ ⊆ V := Finset.union_subset (restrict_subset V x y₁) (restrict_subset V x y₂) have hcard := Finset.card_le_card hsub rw [Finset.card_union_of_disjoint hdisj] at hcard rw [pow_succ]; omega /-- Binary-branching multiclass Littlestone dimension `Ldim V`. -/ noncomputable def Ldim {α β : Type*} [DecidableEq β] (V : Finset (α → β)) : ℕ := by classical exact ((Finset.range (V.card + 1)).filter fun d => hasLTree d V).sup id lemma hasLTree_le_card {α β : Type*} [DecidableEq β] {d : ℕ} {V : Finset (α → β)} (h : hasLTree d V) : d ≤ V.card := by have h1 := hasLTree_card_ge h have h2 : d < 2 ^ d := Nat.lt_two_pow_self omega lemma le_Ldim_of_hasLTree {α β : Type*} [DecidableEq β] {d : ℕ} {V : Finset (α → β)} (h : hasLTree d V) : d ≤ Ldim V := by classical dsimp only [Ldim] have hmem : d ∈ (Finset.range (V.card + 1)).filter fun d => hasLTree d V := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.lt_succ_of_le (hasLTree_le_card h)), h⟩ exact Finset.le_sup (f := id) hmem lemma hasLTree_Ldim {α β : Type*} [DecidableEq β] {V : Finset (α → β)} (hV : V.Nonempty) : hasLTree (Ldim V) V := by classical dsimp only [Ldim] set S := (Finset.range (V.card + 1)).filter fun d => hasLTree d V have h0 : 0 ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.succ_pos _), hV⟩ have hSne : S.Nonempty := ⟨0, h0⟩ have heq : S.sup id = S.sup' hSne id := (Finset.sup'_eq_sup hSne id).symm rw [heq] rcases Finset.exists_mem_eq_sup' hSne id with ⟨d, hd, hdeq⟩ rw [hdeq]; exact (Finset.mem_filter.mp hd).2 lemma hasLTree_iff_le_Ldim {α β : Type*} [DecidableEq β] {V : Finset (α → β)} (hV : V.Nonempty) (d : ℕ) : hasLTree d V ↔ d ≤ Ldim V := ⟨le_Ldim_of_hasLTree, fun hle => hasLTree_of_le hle (hasLTree_Ldim hV)⟩ lemma Ldim_mono {α β : Type*} [DecidableEq β] {U V : Finset (α → β)} (hUV : U ⊆ V) : Ldim U ≤ Ldim V := by by_cases hU : U.Nonempty · exact le_Ldim_of_hasLTree (hasLTree_mono_V hUV (hasLTree_Ldim hU)) · have hemp : U = ∅ := Finset.not_nonempty_iff_eq_empty.mp hU subst hemp classical dsimp only [Ldim] have hfilt : (Finset.range ((∅ : Finset (α → β)).card + 1)).filter (fun d => hasLTree d (∅ : Finset (α → β))) = ∅ := by ext d; simp only [Finset.mem_filter, Finset.notMem_empty, iff_false, not_and] intro _ hd; exact Finset.not_nonempty_empty (hasLTree_of_le (Nat.zero_le d) hd) rw [hfilt]; simp lemma Ldim_eq_zero_iff_card_le_one {α β : Type*} [DecidableEq β] (V : Finset (α → β)) : Ldim V = 0 ↔ V.card ≤ 1 := by constructor · intro h0 by_contra hgt; push Not at hgt obtain ⟨f, hf, g, hg, hne⟩ := Finset.one_lt_card.mp hgt have hex : ∃ x : α, f x ≠ g x := by by_contra hall; push Not at hall; exact hne (funext hall) rcases hex with ⟨x, hfx⟩ have ht1 : hasLTree 1 V := ⟨x, f x, g x, hfx, ⟨f, Finset.mem_filter.mpr ⟨hf, rfl⟩⟩, ⟨g, Finset.mem_filter.mpr ⟨hg, rfl⟩⟩⟩ have := le_Ldim_of_hasLTree ht1 omega · intro hle by_contra hne have hpos : 1 ≤ Ldim V := Nat.pos_of_ne_zero hne by_cases hV : V.Nonempty · have h1 := hasLTree_of_le hpos (hasLTree_Ldim hV) have hc := hasLTree_card_ge h1 omega · have hemp : V = ∅ := Finset.not_nonempty_iff_eq_empty.mp hV subst hemp have h0 : Ldim (∅ : Finset (α → β)) = 0 := by classical dsimp only [Ldim] have hfilt : (Finset.range ((∅ : Finset (α → β)).card + 1)).filter (fun d => hasLTree d (∅ : Finset (α → β))) = ∅ := by ext d; simp only [Finset.mem_filter, Finset.notMem_empty, iff_false, not_and] intro _ hd; exact Finset.not_nonempty_empty (hasLTree_of_le (Nat.zero_le d) hd) rw [hfilt]; simp exact hne h0 /-- **Key Multiclass Littlestone Branching Property**: At ANY query point `x`, at MOST ONE label `y ∈ labels V x` can preserve `Ldim (restrict V x y) = Ldim V`; every other label strictly drops `Ldim` by at least `1`! -/ lemma Ldim_restrict_lt_of_ne {α β : Type*} [DecidableEq β] (V : Finset (α → β)) (x : α) {y₁ y₂ : β} (hy₁ : y₁ ∈ labels V x) (hy₂ : y₂ ∈ labels V x) (hne : y₁ ≠ y₂) (heq : Ldim (restrict V x y₁) = Ldim V) : Ldim (restrict V x y₂) < Ldim V := by have hle2 : Ldim (restrict V x y₂) ≤ Ldim V := Ldim_mono (restrict_subset V x y₂) by_contra hnot; push Not at hnot have heq2 : Ldim (restrict V x y₂) = Ldim V := le_antisymm hle2 hnot have ht1 : hasLTree (Ldim V) (restrict V x y₁) := by rw [← heq]; exact hasLTree_Ldim ((restrict_nonempty_iff V x y₁).mpr hy₁) have ht2 : hasLTree (Ldim V) (restrict V x y₂) := by rw [← heq2]; exact hasLTree_Ldim ((restrict_nonempty_iff V x y₂).mpr hy₂) have hsucc : hasLTree (Ldim V + 1) V := ⟨x, y₁, y₂, hne, ht1, ht2⟩ have := le_Ldim_of_hasLTree hsucc omega /-- **Multiclass Adaptive Sauer–Shelah–Natarajan Polynomial**: `sauerPoly k T d = ∑_{i = 0}^{d} C(T, i) * (k - 1)^i`. -/ def sauerPoly (k T d : ℕ) : ℕ := ∑ i ∈ Finset.range (d + 1), T.choose i * (k - 1) ^ i lemma sauerPoly_zero_T (k d : ℕ) : sauerPoly k 0 d = 1 := by dsimp only [sauerPoly] rw [Finset.sum_eq_single 0] · simp · intro i _ hi obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hi rw [Nat.choose_zero_succ, zero_mul] · intro h; exact absurd (Finset.mem_range.mpr (Nat.succ_pos d)) h lemma sauerPoly_zero_d (k T : ℕ) : sauerPoly k T 0 = 1 := by simp [sauerPoly] lemma sauerPoly_mono_d (k T : ℕ) {d₁ d₂ : ℕ} (h : d₁ ≤ d₂) : sauerPoly k T d₁ ≤ sauerPoly k T d₂ := Finset.sum_le_sum_of_subset (Finset.range_mono (Nat.succ_le_succ h)) /-- **Exact Multiclass Pascal Recurrence for `sauerPoly`**: `sauerPoly k (T + 1) (d + 1) = sauerPoly k T (d + 1) + (k - 1) * sauerPoly k T d`! -/ theorem sauerPoly_succ_succ (k T d : ℕ) : sauerPoly k (T + 1) (d + 1) = sauerPoly k T (d + 1) + (k - 1) * sauerPoly k T d := by dsimp only [sauerPoly] rw [Finset.sum_range_succ' _ (d + 1), Finset.sum_range_succ' _ (d + 1)] simp only [Nat.choose_zero_right, pow_zero, mul_one] have hsplit : ∑ i ∈ Finset.range (d + 1), (T + 1).choose (i + 1) * (k - 1) ^ (i + 1) = (∑ i ∈ Finset.range (d + 1), T.choose (i + 1) * (k - 1) ^ (i + 1)) + (k - 1) * ∑ i ∈ Finset.range (d + 1), T.choose i * (k - 1) ^ i := by rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ rw [Nat.choose_succ_succ, pow_succ']; ring omega /-- **EXACT MULTICLASS ADAPTIVE SAUER–SHELAH THEOREM (`adaptGrowth_le_sauerPoly`)**: For EVERY finite nonempty multiclass concept class `V` over ANY finite alphabet `β` with `k = |β|`, and EVERY horizon `T : ℕ`: `adaptGrowth T V ≤ ∑_{i = 0}^{Ldim V} C(T, i) * (|β| - 1)^i`, and consequently the exact minimax online log-loss satisfies `log (ctxShtarkovUnif detEval V T) ≤ log (sauerPoly |β| T (Ldim V))`! -/ theorem adaptGrowth_le_sauerPoly {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] [DecidableEq β] : ∀ (T : ℕ) (V : Finset (α → β)), adaptGrowth T V ≤ sauerPoly (Fintype.card β) T (Ldim V) | 0, V => by rw [sauerPoly_zero_T] simp only [adaptGrowth]; split_ifs <;> omega | T + 1, V => by by_cases h0 : Ldim V = 0 · have hc : V.card ≤ 1 := (Ldim_eq_zero_iff_card_le_one V).mp h0 rw [h0, sauerPoly_zero_d] exact le_trans (adaptGrowth_le_card (T + 1) V) hc · obtain ⟨d, hd⟩ : ∃ d, Ldim V = d + 1 := Nat.exists_eq_succ_of_ne_zero h0 rw [hd, sauerPoly_succ_succ] simp only [adaptGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun x _ => ?_ by_cases hex : ∃ yStar ∈ labels V x, Ldim (restrict V x yStar) = Ldim V · rcases hex with ⟨yStar, hyStar, hL_star⟩ rw [← Finset.add_sum_erase _ _ hyStar] have h1 : adaptGrowth T (restrict V x yStar) ≤ sauerPoly (Fintype.card β) T (d + 1) := by have := adaptGrowth_le_sauerPoly T (restrict V x yStar) rwa [hL_star, hd] at this have hrest : ∑ y ∈ (labels V x).erase yStar, adaptGrowth T (restrict V x y) ≤ ((labels V x).erase yStar).card * sauerPoly (Fintype.card β) T d := by calc ∑ y ∈ (labels V x).erase yStar, adaptGrowth T (restrict V x y) ≤ ∑ _y ∈ (labels V x).erase yStar, sauerPoly (Fintype.card β) T d := by refine Finset.sum_le_sum fun y hy => ?_ have hy_mem : y ∈ labels V x := Finset.mem_of_mem_erase hy have hy_ne : yStar ≠ y := (Finset.ne_of_mem_erase hy).symm have hlt := Ldim_restrict_lt_of_ne V x hyStar hy_mem hy_ne hL_star have hle : Ldim (restrict V x y) ≤ d := by omega exact le_trans (adaptGrowth_le_sauerPoly T (restrict V x y)) (sauerPoly_mono_d _ _ hle) _ = ((labels V x).erase yStar).card * sauerPoly (Fintype.card β) T d := by rw [Finset.sum_const, smul_eq_mul] have hcard_erase : ((labels V x).erase yStar).card ≤ Fintype.card β - 1 := by rw [Finset.card_erase_of_mem hyStar] have hle_k : (labels V x).card ≤ Fintype.card β := Finset.card_le_univ _ omega have h2 : ((labels V x).erase yStar).card * sauerPoly (Fintype.card β) T d ≤ (Fintype.card β - 1) * sauerPoly (Fintype.card β) T d := Nat.mul_le_mul_right _ hcard_erase omega · push Not at hex by_cases hne : (labels V x).Nonempty · rcases hne with ⟨yStar, hyStar⟩ rw [← Finset.add_sum_erase _ _ hyStar] have h1 : adaptGrowth T (restrict V x yStar) ≤ sauerPoly (Fintype.card β) T (d + 1) := by have hle : Ldim (restrict V x yStar) ≤ d + 1 := by rw [← hd]; exact Ldim_mono (restrict_subset V x yStar) exact le_trans (adaptGrowth_le_sauerPoly T (restrict V x yStar)) (sauerPoly_mono_d _ _ hle) have hrest : ∑ y ∈ (labels V x).erase yStar, adaptGrowth T (restrict V x y) ≤ (Fintype.card β - 1) * sauerPoly (Fintype.card β) T d := by have hcard_erase : ((labels V x).erase yStar).card ≤ Fintype.card β - 1 := by rw [Finset.card_erase_of_mem hyStar] have hle_k : (labels V x).card ≤ Fintype.card β := Finset.card_le_univ _ omega calc ∑ y ∈ (labels V x).erase yStar, adaptGrowth T (restrict V x y) ≤ ∑ _y ∈ (labels V x).erase yStar, sauerPoly (Fintype.card β) T d := by refine Finset.sum_le_sum fun y hy => ?_ have hy_mem : y ∈ labels V x := Finset.mem_of_mem_erase hy have hle_V : Ldim (restrict V x y) ≤ Ldim V := Ldim_mono (restrict_subset V x y) have hne_V := hex y hy_mem have hle : Ldim (restrict V x y) ≤ d := by omega exact le_trans (adaptGrowth_le_sauerPoly T (restrict V x y)) (sauerPoly_mono_d _ _ hle) _ = ((labels V x).erase yStar).card * sauerPoly (Fintype.card β) T d := by rw [Finset.sum_const, smul_eq_mul] _ ≤ (Fintype.card β - 1) * sauerPoly (Fintype.card β) T d := Nat.mul_le_mul_right _ hcard_erase omega · rw [Finset.not_nonempty_iff_eq_empty.mp hne, Finset.sum_empty]; exact Nat.zero_le _ /-- **`k`-ary Hamming Ball Concept Class `B_k(T, d)`** on `Fin T → Fin k`: all functions with at most `d` nonzero coordinates. -/ def hammingBall (k T d : ℕ) [NeZero k] : Finset (Fin T → Fin k) := Finset.univ.filter fun h => (Finset.univ.filter fun i : Fin T => h i ≠ 0).card ≤ d lemma hammingBall_card (k : ℕ) [NeZero k] : ∀ (T d : ℕ), (hammingBall k T d).card = sauerPoly k T d | 0, d => by rw [sauerPoly_zero_T] have huniv : hammingBall k 0 d = Finset.univ := by ext h; simp [hammingBall] rw [huniv, Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_fin, pow_zero] | T + 1, 0 => by rw [sauerPoly_zero_d] have hsing : hammingBall k (T + 1) 0 = {fun _ => 0} := by ext h simp only [hammingBall, Finset.mem_filter, Finset.mem_univ, true_and, Nat.le_zero, Finset.card_eq_zero, Finset.filter_eq_empty_iff, not_not, Finset.mem_singleton] exact ⟨fun hall => funext fun i => hall trivial, fun heq i _ => by rw [heq]⟩ rw [hsing, Finset.card_singleton] | T + 1, d + 1 => by rw [sauerPoly_succ_succ] -- Split by h 0 = 0 vs h 0 ≠ 0! have hpart : (hammingBall k (T + 1) (d + 1)).card = ∑ y : Fin k, (restrict (hammingBall k (T + 1) (d + 1)) 0 y).card := by have h := Finset.card_eq_sum_card_fiberwise (f := fun h : Fin (T + 1) → Fin k => h 0) (s := hammingBall k (T + 1) (d + 1)) (t := Finset.univ) (fun _ _ => Finset.mem_univ _) exact h rw [hpart, ← Finset.add_sum_erase _ _ (Finset.mem_univ (0 : Fin k))] -- For y = 0: bijection with hammingBall k T (d + 1) via Fin.cons 0! have h0_card : (restrict (hammingBall k (T + 1) (d + 1)) 0 0).card = (hammingBall k T (d + 1)).card := by refine Finset.card_bij (fun h _ => fun i : Fin T => h i.succ) ?_ ?_ ?_ · intro h hh simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hh ⊢ have hinj : (Finset.univ.filter fun i : Fin T => h i.succ ≠ 0).card ≤ (Finset.univ.filter fun j : Fin (T + 1) => h j ≠ 0).card := by refine Finset.card_le_card_of_injOn Fin.succ ?_ (fun _ _ _ _ heq => Fin.succ_injective _ heq) intro i hi; simp only [Finset.mem_coe, Finset.mem_filter, Finset.mem_univ, true_and] at hi ⊢; exact hi omega · intro h₁ hh₁ h₂ hh₂ heq have h01 := (Finset.mem_filter.mp hh₁).2 have h02 := (Finset.mem_filter.mp hh₂).2 funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j; exact h01.trans h02.symm · intro g hg refine ⟨Fin.cons (α := fun _ => Fin k) 0 g, ?_, by funext i; simp⟩ simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hg ⊢ refine ⟨?_, by simp⟩ have heq_set : (Finset.univ.filter fun j : Fin (T + 1) => Fin.cons (α := fun _ => Fin k) (0 : Fin k) g j ≠ 0) = (Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩ := by ext j; refine Fin.cases (by simp) (fun i => by simp) j rw [heq_set, Finset.card_map]; exact hg -- For y ≠ 0: bijection with hammingBall k T d via Fin.cons y! have hne_card : ∀ y : Fin k, y ≠ 0 → (restrict (hammingBall k (T + 1) (d + 1)) 0 y).card = (hammingBall k T d).card := by intro y hy refine Finset.card_bij (fun h _ => fun i : Fin T => h i.succ) ?_ ?_ ?_ · intro h hh simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hh ⊢ have heq_set : (Finset.univ.filter fun j : Fin (T + 1) => h j ≠ 0) = insert 0 ((Finset.univ.filter fun i : Fin T => h i.succ ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩) := by ext j; refine Fin.cases ?_ (fun i => ?_) j · simp [hh.2, hy] · simp have hnot : (0 : Fin (T + 1)) ∉ (Finset.univ.filter fun i : Fin T => h i.succ ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩ := by simp rw [heq_set, Finset.card_insert_of_notMem hnot, Finset.card_map] at hh omega · intro h₁ hh₁ h₂ hh₂ heq have h01 := (Finset.mem_filter.mp hh₁).2 have h02 := (Finset.mem_filter.mp hh₂).2 funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j; exact h01.trans h02.symm · intro g hg refine ⟨Fin.cons (α := fun _ => Fin k) y g, ?_, by funext i; simp⟩ simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hg ⊢ refine ⟨?_, by simp⟩ have heq_set : (Finset.univ.filter fun j : Fin (T + 1) => Fin.cons (α := fun _ => Fin k) y g j ≠ 0) = insert 0 ((Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩) := by ext j; refine Fin.cases ?_ (fun i => ?_) j · simp [hy] · simp have hnot : (0 : Fin (T + 1)) ∉ (Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩ := by simp rw [heq_set, Finset.card_insert_of_notMem hnot, Finset.card_map]; omega rw [h0_card, Finset.sum_congr rfl fun y hy => hne_card y (Finset.ne_of_mem_erase hy), Finset.sum_const, smul_eq_mul, Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, Fintype.card_fin, hammingBall_card k T (d + 1), hammingBall_card k T d] lemma adaptGrowth_ge_card_of_card_le {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq α] [DecidableEq β] (V : Finset (α → β)) : ∀ (S : Finset α), (∀ f ∈ V, ∀ g ∈ V, (∀ x ∈ S, f x = g x) → f = g) → V.card ≤ adaptGrowth S.card V := by intro S induction hn : S.card using Nat.strong_induction_on generalizing S V with | h n ih => subst hn intro hsep by_cases hS : S.Nonempty · rcases hS with ⟨x0, hx0⟩ have hcard_pos : 0 < S.card := Finset.card_pos.mpr ⟨x0, hx0⟩ have hsucc : S.card = (S.erase x0).card + 1 := (Finset.card_erase_add_one hx0).symm rw [hsucc] simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels V x, adaptGrowth (S.erase x0).card (restrict V x y)) (Finset.mem_univ x0)) rw [← sum_card_restrict V x0] refine Finset.sum_le_sum fun y _ => ?_ refine ih (S.erase x0).card (by omega) (restrict V x0 y) (S.erase x0) rfl ?_ intro f hf g hg heq apply hsep f (restrict_subset V x0 y hf) g (restrict_subset V x0 y hg) intro x hx by_cases hxx0 : x = x0 · subst hxx0; exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm · exact heq x (Finset.mem_erase.mpr ⟨hxx0, hx⟩) · have hemp : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS subst hemp simp only [Finset.card_empty, adaptGrowth] by_cases hV : V.Nonempty · simp only [hV, ↓reduceIte] rcases hV with ⟨f0, hf0⟩ have hsub : V ⊆ {f0} := fun g hg => Finset.mem_singleton.mpr (hsep g hg f0 hf0 (by simp)) exact le_trans (Finset.card_le_card hsub) (by simp) · rw [Finset.not_nonempty_iff_eq_empty.mp hV]; simp lemma hasLTree_hammingBall {k : ℕ} (hk : 2 ≤ k) [NeZero k] : ∀ (T d : ℕ), d ≤ T → hasLTree d (hammingBall k T d) | T, 0, _ => ⟨fun _ => 0, by simp [hammingBall]⟩ | 0, d + 1, hle => by omega | T + 1, d + 1, hle => by have h1 : (⟨1, by omega⟩ : Fin k) ≠ 0 := by intro h; have := congrArg Fin.val h; simp at this refine ⟨0, 0, ⟨1, by omega⟩, h1.symm, ?_, ?_⟩ · -- Lift hasLTree d (hammingBall k T d) via Fin.cons 0 into restrict (hammingBall k (T+1) (d+1)) 0 0! have hlift : ∀ {m : ℕ} {U : Finset (Fin T → Fin k)} {W : Finset (Fin (T + 1) → Fin k)}, (∀ g ∈ U, Fin.cons (α := fun _ => Fin k) (0 : Fin k) g ∈ W) → hasLTree m U → hasLTree m W := by intro m induction m with | zero => intro U W hmap ⟨g, hg⟩; exact ⟨Fin.cons (α := fun _ => Fin k) 0 g, hmap g hg⟩ | succ m ih => intro U W hmap ⟨i, y₁, y₂, hne, ht1, ht2⟩ refine ⟨i.succ, y₁, y₂, hne, ih (fun g hg => ?_) ht1, ih (fun g hg => ?_) ht2⟩ · exact Finset.mem_filter.mpr ⟨hmap g (Finset.mem_filter.mp hg).1, by simpa using (Finset.mem_filter.mp hg).2⟩ · exact Finset.mem_filter.mpr ⟨hmap g (Finset.mem_filter.mp hg).1, by simpa using (Finset.mem_filter.mp hg).2⟩ refine hlift (U := hammingBall k T d) (fun g hg => ?_) (hasLTree_hammingBall hk T d (by omega)) simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hg ⊢ refine ⟨?_, by simp⟩ have heq_set : (Finset.univ.filter fun j : Fin (T + 1) => Fin.cons (α := fun _ => Fin k) (0 : Fin k) g j ≠ 0) = (Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩ := by ext j; refine Fin.cases (by simp) (fun i => by simp) j rw [heq_set, Finset.card_map]; omega · -- Lift hasLTree d (hammingBall k T d) via Fin.cons 1 into restrict (hammingBall k (T+1) (d+1)) 0 1! have hlift : ∀ {m : ℕ} {U : Finset (Fin T → Fin k)} {W : Finset (Fin (T + 1) → Fin k)}, (∀ g ∈ U, Fin.cons (α := fun _ => Fin k) (⟨1, by omega⟩ : Fin k) g ∈ W) → hasLTree m U → hasLTree m W := by intro m induction m with | zero => intro U W hmap ⟨g, hg⟩; exact ⟨Fin.cons (α := fun _ => Fin k) ⟨1, by omega⟩ g, hmap g hg⟩ | succ m ih => intro U W hmap ⟨i, y₁, y₂, hne, ht1, ht2⟩ refine ⟨i.succ, y₁, y₂, hne, ih (fun g hg => ?_) ht1, ih (fun g hg => ?_) ht2⟩ · exact Finset.mem_filter.mpr ⟨hmap g (Finset.mem_filter.mp hg).1, by simpa using (Finset.mem_filter.mp hg).2⟩ · exact Finset.mem_filter.mpr ⟨hmap g (Finset.mem_filter.mp hg).1, by simpa using (Finset.mem_filter.mp hg).2⟩ refine hlift (U := hammingBall k T d) (fun g hg => ?_) (hasLTree_hammingBall hk T d (by omega)) simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hg ⊢ refine ⟨?_, by simp⟩ have heq_set : (Finset.univ.filter fun j : Fin (T + 1) => Fin.cons (α := fun _ => Fin k) (⟨1, by omega⟩ : Fin k) g j ≠ 0) = insert 0 ((Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩) := by ext j; refine Fin.cases (by simp [h1]) (fun i => by simp) j have hnot : (0 : Fin (T + 1)) ∉ (Finset.univ.filter fun i : Fin T => g i ≠ 0).map ⟨Fin.succ, Fin.succ_injective _⟩ := by simp rw [heq_set, Finset.card_insert_of_notMem hnot, Finset.card_map]; omega lemma not_hasLTree_hammingBall {k : ℕ} [NeZero k] : ∀ (d : ℕ) (T : ℕ), ¬ hasLTree (d + 1) (hammingBall k T d) | 0, T, h => by have hc := hasLTree_card_ge h rw [hammingBall_card, sauerPoly_zero_d] at hc; omega | d + 1, T, ⟨x, y₁, y₂, hne, ht1, ht2⟩ => by -- At least one of y₁, y₂ is nonzero; on that branch every concept has ≤ d nonzero entries on Fin T \ {x}! have hnz : ∃ y : Fin k, y ≠ 0 ∧ hasLTree (d + 1) (restrict (hammingBall k T (d + 1)) x y) := by by_cases hy1 : y₁ = 0 · exact ⟨y₂, fun h => hne (hy1.trans h.symm), ht2⟩ · exact ⟨y₁, hy1, ht1⟩ rcases hnz with ⟨y, hy0, hty⟩ -- Project out coordinate x into Fin (T - 1) → Fin k! have hTpos : 0 < T := Fin.pos_iff_nonempty.mpr ⟨x⟩ obtain ⟨T', rfl⟩ : ∃ T', T = T' + 1 := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hTpos) -- Map Fin (T' + 1) → Fin k to Fin T' → Fin k via x.succAbove let proj : (Fin (T' + 1) → Fin k) → (Fin T' → Fin k) := fun h i => h (x.succAbove i) have hproj_tree : ∀ {m : ℕ} {U : Finset (Fin (T' + 1) → Fin k)}, (∀ h ∈ U, h x = y) → hasLTree m U → hasLTree m (U.image proj) := by intro m induction m with | zero => intro U _ ⟨h, hh⟩; exact ⟨proj h, Finset.mem_image_of_mem _ hh⟩ | succ m ih => intro U hconst ⟨z, z₁, z₂, hzne, h1, h2⟩ have hzx : z ≠ x := by intro hzx; subst hzx rcases hasLTree_of_le (Nat.zero_le m) h1 with ⟨f1, hf1⟩ rcases hasLTree_of_le (Nat.zero_le m) h2 with ⟨f2, hf2⟩ have e1 := (Finset.mem_filter.mp hf1).2 have e2 := (Finset.mem_filter.mp hf2).2 have c1 := hconst f1 (Finset.mem_filter.mp hf1).1 have c2 := hconst f2 (Finset.mem_filter.mp hf2).1 exact hzne (e1.symm.trans (c1.trans (c2.symm.trans e2))) obtain ⟨i, rfl⟩ := Fin.exists_succAbove_eq hzx have hsub : ∀ z₀, (restrict U (x.succAbove i) z₀).image proj ⊆ restrict (U.image proj) i z₀ := by intro z₀ g hg rcases Finset.mem_image.mp hg with ⟨f, hf, rfl⟩ exact Finset.mem_filter.mpr ⟨Finset.mem_image_of_mem _ (Finset.mem_filter.mp hf).1, (Finset.mem_filter.mp hf).2⟩ exact ⟨i, z₁, z₂, hzne, hasLTree_mono_V (hsub z₁) (ih (fun h hh => hconst h (restrict_subset U _ _ hh)) h1), hasLTree_mono_V (hsub z₂) (ih (fun h hh => hconst h (restrict_subset U _ _ hh)) h2)⟩ have ht_img := hproj_tree (fun h hh => (Finset.mem_filter.mp hh).2) hty have himg_sub : (restrict (hammingBall k (T' + 1) (d + 1)) x y).image proj ⊆ hammingBall k T' d := by intro g hg rcases Finset.mem_image.mp hg with ⟨h, hh, rfl⟩ simp only [restrict, hammingBall, Finset.mem_filter, Finset.mem_univ, true_and] at hh ⊢ have hinj : (Finset.univ.filter fun i : Fin T' => h (x.succAbove i) ≠ 0).card + 1 ≤ (Finset.univ.filter fun j : Fin (T' + 1) => h j ≠ 0).card := by have hsub : insert x ((Finset.univ.filter fun i : Fin T' => h (x.succAbove i) ≠ 0).map ⟨x.succAbove, Fin.succAbove_right_injective⟩) ⊆ Finset.univ.filter fun j : Fin (T' + 1) => h j ≠ 0 := by intro j hj simp only [Finset.mem_insert, Finset.mem_map, Finset.mem_filter, Finset.mem_univ, true_and, Function.Embedding.coeFn_mk] at hj ⊢ rcases hj with rfl | ⟨i, hi, rfl⟩ · rw [hh.2]; exact hy0 · exact hi have hnot : x ∉ (Finset.univ.filter fun i : Fin T' => h (x.succAbove i) ≠ 0).map ⟨x.succAbove, Fin.succAbove_right_injective⟩ := by simp only [Finset.mem_map, Finset.mem_filter, Finset.mem_univ, true_and, Function.Embedding.coeFn_mk, not_exists, not_and] intro i _; exact Fin.succAbove_ne x i have hc := Finset.card_le_card hsub rw [Finset.card_insert_of_notMem hnot, Finset.card_map] at hc exact hc dsimp only [proj]; omega exact not_hasLTree_hammingBall d T' (hasLTree_mono_V himg_sub ht_img) /-- **EXACT SHARPNESS OF MULTICLASS ADAPTIVE SAUER–SHELAH ON `k`-ARY HAMMING BALLS**: For ALL `k ≥ 2`, `T ≥ 1`, and `d ≤ T`: `Ldim (hammingBall k T d) = d` AND `adaptGrowth T (hammingBall k T d) = sauerPoly k T d`! -/ theorem hammingBall_achieves_sauer_equality {k T d : ℕ} (hk : 2 ≤ k) [NeZero k] (hT : 0 < T) (hd : d ≤ T) : have : Nonempty (Fin T) := Fin.pos_iff_nonempty.mp hT Ldim (hammingBall k T d) = d ∧ adaptGrowth T (hammingBall k T d) = sauerPoly k T d := by have : Nonempty (Fin T) := Fin.pos_iff_nonempty.mp hT have hL : Ldim (hammingBall k T d) = d := by apply le_antisymm · by_contra hgt; push Not at hgt have hne : (hammingBall k T d).Nonempty := ⟨fun _ => 0, by simp [hammingBall]⟩ have ht := hasLTree_of_le (Nat.succ_le_of_lt hgt) (hasLTree_Ldim hne) exact not_hasLTree_hammingBall d T ht · exact le_Ldim_of_hasLTree (hasLTree_hammingBall hk T d hd) refine ⟨hL, le_antisymm ?_ ?_⟩ · have h := adaptGrowth_le_sauerPoly T (hammingBall k T d) rw [Fintype.card_fin, hL] at h; exact h · rw [← hammingBall_card k T d] have h := adaptGrowth_ge_card_of_card_le (hammingBall k T d) (Finset.univ : Finset (Fin T)) (fun f _ g _ heq => funext fun i => heq i (Finset.mem_univ i)) simpa using h /-- **Oblivious (Fixed-Design) Growth Function `Π_T(V)`** (= oblivious horizon-`T` Shtarkov sum). -/ def obliviousGrowth {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] (T : ℕ) (V : Finset (α → β)) : ℕ := Finset.univ.sup' Finset.univ_nonempty fun xs : Fin T → α => (V.image fun h => fun i : Fin T => h (xs i)).card /-- **Universal Oblivious ≤ Adaptive Domination (`Π_T(V) ≤ S_T^adapt(V)`)**. -/ theorem obliviousGrowth_le_adaptGrowth {α β : Type*} [Fintype α] [Nonempty α] [DecidableEq β] : ∀ (T : ℕ) (V : Finset (α → β)), obliviousGrowth T V ≤ adaptGrowth T V | 0, V => by simp only [obliviousGrowth, adaptGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun xs _ => ?_ by_cases hV : V.Nonempty · simp only [hV, ↓reduceIte] have hsub : (V.image fun h : α → β => fun i : Fin 0 => h (xs i)) ⊆ {Fin.elim0} := by intro f hf; simp only [Finset.mem_singleton]; funext i; exact Fin.elim0 i exact le_trans (Finset.card_le_card hsub) (by simp) · rw [Finset.not_nonempty_iff_eq_empty.mp hV]; simp | T + 1, V => by simp only [obliviousGrowth, adaptGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun xs _ => ?_ refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels V x, adaptGrowth T (restrict V x y)) (Finset.mem_univ (xs 0))) let img := V.image fun h => fun i : Fin (T + 1) => h (xs i) have hpart : img.card = ∑ y ∈ labels V (xs 0), (img.filter fun p => p 0 = y).card := by exact Finset.card_eq_sum_card_fiberwise (f := fun p : Fin (T + 1) → β => p 0) (s := img) (t := labels V (xs 0)) fun p hp => by rcases Finset.mem_image.mp hp with ⟨h, hh, rfl⟩ exact Finset.mem_image_of_mem _ hh rw [hpart] refine Finset.sum_le_sum fun y _ => ?_ let xs' : Fin T → α := fun i => xs i.succ have hcard_le : (img.filter fun p => p 0 = y).card ≤ ((restrict V (xs 0) y).image fun h => fun i : Fin T => h (xs' i)).card := by refine Finset.card_le_card_of_injOn (fun p i => p i.succ) ?_ ?_ · intro p hp rcases Finset.mem_filter.mp hp with ⟨hp_img, hp0⟩ rcases Finset.mem_image.mp hp_img with ⟨h, hh, rfl⟩ exact Finset.mem_image.mpr ⟨h, Finset.mem_filter.mpr ⟨hh, hp0⟩, rfl⟩ · intro p₁ hp₁ p₂ hp₂ heq funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j exact (Finset.mem_filter.mp hp₁).2.trans (Finset.mem_filter.mp hp₂).2.symm exact le_trans hcard_le (le_trans (Finset.le_sup' (f := fun ys : Fin T → α => ((restrict V (xs 0) y).image fun h => fun i => h (ys i)).card) (Finset.mem_univ xs')) (obliviousGrowth_le_adaptGrowth T (restrict V (xs 0) y))) /-- 1D threshold concept class on `Fin N` (`N + 1` concepts: `h_k(i) = decide (k ≤ i)`). -/ def threshClass (N : ℕ) : Finset (Fin N → Bool) := (Finset.range (N + 1)).image fun k => fun i : Fin N => decide (k ≤ i.val) lemma threshClass_card (N : ℕ) : (threshClass N).card = N + 1 := by dsimp only [threshClass] rw [Finset.card_image_of_injOn] · simp · intro k₁ hk₁ k₂ hk₂ heq simp only [Finset.mem_coe, Finset.mem_range] at hk₁ hk₂ by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have h := congrFun heq ⟨k₁, by omega⟩ simp only [decide_eq_decide] at h have : k₁ ≤ k₁ := le_rfl have := h.mp this; omega · have h := congrFun heq ⟨k₂, by omega⟩ simp only [decide_eq_decide] at h have : k₂ ≤ k₂ := le_rfl have := h.mpr this; omega /-- **Oblivious Growth of 1D Thresholds is Linear (`Π_T(threshClass N) ≤ T + 1`)**. -/ theorem obliviousGrowth_threshClass_le (N : ℕ) [NeZero N] (T : ℕ) : obliviousGrowth T (threshClass N) ≤ T + 1 := by simp only [obliviousGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun xs _ => ?_ -- Every restriction p = fun i => decide (k ≤ (xs i).val) is uniquely determined by -- the count of indices i where p i = true, which lies in Finset.range (T + 1)! let countTrue : (Fin T → Bool) → ℕ := fun p => (Finset.univ.filter fun i : Fin T => p i = true).card have hinj : Set.InjOn countTrue ↑((threshClass N).image fun h => fun i : Fin T => h (xs i)) := by intro p₁ hp₁ p₂ hp₂ hcnt simp only [Finset.mem_coe, Finset.mem_image, threshClass, Finset.mem_range] at hp₁ hp₂ rcases hp₁ with ⟨_, ⟨k₁, _, rfl⟩, rfl⟩ rcases hp₂ with ⟨_, ⟨k₂, _, rfl⟩, rfl⟩ dsimp only [countTrue] at hcnt -- Because k ≤ (xs i).val is antitone in k, one filter set is a subset of the other; equal card → equal sets! rcases le_total k₁ k₂ with hle | hle · have hsub : (Finset.univ.filter fun i : Fin T => decide (k₂ ≤ (xs i).val) = true) ⊆ (Finset.univ.filter fun i : Fin T => decide (k₁ ≤ (xs i).val) = true) := by intro i hi; simp only [Finset.mem_filter, Finset.mem_univ, true_and, decide_eq_true_eq] at hi ⊢; omega have heq_set := Finset.eq_of_subset_of_card_le hsub (le_of_eq hcnt) funext i have := Finset.ext_iff.mp heq_set i simp only [Finset.mem_filter, Finset.mem_univ, true_and, decide_eq_true_eq] at this simp [this] · have hsub : (Finset.univ.filter fun i : Fin T => decide (k₁ ≤ (xs i).val) = true) ⊆ (Finset.univ.filter fun i : Fin T => decide (k₂ ≤ (xs i).val) = true) := by intro i hi; simp only [Finset.mem_filter, Finset.mem_univ, true_and, decide_eq_true_eq] at hi ⊢; omega have heq_set := Finset.eq_of_subset_of_card_le hsub (le_of_eq hcnt.symm) funext i have := Finset.ext_iff.mp heq_set i simp only [Finset.mem_filter, Finset.mem_univ, true_and, decide_eq_true_eq] at this simp [this] have hmaps : ∀ p ∈ ((threshClass N).image fun h => fun i : Fin T => h (xs i)), countTrue p ∈ Finset.range (T + 1) := fun p _ => Finset.mem_range.mpr (Nat.lt_succ_of_le (le_trans (Finset.card_filter_le _ _) (by simp))) have hc := Finset.card_le_card_of_injOn countTrue hmaps hinj simpa using hc /-- Sub-interval of 1D thresholds `[a, b)` on `Fin N` (`h_k` for `a ≤ k < b`). -/ def threshInterval (N a b : ℕ) : Finset (Fin N → Bool) := (Finset.Ico a b).image fun k => fun i : Fin N => decide (k ≤ i.val) lemma adaptGrowth_threshInterval_pow2 (N : ℕ) [NeZero N] : ∀ (T a b : ℕ), b ≤ N + 1 → a + 2 ^ T ≤ b → 2 ^ T ≤ adaptGrowth T (threshInterval N a b) | 0, a, b, _, hle => by simp only [pow_zero, adaptGrowth] have hne : (threshInterval N a b).Nonempty := ⟨fun i => decide (a ≤ i.val), Finset.mem_image.mpr ⟨a, Finset.mem_Ico.mpr ⟨le_rfl, by omega⟩, rfl⟩⟩ simp [hne] | T + 1, a, b, hb, hle => by have hpow_pos : 1 ≤ 2 ^ T := Nat.one_le_two_pow rw [pow_succ] at hle have hmid_lt : a + 2 ^ T - 1 < N := by omega let x : Fin N := ⟨a + 2 ^ T - 1, hmid_lt⟩ have hsub_true : threshInterval N a (a + 2 ^ T) ⊆ restrict (threshInterval N a b) x true := by intro f hf rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩ rw [Finset.mem_Ico] at hk refine Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨k, Finset.mem_Ico.mpr ⟨hk.1, by omega⟩, rfl⟩, ?_⟩ simp only [x, decide_eq_true_eq]; omega have hsub_false : threshInterval N (a + 2 ^ T) b ⊆ restrict (threshInterval N a b) x false := by intro f hf rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩ rw [Finset.mem_Ico] at hk refine Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨k, Finset.mem_Ico.mpr ⟨by omega, hk.2⟩, rfl⟩, ?_⟩ simp only [x, decide_eq_false_iff_not]; omega have ht_mem : true ∈ labels (threshInterval N a b) x := (restrict_nonempty_iff _ x true).mp (Finset.Nonempty.mono hsub_true ⟨_, Finset.mem_image.mpr ⟨a, Finset.mem_Ico.mpr ⟨le_rfl, by omega⟩, rfl⟩⟩) have hf_mem : false ∈ labels (threshInterval N a b) x := (restrict_nonempty_iff _ x false).mp (Finset.Nonempty.mono hsub_false ⟨_, Finset.mem_image.mpr ⟨a + 2 ^ T, Finset.mem_Ico.mpr ⟨le_rfl, by omega⟩, rfl⟩⟩) have hpair : ({false, true} : Finset Bool) ⊆ labels (threshInterval N a b) x := by intro y hy; simp only [Finset.mem_insert, Finset.mem_singleton] at hy rcases hy with rfl | rfl; exact hf_mem; exact ht_mem have ih1 := adaptGrowth_threshInterval_pow2 N T a (a + 2 ^ T) (by omega) le_rfl have ih2 := adaptGrowth_threshInterval_pow2 N T (a + 2 ^ T) b hb (by omega) simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x' => ∑ y ∈ labels (threshInterval N a b) x', adaptGrowth T (restrict (threshInterval N a b) x' y)) (Finset.mem_univ x)) calc 2 ^ (T + 1) = 2 ^ T + 2 ^ T := by rw [pow_succ]; ring _ ≤ adaptGrowth T (threshInterval N (a + 2 ^ T) b) + adaptGrowth T (threshInterval N a (a + 2 ^ T)) := Nat.add_le_add ih2 ih1 _ ≤ adaptGrowth T (restrict (threshInterval N a b) x false) + adaptGrowth T (restrict (threshInterval N a b) x true) := Nat.add_le_add (adaptGrowth_mono T hsub_false) (adaptGrowth_mono T hsub_true) _ = ∑ y ∈ ({false, true} : Finset Bool), adaptGrowth T (restrict (threshInterval N a b) x y) := by rw [Finset.sum_pair (by decide : (false : Bool) ≠ true)] _ ≤ ∑ y ∈ labels (threshInterval N a b) x, adaptGrowth T (restrict (threshInterval N a b) x y) := Finset.sum_le_sum_of_subset hpair /-- **EXPONENTIAL ADAPTIVE-VS-OBLIVIOUS ONLINE LOG-LOSS SEPARATION ON 1D THRESHOLDS**: On `threshClass (2^m - 1)` (`|V| = 2^m`), for EVERY `m ≥ 1` and `T ≤ m`: - Oblivious minimax log-loss `≤ Real.log (T + 1)` (`obliviousGrowth ≤ T + 1`), - Adaptive minimax log-loss `= T * Real.log 2` (`adaptGrowth = 2^T`)! -/ theorem threshClass_adaptive_vs_oblivious_exponential_separation {m T : ℕ} (hm : 1 ≤ m) (hT : T ≤ m) : have : NeZero (2 ^ m - 1) := ⟨by have : 2 ≤ 2 ^ m := le_trans (by norm_num : 2 ≤ 2 ^ 1) (Nat.pow_le_pow_right (by norm_num) hm); omega⟩ obliviousGrowth T (threshClass (2 ^ m - 1)) ≤ T + 1 ∧ adaptGrowth T (threshClass (2 ^ m - 1)) = 2 ^ T := by have h2m : 2 ≤ 2 ^ m := le_trans (by norm_num : 2 ≤ 2 ^ 1) (Nat.pow_le_pow_right (by norm_num) hm) have : NeZero (2 ^ m - 1) := ⟨by omega⟩ refine ⟨obliviousGrowth_threshClass_le (2 ^ m - 1) T, le_antisymm ?_ ?_⟩ · have h := adaptGrowth_le_sauerPoly T (threshClass (2 ^ m - 1)) rw [Fintype.card_bool] at h have hs : ∀ d, sauerPoly 2 T d ≤ 2 ^ T := fun d => by dsimp only [sauerPoly] simp only [Nat.reduceSub, one_pow, mul_one] calc ∑ i ∈ Finset.range (d + 1), T.choose i ≤ ∑ i ∈ Finset.range (max d T + 1), T.choose i := Finset.sum_le_sum_of_subset (Finset.range_mono (Nat.succ_le_succ (le_max_left d T))) _ = ∑ i ∈ Finset.range (T + 1), T.choose i := by refine (Finset.sum_subset (Finset.range_mono (Nat.succ_le_succ (le_max_right d T))) fun i _ hi => ?_).symm exact Nat.choose_eq_zero_of_lt (by simp only [Finset.mem_range] at hi; omega) _ = 2 ^ T := Nat.sum_range_choose T exact le_trans h (hs _) · have heq : threshClass (2 ^ m - 1) = threshInterval (2 ^ m - 1) 0 (2 ^ m) := by dsimp only [threshClass, threshInterval] have h1 : 2 ^ m - 1 + 1 = 2 ^ m := by omega rw [h1]; ext h; simp [Nat.Ico_zero_eq_range] rw [heq] exact adaptGrowth_threshInterval_pow2 (2 ^ m - 1) T 0 (2 ^ m) (by omega) (by rw [zero_add]; exact Nat.pow_le_pow_right (by norm_num) hT) /-- Disjoint-domain product class `V₁ × V₂` on `α₁ ⊕ α₂ → β`. -/ def prodClass {α₁ α₂ β : Type*} [Fintype α₁] [Fintype α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] (V₁ : Finset (α₁ → β)) (V₂ : Finset (α₂ → β)) : Finset (α₁ ⊕ α₂ → β) := (V₁ ×ˢ V₂).image fun pq => Sum.elim pq.1 pq.2 lemma labels_prodClass_inl {α₁ α₂ β : Type*} [Fintype α₁] [Fintype α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] {V₁ : Finset (α₁ → β)} {V₂ : Finset (α₂ → β)} (hV₂ : V₂.Nonempty) (x : α₁) : labels (prodClass V₁ V₂) (Sum.inl x) = labels V₁ x := by ext y; simp only [labels, prodClass, Finset.mem_image, Finset.mem_product, Prod.exists] constructor · rintro ⟨_, ⟨h₁, h₂, ⟨hh₁, _⟩, rfl⟩, rfl⟩; exact ⟨h₁, hh₁, rfl⟩ · rintro ⟨h₁, hh₁, rfl⟩; rcases hV₂ with ⟨h₂, hh₂⟩ exact ⟨Sum.elim h₁ h₂, ⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, rfl⟩ lemma labels_prodClass_inr {α₁ α₂ β : Type*} [Fintype α₁] [Fintype α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] {V₁ : Finset (α₁ → β)} {V₂ : Finset (α₂ → β)} (hV₁ : V₁.Nonempty) (x : α₂) : labels (prodClass V₁ V₂) (Sum.inr x) = labels V₂ x := by ext y; simp only [labels, prodClass, Finset.mem_image, Finset.mem_product, Prod.exists] constructor · rintro ⟨_, ⟨h₁, h₂, ⟨_, hh₂⟩, rfl⟩, rfl⟩; exact ⟨h₂, hh₂, rfl⟩ · rintro ⟨h₂, hh₂, rfl⟩; rcases hV₁ with ⟨h₁, hh₁⟩ exact ⟨Sum.elim h₁ h₂, ⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, rfl⟩ lemma restrict_prodClass_inl {α₁ α₂ β : Type*} [Fintype α₁] [Fintype α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] (V₁ : Finset (α₁ → β)) (V₂ : Finset (α₂ → β)) (x : α₁) (y : β) : restrict (prodClass V₁ V₂) (Sum.inl x) y = prodClass (restrict V₁ x y) V₂ := by ext f; simp only [restrict, prodClass, Finset.mem_filter, Finset.mem_image, Finset.mem_product, Prod.exists] constructor · rintro ⟨⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, hfx⟩; exact ⟨h₁, h₂, ⟨⟨hh₁, hfx⟩, hh₂⟩, rfl⟩ · rintro ⟨h₁, h₂, ⟨⟨hh₁, hfx⟩, hh₂⟩, rfl⟩; exact ⟨⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, hfx⟩ lemma restrict_prodClass_inr {α₁ α₂ β : Type*} [Fintype α₁] [Fintype α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] (V₁ : Finset (α₁ → β)) (V₂ : Finset (α₂ → β)) (x : α₂) (y : β) : restrict (prodClass V₁ V₂) (Sum.inr x) y = prodClass V₁ (restrict V₂ x y) := by ext f; simp only [restrict, prodClass, Finset.mem_filter, Finset.mem_image, Finset.mem_product, Prod.exists] constructor · rintro ⟨⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, hfx⟩; exact ⟨h₁, h₂, ⟨hh₁, ⟨hh₂, hfx⟩⟩, rfl⟩ · rintro ⟨h₁, h₂, ⟨hh₁, ⟨hh₂, hfx⟩⟩, rfl⟩; exact ⟨⟨h₁, h₂, ⟨hh₁, hh₂⟩, rfl⟩, hfx⟩ /-- **Exact Oblivious Product Multiplicativity (`Π_T(V₁ × V₂) = max_{t₁ + t₂ = T} Π_{t₁}(V₁) * Π_{t₂}(V₂)`)**. -/ theorem obliviousGrowth_prod_eq_max {α₁ α₂ β : Type*} [Fintype α₁] [Nonempty α₁] [Fintype α₂] [Nonempty α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] (V₁ : Finset (α₁ → β)) (V₂ : Finset (α₂ → β)) (T : ℕ) : obliviousGrowth T (prodClass V₁ V₂) = (Finset.range (T + 1)).sup' ⟨0, Finset.mem_range.mpr (Nat.succ_pos T)⟩ fun t₁ => obliviousGrowth t₁ V₁ * obliviousGrowth (T - t₁) V₂ := by apply le_antisymm · simp only [obliviousGrowth] refine Finset.sup'_le Finset.univ_nonempty _ fun xs _ => ?_ let I₁ : Finset (Fin T) := Finset.univ.filter fun i => (xs i).isLeft let I₂ : Finset (Fin T) := Finset.univ.filter fun i => (xs i).isRight have hcard_sum : I₁.card + I₂.card = T := by have hdisj : Disjoint I₁ I₂ := by rw [Finset.disjoint_left]; intro i hi1 hi2 simp only [I₁, I₂, Finset.mem_filter, Finset.mem_univ, true_and] at hi1 hi2 cases h : xs i <;> simp [h] at hi1 hi2 have hun : I₁ ∪ I₂ = Finset.univ := by ext i; simp only [I₁, I₂, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] cases xs i <;> simp have hc := Finset.card_union_of_disjoint hdisj rw [hun, Finset.card_univ, Fintype.card_fin] at hc; omega let t₁ := I₁.card have ht₁_le : t₁ ≤ T := by omega have ht₂_eq : I₂.card = T - t₁ := by omega -- Embed Fin t₁ ≃ I₁ and Fin (T - t₁) ≃ I₂ to build xs₁ and xs₂! let e₁ : Fin t₁ ≃ I₁ := (Fintype.equivFinOfCardEq (Fintype.card_coe I₁)).symm let e₂ : Fin (T - t₁) ≃ I₂ := (Fintype.equivFinOfCardEq (by rw [Fintype.card_coe, ht₂_eq])).symm let xs₁ : Fin t₁ → α₁ := fun j => match h : xs (e₁ j).1 with | Sum.inl x => x | Sum.inr _ => Classical.arbitrary α₁ let xs₂ : Fin (T - t₁) → α₂ := fun j => match h : xs (e₂ j).1 with | Sum.inl _ => Classical.arbitrary α₂ | Sum.inr x => x have hxs₁_eq : ∀ j : Fin t₁, xs (e₁ j).1 = Sum.inl (xs₁ j) := fun j => by have hmem := (Finset.mem_filter.mp (e₁ j).2).2 dsimp only [xs₁] cases h : xs (e₁ j).1 with | inl x => rfl | inr x => rw [h] at hmem; simp at hmem have hxs₂_eq : ∀ j : Fin (T - t₁), xs (e₂ j).1 = Sum.inr (xs₂ j) := fun j => by have hmem := (Finset.mem_filter.mp (e₂ j).2).2 dsimp only [xs₂] cases h : xs (e₂ j).1 with | inl x => rw [h] at hmem; simp at hmem | inr x => rfl -- Map each pattern p ∈ img(prodClass V₁ V₂, xs) injectively into img(V₁, xs₁) × img(V₂, xs₂)! have hle_prod : ((prodClass V₁ V₂).image fun h => fun i : Fin T => h (xs i)).card ≤ ((V₁.image fun h₁ => fun j : Fin t₁ => h₁ (xs₁ j)) ×ˢ (V₂.image fun h₂ => fun j : Fin (T - t₁) => h₂ (xs₂ j))).card := by refine Finset.card_le_card_of_injOn (fun p => (fun j : Fin t₁ => p (e₁ j).1, fun j : Fin (T - t₁) => p (e₂ j).1)) ?_ ?_ · intro p hp rcases Finset.mem_image.mp hp with ⟨f, hf, rfl⟩ rcases Finset.mem_image.mp hf with ⟨⟨h₁, h₂⟩, hpq, rfl⟩ rcases Finset.mem_product.mp hpq with ⟨hh₁, hh₂⟩ refine Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨h₁, hh₁, ?_⟩, Finset.mem_image.mpr ⟨h₂, hh₂, ?_⟩⟩ · funext j; dsimp only; rw [hxs₁_eq j]; rfl · funext j; dsimp only; rw [hxs₂_eq j]; rfl · intro p₁ _ p₂ _ heq rcases Prod.mk.inj heq with ⟨heq1, heq2⟩ funext i cases hx : xs i with | inl a => have hi : i ∈ I₁ := Finset.mem_filter.mpr ⟨Finset.mem_univ i, by simp [hx]⟩ have h := congrFun heq1 (e₁.symm ⟨i, hi⟩) simpa using h | inr b => have hi : i ∈ I₂ := Finset.mem_filter.mpr ⟨Finset.mem_univ i, by simp [hx]⟩ have h := congrFun heq2 (e₂.symm ⟨i, hi⟩) simpa using h rw [Finset.card_product] at hle_prod have h1 := Finset.le_sup' (f := fun ys : Fin t₁ → α₁ => (V₁.image fun h => fun j => h (ys j)).card) (Finset.mem_univ xs₁) have h2 := Finset.le_sup' (f := fun ys : Fin (T - t₁) → α₂ => (V₂.image fun h => fun j => h (ys j)).card) (Finset.mem_univ xs₂) exact le_trans (le_trans hle_prod (Nat.mul_le_mul h1 h2)) (Finset.le_sup' (f := fun t => (Finset.univ.sup' Finset.univ_nonempty fun ys : Fin t → α₁ => (V₁.image fun h => fun j => h (ys j)).card) * (Finset.univ.sup' Finset.univ_nonempty fun ys : Fin (T - t) → α₂ => (V₂.image fun h => fun j => h (ys j)).card)) (Finset.mem_range.mpr (Nat.lt_succ_of_le ht₁_le))) · refine Finset.sup'_le ⟨0, Finset.mem_range.mpr (Nat.succ_pos T)⟩ _ fun t₁ ht₁ => ?_ have ht₁_le : t₁ ≤ T := Nat.lt_succ_iff.mp (Finset.mem_range.mp ht₁) rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun ys : Fin t₁ → α₁ => (V₁.image fun h => fun j => h (ys j)).card) with ⟨xs₁, _, heq1⟩ rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun ys : Fin (T - t₁) → α₂ => (V₂.image fun h => fun j => h (ys j)).card) with ⟨xs₂, _, heq2⟩ dsimp only [obliviousGrowth] rw [heq1, heq2] let xs : Fin T → α₁ ⊕ α₂ := fun i => if hi : i.val < t₁ then Sum.inl (xs₁ ⟨i.val, hi⟩) else Sum.inr (xs₂ ⟨i.val - t₁, by omega⟩) let fsup : (Fin T → α₁ ⊕ α₂) → ℕ := fun ys => ((prodClass V₁ V₂).image fun h => fun i => h (ys i)).card have hle_sup : fsup xs ≤ Finset.univ.sup' Finset.univ_nonempty fsup := Finset.le_sup' (f := fsup) (Finset.mem_univ xs) refine le_trans ?_ hle_sup dsimp only [fsup] rw [← Finset.card_product] refine Finset.card_le_card_of_injOn (fun pq i => if hi : i.val < t₁ then pq.1 ⟨i.val, hi⟩ else pq.2 ⟨i.val - t₁, by omega⟩) ?_ ?_ · intro ⟨p₁, p₂⟩ hpq rcases Finset.mem_product.mp hpq with ⟨hp₁, hp₂⟩ rcases Finset.mem_image.mp hp₁ with ⟨h₁, hh₁, rfl⟩ rcases Finset.mem_image.mp hp₂ with ⟨h₂, hh₂, rfl⟩ refine Finset.mem_image.mpr ⟨Sum.elim h₁ h₂, Finset.mem_image.mpr ⟨(h₁, h₂), Finset.mem_product.mpr ⟨hh₁, hh₂⟩, rfl⟩, ?_⟩ funext i; dsimp only [xs]; split_ifs <;> rfl · intro ⟨p₁, p₂⟩ _ ⟨q₁, q₂⟩ _ heq ext j · have h := congrFun heq ⟨j.val, by omega⟩ simp only [j.isLt, ↓reduceDIte] at h; exact h · have h := congrFun heq ⟨t₁ + j.val, by omega⟩ have hnot : ¬ (t₁ + j.val < t₁) := by omega simp only [hnot, ↓reduceDIte, Nat.add_sub_cancel_left] at h; exact h /-- **Adaptive Product Super-Multiplicativity Inequality (`∀ t₁ ≤ T, S_{t₁}(V₁) * S_{T-t₁}(V₂) ≤ S_T(V₁ × V₂)`)**. -/ theorem adaptGrowth_prod_ge_mul {α₁ α₂ β : Type*} [Fintype α₁] [Nonempty α₁] [Fintype α₂] [Nonempty α₂] [DecidableEq α₁] [DecidableEq α₂] [DecidableEq β] : ∀ (t₁ t₂ : ℕ) {V₁ : Finset (α₁ → β)} {V₂ : Finset (α₂ → β)}, V₁.Nonempty → V₂.Nonempty → adaptGrowth t₁ V₁ * adaptGrowth t₂ V₂ ≤ adaptGrowth (t₁ + t₂) (prodClass V₁ V₂) | 0, 0, V₁, V₂, hV₁, hV₂ => by have hne : (prodClass V₁ V₂).Nonempty := by rcases hV₁ with ⟨h₁, hh₁⟩; rcases hV₂ with ⟨h₂, hh₂⟩ exact ⟨Sum.elim h₁ h₂, Finset.mem_image.mpr ⟨(h₁, h₂), Finset.mem_product.mpr ⟨hh₁, hh₂⟩, rfl⟩⟩ simp [adaptGrowth, hV₁, hV₂, hne] | 0, t₂ + 1, V₁, V₂, hV₁, hV₂ => by rw [zero_add] simp only [adaptGrowth, hV₁, ↓reduceIte, one_mul] refine Finset.sup'_le Finset.univ_nonempty _ fun x₂ _ => ?_ refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (prodClass V₁ V₂) x, adaptGrowth t₂ (restrict (prodClass V₁ V₂) x y)) (Finset.mem_univ (Sum.inr x₂))) rw [labels_prodClass_inr hV₁] refine Finset.sum_le_sum fun y hy => ?_ rw [restrict_prodClass_inr] have h := adaptGrowth_prod_ge_mul 0 t₂ hV₁ ((restrict_nonempty_iff V₂ x₂ y).mpr hy) simpa [adaptGrowth, hV₁] using h | t₁ + 1, t₂, V₁, V₂, hV₁, hV₂ => by rw [Nat.succ_add] simp only [adaptGrowth] rcases Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun x₁ => ∑ y ∈ labels V₁ x₁, adaptGrowth t₁ (restrict V₁ x₁ y)) with ⟨x₁, _, heq⟩ rw [heq, Finset.sum_mul] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (prodClass V₁ V₂) x, adaptGrowth (t₁ + t₂) (restrict (prodClass V₁ V₂) x y)) (Finset.mem_univ (Sum.inl x₁))) rw [labels_prodClass_inl hV₂] refine Finset.sum_le_sum fun y hy => ?_ rw [restrict_prodClass_inl] exact adaptGrowth_prod_ge_mul t₁ t₂ ((restrict_nonempty_iff V₁ x₁ y).mpr hy) hV₂ /-- 2-point binary singletons `{00, 10, 01}` on `Fin 2`. -/ def sing2Class : Finset (Fin 2 → Bool) := {fun _ => false, fun i => decide (i = 0), fun i => decide (i = 1)} /-- **STRICT DISJOINT-PRODUCT SUPER-MULTIPLICATIVITY OF CONTEXTUAL SHTARKOV SUMS (`13 > 12`)**: Contrasting sharply with oblivious exact multiplicativity `obliviousGrowth_prod_eq_max`, on `V₁ = threshClass 4` (5 concepts on `Fin 4`) and `V₂ = sing2Class` (3 concepts on `Fin 2`) at horizon `T = 4`: `adaptGrowth 4 (prodClass (threshClass 4) sing2Class) ≥ 13 > 12 ≥ max_{t₁ ≤ 4} adaptGrowth t₁ (threshClass 4) * adaptGrowth (4 - t₁) sing2Class`! (Adaptive cross-domain budget reallocation strictly beats EVERY static product split!) -/ theorem adaptGrowth_prod_strict_supermultiplicative : (∀ t₁ ≤ 4, adaptGrowth t₁ (threshClass 4) * adaptGrowth (4 - t₁) sing2Class ≤ 12) ∧ 13 ≤ adaptGrowth 4 (prodClass (threshClass 4) sing2Class) := by have hT4_card : (threshClass 4).card = 5 := threshClass_card 4 have hS2_card : sing2Class.card = 3 := by decide have hT4_le5 : ∀ t, adaptGrowth t (threshClass 4) ≤ 5 := fun t => by simpa [hT4_card] using adaptGrowth_le_card t (threshClass 4) have hS2_le3 : ∀ t, adaptGrowth t sing2Class ≤ 3 := fun t => by simpa [hS2_card] using adaptGrowth_le_card t sing2Class have hbin : ∀ (t : ℕ) {α : Type} [Fintype α] [Nonempty α] (V : Finset (α → Bool)), adaptGrowth t V ≤ 2 ^ t := by intro t α _ _ V have h := adaptGrowth_le_sauerPoly t V rw [Fintype.card_bool] at h have hs : ∀ d, sauerPoly 2 t d ≤ 2 ^ t := fun d => by dsimp only [sauerPoly]; simp only [Nat.reduceSub, one_pow, mul_one] calc ∑ i ∈ Finset.range (d + 1), t.choose i ≤ ∑ i ∈ Finset.range (max d t + 1), t.choose i := Finset.sum_le_sum_of_subset (Finset.range_mono (Nat.succ_le_succ (le_max_left d t))) _ = ∑ i ∈ Finset.range (t + 1), t.choose i := by refine (Finset.sum_subset (Finset.range_mono (Nat.succ_le_succ (le_max_right d t))) fun i _ hi => ?_).symm exact Nat.choose_eq_zero_of_lt (by simp only [Finset.mem_range] at hi; omega) _ = 2 ^ t := Nat.sum_range_choose t exact le_trans h (hs _) constructor · intro t₁ ht₁ -- Check t₁ ∈ {0, 1, 2, 3, 4}: -- t₁ = 0: ≤ 1 * 3 = 3; t₁ = 1: ≤ 2 * 3 = 6; t₁ = 2: ≤ 4 * 3 = 12; t₁ = 3: ≤ 5 * 2 = 10; t₁ = 4: ≤ 5 * 1 = 5! have ha := hbin t₁ (threshClass 4) have hb := hbin (4 - t₁) sing2Class have ha5 := hT4_le5 t₁ have hb3 := hS2_le3 (4 - t₁) interval_cases t₁ <;> norm_num at ha hb ha5 hb3 ⊢ <;> nlinarith · have hT4_ne : (threshClass 4).Nonempty := Finset.card_pos.mp (by omega) have hT4_3 : 5 ≤ adaptGrowth 3 (threshClass 4) := by have hsub_t : threshInterval 4 0 2 ⊆ restrict (threshClass 4) 1 true := by intro f hf; rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩ rw [Finset.mem_Ico] at hk exact Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨k, Finset.mem_range.mpr (by omega), rfl⟩, by simp; omega⟩ have hsub_f : threshInterval 4 2 5 ⊆ restrict (threshClass 4) 1 false := by intro f hf; rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩ rw [Finset.mem_Ico] at hk exact Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨k, Finset.mem_range.mpr (by omega), rfl⟩, by simp; omega⟩ have h1 : 2 ≤ adaptGrowth 2 (threshInterval 4 0 2) := by simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (threshInterval 4 0 2) x, adaptGrowth 1 (restrict (threshInterval 4 0 2) x y)) (Finset.mem_univ (0 : Fin 4))) have ht : true ∈ labels (threshInterval 4 0 2) 0 := Finset.mem_image.mpr ⟨fun i => decide (0 ≤ i.val), Finset.mem_image.mpr ⟨0, by simp, rfl⟩, by simp⟩ have hf : false ∈ labels (threshInterval 4 0 2) 0 := Finset.mem_image.mpr ⟨fun i => decide (1 ≤ i.val), Finset.mem_image.mpr ⟨1, by simp, rfl⟩, by simp⟩ have hp : ({false, true} : Finset Bool) ⊆ labels (threshInterval 4 0 2) 0 := by intro y hy; simp only [Finset.mem_insert, Finset.mem_singleton] at hy; rcases hy with rfl | rfl; exact hf; exact ht calc 2 = 1 + 1 := rfl _ ≤ adaptGrowth 1 (restrict (threshInterval 4 0 2) 0 false) + adaptGrowth 1 (restrict (threshInterval 4 0 2) 0 true) := Nat.add_le_add (adaptGrowth_pos 1 ((restrict_nonempty_iff _ _ _).mpr hf)) (adaptGrowth_pos 1 ((restrict_nonempty_iff _ _ _).mpr ht)) _ = ∑ y ∈ ({false, true} : Finset Bool), adaptGrowth 1 (restrict (threshInterval 4 0 2) 0 y) := by rw [Finset.sum_pair (by decide : (false : Bool) ≠ true)] _ ≤ _ := Finset.sum_le_sum_of_subset hp have h2 : 3 ≤ adaptGrowth 2 (threshInterval 4 2 5) := by simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (threshInterval 4 2 5) x, adaptGrowth 1 (restrict (threshInterval 4 2 5) x y)) (Finset.mem_univ (2 : Fin 4))) have hsub35 : threshInterval 4 3 5 ⊆ restrict (threshInterval 4 2 5) 2 false := by intro f hf; rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩; rw [Finset.mem_Ico] at hk exact Finset.mem_filter.mpr ⟨Finset.mem_image.mpr ⟨k, Finset.mem_Ico.mpr ⟨by omega, hk.2⟩, rfl⟩, by simp; omega⟩ have ht : true ∈ labels (threshInterval 4 2 5) 2 := Finset.mem_image.mpr ⟨fun i => decide (2 ≤ i.val), Finset.mem_image.mpr ⟨2, by simp, rfl⟩, by simp⟩ have hf : false ∈ labels (threshInterval 4 2 5) 2 := Finset.mem_image.mpr ⟨fun i => decide (3 ≤ i.val), Finset.mem_image.mpr ⟨3, by simp, rfl⟩, by simp⟩ have hp : ({false, true} : Finset Bool) ⊆ labels (threshInterval 4 2 5) 2 := by intro y hy; simp only [Finset.mem_insert, Finset.mem_singleton] at hy; rcases hy with rfl | rfl; exact hf; exact ht have h35 : 2 ≤ adaptGrowth 1 (threshInterval 4 3 5) := adaptGrowth_threshInterval_pow2 4 1 3 5 (by omega) (by norm_num) calc 3 = 2 + 1 := rfl _ ≤ adaptGrowth 1 (restrict (threshInterval 4 2 5) 2 false) + adaptGrowth 1 (restrict (threshInterval 4 2 5) 2 true) := Nat.add_le_add (le_trans h35 (adaptGrowth_mono 1 hsub35)) (adaptGrowth_pos 1 ((restrict_nonempty_iff _ _ _).mpr ht)) _ = ∑ y ∈ ({false, true} : Finset Bool), adaptGrowth 1 (restrict (threshInterval 4 2 5) 2 y) := by rw [Finset.sum_pair (by decide : (false : Bool) ≠ true)] _ ≤ _ := Finset.sum_le_sum_of_subset hp have ht1 : true ∈ labels (threshClass 4) 1 := Finset.mem_image.mpr ⟨fun i => decide (0 ≤ i.val), Finset.mem_image.mpr ⟨0, by simp, rfl⟩, by simp⟩ have hf1 : false ∈ labels (threshClass 4) 1 := Finset.mem_image.mpr ⟨fun i => decide (2 ≤ i.val), Finset.mem_image.mpr ⟨2, by simp, rfl⟩, by simp⟩ have hp1 : ({false, true} : Finset Bool) ⊆ labels (threshClass 4) 1 := by intro y hy; simp only [Finset.mem_insert, Finset.mem_singleton] at hy; rcases hy with rfl | rfl; exact hf1; exact ht1 simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (threshClass 4) x, adaptGrowth 2 (restrict (threshClass 4) x y)) (Finset.mem_univ (1 : Fin 4))) calc 5 = 3 + 2 := rfl _ ≤ adaptGrowth 2 (restrict (threshClass 4) 1 false) + adaptGrowth 2 (restrict (threshClass 4) 1 true) := Nat.add_le_add (le_trans h2 (adaptGrowth_mono 2 hsub_f)) (le_trans h1 (adaptGrowth_mono 2 hsub_t)) _ = ∑ y ∈ ({false, true} : Finset Bool), adaptGrowth 2 (restrict (threshClass 4) 1 y) := by rw [Finset.sum_pair (by decide : (false : Bool) ≠ true)] _ ≤ _ := Finset.sum_le_sum_of_subset hp1 have hT4_2 : 4 ≤ adaptGrowth 2 (threshClass 4) := by have hsub : threshInterval 4 0 4 ⊆ threshClass 4 := by intro f hf; rcases Finset.mem_image.mp hf with ⟨k, hk, rfl⟩ exact Finset.mem_image.mpr ⟨k, Finset.mem_range.mpr (by rw [Finset.mem_Ico] at hk; omega), rfl⟩ exact le_trans (adaptGrowth_threshInterval_pow2 4 2 0 4 (by omega) (by norm_num)) (adaptGrowth_mono 2 hsub) -- Step 1 on prodClass: query Sum.inr 0! have hbr_true : 5 ≤ adaptGrowth 3 (prodClass (threshClass 4) (restrict sing2Class 0 true)) := by have hne : (restrict sing2Class 0 true).Nonempty := by decide have h := adaptGrowth_prod_ge_mul 3 0 hT4_ne hne have h0 : adaptGrowth 0 (restrict sing2Class 0 true) = 1 := by simp [adaptGrowth, hne] rw [add_zero, h0, mul_one] at h omega have hbr_false : 8 ≤ adaptGrowth 3 (prodClass (threshClass 4) (restrict sing2Class 0 false)) := by have hne_ff : (restrict (restrict sing2Class 0 false) 1 false).Nonempty := by decide have hne_ft : (restrict (restrict sing2Class 0 false) 1 true).Nonempty := by decide have hff := adaptGrowth_prod_ge_mul 2 0 hT4_ne hne_ff have hft := adaptGrowth_prod_ge_mul 2 0 hT4_ne hne_ft have h0_ff : adaptGrowth 0 (restrict (restrict sing2Class 0 false) 1 false) = 1 := by simp [adaptGrowth, hne_ff] have h0_ft : adaptGrowth 0 (restrict (restrict sing2Class 0 false) 1 true) = 1 := by simp [adaptGrowth, hne_ft] rw [add_zero, h0_ff, mul_one] at hff rw [add_zero, h0_ft, mul_one] at hft conv_rhs => simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (prodClass (threshClass 4) (restrict sing2Class 0 false)) x, adaptGrowth 2 (restrict (prodClass (threshClass 4) (restrict sing2Class 0 false)) x y)) (Finset.mem_univ (Sum.inr 1))) rw [labels_prodClass_inr hT4_ne] have hlab1 : labels (restrict sing2Class 0 false) 1 = {false, true} := by decide rw [hlab1, Finset.sum_pair (by decide : (false : Bool) ≠ true), restrict_prodClass_inr, restrict_prodClass_inr] omega conv_rhs => simp only [adaptGrowth] refine le_trans ?_ (Finset.le_sup' (f := fun x => ∑ y ∈ labels (prodClass (threshClass 4) sing2Class) x, adaptGrowth 3 (restrict (prodClass (threshClass 4) sing2Class) x y)) (Finset.mem_univ (Sum.inr 0))) rw [labels_prodClass_inr hT4_ne] have hlab0 : labels sing2Class 0 = {false, true} := by decide rw [hlab0, Finset.sum_pair (by decide : (false : Bool) ≠ true), restrict_prodClass_inr, restrict_prodClass_inr] omega /-! ## Part 5: Bounded-Memory (Width-`M` Branching Program) Multi-Pass Sequential Log-Loss — ## Exact Information-Theoretic Lower Bound & Sharp Memory Phase Transition -/ /-- A single-pass width-`M` streaming / branching-program online forecaster on domain `Fin d`: at step `j : Fin d` and memory state `q : Fin M`, outputs a probability forecast `pred j q ∈ Δ(β)` and transitions to `trans j q y : Fin M` upon observing label `y : β`. -/ structure PassLearner (β : Type*) [Fintype β] (d M : ℕ) where pred : Fin d → Fin M → β → ℝ nonneg : ∀ j q y, 0 ≤ pred j q y sum_one : ∀ j q, ∑ y : β, pred j q y = 1 trans : Fin d → Fin M → β → Fin M /-- State of a `PassLearner` after processing the first `k ≤ d` coordinates of `h`. -/ def runStateAux {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) : ∀ (k : ℕ), k ≤ d → Fin M → (Fin d → β) → Fin M | 0, _, q₀, _ => q₀ | k + 1, hk, q₀, h => L.trans ⟨k, by omega⟩ (runStateAux L k (by omega) q₀ h) (h ⟨k, by omega⟩) /-- Memory state at the start of coordinate `j : Fin d` during a pass. -/ def runState {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (j : Fin d) (q₀ : Fin M) (h : Fin d → β) : Fin M := runStateAux L j.val (le_of_lt j.isLt) q₀ h /-- Final memory state at the end of a pass on concept `h`. -/ def endState {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (h : Fin d → β) : Fin M := runStateAux L d le_rfl q₀ h /-- Path probability assigned by `L` to concept `h` starting from state `q₀`. -/ noncomputable def passProb {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (h : Fin d → β) : ℝ := ∏ j : Fin d, L.pred j (runState L j q₀ h) (h j) /-- Cumulative log-loss incurred by `L` on concept `h` during a pass starting from `q₀`. -/ noncomputable def passLogLoss {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (h : Fin d → β) : ℝ := ∑ j : Fin d, -Real.log (L.pred j (runState L j q₀ h) (h j)) /-- Prefix of a `(d + 1)`-step pass learner on the first `d` coordinates. -/ def prefixPassLearner {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β (d + 1) M) : PassLearner β d M where pred j := L.pred j.castSucc nonneg j := L.nonneg j.castSucc sum_one j := L.sum_one j.castSucc trans j := L.trans j.castSucc lemma runStateAux_prefix {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β (d + 1) M) (q₀ : Fin M) (h₀ : Fin d → β) (y : β) : ∀ (k : ℕ) (hk : k ≤ d), runStateAux L k (by omega) q₀ (Fin.snoc (α := fun _ => β) h₀ y) = runStateAux (prefixPassLearner L) k hk q₀ h₀ | 0, _ => rfl | k + 1, hk => by change L.trans ⟨k, by omega⟩ (runStateAux L k (by omega) q₀ (Fin.snoc (α := fun _ => β) h₀ y)) (Fin.snoc (α := fun _ => β) h₀ y ⟨k, by omega⟩) = L.trans ⟨k, by omega⟩ (runStateAux (prefixPassLearner L) k (by omega) q₀ h₀) (h₀ ⟨k, by omega⟩) rw [runStateAux_prefix L q₀ h₀ y k (by omega)] have hsnoc : Fin.snoc (α := fun _ => β) h₀ y (⟨k, by omega⟩ : Fin d).castSucc = h₀ ⟨k, by omega⟩ := Fin.snoc_castSucc (α := fun _ => β) y h₀ ⟨k, by omega⟩ exact congrArg (L.trans ⟨k, by omega⟩ _) hsnoc /-- **Exact Kraft Equality (`∑_h passProb L q₀ h = 1`)** for EVERY width-`M` single-pass learner and EVERY starting state `q₀ : Fin M`! -/ theorem widthM_passProb_sum_eq_one {β : Type*} [Fintype β] {M : ℕ} : ∀ {d : ℕ} (L : PassLearner β d M) (q₀ : Fin M), ∑ h : (Fin d → β), passProb L q₀ h = 1 | 0, L, q₀ => by simp only [passProb, Finset.univ_eq_empty, Finset.prod_empty, Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_fin, pow_zero, one_smul] | d + 1, L, q₀ => by let e : (Fin d → β) × β ≃ (Fin (d + 1) → β) := { toFun := fun py => Fin.snoc (α := fun _ => β) py.1 py.2 invFun := fun h => (fun i => h i.castSucc, h (Fin.last d)) left_inv := fun ⟨h₀, y⟩ => by ext i · exact Fin.snoc_castSucc (α := fun _ => β) y h₀ i · exact Fin.snoc_last (α := fun _ => β) y h₀ right_inv := fun h => by funext j refine Fin.lastCases ?_ (fun i => ?_) j · exact Fin.snoc_last (α := fun _ => β) _ _ · exact Fin.snoc_castSucc (α := fun _ => β) _ _ i } rw [← Equiv.sum_comp e, Fintype.sum_prod_type] have hterm : ∀ (h₀ : Fin d → β) (y : β), passProb L q₀ (Fin.snoc (α := fun _ => β) h₀ y) = passProb (prefixPassLearner L) q₀ h₀ * L.pred (Fin.last d) (endState (prefixPassLearner L) q₀ h₀) y := by intro h₀ y dsimp only [passProb] rw [Fin.prod_univ_castSucc] congr 1 · refine Finset.prod_congr rfl fun i _ => ?_ have hst : runState L i.castSucc q₀ (Fin.snoc (α := fun _ => β) h₀ y) = runState (prefixPassLearner L) i q₀ h₀ := runStateAux_prefix L q₀ h₀ y i.val (le_of_lt i.isLt) rw [hst, Fin.snoc_castSucc (α := fun _ => β) y h₀ i]; rfl · dsimp only [runState, endState] rw [Fin.snoc_last (α := fun _ => β) y h₀] have hst := runStateAux_prefix L q₀ h₀ y d le_rfl exact congrArg (fun q => L.pred (Fin.last d) q y) hst have hsum_y : ∀ h₀ : Fin d → β, (∑ y : β, passProb L q₀ (e (h₀, y))) = passProb (prefixPassLearner L) q₀ h₀ := by intro h₀ have h1 : ∀ y : β, passProb L q₀ (e (h₀, y)) = passProb (prefixPassLearner L) q₀ h₀ * L.pred (Fin.last d) (endState (prefixPassLearner L) q₀ h₀) y := fun y => hterm h₀ y rw [Finset.sum_congr rfl fun y _ => h1 y, ← Finset.mul_sum, L.sum_one, mul_one] rw [Finset.sum_congr rfl fun h₀ _ => hsum_y h₀] exact widthM_passProb_sum_eq_one (prefixPassLearner L) q₀ lemma widthM_passProb_nonneg {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (h : Fin d → β) : 0 ≤ passProb L q₀ h := Finset.prod_nonneg fun j _ => L.nonneg j (runState L j q₀ h) (h j) lemma widthM_passProb_sum_subset_le_one {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (F : Finset (Fin d → β)) : ∑ h ∈ F, passProb L q₀ h ≤ 1 := by rw [← widthM_passProb_sum_eq_one L q₀] exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ F) fun h _ _ => widthM_passProb_nonneg L q₀ h lemma passLogLoss_eq_neg_log_passProb {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (h : Fin d → β) (hpos : ∀ j : Fin d, 0 < L.pred j (runState L j q₀ h) (h j)) : passLogLoss L q₀ h = -Real.log (passProb L q₀ h) := by dsimp only [passLogLoss, passProb] rw [Real.log_prod fun j _ => ne_of_gt (hpos j), Finset.sum_neg_distrib] /-- **Single-Pass Information-Theoretic Lower Bound (`|F| * log |F| ≤ ∑_{h ∈ F} passLogLoss`)**: from ANY starting memory state `q₀`, the average log-loss over ANY subset `F` is `≥ log |F|`! -/ theorem widthM_single_pass_logLoss_sum_ge {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β d M) (q₀ : Fin M) (F : Finset (Fin d → β)) (hpos : ∀ h ∈ F, ∀ j : Fin d, 0 < L.pred j (runState L j q₀ h) (h j)) : (F.card : ℝ) * Real.log (F.card : ℝ) ≤ ∑ h ∈ F, passLogLoss L q₀ h := by by_cases hF : F.Nonempty · have hcard_pos : (0 : ℝ) < (F.card : ℝ) := Nat.cast_pos.mpr hF.card_pos have hterm : ∀ h ∈ F, Real.log (F.card : ℝ) - passLogLoss L q₀ h ≤ (F.card : ℝ) * passProb L q₀ h - 1 := by intro h hh have hp_pos : 0 < passProb L q₀ h := Finset.prod_pos fun j _ => hpos h hh j have hlog := Real.log_le_sub_one_of_pos (mul_pos hcard_pos hp_pos) rw [Real.log_mul (ne_of_gt hcard_pos) (ne_of_gt hp_pos)] at hlog rw [passLogLoss_eq_neg_log_passProb L q₀ h (hpos h hh)] linarith have hsum := Finset.sum_le_sum hterm rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, Finset.sum_const, nsmul_eq_mul, mul_one, ← Finset.mul_sum] at hsum have hkraft := widthM_passProb_sum_subset_le_one L q₀ F have hmul : (F.card : ℝ) * ∑ h ∈ F, passProb L q₀ h ≤ (F.card : ℝ) := by have := mul_le_mul_of_nonneg_left hkraft (le_of_lt hcard_pos); linarith linarith · rw [Finset.not_nonempty_iff_eq_empty.mp hF]; simp /-- **Fiber Entropy Inequality (`∑_q |F_q| log |F_q| ≥ |V| (log |V| - log M)`)**: partitioning `V` into `M` memory states loses at most `log M` nats of entropy! -/ theorem fiber_log_card_sum_ge {γ : Type*} {M : ℕ} (hM : 0 < M) (V : Finset γ) (φ : γ → Fin M) : (V.card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ)) ≤ ∑ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * Real.log (((V.filter fun h => φ h = q).card : ℝ)) := by by_cases hV : V.Nonempty · have hV_pos : (0 : ℝ) < (V.card : ℝ) := Nat.cast_pos.mpr hV.card_pos have hM_pos : (0 : ℝ) < (M : ℝ) := Nat.cast_pos.mpr hM have hpart : ∑ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) = (V.card : ℝ) := by exact_mod_cast (Finset.card_eq_sum_card_fiberwise (f := φ) (s := V) (t := Finset.univ) (fun _ _ => Finset.mem_univ _)).symm have hterm : ∀ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ) - Real.log (((V.filter fun h => φ h = q).card : ℝ))) ≤ (V.card : ℝ) / (M : ℝ) - ((V.filter fun h => φ h = q).card : ℝ) := by intro q set c : ℝ := ((V.filter fun h => φ h = q).card : ℝ) by_cases hc0 : c = 0 · rw [hc0, zero_mul, sub_zero]; positivity · have hc_pos : 0 < c := lt_of_le_of_ne (Nat.cast_nonneg _) (Ne.symm hc0) have hlog := Real.log_le_sub_one_of_pos (div_pos hV_pos (mul_pos hM_pos hc_pos)) rw [Real.log_div (ne_of_gt hV_pos) (ne_of_gt (mul_pos hM_pos hc_pos)), Real.log_mul (ne_of_gt hM_pos) (ne_of_gt hc_pos)] at hlog have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt hc_pos) have hsimp : c * ((V.card : ℝ) / ((M : ℝ) * c) - 1) = (V.card : ℝ) / (M : ℝ) - c := by field_simp [ne_of_gt hc_pos, ne_of_gt hM_pos] rw [hsimp] at hmul; linarith have hsum := Finset.sum_le_sum fun q (_ : q ∈ Finset.univ) => hterm q have hlhs : ∑ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ) - Real.log (((V.filter fun h => φ h = q).card : ℝ))) = (V.card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ)) - ∑ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * Real.log (((V.filter fun h => φ h = q).card : ℝ)) := by have h1 : ∀ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ) - Real.log (((V.filter fun h => φ h = q).card : ℝ))) = ((V.filter fun h => φ h = q).card : ℝ) * (Real.log (V.card : ℝ) - Real.log (M : ℝ)) - ((V.filter fun h => φ h = q).card : ℝ) * Real.log (((V.filter fun h => φ h = q).card : ℝ)) := fun _ => by ring rw [Finset.sum_congr rfl fun q _ => h1 q, Finset.sum_sub_distrib, ← Finset.sum_mul, hpart] have hrhs : ∑ q : Fin M, ((V.card : ℝ) / (M : ℝ) - ((V.filter fun h => φ h = q).card : ℝ)) = 0 := by rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_div_cancel₀ _ (ne_of_gt hM_pos), hpart, sub_self] linarith · rw [Finset.not_nonempty_iff_eq_empty.mp hV]; simp /-- A multi-pass width-`M` branching-program online learner running `R` passes over `Fin d`. -/ structure MultiPassLearner (β : Type*) [Fintype β] (d M R : ℕ) where init : Fin M pass : Fin R → PassLearner β d M /-- Starting memory state of pass `r ≤ R` on concept `h`. -/ def stateBeforePassAux {β : Type*} [Fintype β] {d M R : ℕ} (L : MultiPassLearner β d M R) : ∀ (r : ℕ), r ≤ R → (Fin d → β) → Fin M | 0, _, _ => L.init | r + 1, hr, h => endState (L.pass ⟨r, by omega⟩) (stateBeforePassAux L r (by omega) h) h def stateBeforePass {β : Type*} [Fintype β] {d M R : ℕ} (L : MultiPassLearner β d M R) (r : Fin R) (h : Fin d → β) : Fin M := stateBeforePassAux L r.val (le_of_lt r.isLt) h /-- Total cumulative log-loss across all `R` passes on concept `h`. -/ noncomputable def totalLogLoss {β : Type*} [Fintype β] {d M R : ℕ} (L : MultiPassLearner β d M R) (h : Fin d → β) : ℝ := ∑ r : Fin R, passLogLoss (L.pass r) (stateBeforePass L r h) h /-- Admissibility: positive probability assigned along the true path on every concept in `V`. -/ def MultiPassPos {β : Type*} [Fintype β] {d M R : ℕ} (L : MultiPassLearner β d M R) (V : Finset (Fin d → β)) : Prop := ∀ h ∈ V, ∀ r : Fin R, ∀ j : Fin d, 0 < (L.pass r).pred j (runState (L.pass r) j (stateBeforePass L r h) h) (h j) /-- **Per-Pass Width-`M` Log-Loss Lower Bound**: - On Pass 0 (`r = 0`), average log-loss over `V` is `≥ log |V|`. - On EVERY subsequent pass `r : Fin R`, average log-loss over `V` is `≥ max 0 (log |V| - log M)`! -/ theorem widthM_pass_avg_logLoss_ge {β : Type*} [Fintype β] {d M R : ℕ} (hM : 0 < M) (L : MultiPassLearner β d M R) {V : Finset (Fin d → β)} (hV : V.Nonempty) (hpos : MultiPassPos L V) (r : Fin R) : max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) ≤ (1 / (V.card : ℝ)) * ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h := by have hV_pos : (0 : ℝ) < (V.card : ℝ) := Nat.cast_pos.mpr hV.card_pos have hsum_nn : 0 ≤ ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h := by refine Finset.sum_nonneg fun h hh => Finset.sum_nonneg fun j _ => ?_ have hle1 : (L.pass r).pred j (runState (L.pass r) j (stateBeforePass L r h) h) (h j) ≤ 1 := by rw [← (L.pass r).sum_one j (runState (L.pass r) j (stateBeforePass L r h) h)] exact Finset.single_le_sum (fun y _ => (L.pass r).nonneg j _ y) (Finset.mem_univ (h j)) have := Real.log_nonpos (le_of_lt (hpos h hh r j)) hle1 linarith refine max_le (mul_nonneg (by positivity) hsum_nn) ?_ rw [one_div_mul_eq_div, le_div_iff₀ hV_pos, mul_comm] -- Partition V by starting state φ h = stateBeforePass L r h! let φ : (Fin d → β) → Fin M := fun h => stateBeforePass L r h have hsplit : ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h = ∑ q : Fin M, ∑ h ∈ V.filter (fun h => φ h = q), passLogLoss (L.pass r) q h := by rw [← Finset.sum_fiberwise_of_maps_to (s := V) (t := Finset.univ) (g := φ) (fun _ _ => Finset.mem_univ _)] refine Finset.sum_congr rfl fun q _ => Finset.sum_congr rfl fun h hh => ?_ have hq : φ h = q := (Finset.mem_filter.mp hh).2 dsimp only [φ] at hq; rw [hq] rw [hsplit] have hfib_le : ∀ q : Fin M, ((V.filter fun h => φ h = q).card : ℝ) * Real.log (((V.filter fun h => φ h = q).card : ℝ)) ≤ ∑ h ∈ V.filter (fun h => φ h = q), passLogLoss (L.pass r) q h := fun q => by refine widthM_single_pass_logLoss_sum_ge (L.pass r) q (V.filter fun h => φ h = q) fun h hh j => ?_ have hmem : h ∈ V := (Finset.mem_filter.mp hh).1 have hq : stateBeforePass L r h = q := (Finset.mem_filter.mp hh).2 rw [← hq]; exact hpos h hmem r j exact le_trans (fiber_log_card_sum_ge hM V φ) (Finset.sum_le_sum fun q _ => hfib_le q) /-- **UNIVERSAL WIDTH-`M` MULTI-PASS SEQUENTIAL LOG-LOSS LOWER BOUND (DETERMINISTIC)**: For EVERY finite nonempty concept class `V ⊆ (Fin d → β)`, EVERY width `M ≥ 1`, EVERY number of passes `R ≥ 1`, and EVERY admissible width-`M` branching-program learner `L`: `Real.log |V| + (R - 1) * max 0 (Real.log |V| - Real.log M) ≤ avg_h (totalLogLoss L h) ≤ max_h (totalLogLoss L h)`! -/ theorem widthM_multipass_logLoss_lower {β : Type*} [Fintype β] {d M R : ℕ} (hM : 0 < M) (hR : 1 ≤ R) (L : MultiPassLearner β d M R) {V : Finset (Fin d → β)} (hV : V.Nonempty) (hpos : MultiPassPos L V) : Real.log (V.card : ℝ) + ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) ≤ (1 / (V.card : ℝ)) * ∑ h ∈ V, totalLogLoss L h ∧ (1 / (V.card : ℝ)) * ∑ h ∈ V, totalLogLoss L h ≤ V.sup' hV (totalLogLoss L) := by have hV_pos : (0 : ℝ) < (V.card : ℝ) := Nat.cast_pos.mpr hV.card_pos constructor · have hswap : (1 / (V.card : ℝ)) * ∑ h ∈ V, totalLogLoss L h = ∑ r : Fin R, (1 / (V.card : ℝ)) * ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h := by dsimp only [totalLogLoss] rw [Finset.sum_comm, Finset.mul_sum] rw [hswap] let r0 : Fin R := ⟨0, by omega⟩ rw [← Finset.add_sum_erase _ _ (Finset.mem_univ r0)] have hp0 : Real.log (V.card : ℝ) ≤ (1 / (V.card : ℝ)) * ∑ h ∈ V, passLogLoss (L.pass r0) (stateBeforePass L r0 h) h := by rw [one_div_mul_eq_div, le_div_iff₀ hV_pos, mul_comm] have heq : ∀ h ∈ V, stateBeforePass L r0 h = L.init := fun _ _ => rfl rw [Finset.sum_congr rfl fun h hh => by rw [heq h hh]] exact widthM_single_pass_logLoss_sum_ge (L.pass r0) L.init V fun h hh j => by rw [← heq h hh]; exact hpos h hh r0 j have hrest : ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) ≤ ∑ r ∈ Finset.univ.erase r0, (1 / (V.card : ℝ)) * ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h := by calc ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) = ((Finset.univ.erase r0).card : ℝ) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) := by rw [Finset.card_erase_of_mem (Finset.mem_univ r0), Finset.card_univ, Fintype.card_fin, Nat.cast_sub hR, Nat.cast_one] _ = ∑ _r ∈ Finset.univ.erase r0, max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) := by rw [Finset.sum_const, nsmul_eq_mul] _ ≤ _ := Finset.sum_le_sum fun r _ => widthM_pass_avg_logLoss_ge hM L hV hpos r linarith · rw [one_div_mul_eq_div, div_le_iff₀ hV_pos] calc ∑ h ∈ V, totalLogLoss L h ≤ ∑ _h ∈ V, V.sup' hV (totalLogLoss L) := Finset.sum_le_sum fun h hh => Finset.le_sup' (totalLogLoss L) hh _ = V.sup' hV (totalLogLoss L) * (V.card : ℝ) := by rw [Finset.sum_const, nsmul_eq_mul, mul_comm] /-- A randomized width-`M` multi-pass learner modeled as a finite convex mixture of deterministic width-`M` branching programs (covering arbitrary randomized transitions & randomized predictions!). -/ structure RandMultiPassLearner (β : Type*) [Fintype β] (d M R : ℕ) (Ω : Type*) [Fintype Ω] where weight : Ω → ℝ weight_nonneg : ∀ ω, 0 ≤ weight ω weight_sum_one : ∑ ω : Ω, weight ω = 1 learner : Ω → MultiPassLearner β d M R /-- **UNIVERSAL WIDTH-`M` MULTI-PASS LOG-LOSS LOWER BOUND FOR RANDOMIZED BRANCHING PROGRAMS**: randomization CANNOT improve the width-`M` log-loss lower bound by even a single nat! -/ theorem randWidthM_multipass_logLoss_lower {β Ω : Type*} [Fintype β] [Fintype Ω] {d M R : ℕ} (hM : 0 < M) (hR : 1 ≤ R) (RL : RandMultiPassLearner β d M R Ω) {V : Finset (Fin d → β)} (hV : V.Nonempty) (hpos : ∀ ω : Ω, MultiPassPos (RL.learner ω) V) : Real.log (V.card : ℝ) + ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) ≤ (1 / (V.card : ℝ)) * ∑ h ∈ V, ∑ ω : Ω, RL.weight ω * totalLogLoss (RL.learner ω) h := by have hswap : (1 / (V.card : ℝ)) * ∑ h ∈ V, ∑ ω : Ω, RL.weight ω * totalLogLoss (RL.learner ω) h = ∑ ω : Ω, RL.weight ω * ((1 / (V.card : ℝ)) * ∑ h ∈ V, totalLogLoss (RL.learner ω) h) := by rw [Finset.sum_comm, Finset.mul_sum] refine Finset.sum_congr rfl fun ω _ => ?_ rw [← Finset.mul_sum]; ring rw [hswap] calc Real.log (V.card : ℝ) + ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) = (∑ ω : Ω, RL.weight ω) * (Real.log (V.card : ℝ) + ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ))) := by rw [RL.weight_sum_one, one_mul] _ = ∑ ω : Ω, RL.weight ω * (Real.log (V.card : ℝ) + ((R : ℝ) - 1) * max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ))) := Finset.sum_mul _ _ _ _ ≤ ∑ ω : Ω, RL.weight ω * ((1 / (V.card : ℝ)) * ∑ h ∈ V, totalLogLoss (RL.learner ω) h) := Finset.sum_le_sum fun ω _ => mul_le_mul_of_nonneg_left (widthM_multipass_logLoss_lower hM hR (RL.learner ω) hV (hpos ω)).1 (RL.weight_nonneg ω) /-- **Explicit Width-`r^b` Memorization Learner on `Fin d → Fin r`**: memorizes the first `b ≤ d` coordinates in base `r` during Pass 0, retains them forever in `r^b` states, predicts deterministically (`prob = 1`, loss `0`) on coordinates `< b` in passes `≥ 1`, and predicts uniform `1 / r` (loss `log r`) on coordinates `≥ b` (and all of Pass 0)! -/ noncomputable def cubeMemPass0 (r d b : ℕ) [NeZero r] : PassLearner (Fin r) d (r ^ b) where pred _ _ _ := 1 / (r : ℝ) nonneg _ _ _ := by positivity sum_one _ _ := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one_div_cancel] exact Nat.cast_ne_zero.mpr (NeZero.ne r) trans j q y := if j.val < b then ⟨(q.val * r + y.val) % (r ^ b), Nat.mod_lt _ (pow_pos (NeZero.pos r) b)⟩ else q noncomputable def cubeMemPassLater (r d b : ℕ) [NeZero r] : PassLearner (Fin r) d (r ^ b) where pred j q y := if j.val < b then if y.val = (q.val / (r ^ (b - 1 - j.val))) % r then 1 else 0 else 1 / (r : ℝ) nonneg j q y := by split_ifs <;> positivity sum_one j q := by split_ifs with hjb · have hlt : (q.val / r ^ (b - 1 - j.val)) % r < r := Nat.mod_lt _ (NeZero.pos r) let y0 : Fin r := ⟨(q.val / r ^ (b - 1 - j.val)) % r, hlt⟩ rw [Finset.sum_eq_single y0] · simp [y0] · intro y _ hy have hne : y.val ≠ (q.val / r ^ (b - 1 - j.val)) % r := fun h => hy (Fin.ext h) simp [hne] · intro h; exact absurd (Finset.mem_univ y0) h · rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one_div_cancel] exact Nat.cast_ne_zero.mpr (NeZero.ne r) trans _ q _ := q noncomputable def cubeMemLearner (r d b R : ℕ) [NeZero r] : MultiPassLearner (Fin r) d (r ^ b) R where init := ⟨0, pow_pos (NeZero.pos r) b⟩ pass p := if p.val = 0 then cubeMemPass0 r d b else cubeMemPassLater r d b /-- Base-`r` prefix encoding of the first `k` coordinates of `h : Fin d → Fin r`. -/ def baseREncode {r d : ℕ} (h : Fin d → Fin r) : ∀ k : ℕ, k ≤ d → ℕ | 0, _ => 0 | k + 1, hk => baseREncode h k (by omega) * r + (h ⟨k, by omega⟩).val lemma baseREncode_lt_pow {r d : ℕ} [NeZero r] (h : Fin d → Fin r) : ∀ (k : ℕ) (hk : k ≤ d), baseREncode h k hk < r ^ k | 0, _ => by simp [baseREncode] | k + 1, hk => by simp only [baseREncode, pow_succ] have ih := baseREncode_lt_pow h k (by omega) have hy := (h ⟨k, by omega⟩).isLt have hmul : (baseREncode h k (by omega) + 1) * r ≤ r ^ k * r := Nat.mul_le_mul_right r ih nlinarith lemma baseREncode_digit {r d : ℕ} [NeZero r] (h : Fin d → Fin r) : ∀ (k : ℕ) (hk : k ≤ d) (j : ℕ) (hj : j < k), (baseREncode h k hk / r ^ (k - 1 - j)) % r = (h ⟨j, by omega⟩).val | 0, _, _, hj => by omega | k + 1, hk, j, hj => by simp only [baseREncode] by_cases hjk : j = k · subst hjk have hsub : j + 1 - 1 - j = 0 := by omega rw [hsub, pow_zero, Nat.div_one, Nat.mul_add_mod_self_right, Nat.mod_eq_of_lt (h ⟨j, by omega⟩).isLt] · have hj_lt : j < k := by omega have hexp : k + 1 - 1 - j = (k - 1 - j) + 1 := by omega rw [hexp, pow_succ', ← Nat.div_div_eq_div_mul] have hdiv_r : (baseREncode h k (by omega) * r + (h ⟨k, by omega⟩).val) / r = baseREncode h k (by omega) := by rw [mul_comm _ r, Nat.mul_add_div (NeZero.pos r), Nat.div_eq_of_lt (h ⟨k, by omega⟩).isLt, add_zero] rw [hdiv_r] exact baseREncode_digit h k (by omega) j hj_lt private lemma baseREncode_congr {r d : ℕ} (h : Fin d → Fin r) {k₁ k₂ : ℕ} (hk₁ : k₁ ≤ d) (hk₂ : k₂ ≤ d) (heq : k₁ = k₂) : baseREncode h k₁ hk₁ = baseREncode h k₂ hk₂ := by subst heq; rfl lemma cubeMemPass0_runStateAux {r d b : ℕ} [NeZero r] (hb : b ≤ d) (h : Fin d → Fin r) : ∀ (k : ℕ) (hk : k ≤ d), (runStateAux (cubeMemPass0 r d b) k hk ⟨0, pow_pos (NeZero.pos r) b⟩ h).val = baseREncode h (min k b) (by omega) | 0, _ => by simp [runStateAux, baseREncode] | k + 1, hk => by set q := runStateAux (cubeMemPass0 r d b) k (by omega) ⟨0, pow_pos (NeZero.pos r) b⟩ h have ih : q.val = baseREncode h (min k b) (by omega) := cubeMemPass0_runStateAux hb h k (by omega) change ((cubeMemPass0 r d b).trans ⟨k, by omega⟩ q (h ⟨k, by omega⟩)).val = baseREncode h (min (k + 1) b) (by omega) dsimp only [cubeMemPass0] by_cases hkb : k < b · rw [if_pos hkb] have ih' : q.val = baseREncode h k (by omega) := ih.trans (baseREncode_congr h _ _ (Nat.min_eq_left (by omega))) simp only [ih'] have hlt_pow : baseREncode h k (by omega) * r + (h ⟨k, by omega⟩).val < r ^ b := by have hlt1 : baseREncode h (k + 1) (by omega) < r ^ (k + 1) := baseREncode_lt_pow h (k + 1) (by omega) have hpow : r ^ (k + 1) ≤ r ^ b := Nat.pow_le_pow_right (NeZero.pos r) (by omega) exact lt_of_lt_of_le hlt1 hpow rw [Nat.mod_eq_of_lt hlt_pow] exact (baseREncode_congr h (by omega) (by omega) (Nat.min_eq_left (a := k + 1) (b := b) (by omega))).symm · rw [if_neg hkb] have ih' : q.val = baseREncode h b hb := ih.trans (baseREncode_congr h _ _ (Nat.min_eq_right (by omega))) exact ih'.trans (baseREncode_congr h _ _ (Nat.min_eq_right (by omega))).symm lemma cubeMemPassLater_runStateAux {r d b : ℕ} [NeZero r] (q₀ : Fin (r ^ b)) (h : Fin d → Fin r) : ∀ (k : ℕ) (hk : k ≤ d), runStateAux (cubeMemPassLater r d b) k hk q₀ h = q₀ | 0, _ => rfl | k + 1, hk => by change runStateAux (cubeMemPassLater r d b) k (by omega) q₀ h = q₀ exact cubeMemPassLater_runStateAux q₀ h k (by omega) /-- **EXACT SHARPNESS OF WIDTH-`r^b` MULTI-PASS LOG-LOSS ON `r`-ARY CUBES**: For EVERY `r ≥ 2`, `d ≥ 0`, `b ≤ d`, and `R ≥ 1`: on `V = Finset.univ : Finset (Fin d → Fin r)` (`|V| = r^d`) with width `M = r^b`: 1. `cubeMemLearner` achieves exact uniform log-loss `d * log r + (R - 1) * (d - b) * log r` on EVERY `h`, 2. this EQUALS the universal information-theoretic lower bound `log |V| + (R - 1) * (log |V| - log M)`! -/ theorem widthM_cube_logLoss_exact_tight {r d b R : ℕ} [NeZero r] (hb : b ≤ d) (hR : 1 ≤ R) : let V : Finset (Fin d → Fin r) := Finset.univ MultiPassPos (cubeMemLearner r d b R) V ∧ (∀ h : Fin d → Fin r, totalLogLoss (cubeMemLearner r d b R) h = Real.log (V.card : ℝ) + ((R : ℝ) - 1) * (Real.log (V.card : ℝ) - Real.log ((r ^ b : ℕ) : ℝ))) := by intro V have hr_pos : (0 : ℝ) < (r : ℝ) := Nat.cast_pos.mpr (NeZero.pos r) have hstate : ∀ (p : Fin R) (h : Fin d → Fin r), p.val ≠ 0 → (stateBeforePass (cubeMemLearner r d b R) p h).val = baseREncode h b hb := by intro ⟨p, hp⟩ h hp0 dsimp only [stateBeforePass] induction p with | zero => exact absurd rfl hp0 | succ m ih => simp only [stateBeforePassAux] by_cases hm0 : m = 0 · subst hm0 simp only [cubeMemLearner, ↓reduceIte, stateBeforePassAux, endState] have h0 := cubeMemPass0_runStateAux (r := r) hb h d le_rfl have hmin : min d b = b := Nat.min_eq_right hb simpa [hmin] using h0 · have hne : (⟨m, by omega⟩ : Fin R).val ≠ 0 := hm0 simp only [cubeMemLearner, hne, ↓reduceIte, endState] rw [cubeMemPassLater_runStateAux] exact ih (by omega) hm0 have hpos : MultiPassPos (cubeMemLearner r d b R) V := by intro h _ p j by_cases hp0 : p.val = 0 · have hp_eq : (cubeMemLearner r d b R).pass p = cubeMemPass0 r d b := if_pos hp0 rw [hp_eq]; dsimp only [cubeMemPass0]; positivity · have hp_eq : (cubeMemLearner r d b R).pass p = cubeMemPassLater r d b := if_neg hp0 rw [hp_eq] have hst : runState (cubeMemPassLater r d b) j (stateBeforePass (cubeMemLearner r d b R) p h) h = stateBeforePass (cubeMemLearner r d b R) p h := cubeMemPassLater_runStateAux _ h j.val (le_of_lt j.isLt) rw [hst] dsimp only [cubeMemPassLater] by_cases hjb : j.val < b · rw [if_pos hjb] have hdig : (h j).val = ((stateBeforePass (cubeMemLearner r d b R) p h).val / r ^ (b - 1 - j.val)) % r := by rw [hstate p h hp0, baseREncode_digit h b hb j.val hjb] rw [if_pos hdig]; norm_num · rw [if_neg hjb]; positivity refine ⟨hpos, fun h => ?_⟩ have hcard : Real.log (V.card : ℝ) = (d : ℝ) * Real.log (r : ℝ) := by dsimp only [V] rw [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_fin, Nat.cast_pow, Real.log_pow] have hM : Real.log ((r ^ b : ℕ) : ℝ) = (b : ℝ) * Real.log (r : ℝ) := by rw [Nat.cast_pow, Real.log_pow] rw [hcard, hM] dsimp only [totalLogLoss] let p0 : Fin R := ⟨0, by omega⟩ rw [← Finset.add_sum_erase _ _ (Finset.mem_univ p0)] have hpass0 : passLogLoss ((cubeMemLearner r d b R).pass p0) (stateBeforePass (cubeMemLearner r d b R) p0 h) h = (d : ℝ) * Real.log (r : ℝ) := by dsimp only [passLogLoss, cubeMemLearner, p0, cubeMemPass0] simp only [↓reduceIte, one_div, Real.log_inv, neg_neg, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have hpass_later : ∀ p : Fin R, p ≠ p0 → passLogLoss ((cubeMemLearner r d b R).pass p) (stateBeforePass (cubeMemLearner r d b R) p h) h = ((d : ℝ) - (b : ℝ)) * Real.log (r : ℝ) := by intro p hpne have hp0 : p.val ≠ 0 := fun h0 => hpne (Fin.ext h0) have hp_eq : (cubeMemLearner r d b R).pass p = cubeMemPassLater r d b := if_neg hp0 dsimp only [passLogLoss] rw [hp_eq] have hterm : ∀ j : Fin d, -Real.log ((cubeMemPassLater r d b).pred j (runState (cubeMemPassLater r d b) j (stateBeforePass (cubeMemLearner r d b R) p h) h) (h j)) = if j.val < b then 0 else Real.log (r : ℝ) := by intro j dsimp only [runState] rw [cubeMemPassLater_runStateAux _ h j.val (le_of_lt j.isLt)] dsimp only [cubeMemPassLater] by_cases hjb : j.val < b · rw [if_pos hjb, if_pos hjb] have hdig : (h j).val = ((stateBeforePass (cubeMemLearner r d b R) p h).val / r ^ (b - 1 - j.val)) % r := by rw [hstate p h hp0, baseREncode_digit h b hb j.val hjb] rw [if_pos hdig, Real.log_one, neg_zero] · rw [if_neg hjb, if_neg hjb, one_div, Real.log_inv, neg_neg] rw [Finset.sum_congr rfl fun j _ => hterm j] rw [Finset.sum_ite, Finset.sum_const_zero, zero_add, Finset.sum_const, nsmul_eq_mul] have hcnt : (Finset.univ.filter fun j : Fin d => ¬ j.val < b).card = d - b := by have hcompl : (Finset.univ.filter fun j : Fin d => j.val < b).card = b := by have hbij : (Finset.univ.filter fun j : Fin d => j.val < b).card = (Finset.univ : Finset (Fin b)).card := by refine Finset.card_bij (fun j hj => ⟨j.val, (Finset.mem_filter.mp hj).2⟩) (fun _ _ => Finset.mem_univ _) (fun j₁ _ j₂ _ heq => Fin.ext (congrArg (Fin.val (n := b)) heq)) ?_ intro i _; exact ⟨⟨i.val, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, i.isLt⟩, rfl⟩ rw [hbij, Finset.card_univ, Fintype.card_fin] have htot := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin d))) (p := fun j : Fin d => j.val < b) rw [Finset.card_univ, Fintype.card_fin, hcompl] at htot; omega rw [hcnt, Nat.cast_sub hb] rw [hpass0, Finset.sum_congr rfl fun p hp => hpass_later p (Finset.ne_of_mem_erase hp), Finset.sum_const, nsmul_eq_mul, Finset.card_erase_of_mem (Finset.mem_univ p0), Finset.card_univ, Fintype.card_fin, Nat.cast_sub hR, Nat.cast_one] ring /-- **SHARP MEMORY-REGRET PHASE TRANSITION AT `M* = |V|`**: On `V = Finset.univ : Finset (Fin d → Fin r)` (`|V| = r^d`, `r ≥ 2`): - **Above threshold (`M = |V|`)**: multi-pass log-loss stays BOUNDED (`= log |V|`) uniformly for ALL `R ≥ 1`! - **Below threshold (`1 ≤ M < |V|`)**: EVERY width-`M` learner suffers log-loss growing LINEARLY in `R` with strictly positive slope `≥ log(|V| / M) > 0`! -/ theorem widthM_logLoss_memory_phase_transition {r d : ℕ} [NeZero r] : let V : Finset (Fin d → Fin r) := Finset.univ (∀ R ≥ 1, ∃ L : MultiPassLearner (Fin r) d V.card R, MultiPassPos L V ∧ ∀ h ∈ V, totalLogLoss L h = Real.log (V.card : ℝ)) ∧ (∀ M : ℕ, 0 < M → M < V.card → 0 < Real.log ((V.card : ℝ) / (M : ℝ)) ∧ ∀ (R : ℕ) (_hR : 1 ≤ R) (L : MultiPassLearner (Fin r) d M R), MultiPassPos L V → Real.log (V.card : ℝ) + ((R : ℝ) - 1) * Real.log ((V.card : ℝ) / (M : ℝ)) ≤ V.sup' Finset.univ_nonempty (totalLogLoss L)) := by intro V have hcard : V.card = r ^ d := by dsimp only [V]; rw [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_fin] constructor · intro R hR have ht := widthM_cube_logLoss_exact_tight (r := r) (d := d) (b := d) (R := R) le_rfl hR rw [hcard] refine ⟨cubeMemLearner r d d R, ht.1, fun h _ => ?_⟩ have hh := ht.2 h rw [hcard] at hh; linarith · intro M hM hlt have hM_pos : (0 : ℝ) < (M : ℝ) := Nat.cast_pos.mpr hM have hV_pos : (0 : ℝ) < (V.card : ℝ) := Nat.cast_pos.mpr (by omega) have hlt_r : (M : ℝ) < (V.card : ℝ) := by exact_mod_cast hlt have hslope_pos : 0 < Real.log ((V.card : ℝ) / (M : ℝ)) := Real.log_pos ((one_lt_div hM_pos).mpr hlt_r) refine ⟨hslope_pos, fun R hR L hpos => ?_⟩ have hlow := widthM_multipass_logLoss_lower hM hR L Finset.univ_nonempty hpos have hdiv : Real.log ((V.card : ℝ) / (M : ℝ)) = Real.log (V.card : ℝ) - Real.log (M : ℝ) := Real.log_div (ne_of_gt hV_pos) (ne_of_gt hM_pos) have hmax : max 0 (Real.log (V.card : ℝ) - Real.log (M : ℝ)) = Real.log ((V.card : ℝ) / (M : ℝ)) := by rw [← hdiv, max_eq_right (le_of_lt hslope_pos)] rw [hmax] at hlow exact le_trans hlow.1 hlow.2 /-! ## Part 6: Bounded-Memory 0–1 Rate-Distortion Lower Bound vs. Log-Loss — ## Sharp Separation via Strict Width-`M` Block-Majority Learners -/ /-- Binary Shannon entropy in nats: `h₂(p) = -p log p - (1 - p) log (1 - p)`. -/ noncomputable def binEnt (p : ℝ) : ℝ := -(if p = 0 then 0 else p * Real.log p) - (if p = 1 then 0 else (1 - p) * Real.log (1 - p)) lemma binEnt_zero : binEnt 0 = 0 := by simp [binEnt] lemma binEnt_one : binEnt 1 = 0 := by simp [binEnt] lemma binEnt_half : binEnt (1 / 2) = Real.log 2 := by dsimp only [binEnt] have h1 : (1 / 2 : ℝ) ≠ 0 := by norm_num have h2 : (1 / 2 : ℝ) ≠ 1 := by norm_num have h3 : (1 - 1 / 2 : ℝ) = 1 / 2 := by norm_num rw [if_neg h1, if_neg h2, h3, one_div, Real.log_inv]; ring lemma binEnt_symm (p : ℝ) : binEnt (1 - p) = binEnt p := by dsimp only [binEnt] have h1 : (1 - p = 0) ↔ (p = 1) := by constructor <;> intro h <;> linarith have h2 : (1 - p = 1) ↔ (p = 0) := by constructor <;> intro h <;> linarith have h3 : 1 - (1 - p) = p := by ring rw [h3] by_cases hp0 : p = 0 · subst hp0; simp · by_cases hp1 : p = 1 · subst hp1; simp · have h1' : 1 - p ≠ 0 := mt h1.mp hp1 have h2' : 1 - p ≠ 1 := mt h2.mp hp0 rw [if_neg h1', if_neg h2', if_neg hp0, if_neg hp1]; ring lemma binEnt_nonneg {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : 0 ≤ binEnt p := by dsimp only [binEnt] have h1 : (if p = 0 then 0 else p * Real.log p) ≤ 0 := by split_ifs with h · exact le_rfl · exact mul_nonpos_of_nonneg_of_nonpos hp0 (Real.log_nonpos hp0 hp1) have h2 : (if p = 1 then 0 else (1 - p) * Real.log (1 - p)) ≤ 0 := by split_ifs with h · exact le_rfl · exact mul_nonpos_of_nonneg_of_nonpos (by linarith) (Real.log_nonpos (by linarith) (by linarith)) linarith lemma binEnt_hasDerivAt {p : ℝ} (hp0 : 0 < p) (hp1 : p < 1) : HasDerivAt binEnt (Real.log (1 - p) - Real.log p) p := by have hev : binEnt =ᶠ[nhds p] fun z => -(z * Real.log z) - (1 - z) * Real.log (1 - z) := by filter_upwards [Ioo_mem_nhds hp0 hp1] with z hz dsimp only [binEnt] rw [if_neg (ne_of_gt hz.1), if_neg (ne_of_lt hz.2)] refine HasDerivAt.congr_of_eventuallyEq ?_ hev have h1 : HasDerivAt (fun z : ℝ => z * Real.log z) (1 * Real.log p + p * p⁻¹) p := (hasDerivAt_id p).mul (Real.hasDerivAt_log (ne_of_gt hp0)) have h2a : HasDerivAt (fun z : ℝ => (1 : ℝ) - z) (-1) p := HasDerivAt.const_sub 1 (hasDerivAt_id p) have h2b : HasDerivAt (fun z : ℝ => Real.log (1 - z)) ((-1) / (1 - p)) p := by simpa using h2a.log (ne_of_gt (sub_pos.mpr hp1)) have h2 : HasDerivAt (fun z : ℝ => (1 - z) * Real.log (1 - z)) ((-1) * Real.log (1 - p) + (1 - p) * ((-1) / (1 - p))) p := h2a.mul h2b refine (h1.neg.fun_sub h2).congr_deriv ?_ have hp_ne : p ≠ 0 := ne_of_gt hp0 have h1p_ne : 1 - p ≠ 0 := ne_of_gt (sub_pos.mpr hp1) field_simp; ring lemma binEnt_continuousOn : ContinuousOn binEnt (Set.Icc 0 1) := by have hc1 : Continuous (fun z : ℝ => -(z * Real.log z) - (1 - z) * Real.log (1 - z)) := ((Real.continuous_mul_log).neg).sub (Real.continuous_mul_log.comp (continuous_const.sub continuous_id)) refine hc1.continuousOn.congr fun z _ => ?_ dsimp only [binEnt] by_cases hz0 : z = 0 · subst hz0; simp · by_cases hz1 : z = 1 · subst hz1; simp · simp [hz0, hz1] /-- **Monotonicity of Binary Entropy on `[0, 1/2]`**. -/ theorem binEnt_monoOn_half : MonotoneOn binEnt (Set.Icc 0 (1 / 2)) := by refine monotoneOn_of_deriv_nonneg (convex_Icc 0 (1 / 2)) (binEnt_continuousOn.mono fun z hz => ⟨hz.1, by linarith [hz.2]⟩) (fun z hz => by rw [interior_Icc] at hz exact (binEnt_hasDerivAt hz.1 (by linarith [hz.2])).differentiableAt.differentiableWithinAt) (fun z hz => by rw [interior_Icc] at hz rw [(binEnt_hasDerivAt hz.1 (by linarith [hz.2])).deriv] have hle : z ≤ 1 - z := by linarith [hz.2] linarith [Real.log_le_log hz.1 hle]) /-- **Strict Concavity of Binary Entropy on `[0, 1]`**: gives finite-sum Jensen's inequality `∑ w_i * binEnt (p_i) ≤ binEnt (∑ w_i * p_i)`! -/ theorem binEnt_concaveOn : ConcaveOn ℝ (Set.Icc 0 1) binEnt := by refine ⟨convex_Icc 0 1, ?_⟩ intro x hx y hy a b ha hb hab simp only [smul_eq_mul] -- WLOG x ≤ y (by symmetry!) suffices hord : ∀ (u v : ℝ), u ∈ Set.Icc (0 : ℝ) 1 → v ∈ Set.Icc (0 : ℝ) 1 → u ≤ v → ∀ (c d : ℝ), 0 ≤ c → 0 ≤ d → c + d = 1 → c * binEnt u + d * binEnt v ≤ binEnt (c * u + d * v) by rcases le_total x y with hxy | hyx · exact hord x y hx hy hxy a b ha hb hab · have h := hord y x hy hx hyx b a hb ha (by linarith) rw [add_comm (b * binEnt y), add_comm (b * y)] at h; exact h intro u v hu hv huv c d hc hd hcd by_cases hc0 : c = 0 · subst hc0; have hd1 : d = 1 := by linarith subst hd1; simp by_cases hd0 : d = 0 · subst hd0; have hc1 : c = 1 := by linarith subst hc1; simp by_cases heq : u = v · subst heq; rw [← add_mul, hcd, one_mul, ← add_mul, hcd, one_mul] have hc_pos : 0 < c := lt_of_le_of_ne hc (Ne.symm hc0) have hd_pos : 0 < d := lt_of_le_of_ne hd (Ne.symm hd0) have huv_lt : u < v := lt_of_le_of_ne huv heq set m := c * u + d * v have hum : u < m := by have hdiff : m - u = d * (v - u) := by dsimp only [m]; rw [show c = 1 - d by linarith]; ring linarith [mul_pos hd_pos (sub_pos.mpr huv_lt)] have hmv : m < v := by have hdiff : v - m = c * (v - u) := by dsimp only [m]; rw [show d = 1 - c by linarith]; ring linarith [mul_pos hc_pos (sub_pos.mpr huv_lt)] -- MVT on [u, m] and [m, v] using antitone derivative Real.log (1 - z) - Real.log z! obtain ⟨ξ₁, ⟨hξ₁_lo, hξ₁_hi⟩, hmv1⟩ := exists_hasDerivAt_eq_slope binEnt (fun z => Real.log (1 - z) - Real.log z) hum (binEnt_continuousOn.mono fun z hz => ⟨le_trans hu.1 hz.1, le_trans hz.2 (le_trans (le_of_lt hmv) hv.2)⟩) (fun z hz => binEnt_hasDerivAt (lt_of_le_of_lt hu.1 hz.1) (lt_of_lt_of_le (lt_trans hz.2 hmv) hv.2)) obtain ⟨ξ₂, ⟨hξ₂_lo, hξ₂_hi⟩, hmv2⟩ := exists_hasDerivAt_eq_slope binEnt (fun z => Real.log (1 - z) - Real.log z) hmv (binEnt_continuousOn.mono fun z hz => ⟨le_trans (le_trans hu.1 (le_of_lt hum)) hz.1, le_trans hz.2 hv.2⟩) (fun z hz => binEnt_hasDerivAt (lt_of_le_of_lt hu.1 (lt_trans hum hz.1)) (lt_of_lt_of_le hz.2 hv.2)) have hξ_lt : ξ₁ < ξ₂ := lt_trans hξ₁_hi hξ₂_lo have hξ₁_pos : 0 < ξ₁ := lt_of_le_of_lt hu.1 hξ₁_lo have hξ₂_lt1 : ξ₂ < 1 := lt_of_lt_of_le hξ₂_hi hv.2 have hderiv_le : Real.log (1 - ξ₂) - Real.log ξ₂ ≤ Real.log (1 - ξ₁) - Real.log ξ₁ := by have h1 := Real.log_le_log hξ₁_pos (le_of_lt hξ_lt) have h2 := Real.log_le_log (sub_pos.mpr hξ₂_lt1) (by linarith : 1 - ξ₂ ≤ 1 - ξ₁) linarith have hslope : (binEnt v - binEnt m) / (v - m) ≤ (binEnt m - binEnt u) / (m - u) := by linarith have hmu_eq : m - u = d * (v - u) := by dsimp only [m]; nlinarith have hvm_eq : v - m = c * (v - u) := by dsimp only [m]; nlinarith have hvu_pos : 0 < v - u := sub_pos.mpr huv_lt rw [hmu_eq, hvm_eq, div_le_div_iff₀ (mul_pos hc_pos hvu_pos) (mul_pos hd_pos hvu_pos)] at hslope have hsimp : (binEnt v - binEnt m) * (d * (v - u)) - (binEnt m - binEnt u) * (c * (v - u)) = (v - u) * (c * binEnt u + d * binEnt v - (c + d) * binEnt m) := by ring rw [hcd, one_mul] at hsimp nlinarith /-- Expected 0–1 mistakes incurred by a binary single-pass learner `L` on concept `h` from state `q₀`. -/ noncomputable def passZeroOneErr {d M : ℕ} (L : PassLearner Bool d M) (q₀ : Fin M) (h : Fin d → Bool) : ℝ := ∑ j : Fin d, (1 - L.pred j (runState L j q₀ h) (h j)) /-- Tail of a `(d + 1)`-step pass learner on the last `d` coordinates. -/ def tailPassLearner {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β (d + 1) M) : PassLearner β d M where pred j := L.pred j.succ nonneg j := L.nonneg j.succ sum_one j := L.sum_one j.succ trans j := L.trans j.succ lemma runStateAux_tail {β : Type*} [Fintype β] {d M : ℕ} (L : PassLearner β (d + 1) M) (q₀ : Fin M) (h : Fin (d + 1) → β) : ∀ (k : ℕ) (hk : k ≤ d), runStateAux L (k + 1) (by omega) q₀ h = runStateAux (tailPassLearner L) k hk (L.trans 0 q₀ (h 0)) (fun i => h i.succ) | 0, _ => rfl | k + 1, hk => by change L.trans ⟨k + 1, by omega⟩ (runStateAux L (k + 1) (by omega) q₀ h) (h ⟨k + 1, by omega⟩) = L.trans (⟨k, by omega⟩ : Fin d).succ (runStateAux (tailPassLearner L) k (by omega) (L.trans 0 q₀ (h 0)) (fun i => h i.succ)) (h (⟨k, by omega⟩ : Fin d).succ) rw [runStateAux_tail L q₀ h k (by omega)]; rfl /-- Exact 1-bit chain rule for `log |F|` under splitting `F` by `h 0`: `log (n₀ + n₁) = binEnt (n₀ / (n₀ + n₁)) + (n₀ / (n₀ + n₁)) * log n₀ + (n₁ / (n₀ + n₁)) * log n₁`! -/ private lemma log_add_eq_binEnt_chain {n₀ n₁ : ℝ} (h0 : 0 ≤ n₀) (h1 : 0 ≤ n₁) (hpos : 0 < n₀ + n₁) : Real.log (n₀ + n₁) = binEnt (n₀ / (n₀ + n₁)) + (n₀ / (n₀ + n₁)) * Real.log n₀ + (n₁ / (n₀ + n₁)) * Real.log n₁ := by by_cases hn0 : n₀ = 0 · subst hn0; simp [binEnt_zero, div_self (ne_of_gt (by linarith : 0 < n₁))] · by_cases hn1 : n₁ = 0 · subst hn1; simp [binEnt_one, div_self (ne_of_gt (by linarith : 0 < n₀))] · have hα_ne0 : n₀ / (n₀ + n₁) ≠ 0 := div_ne_zero hn0 (ne_of_gt hpos) have h1sub : 1 - n₀ / (n₀ + n₁) = n₁ / (n₀ + n₁) := by field_simp [ne_of_gt hpos]; ring have hα_ne1 : n₀ / (n₀ + n₁) ≠ 1 := by intro h have hz : n₁ / (n₀ + n₁) = 0 := by linarith exact div_ne_zero hn1 (ne_of_gt hpos) hz dsimp only [binEnt] rw [if_neg hα_ne0, if_neg hα_ne1, h1sub, Real.log_div hn0 (ne_of_gt hpos), Real.log_div hn1 (ne_of_gt hpos)] have hsum : n₀ / (n₀ + n₁) + n₁ / (n₀ + n₁) = 1 := by field_simp [ne_of_gt hpos] have hrew : -((n₀ / (n₀ + n₁)) * (Real.log n₀ - Real.log (n₀ + n₁))) - (n₁ / (n₀ + n₁)) * (Real.log n₁ - Real.log (n₀ + n₁)) + (n₀ / (n₀ + n₁)) * Real.log n₀ + (n₁ / (n₀ + n₁)) * Real.log n₁ = (n₀ / (n₀ + n₁) + n₁ / (n₀ + n₁)) * Real.log (n₀ + n₁) := by ring rw [hrew, hsum, one_mul] /-- **Single-Pass Rate-Distortion Converse (`d * h₂(min(ē, 1/2)) ≥ log |F|`)**: For EVERY `d ≥ 1`, EVERY subset `F : Finset (Fin d → Bool)` (`F.Nonempty`), and EVERY binary single-pass learner `L` starting from state `q₀`, the average expected 0–1 error rate `ē = (1 / (d * |F|)) * ∑_{h ∈ F} passZeroOneErr L q₀ h` satisfies `Real.log |F| ≤ d * binEnt (min ē (1 / 2))`! -/ theorem single_pass_zeroOne_binEnt_ge {M : ℕ} : ∀ {d : ℕ}, 0 < d → ∀ (L : PassLearner Bool d M) (q₀ : Fin M) (F : Finset (Fin d → Bool)), F.Nonempty → Real.log (F.card : ℝ) ≤ (d : ℝ) * binEnt (min ((∑ h ∈ F, passZeroOneErr L q₀ h) / ((d : ℝ) * (F.card : ℝ))) (1 / 2)) | 0, hd, _, _, _, _ => by omega | 1, _, L, q₀, F, hF => by have hcard_pos : (0 : ℝ) < (F.card : ℝ) := Nat.cast_pos.mpr hF.card_pos let F₀ := F.filter fun h => h 0 = false let F₁ := F.filter fun h => h 0 = true have hF₀_le1 : F₀.card ≤ 1 := by refine Finset.card_le_one.mpr fun f hf g hg => ?_ funext i; fin_cases i exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm have hF₁_le1 : F₁.card ≤ 1 := by refine Finset.card_le_one.mpr fun f hf g hg => ?_ funext i; fin_cases i exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm have hcard_sum : F₀.card + F₁.card = F.card := by have hdisj : Disjoint F₀ F₁ := by rw [Finset.disjoint_left]; intro h h0 h1 have := (Finset.mem_filter.mp h0).2.symm.trans (Finset.mem_filter.mp h1).2; simp at this have hun : F₀ ∪ F₁ = F := by ext h; simp only [F₀, F₁, Finset.mem_union, Finset.mem_filter] constructor · rintro (⟨hh, _⟩ | ⟨hh, _⟩); exact hh; exact hh · intro hh; cases h 0 <;> simp [hh] rw [← Finset.card_union_of_disjoint hdisj, hun] have hsum_r : (F₀.card : ℝ) + (F₁.card : ℝ) = (F.card : ℝ) := by exact_mod_cast hcard_sum -- Step-0 mistake probability p = L.pred 0 q₀ true ∈ [0, 1] set p : ℝ := L.pred 0 q₀ true have hp0 : 0 ≤ p := L.nonneg 0 q₀ true have h1mp : L.pred 0 q₀ false = 1 - p := by have hs := L.sum_one 0 q₀; simp only [Fintype.sum_bool] at hs; dsimp only [p]; linarith have hp1 : p ≤ 1 := by linarith [L.nonneg 0 q₀ false] have herr_sum : ∑ h ∈ F, passZeroOneErr L q₀ h = (F₀.card : ℝ) * p + (F₁.card : ℝ) * (1 - p) := by have hdisj : Disjoint F₀ F₁ := by rw [Finset.disjoint_left]; intro h h0 h1 have := (Finset.mem_filter.mp h0).2.symm.trans (Finset.mem_filter.mp h1).2; simp at this have hun : F₀ ∪ F₁ = F := by ext h; simp only [F₀, F₁, Finset.mem_union, Finset.mem_filter] constructor · rintro (⟨hh, _⟩ | ⟨hh, _⟩); exact hh; exact hh · intro hh; cases h 0 <;> simp [hh] rw [← hun, Finset.sum_union hdisj] have hs0 : ∑ h ∈ F₀, passZeroOneErr L q₀ h = (F₀.card : ℝ) * p := by have h1 : ∀ h ∈ F₀, passZeroOneErr L q₀ h = p := fun h hh => by dsimp only [passZeroOneErr] rw [Fin.sum_univ_one] change 1 - L.pred 0 q₀ (h 0) = p rw [(Finset.mem_filter.mp hh).2, h1mp]; ring rw [Finset.sum_congr rfl h1, Finset.sum_const, nsmul_eq_mul] have hs1 : ∑ h ∈ F₁, passZeroOneErr L q₀ h = (F₁.card : ℝ) * (1 - p) := by have h1 : ∀ h ∈ F₁, passZeroOneErr L q₀ h = 1 - p := fun h hh => by dsimp only [passZeroOneErr] rw [Fin.sum_univ_one] change 1 - L.pred 0 q₀ (h 0) = 1 - p rw [(Finset.mem_filter.mp hh).2] rw [Finset.sum_congr rfl h1, Finset.sum_const, nsmul_eq_mul] rw [hs0, hs1] set α : ℝ := (F₀.card : ℝ) / (F.card : ℝ) have h1mα : 1 - α = (F₁.card : ℝ) / (F.card : ℝ) := by dsimp only [α]; field_simp [ne_of_gt hcard_pos]; linarith have hα0 : 0 ≤ α := by positivity have h1mα_nn : 0 ≤ 1 - α := by rw [h1mα]; positivity have hα1 : α ≤ 1 := by linarith have he_eq : (∑ h ∈ F, passZeroOneErr L q₀ h) / ((1 : ℝ) * (F.card : ℝ)) = α * p + (1 - α) * (1 - p) := by rw [herr_sum, one_mul, add_div, h1mα]; dsimp only [α]; ring have hmin_le : min α (1 - α) ≤ min (α * p + (1 - α) * (1 - p)) (1 / 2) := by refine le_min ?_ ?_ · rcases le_total α (1 - α) with h | h · rw [min_eq_left h]; nlinarith · rw [min_eq_right h]; nlinarith · rcases le_total α (1 / 2) with h | h · exact le_trans (min_le_left _ _) h · exact le_trans (min_le_right _ _) (by linarith) have hmin_nn : 0 ≤ min α (1 - α) := le_min hα0 (by linarith) have hmin_half : min α (1 - α) ≤ 1 / 2 := by rcases le_total α (1 / 2) with h | h · exact le_trans (min_le_left _ _) h · exact le_trans (min_le_right _ _) (by linarith) have hent_eq : binEnt (min α (1 - α)) = binEnt α := by rcases le_total α (1 - α) with h | h · rw [min_eq_left h] · rw [min_eq_right h, binEnt_symm] have hchain := log_add_eq_binEnt_chain (Nat.cast_nonneg F₀.card) (Nat.cast_nonneg F₁.card) (by linarith) rw [hsum_r] at hchain have hlog0 : Real.log (F₀.card : ℝ) ≤ 0 := by have : (F₀.card : ℝ) ≤ 1 := by exact_mod_cast hF₀_le1 exact Real.log_nonpos (Nat.cast_nonneg _) this have hlog1 : Real.log (F₁.card : ℝ) ≤ 0 := by have : (F₁.card : ℝ) ≤ 1 := by exact_mod_cast hF₁_le1 exact Real.log_nonpos (Nat.cast_nonneg _) this have hmono := binEnt_monoOn_half ⟨hmin_nn, hmin_half⟩ ⟨le_trans hmin_nn hmin_le, min_le_right _ _⟩ hmin_le rw [Nat.cast_one, one_mul, he_eq] rw [hent_eq] at hmono have ht0 : (F₀.card : ℝ) / (F.card : ℝ) * Real.log (F₀.card : ℝ) ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hα0 hlog0 have ht1 : (F₁.card : ℝ) / (F.card : ℝ) * Real.log (F₁.card : ℝ) ≤ 0 := mul_nonpos_of_nonneg_of_nonpos (by positivity) hlog1 linarith | d + 2, _, L, q₀, F, hF => by have hd_pos : 0 < d + 1 := Nat.succ_pos d have hcard_pos : (0 : ℝ) < (F.card : ℝ) := Nat.cast_pos.mpr hF.card_pos let F₀ := F.filter fun h => h 0 = false let F₁ := F.filter fun h => h 0 = true have hdisj : Disjoint F₀ F₁ := by rw [Finset.disjoint_left]; intro h h0 h1 have := (Finset.mem_filter.mp h0).2.symm.trans (Finset.mem_filter.mp h1).2; simp at this have hun : F₀ ∪ F₁ = F := by ext h; simp only [F₀, F₁, Finset.mem_union, Finset.mem_filter] constructor · rintro (⟨hh, _⟩ | ⟨hh, _⟩); exact hh; exact hh · intro hh; cases h 0 <;> simp [hh] have hsum_r : (F₀.card : ℝ) + (F₁.card : ℝ) = (F.card : ℝ) := by have := Finset.card_union_of_disjoint hdisj; rw [hun] at this; exact_mod_cast this.symm set α : ℝ := (F₀.card : ℝ) / (F.card : ℝ) have h1mα : 1 - α = (F₁.card : ℝ) / (F.card : ℝ) := by dsimp only [α]; field_simp [ne_of_gt hcard_pos]; linarith have hα0 : 0 ≤ α := by positivity have h1mα_nn : 0 ≤ 1 - α := by rw [h1mα]; positivity have hα1 : α ≤ 1 := by linarith -- Split passZeroOneErr into coordinate 0 + tail of length d + 1! set p : ℝ := L.pred 0 q₀ true have hp0 : 0 ≤ p := L.nonneg 0 q₀ true have h1mp : L.pred 0 q₀ false = 1 - p := by have hs := L.sum_one 0 q₀; simp only [Fintype.sum_bool] at hs; dsimp only [p]; linarith have hp1 : p ≤ 1 := by linarith [L.nonneg 0 q₀ false] let tail : (Fin (d + 2) → Bool) → (Fin (d + 1) → Bool) := fun h i => h i.succ let T₀ : Finset (Fin (d + 1) → Bool) := F₀.image tail let T₁ : Finset (Fin (d + 1) → Bool) := F₁.image tail have hT₀_card : T₀.card = F₀.card := by refine Finset.card_image_of_injOn fun f hf g hg heq => ?_ funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm have hT₁_card : T₁.card = F₁.card := by refine Finset.card_image_of_injOn fun f hf g hg heq => ?_ funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm have hsplit_err : ∀ h : Fin (d + 2) → Bool, passZeroOneErr L q₀ h = (1 - L.pred 0 q₀ (h 0)) + passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ (h 0)) (tail h) := fun h => by dsimp only [passZeroOneErr] rw [Fin.sum_univ_succ] congr 1 refine Finset.sum_congr rfl fun i _ => ?_ have hst : runState L i.succ q₀ h = runState (tailPassLearner L) i (L.trans 0 q₀ (h 0)) (tail h) := runStateAux_tail L q₀ h i.val (le_of_lt i.isLt) rw [hst]; rfl have hsum_F₀ : ∑ h ∈ F₀, passZeroOneErr L q₀ h = (F₀.card : ℝ) * p + ∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g := by rw [Finset.sum_congr rfl fun h hh => by rw [hsplit_err h, (Finset.mem_filter.mp hh).2, h1mp, sub_sub_cancel]] rw [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul] congr 1 refine (Finset.sum_image fun f hf g hg heq => ?_).symm funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm have hsum_F₁ : ∑ h ∈ F₁, passZeroOneErr L q₀ h = (F₁.card : ℝ) * (1 - p) + ∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g := by rw [Finset.sum_congr rfl fun h hh => by rw [hsplit_err h, (Finset.mem_filter.mp hh).2]] rw [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul] congr 1 refine (Finset.sum_image fun f hf g hg heq => ?_).symm funext j; refine Fin.cases ?_ (fun i => congrFun heq i) j exact (Finset.mem_filter.mp hf).2.trans (Finset.mem_filter.mp hg).2.symm -- Define the 3 clamped error rates e0, r0, r1 ∈ [0, 1/2]! set e₀ : ℝ := min (α * p + (1 - α) * (1 - p)) (1 / 2) set r₀ : ℝ := if F₀.Nonempty then min ((∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) / (((d + 1 : ℕ) : ℝ) * (T₀.card : ℝ))) (1 / 2) else 0 set r₁ : ℝ := if F₁.Nonempty then min ((∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) / (((d + 1 : ℕ) : ℝ) * (T₁.card : ℝ))) (1 / 2) else 0 have he₀_ge : binEnt α ≤ binEnt e₀ := by have hmin_le : min α (1 - α) ≤ e₀ := by dsimp only [e₀]; refine le_min ?_ ?_ · rcases le_total α (1 - α) with h | h · rw [min_eq_left h]; nlinarith · rw [min_eq_right h]; nlinarith · rcases le_total α (1 / 2) with h | h · exact le_trans (min_le_left _ _) h · exact le_trans (min_le_right _ _) (by linarith) have hmin_nn : 0 ≤ min α (1 - α) := le_min hα0 (by linarith) have hmin_half : min α (1 - α) ≤ 1 / 2 := by rcases le_total α (1 / 2) with h | h · exact le_trans (min_le_left _ _) h · exact le_trans (min_le_right _ _) (by linarith) have hent_eq : binEnt (min α (1 - α)) = binEnt α := by rcases le_total α (1 - α) with h | h · rw [min_eq_left h] · rw [min_eq_right h, binEnt_symm] rw [← hent_eq] exact binEnt_monoOn_half ⟨hmin_nn, hmin_half⟩ ⟨le_trans hmin_nn hmin_le, min_le_right _ _⟩ hmin_le have hr₀_mem : r₀ ∈ Set.Icc (0 : ℝ) (1 / 2) := by dsimp only [r₀]; split_ifs with h0 · refine ⟨le_min ?_ (by norm_num), min_le_right _ _⟩ refine div_nonneg (Finset.sum_nonneg fun g _ => Finset.sum_nonneg fun j _ => ?_) (by positivity) have hle1 : (tailPassLearner L).pred j (runState (tailPassLearner L) j (L.trans 0 q₀ false) g) (g j) ≤ 1 := by rw [← (tailPassLearner L).sum_one j _] exact Finset.single_le_sum (fun y _ => (tailPassLearner L).nonneg j _ y) (Finset.mem_univ _) linarith · norm_num have hr₁_mem : r₁ ∈ Set.Icc (0 : ℝ) (1 / 2) := by dsimp only [r₁]; split_ifs with h1 · refine ⟨le_min ?_ (by norm_num), min_le_right _ _⟩ refine div_nonneg (Finset.sum_nonneg fun g _ => Finset.sum_nonneg fun j _ => ?_) (by positivity) have hle1 : (tailPassLearner L).pred j (runState (tailPassLearner L) j (L.trans 0 q₀ true) g) (g j) ≤ 1 := by rw [← (tailPassLearner L).sum_one j _] exact Finset.single_le_sum (fun y _ => (tailPassLearner L).nonneg j _ y) (Finset.mem_univ _) linarith · norm_num have he₀_mem : e₀ ∈ Set.Icc (0 : ℝ) (1 / 2) := by refine ⟨le_min (by nlinarith) (by norm_num), min_le_right _ _⟩ -- IH on T₀ and T₁! have hih₀ : α * Real.log (F₀.card : ℝ) ≤ α * (((d + 1 : ℕ) : ℝ) * binEnt r₀) := by by_cases h0 : F₀.Nonempty · have hT0 : T₀.Nonempty := h0.image tail have hih := single_pass_zeroOne_binEnt_ge hd_pos (tailPassLearner L) (L.trans 0 q₀ false) T₀ hT0 rw [hT₀_card] at hih dsimp only [r₀]; rw [if_pos h0, hT₀_card] exact mul_le_mul_of_nonneg_left hih hα0 · have hemp : F₀ = ∅ := Finset.not_nonempty_iff_eq_empty.mp h0 have hαz : α = 0 := by dsimp only [α]; rw [hemp]; simp rw [hαz]; simp have hih₁ : (1 - α) * Real.log (F₁.card : ℝ) ≤ (1 - α) * (((d + 1 : ℕ) : ℝ) * binEnt r₁) := by by_cases h1 : F₁.Nonempty · have hT1 : T₁.Nonempty := h1.image tail have hih := single_pass_zeroOne_binEnt_ge hd_pos (tailPassLearner L) (L.trans 0 q₀ true) T₁ hT1 rw [hT₁_card] at hih dsimp only [r₁]; rw [if_pos h1, hT₁_card] exact mul_le_mul_of_nonneg_left hih (by linarith) · have hemp : F₁ = ∅ := Finset.not_nonempty_iff_eq_empty.mp h1 have h1αz : 1 - α = 0 := by rw [h1mα, hemp]; simp rw [h1αz]; simp -- Combine via 3-point concavity of binEnt on [0, 1]! have hconc_r : α * binEnt r₀ + (1 - α) * binEnt r₁ ≤ binEnt (α * r₀ + (1 - α) * r₁) := by have h := binEnt_concaveOn.2 ⟨hr₀_mem.1, by linarith only [hr₀_mem.2]⟩ ⟨hr₁_mem.1, by linarith only [hr₁_mem.2]⟩ hα0 h1mα_nn (show α + (1 - α) = 1 by ring) simpa [smul_eq_mul] using h set rbar : ℝ := α * r₀ + (1 - α) * r₁ have hrbar_mem : rbar ∈ Set.Icc (0 : ℝ) (1 / 2) := ⟨add_nonneg (mul_nonneg hα0 hr₀_mem.1) (mul_nonneg h1mα_nn hr₁_mem.1), by nlinarith only [hα0, h1mα_nn, hr₀_mem.2, hr₁_mem.2]⟩ have hd2_pos : (0 : ℝ) < ((d + 2 : ℕ) : ℝ) := Nat.cast_pos.mpr (Nat.succ_pos _) set w0 : ℝ := 1 / ((d + 2 : ℕ) : ℝ) set w1 : ℝ := ((d + 1 : ℕ) : ℝ) / ((d + 2 : ℕ) : ℝ) have hw0_nn : 0 ≤ w0 := by positivity have hw1_nn : 0 ≤ w1 := by positivity have hw_sum : w0 + w1 = 1 := by dsimp only [w0, w1]; push_cast; field_simp; ring have hconc_tot : w0 * binEnt e₀ + w1 * binEnt rbar ≤ binEnt (w0 * e₀ + w1 * rbar) := by have h := binEnt_concaveOn.2 ⟨he₀_mem.1, by linarith only [he₀_mem.2]⟩ ⟨hrbar_mem.1, by linarith only [hrbar_mem.2]⟩ hw0_nn hw1_nn hw_sum simpa [smul_eq_mul] using h -- Show w0 * e₀ + w1 * rbar ≤ min (totalErr / ((d+2) * |F|)) (1/2)! have havg_le : w0 * e₀ + w1 * rbar ≤ min ((∑ h ∈ F, passZeroOneErr L q₀ h) / (((d + 2 : ℕ) : ℝ) * (F.card : ℝ))) (1 / 2) := by refine le_min ?_ (by nlinarith only [he₀_mem.2, hrbar_mem.2, hw_sum, hw0_nn, hw1_nn]) have htot_eq : ∑ h ∈ F, passZeroOneErr L q₀ h = (F₀.card : ℝ) * p + (F₁.card : ℝ) * (1 - p) + (∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) + (∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) := by rw [← hun, Finset.sum_union hdisj, hsum_F₀, hsum_F₁]; ring have he0_le : e₀ ≤ α * p + (1 - α) * (1 - p) := min_le_left _ _ have hr0_le : α * (((d + 1 : ℕ) : ℝ) * r₀) ≤ (∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) / (F.card : ℝ) := by by_cases h0 : F₀.Nonempty · have hF0_pos : (0 : ℝ) < (F₀.card : ℝ) := Nat.cast_pos.mpr h0.card_pos have hd1_pos : (0 : ℝ) < ((d + 1 : ℕ) : ℝ) := Nat.cast_pos.mpr hd_pos dsimp only [r₀]; rw [if_pos h0, hT₀_card] have hle := min_le_left ((∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) / (((d + 1 : ℕ) : ℝ) * (F₀.card : ℝ))) (1 / 2) have hmul := mul_le_mul_of_nonneg_left hle (mul_nonneg hα0 (le_of_lt hd1_pos)) have hsimp : α * ((d + 1 : ℕ) : ℝ) * ((∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) / (((d + 1 : ℕ) : ℝ) * (F₀.card : ℝ))) = (∑ g ∈ T₀, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ false) g) / (F.card : ℝ) := by dsimp only [α]; field_simp [ne_of_gt hcard_pos, ne_of_gt hF0_pos, ne_of_gt hd1_pos] linarith only [hmul, hsimp] · have hemp : F₀ = ∅ := Finset.not_nonempty_iff_eq_empty.mp h0 have hT0emp : T₀ = ∅ := by dsimp only [T₀]; rw [hemp, Finset.image_empty] have hαz : α = 0 := by dsimp only [α]; rw [hemp]; simp rw [hαz, hT0emp]; simp have hr1_le : (1 - α) * (((d + 1 : ℕ) : ℝ) * r₁) ≤ (∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) / (F.card : ℝ) := by by_cases h1 : F₁.Nonempty · have hF1_pos : (0 : ℝ) < (F₁.card : ℝ) := Nat.cast_pos.mpr h1.card_pos have hd1_pos : (0 : ℝ) < ((d + 1 : ℕ) : ℝ) := Nat.cast_pos.mpr hd_pos dsimp only [r₁]; rw [if_pos h1, hT₁_card] have hle := min_le_left ((∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) / (((d + 1 : ℕ) : ℝ) * (F₁.card : ℝ))) (1 / 2) have hmul := mul_le_mul_of_nonneg_left hle (mul_nonneg h1mα_nn (le_of_lt hd1_pos)) have hsimp : (1 - α) * ((d + 1 : ℕ) : ℝ) * ((∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) / (((d + 1 : ℕ) : ℝ) * (F₁.card : ℝ))) = (∑ g ∈ T₁, passZeroOneErr (tailPassLearner L) (L.trans 0 q₀ true) g) / (F.card : ℝ) := by rw [h1mα]; field_simp [ne_of_gt hcard_pos, ne_of_gt hF1_pos, ne_of_gt hd1_pos] linarith only [hmul, hsimp] · have hemp : F₁ = ∅ := Finset.not_nonempty_iff_eq_empty.mp h1 have hT1emp : T₁ = ∅ := by dsimp only [T₁]; rw [hemp, Finset.image_empty] have h1αz : 1 - α = 0 := by rw [h1mα, hemp]; simp rw [h1αz, hT1emp]; simp have hnum : e₀ + ((d + 1 : ℕ) : ℝ) * rbar ≤ (∑ h ∈ F, passZeroOneErr L q₀ h) / (F.card : ℝ) := by rw [htot_eq] have heq_p : ((F₀.card : ℝ) * p + (F₁.card : ℝ) * (1 - p)) / (F.card : ℝ) = α * p + (1 - α) * (1 - p) := by rw [add_div, h1mα]; dsimp only [α]; ring have hrew_r : ((d + 1 : ℕ) : ℝ) * rbar = α * (((d + 1 : ℕ) : ℝ) * r₀) + (1 - α) * (((d + 1 : ℕ) : ℝ) * r₁) := by dsimp only [rbar]; ring rw [add_div, add_div, heq_p, hrew_r] linarith only [he0_le, hr0_le, hr1_le] have hdiv := div_le_div_of_nonneg_right hnum (le_of_lt hd2_pos) have hlhs_eq : w0 * e₀ + w1 * rbar = (e₀ + ((d + 1 : ℕ) : ℝ) * rbar) / ((d + 2 : ℕ) : ℝ) := by dsimp only [w0, w1]; ring have hrhs_eq : (∑ h ∈ F, passZeroOneErr L q₀ h) / (F.card : ℝ) / ((d + 2 : ℕ) : ℝ) = (∑ h ∈ F, passZeroOneErr L q₀ h) / (((d + 2 : ℕ) : ℝ) * (F.card : ℝ)) := by rw [div_div, mul_comm] linarith only [hdiv, hlhs_eq, hrhs_eq] have havg_nn : 0 ≤ w0 * e₀ + w1 * rbar := add_nonneg (mul_nonneg hw0_nn he₀_mem.1) (mul_nonneg hw1_nn hrbar_mem.1) have havg_half : w0 * e₀ + w1 * rbar ≤ 1 / 2 := by nlinarith only [he₀_mem.2, hrbar_mem.2, hw_sum, hw0_nn, hw1_nn] have hmono := binEnt_monoOn_half ⟨havg_nn, havg_half⟩ ⟨le_trans havg_nn havg_le, min_le_right _ _⟩ havg_le have hchain := log_add_eq_binEnt_chain (Nat.cast_nonneg F₀.card) (Nat.cast_nonneg F₁.card) (by linarith only [hcard_pos, hsum_r]) rw [hsum_r] at hchain have hstep1 : Real.log (F.card : ℝ) ≤ binEnt e₀ + ((d + 1 : ℕ) : ℝ) * binEnt rbar := by have h1 : α * Real.log (F₀.card : ℝ) + (1 - α) * Real.log (F₁.card : ℝ) ≤ ((d + 1 : ℕ) : ℝ) * (α * binEnt r₀ + (1 - α) * binEnt r₁) := by linarith only [hih₀, hih₁] have h2 := mul_le_mul_of_nonneg_left hconc_r (Nat.cast_nonneg (d + 1)) dsimp only [α] at h1 h2 hchain he₀_ge; rw [h1mα] at h1 h2 linarith only [hchain, h1, h2, he₀_ge] have hmul_conc := mul_le_mul_of_nonneg_left (le_trans hconc_tot hmono) (le_of_lt hd2_pos) have hmul_lhs : ((d + 2 : ℕ) : ℝ) * (w0 * binEnt e₀ + w1 * binEnt rbar) = binEnt e₀ + ((d + 1 : ℕ) : ℝ) * binEnt rbar := by dsimp only [w0, w1]; field_simp [ne_of_gt hd2_pos] linarith only [hstep1, hmul_conc, hmul_lhs] /-- **EXACT WIDTH-`M` MULTI-PASS 0–1 RATE-DISTORTION CONVERSE**: For EVERY `d ≥ 1`, `M ≥ 1`, `R ≥ 1`, EVERY width-`M` multi-pass learner `L` on `Fin d → Bool`, and EVERY pass `r : Fin R`, the per-pass average expected 0–1 error rate `ē_r = (1 / (d * 2^d)) * ∑ h, passZeroOneErr (L.pass r) (stateBeforePass L r h) h` satisfies: `d * Real.log 2 - Real.log M ≤ d * binEnt (min ē_r (1 / 2))`! -/ theorem widthM_multipass_zeroOne_rate_distortion_lower {d M R : ℕ} (hd : 0 < d) (hM : 0 < M) (L : MultiPassLearner Bool d M R) (r : Fin R) : let V : Finset (Fin d → Bool) := Finset.univ let avgErr : ℝ := (∑ h ∈ V, passZeroOneErr (L.pass r) (stateBeforePass L r h) h) / ((d : ℝ) * (V.card : ℝ)) (d : ℝ) * Real.log 2 - Real.log (M : ℝ) ≤ (d : ℝ) * binEnt (min avgErr (1 / 2)) := by intro V avgErr have hV_card : (V.card : ℝ) = (2 : ℝ) ^ d := by dsimp only [V]; rw [Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, Nat.cast_pow, Nat.cast_ofNat] have hV_pos : (0 : ℝ) < (V.card : ℝ) := by rw [hV_card]; positivity have hd_pos : (0 : ℝ) < (d : ℝ) := Nat.cast_pos.mpr hd let φ : (Fin d → Bool) → Fin M := fun h => stateBeforePass L r h let fib : Fin M → Finset (Fin d → Bool) := fun q => V.filter fun h => φ h = q let w : Fin M → ℝ := fun q => ((fib q).card : ℝ) / (V.card : ℝ) let eq : Fin M → ℝ := fun q => if (fib q).Nonempty then min ((∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * ((fib q).card : ℝ))) (1 / 2) else 0 have hw0 : ∀ q ∈ (Finset.univ : Finset (Fin M)), 0 ≤ w q := fun _ _ => by positivity have hwsum : ∑ q : Fin M, w q = 1 := by dsimp only [w]; rw [← Finset.sum_div] have hpart : ∑ q : Fin M, ((fib q).card : ℝ) = (V.card : ℝ) := by exact_mod_cast (Finset.card_eq_sum_card_fiberwise (f := φ) (s := V) (t := Finset.univ) (fun _ _ => Finset.mem_univ _)).symm rw [hpart, div_self (ne_of_gt hV_pos)] have heq_mem : ∀ q ∈ (Finset.univ : Finset (Fin M)), eq q ∈ Set.Icc (0 : ℝ) (1 / 2) := fun q _ => by dsimp only [eq]; split_ifs with hq · refine ⟨le_min ?_ (by norm_num), min_le_right _ _⟩ refine div_nonneg (Finset.sum_nonneg fun h _ => Finset.sum_nonneg fun j _ => ?_) (by positivity) have hle1 : (L.pass r).pred j (runState (L.pass r) j q h) (h j) ≤ 1 := by rw [← (L.pass r).sum_one j _] exact Finset.single_le_sum (fun y _ => (L.pass r).nonneg j _ y) (Finset.mem_univ _) linarith · norm_num -- Jensen via binEnt_concaveOn! have hjensen : ∑ q : Fin M, w q * binEnt (eq q) ≤ binEnt (∑ q : Fin M, w q * eq q) := by have h := binEnt_concaveOn.le_map_sum hw0 hwsum fun q hq => ⟨(heq_mem q hq).1, by linarith [(heq_mem q hq).2]⟩ simpa [smul_eq_mul] using h -- Lower-bound ∑ q, w q * (d * binEnt (eq q)) ≥ log |V| - log M via single_pass_zeroOne_binEnt_ge + fiber_log_card_sum_ge! have hfib_ent : ∀ q : Fin M, ((fib q).card : ℝ) * Real.log ((fib q).card : ℝ) ≤ ((fib q).card : ℝ) * ((d : ℝ) * binEnt (eq q)) := fun q => by by_cases hq : (fib q).Nonempty · dsimp only [eq]; rw [if_pos hq] exact mul_le_mul_of_nonneg_left (single_pass_zeroOne_binEnt_ge hd (L.pass r) q (fib q) hq) (Nat.cast_nonneg _) · rw [Finset.not_nonempty_iff_eq_empty.mp hq]; simp have hlog_ge : Real.log (V.card : ℝ) - Real.log (M : ℝ) ≤ (d : ℝ) * ∑ q : Fin M, w q * binEnt (eq q) := by have hf := fiber_log_card_sum_ge hM V φ have hsum := Finset.sum_le_sum fun q (_ : q ∈ Finset.univ) => hfib_ent q have hcomb := le_trans hf hsum have hrew : ∑ q : Fin M, ((fib q).card : ℝ) * ((d : ℝ) * binEnt (eq q)) = (V.card : ℝ) * ((d : ℝ) * ∑ q : Fin M, w q * binEnt (eq q)) := by rw [Finset.mul_sum, Finset.mul_sum] refine Finset.sum_congr rfl fun q _ => ?_ dsimp only [w]; field_simp [ne_of_gt hV_pos] rw [hrew] at hcomb exact le_of_mul_le_mul_left hcomb hV_pos -- Upper-bound ∑ q, w q * eq q ≤ min avgErr (1 / 2)! have hsum_eq_le : ∑ q : Fin M, w q * eq q ≤ min avgErr (1 / 2) := by refine le_min ?_ ?_ · have hterm : ∀ q : Fin M, w q * eq q ≤ (∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * (V.card : ℝ)) := fun q => by by_cases hq : (fib q).Nonempty · have hq_pos : (0 : ℝ) < ((fib q).card : ℝ) := Nat.cast_pos.mpr hq.card_pos dsimp only [eq]; rw [if_pos hq] have hle := min_le_left ((∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * ((fib q).card : ℝ))) (1 / 2) have hmul := mul_le_mul_of_nonneg_left hle (hw0 q (Finset.mem_univ q)) have hsimp : w q * ((∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * ((fib q).card : ℝ))) = (∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * (V.card : ℝ)) := by dsimp only [w]; field_simp [ne_of_gt hV_pos, ne_of_gt hq_pos, ne_of_gt hd_pos] linarith · have hemp : fib q = ∅ := Finset.not_nonempty_iff_eq_empty.mp hq dsimp only [w, eq]; rw [hemp]; simp calc ∑ q : Fin M, w q * eq q ≤ ∑ q : Fin M, (∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * (V.card : ℝ)) := Finset.sum_le_sum fun q _ => hterm q _ = (∑ q : Fin M, ∑ h ∈ fib q, passZeroOneErr (L.pass r) q h) / ((d : ℝ) * (V.card : ℝ)) := (Finset.sum_div _ _ _).symm _ = avgErr := by dsimp only [avgErr]; congr 1 rw [← Finset.sum_fiberwise_of_maps_to (s := V) (t := Finset.univ) (g := φ) (fun _ _ => Finset.mem_univ _)] refine Finset.sum_congr rfl fun q _ => Finset.sum_congr rfl fun h hh => ?_ have hq : φ h = q := (Finset.mem_filter.mp hh).2 dsimp only [φ] at hq; rw [hq] · calc ∑ q : Fin M, w q * eq q ≤ ∑ q : Fin M, w q * (1 / 2) := Finset.sum_le_sum fun q hq => mul_le_mul_of_nonneg_left (heq_mem q hq).2 (hw0 q hq) _ = (∑ q : Fin M, w q) * (1 / 2) := (Finset.sum_mul _ _ _).symm _ = 1 / 2 := by rw [hwsum, one_mul] have hsum_nn : 0 ≤ ∑ q : Fin M, w q * eq q := Finset.sum_nonneg fun q hq => mul_nonneg (hw0 q hq) (heq_mem q hq).1 have hmono := binEnt_monoOn_half ⟨hsum_nn, le_trans hsum_eq_le (min_le_right _ _)⟩ ⟨le_trans hsum_nn hsum_eq_le, min_le_right _ _⟩ hsum_eq_le have hlogV : Real.log (V.card : ℝ) = (d : ℝ) * Real.log 2 := by rw [hV_card, Real.log_pow] rw [← hlogV] exact le_trans hlog_ge (mul_le_mul_of_nonneg_left (le_trans hjensen hmono) (le_of_lt hd_pos)) /-- 3-bit majority function on `Bool`. -/ def maj3 (a b c : Bool) : Bool := (a && b) || (a && c) || (b && c) /-- Bit encoding `false ↦ 0, true ↦ 1`. -/ def b2n (b : Bool) : ℕ := if b then 1 else 0 /-- **Explicit Infinite Family of Strict Width-`3 * 2^(t - 1)` Block-Majority Learners** on `Fin (3 * t) → Bool`: computes `t` disjoint 3-bit majorities in Pass 0 using strictly `≤ 3 * 2^(t - 1)` states at EVERY intermediate step, stores all `t` majority bits in `2^t` states, and outputs them in all subsequent passes `r ≥ 1`! -/ noncomputable def blockMaj3Pass0 (t : ℕ) (_ht : 1 ≤ t) : PassLearner Bool (3 * t) (3 * 2 ^ (t - 1)) where pred _ _ _ := 1 / 2 nonneg _ _ _ := by norm_num sum_one _ _ := by simp only [Fintype.sum_bool]; norm_num trans j q y := let k := j.val / 3 let s := j.val % 3 let p := 2 ^ k have hM_pos : 0 < 3 * 2 ^ (t - 1) := by positivity if s = 0 then ⟨(q.val + b2n y * p) % (3 * 2 ^ (t - 1)), Nat.mod_lt _ hM_pos⟩ else if s = 1 then let m := q.val % p let c₁ := q.val / p ⟨(m + (c₁ + b2n y) * p) % (3 * 2 ^ (t - 1)), Nat.mod_lt _ hM_pos⟩ else let m := q.val % p let c₂ := q.val / p let majBit := if 2 ≤ c₂ + b2n y then 1 else 0 ⟨(m + majBit * p) % (3 * 2 ^ (t - 1)), Nat.mod_lt _ hM_pos⟩ noncomputable def blockMaj3PassLater (t : ℕ) (_ht : 1 ≤ t) : PassLearner Bool (3 * t) (3 * 2 ^ (t - 1)) where pred j q y := let k := j.val / 3 let bit : Bool := decide ((q.val / 2 ^ k) % 2 = 1) if y = bit then 1 else 0 nonneg _ _ _ := by dsimp only; split_ifs <;> norm_num sum_one j q := by simp only [Fintype.sum_bool] cases decide ((q.val / 2 ^ (j.val / 3)) % 2 = 1) <;> simp trans _ q _ := q noncomputable def blockMaj3Learner (t : ℕ) (ht : 1 ≤ t) (R : ℕ) : MultiPassLearner Bool (3 * t) (3 * 2 ^ (t - 1)) R where init := ⟨0, by positivity⟩ pass p := if p.val = 0 then blockMaj3Pass0 t ht else blockMaj3PassLater t ht /-- Packed `k`-bit majority code `∑_{i < k} b2n(maj3_i) * 2^i` of the first `k ≤ t` blocks of `h`. -/ def packMaj3 {t : ℕ} (h : Fin (3 * t) → Bool) : ∀ k : ℕ, k ≤ t → ℕ | 0, _ => 0 | k + 1, hk => packMaj3 h k (by omega) + b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) * 2 ^ k lemma packMaj3_lt_pow {t : ℕ} (h : Fin (3 * t) → Bool) : ∀ (k : ℕ) (hk : k ≤ t), packMaj3 h k hk < 2 ^ k | 0, _ => by simp [packMaj3] | k + 1, hk => by simp only [packMaj3, pow_succ] have ih := packMaj3_lt_pow h k (by omega) have hb : b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) ≤ 1 := by dsimp only [b2n]; split_ifs <;> omega nlinarith lemma packMaj3_bit {t : ℕ} (h : Fin (3 * t) → Bool) : ∀ (k : ℕ) (hk : k ≤ t) (i : ℕ) (hi : i < k), (packMaj3 h k hk / 2 ^ i) % 2 = b2n (maj3 (h ⟨3 * i, by omega⟩) (h ⟨3 * i + 1, by omega⟩) (h ⟨3 * i + 2, by omega⟩)) | 0, _, _, hi => by omega | k + 1, hk, i, hi => by simp only [packMaj3] by_cases hik : i = k · subst hik rw [Nat.add_mul_div_right _ _ (Nat.two_pow_pos i), Nat.div_eq_of_lt (packMaj3_lt_pow h i (by omega)), zero_add] have hb : b2n (maj3 (h ⟨3 * i, by omega⟩) (h ⟨3 * i + 1, by omega⟩) (h ⟨3 * i + 2, by omega⟩)) < 2 := by dsimp only [b2n]; split_ifs <;> omega exact Nat.mod_eq_of_lt hb · have hi_lt : i < k := by omega have hpow : 2 ^ k = 2 ^ (k - i) * 2 ^ i := by rw [← pow_add, Nat.sub_add_cancel (le_of_lt hi_lt)] have hpow2 : 2 ^ (k - i) = 2 * 2 ^ (k - i - 1) := by rw [← pow_succ']; congr 1; omega rw [hpow, ← mul_assoc, Nat.add_mul_div_right _ _ (Nat.two_pow_pos i), hpow2] have hmod : (packMaj3 h k (by omega) / 2 ^ i + b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) * (2 * 2 ^ (k - i - 1))) % 2 = (packMaj3 h k (by omega) / 2 ^ i) % 2 := by have hrew : b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) * (2 * 2 ^ (k - i - 1)) = 2 * (b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) * 2 ^ (k - i - 1)) := by ring rw [hrew, Nat.add_mul_mod_self_left] rw [hmod] exact packMaj3_bit h k (by omega) i hi_lt lemma blockMaj3Pass0_block_state {t : ℕ} (ht : 1 ≤ t) (h : Fin (3 * t) → Bool) : ∀ (k : ℕ) (hk : k ≤ t), (runStateAux (blockMaj3Pass0 t ht) (3 * k) (by omega) ⟨0, by positivity⟩ h).val = packMaj3 h k hk | 0, _ => by simp [runStateAux, packMaj3] | k + 1, hk => by have ih := blockMaj3Pass0_block_state ht h k (by omega) have hlt_m : packMaj3 h k (by omega) < 2 ^ k := packMaj3_lt_pow h k (by omega) have hpow_le : 2 ^ k ≤ 2 ^ (t - 1) := Nat.pow_le_pow_right (by norm_num) (by omega) have hstep0 : 3 * (k + 1) = (3 * k + 2) + 1 := by omega have hstep1 : 3 * k + 2 = (3 * k + 1) + 1 := by omega have hstep2 : 3 * k + 1 = 3 * k + 1 := rfl -- Step s = 0 (at index 3*k): have h_s0 : (runStateAux (blockMaj3Pass0 t ht) (3 * k + 1) (by omega) ⟨0, by positivity⟩ h).val = packMaj3 h k (by omega) + b2n (h ⟨3 * k, by omega⟩) * 2 ^ k := by set q0 := runStateAux (blockMaj3Pass0 t ht) (3 * k) (by omega) ⟨0, by positivity⟩ h have ih' : q0.val = packMaj3 h k (by omega) := ih change ((blockMaj3Pass0 t ht).trans ⟨3 * k, by omega⟩ q0 (h ⟨3 * k, by omega⟩)).val = _ dsimp only [blockMaj3Pass0] have hdiv : (3 * k) / 3 = k := by omega have hmod : (3 * k) % 3 = 0 := by omega simp only [hdiv, hmod, ↓reduceIte] rw [ih'] have hb0 : b2n (h ⟨3 * k, by omega⟩) ≤ 1 := by dsimp only [b2n]; split_ifs <;> omega have hlt : packMaj3 h k (by omega) + b2n (h ⟨3 * k, by omega⟩) * 2 ^ k < 3 * 2 ^ (t - 1) := by nlinarith exact Nat.mod_eq_of_lt hlt -- Step s = 1 (at index 3*k + 1): have h_s1 : (runStateAux (blockMaj3Pass0 t ht) (3 * k + 2) (by omega) ⟨0, by positivity⟩ h).val = packMaj3 h k (by omega) + (b2n (h ⟨3 * k, by omega⟩) + b2n (h ⟨3 * k + 1, by omega⟩)) * 2 ^ k := by set q1 := runStateAux (blockMaj3Pass0 t ht) (3 * k + 1) (by omega) ⟨0, by positivity⟩ h have h_s0' : q1.val = packMaj3 h k (by omega) + b2n (h ⟨3 * k, by omega⟩) * 2 ^ k := h_s0 change ((blockMaj3Pass0 t ht).trans ⟨3 * k + 1, by omega⟩ q1 (h ⟨3 * k + 1, by omega⟩)).val = _ dsimp only [blockMaj3Pass0] have hdiv : (3 * k + 1) / 3 = k := by omega have hmod1 : (3 * k + 1) % 3 = 1 := by omega have hne0 : (1 : ℕ) ≠ 0 := by decide simp only [hdiv, hmod1, hne0, ↓reduceIte] rw [h_s0'] rw [Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt hlt_m, Nat.add_mul_div_right _ _ (Nat.two_pow_pos k), Nat.div_eq_of_lt hlt_m, zero_add] have hb0 : b2n (h ⟨3 * k, by omega⟩) ≤ 1 := by dsimp only [b2n]; split_ifs <;> omega have hb1 : b2n (h ⟨3 * k + 1, by omega⟩) ≤ 1 := by dsimp only [b2n]; split_ifs <;> omega have hlt : packMaj3 h k (by omega) + (b2n (h ⟨3 * k, by omega⟩) + b2n (h ⟨3 * k + 1, by omega⟩)) * 2 ^ k < 3 * 2 ^ (t - 1) := by nlinarith exact Nat.mod_eq_of_lt hlt -- Step s = 2 (at index 3*k + 2): have h_s2 : (runStateAux (blockMaj3Pass0 t ht) (3 * k + 3) (by omega) ⟨0, by positivity⟩ h).val = packMaj3 h (k + 1) hk := by set q2 := runStateAux (blockMaj3Pass0 t ht) (3 * k + 2) (by omega) ⟨0, by positivity⟩ h have h_s1' : q2.val = packMaj3 h k (by omega) + (b2n (h ⟨3 * k, by omega⟩) + b2n (h ⟨3 * k + 1, by omega⟩)) * 2 ^ k := h_s1 change ((blockMaj3Pass0 t ht).trans ⟨3 * k + 2, by omega⟩ q2 (h ⟨3 * k + 2, by omega⟩)).val = _ dsimp only [blockMaj3Pass0] have hdiv : (3 * k + 2) / 3 = k := by omega have hmod2 : (3 * k + 2) % 3 = 2 := by omega have hne0 : (2 : ℕ) ≠ 0 := by decide have hne1 : (2 : ℕ) ≠ 1 := by decide simp only [hdiv, hmod2, hne0, hne1, ↓reduceIte] rw [h_s1'] rw [Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt hlt_m, Nat.add_mul_div_right _ _ (Nat.two_pow_pos k), Nat.div_eq_of_lt hlt_m, zero_add] have hmaj_eq : (if 2 ≤ b2n (h ⟨3 * k, by omega⟩) + b2n (h ⟨3 * k + 1, by omega⟩) + b2n (h ⟨3 * k + 2, by omega⟩) then 1 else 0) = b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) := by cases h ⟨3 * k, by omega⟩ <;> cases h ⟨3 * k + 1, by omega⟩ <;> cases h ⟨3 * k + 2, by omega⟩ <;> rfl rw [hmaj_eq] have hlt : packMaj3 h k (by omega) + b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) * 2 ^ k < 3 * 2 ^ (t - 1) := by have hb : b2n (maj3 (h ⟨3 * k, by omega⟩) (h ⟨3 * k + 1, by omega⟩) (h ⟨3 * k + 2, by omega⟩)) ≤ 1 := by dsimp only [b2n]; split_ifs <;> omega nlinarith rw [Nat.mod_eq_of_lt hlt]; rfl exact h_s2 lemma blockMaj3PassLater_runStateAux {t : ℕ} (ht : 1 ≤ t) (q₀ : Fin (3 * 2 ^ (t - 1))) (h : Fin (3 * t) → Bool) : ∀ (k : ℕ) (hk : k ≤ 3 * t), runStateAux (blockMaj3PassLater t ht) k hk q₀ h = q₀ | 0, _ => rfl | k + 1, hk => by change runStateAux (blockMaj3PassLater t ht) k (by omega) q₀ h = q₀ exact blockMaj3PassLater_runStateAux ht q₀ h k (by omega) /-- **Exact Per-Pass 0–1 Performance of Strict Width-`3 * 2^(t-1)` Block-Majority Learner**: For EVERY `t ≥ 1`, `R ≥ 2`, and EVERY pass `r : Fin R` with `r.val ≠ 0`: 1. Worst-case 0–1 mistakes on EVERY `h : Fin (3 * t) → Bool` is `≤ t`, 2. Average 0–1 mistakes over `Fin (3 * t) → Bool` equals EXACTLY `(3 / 4 : ℝ) * t`! -/ theorem blockMaj3Learner_pass_zeroOne_exact {t R : ℕ} (ht : 1 ≤ t) (r : Fin R) (hr0 : r.val ≠ 0) : (∀ h : Fin (3 * t) → Bool, passZeroOneErr ((blockMaj3Learner t ht R).pass r) (stateBeforePass (blockMaj3Learner t ht R) r h) h ≤ (t : ℝ)) ∧ (∑ h : Fin (3 * t) → Bool, passZeroOneErr ((blockMaj3Learner t ht R).pass r) (stateBeforePass (blockMaj3Learner t ht R) r h) h) / ((2 : ℝ) ^ (3 * t)) = (3 / 4 : ℝ) * (t : ℝ) := by have hstate : ∀ (p : Fin R) (h : Fin (3 * t) → Bool), p.val ≠ 0 → (stateBeforePass (blockMaj3Learner t ht R) p h).val = packMaj3 h t le_rfl := by intro ⟨p, hp⟩ h hp0 dsimp only [stateBeforePass] induction p with | zero => exact absurd rfl hp0 | succ m ih => simp only [stateBeforePassAux] by_cases hm0 : m = 0 · subst hm0 simp only [blockMaj3Learner, ↓reduceIte, stateBeforePassAux, endState] exact blockMaj3Pass0_block_state ht h t le_rfl · have hne : (⟨m, by omega⟩ : Fin R).val ≠ 0 := hm0 simp only [blockMaj3Learner, hne, ↓reduceIte, endState] rw [blockMaj3PassLater_runStateAux] exact ih (by omega) hm0 -- Evaluate passZeroOneErr on pass r for any h! have herr_eq : ∀ h : Fin (3 * t) → Bool, passZeroOneErr ((blockMaj3Learner t ht R).pass r) (stateBeforePass (blockMaj3Learner t ht R) r h) h = ∑ k : Fin t, ((if h ⟨3 * k.val, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1) + (if h ⟨3 * k.val + 1, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1) + (if h ⟨3 * k.val + 2, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1)) := by intro h have hp_eq : (blockMaj3Learner t ht R).pass r = blockMaj3PassLater t ht := if_neg hr0 dsimp only [passZeroOneErr] rw [hp_eq] have hbit : ∀ j : Fin (3 * t), 1 - (blockMaj3PassLater t ht).pred j (runState (blockMaj3PassLater t ht) j (stateBeforePass (blockMaj3Learner t ht R) r h) h) (h j) = if h j = maj3 (h ⟨3 * (j.val / 3), by omega⟩) (h ⟨3 * (j.val / 3) + 1, by omega⟩) (h ⟨3 * (j.val / 3) + 2, by omega⟩) then (0 : ℝ) else 1 := by intro j dsimp only [runState] rw [blockMaj3PassLater_runStateAux ht _ h j.val (le_of_lt j.isLt)] dsimp only [blockMaj3PassLater] rw [hstate r h hr0, packMaj3_bit h t le_rfl (j.val / 3) (by omega)] have hdec : decide (b2n (maj3 (h ⟨3 * (j.val / 3), by omega⟩) (h ⟨3 * (j.val / 3) + 1, by omega⟩) (h ⟨3 * (j.val / 3) + 2, by omega⟩)) = 1) = maj3 (h ⟨3 * (j.val / 3), by omega⟩) (h ⟨3 * (j.val / 3) + 1, by omega⟩) (h ⟨3 * (j.val / 3) + 2, by omega⟩) := by cases maj3 (h ⟨3 * (j.val / 3), by omega⟩) (h ⟨3 * (j.val / 3) + 1, by omega⟩) (h ⟨3 * (j.val / 3) + 2, by omega⟩) <;> rfl rw [hdec]; split_ifs <;> norm_num rw [Finset.sum_congr rfl fun j _ => hbit j] -- Re-index Fin (3 * t) ≃ Fin t × Fin 3! let e : Fin t × Fin 3 ≃ Fin (3 * t) := { toFun := fun ks => ⟨3 * ks.1.val + ks.2.val, by omega⟩ invFun := fun j => (⟨j.val / 3, by omega⟩, ⟨j.val % 3, Nat.mod_lt _ (by norm_num)⟩) left_inv := fun ⟨k, s⟩ => by ext <;> (dsimp; omega) right_inv := fun j => by ext; simp; omega } rw [← Equiv.sum_comp e, Fintype.sum_prod_type] refine Finset.sum_congr rfl fun k _ => ?_ rw [Fin.sum_univ_three] have h0 : (3 * k.val) / 3 = k.val := by omega have h1 : (3 * k.val + 1) / 3 = k.val := by omega have h2 : (3 * k.val + 2) / 3 = k.val := by omega simp only [e, Equiv.coe_fn_mk, Fin.val_zero, Fin.val_one, Fin.val_two, add_zero, h0, h1, h2] constructor · intro h rw [herr_eq h] calc ∑ k : Fin t, _ ≤ ∑ _k : Fin t, (1 : ℝ) := by refine Finset.sum_le_sum fun k _ => ?_ cases h ⟨3 * k.val, by omega⟩ <;> cases h ⟨3 * k.val + 1, by omega⟩ <;> cases h ⟨3 * k.val + 2, by omega⟩ <;> simp [maj3] _ = (t : ℝ) := by simp · simp_rw [herr_eq] rw [Finset.sum_comm] -- For each block k : Fin t, the sum over all h : Fin (3*t) → Bool of block-k errors equals (3/4) * 2^(3*t)! have hblock_sum : ∀ k : Fin t, ∑ h : Fin (3 * t) → Bool, ((if h ⟨3 * k.val, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1) + (if h ⟨3 * k.val + 1, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1) + (if h ⟨3 * k.val + 2, by omega⟩ = maj3 (h ⟨3 * k.val, by omega⟩) (h ⟨3 * k.val + 1, by omega⟩) (h ⟨3 * k.val + 2, by omega⟩) then (0 : ℝ) else 1)) = (3 / 4 : ℝ) * (2 : ℝ) ^ (3 * t) := by intro k let i0 : Fin (3 * t) := ⟨3 * k.val, by omega⟩ let i1 : Fin (3 * t) := ⟨3 * k.val + 1, by omega⟩ let i2 : Fin (3 * t) := ⟨3 * k.val + 2, by omega⟩ have h01 : i0 ≠ i1 := by intro h; have := congrArg Fin.val h; simp [i0, i1] at this have h02 : i0 ≠ i2 := by intro h; have := congrArg Fin.val h; simp [i0, i2] at this have h12 : i1 ≠ i2 := by intro h; have := congrArg Fin.val h; simp [i1, i2] at this let S : Finset (Fin (3 * t)) := {i0, i1, i2} have hScard : S.card = 3 := by dsimp only [S] rw [Finset.card_insert_of_notMem (by simp [h01, h02]), Finset.card_pair h12] -- Fiber over the 3-tuple (h i0, h i1, h i2) ∈ Bool × Bool × Bool! let proj : (Fin (3 * t) → Bool) → Bool × Bool × Bool := fun h => (h i0, h i1, h i2) have hfib_card : ∀ abc : Bool × Bool × Bool, (Finset.univ.filter fun h : Fin (3 * t) → Bool => proj h = abc).card = 2 ^ (3 * t - 3) := by intro ⟨a, b, c⟩ let rest := (Finset.univ : Finset (Fin (3 * t))) \ S have hrest_card : rest.card = 3 * t - 3 := by dsimp only [rest]; rw [Finset.card_sdiff, Finset.inter_univ, Finset.card_univ, Fintype.card_fin, hScard] have hbij : (Finset.univ.filter fun h : Fin (3 * t) → Bool => proj h = (a, b, c)).card = (Finset.univ : Finset (rest → Bool)).card := by refine Finset.card_bij (fun h _ r => h r.1) (fun _ _ => Finset.mem_univ _) ?_ ?_ · intro f hf g hg heq have hpf := (Finset.mem_filter.mp hf).2 have hpg := (Finset.mem_filter.mp hg).2 dsimp only [proj] at hpf hpg funext x by_cases hx : x ∈ S · simp only [S, Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | rfl | rfl · exact (congrArg Prod.fst hpf).trans (congrArg Prod.fst hpg).symm · exact (congrArg (fun p => p.2.1) hpf).trans (congrArg (fun p => p.2.1) hpg).symm · exact (congrArg (fun p => p.2.2) hpf).trans (congrArg (fun p => p.2.2) hpg).symm · exact congrFun heq ⟨x, Finset.mem_sdiff.mpr ⟨Finset.mem_univ x, hx⟩⟩ · intro g _ let f : Fin (3 * t) → Bool := fun x => if x = i0 then a else if x = i1 then b else if x = i2 then c else if hx : x ∈ rest then g ⟨x, hx⟩ else false refine ⟨f, Finset.mem_filter.mpr ⟨Finset.mem_univ f, ?_⟩, ?_⟩ · dsimp only [proj, f] simp [h01.symm, h02.symm, h12.symm] · funext ⟨x, hx⟩ have hxnot : x ∉ S := (Finset.mem_sdiff.mp hx).2 have hn0 : x ≠ i0 := fun heq => hxnot (by simp [S, heq]) have hn1 : x ≠ i1 := fun heq => hxnot (by simp [S, heq]) have hn2 : x ≠ i2 := fun heq => hxnot (by simp [S, heq]) simp [f, hn0, hn1, hn2, hx] rw [hbij, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_coe, hrest_card] rw [← Finset.sum_fiberwise_of_maps_to (s := Finset.univ) (t := Finset.univ) (g := proj) (fun _ _ => Finset.mem_univ _)] have hconst_fib : ∀ abc : Bool × Bool × Bool, ∑ h ∈ Finset.univ.filter (fun h => proj h = abc), ((if h i0 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1) + (if h i1 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1) + (if h i2 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1)) = ((2 : ℝ) ^ (3 * t - 3)) * ((if abc.1 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1) + (if abc.2.1 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1) + (if abc.2.2 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1)) := by intro abc rcases abc with ⟨a, b, c⟩ have hcongr : ∀ h ∈ Finset.univ.filter (fun h => proj h = (a, b, c)), ((if h i0 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1) + (if h i1 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1) + (if h i2 = maj3 (h i0) (h i1) (h i2) then (0 : ℝ) else 1)) = ((if a = maj3 a b c then (0 : ℝ) else 1) + (if b = maj3 a b c then (0 : ℝ) else 1) + (if c = maj3 a b c then (0 : ℝ) else 1)) := fun h hh => by have hp := (Finset.mem_filter.mp hh).2 dsimp only [proj] at hp rcases Prod.mk.inj hp with ⟨h0, hp2⟩ rcases Prod.mk.inj hp2 with ⟨h1, h2⟩ rw [h0, h1, h2] rw [Finset.sum_congr rfl hcongr, Finset.sum_const, nsmul_eq_mul, hfib_card (a, b, c), Nat.cast_pow, Nat.cast_ofNat] rw [Finset.sum_congr rfl fun abc _ => hconst_fib abc, ← Finset.mul_sum] have h8 : ∑ abc : Bool × Bool × Bool, ((if abc.1 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1) + (if abc.2.1 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1) + (if abc.2.2 = maj3 abc.1 abc.2.1 abc.2.2 then (0 : ℝ) else 1)) = 6 := by simp only [Fintype.sum_prod_type, Fintype.sum_bool, maj3]; norm_num rw [h8] have hpow : (2 : ℝ) ^ (3 * t) = (2 : ℝ) ^ (3 * t - 3) * (2 : ℝ) ^ 3 := by rw [← pow_add, Nat.sub_add_cancel (by omega)] rw [hpow]; ring rw [Finset.sum_congr rfl fun k _ => hblock_sum k, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have h2pos : (2 : ℝ) ^ (3 * t) ≠ 0 := by positivity field_simp /-- Lift a width-`M₁` learner into a larger width `M₂ ≥ M₁` without changing predictions or losses! -/ def liftPassLearner {β : Type*} [Fintype β] {d M₁ M₂ : ℕ} (hM : M₁ ≤ M₂) (L : PassLearner β d M₁) (hM₁ : 0 < M₁) : PassLearner β d M₂ where pred j q y := if hq : q.val < M₁ then L.pred j ⟨q.val, hq⟩ y else L.pred j ⟨0, hM₁⟩ y nonneg j q y := by split_ifs <;> exact L.nonneg j _ y sum_one j q := by split_ifs <;> exact L.sum_one j _ trans j q y := if hq : q.val < M₁ then ⟨(L.trans j ⟨q.val, hq⟩ y).val, lt_of_lt_of_le (L.trans j ⟨q.val, hq⟩ y).isLt hM⟩ else ⟨(L.trans j ⟨0, hM₁⟩ y).val, lt_of_lt_of_le (L.trans j ⟨0, hM₁⟩ y).isLt hM⟩ def liftMultiPassLearner {β : Type*} [Fintype β] {d M₁ M₂ R : ℕ} (hM : M₁ ≤ M₂) (hM₁ : 0 < M₁) (L : MultiPassLearner β d M₁ R) : MultiPassLearner β d M₂ R where init := ⟨L.init.val, lt_of_lt_of_le L.init.isLt hM⟩ pass p := liftPassLearner hM (L.pass p) hM₁ lemma liftPassLearner_runStateAux {β : Type*} [Fintype β] {d M₁ M₂ : ℕ} (hM : M₁ ≤ M₂) (hM₁ : 0 < M₁) (L : PassLearner β d M₁) (q₀ : Fin M₁) (h : Fin d → β) : ∀ (k : ℕ) (hk : k ≤ d), runStateAux (liftPassLearner hM L hM₁) k hk ⟨q₀.val, lt_of_lt_of_le q₀.isLt hM⟩ h = ⟨(runStateAux L k hk q₀ h).val, lt_of_lt_of_le (runStateAux L k hk q₀ h).isLt hM⟩ | 0, _ => rfl | k + 1, hk => by change (liftPassLearner hM L hM₁).trans ⟨k, by omega⟩ (runStateAux (liftPassLearner hM L hM₁) k (by omega) ⟨q₀.val, lt_of_lt_of_le q₀.isLt hM⟩ h) (h ⟨k, by omega⟩) = ⟨(L.trans ⟨k, by omega⟩ (runStateAux L k (by omega) q₀ h) (h ⟨k, by omega⟩)).val, lt_of_lt_of_le (L.trans ⟨k, by omega⟩ (runStateAux L k (by omega) q₀ h) (h ⟨k, by omega⟩)).isLt hM⟩ rw [liftPassLearner_runStateAux hM hM₁ L q₀ h k (by omega)] dsimp only [liftPassLearner] simp only [(runStateAux L k (by omega) q₀ h).isLt, ↓reduceDIte, Fin.eta] lemma liftMultiPassLearner_stateBeforePass {β : Type*} [Fintype β] {d M₁ M₂ R : ℕ} (hM : M₁ ≤ M₂) (hM₁ : 0 < M₁) (L : MultiPassLearner β d M₁ R) (h : Fin d → β) : ∀ (r : ℕ) (hr : r ≤ R), stateBeforePassAux (liftMultiPassLearner hM hM₁ L) r hr h = ⟨(stateBeforePassAux L r hr h).val, lt_of_lt_of_le (stateBeforePassAux L r hr h).isLt hM⟩ | 0, _ => rfl | r + 1, hr => by change runStateAux (liftPassLearner hM (L.pass ⟨r, by omega⟩) hM₁) d le_rfl (stateBeforePassAux (liftMultiPassLearner hM hM₁ L) r (by omega) h) h = ⟨(runStateAux (L.pass ⟨r, by omega⟩) d le_rfl (stateBeforePassAux L r (by omega) h) h).val, lt_of_lt_of_le (runStateAux (L.pass ⟨r, by omega⟩) d le_rfl (stateBeforePassAux L r (by omega) h) h).isLt hM⟩ rw [liftMultiPassLearner_stateBeforePass hM hM₁ L h r (by omega)] exact liftPassLearner_runStateAux hM hM₁ (L.pass ⟨r, by omega⟩) _ h d le_rfl /-- **EXACT BOUNDED-MEMORY LOG-LOSS vs. 0–1 LOSS SEPARATION THEOREM (`t ≥ 3`, EXACT POWER-OF-TWO MEMORY `M = 2^(t+1)`)**: On the `(3 * t)`-dimensional Boolean cube `V = Fin (3 * t) → Bool` (`|V| = 2^(3t)`) with **strict width `M = 2^(t + 1)`** (`t + 1` bits of memory at EVERY step, even mid-pass!): 1. **Log-Loss (Unbeatable Memorization Barrier)**: EVERY width-`2^(t+1)` learner suffers average per-pass log-loss `≥ (2 * t - 1) * Real.log 2` on every pass `r ≥ 1` — ZERO improvement over trivial `(t + 1)`-bit memorization! 2. **0–1 Loss (Strict Rate-Distortion Breakthrough)**: our explicit strict width-`2^(t+1)` block-majority learner achieves average per-pass 0–1 mistakes `= (3 / 4) * t`, STRICTLY beating BOTH `(t + 1)`-bit memorization's `(2 * t - 1) / 2 = t - 1/2` mistakes/pass AND the `(1 / 2) * (log-loss-in-bits)` barrier by `t / 4 - 1/2 > 0` (**25% asymptotic separation**)! -/ theorem memory_logloss_vs_zeroOne_separation {t R : ℕ} (ht : 3 ≤ t) (r : Fin R) (hr0 : r.val ≠ 0) : let V : Finset (Fin (3 * t) → Bool) := Finset.univ let M := 2 ^ (t + 1) -- (1) Every width-M learner pays ≥ (2t - 1) log 2 average log-loss on pass r: (∀ L : MultiPassLearner Bool (3 * t) M R, MultiPassPos L V → ((2 * t - 1 : ℕ) : ℝ) * Real.log 2 ≤ (1 / (V.card : ℝ)) * ∑ h ∈ V, passLogLoss (L.pass r) (stateBeforePass L r h) h) ∧ -- (2) Yet there EXISTS a strict width-M learner achieving (3/4)*t < (2t - 1)/2 average 0–1 mistakes on pass r! (∃ L01 : MultiPassLearner Bool (3 * t) M R, (∀ h ∈ V, passZeroOneErr (L01.pass r) (stateBeforePass L01 r h) h ≤ (t : ℝ)) ∧ (1 / (V.card : ℝ)) * ∑ h ∈ V, passZeroOneErr (L01.pass r) (stateBeforePass L01 r h) h = (3 / 4 : ℝ) * (t : ℝ) ∧ (3 / 4 : ℝ) * (t : ℝ) < ((2 * t - 1 : ℕ) : ℝ) / 2) := by intro V M have hM_pos : 0 < M := Nat.two_pow_pos (t + 1) have hV_card : (V.card : ℝ) = (2 : ℝ) ^ (3 * t) := by dsimp only [V]; rw [Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, Nat.cast_pow, Nat.cast_ofNat] constructor · intro L hpos have hlow := widthM_pass_avg_logLoss_ge hM_pos L Finset.univ_nonempty hpos r have hlogV : Real.log (V.card : ℝ) = ((3 * t : ℕ) : ℝ) * Real.log 2 := by rw [hV_card, Real.log_pow] have hlogM : Real.log (M : ℝ) = ((t + 1 : ℕ) : ℝ) * Real.log 2 := by dsimp only [M]; rw [Nat.cast_pow, Nat.cast_ofNat, Real.log_pow] have hdiff : Real.log (V.card : ℝ) - Real.log (M : ℝ) = ((2 * t - 1 : ℕ) : ℝ) * Real.log 2 := by rw [hlogV, hlogM, Nat.cast_sub (by omega : 1 ≤ 2 * t)] push_cast; ring have hmax := le_max_right (0 : ℝ) (Real.log (V.card : ℝ) - Real.log (M : ℝ)) linarith · have hM_le : 3 * 2 ^ (t - 1) ≤ M := by dsimp only [M] have hexp : t + 1 = (t - 1) + 2 := by omega rw [hexp, pow_add]; norm_num; omega have hM1_pos : 0 < 3 * 2 ^ (t - 1) := by positivity let L01 := liftMultiPassLearner hM_le hM1_pos (blockMaj3Learner t (by omega) R) have herr_lift : ∀ h : Fin (3 * t) → Bool, passZeroOneErr (L01.pass r) (stateBeforePass L01 r h) h = passZeroOneErr ((blockMaj3Learner t (by omega) R).pass r) (stateBeforePass (blockMaj3Learner t (by omega) R) r h) h := by intro h have hst0 : stateBeforePass L01 r h = ⟨(stateBeforePass (blockMaj3Learner t (by omega) R) r h).val, lt_of_lt_of_le (stateBeforePass (blockMaj3Learner t (by omega) R) r h).isLt hM_le⟩ := liftMultiPassLearner_stateBeforePass hM_le hM1_pos (blockMaj3Learner t (by omega) R) h r.val (le_of_lt r.isLt) dsimp only [passZeroOneErr] rw [hst0] change ∑ j : Fin (3 * t), (1 - (liftPassLearner hM_le ((blockMaj3Learner t (by omega) R).pass r) hM1_pos).pred j (runState (liftPassLearner hM_le ((blockMaj3Learner t (by omega) R).pass r) hM1_pos) j ⟨(stateBeforePass (blockMaj3Learner t (by omega) R) r h).val, _⟩ h) (h j)) = _ refine Finset.sum_congr rfl fun j _ => ?_ dsimp only [runState] rw [liftPassLearner_runStateAux hM_le hM1_pos] dsimp only [liftPassLearner] simp only [(runStateAux ((blockMaj3Learner t (by omega) R).pass r) j.val (le_of_lt j.isLt) (stateBeforePass (blockMaj3Learner t (by omega) R) r h) h).isLt, ↓reduceDIte, Fin.eta] have hexact := blockMaj3Learner_pass_zeroOne_exact (t := t) (ht := by omega) r hr0 refine ⟨L01, fun h _ => by rw [herr_lift h]; exact hexact.1 h, ?_, ?_⟩ · rw [Finset.sum_congr rfl fun h _ => herr_lift h, one_div_mul_eq_div, hV_card] exact hexact.2 · rw [Nat.cast_sub (by omega : 1 ≤ 2 * t)] push_cast have ht_r : (3 : ℝ) ≤ (t : ℝ) := by exact_mod_cast ht linarith end OnlineLogLossMemoryMinimax /-! ## Part 7: Machine-Checked `#print axioms` Verification (45 Headline Theorems) -/ #print axioms OnlineLogLossMemoryMinimax.klDiv_nonneg #print axioms OnlineLogLossMemoryMinimax.klDiv_eq_zero_iff #print axioms OnlineLogLossMemoryMinimax.logLoss_selfDual_kl_identity #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_scale #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_add_le #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_ge_weight #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_mono_T #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_le_sum_w #print axioms OnlineLogLossMemoryMinimax.ctxShtarkovUnif_le_card #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_submul_horizon #print axioms OnlineLogLossMemoryMinimax.cNMLForecaster_regret_le #print axioms OnlineLogLossMemoryMinimax.cNMLAdversary_exact_kl_excess #print axioms OnlineLogLossMemoryMinimax.cNMLAdversary_regret_ge #print axioms OnlineLogLossMemoryMinimax.online_logloss_cNML_minimax_exact #print axioms OnlineLogLossMemoryMinimax.ctxShtarkovUnif_block_reset_bound #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_two_experts_eq_one_add_adaptTV #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_two_experts_one_round #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_two_experts_bhatt_sandwich #print axioms OnlineLogLossMemoryMinimax.tvDist_sq_le_two_mul_jsDiv #print axioms OnlineLogLossMemoryMinimax.shtarkov_vs_js_capacity_exact_bounds #print axioms OnlineLogLossMemoryMinimax.shtarkov_vs_js_capacity_unbounded_ratio #print axioms OnlineLogLossMemoryMinimax.ctxShtarkov_detEval_eq_adaptGrowth #print axioms OnlineLogLossMemoryMinimax.sauerPoly_succ_succ #print axioms OnlineLogLossMemoryMinimax.adaptGrowth_le_sauerPoly #print axioms OnlineLogLossMemoryMinimax.hammingBall_achieves_sauer_equality #print axioms OnlineLogLossMemoryMinimax.obliviousGrowth_le_adaptGrowth #print axioms OnlineLogLossMemoryMinimax.obliviousGrowth_threshClass_le #print axioms OnlineLogLossMemoryMinimax.threshClass_adaptive_vs_oblivious_exponential_separation #print axioms OnlineLogLossMemoryMinimax.obliviousGrowth_prod_eq_max #print axioms OnlineLogLossMemoryMinimax.adaptGrowth_prod_ge_mul #print axioms OnlineLogLossMemoryMinimax.adaptGrowth_prod_strict_supermultiplicative #print axioms OnlineLogLossMemoryMinimax.widthM_passProb_sum_eq_one #print axioms OnlineLogLossMemoryMinimax.widthM_single_pass_logLoss_sum_ge #print axioms OnlineLogLossMemoryMinimax.fiber_log_card_sum_ge #print axioms OnlineLogLossMemoryMinimax.widthM_pass_avg_logLoss_ge #print axioms OnlineLogLossMemoryMinimax.widthM_multipass_logLoss_lower #print axioms OnlineLogLossMemoryMinimax.randWidthM_multipass_logLoss_lower #print axioms OnlineLogLossMemoryMinimax.widthM_cube_logLoss_exact_tight #print axioms OnlineLogLossMemoryMinimax.widthM_logLoss_memory_phase_transition #print axioms OnlineLogLossMemoryMinimax.binEnt_monoOn_half #print axioms OnlineLogLossMemoryMinimax.binEnt_concaveOn #print axioms OnlineLogLossMemoryMinimax.single_pass_zeroOne_binEnt_ge #print axioms OnlineLogLossMemoryMinimax.widthM_multipass_zeroOne_rate_distortion_lower #print axioms OnlineLogLossMemoryMinimax.blockMaj3Learner_pass_zeroOne_exact #print axioms OnlineLogLossMemoryMinimax.memory_logloss_vs_zeroOne_separation