import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.Real.Sqrt import Mathlib.Data.Matrix.Mul import Mathlib.Data.ZMod.Basic import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus /-! # Mathematical Theory of Neural Implicit Bias, Double Descent, Grokking, and Depth Separation A completely self-contained, machine-checked Lean 4 formalization of sharp non-asymptotic theorems across four pillars of deep learning theory: 1. **Exact Ridgeless Minimum-Norm Interpolation Risk, Double Descent & Benign Overfitting** 2. **Exact Gradient-Flow Implicit Bias (Max-Margin Rate & Hyperbolic Entropy `q_α` Transition)** 3. **Exact Modular-Addition Fourier Grokking Margin vs. Memorization Capacity Gap** 4. **Sharp ReLU / Barron Depth-Separation Bounds** -/ open scoped BigOperators open Finset namespace NeuralImplicitBiasGrokking /-! ============================================================================ SECTION 1: RIDGELESS MINIMUM-NORM INTERPOLATION, DOUBLE DESCENT & BENIGN OVERFITTING ============================================================================ -/ section Pillar1 /-- Euclidean inner product on `Fin d → ℝ`. -/ def dot {d : ℕ} (u v : Fin d → ℝ) : ℝ := ∑ i : Fin d, u i * v i /-- Squared Euclidean norm on `Fin d → ℝ`. -/ def normSq {d : ℕ} (u : Fin d → ℝ) : ℝ := ∑ i : Fin d, (u i) ^ 2 /-- Euclidean norm `‖u‖₂` on `Fin d → ℝ`. -/ noncomputable def euclidNorm {d : ℕ} (u : Fin d → ℝ) : ℝ := Real.sqrt (normSq u) /-- `ℓ₁` norm on `Fin d → ℝ`. -/ def l1Norm {d : ℕ} (u : Fin d → ℝ) : ℝ := ∑ i : Fin d, |u i| /-- Diagonal `Σ`-weighted squared norm `∑ j, σ_j * u_j^2`. -/ def weightedNormSq {d : ℕ} (w : Fin d → ℝ) (u : Fin d → ℝ) : ℝ := ∑ j : Fin d, w j * (u j) ^ 2 lemma normSq_nonneg {d : ℕ} (u : Fin d → ℝ) : 0 ≤ normSq u := Finset.sum_nonneg fun _ _ => sq_nonneg _ lemma euclidNorm_nonneg {d : ℕ} (u : Fin d → ℝ) : 0 ≤ euclidNorm u := Real.sqrt_nonneg _ lemma euclidNorm_sq {d : ℕ} (u : Fin d → ℝ) : (euclidNorm u) ^ 2 = normSq u := Real.sq_sqrt (normSq_nonneg u) lemma normSq_eq_zero_iff {d : ℕ} (u : Fin d → ℝ) : normSq u = 0 ↔ u = 0 := by constructor · intro h ext i have hi : (u i) ^ 2 = 0 := by have hle : (u i) ^ 2 ≤ normSq u := Finset.single_le_sum (f := fun j => (u j) ^ 2) (fun j _ => sq_nonneg (u j)) (Finset.mem_univ i) linarith [sq_nonneg (u i)] exact sq_eq_zero_iff.mp hi · rintro rfl simp [normSq] lemma dot_comm {d : ℕ} (u v : Fin d → ℝ) : dot u v = dot v u := by simp only [dot, mul_comm] lemma normSq_add {d : ℕ} (u v : Fin d → ℝ) : normSq (u + v) = normSq u + 2 * dot u v + normSq v := by simp only [normSq, dot, Pi.add_apply, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ ring lemma normSq_sub {d : ℕ} (u v : Fin d → ℝ) : normSq (u - v) = normSq u - 2 * dot u v + normSq v := by simp only [normSq, dot, Pi.sub_apply, Finset.mul_sum] rw [← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ ring /-- Cauchy–Schwarz inequality in squared form for `Fin d → ℝ`. -/ lemma dot_sq_le_normSq_mul {d : ℕ} (u v : Fin d → ℝ) : (dot u v) ^ 2 ≤ normSq u * normSq v := by simpa only [dot, normSq] using Finset.sum_mul_sq_le_sq_mul_sq Finset.univ u v /-- Cauchy–Schwarz inequality in norm form: `|⟨u, v⟩| ≤ ‖u‖₂ ‖v‖₂`. -/ lemma abs_dot_le_euclidNorm_mul {d : ℕ} (u v : Fin d → ℝ) : |dot u v| ≤ euclidNorm u * euclidNorm v := by have hsq : |dot u v| ^ 2 ≤ (euclidNorm u * euclidNorm v) ^ 2 := by rw [sq_abs, mul_pow, euclidNorm_sq, euclidNorm_sq] exact dot_sq_le_normSq_mul u v have h1 : 0 ≤ euclidNorm u * euclidNorm v := mul_nonneg (euclidNorm_nonneg u) (euclidNorm_nonneg v) nlinarith [abs_nonneg (dot u v), h1] /-- **Theorem 1.1 (Exact Pythagorean Optimality of Minimum-Norm Interpolators).** -/ theorem min_norm_interpolator_pythagorean {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ) (y : Fin n → ℝ) (v : Fin n → ℝ) (β : Fin p → ℝ) (h_interp_hat : X.mulVec (X.transpose.mulVec v) = y) (h_interp_β : X.mulVec β = y) : normSq β = normSq (X.transpose.mulVec v) + normSq (β - X.transpose.mulVec v) := by set βhat := X.transpose.mulVec v have h_orth : dot βhat (β - βhat) = 0 := by have hdiff : X.mulVec (β - βhat) = 0 := by rw [Matrix.mulVec_sub, h_interp_β, h_interp_hat, sub_self] calc dot βhat (β - βhat) = ∑ j : Fin p, (∑ i : Fin n, X i j * v i) * (β j - βhat j) := by simp [dot, βhat, Matrix.mulVec, dotProduct, Matrix.transpose_apply] _ = ∑ i : Fin n, v i * ∑ j : Fin p, X i j * (β j - βhat j) := by simp_rw [Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun j _ => ?_ ring _ = ∑ i : Fin n, v i * (X.mulVec (β - βhat) i) := by simp [Matrix.mulVec, dotProduct] _ = 0 := by simp [hdiff] have hdecomp : β = βhat + (β - βhat) := by ext j; simp conv_lhs => rw [hdecomp] rw [normSq_add, h_orth] ring /-- **Corollary 1.2 (Unique Global Optimality of Minimum-Norm Interpolator).** -/ theorem min_norm_interpolator_unique {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ) (y : Fin n → ℝ) (v : Fin n → ℝ) (β : Fin p → ℝ) (h_interp_hat : X.mulVec (X.transpose.mulVec v) = y) (h_interp_β : X.mulVec β = y) : normSq (X.transpose.mulVec v) ≤ normSq β ∧ (normSq β = normSq (X.transpose.mulVec v) ↔ β = X.transpose.mulVec v) := by have hpyth := min_norm_interpolator_pythagorean X y v β h_interp_hat h_interp_β constructor · linarith [normSq_nonneg (β - X.transpose.mulVec v)] · constructor · intro heq have h0 : normSq (β - X.transpose.mulVec v) = 0 := by linarith have hsub := (normSq_eq_zero_iff _).mp h0 ext j have := congr_fun hsub j simpa [sub_eq_zero] using this · rintro rfl; rfl /-- Rademacher sign vector `s : Fin n → Bool` mapped to `{+1, -1}^n`. -/ def radSign (b : Bool) : ℝ := if b then 1 else -1 lemma radSign_sq (b : Bool) : (radSign b) ^ 2 = 1 := by cases b <;> norm_num [radSign] lemma sum_radSign_single {n : ℕ} (i : Fin n) : ∑ s : Fin n → Bool, radSign (s i) = 0 := by let flip : (Fin n → Bool) ≃ (Fin n → Bool) := { toFun := fun s => Function.update s i !(s i) invFun := fun s => Function.update s i !(s i) left_inv := fun s => by ext j; by_cases hj : j = i <;> simp [hj] right_inv := fun s => by ext j; by_cases hj : j = i <;> simp [hj] } have h1 : ∑ s : Fin n → Bool, radSign (s i) = ∑ s : Fin n → Bool, radSign (flip s i) := (Equiv.sum_comp flip (fun s => radSign (s i))).symm have h2 : ∀ s : Fin n → Bool, radSign (flip s i) = -radSign (s i) := by intro s simp only [flip, Equiv.coe_fn_mk, Function.update_self] cases s i <;> norm_num [radSign] simp_rw [h2, Finset.sum_neg_distrib] at h1 linarith lemma sum_radSign_pair {n : ℕ} {i k : Fin n} (hik : i ≠ k) : ∑ s : Fin n → Bool, radSign (s i) * radSign (s k) = 0 := by let flip : (Fin n → Bool) ≃ (Fin n → Bool) := { toFun := fun s => Function.update s i !(s i) invFun := fun s => Function.update s i !(s i) left_inv := fun s => by ext j; by_cases hj : j = i <;> simp [hj] right_inv := fun s => by ext j; by_cases hj : j = i <;> simp [hj] } have h1 : ∑ s : Fin n → Bool, radSign (s i) * radSign (s k) = ∑ s : Fin n → Bool, radSign (flip s i) * radSign (flip s k) := (Equiv.sum_comp flip (fun s => radSign (s i) * radSign (s k))).symm have h2 : ∀ s : Fin n → Bool, radSign (flip s i) * radSign (flip s k) = -(radSign (s i) * radSign (s k)) := by intro s simp only [flip, Equiv.coe_fn_mk, Function.update_self, Function.update_of_ne hik.symm] cases s i <;> cases s k <;> norm_num [radSign] simp_rw [h2, Finset.sum_neg_distrib] at h1 linarith /-- **Theorem 1.3 (Exact Finite-Sample Orthogonal Bias–Variance Decomposition).** -/ theorem ridgeless_bias_variance_exact {n p : ℕ} (w : Fin p → ℝ) (P : Matrix (Fin p) (Fin p) ℝ) (M : Matrix (Fin p) (Fin n) ℝ) (βstar : Fin p → ℝ) (σ : ℝ) : (1 / (2 : ℝ) ^ n) * ∑ s : Fin n → Bool, weightedNormSq w (P.mulVec βstar + M.mulVec (fun i => σ * radSign (s i)) - βstar) = weightedNormSq w (P.mulVec βstar - βstar) + σ ^ 2 * ∑ j : Fin p, w j * ∑ i : Fin n, (M j i) ^ 2 := by have hcard : (Fintype.card (Fin n → Bool) : ℝ) = (2 : ℝ) ^ n := by simp [Fintype.card_bool] have h2ne : (2 : ℝ) ^ n ≠ 0 := by positivity set b : Fin p → ℝ := P.mulVec βstar - βstar have hexpand : ∀ s : Fin n → Bool, weightedNormSq w (P.mulVec βstar + M.mulVec (fun i => σ * radSign (s i)) - βstar) = weightedNormSq w b + 2 * σ * ∑ i : Fin n, (∑ j : Fin p, w j * b j * M j i) * radSign (s i) + σ ^ 2 * ∑ i : Fin n, ∑ k : Fin n, (∑ j : Fin p, w j * M j i * M j k) * (radSign (s i) * radSign (s k)) := by intro s simp only [weightedNormSq, b, Pi.sub_apply, Pi.add_apply, Matrix.mulVec, dotProduct] have hpt : ∀ j : Fin p, w j * (∑ x, P j x * βstar x + ∑ i, M j i * (σ * radSign (s i)) - βstar j) ^ 2 = w j * (∑ x, P j x * βstar x - βstar j) ^ 2 + 2 * σ * ∑ i : Fin n, (w j * (∑ x, P j x * βstar x - βstar j) * M j i) * radSign (s i) + σ ^ 2 * ∑ i : Fin n, ∑ k : Fin n, (w j * M j i * M j k) * (radSign (s i) * radSign (s k)) := by intro j set bj := ∑ x, P j x * βstar x - βstar j have hsq : (∑ x, P j x * βstar x + ∑ i, M j i * (σ * radSign (s i)) - βstar j) ^ 2 = bj ^ 2 + 2 * bj * ∑ i, M j i * (σ * radSign (s i)) + (∑ i, M j i * (σ * radSign (s i))) ^ 2 := by have : ∑ x, P j x * βstar x + ∑ i, M j i * (σ * radSign (s i)) - βstar j = bj + ∑ i, M j i * (σ * radSign (s i)) := by simp [bj]; ring rw [this]; ring rw [hsq] have hterm2 : w j * (2 * bj * ∑ i, M j i * (σ * radSign (s i))) = 2 * σ * ∑ i : Fin n, (w j * bj * M j i) * radSign (s i) := by rw [← mul_assoc, Finset.mul_sum, Finset.mul_sum] refine Finset.sum_congr rfl fun i _ => ?_; ring have hterm3 : w j * (∑ i, M j i * (σ * radSign (s i))) ^ 2 = σ ^ 2 * ∑ i : Fin n, ∑ k : Fin n, (w j * M j i * M j k) * (radSign (s i) * radSign (s k)) := by rw [sq, Finset.sum_mul, Finset.mul_sum, Finset.mul_sum] refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] refine Finset.sum_congr rfl fun k _ => ?_; ring linarith simp_rw [hpt] rw [Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum] congr 1 · congr 1 rw [Finset.sum_comm] refine congrArg (2 * σ * ·) (Finset.sum_congr rfl fun i _ => ?_) rw [Finset.sum_mul] · rw [Finset.sum_comm] refine congrArg (σ ^ 2 * ·) (Finset.sum_congr rfl fun i _ => ?_) rw [Finset.sum_comm] refine Finset.sum_congr rfl fun k _ => ?_ rw [Finset.sum_mul] simp_rw [hexpand, Finset.sum_add_distrib] have h1 : ∑ _s : Fin n → Bool, weightedNormSq w b = (2 : ℝ) ^ n * weightedNormSq w b := by rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, hcard] have h2 : ∑ s : Fin n → Bool, 2 * σ * ∑ i : Fin n, (∑ j : Fin p, w j * b j * M j i) * radSign (s i) = 0 := by rw [← Finset.mul_sum, Finset.sum_comm] have : ∀ i : Fin n, ∑ s : Fin n → Bool, (∑ j : Fin p, w j * b j * M j i) * radSign (s i) = 0 := by intro i rw [← Finset.mul_sum, sum_radSign_single i, mul_zero] simp [this] have h3 : ∑ s : Fin n → Bool, σ ^ 2 * ∑ i : Fin n, ∑ k : Fin n, (∑ j : Fin p, w j * M j i * M j k) * (radSign (s i) * radSign (s k)) = (2 : ℝ) ^ n * (σ ^ 2 * ∑ j : Fin p, w j * ∑ i : Fin n, (M j i) ^ 2) := by rw [← Finset.mul_sum, Finset.sum_comm] have hinner : ∀ i : Fin n, ∑ s : Fin n → Bool, ∑ k : Fin n, (∑ j : Fin p, w j * M j i * M j k) * (radSign (s i) * radSign (s k)) = (2 : ℝ) ^ n * ∑ j : Fin p, w j * (M j i) ^ 2 := by intro i rw [Finset.sum_comm] have hterm : ∀ k : Fin n, ∑ s : Fin n → Bool, (∑ j : Fin p, w j * M j i * M j k) * (radSign (s i) * radSign (s k)) = if k = i then (2 : ℝ) ^ n * ∑ j : Fin p, w j * (M j i) ^ 2 else 0 := by intro k by_cases hki : k = i · subst hki simp only [↓reduceIte, ← sq, radSign_sq, mul_one, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, hcard] congr 1 refine Finset.sum_congr rfl fun j _ => ?_; ring · simp only [hki, ↓reduceIte, ← Finset.mul_sum, sum_radSign_pair (Ne.symm hki), mul_zero] simp [hterm] simp_rw [hinner, ← Finset.mul_sum] have hswap : ∑ i : Fin n, ∑ j : Fin p, w j * (M j i) ^ 2 = ∑ j : Fin p, w j * ∑ i : Fin n, (M j i) ^ 2 := by rw [Finset.sum_comm] refine Finset.sum_congr rfl fun j _ => ?_ rw [Finset.mul_sum] rw [hswap]; ring rw [h1, h2, h3] field_simp [h2ne] ring /-- Exact finite-sample overparameterized isotropic ridgeless risk `R_over(n, p; S, σ)`. -/ noncomputable def isotropicOverRisk (n p S σ : ℝ) : ℝ := S * (1 - n / p) + σ ^ 2 * n / (p - n - 1) /-- Exact finite-sample underparameterized isotropic OLS variance risk `σ² p / (n - p - 1)`. -/ noncomputable def isotropicUnderRisk (n p σ : ℝ) : ℝ := σ ^ 2 * p / (n - p - 1) /-- **Theorem 1.4 (Exact Sum-of-Squares Double-Descent Identity).** -/ theorem isotropic_double_descent_exact_sos {n p S : ℝ} (σ : ℝ) (hn : 0 < n) (hp : n + 1 < p) (hS : 0 ≤ S) : isotropicOverRisk n p S σ - (S - (n / (n + 1)) * (Real.sqrt S - σ) ^ 2) = (n / (n + 1)) * (Real.sqrt S * (p - n - 1) - σ * p) ^ 2 / (p * (p - n - 1)) := by have hp0 : p ≠ 0 := by linarith have hpn : p - n - 1 ≠ 0 := by linarith have hn1 : n + 1 ≠ 0 := by linarith set s := Real.sqrt S have hS_eq : S = s ^ 2 := (Real.sq_sqrt hS).symm unfold isotropicOverRisk rw [hS_eq] field_simp [hp0, hpn, hn1] ring /-- **Theorem 1.5 (Sharp Global Minimum of Overparameterized Double-Descent Risk).** -/ theorem isotropic_double_descent_exact_minimum {n S σ : ℝ} (hn : 0 < n) (hS : 0 ≤ S) (hσ : 0 < σ) : (∀ p : ℝ, n + 1 < p → S - (n / (n + 1)) * (Real.sqrt S - σ) ^ 2 ≤ isotropicOverRisk n p S σ) ∧ (σ < Real.sqrt S → let pStar := (n + 1) * Real.sqrt S / (Real.sqrt S - σ) n + 1 < pStar ∧ isotropicOverRisk n pStar S σ = S - (n / (n + 1)) * (Real.sqrt S - σ) ^ 2) := by constructor · intro p hp have hdiff := isotropic_double_descent_exact_sos σ hn hp hS have hrhs : 0 ≤ (n / (n + 1)) * (Real.sqrt S * (p - n - 1) - σ * p) ^ 2 / (p * (p - n - 1)) := by have hp0 : 0 < p := by linarith have hpn : 0 < p - n - 1 := by linarith positivity linarith · intro hSNR dsimp only set pStar := (n + 1) * Real.sqrt S / (Real.sqrt S - σ) have hden : 0 < Real.sqrt S - σ := by linarith have hpStar : n + 1 < pStar := by rw [lt_div_iff₀ hden] nlinarith refine ⟨hpStar, ?_⟩ have hdiff := isotropic_double_descent_exact_sos σ hn hpStar hS have hzero : Real.sqrt S * (pStar - n - 1) - σ * pStar = 0 := by simp only [pStar] field_simp [ne_of_gt hden] ring rw [hzero] at hdiff simp only [ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_zero, zero_div] at hdiff linarith /-- **Theorem 1.6 (Exact Discrete Double-Descent Phase Transition).** -/ theorem isotropic_double_descent_phase_transition {n S σ : ℝ} (hn : 0 < n) (hσ : 0 < σ) : (∀ p : ℝ, n + 1 < p → isotropicOverRisk n (p + 1) S σ - isotropicOverRisk n p S σ = S * n / (p * (p + 1)) - σ ^ 2 * n / ((p - n - 1) * (p - n))) ∧ (S ≤ σ ^ 2 → ∀ p : ℝ, n + 1 < p → isotropicOverRisk n (p + 1) S σ < isotropicOverRisk n p S σ) ∧ (∀ p₁ p₂ : ℝ, 0 ≤ p₁ → p₁ < p₂ → p₂ < n - 1 → isotropicUnderRisk n p₁ σ < isotropicUnderRisk n p₂ σ) := by refine ⟨?_, ?_, ?_⟩ · intro p hp have hp0 : p ≠ 0 := by linarith have hp1 : p + 1 ≠ 0 := by linarith have hpn1 : p - n - 1 ≠ 0 := by linarith have hpn : p - n ≠ 0 := by linarith unfold isotropicOverRisk have hsub : p + 1 - n - 1 = p - n := by ring rw [hsub] field_simp [hp0, hp1, hpn1, hpn] ring · intro hS p hp have hstep : isotropicOverRisk n (p + 1) S σ - isotropicOverRisk n p S σ = S * n / (p * (p + 1)) - σ ^ 2 * n / ((p - n - 1) * (p - n)) := by have hp0 : p ≠ 0 := by linarith have hp1 : p + 1 ≠ 0 := by linarith have hpn1 : p - n - 1 ≠ 0 := by linarith have hpn : p - n ≠ 0 := by linarith unfold isotropicOverRisk have hsub : p + 1 - n - 1 = p - n := by ring rw [hsub] field_simp [hp0, hp1, hpn1, hpn] ring have hd1 : 0 < (p - n - 1) * (p - n) := by nlinarith have hd2 : (p - n - 1) * (p - n) < p * (p + 1) := by nlinarith have hlt1 : S * n / (p * (p + 1)) ≤ σ ^ 2 * n / (p * (p + 1)) := div_le_div_of_nonneg_right (by nlinarith) (by nlinarith) have hlt2 : σ ^ 2 * n / (p * (p + 1)) < σ ^ 2 * n / ((p - n - 1) * (p - n)) := div_lt_div_of_pos_left (by positivity) hd1 hd2 linarith · intro p₁ p₂ _hp₁ h12 h2n unfold isotropicUnderRisk have hd1 : 0 < n - p₁ - 1 := by linarith have hd2 : 0 < n - p₂ - 1 := by linarith rw [div_lt_div_iff₀ hd1 hd2] have hσ2 : 0 < σ ^ 2 := sq_pos_of_pos hσ have hdiff : (n - 1) * (p₂ - p₁) > 0 := by nlinarith nlinarith /-- Helper: summing a function supported on `j.val < k` over `Fin n` equals summing over `Fin k`. -/ lemma sum_fin_lt_eq {n k : ℕ} (hk : k ≤ n) (g : Fin k → ℝ) : ∑ j : Fin n, (if hj : (j : ℕ) < k then g ⟨j.val, hj⟩ else 0) = ∑ r : Fin k, g r := by let S : Finset (Fin n) := Finset.univ.filter (fun j : Fin n => (j : ℕ) < k) have h1 : ∑ j : Fin n, (if hj : (j : ℕ) < k then g ⟨j.val, hj⟩ else 0) = ∑ j ∈ S, (if hj : (j : ℕ) < k then g ⟨j.val, hj⟩ else 0) := by symm refine Finset.sum_subset (Finset.subset_univ S) fun j _ hjS => ?_ have hnot : ¬ (j : ℕ) < k := by simpa [S] using hjS simp [hnot] rw [h1] symm refine Finset.sum_nbij (fun r : Fin k => (⟨r.val, Nat.lt_of_lt_of_le r.isLt hk⟩ : Fin n)) ?_ ?_ ?_ ?_ · intro r _; simp [S, r.isLt] · intro r₁ _ r₂ _ h; exact Fin.ext (by simpa using h) · intro j hj have hjk : (j : ℕ) < k := (Finset.mem_filter.mp hj).2 exact ⟨⟨j.val, hjk⟩, Finset.mem_univ _, Fin.ext rfl⟩ · intro r _; simp [r.isLt] /-- Helper: count of `j : Fin n` with `j.val < k` is `k` when `k ≤ n`. -/ lemma card_fin_lt_eq {n k : ℕ} (hk : k ≤ n) : (∑ j : Fin n, if (j : ℕ) < k then (1 : ℝ) else 0) = (k : ℝ) := by have := sum_fin_lt_eq hk (fun _ : Fin k => (1 : ℝ)) simpa using this /-- Explicit finite-dimensional Parseval-frame spiked-covariance design matrix `X = [X₁ | X₂] ∈ ℝ^{n × (k + m·n)}`. -/ noncomputable def parsevalDesign (n k m : ℕ) (lam1 lam2 : ℝ) : Matrix (Fin n) (Fin k ⊕ (Fin m × Fin n)) ℝ := fun i col => match col with | Sum.inl r => if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0 | Sum.inr (_, q) => if i = q then Real.sqrt ((n : ℝ) * lam2) else 0 /-- Spiked diagonal covariance weights `Σ = diag(lam1 · 1_k, lam2 · 1_{m·n})`. -/ def spikedCov (k m n : ℕ) (lam1 lam2 : ℝ) : Fin k ⊕ (Fin m × Fin n) → ℝ := fun col => match col with | Sum.inl _ => lam1 | Sum.inr _ => lam2 /-- Exact Gram-inverse diagonal entries `((X Xᵀ)⁻¹)_{ii}` for the Parseval-frame witness. -/ noncomputable def parsevalGramInvDiag (n k m : ℕ) (lam1 lam2 : ℝ) (i : Fin n) : ℝ := if (i : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 1 / ((m * n : ℝ) * lam2) /-- Explicit Moore–Penrose right-inverse `M = Xᵀ (X Xᵀ)⁻¹` for the Parseval-frame witness. -/ noncomputable def parsevalPinv (n k m : ℕ) (lam1 lam2 : ℝ) : Matrix (Fin k ⊕ (Fin m × Fin n)) (Fin n) ℝ := fun col i => parsevalDesign n k m lam1 lam2 i col * parsevalGramInvDiag n k m lam1 lam2 i /-- **Theorem 1.7 (Exact Interpolation & Row-Space Optimality of Parseval-Frame Witness).** -/ theorem parseval_exact_interpolation {n k m : ℕ} {lam1 lam2 : ℝ} (hk : k < n) (hm : 1 ≤ m) (hlam1 : 0 < lam1) (hlam2 : 0 < lam2) : parsevalDesign n k m lam1 lam2 * parsevalPinv n k m lam1 lam2 = 1 := by have hn : 0 < (n : ℝ) := by exact_mod_cast (show 0 < n by omega) have hmR : 0 < (m : ℝ) := by exact_mod_cast (show 0 < m by omega) have hα : 0 < (n : ℝ) * lam1 := by positivity have hμ : 0 < (m * n : ℝ) * lam2 := by positivity ext i j simp only [Matrix.mul_apply, Matrix.one_apply, Fintype.sum_sum_type, Fintype.sum_prod_type] by_cases hij : i = j · subst hij simp only [↓reduceIte, parsevalDesign, parsevalPinv, parsevalGramInvDiag] have hsq1 : Real.sqrt ((n : ℝ) * lam1) * Real.sqrt ((n : ℝ) * lam1) = (n : ℝ) * lam1 := Real.mul_self_sqrt (le_of_lt hα) have hsq2 : Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam2) = (n : ℝ) * lam2 := Real.mul_self_sqrt (le_of_lt (by positivity)) have hsum_inr : ∑ x : Fin m, ∑ y : Fin n, (if i = y then Real.sqrt ((n : ℝ) * lam2) else 0) * ((if i = y then Real.sqrt ((n : ℝ) * lam2) else 0) * (if (i : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 1 / ((m * n : ℝ) * lam2))) = (m * n : ℝ) * lam2 * (if (i : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 1 / ((m * n : ℝ) * lam2)) := by have hinner_y : ∑ y : Fin n, (if i = y then Real.sqrt ((n : ℝ) * lam2) else 0) * ((if i = y then Real.sqrt ((n : ℝ) * lam2) else 0) * (if (i : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 1 / ((m * n : ℝ) * lam2))) = (n : ℝ) * lam2 * (if (i : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 1 / ((m * n : ℝ) * lam2)) := by rw [Finset.sum_eq_single i] · simp only [↓reduceIte, ← mul_assoc, hsq2] · intro y _ hy; rw [if_neg hy.symm]; ring · intro h; exact absurd (Finset.mem_univ _) h simp_rw [hinner_y, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] ring rw [hsum_inr] by_cases hik : (i : ℕ) < k · simp only [hik, ↓reduceIte] have hsum_inl : ∑ r : Fin k, (if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * ((if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2))) = (n : ℝ) * lam1 * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) := by rw [Finset.sum_eq_single ⟨i.val, hik⟩] · simp only [↓reduceIte, ← mul_assoc, hsq1] · intro r _ hr have hne : (i : ℕ) ≠ (r : ℕ) := fun heq => hr (Fin.ext heq.symm) simp [hne] · intro h; exact absurd (Finset.mem_univ _) h rw [hsum_inl] have hden : (n : ℝ) * lam1 + (m * n : ℝ) * lam2 ≠ 0 := by linarith field_simp [hden] · simp only [hik, ↓reduceIte] have hsum_inl : ∑ r : Fin k, (if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * ((if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * (1 / ((m * n : ℝ) * lam2))) = 0 := by refine Finset.sum_eq_zero fun r _ => ?_ have hne : (i : ℕ) ≠ (r : ℕ) := by omega simp [hne] rw [hsum_inl, zero_add] have hden : (m * n : ℝ) * lam2 ≠ 0 := ne_of_gt hμ field_simp [hden] · simp only [hij, ↓reduceIte, parsevalDesign, parsevalPinv] have h1 : ∑ r : Fin k, (if (i : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * ((if (j : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam1) else 0) * parsevalGramInvDiag n k m lam1 lam2 j) = 0 := by refine Finset.sum_eq_zero fun r _ => ?_ by_cases hi : (i : ℕ) = (r : ℕ) · have hj : (j : ℕ) ≠ (r : ℕ) := fun h => hij (Fin.ext (hi.trans h.symm)) simp [hi, hj] · simp [hi] have h2 : ∑ x : Fin m, ∑ y : Fin n, (if i = y then Real.sqrt ((n : ℝ) * lam2) else 0) * ((if j = y then Real.sqrt ((n : ℝ) * lam2) else 0) * parsevalGramInvDiag n k m lam1 lam2 j) = 0 := by refine Finset.sum_eq_zero fun _ _ => Finset.sum_eq_zero fun y _ => ?_ by_cases hi : i = y · have hj : j ≠ y := fun h => hij (hi.trans h.symm) simp [hi, hj] · simp [hi] rw [h1, h2, add_zero] /-- **Theorem 1.8 (Exact Non-Asymptotic Benign-Overfitting Risk Formula — Zero Hidden Constants).** -/ theorem benign_overfitting_exact_risk {n k m : ℕ} {lam1 lam2 σ : ℝ} (hk : k < n) (hm : 1 ≤ m) (hlam1 : 0 < lam1) (hlam2 : 0 < lam2) (β_sig : Fin k → ℝ) : let X := parsevalDesign n k m lam1 lam2 let M := parsevalPinv n k m lam1 lam2 let Sw := spikedCov k m n lam1 lam2 let βstar : Fin k ⊕ (Fin m × Fin n) → ℝ := fun c => match c with | Sum.inl r => β_sig r | Sum.inr _ => 0 let S := normSq β_sig let ρ := ((m : ℝ) * lam2) / lam1 (∑ c, Sw c * ((M * X).mulVec βstar c - βstar c) ^ 2 = lam1 * S * (ρ ^ 2 * (1 + 1 / (m : ℝ))) / (1 + ρ) ^ 2) ∧ (σ ^ 2 * ∑ c, Sw c * ∑ i : Fin n, (M c i) ^ 2 = σ ^ 2 * (((k : ℝ) / (n : ℝ)) * (1 + ρ ^ 2 / (m : ℝ)) / (1 + ρ) ^ 2 + ((n : ℝ) - (k : ℝ)) / ((m : ℝ) * (n : ℝ)))) := by have hn : 0 < (n : ℝ) := by exact_mod_cast (show 0 < n by omega) have hmR : 0 < (m : ℝ) := by exact_mod_cast (show 0 < m by omega) have hα : 0 < (n : ℝ) * lam1 := by positivity have hμ : 0 < (m * n : ℝ) * lam2 := by positivity have hαμ : 0 < (n : ℝ) * lam1 + (m * n : ℝ) * lam2 := by linarith have hsq1 : Real.sqrt ((n : ℝ) * lam1) ^ 2 = (n : ℝ) * lam1 := Real.sq_sqrt (le_of_lt hα) have hsq2 : Real.sqrt ((n : ℝ) * lam2) ^ 2 = (n : ℝ) * lam2 := Real.sq_sqrt (le_of_lt (by positivity)) dsimp only set ρ := ((m : ℝ) * lam2) / lam1 have hden : (n : ℝ) * lam1 + (m * n : ℝ) * lam2 ≠ 0 := ne_of_gt hαμ constructor · -- Part 1: Exact Bias^2 rw [Fintype.sum_sum_type, Fintype.sum_prod_type] have hinl : ∀ r : Fin k, (parsevalPinv n k m lam1 lam2 * parsevalDesign n k m lam1 lam2).mulVec (fun c => match c with | Sum.inl r => β_sig r | Sum.inr _ => 0) (Sum.inl r) - β_sig r = -((m * n : ℝ) * lam2 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) * β_sig r := by intro r have hrn : (r : ℕ) < n := Nat.lt_trans r.isLt hk simp only [Matrix.mulVec, dotProduct, Matrix.mul_apply, Fintype.sum_sum_type, mul_zero, Finset.sum_const_zero, add_zero] have hterm : ∀ r' : Fin k, (∑ i : Fin n, parsevalPinv n k m lam1 lam2 (Sum.inl r) i * parsevalDesign n k m lam1 lam2 i (Sum.inl r')) * β_sig r' = if r' = r then ((n : ℝ) * lam1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) * β_sig r else 0 := by intro r' by_cases hrr' : r' = r · subst hrr' simp only [↓reduceIte, parsevalPinv, parsevalDesign, parsevalGramInvDiag] rw [Finset.sum_eq_single ⟨r'.val, hrn⟩] · simp only [r'.isLt, ↓reduceIte] have hmul : Real.sqrt ((n : ℝ) * lam1) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) * Real.sqrt ((n : ℝ) * lam1) = (n : ℝ) * lam1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) := by have hprod : Real.sqrt ((n : ℝ) * lam1) * Real.sqrt ((n : ℝ) * lam1) = (n : ℝ) * lam1 := by rw [← sq, hsq1] calc Real.sqrt ((n : ℝ) * lam1) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) * Real.sqrt ((n : ℝ) * lam1) = (Real.sqrt ((n : ℝ) * lam1) * Real.sqrt ((n : ℝ) * lam1)) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2)) := by ring _ = (n : ℝ) * lam1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) := by rw [hprod]; ring rw [hmul] · intro i _ hi have hne : (i : ℕ) ≠ (r' : ℕ) := fun heq => hi (Fin.ext heq) simp [hne] · intro h; exact absurd (Finset.mem_univ _) h · simp only [hrr', ↓reduceIte] have h0 : ∑ i : Fin n, parsevalPinv n k m lam1 lam2 (Sum.inl r) i * parsevalDesign n k m lam1 lam2 i (Sum.inl r') = 0 := by refine Finset.sum_eq_zero fun i _ => ?_ simp only [parsevalPinv, parsevalDesign] by_cases hir : (i : ℕ) = (r : ℕ) · have hir' : (i : ℕ) ≠ (r' : ℕ) := fun h => hrr' (Fin.ext (h.symm.trans hir)) rw [if_pos hir, if_neg hir']; ring · rw [if_neg hir]; ring rw [h0, zero_mul] simp_rw [hterm] rw [Finset.sum_ite_eq'] simp only [Finset.mem_univ, ↓reduceIte] field_simp [hden]; ring have hinr : ∀ (q : Fin m) (j : Fin n), (parsevalPinv n k m lam1 lam2 * parsevalDesign n k m lam1 lam2).mulVec (fun c => match c with | Sum.inl r => β_sig r | Sum.inr _ => 0) (Sum.inr (q, j)) - 0 = if hj : (j : ℕ) < k then Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) * β_sig ⟨j.val, hj⟩ else 0 := by intro q j rw [sub_zero] simp only [Matrix.mulVec, dotProduct, Matrix.mul_apply, Fintype.sum_sum_type, mul_zero, Finset.sum_const_zero, add_zero] have hinner : ∀ r : Fin k, ∑ i : Fin n, parsevalPinv n k m lam1 lam2 (Sum.inr (q, j)) i * parsevalDesign n k m lam1 lam2 i (Sum.inl r) = if (j : ℕ) = (r : ℕ) then Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) else 0 := by intro r simp only [parsevalPinv, parsevalDesign, parsevalGramInvDiag] rw [Finset.sum_eq_single j] · by_cases hjr : (j : ℕ) = (r : ℕ) · simp only [↓reduceIte, hjr, r.isLt]; ring · simp [hjr] · intro i _ hij; simp [hij] · intro h; exact absurd (Finset.mem_univ _) h simp_rw [hinner] by_cases hjk : (j : ℕ) < k · simp only [hjk, ↓reduceDIte] rw [Finset.sum_eq_single ⟨j.val, hjk⟩] · simp · intro r _ hr have hne : (j : ℕ) ≠ (r : ℕ) := fun heq => hr (Fin.ext heq.symm) simp [hne] · intro h; exact absurd (Finset.mem_univ _) h · simp only [hjk, ↓reduceDIte] refine Finset.sum_eq_zero fun r _ => ?_ have hne : (j : ℕ) ≠ (r : ℕ) := by omega simp [hne] have hsum1 : ∑ r : Fin k, spikedCov k m n lam1 lam2 (Sum.inl r) * ((parsevalPinv n k m lam1 lam2 * parsevalDesign n k m lam1 lam2).mulVec (fun c => match c with | Sum.inl r => β_sig r | Sum.inr _ => 0) (Sum.inl r) - β_sig r) ^ 2 = lam1 * (((m * n : ℝ) * lam2) ^ 2 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * normSq β_sig := by simp_rw [spikedCov, hinl, normSq, Finset.mul_sum] refine Finset.sum_congr rfl fun r _ => ?_; field_simp [hden] have hsum2 : ∑ q : Fin m, ∑ j : Fin n, spikedCov k m n lam1 lam2 (Sum.inr (q, j)) * ((parsevalPinv n k m lam1 lam2 * parsevalDesign n k m lam1 lam2).mulVec (fun c => match c with | Sum.inl r => β_sig r | Sum.inr _ => 0) (Sum.inr (q, j)) - 0) ^ 2 = (m : ℝ) * lam2 * ((n : ℝ) * lam2 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * normSq β_sig := by simp_rw [spikedCov, hinr] have hinner_j : ∑ j : Fin n, lam2 * (if hj : (j : ℕ) < k then Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) * β_sig ⟨j.val, hj⟩ else 0) ^ 2 = lam2 * ((n : ℝ) * lam2 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * normSq β_sig := by have hrew : ∀ j : Fin n, lam2 * (if hj : (j : ℕ) < k then Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) * β_sig ⟨j.val, hj⟩ else 0) ^ 2 = if hj : (j : ℕ) < k then lam2 * ((n : ℝ) * lam2 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * (β_sig ⟨j.val, hj⟩) ^ 2 else 0 := by intro j by_cases hj : (j : ℕ) < k · simp only [hj, ↓reduceDIte] calc lam2 * (Real.sqrt ((n : ℝ) * lam2) * Real.sqrt ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) * β_sig ⟨j.val, hj⟩) ^ 2 = lam2 * (Real.sqrt ((n : ℝ) * lam2) ^ 2 * Real.sqrt ((n : ℝ) * lam1) ^ 2 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * (β_sig ⟨j.val, hj⟩) ^ 2 := by field_simp [hden] _ = _ := by rw [hsq1, hsq2] · simp [hj] simp_rw [hrew] rw [sum_fin_lt_eq (le_of_lt hk) (fun r => lam2 * ((n : ℝ) * lam2 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) * (β_sig r) ^ 2), ← Finset.mul_sum, normSq] simp_rw [hinner_j, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] ring rw [hsum1, hsum2] simp only [ρ] field_simp [ne_of_gt hlam1, ne_of_gt hmR, ne_of_gt hn, hden] · -- Part 2: Exact Variance congr 1 rw [Fintype.sum_sum_type, Fintype.sum_prod_type] have hv1 : ∑ r : Fin k, spikedCov k m n lam1 lam2 (Sum.inl r) * ∑ i : Fin n, (parsevalPinv n k m lam1 lam2 (Sum.inl r) i) ^ 2 = (k : ℝ) * lam1 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 := by have hpt : ∀ r : Fin k, spikedCov k m n lam1 lam2 (Sum.inl r) * ∑ i : Fin n, (parsevalPinv n k m lam1 lam2 (Sum.inl r) i) ^ 2 = lam1 * ((n : ℝ) * lam1) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 := by intro r have hrn : (r : ℕ) < n := Nat.lt_trans r.isLt hk simp only [spikedCov, parsevalPinv, parsevalDesign, parsevalGramInvDiag] rw [Finset.sum_eq_single ⟨r.val, hrn⟩] · simp only [r.isLt, ↓reduceIte] calc lam1 * (Real.sqrt ((n : ℝ) * lam1) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2))) ^ 2 = lam1 * (Real.sqrt ((n : ℝ) * lam1) ^ 2) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 := by field_simp [hden] _ = _ := by rw [hsq1] · intro i _ hi have hne : (i : ℕ) ≠ (r : ℕ) := fun heq => hi (Fin.ext heq) simp [hne] · intro h; exact absurd (Finset.mem_univ _) h simp_rw [hpt, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] ring have hv2 : ∑ q : Fin m, ∑ j : Fin n, spikedCov k m n lam1 lam2 (Sum.inr (q, j)) * ∑ i : Fin n, (parsevalPinv n k m lam1 lam2 (Sum.inr (q, j)) i) ^ 2 = (m : ℝ) * lam2 * ((n : ℝ) * lam2) * ((k : ℝ) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 + ((n : ℝ) - (k : ℝ)) / ((m * n : ℝ) * lam2) ^ 2) := by have hinner : ∀ _q : Fin m, ∑ j : Fin n, spikedCov k m n lam1 lam2 (Sum.inr (_q, j)) * ∑ i : Fin n, (parsevalPinv n k m lam1 lam2 (Sum.inr (_q, j)) i) ^ 2 = lam2 * ((n : ℝ) * lam2) * ((k : ℝ) / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 + ((n : ℝ) - (k : ℝ)) / ((m * n : ℝ) * lam2) ^ 2) := by intro q have hpt : ∀ j : Fin n, spikedCov k m n lam1 lam2 (Sum.inr (q, j)) * ∑ i : Fin n, (parsevalPinv n k m lam1 lam2 (Sum.inr (q, j)) i) ^ 2 = lam2 * ((n : ℝ) * lam2) * (if (j : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 else 1 / ((m * n : ℝ) * lam2) ^ 2) := by intro j simp only [spikedCov, parsevalPinv, parsevalDesign, parsevalGramInvDiag] rw [Finset.sum_eq_single j] · simp only [↓reduceIte] by_cases hj : (j : ℕ) < k · simp only [hj, ↓reduceIte] calc lam2 * (Real.sqrt ((n : ℝ) * lam2) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2))) ^ 2 = lam2 * (Real.sqrt ((n : ℝ) * lam2) ^ 2) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) := by field_simp [hden] _ = _ := by rw [hsq2] · simp only [hj, ↓reduceIte] calc lam2 * (Real.sqrt ((n : ℝ) * lam2) * (1 / ((m * n : ℝ) * lam2))) ^ 2 = lam2 * (Real.sqrt ((n : ℝ) * lam2) ^ 2) * (1 / ((m * n : ℝ) * lam2) ^ 2) := by field_simp [ne_of_gt hμ] _ = _ := by rw [hsq2] · intro i _ hij; simp [hij] · intro h; exact absurd (Finset.mem_univ _) h simp_rw [hpt, ← Finset.mul_sum] congr 1 have hsplit : ∀ j : Fin n, (if (j : ℕ) < k then 1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2 else 1 / ((m * n : ℝ) * lam2) ^ 2) = (if (j : ℕ) < k then (1 : ℝ) else 0) * (1 / ((n : ℝ) * lam1 + (m * n : ℝ) * lam2) ^ 2) + (1 - if (j : ℕ) < k then (1 : ℝ) else 0) * (1 / ((m * n : ℝ) * lam2) ^ 2) := by intro j; by_cases hj : (j : ℕ) < k <;> simp [hj] simp_rw [hsplit, Finset.sum_add_distrib, ← Finset.sum_mul, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, card_fin_lt_eq (le_of_lt hk)] ring simp_rw [hinner, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] ring rw [hv1, hv2] simp only [ρ] field_simp [ne_of_gt hlam1, ne_of_gt hlam2, ne_of_gt hmR, ne_of_gt hn, hden] ring /-- **Theorem 1.9 (Optimal Self-Induced Ridge SOS Identity — Beating Oracle OLS).** -/ theorem benign_overfitting_optimal_self_ridge {A B ρ : ℝ} (hA : 0 < A) (hB : 0 < B) (hρ : 0 ≤ ρ) : (A * ρ ^ 2 + B) / (1 + ρ) ^ 2 - (A * B) / (A + B) = (A * ρ - B) ^ 2 / ((A + B) * (1 + ρ) ^ 2) ∧ (A * B) / (A + B) < B := by have h1 : 1 + ρ ≠ 0 := by linarith have hAB : A + B ≠ 0 := by linarith constructor · field_simp [h1, hAB]; ring · rw [div_lt_iff₀ (by linarith)] nlinarith end Pillar1 /-! ============================================================================ SECTION 2: GRADIENT-FLOW IMPLICIT BIAS — MAX-MARGIN DIRECTIONAL CONVERGENCE & DIAGONAL LINEAR NETWORK HYPERBOLIC ENTROPY `q_α` TRANSITION ============================================================================ -/ section Pillar2A /-- Helper: chain rule for `fun s => Real.sqrt (f s)` when `0 < f t`. -/ lemma hasDerivAt_sqrt_comp {f : ℝ → ℝ} {f' t : ℝ} (hf : HasDerivAt f f' t) (hft : 0 < f t) : HasDerivAt (fun s => Real.sqrt (f s)) (f' / (2 * Real.sqrt (f t))) t := by have hrpow : HasDerivAt (fun s => (f s) ^ ((1 : ℝ) / 2)) (f' * ((1 : ℝ) / 2) * (f t) ^ ((1 : ℝ) / 2 - 1)) t := hf.rpow_const (Or.inl (ne_of_gt hft)) have hfun : (fun s => (f s) ^ ((1 : ℝ) / 2)) = (fun s => Real.sqrt (f s)) := by ext s; exact (Real.sqrt_eq_rpow (f s)).symm rw [hfun] at hrpow refine hrpow.congr_deriv ?_ have hrt_pos : 0 < Real.sqrt (f t) := Real.sqrt_pos.mpr hft have hpow_neg : (f t) ^ ((1 : ℝ) / 2 - 1) = (Real.sqrt (f t))⁻¹ := by have heq : (1 : ℝ) / 2 - 1 = -((1 : ℝ) / 2) := by ring rw [heq, Real.rpow_neg (le_of_lt hft), ← Real.sqrt_eq_rpow] rw [hpow_neg] field_simp [ne_of_gt hrt_pos] /-- Exponential empirical loss `L(w) = ∑_{i=1}^n exp(-⟨w, z_i⟩)`. -/ noncomputable def expLoss {n d : ℕ} (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) : ℝ := ∑ i : Fin n, Real.exp (-dot w (Z i)) /-- Negative gradient of exponential loss: `g(w) = -∇L(w) = ∑_i exp(-⟨w, z_i⟩) z_i`. -/ noncomputable def expNegGrad {n d : ℕ} (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) : Fin d → ℝ := fun k => ∑ i : Fin n, Real.exp (-dot w (Z i)) * Z i k /-- Softmax sample weights `p_i(w) = exp(-⟨w, z_i⟩) / L(w)`. -/ noncomputable def expSoftmax {n d : ℕ} (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) (i : Fin n) : ℝ := Real.exp (-dot w (Z i)) / expLoss Z w /-- Discrete Shannon entropy `H(p) = -∑_i p_i log p_i`. -/ noncomputable def shannonEntropy {n : ℕ} (p : Fin n → ℝ) : ℝ := -∑ i : Fin n, p i * Real.log (p i) lemma expLoss_pos {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) : 0 < expLoss Z w := by unfold expLoss exact Finset.sum_pos (fun i _ => Real.exp_pos _) Finset.univ_nonempty lemma expSoftmax_pos {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) (i : Fin n) : 0 < expSoftmax Z w i := div_pos (Real.exp_pos _) (expLoss_pos Z w) lemma expSoftmax_sum_one {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) : ∑ i : Fin n, expSoftmax Z w i = 1 := by unfold expSoftmax rw [← Finset.sum_div] exact div_self (ne_of_gt (expLoss_pos Z w)) lemma dot_expNegGrad {n d : ℕ} (Z : Fin n → Fin d → ℝ) (w v : Fin d → ℝ) : dot v (expNegGrad Z w) = ∑ i : Fin n, Real.exp (-dot w (Z i)) * dot v (Z i) := by simp only [dot, expNegGrad] simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun i _ => ?_ refine Finset.sum_congr rfl fun k _ => ?_ ring /-- **Theorem 2.1 (Exact Shannon-Entropy Identity for Exponential Loss).** -/ theorem exp_loss_shannon_entropy_identity {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : Fin d → ℝ) : dot w (expNegGrad Z w) = expLoss Z w * (-Real.log (expLoss Z w) + shannonEntropy (expSoftmax Z w)) := by have hLpos : 0 < expLoss Z w := expLoss_pos Z w have hLne : expLoss Z w ≠ 0 := ne_of_gt hLpos rw [dot_expNegGrad] unfold shannonEntropy have hterm : ∀ i : Fin n, expSoftmax Z w i * Real.log (expSoftmax Z w i) = (Real.exp (-dot w (Z i)) / expLoss Z w) * (-dot w (Z i) - Real.log (expLoss Z w)) := by intro i unfold expSoftmax rw [Real.log_div (ne_of_gt (Real.exp_pos _)) hLne, Real.log_exp] simp_rw [hterm] have hsum : ∑ i : Fin n, (Real.exp (-dot w (Z i)) / expLoss Z w) * (-dot w (Z i) - Real.log (expLoss Z w)) = -(∑ i : Fin n, Real.exp (-dot w (Z i)) * dot w (Z i)) / expLoss Z w - Real.log (expLoss Z w) := by have h1 : ∀ i : Fin n, (Real.exp (-dot w (Z i)) / expLoss Z w) * (-dot w (Z i) - Real.log (expLoss Z w)) = -(Real.exp (-dot w (Z i)) * dot w (Z i)) / expLoss Z w - (Real.exp (-dot w (Z i)) / expLoss Z w) * Real.log (expLoss Z w) := by intro i; ring simp_rw [h1, Finset.sum_sub_distrib, ← Finset.sum_div, ← Finset.sum_mul, Finset.sum_neg_distrib] have hsum1 : (∑ i : Fin n, Real.exp (-dot w (Z i)) / expLoss Z w) = 1 := expSoftmax_sum_one Z w rw [hsum1, one_mul] rw [hsum] field_simp [hLne] ring /-- **Lemma 2.2 (Exact Bounds `0 ≤ H(p) ≤ log n` on Shannon Entropy).** -/ lemma shannonEntropy_bounds {n : ℕ} [NeZero n] {p : Fin n → ℝ} (hp_pos : ∀ i, 0 < p i) (hp_sum : ∑ i, p i = 1) : 0 ≤ shannonEntropy p ∧ shannonEntropy p ≤ Real.log (n : ℝ) := by have hn_pos : 0 < (n : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne n) constructor · unfold shannonEntropy have hle : ∑ i : Fin n, p i * Real.log (p i) ≤ 0 := by refine Finset.sum_nonpos fun i _ => ?_ have hpi_le : p i ≤ 1 := by have := Finset.single_le_sum (f := p) (fun j _ => le_of_lt (hp_pos j)) (Finset.mem_univ i) linarith exact mul_nonpos_of_nonneg_of_nonpos (le_of_lt (hp_pos i)) (Real.log_nonpos (le_of_lt (hp_pos i)) hpi_le) linarith · have hdiff : shannonEntropy p - Real.log (n : ℝ) = ∑ i : Fin n, p i * Real.log (1 / ((n : ℝ) * p i)) := by unfold shannonEntropy have hterm : ∀ i : Fin n, p i * Real.log (1 / ((n : ℝ) * p i)) = -(p i * Real.log (p i)) - p i * Real.log (n : ℝ) := by intro i rw [one_div, Real.log_inv, Real.log_mul (ne_of_gt hn_pos) (ne_of_gt (hp_pos i))] ring simp_rw [hterm, Finset.sum_sub_distrib, Finset.sum_neg_distrib, ← Finset.sum_mul, hp_sum, one_mul] have hle : ∑ i : Fin n, p i * Real.log (1 / ((n : ℝ) * p i)) ≤ 0 := by have hpt : ∀ i : Fin n, p i * Real.log (1 / ((n : ℝ) * p i)) ≤ 1 / (n : ℝ) - p i := by intro i have hpos : 0 < 1 / ((n : ℝ) * p i) := by positivity [hp_pos i] have hlog := Real.log_le_sub_one_of_pos hpos have hmul := mul_le_mul_of_nonneg_left hlog (le_of_lt (hp_pos i)) have hsimp : p i * (1 / ((n : ℝ) * p i) - 1) = 1 / (n : ℝ) - p i := by field_simp [ne_of_gt hn_pos, ne_of_gt (hp_pos i)] linarith calc ∑ i : Fin n, p i * Real.log (1 / ((n : ℝ) * p i)) ≤ ∑ i : Fin n, (1 / (n : ℝ) - p i) := Finset.sum_le_sum fun i _ => hpt i _ = (∑ _i : Fin n, (1 / (n : ℝ))) - ∑ i : Fin n, p i := Finset.sum_sub_distrib _ _ _ = 1 - 1 := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, hp_sum] field_simp [ne_of_gt hn_pos] _ = 0 := sub_self 1 linarith /-- Helper: derivative of `t ↦ dot (w t) v` along a coordinatewise differentiable trajectory. -/ lemma hasDerivAt_dot_const {d : ℕ} {w : ℝ → Fin d → ℝ} {w' : ℝ → Fin d → ℝ} (hw : ∀ t k, HasDerivAt (fun s => w s k) (w' t k) t) (v : Fin d → ℝ) (t : ℝ) : HasDerivAt (fun s => dot (w s) v) (dot (w' t) v) t := by unfold dot simpa using HasDerivAt.fun_sum (u := Finset.univ) (fun k _ => (hw t k).mul_const (v k)) /-- Helper: derivative of `t ↦ normSq (w t)` is `2 * dot (w t) (w' t)`. -/ lemma hasDerivAt_normSq {d : ℕ} {w : ℝ → Fin d → ℝ} {w' : ℝ → Fin d → ℝ} (hw : ∀ t k, HasDerivAt (fun s => w s k) (w' t k) t) (t : ℝ) : HasDerivAt (fun s => normSq (w s)) (2 * dot (w t) (w' t)) t := by unfold normSq dot have h1 : ∀ k ∈ (Finset.univ : Finset (Fin d)), HasDerivAt (fun s => (w s k) ^ 2) (2 * (w t k * w' t k)) t := by intro k _ exact ((hw t k).fun_pow 2).congr_deriv (by ring) exact (HasDerivAt.fun_sum h1).congr_deriv (by rw [Finset.mul_sum]) /-- Helper: derivative of `t ↦ expLoss Z (w t)` along exponential gradient flow `w' = expNegGrad Z w` equals `-normSq (expNegGrad Z (w t))`. -/ lemma hasDerivAt_expLoss_gf {n d : ℕ} (Z : Fin n → Fin d → ℝ) {w : ℝ → Fin d → ℝ} (hgf : ∀ t k, HasDerivAt (fun s => w s k) (expNegGrad Z (w t) k) t) (t : ℝ) : HasDerivAt (fun s => expLoss Z (w s)) (-normSq (expNegGrad Z (w t))) t := by unfold expLoss have hterm : ∀ i ∈ (Finset.univ : Finset (Fin n)), HasDerivAt (fun s => Real.exp (-dot (w s) (Z i))) (-(Real.exp (-dot (w t) (Z i)) * dot (expNegGrad Z (w t)) (Z i))) t := by intro i _ have hd : HasDerivAt (fun s => -dot (w s) (Z i)) (-dot (expNegGrad Z (w t)) (Z i)) t := (hasDerivAt_dot_const hgf (Z i) t).fun_neg exact hd.exp.congr_deriv (by ring) refine (HasDerivAt.fun_sum hterm).congr_deriv ?_ rw [Finset.sum_neg_distrib, ← dot_expNegGrad, dot] unfold normSq congr 1 refine Finset.sum_congr rfl fun k _ => ?_; ring /-- **Theorem 2.3 (Exact Non-Asymptotic `O(1/t)` Loss Decay & Norm-Growth Lower Bound).** -/ theorem exp_gf_loss_decay_and_norm_growth {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : ℝ → Fin d → ℝ) (uStar : Fin d → ℝ) (γ B : ℝ) (hgf : ∀ t k, HasDerivAt (fun s => w s k) (expNegGrad Z (w t) k) t) (hu_norm : normSq uStar = 1) (hγ_pos : 0 < γ) (hsep : ∀ i, γ ≤ dot uStar (Z i)) (hB_pos : 0 < B) (hB : ∀ i, euclidNorm (Z i) ≤ B) {t : ℝ} (ht : 0 ≤ t) : expLoss Z (w t) ≤ expLoss Z (w 0) / (1 + γ ^ 2 * expLoss Z (w 0) * t) ∧ (1 / B) * Real.log ((n : ℝ) * (1 + γ ^ 2 * expLoss Z (w 0) * t) / expLoss Z (w 0)) ≤ euclidNorm (w t) := by let φ : ℝ → ℝ := fun s => (expLoss Z (w s))⁻¹ - γ ^ 2 * s have hderiv_φ : ∀ s, ∃ dφ, HasDerivAt φ dφ s ∧ 0 ≤ dφ := by intro s have hLpos := expLoss_pos Z (w s) have hLne := ne_of_gt hLpos have hL := hasDerivAt_expLoss_gf Z hgf s have hinv := hL.inv hLne have hlin : HasDerivAt (fun x => γ ^ 2 * x) (γ ^ 2) s := by simpa using (hasDerivAt_id s).const_mul (γ ^ 2) refine ⟨-(-normSq (expNegGrad Z (w s))) / (expLoss Z (w s)) ^ 2 - γ ^ 2, hinv.fun_sub hlin, ?_⟩ have hdot_ge : γ * expLoss Z (w s) ≤ dot uStar (expNegGrad Z (w s)) := by rw [dot_expNegGrad, expLoss, Finset.mul_sum] refine Finset.sum_le_sum fun i _ => ?_ have hexp := le_of_lt (Real.exp_pos (-dot (w s) (Z i))) nlinarith [hsep i] have hcs := dot_sq_le_normSq_mul uStar (expNegGrad Z (w s)) rw [hu_norm, one_mul] at hcs have hsq_ge : γ ^ 2 * (expLoss Z (w s)) ^ 2 ≤ normSq (expNegGrad Z (w s)) := by have h1 : (γ * expLoss Z (w s)) ^ 2 ≤ (dot uStar (expNegGrad Z (w s))) ^ 2 := by nlinarith [mul_nonneg (le_of_lt hγ_pos) (le_of_lt hLpos)] linarith rw [neg_neg, sub_nonneg, le_div_iff₀ (sq_pos_of_pos hLpos)] exact hsq_ge have hmono : Monotone φ := monotone_of_deriv_nonneg (fun s => let ⟨_, hd, _⟩ := hderiv_φ s; hd.differentiableAt) (fun s => let ⟨dφ, hd, hnn⟩ := hderiv_φ s; by rwa [hd.deriv]) have hφ_ge : φ 0 ≤ φ t := hmono ht have hL0pos := expLoss_pos Z (w 0) have hLtpos := expLoss_pos Z (w t) have hden_pos : 0 < 1 + γ ^ 2 * expLoss Z (w 0) * t := by positivity have hloss : expLoss Z (w t) ≤ expLoss Z (w 0) / (1 + γ ^ 2 * expLoss Z (w 0) * t) := by simp only [φ, mul_zero, sub_zero] at hφ_ge have hinv_ge : (1 + γ ^ 2 * expLoss Z (w 0) * t) / expLoss Z (w 0) ≤ (expLoss Z (w t))⁻¹ := by have : (1 + γ ^ 2 * expLoss Z (w 0) * t) / expLoss Z (w 0) = (expLoss Z (w 0))⁻¹ + γ ^ 2 * t := by field_simp [ne_of_gt hL0pos] linarith rw [le_div_iff₀ hden_pos] have h1 := mul_le_mul_of_nonneg_left hinv_ge (le_of_lt hLtpos) have h2 : expLoss Z (w t) * (expLoss Z (w t))⁻¹ = 1 := mul_inv_cancel₀ (ne_of_gt hLtpos) rw [h2] at h1 have h3 := mul_le_mul_of_nonneg_right h1 (le_of_lt hL0pos) have h4 : expLoss Z (w t) * ((1 + γ ^ 2 * expLoss Z (w 0) * t) / expLoss Z (w 0)) * expLoss Z (w 0) = expLoss Z (w t) * (1 + γ ^ 2 * expLoss Z (w 0) * t) := by field_simp [ne_of_gt hL0pos] linarith refine ⟨hloss, ?_⟩ have hL_lower : (n : ℝ) * Real.exp (-B * euclidNorm (w t)) ≤ expLoss Z (w t) := by unfold expLoss calc (n : ℝ) * Real.exp (-B * euclidNorm (w t)) = ∑ _i : Fin n, Real.exp (-B * euclidNorm (w t)) := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] _ ≤ ∑ i : Fin n, Real.exp (-dot (w t) (Z i)) := by refine Finset.sum_le_sum fun i _ => Real.exp_le_exp.mpr ?_ have hcs := abs_dot_le_euclidNorm_mul (w t) (Z i) have hle : dot (w t) (Z i) ≤ euclidNorm (w t) * B := by calc dot (w t) (Z i) ≤ |dot (w t) (Z i)| := le_abs_self _ _ ≤ euclidNorm (w t) * euclidNorm (Z i) := hcs _ ≤ euclidNorm (w t) * B := mul_le_mul_of_nonneg_left (hB i) (euclidNorm_nonneg _) linarith have hchain : (n : ℝ) * Real.exp (-B * euclidNorm (w t)) ≤ expLoss Z (w 0) / (1 + γ ^ 2 * expLoss Z (w 0) * t) := le_trans hL_lower hloss have hn_pos : 0 < (n : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne n) have hratio : (n : ℝ) * (1 + γ ^ 2 * expLoss Z (w 0) * t) / expLoss Z (w 0) ≤ Real.exp (B * euclidNorm (w t)) := by rw [div_le_iff₀ hL0pos] have hmul := mul_le_mul_of_nonneg_right hchain (le_of_lt (Real.exp_pos (B * euclidNorm (w t)))) have hmul2 := mul_le_mul_of_nonneg_right hmul (le_of_lt hden_pos) have hexp_cancel : Real.exp (-B * euclidNorm (w t)) * Real.exp (B * euclidNorm (w t)) = 1 := by rw [← Real.exp_add]; simp have hLHS : (n : ℝ) * Real.exp (-B * euclidNorm (w t)) * Real.exp (B * euclidNorm (w t)) * (1 + γ ^ 2 * expLoss Z (w 0) * t) = (n : ℝ) * (1 + γ ^ 2 * expLoss Z (w 0) * t) := by calc (n : ℝ) * Real.exp (-B * euclidNorm (w t)) * Real.exp (B * euclidNorm (w t)) * (1 + γ ^ 2 * expLoss Z (w 0) * t) = (n : ℝ) * (Real.exp (-B * euclidNorm (w t)) * Real.exp (B * euclidNorm (w t))) * (1 + γ ^ 2 * expLoss Z (w 0) * t) := by ring _ = _ := by rw [hexp_cancel, mul_one] have hRHS : expLoss Z (w 0) / (1 + γ ^ 2 * expLoss Z (w 0) * t) * Real.exp (B * euclidNorm (w t)) * (1 + γ ^ 2 * expLoss Z (w 0) * t) = Real.exp (B * euclidNorm (w t)) * expLoss Z (w 0) := by field_simp [ne_of_gt hden_pos] linarith have hlog := Real.log_le_log (by positivity) hratio rw [Real.log_exp] at hlog rw [one_div, inv_mul_le_iff₀ hB_pos] linarith /-- **Theorem 2.4 (Monotone Smooth Normalized Margin with Exact Entropy Production Rate).** -/ theorem exp_gf_smooth_margin_deriv_nonneg {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : ℝ → Fin d → ℝ) (hgf : ∀ t k, HasDerivAt (fun s => w s k) (expNegGrad Z (w t) k) t) (t : ℝ) (hL_le : expLoss Z (w t) ≤ 1) (hw_pos : 0 < normSq (w t)) : let L := expLoss Z (w t) let g := expNegGrad Z (w t) let r := euclidNorm (w t) let H := shannonEntropy (expSoftmax Z (w t)) HasDerivAt (fun s => -Real.log (expLoss Z (w s)) / euclidNorm (w s)) (((normSq g * normSq (w t) - (dot (w t) g) ^ 2) + L * H * dot (w t) g) / (L * r ^ 3)) t ∧ 0 ≤ ((normSq g * normSq (w t) - (dot (w t) g) ^ 2) + L * H * dot (w t) g) / (L * r ^ 3) := by dsimp only set L := expLoss Z (w t) set g := expNegGrad Z (w t) set r := euclidNorm (w t) set H := shannonEntropy (expSoftmax Z (w t)) have hLpos : 0 < L := expLoss_pos Z (w t) have hLne : L ≠ 0 := ne_of_gt hLpos have hrpos : 0 < r := Real.sqrt_pos.mpr hw_pos have hrne : r ≠ 0 := ne_of_gt hrpos have hrsq : r ^ 2 = normSq (w t) := euclidNorm_sq (w t) have hderiv_num : HasDerivAt (fun s => -Real.log (expLoss Z (w s))) (normSq g / L) t := by have h1 := ((hasDerivAt_expLoss_gf Z hgf t).log hLne).fun_neg exact h1.congr_deriv (by ring) have hderiv_r : HasDerivAt (fun s => euclidNorm (w s)) (dot (w t) g / r) t := by unfold euclidNorm refine (hasDerivAt_sqrt_comp (hasDerivAt_normSq hgf t) hw_pos).congr_deriv ?_ change 2 * dot (w t) g / (2 * r) = dot (w t) g / r field_simp [hrne] have hquot := hderiv_num.fun_div hderiv_r hrne have hent := exp_loss_shannon_entropy_identity Z (w t) have hH_nn : 0 ≤ H := (shannonEntropy_bounds (expSoftmax_pos Z (w t)) (expSoftmax_sum_one Z (w t))).1 have hnegLog_nn : 0 ≤ -Real.log L := by have := Real.log_nonpos (le_of_lt hLpos) hL_le linarith have hdot_nn : 0 ≤ dot (w t) g := by rw [hent]; exact mul_nonneg (le_of_lt hLpos) (by linarith) constructor · refine hquot.congr_deriv ?_ change (normSq g / L * r - -Real.log L * (dot (w t) g / r)) / r ^ 2 = ((normSq g * normSq (w t) - dot (w t) g ^ 2) + L * H * dot (w t) g) / (L * r ^ 3) have hlogL : L * Real.log L = L * H - dot (w t) g := by linarith [hent] field_simp [hLne, hrne] calc normSq g * r ^ 2 - -(L * Real.log L * dot (w t) g) = normSq g * normSq (w t) + (L * Real.log L) * dot (w t) g := by rw [hrsq]; ring _ = normSq g * normSq (w t) + (L * H - dot (w t) g) * dot (w t) g := by rw [hlogL] _ = normSq g * normSq (w t) - dot (w t) g ^ 2 + L * dot (w t) g * H := by ring · have hcs : 0 ≤ normSq g * normSq (w t) - (dot (w t) g) ^ 2 := by have := dot_sq_le_normSq_mul (w t) g linarith have h2 : 0 ≤ L * H * dot (w t) g := by positivity have hden : 0 < L * r ^ 3 := by positivity exact div_nonneg (by linarith) (le_of_lt hden) /-- **Theorem 2.5 (Exact Non-Asymptotic Max-Margin Directional Convergence Rate).** -/ theorem exp_gf_max_margin_directional_rate {n d : ℕ} [NeZero n] (Z : Fin n → Fin d → ℝ) (w : ℝ → Fin d → ℝ) (uStar : Fin d → ℝ) (γ : ℝ) (hgf : ∀ s k, HasDerivAt (fun x => w x k) (expNegGrad Z (w s) k) s) (hu_norm : normSq uStar = 1) (hγ_pos : 0 < γ) (hsep : ∀ i, γ ≤ dot uStar (Z i)) (hmax_margin : ∀ v : Fin d → ℝ, ∃ i : Fin n, dot v (Z i) ≤ γ * euclidNorm v) {t₀ t : ℝ} (ht : t₀ ≤ t) (hproj_pos : ∀ s ∈ Set.Icc t₀ t, 0 < dot (w s) uStar) : 1 - dot (w t) uStar / euclidNorm (w t) ≤ ((euclidNorm (w t₀) - dot (w t₀) uStar) + (Real.log (n : ℝ) / γ) * Real.log (dot (w t) uStar / dot (w t₀) uStar)) / euclidNorm (w t) := by let Ψ : ℝ → ℝ := fun s => euclidNorm (w s) - dot (w s) uStar - (Real.log (n : ℝ) / γ) * Real.log (dot (w s) uStar) have hnorm_ge_proj : ∀ s, dot (w s) uStar ≤ euclidNorm (w s) := by intro s have hcs := abs_dot_le_euclidNorm_mul (w s) uStar have hu1 : euclidNorm uStar = 1 := by simp [euclidNorm, hu_norm] rw [hu1, mul_one] at hcs exact le_trans (le_abs_self _) hcs have hderiv_le : ∀ s ∈ Set.Icc t₀ t, ∃ dΨ, HasDerivAt Ψ dΨ s ∧ dΨ ≤ 0 := by intro s hs have hps : 0 < dot (w s) uStar := hproj_pos s hs have hrs : 0 < euclidNorm (w s) := lt_of_lt_of_le hps (hnorm_ge_proj s) have hnsq_pos : 0 < normSq (w s) := by have := euclidNorm_sq (w s) nlinarith have hrne : euclidNorm (w s) ≠ 0 := ne_of_gt hrs have hLpos := expLoss_pos Z (w s) have hderiv_r : HasDerivAt (fun x => euclidNorm (w x)) (dot (w s) (expNegGrad Z (w s)) / euclidNorm (w s)) s := by unfold euclidNorm refine (hasDerivAt_sqrt_comp (hasDerivAt_normSq hgf s) hnsq_pos).congr_deriv ?_ change 2 * dot (w s) (expNegGrad Z (w s)) / (2 * euclidNorm (w s)) = dot (w s) (expNegGrad Z (w s)) / euclidNorm (w s) field_simp [hrne] have hderiv_p : HasDerivAt (fun x => dot (w x) uStar) (dot (expNegGrad Z (w s)) uStar) s := hasDerivAt_dot_const hgf uStar s have hderiv_log : HasDerivAt (fun x => (Real.log (n : ℝ) / γ) * Real.log (dot (w x) uStar)) ((Real.log (n : ℝ) / γ) * (dot (expNegGrad Z (w s)) uStar / dot (w s) uStar)) s := (hderiv_p.log (ne_of_gt hps)).const_mul _ refine ⟨dot (w s) (expNegGrad Z (w s)) / euclidNorm (w s) - dot (expNegGrad Z (w s)) uStar - (Real.log (n : ℝ) / γ) * (dot (expNegGrad Z (w s)) uStar / dot (w s) uStar), (hderiv_r.fun_sub hderiv_p).fun_sub hderiv_log, ?_⟩ obtain ⟨i₀, hi₀⟩ := hmax_margin (w s) have hL_ge_i₀ : Real.exp (-dot (w s) (Z i₀)) ≤ expLoss Z (w s) := Finset.single_le_sum (f := fun i => Real.exp (-dot (w s) (Z i))) (fun i _ => le_of_lt (Real.exp_pos _)) (Finset.mem_univ i₀) have hneglog_le : -Real.log (expLoss Z (w s)) ≤ γ * euclidNorm (w s) := by have hlog := Real.log_le_log (Real.exp_pos _) hL_ge_i₀ rw [Real.log_exp] at hlog linarith have hH_le : shannonEntropy (expSoftmax Z (w s)) ≤ Real.log (n : ℝ) := (shannonEntropy_bounds (expSoftmax_pos Z (w s)) (expSoftmax_sum_one Z (w s))).2 have hlogn_nn : 0 ≤ Real.log (n : ℝ) := by have : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne n) exact Real.log_nonneg this have hdr_le : dot (w s) (expNegGrad Z (w s)) / euclidNorm (w s) ≤ γ * expLoss Z (w s) + Real.log (n : ℝ) * expLoss Z (w s) / euclidNorm (w s) := by rw [exp_loss_shannon_entropy_identity] have hnum : expLoss Z (w s) * (-Real.log (expLoss Z (w s)) + shannonEntropy (expSoftmax Z (w s))) ≤ expLoss Z (w s) * (γ * euclidNorm (w s) + Real.log (n : ℝ)) := mul_le_mul_of_nonneg_left (by linarith) (le_of_lt hLpos) have hdiv := div_le_div_of_nonneg_right hnum (le_of_lt hrs) have hsimp : expLoss Z (w s) * (γ * euclidNorm (w s) + Real.log (n : ℝ)) / euclidNorm (w s) = γ * expLoss Z (w s) + Real.log (n : ℝ) * expLoss Z (w s) / euclidNorm (w s) := by field_simp [hrne] linarith have hdp_ge : γ * expLoss Z (w s) ≤ dot (expNegGrad Z (w s)) uStar := by rw [dot_comm, dot_expNegGrad, expLoss, Finset.mul_sum] refine Finset.sum_le_sum fun i _ => ?_ have hexp := le_of_lt (Real.exp_pos (-dot (w s) (Z i))) nlinarith [hsep i] have hlogterm : Real.log (n : ℝ) * expLoss Z (w s) / euclidNorm (w s) ≤ (Real.log (n : ℝ) / γ) * (dot (expNegGrad Z (w s)) uStar / dot (w s) uStar) := by have h1 : Real.log (n : ℝ) * expLoss Z (w s) / euclidNorm (w s) ≤ Real.log (n : ℝ) * expLoss Z (w s) / dot (w s) uStar := div_le_div_of_nonneg_left (mul_nonneg hlogn_nn (le_of_lt hLpos)) hps (hnorm_ge_proj s) have h2 : expLoss Z (w s) ≤ dot (expNegGrad Z (w s)) uStar / γ := (le_div_iff₀ hγ_pos).mpr (by linarith) have h3 : Real.log (n : ℝ) * expLoss Z (w s) / dot (w s) uStar ≤ (Real.log (n : ℝ) / γ) * (dot (expNegGrad Z (w s)) uStar / dot (w s) uStar) := by have hrew : (Real.log (n : ℝ) / γ) * (dot (expNegGrad Z (w s)) uStar / dot (w s) uStar) = Real.log (n : ℝ) * (dot (expNegGrad Z (w s)) uStar / γ) / dot (w s) uStar := by ring rw [hrew] exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left h2 hlogn_nn) (le_of_lt hps) exact le_trans h1 h3 linarith have hanti : AntitoneOn Ψ (Set.Icc t₀ t) := by refine antitoneOn_of_deriv_nonpos (convex_Icc t₀ t) ?_ ?_ ?_ · exact fun s hs => (let ⟨_, hd, _⟩ := hderiv_le s hs; hd.continuousAt.continuousWithinAt) · intro s hs have hmem : s ∈ Set.Icc t₀ t := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hs) exact let ⟨_, hd, _⟩ := hderiv_le s hmem; hd.differentiableAt.differentiableWithinAt · intro s hs have hmem : s ∈ Set.Icc t₀ t := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hs) exact let ⟨dΨ, hd, hle⟩ := hderiv_le s hmem; by rwa [hd.deriv] have hΨ_le : Ψ t ≤ Ψ t₀ := hanti (Set.left_mem_Icc.mpr ht) (Set.right_mem_Icc.mpr ht) ht have hp0 : 0 < dot (w t₀) uStar := hproj_pos t₀ (Set.left_mem_Icc.mpr ht) have hpt : 0 < dot (w t) uStar := hproj_pos t (Set.right_mem_Icc.mpr ht) have hrt : 0 < euclidNorm (w t) := lt_of_lt_of_le hpt (hnorm_ge_proj t) have hdiff_le : euclidNorm (w t) - dot (w t) uStar ≤ (euclidNorm (w t₀) - dot (w t₀) uStar) + (Real.log (n : ℝ) / γ) * Real.log (dot (w t) uStar / dot (w t₀) uStar) := by simp only [Ψ] at hΨ_le rw [Real.log_div (ne_of_gt hpt) (ne_of_gt hp0)] linarith have hdiv := div_le_div_of_nonneg_right hdiff_le (le_of_lt hrt) have hLHS : (euclidNorm (w t) - dot (w t) uStar) / euclidNorm (w t) = 1 - dot (w t) uStar / euclidNorm (w t) := by rw [sub_div, div_self (ne_of_gt hrt)] linarith end Pillar2A section Pillar2B /-- Inverse hyperbolic sine `arsinh(z) = log(z + √(z² + 1))`. -/ noncomputable def myArsinh (z : ℝ) : ℝ := Real.log (z + Real.sqrt (z ^ 2 + 1)) lemma myArsinh_arg_pos (z : ℝ) : 0 < z + Real.sqrt (z ^ 2 + 1) := by have h1 : |z| < Real.sqrt (z ^ 2 + 1) := by have hsq : |z| ^ 2 < Real.sqrt (z ^ 2 + 1) ^ 2 := by rw [sq_abs, Real.sq_sqrt (by positivity)]; linarith nlinarith [abs_nonneg z, Real.sqrt_nonneg (z ^ 2 + 1)] linarith [neg_abs_le z] lemma myArsinh_zero : myArsinh 0 = 0 := by simp [myArsinh] lemma myArsinh_neg (z : ℝ) : myArsinh (-z) = -myArsinh z := by unfold myArsinh have hprod : (-z + Real.sqrt ((-z) ^ 2 + 1)) * (z + Real.sqrt (z ^ 2 + 1)) = 1 := by have hsq : Real.sqrt (z ^ 2 + 1) ^ 2 = z ^ 2 + 1 := Real.sq_sqrt (by positivity) have hneg : (-z) ^ 2 = z ^ 2 := by ring rw [hneg] nlinarith [hsq] have heq : -z + Real.sqrt ((-z) ^ 2 + 1) = (z + Real.sqrt (z ^ 2 + 1))⁻¹ := eq_inv_of_mul_eq_one_left hprod rw [heq, Real.log_inv] lemma hasDerivAt_myArsinh (z : ℝ) : HasDerivAt myArsinh (1 / Real.sqrt (z ^ 2 + 1)) z := by have hsq_pos : 0 < z ^ 2 + 1 := by positivity have hrt_pos : 0 < Real.sqrt (z ^ 2 + 1) := Real.sqrt_pos.mpr hsq_pos have hinner : HasDerivAt (fun x => x ^ 2 + 1) (2 * z) z := by have hpow := ((hasDerivAt_id' z).fun_pow 2).add_const (1 : ℝ) exact hpow.congr_deriv (by ring) have hsqrt : HasDerivAt (fun x => Real.sqrt (x ^ 2 + 1)) (z / Real.sqrt (z ^ 2 + 1)) z := by refine (hasDerivAt_sqrt_comp hinner hsq_pos).congr_deriv ?_ field_simp [ne_of_gt hrt_pos] have hsum : HasDerivAt (fun x => x + Real.sqrt (x ^ 2 + 1)) (1 + z / Real.sqrt (z ^ 2 + 1)) z := (hasDerivAt_id' z).fun_add hsqrt have hlog := hsum.log (ne_of_gt (myArsinh_arg_pos z)) refine hlog.congr_deriv ?_ have harg_ne : z + Real.sqrt (z ^ 2 + 1) ≠ 0 := ne_of_gt (myArsinh_arg_pos z) field_simp [ne_of_gt hrt_pos, harg_ne] ring /-- Dimensionless hyperbolic entropy `h(z) = z arsinh(z) - √(z² + 1) + 1`. -/ noncomputable def hypH (z : ℝ) : ℝ := z * myArsinh z - Real.sqrt (z ^ 2 + 1) + 1 /-- Coordinate hyperbolic entropy potential `φ_α(x) = α² h(x / (2 α²))` (Woodworth et al. 2020). -/ noncomputable def phiAlpha (α x : ℝ) : ℝ := α ^ 2 * hypH (x / (2 * α ^ 2)) /-- Total hyperbolic entropy `q_α(w) = ∑_i φ_α(w_i)`. -/ noncomputable def hypEntropy {d : ℕ} (α : ℝ) (w : Fin d → ℝ) : ℝ := ∑ i : Fin d, phiAlpha α (w i) lemma hypH_even (z : ℝ) : hypH (-z) = hypH z := by unfold hypH; rw [myArsinh_neg]; ring_nf lemma hypH_zero : hypH 0 = 0 := by simp [hypH, myArsinh_zero] lemma hasDerivAt_hypH (z : ℝ) : HasDerivAt hypH (myArsinh z) z := by have hsq_pos : 0 < z ^ 2 + 1 := by positivity have hrt_pos : 0 < Real.sqrt (z ^ 2 + 1) := Real.sqrt_pos.mpr hsq_pos have h1 : HasDerivAt (fun x => x * myArsinh x) (1 * myArsinh z + z * (1 / Real.sqrt (z ^ 2 + 1))) z := (hasDerivAt_id' z).fun_mul (hasDerivAt_myArsinh z) have hinner : HasDerivAt (fun x => x ^ 2 + 1) (2 * z) z := by have hpow := ((hasDerivAt_id' z).fun_pow 2).add_const (1 : ℝ) exact hpow.congr_deriv (by ring) have h2 : HasDerivAt (fun x => Real.sqrt (x ^ 2 + 1)) (z / Real.sqrt (z ^ 2 + 1)) z := by refine (hasDerivAt_sqrt_comp hinner hsq_pos).congr_deriv ?_ field_simp [ne_of_gt hrt_pos] exact ((h1.fun_sub h2).add_const (1 : ℝ)).congr_deriv (by ring) lemma hasDerivAt_phiAlpha {α : ℝ} (hα : 0 < α) (x : ℝ) : HasDerivAt (phiAlpha α) ((1 / 2) * myArsinh (x / (2 * α ^ 2))) x := by have hscale : HasDerivAt (fun y => y / (2 * α ^ 2)) (1 / (2 * α ^ 2)) x := ((hasDerivAt_id' x).div_const (2 * α ^ 2)).congr_deriv (by ring) have hcomp := (hasDerivAt_hypH (x / (2 * α ^ 2))).comp x hscale have hmul := hcomp.const_mul (α ^ 2) refine hmul.congr_deriv ?_ field_simp [ne_of_gt hα] lemma hasDerivAt_phiAlpha_grad {α : ℝ} (hα : 0 < α) (x : ℝ) : HasDerivAt (fun y => (1 / 2) * myArsinh (y / (2 * α ^ 2))) (1 / (2 * Real.sqrt (x ^ 2 + 4 * α ^ 4))) x := by have hscale : HasDerivAt (fun y => y / (2 * α ^ 2)) (1 / (2 * α ^ 2)) x := ((hasDerivAt_id' x).div_const (2 * α ^ 2)).congr_deriv (by ring) have hcomp := (hasDerivAt_myArsinh (x / (2 * α ^ 2))).comp x hscale have hmul := hcomp.const_mul (1 / 2 : ℝ) refine hmul.congr_deriv ?_ have hα2 : 0 < 2 * α ^ 2 := by positivity have hrt : 2 * α ^ 2 * Real.sqrt ((x / (2 * α ^ 2)) ^ 2 + 1) = Real.sqrt (x ^ 2 + 4 * α ^ 4) := by have hsq1 : (2 * α ^ 2 * Real.sqrt ((x / (2 * α ^ 2)) ^ 2 + 1)) ^ 2 = x ^ 2 + 4 * α ^ 4 := by rw [mul_pow, Real.sq_sqrt (by positivity)]; field_simp [ne_of_gt hα]; ring have hsq2 : Real.sqrt (x ^ 2 + 4 * α ^ 4) ^ 2 = x ^ 2 + 4 * α ^ 4 := Real.sq_sqrt (by positivity) nlinarith [mul_nonneg (le_of_lt hα2) (Real.sqrt_nonneg ((x / (2 * α ^ 2)) ^ 2 + 1)), Real.sqrt_nonneg (x ^ 2 + 4 * α ^ 4)] have hrt_ne : Real.sqrt ((x / (2 * α ^ 2)) ^ 2 + 1) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (by positivity)) rw [← hrt] field_simp [ne_of_gt hα, hrt_ne] /-- **Theorem 2.6 (Diagonal Linear Network Exact Invariant & Mirror-Flow Equivalence).** -/ theorem diag_net_invariant_and_mirror_flow {α : ℝ} (hα : 0 < α) (uPlus uMinus g : ℝ → ℝ) (huP_init : uPlus 0 = α) (huM_init : uMinus 0 = α) (huP_gf : ∀ t, HasDerivAt uPlus (-2 * uPlus t * g t) t) (huM_gf : ∀ t, HasDerivAt uMinus (2 * uMinus t * g t) t) : (∀ t, uPlus t * uMinus t = α ^ 2) ∧ (∀ t, HasDerivAt (fun s => (1 / 2) * myArsinh ((uPlus s ^ 2 - uMinus s ^ 2) / (2 * α ^ 2))) (-2 * g t) t) := by have hinv : ∀ t, uPlus t * uMinus t = α ^ 2 := by have hderiv0 : ∀ t, HasDerivAt (fun s => uPlus s * uMinus s) 0 t := by intro t exact ((huP_gf t).fun_mul (huM_gf t)).congr_deriv (by ring) have hconst : ∀ t, uPlus t * uMinus t = uPlus 0 * uMinus 0 := by intro t exact is_const_of_deriv_eq_zero (fun s => (hderiv0 s).differentiableAt) (fun s => (hderiv0 s).deriv) t 0 intro t rw [hconst t, huP_init, huM_init, sq] refine ⟨hinv, ?_⟩ intro t have hw_deriv : HasDerivAt (fun s => uPlus s ^ 2 - uMinus s ^ 2) (-4 * (uPlus t ^ 2 + uMinus t ^ 2) * g t) t := by have h1 := ((huP_gf t).fun_pow 2).congr_deriv (show 2 * uPlus t ^ (2 - 1) * (-2 * uPlus t * g t) = -4 * uPlus t ^ 2 * g t by ring) have h2 := ((huM_gf t).fun_pow 2).congr_deriv (show 2 * uMinus t ^ (2 - 1) * (2 * uMinus t * g t) = 4 * uMinus t ^ 2 * g t by ring) exact (h1.fun_sub h2).congr_deriv (by ring) have hchain := (hasDerivAt_phiAlpha_grad hα (uPlus t ^ 2 - uMinus t ^ 2)).comp t hw_deriv refine hchain.congr_deriv ?_ have hsum_sq : Real.sqrt ((uPlus t ^ 2 - uMinus t ^ 2) ^ 2 + 4 * α ^ 4) = uPlus t ^ 2 + uMinus t ^ 2 := by have hid : (uPlus t ^ 2 - uMinus t ^ 2) ^ 2 + 4 * α ^ 4 = (uPlus t ^ 2 + uMinus t ^ 2) ^ 2 := by have := hinv t nlinarith [sq_nonneg (uPlus t), sq_nonneg (uMinus t)] rw [hid, Real.sqrt_sq (by positivity)] rw [hsum_sq] have hpos : 0 < uPlus t ^ 2 + uMinus t ^ 2 := by have hprod := hinv t have hne : uPlus t ≠ 0 := fun h0 => by rw [h0, zero_mul] at hprod; nlinarith [sq_pos_of_pos hα] positivity field_simp [ne_of_gt hpos] ring /-- Strict convexity of `φ_α` in first-order Bregman form. -/ lemma phiAlpha_bregman_pos {α : ℝ} (hα : 0 < α) {x y : ℝ} (hxy : x ≠ y) : 0 < phiAlpha α y - phiAlpha α x - ((1 / 2) * myArsinh (x / (2 * α ^ 2))) * (y - x) := by have hgrad_strict : StrictMono (fun z => (1 / 2) * myArsinh (z / (2 * α ^ 2))) := by refine strictMono_of_deriv_pos fun z => ?_ rw [(hasDerivAt_phiAlpha_grad hα z).deriv] positivity rcases lt_or_gt_of_ne hxy with hlt | hgt · obtain ⟨c, hc, hmv⟩ := exists_deriv_eq_slope (phiAlpha α) hlt (fun z _ => (hasDerivAt_phiAlpha hα z).continuousAt.continuousWithinAt) (fun z _ => (hasDerivAt_phiAlpha hα z).differentiableAt.differentiableWithinAt) rw [(hasDerivAt_phiAlpha hα c).deriv] at hmv have hgt_slope : (1 / 2) * myArsinh (x / (2 * α ^ 2)) < (1 / 2) * myArsinh (c / (2 * α ^ 2)) := hgrad_strict hc.1 rw [hmv, lt_div_iff₀ (sub_pos.mpr hlt)] at hgt_slope linarith · obtain ⟨c, hc, hmv⟩ := exists_deriv_eq_slope (phiAlpha α) hgt (fun z _ => (hasDerivAt_phiAlpha hα z).continuousAt.continuousWithinAt) (fun z _ => (hasDerivAt_phiAlpha hα z).differentiableAt.differentiableWithinAt) rw [(hasDerivAt_phiAlpha hα c).deriv] at hmv have hlt_slope : (1 / 2) * myArsinh (c / (2 * α ^ 2)) < (1 / 2) * myArsinh (x / (2 * α ^ 2)) := hgrad_strict hc.2 rw [hmv, div_lt_iff₀ (sub_pos.mpr hgt)] at hlt_slope linarith /-- **Theorem 2.7 (Strict Convexity & KKT Unique Global Optimality of `q_α`).** -/ theorem hypentropy_kkt_unique_minimizer {n d : ℕ} {α : ℝ} (hα : 0 < α) (X : Matrix (Fin n) (Fin d) ℝ) (y : Fin n → ℝ) (wStar : Fin d → ℝ) (ν : Fin n → ℝ) (h_interp_star : X.mulVec wStar = y) (h_kkt : ∀ j : Fin d, (1 / 2) * myArsinh (wStar j / (2 * α ^ 2)) = (X.transpose.mulVec ν) j) (w : Fin d → ℝ) (h_interp_w : X.mulVec w = y) : hypEntropy α wStar ≤ hypEntropy α w ∧ (w ≠ wStar → hypEntropy α wStar < hypEntropy α w) := by have hlin0 : ∑ j : Fin d, ((1 / 2) * myArsinh (wStar j / (2 * α ^ 2))) * (w j - wStar j) = 0 := by simp_rw [h_kkt] have hdiff : X.mulVec (w - wStar) = 0 := by rw [Matrix.mulVec_sub, h_interp_w, h_interp_star, sub_self] calc ∑ j : Fin d, (X.transpose.mulVec ν) j * (w j - wStar j) = ∑ j : Fin d, (∑ i : Fin n, X i j * ν i) * (w j - wStar j) := by simp [Matrix.mulVec, dotProduct, Matrix.transpose_apply] _ = ∑ i : Fin n, ν i * ∑ j : Fin d, X i j * (w j - wStar j) := by simp_rw [Finset.sum_mul]; rw [Finset.sum_comm] refine Finset.sum_congr rfl fun i _ => ?_ rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun j _ => ?_; ring _ = ∑ i : Fin n, ν i * (X.mulVec (w - wStar) i) := by simp [Matrix.mulVec, dotProduct] _ = 0 := by simp [hdiff] have hterm_nn : ∀ j : Fin d, 0 ≤ phiAlpha α (w j) - phiAlpha α (wStar j) - ((1 / 2) * myArsinh (wStar j / (2 * α ^ 2))) * (w j - wStar j) := by intro j by_cases hj : wStar j = w j · rw [hj]; ring_nf; exact le_rfl · exact le_of_lt (phiAlpha_bregman_pos hα hj) have hdiff_eq : hypEntropy α w - hypEntropy α wStar = ∑ j : Fin d, (phiAlpha α (w j) - phiAlpha α (wStar j) - ((1 / 2) * myArsinh (wStar j / (2 * α ^ 2))) * (w j - wStar j)) := by unfold hypEntropy rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, hlin0, sub_zero] constructor · have hnn : 0 ≤ ∑ j : Fin d, (phiAlpha α (w j) - phiAlpha α (wStar j) - ((1 / 2) * myArsinh (wStar j / (2 * α ^ 2))) * (w j - wStar j)) := Finset.sum_nonneg fun j _ => hterm_nn j linarith · intro hne have hex : ∃ j : Fin d, wStar j ≠ w j := by by_contra hall push Not at hall exact hne (funext fun j => (hall j).symm) obtain ⟨j₀, hj₀⟩ := hex have hpos_j₀ := phiAlpha_bregman_pos hα hj₀ have hsum_pos : 0 < ∑ j : Fin d, (phiAlpha α (w j) - phiAlpha α (wStar j) - ((1 / 2) * myArsinh (wStar j / (2 * α ^ 2))) * (w j - wStar j)) := Finset.sum_pos' (fun j _ => hterm_nn j) ⟨j₀, Finset.mem_univ j₀, hpos_j₀⟩ linarith /-- Exact two-sided `ℓ₂` sandwich for the dimensionless hyperbolic entropy `hypH`. -/ lemma hypH_l2_sandwich (z : ℝ) : z ^ 2 / (2 * Real.sqrt (z ^ 2 + 1)) ≤ hypH z ∧ hypH z ≤ z ^ 2 / 2 := by suffices hpos : ∀ u : ℝ, 0 ≤ u → u ^ 2 / (2 * Real.sqrt (u ^ 2 + 1)) ≤ hypH u ∧ hypH u ≤ u ^ 2 / 2 by have := hpos |z| (abs_nonneg z) rw [sq_abs] at this by_cases hz : 0 ≤ z · rwa [abs_of_nonneg hz] at this · rw [abs_of_neg (not_le.mp hz), hypH_even] at this exact this intro u hu have harsinh_bounds : ∀ t : ℝ, 0 ≤ t → t / Real.sqrt (t ^ 2 + 1) ≤ myArsinh t ∧ myArsinh t ≤ t := by intro t ht constructor · let f : ℝ → ℝ := fun x => myArsinh x - x / Real.sqrt (t ^ 2 + 1) have hdf : ∀ x, HasDerivAt f (1 / Real.sqrt (x ^ 2 + 1) - 1 / Real.sqrt (t ^ 2 + 1)) x := by intro x exact (hasDerivAt_myArsinh x).fun_sub ((hasDerivAt_id x).div_const (Real.sqrt (t ^ 2 + 1))) have hf : MonotoneOn f (Set.Icc 0 t) := by refine monotoneOn_of_deriv_nonneg (convex_Icc 0 t) (fun x _ => (hdf x).continuousAt.continuousWithinAt) (fun x _ => (hdf x).differentiableAt.differentiableWithinAt) ?_ intro x hx have hmem : x ∈ Set.Icc 0 t := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hx) rw [(hdf x).deriv, sub_nonneg] apply div_le_div_of_nonneg_left zero_le_one (Real.sqrt_pos.mpr (by positivity)) exact Real.sqrt_le_sqrt (by nlinarith [hmem.1, hmem.2]) have h0t := hf (Set.left_mem_Icc.mpr ht) (Set.right_mem_Icc.mpr ht) ht simp only [f, myArsinh_zero, zero_div, sub_self] at h0t linarith · let g : ℝ → ℝ := fun x => x - myArsinh x have hdg : ∀ x, HasDerivAt g (1 - 1 / Real.sqrt (x ^ 2 + 1)) x := fun x => (hasDerivAt_id x).fun_sub (hasDerivAt_myArsinh x) have hg : Monotone g := monotone_of_deriv_nonneg (fun x => (hdg x).differentiableAt) (fun x => by rw [(hdg x).deriv, sub_nonneg] have h1 : (1 : ℝ) ≤ Real.sqrt (x ^ 2 + 1) := calc (1 : ℝ) = Real.sqrt 1 := Real.sqrt_one.symm _ ≤ Real.sqrt (x ^ 2 + 1) := Real.sqrt_le_sqrt (by linarith [sq_nonneg x]) exact div_le_one_of_le₀ h1 (Real.sqrt_nonneg _)) have h0t := hg ht simp only [g, myArsinh_zero, sub_self] at h0t linarith constructor · let f : ℝ → ℝ := fun x => hypH x - x ^ 2 / (2 * Real.sqrt (u ^ 2 + 1)) have hdf : ∀ x, HasDerivAt f (myArsinh x - x / Real.sqrt (u ^ 2 + 1)) x := by intro x have h2 : HasDerivAt (fun y => y ^ 2 / (2 * Real.sqrt (u ^ 2 + 1))) (x / Real.sqrt (u ^ 2 + 1)) x := (((hasDerivAt_id' x).fun_pow 2).div_const (2 * Real.sqrt (u ^ 2 + 1))).congr_deriv (by ring) exact (hasDerivAt_hypH x).fun_sub h2 have hf : MonotoneOn f (Set.Icc 0 u) := by refine monotoneOn_of_deriv_nonneg (convex_Icc 0 u) (fun x _ => (hdf x).continuousAt.continuousWithinAt) (fun x _ => (hdf x).differentiableAt.differentiableWithinAt) ?_ intro x hx have hmem : x ∈ Set.Icc 0 u := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hx) rw [(hdf x).deriv, sub_nonneg] have h1 := (harsinh_bounds x hmem.1).1 have h2 : x / Real.sqrt (u ^ 2 + 1) ≤ x / Real.sqrt (x ^ 2 + 1) := by apply div_le_div_of_nonneg_left hmem.1 (Real.sqrt_pos.mpr (by positivity)) exact Real.sqrt_le_sqrt (by nlinarith [hmem.1, hmem.2]) exact le_trans h2 h1 have h0u := hf (Set.left_mem_Icc.mpr hu) (Set.right_mem_Icc.mpr hu) hu simp only [f, hypH_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, zero_div, sub_self] at h0u linarith · let g : ℝ → ℝ := fun x => x ^ 2 / 2 - hypH x have hdg : ∀ x, HasDerivAt g (x - myArsinh x) x := by intro x have h1 : HasDerivAt (fun y => y ^ 2 / 2) x x := (((hasDerivAt_id' x).fun_pow 2).div_const (2 : ℝ)).congr_deriv (by ring) exact h1.fun_sub (hasDerivAt_hypH x) have hg : MonotoneOn g (Set.Icc 0 u) := by refine monotoneOn_of_deriv_nonneg (convex_Icc 0 u) (fun x _ => (hdg x).continuousAt.continuousWithinAt) (fun x _ => (hdg x).differentiableAt.differentiableWithinAt) ?_ intro x hx have hmem : x ∈ Set.Icc 0 u := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hx) rw [(hdg x).deriv, sub_nonneg] exact (harsinh_bounds x hmem.1).2 have h0u := hg (Set.left_mem_Icc.mpr hu) (Set.right_mem_Icc.mpr hu) hu simp only [g, hypH_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, zero_div, sub_self] at h0u linarith /-- **Theorem 2.8 (Exact Non-Asymptotic `ℓ₂` / Kernel-Regime Sandwich for `q_α`).** -/ theorem hypentropy_l2_exact_sandwich {d : ℕ} {α : ℝ} (hα : 0 < α) (w : Fin d → ℝ) : (1 / (8 * α ^ 2)) * ∑ i : Fin d, (w i) ^ 2 / Real.sqrt ((w i / (2 * α ^ 2)) ^ 2 + 1) ≤ hypEntropy α w ∧ hypEntropy α w ≤ normSq w / (8 * α ^ 2) := by constructor · unfold hypEntropy phiAlpha rw [Finset.mul_sum] refine Finset.sum_le_sum fun i _ => ?_ have hlo := (hypH_l2_sandwich (w i / (2 * α ^ 2))).1 have hmul := mul_le_mul_of_nonneg_left hlo (sq_nonneg α) have heq : α ^ 2 * ((w i / (2 * α ^ 2)) ^ 2 / (2 * Real.sqrt ((w i / (2 * α ^ 2)) ^ 2 + 1))) = 1 / (8 * α ^ 2) * ((w i) ^ 2 / Real.sqrt ((w i / (2 * α ^ 2)) ^ 2 + 1)) := by field_simp [ne_of_gt hα]; ring linarith · unfold hypEntropy phiAlpha normSq rw [Finset.sum_div] refine Finset.sum_le_sum fun i _ => ?_ have hhi := (hypH_l2_sandwich (w i / (2 * α ^ 2))).2 have hmul := mul_le_mul_of_nonneg_left hhi (sq_nonneg α) have heq : α ^ 2 * ((w i / (2 * α ^ 2)) ^ 2 / 2) = (w i) ^ 2 / (8 * α ^ 2) := by field_simp [ne_of_gt hα]; ring linarith /-- **Theorem 2.9 (Exact Non-Asymptotic `ℓ₂` Interpolator Convergence as `α → ∞`).** -/ theorem hypentropy_l2_interpolator_convergence {n d : ℕ} {α M : ℝ} (hα : 0 < α) (_hM : 0 ≤ M) (X : Matrix (Fin n) (Fin d) ℝ) (y : Fin n → ℝ) (v : Fin n → ℝ) (wα : Fin d → ℝ) (h_interp_2 : X.mulVec (X.transpose.mulVec v) = y) (h_interp_α : X.mulVec wα = y) (h_min : hypEntropy α wα ≤ hypEntropy α (X.transpose.mulVec v)) (h_bound : ∀ i, |wα i| ≤ M) : normSq (wα - X.transpose.mulVec v) ≤ normSq (X.transpose.mulVec v) * M ^ 2 / (8 * α ^ 4) := by set w₂ := X.transpose.mulVec v have hpyth := min_norm_interpolator_pythagorean X y v wα h_interp_2 h_interp_α have hlo := (hypentropy_l2_exact_sandwich hα wα).1 have hhi := (hypentropy_l2_exact_sandwich hα w₂).2 set R := Real.sqrt ((M / (2 * α ^ 2)) ^ 2 + 1) have hR_pos : 0 < R := Real.sqrt_pos.mpr (by positivity) have hsum_ge : normSq wα / R ≤ ∑ i : Fin d, (wα i) ^ 2 / Real.sqrt ((wα i / (2 * α ^ 2)) ^ 2 + 1) := by unfold normSq; rw [Finset.sum_div] refine Finset.sum_le_sum fun i _ => ?_ apply div_le_div_of_nonneg_left (sq_nonneg _) (Real.sqrt_pos.mpr (by positivity)) apply Real.sqrt_le_sqrt have hwi : (wα i) ^ 2 ≤ M ^ 2 := by have := h_bound i; nlinarith [sq_abs (wα i), abs_nonneg (wα i)] have hdiv : (wα i / (2 * α ^ 2)) ^ 2 ≤ (M / (2 * α ^ 2)) ^ 2 := by rw [div_pow, div_pow] exact div_le_div_of_nonneg_right hwi (by positivity) linarith have hchain : (1 / (8 * α ^ 2)) * (normSq wα / R) ≤ normSq w₂ / (8 * α ^ 2) := by calc (1 / (8 * α ^ 2)) * (normSq wα / R) ≤ (1 / (8 * α ^ 2)) * ∑ i : Fin d, (wα i) ^ 2 / Real.sqrt ((wα i / (2 * α ^ 2)) ^ 2 + 1) := mul_le_mul_of_nonneg_left hsum_ge (by positivity) _ ≤ hypEntropy α wα := hlo _ ≤ hypEntropy α w₂ := h_min _ ≤ normSq w₂ / (8 * α ^ 2) := hhi have hnorm_le : normSq wα ≤ R * normSq w₂ := by have h8 : 0 < 8 * α ^ 2 := by positivity have h1 := mul_le_mul_of_nonneg_left hchain (le_of_lt h8) have h2 : 8 * α ^ 2 * (1 / (8 * α ^ 2) * (normSq wα / R)) = normSq wα / R := by field_simp [ne_of_gt hα] have h3 : 8 * α ^ 2 * (normSq w₂ / (8 * α ^ 2)) = normSq w₂ := by field_simp [ne_of_gt hα] rw [h2, h3] at h1 have h4 := (div_le_iff₀ hR_pos).mp h1 linarith have hR_ge1 : 1 ≤ R := by rw [← Real.sqrt_one]; exact Real.sqrt_le_sqrt (by linarith [sq_nonneg (M / (2 * α ^ 2))]) have hR_sub : R - 1 ≤ M ^ 2 / (8 * α ^ 4) := by have hRsq : R ^ 2 = (M / (2 * α ^ 2)) ^ 2 + 1 := Real.sq_sqrt (by positivity) have hmul : (R - 1) * (R + 1) = M ^ 2 / (4 * α ^ 4) := by have : (R - 1) * (R + 1) = R ^ 2 - 1 := by ring rw [this, hRsq]; field_simp [ne_of_gt hα]; ring have h2 : (R - 1) * 2 ≤ (R - 1) * (R + 1) := by nlinarith have hdiv2 : M ^ 2 / (4 * α ^ 4) / 2 = M ^ 2 / (8 * α ^ 4) := by ring linarith have hdiff : normSq (wα - w₂) ≤ (R - 1) * normSq w₂ := by linarith have hfinal := mul_le_mul_of_nonneg_right hR_sub (normSq_nonneg w₂) linarith [show M ^ 2 / (8 * α ^ 4) * normSq w₂ = normSq w₂ * M ^ 2 / (8 * α ^ 4) by ring] /-- Coordinate `ℓ₁` exact two-sided sandwich for `phiAlpha`. -/ lemma phiAlpha_l1_sandwich {α : ℝ} (hα0 : 0 < α) (hα1 : α ≤ 1) (x : ℝ) : |x| * Real.log (1 / α) - (1 - α ^ 2) ^ 2 / 2 ≤ phiAlpha α x ∧ phiAlpha α x ≤ |x| * Real.log (1 / α) + (1 / 2) * |x| * Real.log (|x| + 1) := by have heven : phiAlpha α x = phiAlpha α |x| := by unfold phiAlpha by_cases hx : 0 ≤ x · rw [abs_of_nonneg hx] · rw [abs_of_neg (not_le.mp hx)] have hneg : -x / (2 * α ^ 2) = -(x / (2 * α ^ 2)) := by ring rw [hneg, hypH_even] rw [heven] set u := |x| have hu : 0 ≤ u := abs_nonneg x have hrew : phiAlpha α u - u * Real.log (1 / α) = (1 / 2) * (u * Real.log ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) - Real.sqrt (u ^ 2 + 4 * α ^ 4) + 2 * α ^ 2) := by unfold phiAlpha hypH myArsinh have hα2 : 0 < 2 * α ^ 2 := by positivity have hrt : 2 * α ^ 2 * Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1) = Real.sqrt (u ^ 2 + 4 * α ^ 4) := by have hsq1 : (2 * α ^ 2 * Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1)) ^ 2 = u ^ 2 + 4 * α ^ 4 := by rw [mul_pow, Real.sq_sqrt (by positivity)]; field_simp [ne_of_gt hα0]; ring have hsq2 : Real.sqrt (u ^ 2 + 4 * α ^ 4) ^ 2 = u ^ 2 + 4 * α ^ 4 := Real.sq_sqrt (by positivity) nlinarith [mul_nonneg (le_of_lt hα2) (Real.sqrt_nonneg ((u / (2 * α ^ 2)) ^ 2 + 1)), Real.sqrt_nonneg (u ^ 2 + 4 * α ^ 4)] have harg : u / (2 * α ^ 2) + Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1) = ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) / (α ^ 2) := by rw [← hrt]; field_simp [ne_of_gt hα0] have hnum_pos : 0 < (u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2 := by positivity rw [harg, Real.log_div (ne_of_gt hnum_pos) (by positivity), Real.log_pow, one_div, Real.log_inv] have hterm : α ^ 2 * Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1) = (1 / 2) * Real.sqrt (u ^ 2 + 4 * α ^ 4) := by linarith push_cast calc α ^ 2 * (u / (2 * α ^ 2) * (Real.log ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) - 2 * Real.log α) - Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1) + 1) - u * -Real.log α = (1 / 2) * u * (Real.log ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) - 2 * Real.log α) - (α ^ 2 * Real.sqrt ((u / (2 * α ^ 2)) ^ 2 + 1)) + α ^ 2 + u * Real.log α := by field_simp [ne_of_gt hα0]; ring _ = _ := by rw [hterm]; ring let ψ : ℝ → ℝ := fun t => t * Real.log ((t + Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2) - Real.sqrt (t ^ 2 + 4 * α ^ 4) + 2 * α ^ 2 have hderiv_ψ : ∀ t : ℝ, HasDerivAt ψ (Real.log ((t + Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2)) t := by intro t have h4 : 0 < t ^ 2 + 4 * α ^ 4 := by positivity have hrt_pos : 0 < Real.sqrt (t ^ 2 + 4 * α ^ 4) := Real.sqrt_pos.mpr h4 have harg_pos : 0 < (t + Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2 := by have h1 : |t| < Real.sqrt (t ^ 2 + 4 * α ^ 4) := by have : |t| ^ 2 < Real.sqrt (t ^ 2 + 4 * α ^ 4) ^ 2 := by rw [sq_abs, Real.sq_sqrt (le_of_lt h4)]; linarith [show 0 < 4 * α ^ 4 by positivity] nlinarith [abs_nonneg t, Real.sqrt_nonneg (t ^ 2 + 4 * α ^ 4)] linarith [neg_abs_le t] have hinner : HasDerivAt (fun y => y ^ 2 + 4 * α ^ 4) (2 * t) t := (((hasDerivAt_id' t).fun_pow 2).add_const (4 * α ^ 4)).congr_deriv (by ring) have hrt : HasDerivAt (fun y => Real.sqrt (y ^ 2 + 4 * α ^ 4)) (t / Real.sqrt (t ^ 2 + 4 * α ^ 4)) t := by refine (hasDerivAt_sqrt_comp hinner h4).congr_deriv ?_ field_simp [ne_of_gt hrt_pos] have harg : HasDerivAt (fun y => (y + Real.sqrt (y ^ 2 + 4 * α ^ 4)) / 2) ((1 + t / Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2) t := ((hasDerivAt_id' t).fun_add hrt).div_const 2 have hlog := harg.log (ne_of_gt harg_pos) have hprod := (hasDerivAt_id' t).fun_mul hlog refine ((hprod.fun_sub hrt).add_const (2 * α ^ 2)).congr_deriv ?_ have harg_ne : t + Real.sqrt (t ^ 2 + 4 * α ^ 4) ≠ 0 := by linarith field_simp [ne_of_gt hrt_pos, harg_ne] ring constructor · set t₀ := 1 - α ^ 4 have hrt_t₀ : Real.sqrt (t₀ ^ 2 + 4 * α ^ 4) = 1 + α ^ 4 := by have hid : t₀ ^ 2 + 4 * α ^ 4 = (1 + α ^ 4) ^ 2 := by simp [t₀]; ring rw [hid, Real.sqrt_sq (by positivity)] have hψ_t₀ : ψ t₀ = -(1 - α ^ 2) ^ 2 := by simp only [ψ, hrt_t₀] have h1 : (t₀ + (1 + α ^ 4)) / 2 = 1 := by simp [t₀] rw [h1, Real.log_one, mul_zero, zero_sub] ring have harg_mono : ∀ t, (t ≤ t₀ → (t + Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2 ≤ 1) ∧ (t₀ ≤ t → 1 ≤ (t + Real.sqrt (t ^ 2 + 4 * α ^ 4)) / 2) := by intro t have harg_mono_fn : Monotone (fun y => y + Real.sqrt (y ^ 2 + 4 * α ^ 4)) := by have hda : ∀ y, HasDerivAt (fun x => x + Real.sqrt (x ^ 2 + 4 * α ^ 4)) (1 + y / Real.sqrt (y ^ 2 + 4 * α ^ 4)) y := by intro y have h4 : 0 < y ^ 2 + 4 * α ^ 4 := by positivity have hrt_pos : 0 < Real.sqrt (y ^ 2 + 4 * α ^ 4) := Real.sqrt_pos.mpr h4 have hinner : HasDerivAt (fun x => x ^ 2 + 4 * α ^ 4) (2 * y) y := (((hasDerivAt_id' y).fun_pow 2).add_const (4 * α ^ 4)).congr_deriv (by ring) have hrt : HasDerivAt (fun x => Real.sqrt (x ^ 2 + 4 * α ^ 4)) (y / Real.sqrt (y ^ 2 + 4 * α ^ 4)) y := by refine (hasDerivAt_sqrt_comp hinner h4).congr_deriv ?_ field_simp [ne_of_gt hrt_pos] exact (hasDerivAt_id' y).fun_add hrt refine monotone_of_deriv_nonneg (fun y => (hda y).differentiableAt) fun y => ?_ rw [(hda y).deriv] have h4 : 0 < y ^ 2 + 4 * α ^ 4 := by positivity have hrt_pos : 0 < Real.sqrt (y ^ 2 + 4 * α ^ 4) := Real.sqrt_pos.mpr h4 have hlt : |y| ≤ Real.sqrt (y ^ 2 + 4 * α ^ 4) := by have : |y| ^ 2 ≤ Real.sqrt (y ^ 2 + 4 * α ^ 4) ^ 2 := by rw [sq_abs, Real.sq_sqrt (le_of_lt h4)]; linarith [show 0 < 4 * α ^ 4 by positivity] nlinarith [abs_nonneg y, Real.sqrt_nonneg (y ^ 2 + 4 * α ^ 4)] have hge : -1 ≤ y / Real.sqrt (y ^ 2 + 4 * α ^ 4) := by rw [le_div_iff₀ hrt_pos]; linarith [neg_abs_le y] linarith have hval_t₀ : t₀ + Real.sqrt (t₀ ^ 2 + 4 * α ^ 4) = 2 := by rw [hrt_t₀]; simp [t₀]; norm_num constructor · intro hle; linarith [harg_mono_fn hle] · intro hge; linarith [harg_mono_fn hge] have hψ_ge : ψ t₀ ≤ ψ u := by rcases le_total u t₀ with hle | hge · have hanti : AntitoneOn ψ (Set.Icc u t₀) := by refine antitoneOn_of_deriv_nonpos (convex_Icc u t₀) (fun y _ => (hderiv_ψ y).continuousAt.continuousWithinAt) (fun y _ => (hderiv_ψ y).differentiableAt.differentiableWithinAt) ?_ intro y hy have hmem : y ∈ Set.Icc u t₀ := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hy) rw [(hderiv_ψ y).deriv] have hpos : 0 < (y + Real.sqrt (y ^ 2 + 4 * α ^ 4)) / 2 := by have h1 : |y| < Real.sqrt (y ^ 2 + 4 * α ^ 4) := by have : |y| ^ 2 < Real.sqrt (y ^ 2 + 4 * α ^ 4) ^ 2 := by rw [sq_abs, Real.sq_sqrt (by positivity)]; linarith [show 0 < 4 * α ^ 4 by positivity] nlinarith [abs_nonneg y, Real.sqrt_nonneg (y ^ 2 + 4 * α ^ 4)] linarith [neg_abs_le y] exact Real.log_nonpos (le_of_lt hpos) ((harg_mono y).1 hmem.2) exact hanti (Set.left_mem_Icc.mpr hle) (Set.right_mem_Icc.mpr hle) hle · have hmono : MonotoneOn ψ (Set.Icc t₀ u) := by refine monotoneOn_of_deriv_nonneg (convex_Icc t₀ u) (fun y _ => (hderiv_ψ y).continuousAt.continuousWithinAt) (fun y _ => (hderiv_ψ y).differentiableAt.differentiableWithinAt) ?_ intro y hy have hmem : y ∈ Set.Icc t₀ u := Set.Ioo_subset_Icc_self (by simpa [interior_Icc] using hy) rw [(hderiv_ψ y).deriv] exact Real.log_nonneg ((harg_mono y).2 hmem.1) exact hmono (Set.left_mem_Icc.mpr hge) (Set.right_mem_Icc.mpr hge) hge have hψ_bound : -(1 - α ^ 2) ^ 2 ≤ ψ u := by rwa [← hψ_t₀] linarith [hrew] · have hrt_le : Real.sqrt (u ^ 2 + 4 * α ^ 4) ≤ u + 2 * α ^ 2 := by have hsq : Real.sqrt (u ^ 2 + 4 * α ^ 4) ^ 2 ≤ (u + 2 * α ^ 2) ^ 2 := by rw [Real.sq_sqrt (by positivity)] nlinarith [sq_nonneg α] nlinarith [Real.sqrt_nonneg (u ^ 2 + 4 * α ^ 4)] have hrt_ge : 2 * α ^ 2 ≤ Real.sqrt (u ^ 2 + 4 * α ^ 4) := by have hsq : (2 * α ^ 2) ^ 2 ≤ Real.sqrt (u ^ 2 + 4 * α ^ 4) ^ 2 := by rw [Real.sq_sqrt (by positivity)]; nlinarith nlinarith [Real.sqrt_nonneg (u ^ 2 + 4 * α ^ 4)] have harg_le : (u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2 ≤ u + 1 := by have hαsq : α ^ 2 ≤ 1 := by nlinarith linarith have hlog_le : Real.log ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) ≤ Real.log (u + 1) := Real.log_le_log (by positivity) harg_le have hmul_le : u * Real.log ((u + Real.sqrt (u ^ 2 + 4 * α ^ 4)) / 2) ≤ u * Real.log (u + 1) := mul_le_mul_of_nonneg_left hlog_le hu linarith [hrew] /-- **Theorem 2.10 (Exact Non-Asymptotic `ℓ₁` / Rich-Regime Sandwich & Exact Tightness).** -/ theorem hypentropy_l1_exact_sandwich_and_tightness {d : ℕ} {α : ℝ} (hα0 : 0 < α) (hα1 : α ≤ 1) : (∀ w : Fin d → ℝ, l1Norm w * Real.log (1 / α) - (d : ℝ) * (1 - α ^ 2) ^ 2 / 2 ≤ hypEntropy α w ∧ hypEntropy α w ≤ l1Norm w * Real.log (1 / α) + (1 / 2) * ∑ i : Fin d, |w i| * Real.log (|w i| + 1)) ∧ hypEntropy α (fun _ : Fin d => 1 - α ^ 4) = l1Norm (fun _ : Fin d => 1 - α ^ 4) * Real.log (1 / α) - (d : ℝ) * (1 - α ^ 2) ^ 2 / 2 := by constructor · intro w constructor · unfold hypEntropy l1Norm rw [Finset.sum_mul] have hconst : (d : ℝ) * (1 - α ^ 2) ^ 2 / 2 = ∑ _i : Fin d, (1 - α ^ 2) ^ 2 / 2 := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]; ring rw [hconst, ← Finset.sum_sub_distrib] exact Finset.sum_le_sum fun i _ => (phiAlpha_l1_sandwich hα0 hα1 (w i)).1 · unfold hypEntropy l1Norm rw [Finset.sum_mul, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_le_sum fun i _ => ?_ have hhi := (phiAlpha_l1_sandwich hα0 hα1 (w i)).2 linarith · have ht0_nn : 0 ≤ 1 - α ^ 4 := by have hα2 : α ^ 2 ≤ 1 := by nlinarith nlinarith [sq_nonneg α, hα2] have hpt : phiAlpha α (1 - α ^ 4) = (1 - α ^ 4) * Real.log (1 / α) - (1 - α ^ 2) ^ 2 / 2 := by unfold phiAlpha hypH myArsinh have hrt : Real.sqrt (((1 - α ^ 4) / (2 * α ^ 2)) ^ 2 + 1) = (1 + α ^ 4) / (2 * α ^ 2) := by have hid : ((1 - α ^ 4) / (2 * α ^ 2)) ^ 2 + 1 = ((1 + α ^ 4) / (2 * α ^ 2)) ^ 2 := by field_simp [ne_of_gt hα0]; ring rw [hid, Real.sqrt_sq (by positivity)] rw [hrt] have harg : (1 - α ^ 4) / (2 * α ^ 2) + (1 + α ^ 4) / (2 * α ^ 2) = (α ^ 2)⁻¹ := by field_simp [ne_of_gt hα0]; ring rw [harg, Real.log_inv, Real.log_pow, one_div, Real.log_inv] push_cast field_simp [ne_of_gt hα0] ring unfold hypEntropy l1Norm simp_rw [hpt, abs_of_nonneg ht0_nn, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] ring /-- **Theorem 2.11 (Exact Non-Asymptotic `ℓ₁` Interpolator Convergence as `α → 0`).** -/ theorem hypentropy_l1_interpolator_convergence {d : ℕ} {α M : ℝ} (hα0 : 0 < α) (hα1 : α < 1) (wα w₁ : Fin d → ℝ) (h_min_q : hypEntropy α wα ≤ hypEntropy α w₁) (h_min_l1 : l1Norm w₁ ≤ l1Norm wα) (h_bound : ∀ i, |w₁ i| ≤ M) : 0 ≤ l1Norm wα - l1Norm w₁ ∧ l1Norm wα - l1Norm w₁ ≤ ((d : ℝ) * (1 - α ^ 2) ^ 2 + l1Norm w₁ * Real.log (M + 1)) / (2 * Real.log (1 / α)) := by have hlog_pos : 0 < Real.log (1 / α) := Real.log_pos ((one_lt_div hα0).mpr hα1) have hlo := ((hypentropy_l1_exact_sandwich_and_tightness (d := d) hα0 (le_of_lt hα1)).1 wα).1 have hhi := ((hypentropy_l1_exact_sandwich_and_tightness (d := d) hα0 (le_of_lt hα1)).1 w₁).2 have hsum_le : ∑ i : Fin d, |w₁ i| * Real.log (|w₁ i| + 1) ≤ l1Norm w₁ * Real.log (M + 1) := by unfold l1Norm; rw [Finset.sum_mul] refine Finset.sum_le_sum fun i _ => ?_ exact mul_le_mul_of_nonneg_left (Real.log_le_log (by linarith [abs_nonneg (w₁ i)]) (by linarith [h_bound i])) (abs_nonneg _) constructor · linarith · rw [le_div_iff₀ (by positivity)] linarith /-- **Theorem 2.12 (Exact Closed-Form 2D Phase-Transition Witness: `w₁ + 2 w₂ = 1`).** -/ theorem hypentropy_2d_exact_phase_transition_witness {s : ℝ} (hs : 0 < s) : let sh := (Real.exp s - Real.exp (-s)) / 2 let ch := (Real.exp s + Real.exp (-s)) / 2 let α := Real.sqrt (1 / (2 * sh * (1 + 4 * ch))) let wStar : Fin 2 → ℝ := ![1 / (1 + 4 * ch), 2 * ch / (1 + 4 * ch)] let X : Matrix (Fin 1) (Fin 2) ℝ := Matrix.of ![![1, 2]] let y : Fin 1 → ℝ := ![1] 0 < α ∧ X.mulVec wStar = y ∧ wStar 1 / wStar 0 = 2 * ch ∧ 2 < wStar 1 / wStar 0 ∧ (∀ w : Fin 2 → ℝ, X.mulVec w = y → hypEntropy α wStar ≤ hypEntropy α w) := by dsimp only set sh := (Real.exp s - Real.exp (-s)) / 2 set ch := (Real.exp s + Real.exp (-s)) / 2 have hexp_gt : 1 < Real.exp s := Real.one_lt_exp_iff.mpr hs have hexp_inv : Real.exp (-s) = (Real.exp s)⁻¹ := Real.exp_neg s have hsh_pos : 0 < sh := by have : Real.exp (-s) < 1 := by rw [hexp_inv]; exact inv_lt_one_of_one_lt₀ hexp_gt simp only [sh]; linarith have hch_gt1 : 1 < ch := by have hmul : Real.exp s * Real.exp (-s) = 1 := by rw [← Real.exp_add]; simp have hne : Real.exp s - 1 ≠ 0 := by linarith have hsq : 0 < (Real.exp s - 1) ^ 2 := sq_pos_of_ne_zero hne have : 2 < Real.exp s + Real.exp (-s) := by have hexp_pos : 0 < Real.exp s := Real.exp_pos s nlinarith simp only [ch]; linarith have hch_pos : 0 < ch := by linarith have hden_pos : 0 < 1 + 4 * ch := by linarith have hα2_pos : 0 < 1 / (2 * sh * (1 + 4 * ch)) := by positivity set α := Real.sqrt (1 / (2 * sh * (1 + 4 * ch))) have hα_pos : 0 < α := Real.sqrt_pos.mpr hα2_pos have hαsq : α ^ 2 = 1 / (2 * sh * (1 + 4 * ch)) := Real.sq_sqrt (le_of_lt hα2_pos) set wStar : Fin 2 → ℝ := ![1 / (1 + 4 * ch), 2 * ch / (1 + 4 * ch)] set X : Matrix (Fin 1) (Fin 2) ℝ := Matrix.of ![![1, 2]] set y : Fin 1 → ℝ := ![1] have hinterp : X.mulVec wStar = y := by ext i fin_cases i simp [X, y, wStar, Matrix.mulVec, dotProduct, Fin.sum_univ_two] field_simp [ne_of_gt hden_pos]; ring have hratio : wStar 1 / wStar 0 = 2 * ch := by simp only [wStar, Matrix.cons_val_zero, Matrix.cons_val_one] field_simp [ne_of_gt hden_pos] refine ⟨hα_pos, hinterp, hratio, by linarith, ?_⟩ have harsinh_sh : ∀ t : ℝ, 0 < t → myArsinh ((Real.exp t - Real.exp (-t)) / 2) = t := by intro t _ unfold myArsinh have hmul : Real.exp t * Real.exp (-t) = 1 := by rw [← Real.exp_add]; simp have hid : ((Real.exp t - Real.exp (-t)) / 2) ^ 2 + 1 = ((Real.exp t + Real.exp (-t)) / 2) ^ 2 := by nlinarith rw [hid, Real.sqrt_sq (by positivity)] have hsum : (Real.exp t - Real.exp (-t)) / 2 + (Real.exp t + Real.exp (-t)) / 2 = Real.exp t := by ring rw [hsum, Real.log_exp] have hkkt : ∀ j : Fin 2, (1 / 2) * myArsinh (wStar j / (2 * α ^ 2)) = (X.transpose.mulVec ![s / 2]) j := by intro j fin_cases j · change (1 / 2) * myArsinh (wStar 0 / (2 * α ^ 2)) = (X.transpose.mulVec ![s / 2]) 0 have hw0 : wStar 0 = 1 / (1 + 4 * ch) := rfl have hxt0 : (X.transpose.mulVec ![s / 2]) 0 = 1 * (s / 2) := by simp [X, Matrix.mulVec, dotProduct] rw [hw0, hxt0] have harg0 : 1 / (1 + 4 * ch) / (2 * α ^ 2) = sh := by rw [hαsq]; field_simp [ne_of_gt hden_pos, ne_of_gt hsh_pos] rw [harg0, harsinh_sh s hs]; ring · change (1 / 2) * myArsinh (wStar 1 / (2 * α ^ 2)) = (X.transpose.mulVec ![s / 2]) 1 have hw1 : wStar 1 = 2 * ch / (1 + 4 * ch) := rfl have hxt1 : (X.transpose.mulVec ![s / 2]) 1 = 2 * (s / 2) := by simp [X, Matrix.mulVec, dotProduct] rw [hw1, hxt1] have hsh2 : 2 * sh * ch = (Real.exp (2 * s) - Real.exp (-(2 * s))) / 2 := by simp only [sh, ch] have h1 : Real.exp (2 * s) = Real.exp s * Real.exp s := by rw [← Real.exp_add]; congr 1; ring have h2 : Real.exp (-(2 * s)) = Real.exp (-s) * Real.exp (-s) := by rw [← Real.exp_add]; congr 1; ring rw [h1, h2]; ring have harg1 : 2 * ch / (1 + 4 * ch) / (2 * α ^ 2) = (Real.exp (2 * s) - Real.exp (-(2 * s))) / 2 := by rw [hαsq, ← hsh2]; field_simp [ne_of_gt hden_pos, ne_of_gt hsh_pos] rw [harg1, harsinh_sh (2 * s) (by linarith)]; ring intro w hw exact (hypentropy_kkt_unique_minimizer hα_pos X y wStar ![s / 2] hinterp hkkt w hw).1 end Pillar2B /-! ============================================================================ SECTION 3: EXACT MODULAR-ADDITION FOURIER GROKKING MARGIN VS. MEMORIZATION CAPACITY GAP (SHARPENING MORWANI ET AL. 2024) ============================================================================ -/ section Pillar3 /-- Squared `ℓ₂` norm on `ZMod p → ℝ`. -/ def zNormSq {p : ℕ} [NeZero p] (u : ZMod p → ℝ) : ℝ := ∑ a : ZMod p, (u a) ^ 2 /-- Euclidean `ℓ₂` norm on `ZMod p → ℝ`. -/ noncomputable def zNorm {p : ℕ} [NeZero p] (u : ZMod p → ℝ) : ℝ := Real.sqrt (zNormSq u) lemma zNormSq_nonneg {p : ℕ} [NeZero p] (u : ZMod p → ℝ) : 0 ≤ zNormSq u := Finset.sum_nonneg fun _ _ => sq_nonneg _ lemma zNorm_nonneg {p : ℕ} [NeZero p] (u : ZMod p → ℝ) : 0 ≤ zNorm u := Real.sqrt_nonneg _ lemma zNorm_sq {p : ℕ} [NeZero p] (u : ZMod p → ℝ) : (zNorm u) ^ 2 = zNormSq u := Real.sq_sqrt (zNormSq_nonneg u) /-- Mean-centered output weights `w̃(c) = w(c) - (1/p) ∑_r w(r)`. -/ noncomputable def zCentered {p : ℕ} [NeZero p] (w : ZMod p → ℝ) (c : ZMod p) : ℝ := w c - (∑ r : ZMod p, w r) / (p : ℝ) lemma zCentered_sum_zero {p : ℕ} [NeZero p] (w : ZMod p → ℝ) : ∑ c : ZMod p, zCentered w c = 0 := by have hp : (p : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne p unfold zCentered rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul] field_simp [hp]; ring lemma zCentered_normSq_le {p : ℕ} [NeZero p] (w : ZMod p → ℝ) : zNormSq (zCentered w) ≤ zNormSq w := by have hp : 0 < (p : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne p) set μ := (∑ r : ZMod p, w r) / (p : ℝ) have hpyth : zNormSq w = zNormSq (zCentered w) + (p : ℝ) * μ ^ 2 := by unfold zNormSq zCentered have hpt : ∀ c : ZMod p, (w c) ^ 2 = (w c - μ) ^ 2 + 2 * μ * (w c - μ) + μ ^ 2 := by intro c; ring simp_rw [hpt] rw [Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul] have h0 : ∑ c : ZMod p, (w c - μ) = 0 := zCentered_sum_zero w rw [h0, mul_zero, add_zero] nlinarith [sq_nonneg μ] /-- Sharp single-coordinate centering bound: `|w̃(c)|² ≤ ((p - 1)/p) ‖w‖₂²`. -/ lemma zCentered_coord_sq_le {p : ℕ} [NeZero p] (w : ZMod p → ℝ) (c : ZMod p) : (zCentered w c) ^ 2 ≤ ((p : ℝ) - 1) / (p : ℝ) * zNormSq w := by have hp_pos : 0 < (p : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne p) have hp1 : 1 ≤ p := Nat.one_le_iff_ne_zero.mpr (NeZero.ne p) have hcard_erase : ((Finset.univ.erase c).card : ℝ) = (p : ℝ) - 1 := by rw [Finset.card_erase_of_mem (Finset.mem_univ c), Finset.card_univ, ZMod.card, Nat.cast_sub hp1] simp have hwc_eq : zCentered w c = (1 / (p : ℝ)) * ∑ r ∈ Finset.univ.erase c, (w c - w r) := by unfold zCentered have hsum : ∑ r : ZMod p, w r = w c + ∑ r ∈ Finset.univ.erase c, w r := (Finset.add_sum_erase Finset.univ w (Finset.mem_univ c)).symm rw [hsum, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, hcard_erase] field_simp [ne_of_gt hp_pos]; ring -- Write zCentered w c = ∑ r, α_r w_r where α_c = (p-1)/p, α_{r ≠ c} = -1/p, ∑ α_r² = (p-1)/p let α : ZMod p → ℝ := fun r => if r = c then ((p : ℝ) - 1) / (p : ℝ) else -(1 / (p : ℝ)) have hdot : zCentered w c = ∑ r : ZMod p, α r * w r := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ c)] simp only [α, ↓reduceIte] have hrest : ∑ r ∈ Finset.univ.erase c, (if r = c then ((p : ℝ) - 1) / (p : ℝ) else -(1 / (p : ℝ))) * w r = -(1 / (p : ℝ)) * ∑ r ∈ Finset.univ.erase c, w r := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun r hr => ?_ have hne : r ≠ c := (Finset.mem_erase.mp hr).1 rw [if_neg hne] rw [hrest, hwc_eq, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, hcard_erase] field_simp [ne_of_gt hp_pos]; ring have hα_sq : ∑ r : ZMod p, (α r) ^ 2 = ((p : ℝ) - 1) / (p : ℝ) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ c)] simp only [α, ↓reduceIte] have hrest : ∑ r ∈ Finset.univ.erase c, (if r = c then ((p : ℝ) - 1) / (p : ℝ) else -(1 / (p : ℝ))) ^ 2 = ((p : ℝ) - 1) * (1 / (p : ℝ)) ^ 2 := by have hpt : ∀ r ∈ Finset.univ.erase c, (if r = c then ((p : ℝ) - 1) / (p : ℝ) else -(1 / (p : ℝ))) ^ 2 = (1 / (p : ℝ)) ^ 2 := by intro r hr; rw [if_neg (Finset.mem_erase.mp hr).1]; ring rw [Finset.sum_congr rfl hpt, Finset.sum_const, nsmul_eq_mul, hcard_erase] rw [hrest] field_simp [ne_of_gt hp_pos]; ring rw [hdot] have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ α w rw [hα_sq] at hcs exact hcs /-- Single 2-layer quadratic-activation neuron output `w_c (u_a + v_b)²`. -/ def quadNeuronOut {p : ℕ} [NeZero p] (u v w : ZMod p → ℝ) (a b c : ZMod p) : ℝ := w c * (u a + v b) ^ 2 /-- Width-`m` 2-layer quadratic-activation neural network output on `ZMod p`. -/ def quadNetOut {p m : ℕ} [NeZero p] (U V W : Fin m → ZMod p → ℝ) (a b c : ZMod p) : ℝ := ∑ j : Fin m, quadNeuronOut (U j) (V j) (W j) a b c /-- Single-neuron homogeneous `L_{2,3}³` norm `(‖u‖₂² + ‖v‖₂² + ‖w‖₂²)^{3/2}`. -/ noncomputable def neuronNorm3 {p : ℕ} [NeZero p] (u v w : ZMod p → ℝ) : ℝ := (zNormSq u + zNormSq v + zNormSq w) * Real.sqrt (zNormSq u + zNormSq v + zNormSq w) lemma neuronNorm3_eq_rpow {p : ℕ} [NeZero p] (u v w : ZMod p → ℝ) : neuronNorm3 u v w = (zNormSq u + zNormSq v + zNormSq w) ^ ((3 : ℝ) / 2) := by unfold neuronNorm3 set x := zNormSq u + zNormSq v + zNormSq w have hx : 0 ≤ x := add_nonneg (add_nonneg (zNormSq_nonneg u) (zNormSq_nonneg v)) (zNormSq_nonneg w) have h32 : (3 : ℝ) / 2 = 1 + (1 : ℝ) / 2 := by norm_num rw [h32, Real.rpow_add' hx (by norm_num), Real.rpow_one, ← Real.sqrt_eq_rpow] /-- Network homogeneous `L_{2,3}³` norm `∑_j (‖u_j‖₂² + ‖v_j‖₂² + ‖w_j‖₂²)^{3/2}`. -/ noncomputable def netNorm3 {p m : ℕ} [NeZero p] (U V W : Fin m → ZMod p → ℝ) : ℝ := ∑ j : Fin m, neuronNorm3 (U j) (V j) (W j) /-- Multiclass margin predicate on a subset `S ⊆ (ZMod p)²`. -/ def HasModAddMargin {p m : ℕ} [NeZero p] (U V W : Fin m → ZMod p → ℝ) (S : Finset (ZMod p × ZMod p)) (γ : ℝ) : Prop := ∀ ab ∈ S, ∀ c : ZMod p, c ≠ ab.1 + ab.2 → γ ≤ quadNetOut U V W ab.1 ab.2 (ab.1 + ab.2) - quadNetOut U V W ab.1 ab.2 c /-- Exact 3-variable AM-GM inequality via a single-line SOS identity: `√A √B √C ≤ (A + B + C) √(A + B + C) / (3 √3)`. -/ lemma amgm3_sqrt {A B C : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) : Real.sqrt A * Real.sqrt B * Real.sqrt C ≤ (A + B + C) * Real.sqrt (A + B + C) / (3 * Real.sqrt 3) := by have hpoly : 27 * A * B * C ≤ (A + B + C) ^ 3 := by have hsos : 2 * ((A + B + C) ^ 3 - 27 * A * B * C) = (A + B + 7 * C) * (A - B) ^ 2 + (B + C + 7 * A) * (B - C) ^ 2 + (C + A + 7 * B) * (C - A) ^ 2 := by ring have hnn : 0 ≤ (A + B + 7 * C) * (A - B) ^ 2 + (B + C + 7 * A) * (B - C) ^ 2 + (C + A + 7 * B) * (C - A) ^ 2 := by positivity linarith have h3rt3 : 0 < 3 * Real.sqrt 3 := by positivity rw [le_div_iff₀ h3rt3] have hsq : (Real.sqrt A * Real.sqrt B * Real.sqrt C * (3 * Real.sqrt 3)) ^ 2 ≤ ((A + B + C) * Real.sqrt (A + B + C)) ^ 2 := by have h1 : (Real.sqrt A * Real.sqrt B * Real.sqrt C * (3 * Real.sqrt 3)) ^ 2 = 27 * (Real.sqrt A ^ 2) * (Real.sqrt B ^ 2) * (Real.sqrt C ^ 2) := by have : Real.sqrt 3 ^ 2 = 3 := Real.sq_sqrt (by norm_num) calc (Real.sqrt A * Real.sqrt B * Real.sqrt C * (3 * Real.sqrt 3)) ^ 2 = 9 * (Real.sqrt 3 ^ 2) * (Real.sqrt A ^ 2) * (Real.sqrt B ^ 2) * (Real.sqrt C ^ 2) := by ring _ = _ := by rw [this]; ring have h2 : ((A + B + C) * Real.sqrt (A + B + C)) ^ 2 = (A + B + C) ^ 3 := by rw [mul_pow, Real.sq_sqrt (by linarith)]; ring rw [h1, h2, Real.sq_sqrt hA, Real.sq_sqrt hB, Real.sq_sqrt hC] exact hpoly have hL : 0 ≤ Real.sqrt A * Real.sqrt B * Real.sqrt C * (3 * Real.sqrt 3) := by positivity have hR : 0 ≤ (A + B + C) * Real.sqrt (A + B + C) := by positivity nlinarith /-- **Theorem 3.1 (Exact Algebraic Reduction of Multiclass Margin to Trilinear Convolution).** For any single quadratic neuron `(u, v, w)` on `ZMod p`, the summed multiclass margin over all `(a, b) ∈ (ZMod p)²` and wrong classes `c ≠ a + b` equals EXACTLY `2 p ∑_{a, b} u(a) v(b) w̃(a + b)` (all `u(a)²` and `v(b)²` terms cancel identically!). -/ theorem quad_neuron_sum_margin_eq_convolution {p : ℕ} [NeZero p] (u v w : ZMod p → ℝ) : ∑ a : ZMod p, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNeuronOut u v w a b (a + b) - quadNeuronOut u v w a b c) = 2 * (p : ℝ) * ∑ a : ZMod p, ∑ b : ZMod p, u a * v b * zCentered w (a + b) := by have hp_pos : 0 < (p : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne p) have hinner : ∀ a b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNeuronOut u v w a b (a + b) - quadNeuronOut u v w a b c) = (p : ℝ) * zCentered w (a + b) * (u a + v b) ^ 2 := by intro a b unfold quadNeuronOut zCentered have h1 : ∑ c ∈ Finset.univ.erase (a + b), (w (a + b) * (u a + v b) ^ 2 - w c * (u a + v b) ^ 2) = (∑ c ∈ Finset.univ.erase (a + b), (w (a + b) - w c)) * (u a + v b) ^ 2 := by rw [Finset.sum_mul]; refine Finset.sum_congr rfl fun c _ => ?_; ring rw [h1] congr 1 have hcard : ((Finset.univ.erase (a + b)).card : ℝ) = (p : ℝ) - 1 := by have hp1 : 1 ≤ p := Nat.one_le_iff_ne_zero.mpr (NeZero.ne p) rw [Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ZMod.card, Nat.cast_sub hp1] simp have hsum : ∑ r : ZMod p, w r = w (a + b) + ∑ r ∈ Finset.univ.erase (a + b), w r := (Finset.add_sum_erase Finset.univ w (Finset.mem_univ (a + b))).symm rw [Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, hcard, hsum] field_simp [ne_of_gt hp_pos]; ring simp_rw [hinner] have hexpand : ∀ a b : ZMod p, (p : ℝ) * zCentered w (a + b) * (u a + v b) ^ 2 = (p : ℝ) * (u a) ^ 2 * zCentered w (a + b) + (p : ℝ) * (v b) ^ 2 * zCentered w (a + b) + 2 * (p : ℝ) * (u a * v b * zCentered w (a + b)) := by intro a b; ring simp_rw [hexpand, Finset.sum_add_distrib] have hkill_u : ∑ a : ZMod p, ∑ b : ZMod p, (p : ℝ) * (u a) ^ 2 * zCentered w (a + b) = 0 := by refine Finset.sum_eq_zero fun a _ => ?_ rw [← Finset.mul_sum] have hshift : ∑ b : ZMod p, zCentered w (a + b) = ∑ c : ZMod p, zCentered w c := Equiv.sum_comp (Equiv.addLeft a) (zCentered w) rw [hshift, zCentered_sum_zero, mul_zero] have hkill_v : ∑ a : ZMod p, ∑ b : ZMod p, (p : ℝ) * (v b) ^ 2 * zCentered w (a + b) = 0 := by rw [Finset.sum_comm] refine Finset.sum_eq_zero fun b _ => ?_ rw [← Finset.mul_sum] have hshift : ∑ a : ZMod p, zCentered w (a + b) = ∑ c : ZMod p, zCentered w c := Equiv.sum_comp (Equiv.addRight b) (zCentered w) rw [hshift, zCentered_sum_zero, mul_zero] rw [hkill_u, hkill_v, zero_add, zero_add] simp_rw [← Finset.mul_sum] /-- Corollary: total network margin bound by summed trilinear convolutions. -/ lemma quad_net_margin_le_sum_convolutions {p m : ℕ} [NeZero p] (U V W : Fin m → ZMod p → ℝ) {γ : ℝ} (hmargin : HasModAddMargin U V W Finset.univ γ) : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ ≤ 2 * (p : ℝ) * ∑ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) := by have hp1 : 1 ≤ p := Nat.one_le_iff_ne_zero.mpr (NeZero.ne p) have hcard_erase : ∀ x : ZMod p, ((Finset.univ.erase x).card : ℝ) = (p : ℝ) - 1 := fun x => by rw [Finset.card_erase_of_mem (Finset.mem_univ x), Finset.card_univ, ZMod.card, Nat.cast_sub hp1] simp have hlower : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ ≤ ∑ a : ZMod p, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNetOut U V W a b (a + b) - quadNetOut U V W a b c) := by calc (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ = ∑ a : ZMod p, ∑ b : ZMod p, ∑ _c ∈ Finset.univ.erase (a + b), γ := by have h1 : ∀ a b : ZMod p, ∑ _c ∈ Finset.univ.erase (a + b), γ = ((p : ℝ) - 1) * γ := fun a b => by rw [Finset.sum_const, nsmul_eq_mul, hcard_erase] simp_rw [h1, Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul] ring _ ≤ ∑ a : ZMod p, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNetOut U V W a b (a + b) - quadNetOut U V W a b c) := by refine Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => Finset.sum_le_sum fun c hc => hmargin (a, b) (Finset.mem_univ _) c (Finset.mem_erase.mp hc).1 have hswap : ∑ a : ZMod p, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNetOut U V W a b (a + b) - quadNetOut U V W a b c) = ∑ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNeuronOut (U j) (V j) (W j) a b (a + b) - quadNeuronOut (U j) (V j) (W j) a b c) := by unfold quadNetOut simp_rw [← Finset.sum_sub_distrib] trans (∑ a : ZMod p, ∑ b : ZMod p, ∑ j : Fin m, ∑ c ∈ Finset.univ.erase (a + b), (quadNeuronOut (U j) (V j) (W j) a b (a + b) - quadNeuronOut (U j) (V j) (W j) a b c)) · refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun b _ => Finset.sum_comm · trans (∑ a : ZMod p, ∑ j : Fin m, ∑ b : ZMod p, ∑ c ∈ Finset.univ.erase (a + b), (quadNeuronOut (U j) (V j) (W j) a b (a + b) - quadNeuronOut (U j) (V j) (W j) a b c)) · refine Finset.sum_congr rfl fun a _ => Finset.sum_comm · exact Finset.sum_comm rw [hswap] at hlower simp_rw [quad_neuron_sum_margin_eq_convolution, ← Finset.mul_sum] at hlower exact hlower /-- Primitive `p`-th root of unity `ζ_p = exp(2πi / p)`. -/ noncomputable def zeta (p : ℕ) : ℂ := Complex.exp (2 * Real.pi * Complex.I / (p : ℂ)) lemma zeta_pow_eq_exp (p : ℕ) (k : ℕ) : (zeta p) ^ k = Complex.exp (2 * Real.pi * Complex.I * (k : ℂ) / (p : ℂ)) := by unfold zeta rw [← Complex.exp_nat_mul] congr 1; ring lemma zeta_pow_p {p : ℕ} [NeZero p] : (zeta p) ^ p = 1 := by have hp : (p : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne p rw [zeta_pow_eq_exp] have harg : 2 * Real.pi * Complex.I * (p : ℂ) / (p : ℂ) = 2 * Real.pi * Complex.I := by field_simp [hp] rw [harg, Complex.exp_two_pi_mul_I] lemma zeta_pow_mod {p : ℕ} [NeZero p] (m : ℕ) : (zeta p) ^ (m % p) = (zeta p) ^ m := by have hdiv : m = p * (m / p) + m % p := (Nat.div_add_mod m p).symm conv_rhs => rw [hdiv, pow_add, pow_mul, zeta_pow_p, one_pow, one_mul] lemma zeta_pow_val_add {p : ℕ} [NeZero p] (k : ℕ) (a b : ZMod p) : (zeta p) ^ (k * (a + b).val) = (zeta p) ^ (k * a.val) * (zeta p) ^ (k * b.val) := by rw [← pow_add, ← mul_add, ZMod.val_add] have hmod : (k * ((a.val + b.val) % p)) % p = (k * (a.val + b.val)) % p := by rw [Nat.mul_mod, Nat.mod_mod, ← Nat.mul_mod] rw [← zeta_pow_mod (k * ((a.val + b.val) % p)), hmod, zeta_pow_mod] lemma zeta_pow_conj {p : ℕ} [NeZero p] (m : ℕ) : starRingEnd ℂ ((zeta p) ^ m) = Complex.exp (-(2 * Real.pi * Complex.I * (m : ℂ) / (p : ℂ))) := by rw [zeta_pow_eq_exp, ← Complex.exp_conj] congr 1 simp [Complex.conj_ofReal, map_ofNat] ring lemma zeta_pow_sub_eq_conj {p : ℕ} [NeZero p] {k : ℕ} (hk : k ≤ p) (a : ZMod p) : (zeta p) ^ ((p - k) * a.val) = starRingEnd ℂ ((zeta p) ^ (k * a.val)) := by have hprod : (zeta p) ^ ((p - k) * a.val) * (zeta p) ^ (k * a.val) = 1 := by rw [← pow_add, ← add_mul, Nat.sub_add_cancel hk, pow_mul, zeta_pow_p, one_pow] have hnorm1 : (zeta p) ^ (k * a.val) * starRingEnd ℂ ((zeta p) ^ (k * a.val)) = 1 := by rw [zeta_pow_conj, zeta_pow_eq_exp, ← Complex.exp_add, add_neg_cancel, Complex.exp_zero] have hne : (zeta p) ^ (k * a.val) ≠ 0 := by rw [zeta_pow_eq_exp]; exact Complex.exp_ne_zero _ apply mul_right_cancel₀ hne rw [hprod, mul_comm, hnorm1] lemma zeta_pow_ne_one {p : ℕ} [NeZero p] {k : ℕ} (hk : ¬ p ∣ k) : (zeta p) ^ k ≠ 1 := by intro heq rw [zeta_pow_eq_exp, Complex.exp_eq_one_iff] at heq obtain ⟨n, hn⟩ := heq have hpi : (Real.pi : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr Real.pi_ne_zero have hI : (Complex.I : ℂ) ≠ 0 := Complex.I_ne_zero have hpC : (p : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne p have hkn : (k : ℂ) = (n : ℂ) * (p : ℂ) := by have h1 : 2 * (Real.pi : ℂ) * Complex.I * (k : ℂ) = (n : ℂ) * (2 * (Real.pi : ℂ) * Complex.I) * (p : ℂ) := by have := congrArg (· * (p : ℂ)) hn rw [div_mul_cancel₀ _ hpC] at this exact this have h2 : (2 * (Real.pi : ℂ) * Complex.I) * (k : ℂ) = (2 * (Real.pi : ℂ) * Complex.I) * ((n : ℂ) * (p : ℂ)) := by linear_combination h1 exact mul_left_cancel₀ (mul_ne_zero (mul_ne_zero two_ne_zero hpi) hI) h2 have hkn_int : (k : ℤ) = n * (p : ℤ) := by exact_mod_cast hkn have hdvd : (p : ℤ) ∣ (k : ℤ) := ⟨n, by linarith⟩ exact hk (Int.ofNat_dvd.mp hdvd) /-- Character orthogonality on `ZMod p`: `∑_{a : ZMod p} ζ_p^{k a} = 0` when `¬ p ∣ k`. -/ lemma zeta_orthogonality {p : ℕ} [NeZero p] {k : ℕ} (hk : ¬ p ∣ k) : ∑ a : ZMod p, (zeta p) ^ (k * a.val) = 0 := by have hp1 : 1 < p := by rcases Nat.eq_zero_or_pos p with rfl | hp · exact absurd rfl (NeZero.ne 0) · by_contra hle have hp1' : p = 1 := by omega subst hp1'; exact hk (one_dvd k) have hval1 : ((1 : ZMod p).val) = 1 := ZMod.val_one_eq_one_mod p ▸ Nat.mod_eq_of_lt hp1 have hshift : (zeta p) ^ k * ∑ a : ZMod p, (zeta p) ^ (k * a.val) = ∑ a : ZMod p, (zeta p) ^ (k * a.val) := by rw [Finset.mul_sum] trans (∑ a : ZMod p, (zeta p) ^ (k * (a + 1).val)) · refine Finset.sum_congr rfl fun a _ => ?_ rw [zeta_pow_val_add, hval1, mul_one, mul_comm] · exact Equiv.sum_comp (Equiv.addRight (1 : ZMod p)) (fun a => (zeta p) ^ (k * a.val)) have hmul : ((zeta p) ^ k - 1) * ∑ a : ZMod p, (zeta p) ^ (k * a.val) = 0 := by linear_combination hshift exact (mul_eq_zero.mp hmul).resolve_left (sub_ne_zero.mpr (zeta_pow_ne_one hk)) /-- Discrete Fourier Transform `û(k) = ∑_{a : ZMod p} u(a) ζ_p^{k a}`. -/ noncomputable def dft {p : ℕ} [NeZero p] (u : ZMod p → ℝ) (k : Fin p) : ℂ := ∑ a : ZMod p, (u a : ℂ) * (zeta p) ^ (k.val * a.val) /-- **Theorem 3.2 (Exact Discrete Fourier Parseval, Conjugate Symmetry & Trilinear Convolution).** -/ theorem dft_parseval_and_convolution {p : ℕ} [NeZero p] (u v w : ZMod p → ℝ) : (∑ k : Fin p, ‖dft u k‖ ^ 2 = (p : ℝ) * zNormSq u) ∧ (∀ k : ℕ, (hk0 : 1 ≤ k) → (hkp : k < p) → ‖dft u ⟨p - k, by omega⟩‖ = ‖dft u ⟨k, hkp⟩‖) ∧ (((∑ a : ZMod p, ∑ b : ZMod p, u a * v b * w (a + b) : ℝ) : ℂ) = (1 / (p : ℂ)) * ∑ k : Fin p, dft u k * dft v k * starRingEnd ℂ (dft w k)) := by have hpC : (p : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne p have hsum_char : ∀ x : ZMod p, ∑ k : Fin p, (zeta p) ^ (k.val * x.val) = if x = 0 then (p : ℂ) else 0 := by intro x by_cases hx : x = 0 · subst hx; simp [ZMod.val_zero] · rw [if_neg hx] have hndvd : ¬ p ∣ x.val := by intro hd have hxpos : 0 < x.val := Nat.pos_of_ne_zero (fun h0 => hx ((ZMod.val_eq_zero x).mp h0)) have hle := Nat.le_of_dvd hxpos hd exact absurd hle (not_le.mpr x.val_lt) -- Reindex Fin p to ZMod p via ZMod.valEquiv (or direct Fin p geometric sum) have hshift : (zeta p) ^ x.val * ∑ k : Fin p, (zeta p) ^ (k.val * x.val) = ∑ k : Fin p, (zeta p) ^ (k.val * x.val) := by rw [Finset.mul_sum] have hbij : ∑ k : Fin p, (zeta p) ^ x.val * (zeta p) ^ (k.val * x.val) = ∑ k : ZMod p, (zeta p) ^ (x.val * (k + 1).val) := by refine Finset.sum_nbij (fun k : Fin p => (k.val : ZMod p)) (fun _ _ => Finset.mem_univ _) ?_ ?_ ?_ · intro k₁ _ k₂ _ heq dsimp only at heq have h1 : ((k₁.val : ZMod p).val) = k₁.val := ZMod.val_natCast_of_lt k₁.isLt have h2 : ((k₂.val : ZMod p).val) = k₂.val := ZMod.val_natCast_of_lt k₂.isLt exact Fin.ext (by rw [← h1, ← h2, heq]) · intro z _ exact ⟨⟨z.val, z.val_lt⟩, Finset.mem_univ _, ZMod.natCast_zmod_val z⟩ · intro k _ have hp1 : 1 < p := by have hxpos : 0 < x.val := Nat.pos_of_ne_zero (fun h0 => hx ((ZMod.val_eq_zero x).mp h0)) have := x.val_lt; omega have hval1 : ((1 : ZMod p).val) = 1 := ZMod.val_one_eq_one_mod p ▸ Nat.mod_eq_of_lt hp1 have hvk : ((k.val : ZMod p).val) = k.val := ZMod.val_natCast_of_lt k.isLt rw [zeta_pow_val_add, hvk, hval1, mul_one, mul_comm (k.val) (x.val), mul_comm] rw [hbij] trans (∑ z : ZMod p, (zeta p) ^ (x.val * z.val)) · exact Equiv.sum_comp (Equiv.addRight (1 : ZMod p)) (fun z => (zeta p) ^ (x.val * z.val)) · symm refine Finset.sum_nbij (fun k : Fin p => (k.val : ZMod p)) (fun _ _ => Finset.mem_univ _) ?_ ?_ ?_ · intro k₁ _ k₂ _ heq dsimp only at heq have h1 : ((k₁.val : ZMod p).val) = k₁.val := ZMod.val_natCast_of_lt k₁.isLt have h2 : ((k₂.val : ZMod p).val) = k₂.val := ZMod.val_natCast_of_lt k₂.isLt exact Fin.ext (by rw [← h1, ← h2, heq]) · intro z _ exact ⟨⟨z.val, z.val_lt⟩, Finset.mem_univ _, ZMod.natCast_zmod_val z⟩ · intro k _ rw [ZMod.val_natCast_of_lt k.isLt, mul_comm] have hmul : ((zeta p) ^ x.val - 1) * ∑ k : Fin p, (zeta p) ^ (k.val * x.val) = 0 := by linear_combination hshift exact (mul_eq_zero.mp hmul).resolve_left (sub_ne_zero.mpr (zeta_pow_ne_one hndvd)) have hsum_diff : ∀ a b : ZMod p, ∑ k : Fin p, (zeta p) ^ (k.val * a.val) * starRingEnd ℂ ((zeta p) ^ (k.val * b.val)) = if a = b then (p : ℂ) else 0 := by intro a b have hpt : ∀ k : Fin p, (zeta p) ^ (k.val * a.val) * starRingEnd ℂ ((zeta p) ^ (k.val * b.val)) = (zeta p) ^ (k.val * (a - b).val) := by intro k have hadd : (zeta p) ^ (k.val * a.val) = (zeta p) ^ (k.val * (a - b).val) * (zeta p) ^ (k.val * b.val) := by conv_lhs => rw [show a = (a - b) + b by ring] exact zeta_pow_val_add k.val (a - b) b have hunit : (zeta p) ^ (k.val * b.val) * starRingEnd ℂ ((zeta p) ^ (k.val * b.val)) = 1 := by rw [zeta_pow_conj, zeta_pow_eq_exp, ← Complex.exp_add, add_neg_cancel, Complex.exp_zero] rw [hadd, mul_assoc, hunit, mul_one] simp_rw [hpt, hsum_char (a - b), sub_eq_zero] refine ⟨?_, ?_, ?_⟩ · -- Part 1: Parseval have hC : ((∑ k : Fin p, ‖dft u k‖ ^ 2 : ℝ) : ℂ) = (((p : ℝ) * zNormSq u : ℝ) : ℂ) := by have hnorm : ∀ k : Fin p, ((‖dft u k‖ : ℂ) ^ 2) = dft u k * starRingEnd ℂ (dft u k) := by intro k; rw [← Complex.ofReal_pow, Complex.mul_conj, Complex.normSq_eq_norm_sq] push_cast [zNormSq] simp_rw [hnorm] unfold dft have hexp : ∀ k : Fin p, (∑ a : ZMod p, (u a : ℂ) * (zeta p) ^ (k.val * a.val)) * starRingEnd ℂ (∑ b : ZMod p, (u b : ℂ) * (zeta p) ^ (k.val * b.val)) = ∑ a : ZMod p, ∑ b : ZMod p, ((u a : ℂ) * (u b : ℂ)) * ((zeta p) ^ (k.val * a.val) * starRingEnd ℂ ((zeta p) ^ (k.val * b.val))) := by intro k rw [map_sum, Finset.sum_mul] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun b _ => ?_ rw [map_mul, Complex.conj_ofReal]; ring simp_rw [hexp] rw [Finset.sum_comm] trans (∑ a : ZMod p, ∑ b : ZMod p, ∑ k : Fin p, ((u a : ℂ) * (u b : ℂ)) * ((zeta p) ^ (k.val * a.val) * starRingEnd ℂ ((zeta p) ^ (k.val * b.val)))) · refine Finset.sum_congr rfl fun a _ => Finset.sum_comm · simp_rw [← Finset.mul_sum, hsum_diff, mul_ite, mul_zero] simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] rw [Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => ?_; ring exact Complex.ofReal_injective hC · -- Part 2: Conjugate symmetry for real u intro k _hk0 hkp have hconj : dft u ⟨p - k, by omega⟩ = starRingEnd ℂ (dft u ⟨k, hkp⟩) := by unfold dft rw [map_sum] refine Finset.sum_congr rfl fun a _ => ?_ rw [map_mul, Complex.conj_ofReal] exact congrArg ((u a : ℂ) * ·) (zeta_pow_sub_eq_conj (le_of_lt hkp) a) rw [hconj, Complex.norm_conj] · -- Part 3: Trilinear convolution have hRHS : ∑ k : Fin p, dft u k * dft v k * starRingEnd ℂ (dft w k) = (p : ℂ) * ∑ a : ZMod p, ∑ b : ZMod p, (u a : ℂ) * (v b : ℂ) * (w (a + b) : ℂ) := by unfold dft have hexp : ∀ k : Fin p, (∑ a : ZMod p, (u a : ℂ) * (zeta p) ^ (k.val * a.val)) * (∑ b : ZMod p, (v b : ℂ) * (zeta p) ^ (k.val * b.val)) * starRingEnd ℂ (∑ c : ZMod p, (w c : ℂ) * (zeta p) ^ (k.val * c.val)) = ∑ a : ZMod p, ∑ b : ZMod p, ∑ c : ZMod p, ((u a : ℂ) * (v b : ℂ) * (w c : ℂ)) * ((zeta p) ^ (k.val * (a + b).val) * starRingEnd ℂ ((zeta p) ^ (k.val * c.val))) := by intro k rw [map_sum, Finset.sum_mul, Finset.sum_mul] refine Finset.sum_congr rfl fun a _ => ?_ conv_lhs => arg 1; rw [Finset.mul_sum] rw [Finset.sum_mul] refine Finset.sum_congr rfl fun b _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun c _ => ?_ rw [map_mul, Complex.conj_ofReal, zeta_pow_val_add]; ring simp_rw [hexp] rw [Finset.sum_comm] trans (∑ a : ZMod p, ∑ b : ZMod p, ∑ c : ZMod p, ∑ k : Fin p, ((u a : ℂ) * (v b : ℂ) * (w c : ℂ)) * ((zeta p) ^ (k.val * (a + b).val) * starRingEnd ℂ ((zeta p) ^ (k.val * c.val)))) · refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_comm] exact Finset.sum_congr rfl fun b _ => Finset.sum_comm · simp_rw [← Finset.mul_sum, hsum_diff, mul_ite, mul_zero] simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] rw [Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun b _ => ?_; ring rw [hRHS] push_cast field_simp [hpC] /-- **Theorem 3.3 (Universal Full-Width Fourier Margin Upper Bound — Morwani et al. ICLR 2024 Thm. 7).** For EVERY odd `p = 2 q + 1 ≥ 3` (`q ≥ 1`), EVERY width `m`, and EVERY 2-layer quadratic network `(U, V, W)` achieving multiclass margin `γ` on all of `mathcal{D}_p = (ZMod p)²`: `γ ≤ √(2 / 27) / (√p · (p - 1)) · ‖θ‖_{2,3}³`. -/ theorem modular_addition_universal_margin_upper_bound {q m : ℕ} (hq : 1 ≤ q) (U V W : Fin m → ZMod (2 * q + 1) → ℝ) {γ : ℝ} (hmargin : HasModAddMargin U V W Finset.univ γ) : γ ≤ Real.sqrt (2 / 27) / (Real.sqrt (2 * q + 1 : ℝ) * ((2 * q + 1 : ℝ) - 1)) * netNorm3 U V W := by let p := 2 * q + 1 have : NeZero p := ⟨by omega⟩ have hp_pos : 0 < (p : ℝ) := by exact_mod_cast (show 0 < p by omega) have hpm1_pos : 0 < (p : ℝ) - 1 := by have : (3 : ℝ) ≤ (p : ℝ) := by exact_mod_cast (show 3 ≤ p by omega) linarith have hsingle_sharp : ∀ u v w : ZMod p → ℝ, ∑ a : ZMod p, ∑ b : ZMod p, u a * v b * zCentered w (a + b) ≤ Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3)) * neuronNorm3 u v w := by intro u v w set wt := zCentered w have hconv := (dft_parseval_and_convolution u v wt).2.2 have hwt0 : dft wt ⟨0, by omega⟩ = 0 := by unfold dft; simp only [zero_mul, pow_zero, mul_one] have : (∑ a : ZMod p, (wt a : ℂ)) = ((∑ a : ZMod p, wt a : ℝ) : ℂ) := by push_cast; rfl rw [this, zCentered_sum_zero, Complex.ofReal_zero] have hnorm_conv : ∑ a : ZMod p, ∑ b : ZMod p, u a * v b * wt (a + b) ≤ (1 / (p : ℝ)) * ∑ k ∈ Finset.univ.erase ⟨0, by omega⟩, ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖ := by have hle_norm : ∑ a : ZMod p, ∑ b : ZMod p, u a * v b * wt (a + b) ≤ ‖((∑ a : ZMod p, ∑ b : ZMod p, u a * v b * wt (a + b) : ℝ) : ℂ)‖ := by rw [Complex.norm_real]; exact le_abs_self _ rw [hconv, norm_mul, one_div, norm_inv, Complex.norm_natCast, ← one_div] at hle_norm have htri : ‖∑ k : Fin p, dft u k * dft v k * starRingEnd ℂ (dft wt k)‖ ≤ ∑ k ∈ Finset.univ.erase ⟨0, by omega⟩, ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖ := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ⟨0, by omega⟩), hwt0, map_zero, mul_zero, zero_add] refine le_trans (norm_sum_le _ _) (Finset.sum_le_sum fun k _ => ?_) rw [norm_mul, norm_mul, Complex.norm_conj] have hmul := mul_le_mul_of_nonneg_left htri (div_nonneg zero_le_one (le_of_lt hp_pos)) linarith let halfSum : (Fin p → ℝ) → ℝ := fun f => ∑ r : Fin q, f ⟨r.val + 1, by omega⟩ have hsplit_pair : ∀ f : Fin p → ℝ, (∀ r : Fin q, f ⟨p - (r.val + 1), by omega⟩ = f ⟨r.val + 1, by omega⟩) → ∑ k ∈ Finset.univ.erase ⟨0, by omega⟩, f k = 2 * halfSum f := by intro f hsym let e : Fin q ⊕ Fin q → Fin p := fun s => match s with | Sum.inl r => ⟨r.val + 1, by omega⟩ | Sum.inr r => ⟨p - (r.val + 1), by omega⟩ have hbij : ∑ s : Fin q ⊕ Fin q, f (e s) = ∑ k ∈ Finset.univ.erase ⟨0, by omega⟩, f k := by refine Finset.sum_nbij e ?_ ?_ ?_ (fun _ _ => rfl) · intro s _ cases s with | inl r => simp [e, Fin.ext_iff] | inr r => simp only [e, Finset.mem_erase, Finset.mem_univ, and_true, ne_eq, Fin.mk.injEq] omega · intro s₁ _ s₂ _ heq cases s₁ with | inl r₁ => cases s₂ with | inl r₂ => simp only [e, Fin.mk.injEq] at heq; exact congrArg Sum.inl (Fin.ext (by omega)) | inr r₂ => simp only [e, Fin.mk.injEq] at heq; omega | inr r₁ => cases s₂ with | inl r₂ => simp only [e, Fin.mk.injEq] at heq; omega | inr r₂ => simp only [e, Fin.mk.injEq] at heq; exact congrArg Sum.inr (Fin.ext (by omega)) · intro k hk have hk0 : k.val ≠ 0 := fun h0 => (Finset.mem_erase.mp hk).1 (Fin.ext h0) by_cases hle : k.val ≤ q · exact ⟨Sum.inl ⟨k.val - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp [e]; omega)⟩ · exact ⟨Sum.inr ⟨p - k.val - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp [e]; omega)⟩ rw [← hbij, Fintype.sum_sum_type]; simp only [e, halfSum] have hsym_sum : ∑ r : Fin q, f ⟨p - (r.val + 1), by omega⟩ = ∑ r : Fin q, f ⟨r.val + 1, by omega⟩ := Finset.sum_congr rfl fun r _ => hsym r rw [hsym_sum]; ring have hhalf_sq : ∀ x : ZMod p → ℝ, halfSum (fun k => ‖dft x k‖ ^ 2) ≤ ((p : ℝ) / 2) * zNormSq x := by intro x have hsym : ∀ r : Fin q, ‖dft x ⟨p - (r.val + 1), by omega⟩‖ ^ 2 = ‖dft x ⟨r.val + 1, by omega⟩‖ ^ 2 := fun r => by rw [(dft_parseval_and_convolution x x x).2.1 (r.val + 1) (by omega) (by omega)] have h2 := hsplit_pair (fun k => ‖dft x k‖ ^ 2) hsym have hle : ∑ k ∈ Finset.univ.erase ⟨0, by omega⟩, ‖dft x k‖ ^ 2 ≤ ∑ k : Fin p, ‖dft x k‖ ^ 2 := Finset.sum_le_sum_of_subset_of_nonneg (Finset.erase_subset _ _) (fun _ _ _ => sq_nonneg _) have hp_eq := (dft_parseval_and_convolution x x x).1 linarith have hsym_prod : ∀ r : Fin q, ‖dft u ⟨p - (r.val + 1), by omega⟩‖ * ‖dft v ⟨p - (r.val + 1), by omega⟩‖ * ‖dft wt ⟨p - (r.val + 1), by omega⟩‖ = ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖ * ‖dft wt ⟨r.val + 1, by omega⟩‖ := fun r => by rw [(dft_parseval_and_convolution u u u).2.1 (r.val + 1) (by omega) (by omega), (dft_parseval_and_convolution v v v).2.1 (r.val + 1) (by omega) (by omega), (dft_parseval_and_convolution wt wt wt).2.1 (r.val + 1) (by omega) (by omega)] have hsplit3 := hsplit_pair (fun k => ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖) hsym_prod set Su := halfSum (fun k => ‖dft u k‖ ^ 2) set Sv := halfSum (fun k => ‖dft v k‖ ^ 2) set Sw := halfSum (fun k => ‖dft wt k‖ ^ 2) have hSu_nn : 0 ≤ Su := Finset.sum_nonneg fun _ _ => sq_nonneg _ have hSv_nn : 0 ≤ Sv := Finset.sum_nonneg fun _ _ => sq_nonneg _ have hSw_nn : 0 ≤ Sw := Finset.sum_nonneg fun _ _ => sq_nonneg _ have htrilin : halfSum (fun k => ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖) ≤ Real.sqrt Su * Real.sqrt Sv * Real.sqrt Sw := by have h1 : halfSum (fun k => ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖) ≤ Real.sqrt Sw * ∑ r : Fin q, ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖ := by unfold halfSum; rw [Finset.mul_sum] refine Finset.sum_le_sum fun r _ => ?_ have hle_w : ‖dft wt ⟨r.val + 1, by omega⟩‖ ≤ Real.sqrt Sw := by have hsq : ‖dft wt ⟨r.val + 1, by omega⟩‖ ^ 2 ≤ Sw := Finset.single_le_sum (f := fun r : Fin q => ‖dft wt ⟨r.val + 1, by omega⟩‖ ^ 2) (fun _ _ => sq_nonneg _) (Finset.mem_univ r) have := Real.sqrt_le_sqrt hsq rwa [Real.sqrt_sq (norm_nonneg _)] at this have hprod_nn : 0 ≤ ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖ := by positivity nlinarith have h2 : ∑ r : Fin q, ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖ ≤ Real.sqrt Su * Real.sqrt Sv := by have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun r : Fin q => ‖dft u ⟨r.val + 1, by omega⟩‖) (fun r : Fin q => ‖dft v ⟨r.val + 1, by omega⟩‖) have hsq : (∑ r : Fin q, ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖) ^ 2 ≤ (Real.sqrt Su * Real.sqrt Sv) ^ 2 := by rw [mul_pow, Real.sq_sqrt hSu_nn, Real.sq_sqrt hSv_nn]; exact hcs have hL : 0 ≤ ∑ r : Fin q, ‖dft u ⟨r.val + 1, by omega⟩‖ * ‖dft v ⟨r.val + 1, by omega⟩‖ := Finset.sum_nonneg fun _ _ => by positivity have hR : 0 ≤ Real.sqrt Su * Real.sqrt Sv := by positivity nlinarith have h3 := mul_le_mul_of_nonneg_left h2 (Real.sqrt_nonneg Sw) linarith [show Real.sqrt Sw * (Real.sqrt Su * Real.sqrt Sv) = Real.sqrt Su * Real.sqrt Sv * Real.sqrt Sw by ring] have hprod_le : Real.sqrt Su * Real.sqrt Sv * Real.sqrt Sw ≤ Real.sqrt ((p : ℝ) / 2 * zNormSq u) * Real.sqrt ((p : ℝ) / 2 * zNormSq v) * Real.sqrt ((p : ℝ) / 2 * zNormSq w) := by have hw_le : Sw ≤ (p : ℝ) / 2 * zNormSq w := le_trans (hhalf_sq wt) (mul_le_mul_of_nonneg_left (zCentered_normSq_le w) (by positivity)) have hru := Real.sqrt_le_sqrt (hhalf_sq u) have hrv := Real.sqrt_le_sqrt (hhalf_sq v) have hrw := Real.sqrt_le_sqrt hw_le gcongr have hfactor : Real.sqrt ((p : ℝ) / 2 * zNormSq u) * Real.sqrt ((p : ℝ) / 2 * zNormSq v) * Real.sqrt ((p : ℝ) / 2 * zNormSq w) = ((p : ℝ) * Real.sqrt (p : ℝ)) / (2 * Real.sqrt 2) * (Real.sqrt (zNormSq u) * Real.sqrt (zNormSq v) * Real.sqrt (zNormSq w)) := by rw [Real.sqrt_mul (by positivity), Real.sqrt_mul (by positivity), Real.sqrt_mul (by positivity), Real.sqrt_div (le_of_lt hp_pos)] have hs2ne : Real.sqrt 2 ≠ 0 := by positivity field_simp [hs2ne] rw [Real.sq_sqrt (le_of_lt hp_pos), Real.sq_sqrt (by norm_num)] ring have hamgm := amgm3_sqrt (zNormSq_nonneg u) (zNormSq_nonneg v) (zNormSq_nonneg w) have hstep1 : halfSum (fun k => ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖) ≤ ((p : ℝ) * Real.sqrt (p : ℝ)) / (2 * Real.sqrt 2) * (neuronNorm3 u v w / (3 * Real.sqrt 3)) := calc halfSum (fun k => ‖dft u k‖ * ‖dft v k‖ * ‖dft wt k‖) ≤ Real.sqrt Su * Real.sqrt Sv * Real.sqrt Sw := htrilin _ ≤ Real.sqrt ((p : ℝ) / 2 * zNormSq u) * Real.sqrt ((p : ℝ) / 2 * zNormSq v) * Real.sqrt ((p : ℝ) / 2 * zNormSq w) := hprod_le _ = ((p : ℝ) * Real.sqrt (p : ℝ)) / (2 * Real.sqrt 2) * (Real.sqrt (zNormSq u) * Real.sqrt (zNormSq v) * Real.sqrt (zNormSq w)) := hfactor _ ≤ ((p : ℝ) * Real.sqrt (p : ℝ)) / (2 * Real.sqrt 2) * (neuronNorm3 u v w / (3 * Real.sqrt 3)) := mul_le_mul_of_nonneg_left hamgm (by positivity) have hstep2 := mul_le_mul_of_nonneg_left hstep1 (show 0 ≤ (1 / (p : ℝ)) * 2 by positivity) have hsimp : (1 / (p : ℝ)) * 2 * (((p : ℝ) * Real.sqrt (p : ℝ)) / (2 * Real.sqrt 2) * (neuronNorm3 u v w / (3 * Real.sqrt 3))) = Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3)) * neuronNorm3 u v w := by have hs2ne : Real.sqrt 2 ≠ 0 := by positivity have hs3ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hp_pos, hs2ne, hs3ne] rw [hsplit3] at hnorm_conv linarith have hsum_bound : ∑ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3)) * netNorm3 U V W := by unfold netNorm3 rw [Finset.mul_sum] exact Finset.sum_le_sum fun j _ => hsingle_sharp (U j) (V j) (W j) have hconv_total := quad_net_margin_le_sum_convolutions U V W hmargin have hbound_prod : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ ≤ 2 * (p : ℝ) * (Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3)) * netNorm3 U V W) := le_trans hconv_total (mul_le_mul_of_nonneg_left hsum_bound (by positivity)) have hden_pos : 0 < (p : ℝ) ^ 2 * ((p : ℝ) - 1) := by positivity have hconst_eq : 2 * (p : ℝ) * (Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3))) / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = Real.sqrt (2 / 27) / (Real.sqrt (p : ℝ) * ((p : ℝ) - 1)) := by have hrt27 : Real.sqrt (2 / 27 : ℝ) = Real.sqrt 2 / (3 * Real.sqrt 3) := by rw [Real.sqrt_div (by norm_num)] have h27 : Real.sqrt 27 = 3 * Real.sqrt 3 := by have : (27 : ℝ) = 3 ^ 2 * 3 := by norm_num rw [this, Real.sqrt_mul (by norm_num), Real.sqrt_sq (by norm_num)] rw [h27] rw [hrt27] have hsp_ne : Real.sqrt (p : ℝ) ≠ 0 := by positivity have hs2_ne : Real.sqrt 2 ≠ 0 := by positivity have hs3_ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hs2_ne, hs3_ne] rw [Real.sq_sqrt (le_of_lt hp_pos), Real.sq_sqrt (by norm_num)] ring have hdiv := div_le_div_of_nonneg_right hbound_prod (le_of_lt hden_pos) have hL : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = γ := by field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos] have hR : 2 * (p : ℝ) * (Real.sqrt (p : ℝ) / (Real.sqrt 2 * (3 * Real.sqrt 3)) * netNorm3 U V W) / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = Real.sqrt (2 / 27) / (Real.sqrt (p : ℝ) * ((p : ℝ) - 1)) * netNorm3 U V W := by rw [← hconst_eq]; ring have hp_cast : (p : ℝ) = (2 * q + 1 : ℝ) := by simp [p] rw [← hp_cast] linarith /-- Explicit 8-neuron single-frequency Fourier block for frequency `k ∈ {1, ..., q}` on `ZMod (2q+1)`. -/ noncomputable def fourierNeuronU (q : ℕ) (r : Fin q) (t : Fin 8) (a : ZMod (2 * q + 1)) : ℝ := let θ := 2 * Real.pi * ((r.val + 1 : ℝ) * (a.val : ℝ)) / (2 * q + 1 : ℝ) match t.val with | 0 => Real.cos θ | 1 => Real.cos θ | 2 => Real.sin θ | 3 => Real.sin θ | 4 => Real.sin θ | 5 => Real.sin θ | 6 => Real.cos θ | _ => Real.cos θ noncomputable def fourierNeuronV (q : ℕ) (r : Fin q) (t : Fin 8) (b : ZMod (2 * q + 1)) : ℝ := let θ := 2 * Real.pi * ((r.val + 1 : ℝ) * (b.val : ℝ)) / (2 * q + 1 : ℝ) match t.val with | 0 => Real.cos θ | 1 => -Real.cos θ | 2 => Real.sin θ | 3 => -Real.sin θ | 4 => Real.cos θ | 5 => -Real.cos θ | 6 => Real.sin θ | _ => -Real.sin θ noncomputable def fourierNeuronW (q : ℕ) (r : Fin q) (t : Fin 8) (c : ZMod (2 * q + 1)) : ℝ := let θ := 2 * Real.pi * ((r.val + 1 : ℝ) * (c.val : ℝ)) / (2 * q + 1 : ℝ) match t.val with | 0 => Real.cos θ | 1 => -Real.cos θ | 2 => -Real.cos θ | 3 => Real.cos θ | 4 => Real.sin θ | 5 => -Real.sin θ | 6 => Real.sin θ | _ => -Real.sin θ /-- Cosine orthogonality: `∑_{a : ZMod p} cos(2π k a / p) = 0` when `¬ p ∣ k`. -/ lemma sum_cos_zmod_zero {p : ℕ} [NeZero p] {k : ℕ} (hk : ¬ p ∣ k) : ∑ a : ZMod p, Real.cos (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ)) = 0 := by have hz := congrArg Complex.re (zeta_orthogonality (p := p) hk) rw [Complex.re_sum, Complex.zero_re] at hz rw [← hz] refine Finset.sum_congr rfl fun a _ => ?_ rw [zeta_pow_eq_exp] have harg : (2 * Real.pi * Complex.I * ((k * a.val : ℕ) : ℂ) / (p : ℂ)) = ((2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ) : ℝ) : ℂ) * Complex.I := by push_cast; ring rw [harg, Complex.exp_ofReal_mul_I_re] /-- Squared cosine & sine norms on `ZMod (2q+1)`: both equal `p / 2` for `1 ≤ k ≤ q`. -/ lemma sum_cos_sin_sq_odd {q : ℕ} (k : ℕ) (hk1 : 1 ≤ k) (hkq : k ≤ q) : let p := 2 * q + 1 (∑ a : ZMod p, (Real.cos (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 = (p : ℝ) / 2) ∧ (∑ a : ZMod p, (Real.sin (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 = (p : ℝ) / 2) := by dsimp only let p := 2 * q + 1 have : NeZero p := ⟨by omega⟩ have hndvd : ¬ p ∣ (2 * k) := by intro hd have hpos : 0 < 2 * k := by omega have hle := Nat.le_of_dvd hpos hd omega have h2k := sum_cos_zmod_zero (p := p) hndvd have hcos_sq : ∀ a : ZMod p, (Real.cos (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 = (1 + Real.cos (2 * Real.pi * (((2 * k : ℕ) : ℝ) * (a.val : ℝ)) / (p : ℝ))) / 2 := by intro a have h2 : 2 * Real.pi * (((2 * k : ℕ) : ℝ) * (a.val : ℝ)) / (p : ℝ) = 2 * (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ)) := by push_cast; ring rw [h2, Real.cos_two_mul]; ring have hcos_sum : ∑ a : ZMod p, (Real.cos (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 = (p : ℝ) / 2 := by simp_rw [hcos_sq] rw [← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul, mul_one, h2k, add_zero] refine ⟨hcos_sum, ?_⟩ have hsin_sq : ∀ a : ZMod p, (Real.sin (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 = 1 - (Real.cos (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))) ^ 2 := by intro a; linarith [Real.sin_sq_add_cos_sq (2 * Real.pi * ((k : ℝ) * (a.val : ℝ)) / (p : ℝ))] rw [Finset.sum_congr rfl fun a _ => hsin_sq a, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul, mul_one, hcos_sum] ring theorem fourier_circuit_exact_margin {q : ℕ} (hq : 1 ≤ q) : let p := 2 * q + 1 let idx : Fin (q * 8) ≃ Fin q × Fin 8 := finProdFinEquiv.symm let U : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronU q (idx j).1 (idx j).2 let V : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronV q (idx j).1 (idx j).2 let W : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronW q (idx j).1 (idx j).2 (∀ a b c : ZMod p, quadNetOut U V W a b c = if c = a + b then 2 * ((p : ℝ) - 1) else -2) ∧ HasModAddMargin U V W Finset.univ (2 * (p : ℝ)) ∧ netNorm3 U V W = 4 * ((p : ℝ) - 1) * ((3 * (p : ℝ) / 2) * Real.sqrt (3 * (p : ℝ) / 2)) ∧ (2 * (p : ℝ)) / netNorm3 U V W = Real.sqrt (2 / 27) / (Real.sqrt (p : ℝ) * ((p : ℝ) - 1)) := by dsimp only let p := 2 * q + 1 have : NeZero p := ⟨by omega⟩ have hp_pos : 0 < (p : ℝ) := by exact_mod_cast (show 0 < p by omega) have hpm1_pos : 0 < (p : ℝ) - 1 := by have : (3 : ℝ) ≤ (p : ℝ) := by exact_mod_cast (show 3 ≤ p by omega) linarith let idx : Fin (q * 8) ≃ Fin q × Fin 8 := finProdFinEquiv.symm let U : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronU q (idx j).1 (idx j).2 let V : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronV q (idx j).1 (idx j).2 let W : Fin (q * 8) → ZMod p → ℝ := fun j => fourierNeuronW q (idx j).1 (idx j).2 have hblock : ∀ (r : Fin q) (a b c : ZMod p), ∑ t : Fin 8, quadNeuronOut (fourierNeuronU q r t) (fourierNeuronV q r t) (fourierNeuronW q r t) a b c = 4 * Real.cos (2 * Real.pi * ((r.val + 1 : ℝ) * ((a + b - c).val : ℝ)) / (p : ℝ)) := by intro r a b c set A := 2 * Real.pi * ((r.val + 1 : ℝ) * (a.val : ℝ)) / (2 * q + 1 : ℝ) set B := 2 * Real.pi * ((r.val + 1 : ℝ) * (b.val : ℝ)) / (2 * q + 1 : ℝ) set C := 2 * Real.pi * ((r.val + 1 : ℝ) * (c.val : ℝ)) / (2 * q + 1 : ℝ) have h8 : ∑ t : Fin 8, quadNeuronOut (fourierNeuronU q r t) (fourierNeuronV q r t) (fourierNeuronW q r t) a b c = 4 * Real.cos (A + B - C) := by rw [Fin.sum_univ_eight] dsimp only [quadNeuronOut, fourierNeuronU, fourierNeuronV, fourierNeuronW] change Real.cos C * (Real.cos A + Real.cos B) ^ 2 + (-Real.cos C) * (Real.cos A + -Real.cos B) ^ 2 + (-Real.cos C) * (Real.sin A + Real.sin B) ^ 2 + Real.cos C * (Real.sin A + -Real.sin B) ^ 2 + Real.sin C * (Real.sin A + Real.cos B) ^ 2 + (-Real.sin C) * (Real.sin A + -Real.cos B) ^ 2 + Real.sin C * (Real.cos A + Real.sin B) ^ 2 + (-Real.sin C) * (Real.cos A + -Real.sin B) ^ 2 = 4 * Real.cos (A + B - C) rw [Real.cos_sub, Real.cos_add, Real.sin_add]; ring rw [h8] congr 1 have hmod_int : ((a.val : ℤ) + (b.val : ℤ) - (c.val : ℤ) - ((a + b - c).val : ℤ)) % (p : ℤ) = 0 := by have h3 : ((((a.val : ℤ) + (b.val : ℤ) - (c.val : ℤ) - ((a + b - c).val : ℤ)) : ℤ) : ZMod p) = 0 := by push_cast; simp exact Int.emod_eq_zero_of_dvd ((ZMod.intCast_zmod_eq_zero_iff_dvd _ p).mp h3) obtain ⟨m_int, hm_int⟩ := Int.dvd_of_emod_eq_zero hmod_int have hangle : A + B - C = 2 * Real.pi * ((r.val + 1 : ℝ) * ((a + b - c).val : ℝ)) / (p : ℝ) + ((r.val + 1 : ℤ) * m_int : ℤ) * (2 * Real.pi) := by have hmR : (a.val : ℝ) + (b.val : ℝ) - (c.val : ℝ) = ((a + b - c).val : ℝ) + (p : ℝ) * (m_int : ℝ) := by have h : (a.val : ℝ) + (b.val : ℝ) - (c.val : ℝ) - ((a + b - c).val : ℝ) = (p : ℝ) * (m_int : ℝ) := by exact_mod_cast hm_int linarith have hpcast : (2 * (q : ℝ) + 1) = (p : ℝ) := by simp [p] calc A + B - C = 2 * Real.pi * ((r.val : ℝ) + 1) * ((a.val : ℝ) + (b.val : ℝ) - (c.val : ℝ)) / (p : ℝ) := by simp only [A, B, C, hpcast]; ring _ = 2 * Real.pi * ((r.val : ℝ) + 1) * (((a + b - c).val : ℝ) + (p : ℝ) * (m_int : ℝ)) / (p : ℝ) := by rw [hmR] _ = 2 * Real.pi * ((r.val + 1 : ℝ) * ((a + b - c).val : ℝ)) / (p : ℝ) + ((r.val + 1 : ℤ) * m_int : ℤ) * (2 * Real.pi) := by push_cast; field_simp [ne_of_gt hp_pos] rw [hangle, Real.cos_add_int_mul_two_pi] have hlogits : ∀ a b c : ZMod p, quadNetOut U V W a b c = if c = a + b then 2 * ((p : ℝ) - 1) else -2 := by intro a b c unfold quadNetOut rw [← Equiv.sum_comp idx.symm, Fintype.sum_prod_type] have hsimp : ∀ (r : Fin q) (t : Fin 8), quadNeuronOut (U (idx.symm (r, t))) (V (idx.symm (r, t))) (W (idx.symm (r, t))) a b c = quadNeuronOut (fourierNeuronU q r t) (fourierNeuronV q r t) (fourierNeuronW q r t) a b c := by intro r t; simp [U, V, W] simp_rw [hsimp, hblock] set x := a + b - c have hx_eq : (x = 0) ↔ (c = a + b) := by simp only [x, sub_eq_zero, eq_comm] by_cases hcab : c = a + b · rw [if_pos hcab] have hx0 : x = 0 := hx_eq.mpr hcab simp only [hx0, ZMod.val_zero, Nat.cast_zero, mul_zero, zero_div, Real.cos_zero, mul_one, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have hpq : (p : ℝ) = 2 * (q : ℝ) + 1 := by simp [p] linarith · rw [if_neg hcab] have hxne : x ≠ 0 := fun h => hcab (hx_eq.mp h) have hndvd : ¬ p ∣ x.val := by intro hd have hxpos : 0 < x.val := Nat.pos_of_ne_zero (fun h0 => hxne ((ZMod.val_eq_zero x).mp h0)) exact absurd (Nat.le_of_dvd hxpos hd) (not_le.mpr x.val_lt) have hfull := sum_cos_zmod_zero (p := p) hndvd have hfull_fin : ∑ k : Fin p, Real.cos (2 * Real.pi * ((k.val : ℝ) * (x.val : ℝ)) / (p : ℝ)) = 0 := by rw [← hfull] refine Finset.sum_nbij (fun k : Fin p => (k.val : ZMod p)) (fun _ _ => Finset.mem_univ _) ?_ ?_ ?_ · intro k₁ _ k₂ _ heq dsimp only at heq have h1 := ZMod.val_natCast_of_lt k₁.isLt have h2 := ZMod.val_natCast_of_lt k₂.isLt exact Fin.ext (by rw [← h1, ← h2, heq]) · intro z _; exact ⟨⟨z.val, z.val_lt⟩, Finset.mem_univ _, ZMod.natCast_zmod_val z⟩ · intro k _; rw [ZMod.val_natCast_of_lt k.isLt]; congr 1; ring rw [← Finset.add_sum_erase _ _ (Finset.mem_univ (⟨0, by omega⟩ : Fin p))] at hfull_fin simp only [Nat.cast_zero, zero_mul, mul_zero, zero_div, Real.cos_zero] at hfull_fin let e : Fin q ⊕ Fin q → Fin p := fun s => match s with | Sum.inl r => ⟨r.val + 1, by omega⟩ | Sum.inr r => ⟨p - (r.val + 1), by omega⟩ have hbij : ∑ s : Fin q ⊕ Fin q, Real.cos (2 * Real.pi * (((e s).val : ℝ) * (x.val : ℝ)) / (p : ℝ)) = ∑ k ∈ Finset.univ.erase (⟨0, by omega⟩ : Fin p), Real.cos (2 * Real.pi * ((k.val : ℝ) * (x.val : ℝ)) / (p : ℝ)) := by refine Finset.sum_nbij e ?_ ?_ ?_ (fun _ _ => rfl) · intro s _ cases s with | inl r => simp [e, Fin.ext_iff] | inr r => simp only [e, Finset.mem_erase, Finset.mem_univ, and_true, ne_eq, Fin.mk.injEq]; omega · intro s₁ _ s₂ _ heq cases s₁ with | inl r₁ => cases s₂ with | inl r₂ => simp only [e, Fin.mk.injEq] at heq; exact congrArg Sum.inl (Fin.ext (by omega)) | inr r₂ => simp only [e, Fin.mk.injEq] at heq; omega | inr r₁ => cases s₂ with | inl r₂ => simp only [e, Fin.mk.injEq] at heq; omega | inr r₂ => simp only [e, Fin.mk.injEq] at heq; exact congrArg Sum.inr (Fin.ext (by omega)) · intro k hk have hk0 : k.val ≠ 0 := fun h0 => (Finset.mem_erase.mp hk).1 (Fin.ext h0) by_cases hle : k.val ≤ q · exact ⟨Sum.inl ⟨k.val - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp [e]; omega)⟩ · exact ⟨Sum.inr ⟨p - k.val - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp [e]; omega)⟩ rw [← hbij, Fintype.sum_sum_type] at hfull_fin have hcos_sym : ∀ r : Fin q, Real.cos (2 * Real.pi * ((((p - (r.val + 1) : ℕ) : ℝ)) * (x.val : ℝ)) / (p : ℝ)) = Real.cos (2 * Real.pi * (((r.val + 1 : ℝ)) * (x.val : ℝ)) / (p : ℝ)) := by intro r have hsub : ((p - (r.val + 1) : ℕ) : ℝ) = (p : ℝ) - ((r.val : ℝ) + 1) := by rw [Nat.cast_sub (by omega)]; push_cast; ring rw [hsub] have harg : 2 * Real.pi * (((p : ℝ) - ((r.val : ℝ) + 1)) * (x.val : ℝ)) / (p : ℝ) = -(2 * Real.pi * (((r.val : ℝ) + 1) * (x.val : ℝ)) / (p : ℝ)) + (x.val : ℤ) * (2 * Real.pi) := by push_cast; field_simp [ne_of_gt hp_pos]; ring rw [harg, Real.cos_add_int_mul_two_pi, Real.cos_neg] simp only [e] at hfull_fin simp_rw [hcos_sym] at hfull_fin have hsum_cos : ∑ r : Fin q, Real.cos (2 * Real.pi * (((r.val : ℝ) + 1) * (x.val : ℝ)) / (p : ℝ)) = -(1 / 2) := by have hcast : ∀ r : Fin q, ((r.val + 1 : ℕ) : ℝ) = (r.val : ℝ) + 1 := fun r => by push_cast; rfl simp_rw [hcast] at hfull_fin linarith rw [← Finset.mul_sum, hsum_cos]; ring have hmarg : HasModAddMargin U V W Finset.univ (2 * (p : ℝ)) := by intro ab _ c hc rw [hlogits ab.1 ab.2 (ab.1 + ab.2), if_pos rfl, hlogits ab.1 ab.2 c, if_neg hc] ring_nf; exact le_rfl have hnorm : netNorm3 U V W = 4 * ((p : ℝ) - 1) * ((3 * (p : ℝ) / 2) * Real.sqrt (3 * (p : ℝ) / 2)) := by unfold netNorm3 rw [← Equiv.sum_comp idx.symm, Fintype.sum_prod_type] have heach : ∀ (r : Fin q) (t : Fin 8), neuronNorm3 (U (idx.symm (r, t))) (V (idx.symm (r, t))) (W (idx.symm (r, t))) = (3 * (p : ℝ) / 2) * Real.sqrt (3 * (p : ℝ) / 2) := by intro r t simp only [U, V, W, Equiv.apply_symm_apply, neuronNorm3] have hcs := sum_cos_sin_sq_odd (q := q) (r.val + 1) (by omega) (by omega) have hcast : ((r.val + 1 : ℕ) : ℝ) = (r.val : ℝ) + 1 := by push_cast; rfl have hpcast : (2 * (q : ℝ) + 1) = (p : ℝ) := by simp [p] rw [hcast] at hcs have hu : zNormSq (fourierNeuronU q r t) = (p : ℝ) / 2 := by unfold zNormSq fourierNeuronU fin_cases t <;> first | simpa [hpcast] using hcs.1 | simpa [hpcast] using hcs.2 have hv : zNormSq (fourierNeuronV q r t) = (p : ℝ) / 2 := by unfold zNormSq fourierNeuronV fin_cases t <;> first | simpa [hpcast, neg_sq] using hcs.1 | simpa [hpcast, neg_sq] using hcs.2 have hw : zNormSq (fourierNeuronW q r t) = (p : ℝ) / 2 := by unfold zNormSq fourierNeuronW fin_cases t <;> first | simpa [hpcast, neg_sq] using hcs.1 | simpa [hpcast, neg_sq] using hcs.2 rw [hu, hv, hw] have h32 : (p : ℝ) / 2 + (p : ℝ) / 2 + (p : ℝ) / 2 = 3 * (p : ℝ) / 2 := by ring rw [h32] simp_rw [heach, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have hpq : (p : ℝ) = 2 * (q : ℝ) + 1 := by simp [p] push_cast have h8q : (q : ℝ) * 8 = 4 * ((p : ℝ) - 1) := by linarith rw [← mul_assoc, h8q] refine ⟨hlogits, hmarg, hnorm, ?_⟩ rw [hnorm] have hrt32 : Real.sqrt (3 * (p : ℝ) / 2) = Real.sqrt 3 * Real.sqrt (p : ℝ) / Real.sqrt 2 := by rw [Real.sqrt_div (by positivity), Real.sqrt_mul (by norm_num)] have hrt27 : Real.sqrt (2 / 27 : ℝ) = Real.sqrt 2 / (3 * Real.sqrt 3) := by rw [Real.sqrt_div (by norm_num)] have h27 : Real.sqrt 27 = 3 * Real.sqrt 3 := by have : (27 : ℝ) = 3 ^ 2 * 3 := by norm_num rw [this, Real.sqrt_mul (by norm_num), Real.sqrt_sq (by norm_num)] rw [h27] rw [hrt32, hrt27] have hsp_ne : Real.sqrt (p : ℝ) ≠ 0 := by positivity have hs2_ne : Real.sqrt 2 ≠ 0 := by positivity have hs3_ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hs2_ne, hs3_ne] ring /-- **Theorem 3.5 (Sharp Spatial-Sparsity Memorization Margin Barrier).** 1. For ANY quadratic network `(U, V, W)` on `ZMod p` (`p ≥ 2`) whose neurons have input support size `|{a | U_j a ≠ 0}| ≤ s` (or `|{b | V_j b ≠ 0}| ≤ s`): `γ ≤ (2 √s) / (3 √3 · p (p - 1)) · ‖θ‖_{2,3}³`. 2. For **pure pair-memorization** (`s = 1`, each neuron supported on at most one `a` and one `b`), the **EXACTLY SHARP** barrier improves by an extra factor `√((p - 1)/p)`: `γ ≤ 2 / (3 √3 · p^{3/2} √(p - 1)) · ‖θ‖_{2,3}³`. -/ theorem sparse_memorization_margin_upper_bound {p m s : ℕ} [NeZero p] (hp2 : 2 ≤ p) (U V W : Fin m → ZMod p → ℝ) {γ : ℝ} (hmargin : HasModAddMargin U V W Finset.univ γ) : ((∀ j : Fin m, (Finset.univ.filter fun a => U j a ≠ 0).card ≤ s) → γ ≤ 2 * Real.sqrt (s : ℝ) / (3 * Real.sqrt 3 * (p : ℝ) * ((p : ℝ) - 1)) * netNorm3 U V W) ∧ ((∀ j : Fin m, (Finset.univ.filter fun a => U j a ≠ 0).card ≤ 1 ∧ (Finset.univ.filter fun b => V j b ≠ 0).card ≤ 1) → γ ≤ 2 / (3 * Real.sqrt 3 * (p : ℝ) * Real.sqrt (p : ℝ) * Real.sqrt ((p : ℝ) - 1)) * netNorm3 U V W) := by have hp_pos : 0 < (p : ℝ) := by exact_mod_cast (show 0 < p by omega) have hpm1_pos : 0 < (p : ℝ) - 1 := by have : (2 : ℝ) ≤ (p : ℝ) := by exact_mod_cast hp2 linarith have hconv_total := quad_net_margin_le_sum_convolutions U V W hmargin constructor · intro hsupp have hsingle : ∀ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (s : ℝ) / (3 * Real.sqrt 3) * neuronNorm3 (U j) (V j) (W j) := by intro j set Su := Finset.univ.filter (fun a : ZMod p => U j a ≠ 0) have hrestrict : ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) = ∑ a ∈ Su, U j a * ∑ b : ZMod p, V j b * zCentered (W j) (a + b) := by have hsub : ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) = ∑ a ∈ Su, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) := by symm refine Finset.sum_subset (Finset.subset_univ Su) fun a _ ha => ?_ have h0 : U j a = 0 := by simpa [Su] using ha simp [h0] rw [hsub] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun b _ => ?_; ring rw [hrestrict] have hinner_cs : ∀ a : ZMod p, |∑ b : ZMod p, V j b * zCentered (W j) (a + b)| ≤ zNorm (V j) * zNorm (W j) := by intro a have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (V j) (fun b => zCentered (W j) (a + b)) have hshift : ∑ b : ZMod p, (zCentered (W j) (a + b)) ^ 2 = zNormSq (zCentered (W j)) := Equiv.sum_comp (Equiv.addLeft a) (fun c => (zCentered (W j) c) ^ 2) rw [hshift] at hcs have hle : (∑ b : ZMod p, V j b * zCentered (W j) (a + b)) ^ 2 ≤ (zNorm (V j) * zNorm (W j)) ^ 2 := by rw [mul_pow, zNorm_sq, zNorm_sq] exact le_trans hcs (mul_le_mul_of_nonneg_left (zCentered_normSq_le (W j)) (zNormSq_nonneg _)) rw [← sq_abs] at hle nlinarith [abs_nonneg (∑ b : ZMod p, V j b * zCentered (W j) (a + b)), mul_nonneg (zNorm_nonneg (V j)) (zNorm_nonneg (W j))] have hbound1 : ∑ a ∈ Su, U j a * ∑ b : ZMod p, V j b * zCentered (W j) (a + b) ≤ (∑ a ∈ Su, |U j a|) * (zNorm (V j) * zNorm (W j)) := by rw [Finset.sum_mul] refine Finset.sum_le_sum fun a _ => ?_ calc U j a * ∑ b : ZMod p, V j b * zCentered (W j) (a + b) ≤ |U j a * ∑ b : ZMod p, V j b * zCentered (W j) (a + b)| := le_abs_self _ _ = |U j a| * |∑ b : ZMod p, V j b * zCentered (W j) (a + b)| := abs_mul _ _ _ ≤ |U j a| * (zNorm (V j) * zNorm (W j)) := mul_le_mul_of_nonneg_left (hinner_cs a) (abs_nonneg _) have hl1_u : ∑ a ∈ Su, |U j a| ≤ Real.sqrt (s : ℝ) * zNorm (U j) := by have hcs := Finset.sum_mul_sq_le_sq_mul_sq Su (fun _ => (1 : ℝ)) (fun a => |U j a|) simp only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, sq_abs] at hcs have hsub_sq : ∑ a ∈ Su, (U j a) ^ 2 ≤ zNormSq (U j) := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ Su) (fun _ _ _ => sq_nonneg _) have hcard_le : (Su.card : ℝ) ≤ (s : ℝ) := by exact_mod_cast hsupp j have hsq : (∑ a ∈ Su, |U j a|) ^ 2 ≤ (Real.sqrt (s : ℝ) * zNorm (U j)) ^ 2 := by rw [mul_pow, Real.sq_sqrt (Nat.cast_nonneg s), zNorm_sq] exact le_trans hcs (mul_le_mul hcard_le hsub_sq (Finset.sum_nonneg fun _ _ => sq_nonneg _) (Nat.cast_nonneg s)) nlinarith [Finset.sum_nonneg (s := Su) (f := fun a => |U j a|) (fun _ _ => abs_nonneg _), mul_nonneg (Real.sqrt_nonneg (s : ℝ)) (zNorm_nonneg (U j))] have hstep : ∑ a ∈ Su, U j a * ∑ b : ZMod p, V j b * zCentered (W j) (a + b) ≤ Real.sqrt (s : ℝ) * (zNorm (U j) * zNorm (V j) * zNorm (W j)) := by have hmul := mul_le_mul_of_nonneg_right hl1_u (mul_nonneg (zNorm_nonneg (V j)) (zNorm_nonneg (W j))) linarith [show Real.sqrt (s : ℝ) * zNorm (U j) * (zNorm (V j) * zNorm (W j)) = Real.sqrt (s : ℝ) * (zNorm (U j) * zNorm (V j) * zNorm (W j)) by ring] have hamgm := amgm3_sqrt (zNormSq_nonneg (U j)) (zNormSq_nonneg (V j)) (zNormSq_nonneg (W j)) have hstep2 := mul_le_mul_of_nonneg_left hamgm (Real.sqrt_nonneg (s : ℝ)) unfold neuronNorm3 zNorm at * linarith [show Real.sqrt (s : ℝ) * ((zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) * Real.sqrt (zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) / (3 * Real.sqrt 3)) = Real.sqrt (s : ℝ) / (3 * Real.sqrt 3) * ((zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) * Real.sqrt (zNormSq (U j) + zNormSq (V j) + zNormSq (W j))) by ring] have hsum : ∑ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (s : ℝ) / (3 * Real.sqrt 3) * netNorm3 U V W := by unfold netNorm3; rw [Finset.mul_sum]; exact Finset.sum_le_sum fun j _ => hsingle j have htot := le_trans hconv_total (mul_le_mul_of_nonneg_left hsum (by positivity)) have hden_pos : 0 < (p : ℝ) ^ 2 * ((p : ℝ) - 1) := by positivity have hdiv := div_le_div_of_nonneg_right htot (le_of_lt hden_pos) have hL : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = γ := by field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos] have hR : 2 * (p : ℝ) * (Real.sqrt (s : ℝ) / (3 * Real.sqrt 3) * netNorm3 U V W) / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = 2 * Real.sqrt (s : ℝ) / (3 * Real.sqrt 3 * (p : ℝ) * ((p : ℝ) - 1)) * netNorm3 U V W := by have hs3ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hs3ne] linarith · intro hsupp1 have hsingle1 : ∀ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) / (3 * Real.sqrt 3) * neuronNorm3 (U j) (V j) (W j) := by intro j set Su := Finset.univ.filter (fun a : ZMod p => U j a ≠ 0) set Sv := Finset.univ.filter (fun b : ZMod p => V j b ≠ 0) have hcoord : ∀ c : ZMod p, |zCentered (W j) c| ≤ Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j) := by intro c have hsq := zCentered_coord_sq_le (W j) c have h1 : |zCentered (W j) c| ^ 2 ≤ (Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j)) ^ 2 := by rw [sq_abs, mul_pow, Real.sq_sqrt (by positivity), zNorm_sq]; exact hsq nlinarith [abs_nonneg (zCentered (W j) c), mul_nonneg (Real.sqrt_nonneg (((p : ℝ) - 1) / (p : ℝ))) (zNorm_nonneg (W j))] have hsum_restrict : ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) = ∑ a ∈ Su, ∑ b ∈ Sv, U j a * V j b * zCentered (W j) (a + b) := by symm refine (Finset.sum_subset (Finset.subset_univ Su) fun a _ ha => by have h0 : U j a = 0 := by simpa [Su] using ha simp [h0]).trans (Finset.sum_congr rfl fun a _ => ?_) refine Finset.sum_subset (Finset.subset_univ Sv) fun b _ hb => ?_ have h0 : V j b = 0 := by simpa [Sv] using hb simp [h0] rw [hsum_restrict] have hbound : ∑ a ∈ Su, ∑ b ∈ Sv, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j) * (∑ a ∈ Su, |U j a|) * (∑ b ∈ Sv, |V j b|) := by calc ∑ a ∈ Su, ∑ b ∈ Sv, U j a * V j b * zCentered (W j) (a + b) ≤ ∑ a ∈ Su, ∑ b ∈ Sv, |U j a| * |V j b| * (Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j)) := by refine Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => ?_ calc U j a * V j b * zCentered (W j) (a + b) ≤ |U j a * V j b * zCentered (W j) (a + b)| := le_abs_self _ _ = |U j a| * |V j b| * |zCentered (W j) (a + b)| := by rw [abs_mul, abs_mul] _ ≤ |U j a| * |V j b| * (Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j)) := mul_le_mul_of_nonneg_left (hcoord (a + b)) (by positivity) _ = Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j) * (∑ a ∈ Su, |U j a|) * (∑ b ∈ Sv, |V j b|) := by rw [Finset.mul_sum, Finset.sum_comm] refine Finset.sum_congr rfl fun b _ => ?_ rw [mul_assoc, Finset.sum_mul, Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => ?_; ring have hl1_1 : ∀ (f : ZMod p → ℝ) (Sf : Finset (ZMod p)), Sf.card ≤ 1 → ∑ x ∈ Sf, |f x| ≤ zNorm f := by intro f Sf hcard have hcs := Finset.sum_mul_sq_le_sq_mul_sq Sf (fun _ => (1 : ℝ)) (fun x => |f x|) simp only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, sq_abs] at hcs have hsub : ∑ x ∈ Sf, (f x) ^ 2 ≤ zNormSq f := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ Sf) (fun _ _ _ => sq_nonneg _) have hc1 : (Sf.card : ℝ) ≤ 1 := by exact_mod_cast hcard have hsq : (∑ x ∈ Sf, |f x|) ^ 2 ≤ (zNorm f) ^ 2 := by rw [zNorm_sq] exact le_trans hcs (by nlinarith [Finset.sum_nonneg (s := Sf) (f := fun x => (f x) ^ 2) (fun _ _ => sq_nonneg _)]) nlinarith [Finset.sum_nonneg (s := Sf) (f := fun x => |f x|) (fun _ _ => abs_nonneg _), zNorm_nonneg f] have hu1 := hl1_1 (U j) Su (hsupp1 j).1 have hv1 := hl1_1 (V j) Sv (hsupp1 j).2 have hstep : Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j) * (∑ a ∈ Su, |U j a|) * (∑ b ∈ Sv, |V j b|) ≤ Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * (zNorm (U j) * zNorm (V j) * zNorm (W j)) := by have hnn1 : 0 ≤ ∑ a ∈ Su, |U j a| := Finset.sum_nonneg fun _ _ => abs_nonneg _ have hnn2 : 0 ≤ ∑ b ∈ Sv, |V j b| := Finset.sum_nonneg fun _ _ => abs_nonneg _ have hprod : (∑ a ∈ Su, |U j a|) * (∑ b ∈ Sv, |V j b|) ≤ zNorm (U j) * zNorm (V j) := mul_le_mul hu1 hv1 hnn2 (zNorm_nonneg _) have hmul := mul_le_mul_of_nonneg_left hprod (mul_nonneg (Real.sqrt_nonneg (((p : ℝ) - 1) / (p : ℝ))) (zNorm_nonneg (W j))) linarith [show Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * zNorm (W j) * (zNorm (U j) * zNorm (V j)) = Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * (zNorm (U j) * zNorm (V j) * zNorm (W j)) by ring] have hamgm := amgm3_sqrt (zNormSq_nonneg (U j)) (zNormSq_nonneg (V j)) (zNormSq_nonneg (W j)) have hstep2 := mul_le_mul_of_nonneg_left hamgm (Real.sqrt_nonneg (((p : ℝ) - 1) / (p : ℝ))) unfold neuronNorm3 zNorm at * linarith [show Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) * ((zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) * Real.sqrt (zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) / (3 * Real.sqrt 3)) = Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) / (3 * Real.sqrt 3) * ((zNormSq (U j) + zNormSq (V j) + zNormSq (W j)) * Real.sqrt (zNormSq (U j) + zNormSq (V j) + zNormSq (W j))) by ring] have hsum : ∑ j : Fin m, ∑ a : ZMod p, ∑ b : ZMod p, U j a * V j b * zCentered (W j) (a + b) ≤ Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) / (3 * Real.sqrt 3) * netNorm3 U V W := by unfold netNorm3; rw [Finset.mul_sum]; exact Finset.sum_le_sum fun j _ => hsingle1 j have htot := le_trans hconv_total (mul_le_mul_of_nonneg_left hsum (by positivity)) have hden_pos : 0 < (p : ℝ) ^ 2 * ((p : ℝ) - 1) := by positivity have hdiv := div_le_div_of_nonneg_right htot (le_of_lt hden_pos) have hL : (p : ℝ) ^ 2 * ((p : ℝ) - 1) * γ / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = γ := by field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos] have hR : 2 * (p : ℝ) * (Real.sqrt (((p : ℝ) - 1) / (p : ℝ)) / (3 * Real.sqrt 3) * netNorm3 U V W) / ((p : ℝ) ^ 2 * ((p : ℝ) - 1)) = 2 / (3 * Real.sqrt 3 * (p : ℝ) * Real.sqrt (p : ℝ) * Real.sqrt ((p : ℝ) - 1)) * netNorm3 U V W := by rw [Real.sqrt_div (le_of_lt hpm1_pos)] have hsp_ne : Real.sqrt (p : ℝ) ≠ 0 := by positivity have hspm_ne : Real.sqrt ((p : ℝ) - 1) ≠ 0 := by positivity have hs3_ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hspm_ne, hs3_ne] rw [Real.sq_sqrt (le_of_lt hpm1_pos)] linarith /-- **Theorem 3.6 (Exact Pair-Memorization Margin on Arbitrary Subset `S ⊆ (ZMod p)²`).** For ANY nonempty training subset `S ⊆ (ZMod p)²` (`p ≥ 2`), the explicit `2 |S|`-neuron lookup-table network achieves zero interference on `S` and exact normalized margin `γ_mem(S) = (2 / (3 √3 · |S|)) · √(p / (p - 1))` — matching Theorem 3.5(2) with exact equality at `S = univ`! -/ theorem pair_memorization_subset_exact_margin {p : ℕ} [NeZero p] (hp2 : 2 ≤ p) (S : Finset (ZMod p × ZMod p)) (hS : S.Nonempty) : ∃ (m : ℕ) (U V W : Fin m → ZMod p → ℝ) (γ : ℝ), m = 2 * S.card ∧ HasModAddMargin U V W S γ ∧ 0 < netNorm3 U V W ∧ γ / netNorm3 U V W = 2 / (3 * Real.sqrt 3 * (S.card : ℝ)) * Real.sqrt ((p : ℝ) / ((p : ℝ) - 1)) := by have hp_pos : 0 < (p : ℝ) := by exact_mod_cast (show 0 < p by omega) have hpm1_pos : 0 < (p : ℝ) - 1 := by have : (2 : ℝ) ≤ (p : ℝ) := by exact_mod_cast hp2 linarith have hS_pos : 0 < (S.card : ℝ) := by exact_mod_cast hS.card_pos let enum : Fin S.card ≃ S := (Fintype.equivFinOfCardEq (Fintype.card_coe S)).symm let idx : Fin (2 * S.card) ≃ Fin 2 × Fin S.card := finProdFinEquiv.symm let scaleW : ℝ := Real.sqrt ((p : ℝ) / ((p : ℝ) - 1)) let U : Fin (2 * S.card) → ZMod p → ℝ := fun j a => if a = (enum (idx j).2).1.1 then 1 else 0 let V : Fin (2 * S.card) → ZMod p → ℝ := fun j b => let sgn : ℝ := if (idx j).1 = 0 then 1 else -1 if b = (enum (idx j).2).1.2 then sgn else 0 let W : Fin (2 * S.card) → ZMod p → ℝ := fun j c => let sgn : ℝ := if (idx j).1 = 0 then 1 else -1 let target := (enum (idx j).2).1.1 + (enum (idx j).2).1.2 sgn * scaleW * ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) refine ⟨2 * S.card, U, V, W, 4 * scaleW, rfl, ?_, ?_, ?_⟩ · intro ab hab c hc have hout : ∀ x : ZMod p, quadNetOut U V W ab.1 ab.2 x = 4 * scaleW * ((if x = ab.1 + ab.2 then (1 : ℝ) else 0) - 1 / (p : ℝ)) := by intro x unfold quadNetOut rw [← Equiv.sum_comp idx.symm, Fintype.sum_prod_type, Finset.sum_comm] -- For each pair k : Fin S.card, summing over Fin 2 gives 4 * 1_{ab = enum k} * w_k(x) have hpair : ∀ k : Fin S.card, ∑ t : Fin 2, quadNeuronOut (U (idx.symm (t, k))) (V (idx.symm (t, k))) (W (idx.symm (t, k))) ab.1 ab.2 x = if (enum k).1 = ab then 4 * scaleW * ((if x = ab.1 + ab.2 then (1 : ℝ) else 0) - 1 / (p : ℝ)) else 0 := by intro k rw [Fin.sum_univ_two] simp only [quadNeuronOut, U, V, W, Equiv.apply_symm_apply, ↓reduceIte, show (1 : Fin 2) ≠ 0 by decide] set a₀ := (enum k).1.1 set b₀ := (enum k).1.2 have hpol : ((if ab.1 = a₀ then (1 : ℝ) else 0) + (if ab.2 = b₀ then (1 : ℝ) else 0)) ^ 2 - ((if ab.1 = a₀ then (1 : ℝ) else 0) + (if ab.2 = b₀ then (-1 : ℝ) else 0)) ^ 2 = if (enum k).1 = ab then 4 else 0 := by by_cases ha : ab.1 = a₀ <;> by_cases hb : ab.2 = b₀ · have heq : (enum k).1 = ab := Prod.ext ha.symm hb.symm simp only [ha, hb, heq, ↓reduceIte]; ring · have hne : (enum k).1 ≠ ab := fun h => hb (congrArg Prod.snd h).symm simp only [ha, hb, hne, ↓reduceIte]; ring · have hne : (enum k).1 ≠ ab := fun h => ha (congrArg Prod.fst h).symm simp only [ha, hb, hne, ↓reduceIte]; ring · have hne : (enum k).1 ≠ ab := fun h => ha (congrArg Prod.fst h).symm simp only [ha, hb, hne, ↓reduceIte]; ring by_cases heq : (enum k).1 = ab · rw [if_pos heq] at hpol ⊢ have ha : a₀ + b₀ = ab.1 + ab.2 := by rw [← heq] rw [ha] linear_combination scaleW * ((if x = ab.1 + ab.2 then (1 : ℝ) else 0) - 1 / (p : ℝ)) * hpol · rw [if_neg heq] at hpol ⊢ linear_combination scaleW * ((if x = a₀ + b₀ then (1 : ℝ) else 0) - 1 / (p : ℝ)) * hpol simp_rw [hpair] rw [Finset.sum_eq_single (enum.symm ⟨ab, hab⟩)] · simp · intro k _ hk have hne : (enum k).1 ≠ ab := fun heq => hk (by apply enum.injective exact Subtype.ext (by simpa using heq)) rw [if_neg hne] · intro h; exact absurd (Finset.mem_univ _) h rw [hout (ab.1 + ab.2), hout c, if_pos rfl, if_neg hc] ring_nf; exact le_rfl · -- Norm = 2 * |S| * 3 √3 > 0 have hnorm_eq : netNorm3 U V W = 2 * (S.card : ℝ) * (3 * Real.sqrt 3) := by unfold netNorm3 have heach : ∀ j : Fin (2 * S.card), neuronNorm3 (U j) (V j) (W j) = 3 * Real.sqrt 3 := by intro j unfold neuronNorm3 have hu : zNormSq (U j) = 1 := by unfold zNormSq U rw [Finset.sum_eq_single (enum (idx j).2).1.1] · simp · intro a _ ha; simp [ha] · intro h; exact absurd (Finset.mem_univ _) h have hv : zNormSq (V j) = 1 := by unfold zNormSq V rw [Finset.sum_eq_single (enum (idx j).2).1.2] · by_cases h0 : (idx j).1 = 0 <;> simp [h0] · intro b _ hb; simp [hb] · intro h; exact absurd (Finset.mem_univ _) h have hw : zNormSq (W j) = 1 := by unfold zNormSq W set target := (enum (idx j).2).1.1 + (enum (idx j).2).1.2 have hsgn : (if (idx j).1 = 0 then (1 : ℝ) else -1) ^ 2 = 1 := by by_cases h0 : (idx j).1 = 0 <;> simp [h0] have hscale : scaleW ^ 2 = (p : ℝ) / ((p : ℝ) - 1) := Real.sq_sqrt (by positivity) have hsum_sq : ∑ c : ZMod p, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = ((p : ℝ) - 1) / (p : ℝ) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ target), if_pos rfl] have hrest : ∑ c ∈ Finset.univ.erase target, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = ((p : ℝ) - 1) * (1 / (p : ℝ)) ^ 2 := by have hpt : ∀ c ∈ Finset.univ.erase target, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = (1 / (p : ℝ)) ^ 2 := by intro c hc; rw [if_neg (Finset.mem_erase.mp hc).1]; ring rw [Finset.sum_congr rfl hpt, Finset.sum_const, nsmul_eq_mul, Finset.card_erase_of_mem (Finset.mem_univ target), Finset.card_univ, ZMod.card, Nat.cast_sub (by omega)] simp rw [hrest]; field_simp [ne_of_gt hp_pos]; ring have hpull : ∑ c : ZMod p, ((if (idx j).1 = 0 then (1 : ℝ) else -1) * scaleW * ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ))) ^ 2 = ((if (idx j).1 = 0 then (1 : ℝ) else -1) ^ 2 * scaleW ^ 2) * ∑ c : ZMod p, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 := by rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun c _ => ?_; ring rw [hpull, hsgn, one_mul, hscale, hsum_sq] field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos] rw [hu, hv, hw]; norm_num simp_rw [heach, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] push_cast; ring rw [hnorm_eq]; positivity · -- Exact ratio have hnorm_eq : netNorm3 U V W = 2 * (S.card : ℝ) * (3 * Real.sqrt 3) := by unfold netNorm3 have heach : ∀ j : Fin (2 * S.card), neuronNorm3 (U j) (V j) (W j) = 3 * Real.sqrt 3 := by intro j unfold neuronNorm3 have hu : zNormSq (U j) = 1 := by unfold zNormSq U rw [Finset.sum_eq_single (enum (idx j).2).1.1] · simp · intro a _ ha; simp [ha] · intro h; exact absurd (Finset.mem_univ _) h have hv : zNormSq (V j) = 1 := by unfold zNormSq V rw [Finset.sum_eq_single (enum (idx j).2).1.2] · by_cases h0 : (idx j).1 = 0 <;> simp [h0] · intro b _ hb; simp [hb] · intro h; exact absurd (Finset.mem_univ _) h have hw : zNormSq (W j) = 1 := by unfold zNormSq W set target := (enum (idx j).2).1.1 + (enum (idx j).2).1.2 have hsgn : (if (idx j).1 = 0 then (1 : ℝ) else -1) ^ 2 = 1 := by by_cases h0 : (idx j).1 = 0 <;> simp [h0] have hscale : scaleW ^ 2 = (p : ℝ) / ((p : ℝ) - 1) := Real.sq_sqrt (by positivity) have hsum_sq : ∑ c : ZMod p, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = ((p : ℝ) - 1) / (p : ℝ) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ target), if_pos rfl] have hrest : ∑ c ∈ Finset.univ.erase target, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = ((p : ℝ) - 1) * (1 / (p : ℝ)) ^ 2 := by have hpt : ∀ c ∈ Finset.univ.erase target, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 = (1 / (p : ℝ)) ^ 2 := by intro c hc; rw [if_neg (Finset.mem_erase.mp hc).1]; ring rw [Finset.sum_congr rfl hpt, Finset.sum_const, nsmul_eq_mul, Finset.card_erase_of_mem (Finset.mem_univ target), Finset.card_univ, ZMod.card, Nat.cast_sub (by omega)] simp rw [hrest]; field_simp [ne_of_gt hp_pos]; ring have hpull : ∑ c : ZMod p, ((if (idx j).1 = 0 then (1 : ℝ) else -1) * scaleW * ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ))) ^ 2 = ((if (idx j).1 = 0 then (1 : ℝ) else -1) ^ 2 * scaleW ^ 2) * ∑ c : ZMod p, ((if c = target then (1 : ℝ) else 0) - 1 / (p : ℝ)) ^ 2 := by rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun c _ => ?_; ring rw [hpull, hsgn, one_mul, hscale, hsum_sq] field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos] rw [hu, hv, hw]; norm_num simp_rw [heach, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] push_cast; ring rw [hnorm_eq] have hs3ne : Real.sqrt 3 ≠ 0 := by positivity field_simp [ne_of_gt hS_pos, hs3ne]; ring /-- **Theorem 3.7 (Exact Grokking Margin Separation & Subset-Size Phase Transition).** Comparing the exact Fourier grokking margin `γ_F(p) = √(2/27) / (√p (p - 1))` against: - `γ_mem(p, M) = (2 / (3 √3 · M)) · √(p / (p - 1))` (pair memorization on training subset of size `M`), - `γ_sparse(p, s) = (2 √s) / (3 √3 · p (p - 1))` (`s`-sparse memorization barrier on full table): 1. **Exact full-table separation (`M = p²`)**: `γ_F(p) / γ_mem(p, p²) = p / √(2 (p - 1)) > √(p / 2)`. 2. **Exact `s`-sparse separation (`0 < s`)**: `γ_F(p) / γ_sparse(p, s) = √(p / (2 s))`. 3. **Exact subset-size grokking phase transition**: `γ_F(p) > γ_mem(p, M) ↔ √2 · p · √(p - 1) < M`! -/ theorem grokking_margin_separation_and_phase_transition {p M s : ℝ} (hp : 3 ≤ p) (hM : 0 < M) (hs : 0 < s) : let γF := Real.sqrt (2 / 27) / (Real.sqrt p * (p - 1)) let γMem := 2 / (3 * Real.sqrt 3 * M) * Real.sqrt (p / (p - 1)) let γMemFull := 2 / (3 * Real.sqrt 3 * p ^ 2) * Real.sqrt (p / (p - 1)) let γSparse := 2 * Real.sqrt s / (3 * Real.sqrt 3 * p * (p - 1)) (γF / γMemFull = p / Real.sqrt (2 * (p - 1)) ∧ Real.sqrt (p / 2) < γF / γMemFull) ∧ (γF / γSparse = Real.sqrt (p / (2 * s))) ∧ (γMem < γF ↔ Real.sqrt 2 * p * Real.sqrt (p - 1) < M) := by dsimp only have hp_pos : 0 < p := by linarith have hpm1_pos : 0 < p - 1 := by linarith have hrt27 : Real.sqrt (2 / 27 : ℝ) = Real.sqrt 2 / (3 * Real.sqrt 3) := by rw [Real.sqrt_div (by norm_num)] have h27 : Real.sqrt 27 = 3 * Real.sqrt 3 := by have : (27 : ℝ) = 3 ^ 2 * 3 := by norm_num rw [this, Real.sqrt_mul (by norm_num), Real.sqrt_sq (by norm_num)] rw [h27] have hsp2 : Real.sqrt p * Real.sqrt p = p := Real.mul_self_sqrt (le_of_lt hp_pos) have hs22 : Real.sqrt 2 * Real.sqrt 2 = 2 := Real.mul_self_sqrt (by norm_num) have hspm2 : Real.sqrt (p - 1) * Real.sqrt (p - 1) = p - 1 := Real.mul_self_sqrt (le_of_lt hpm1_pos) have hsp_ne : Real.sqrt p ≠ 0 := by positivity have hspm_ne : Real.sqrt (p - 1) ≠ 0 := by positivity have hs2_ne : Real.sqrt 2 ≠ 0 := by positivity have hs3_ne : Real.sqrt 3 ≠ 0 := by positivity have hss_ne : Real.sqrt s ≠ 0 := by positivity refine ⟨⟨?_, ?_⟩, ?_, ?_⟩ · -- Full-table exact ratio rw [hrt27, Real.sqrt_div (le_of_lt hp_pos), Real.sqrt_mul (by norm_num)] field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hspm_ne, hs2_ne, hs3_ne] rw [Real.sq_sqrt (le_of_lt hp_pos), Real.sq_sqrt (by norm_num), Real.sq_sqrt (le_of_lt hpm1_pos)] ring · -- Strictly beats √(p / 2) have hrat : Real.sqrt (2 / 27) / (Real.sqrt p * (p - 1)) / (2 / (3 * Real.sqrt 3 * p ^ 2) * Real.sqrt (p / (p - 1))) = p / Real.sqrt (2 * (p - 1)) := by rw [hrt27, Real.sqrt_div (le_of_lt hp_pos), Real.sqrt_mul (by norm_num)] field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hspm_ne, hs2_ne, hs3_ne] rw [Real.sq_sqrt (le_of_lt hp_pos), Real.sq_sqrt (by norm_num), Real.sq_sqrt (le_of_lt hpm1_pos)] ring rw [hrat] have hsq : Real.sqrt (p / 2) ^ 2 < (p / Real.sqrt (2 * (p - 1))) ^ 2 := by rw [Real.sq_sqrt (by positivity), div_pow, Real.sq_sqrt (by positivity)] rw [div_lt_div_iff₀ (by norm_num) (by positivity)] nlinarith nlinarith [Real.sqrt_nonneg (p / 2), div_nonneg (le_of_lt hp_pos) (Real.sqrt_nonneg (2 * (p - 1)))] · -- s-sparse exact ratio rw [hrt27, Real.sqrt_div (le_of_lt hp_pos), Real.sqrt_mul (by norm_num)] field_simp [ne_of_gt hp_pos, ne_of_gt hpm1_pos, hsp_ne, hs2_ne, hs3_ne, hss_ne] rw [Real.sq_sqrt (le_of_lt hp_pos), Real.sq_sqrt (by norm_num)] ring · -- Exact subset-size grokking phase transition rw [hrt27, Real.sqrt_div (le_of_lt hp_pos)] have hL : 2 / (3 * Real.sqrt 3 * M) * (Real.sqrt p / Real.sqrt (p - 1)) = (2 * Real.sqrt p) / (3 * Real.sqrt 3 * M * Real.sqrt (p - 1)) := by field_simp [ne_of_gt hM, hspm_ne, hs3_ne] have hR : Real.sqrt 2 / (3 * Real.sqrt 3) / (Real.sqrt p * (p - 1)) = Real.sqrt 2 / (3 * Real.sqrt 3 * Real.sqrt p * (p - 1)) := by field_simp [ne_of_gt hpm1_pos, hsp_ne, hs3_ne] rw [hL, hR, div_lt_div_iff₀ (by positivity) (by positivity)] constructor · intro hlt have hcoef : 0 < 3 * Real.sqrt 3 * Real.sqrt (p - 1) := by positivity have hrew : 2 * Real.sqrt p * (3 * Real.sqrt 3 * Real.sqrt p * (p - 1)) = (3 * Real.sqrt 3 * Real.sqrt (p - 1)) * (Real.sqrt 2 * (Real.sqrt 2 * p * Real.sqrt (p - 1))) := by calc 2 * Real.sqrt p * (3 * Real.sqrt 3 * Real.sqrt p * (p - 1)) = 3 * Real.sqrt 3 * 2 * (Real.sqrt p * Real.sqrt p) * (p - 1) := by ring _ = 3 * Real.sqrt 3 * (Real.sqrt 2 * Real.sqrt 2) * p * (Real.sqrt (p - 1) * Real.sqrt (p - 1)) := by rw [hsp2, hs22, hspm2] _ = _ := by ring have hrew2 : Real.sqrt 2 * (3 * Real.sqrt 3 * M * Real.sqrt (p - 1)) = (3 * Real.sqrt 3 * Real.sqrt (p - 1)) * (Real.sqrt 2 * M) := by ring rw [hrew, hrew2] at hlt have hlt2 := lt_of_mul_lt_mul_left hlt (le_of_lt hcoef) exact lt_of_mul_lt_mul_left hlt2 (Real.sqrt_nonneg 2) · intro hMgt have hcoef : 0 < 3 * Real.sqrt 3 * Real.sqrt (p - 1) := by positivity have hrew : 2 * Real.sqrt p * (3 * Real.sqrt 3 * Real.sqrt p * (p - 1)) = (3 * Real.sqrt 3 * Real.sqrt (p - 1)) * (Real.sqrt 2 * (Real.sqrt 2 * p * Real.sqrt (p - 1))) := by calc 2 * Real.sqrt p * (3 * Real.sqrt 3 * Real.sqrt p * (p - 1)) = 3 * Real.sqrt 3 * 2 * (Real.sqrt p * Real.sqrt p) * (p - 1) := by ring _ = 3 * Real.sqrt 3 * (Real.sqrt 2 * Real.sqrt 2) * p * (Real.sqrt (p - 1) * Real.sqrt (p - 1)) := by rw [hsp2, hs22, hspm2] _ = _ := by ring have hrew2 : Real.sqrt 2 * (3 * Real.sqrt 3 * M * Real.sqrt (p - 1)) = (3 * Real.sqrt 3 * Real.sqrt (p - 1)) * (Real.sqrt 2 * M) := by ring rw [hrew, hrew2] exact mul_lt_mul_of_pos_left (mul_lt_mul_of_pos_left hMgt (by positivity)) hcoef end Pillar3 /-! ============================================================================ SECTION 4: SHARP RELU / BARRON DEPTH-SEPARATION BOUNDS (EXACT SAWTOOTH OSCILLATIONS, L∞ / L¹ LOWER BOUNDS, INFINITE-WIDTH BARRON-NORM SEPARATION & BARRON–MAUREY O(1/m)) ============================================================================ -/ section Pillar4 /-- Rectified Linear Unit `ReLU(x) = max(0, x)`. -/ def relu (x : ℝ) : ℝ := max 0 x lemma relu_nonneg (x : ℝ) : 0 ≤ relu x := le_max_left 0 x lemma relu_of_nonneg {x : ℝ} (hx : 0 ≤ x) : relu x = x := max_eq_right hx lemma relu_of_nonpos {x : ℝ} (hx : x ≤ 0) : relu x = 0 := max_eq_left hx lemma relu_lip (x y : ℝ) : |relu x - relu y| ≤ |x - y| := by unfold relu rcases le_total 0 x with hx | hx <;> rcases le_total 0 y with hy | hy · rw [max_eq_right hx, max_eq_right hy] · rw [max_eq_right hx, max_eq_left hy, sub_zero, abs_of_nonneg hx, abs_of_nonneg (by linarith)] linarith · rw [max_eq_left hx, max_eq_right hy, zero_sub, abs_neg, abs_of_nonneg hy, abs_of_nonpos (by linarith)] linarith · rw [max_eq_left hx, max_eq_left hy, sub_self, abs_zero] exact abs_nonneg _ lemma continuous_relu : Continuous relu := continuous_const.max continuous_id /-- Explicit `w`-neuron 1D ReLU sawtooth layer on `[0, 1]`: `S_w(x) = ReLU(w x) + ∑_{j=1}^{w-1} 2 (-1)^j ReLU(w x - j)`. -/ def sawtoothLayer (w : ℕ) (x : ℝ) : ℝ := relu ((w : ℝ) * x) + ∑ j ∈ Finset.Ico 1 w, 2 * (-1 : ℝ) ^ j * relu ((w : ℝ) * x - (j : ℝ)) /-- `L`-layer iterated ReLU sawtooth network `S_w^[L]` (depth `L`, width `w`, `w L` total ReLUs). -/ def sawtoothIter (w L : ℕ) (x : ℝ) : ℝ := (sawtoothLayer w)^[L] x lemma continuous_sawtoothLayer (w : ℕ) : Continuous (sawtoothLayer w) := by unfold sawtoothLayer refine (continuous_relu.comp (continuous_const.mul continuous_id)).add ?_ refine continuous_finsetSum _ fun j _ => ?_ exact continuous_const.mul (continuous_relu.comp ((continuous_const.mul continuous_id).sub continuous_const)) lemma continuous_sawtoothIter (w L : ℕ) : Continuous (sawtoothIter w L) := by unfold sawtoothIter induction L with | zero => exact continuous_id | succ L ih => rw [Function.iterate_succ'] exact (continuous_sawtoothLayer w).comp ih /-- Alternating telescoping sum identity for `sawtoothLayer`. -/ lemma sawtooth_telescope (y : ℝ) (k : ℕ) : y + ∑ j ∈ Finset.Ico 1 (k + 1), 2 * (-1 : ℝ) ^ j * (y - (j : ℝ)) = if Even k then y - (k : ℝ) else (k : ℝ) + 1 - y := by induction k with | zero => simp | succ k ih => rw [Finset.sum_Ico_succ_top (by omega : 1 ≤ k + 1), ← add_assoc, ih] by_cases hk : Even k · have hodd : ¬ Even (k + 1) := by simp [Nat.even_add_one, hk] rw [if_pos hk, if_neg hodd] have hpow : (-1 : ℝ) ^ (k + 1) = -1 := by obtain ⟨m, rfl⟩ := hk rw [show m + m + 1 = 2 * m + 1 by omega, pow_succ, pow_mul] norm_num rw [hpow]; push_cast; ring · have hev : Even (k + 1) := by rwa [Nat.even_add_one] rw [if_neg hk, if_pos hev] have hpow : (-1 : ℝ) ^ (k + 1) = 1 := by obtain ⟨m, hm⟩ := hev rw [hm, ← two_mul, pow_mul]; norm_num rw [hpow]; push_cast; ring /-- Exact piecewise-linear formula for `sawtoothLayer w` on `[k / w, (k + 1) / w]`. -/ lemma sawtoothLayer_piece {w k : ℕ} (hk : k < w) {x : ℝ} (hxlo : (k : ℝ) / (w : ℝ) ≤ x) (hxhi : x ≤ ((k : ℝ) + 1) / (w : ℝ)) : sawtoothLayer w x = if Even k then (w : ℝ) * x - (k : ℝ) else (k : ℝ) + 1 - (w : ℝ) * x := by have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hy_lo : (k : ℝ) ≤ (w : ℝ) * x := by have := mul_le_mul_of_nonneg_left hxlo (le_of_lt hw_pos) rwa [mul_div_cancel₀ _ (ne_of_gt hw_pos)] at this have hy_hi : (w : ℝ) * x ≤ (k : ℝ) + 1 := by have := mul_le_mul_of_nonneg_left hxhi (le_of_lt hw_pos) rwa [mul_div_cancel₀ _ (ne_of_gt hw_pos)] at this have hy_nn : 0 ≤ (w : ℝ) * x := le_trans (Nat.cast_nonneg k) hy_lo unfold sawtoothLayer rw [relu_of_nonneg hy_nn] have hsplit : Finset.Ico 1 w = Finset.Ico 1 (k + 1) ∪ Finset.Ico (k + 1) w := (Finset.Ico_union_Ico_eq_Ico (by omega) (by omega)).symm have hdisj : Disjoint (Finset.Ico 1 (k + 1)) (Finset.Ico (k + 1) w) := Finset.Ico_disjoint_Ico_consecutive 1 (k + 1) w rw [hsplit, Finset.sum_union hdisj] have hzero : ∑ j ∈ Finset.Ico (k + 1) w, 2 * (-1 : ℝ) ^ j * relu ((w : ℝ) * x - (j : ℝ)) = 0 := by refine Finset.sum_eq_zero fun j hj => ?_ have hj_ge : k + 1 ≤ j := (Finset.mem_Ico.mp hj).1 have hj_geR : (k : ℝ) + 1 ≤ (j : ℝ) := by exact_mod_cast hj_ge rw [relu_of_nonpos (by linarith), mul_zero] have hpos : ∑ j ∈ Finset.Ico 1 (k + 1), 2 * (-1 : ℝ) ^ j * relu ((w : ℝ) * x - (j : ℝ)) = ∑ j ∈ Finset.Ico 1 (k + 1), 2 * (-1 : ℝ) ^ j * ((w : ℝ) * x - (j : ℝ)) := by refine Finset.sum_congr rfl fun j hj => ?_ have hj_le : j ≤ k := by have := (Finset.mem_Ico.mp hj).2; omega have hj_leR : (j : ℝ) ≤ (k : ℝ) := by exact_mod_cast hj_le rw [relu_of_nonneg (by linarith)] rw [hzero, add_zero, hpos] exact sawtooth_telescope ((w : ℝ) * x) k /-- **Theorem 4.1 (Exact `w^L`-Piece Iterated Sawtooth Formula & Alternating Grid Extrema).** For EVERY even width `w ≥ 2` and EVERY depth `L : ℕ`: 1. On every interval `[k / w^L, (k + 1) / w^L]` (`k < w^L`), `S_w^[L](x) = w^L x - k` (for even `k`) and `(k + 1) - w^L x` (for odd `k`). 2. At all `w^L + 1` grid points `x_k = k / w^L` (`k ≤ w^L`), `S_w^[L](k / w^L) = if Even k then 0 else 1` (exact `w^L` full `0–1` oscillations!). -/ theorem sawtoothIter_exact_piece_and_grid {w : ℕ} (hw2 : 2 ≤ w) (hweven : Even w) (L : ℕ) : (∀ (k : ℕ), k < w ^ L → ∀ x : ℝ, (k : ℝ) / ((w : ℝ) ^ L) ≤ x → x ≤ ((k : ℝ) + 1) / ((w : ℝ) ^ L) → sawtoothIter w L x = if Even k then (w : ℝ) ^ L * x - (k : ℝ) else (k : ℝ) + 1 - (w : ℝ) ^ L * x) ∧ (∀ (k : ℕ), k ≤ w ^ L → sawtoothIter w L ((k : ℝ) / ((w : ℝ) ^ L)) = if Even k then 0 else 1) := by have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hpiece : ∀ (L k : ℕ), k < w ^ L → ∀ x : ℝ, (k : ℝ) / ((w : ℝ) ^ L) ≤ x → x ≤ ((k : ℝ) + 1) / ((w : ℝ) ^ L) → sawtoothIter w L x = if Even k then (w : ℝ) ^ L * x - (k : ℝ) else (k : ℝ) + 1 - (w : ℝ) ^ L * x := by intro L induction L with | zero => intro k hk x _ _ have hk0 : k = 0 := by simpa using hk subst hk0 simp [sawtoothIter] | succ L ih => intro k hk x hxlo hxhi have hstep : sawtoothIter w (L + 1) x = sawtoothLayer w (sawtoothIter w L x) := by unfold sawtoothIter; rw [Function.iterate_succ_apply'] rw [hstep] set q := k / w set r := k % w have hkr : k = q * w + r := by simp only [q, r] have := Nat.div_add_mod k w linarith [mul_comm w (k / w)] have hr_lt : r < w := Nat.mod_lt k (by omega) have hq_lt : q < w ^ L := by rw [pow_succ] at hk exact Nat.div_lt_of_lt_mul (by linarith [mul_comm (w ^ L) w]) have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L have hq_lo : (q : ℝ) / ((w : ℝ) ^ L) ≤ x := by have hk_ge : (q : ℝ) * (w : ℝ) ≤ (k : ℝ) := by exact_mod_cast (by omega : q * w ≤ k) have h1 : (q : ℝ) / ((w : ℝ) ^ L) ≤ (k : ℝ) / ((w : ℝ) ^ (L + 1)) := by rw [pow_succ, div_le_div_iff₀ hwL_pos (by positivity)] nlinarith exact le_trans h1 hxlo have hq_hi : x ≤ ((q : ℝ) + 1) / ((w : ℝ) ^ L) := by have hk_le : (k : ℝ) + 1 ≤ ((q : ℝ) + 1) * (w : ℝ) := by have : k + 1 ≤ (q + 1) * w := by nlinarith exact_mod_cast this have h1 : ((k : ℝ) + 1) / ((w : ℝ) ^ (L + 1)) ≤ ((q : ℝ) + 1) / ((w : ℝ) ^ L) := by rw [pow_succ, div_le_div_iff₀ (by positivity) hwL_pos] nlinarith exact le_trans hxhi h1 have hinner := ih q hq_lt x hq_lo hq_hi rw [hinner] have hwx_lo : (k : ℝ) ≤ (w : ℝ) ^ (L + 1) * x := by have := mul_le_mul_of_nonneg_left hxlo (le_of_lt (pow_pos hw_pos (L + 1))) rwa [mul_div_cancel₀ _ (ne_of_gt (pow_pos hw_pos (L + 1)))] at this have hwx_hi : (w : ℝ) ^ (L + 1) * x ≤ (k : ℝ) + 1 := by have := mul_le_mul_of_nonneg_left hxhi (le_of_lt (pow_pos hw_pos (L + 1))) rwa [mul_div_cancel₀ _ (ne_of_gt (pow_pos hw_pos (L + 1)))] at this have hkR : (k : ℝ) = (q : ℝ) * (w : ℝ) + (r : ℝ) := by exact_mod_cast hkr have hev_iff : Even k ↔ Even r := by rw [hkr, Nat.even_add] have hqw : Even (q * w) := hweven.mul_left q simp [hqw] by_cases hqev : Even q · rw [if_pos hqev] have hy_lo : (r : ℝ) / (w : ℝ) ≤ (w : ℝ) ^ L * x - (q : ℝ) := by rw [div_le_iff₀ hw_pos] have : (w : ℝ) ^ (L + 1) * x = ((w : ℝ) ^ L * x) * (w : ℝ) := by rw [pow_succ]; ring linarith have hy_hi : (w : ℝ) ^ L * x - (q : ℝ) ≤ ((r : ℝ) + 1) / (w : ℝ) := by rw [le_div_iff₀ hw_pos] have : (w : ℝ) ^ (L + 1) * x = ((w : ℝ) ^ L * x) * (w : ℝ) := by rw [pow_succ]; ring linarith rw [sawtoothLayer_piece hr_lt hy_lo hy_hi] by_cases hrev : Even r · rw [if_pos hrev, if_pos (hev_iff.mpr hrev), pow_succ]; linarith · rw [if_neg hrev, if_neg (fun h => hrev (hev_iff.mp h)), pow_succ]; linarith · rw [if_neg hqev] set r' := w - 1 - r have hr'_lt : r' < w := by omega have hr'R : (r' : ℝ) = (w : ℝ) - 1 - (r : ℝ) := by have h1 : 1 ≤ w := by omega have h2 : r ≤ w - 1 := by omega simp only [r'] rw [Nat.cast_sub h2, Nat.cast_sub h1]; simp have hy_lo : (r' : ℝ) / (w : ℝ) ≤ (q : ℝ) + 1 - (w : ℝ) ^ L * x := by rw [div_le_iff₀ hw_pos, hr'R] have : (w : ℝ) ^ (L + 1) * x = ((w : ℝ) ^ L * x) * (w : ℝ) := by rw [pow_succ]; ring linarith have hy_hi : (q : ℝ) + 1 - (w : ℝ) ^ L * x ≤ ((r' : ℝ) + 1) / (w : ℝ) := by rw [le_div_iff₀ hw_pos, hr'R] have : (w : ℝ) ^ (L + 1) * x = ((w : ℝ) ^ L * x) * (w : ℝ) := by rw [pow_succ]; ring linarith rw [sawtoothLayer_piece hr'_lt hy_lo hy_hi] have hr'_parity : Even r' ↔ ¬ Even r := by obtain ⟨m, hm⟩ := hweven have hsum : r' + r + 1 = m + m := by omega constructor · intro h1 h2 have h3 : Even (r' + r) := h1.add h2 have h4 : Odd (r' + r + 1) := h3.add_one rw [hsum] at h4 exact (Nat.not_even_iff_odd.mpr h4) ⟨m, rfl⟩ · intro h2 have h2' : Odd r := Nat.not_even_iff_odd.mp h2 by_contra h1 have h1' : Odd r' := Nat.not_even_iff_odd.mp h1 have h3 : Even (r' + r) := Odd.add_odd h1' h2' have h4 : Odd (r' + r + 1) := h3.add_one rw [hsum] at h4 exact (Nat.not_even_iff_odd.mpr h4) ⟨m, rfl⟩ by_cases hrev : Even r · rw [if_neg (fun h => hr'_parity.mp h hrev), if_pos (hev_iff.mpr hrev), hr'R, pow_succ] linarith · rw [if_pos (hr'_parity.mpr hrev), if_neg (fun h => hrev (hev_iff.mp h)), hr'R, pow_succ] linarith refine ⟨hpiece L, ?_⟩ intro k hk have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L rcases lt_or_eq_of_le hk with hlt | rfl · have h := hpiece L k hlt ((k : ℝ) / (w : ℝ) ^ L) le_rfl (div_le_div_of_nonneg_right (by linarith) (le_of_lt hwL_pos)) rw [h, mul_div_cancel₀ _ (ne_of_gt hwL_pos)] by_cases hk_ev : Even k <;> simp [hk_ev] · rcases Nat.eq_zero_or_pos L with rfl | hLpos · simp [sawtoothIter] · have hpos : 1 ≤ w ^ L := Nat.one_le_pow L w (by omega) have hlt : w ^ L - 1 < w ^ L := by omega have hcast : ((w ^ L - 1 : ℕ) : ℝ) + 1 = (w : ℝ) ^ L := by rw [Nat.cast_sub hpos]; push_cast; ring have h := hpiece L (w ^ L - 1) hlt (((w ^ L : ℕ) : ℝ) / (w : ℝ) ^ L) (div_le_div_of_nonneg_right (by exact_mod_cast Nat.sub_le _ 1) (le_of_lt hwL_pos)) (by push_cast; rw [hcast]) have hev_wL : Even (w ^ L) := hweven.pow_of_ne_zero (by omega) have hodd_sub : ¬ Even (w ^ L - 1) := by intro h1 have h2 : Odd ((w ^ L - 1) + 1) := h1.add_one rw [Nat.sub_add_cancel hpos] at h2 exact (Nat.not_even_iff_odd.mpr h2) hev_wL rw [h, if_neg hodd_sub, if_pos hev_wL, hcast] push_cast rw [mul_div_cancel₀ _ (ne_of_gt hwL_pos), sub_self] /-- Continuous piecewise-affine function on `ℝ` with breakpoint set `B : Finset ℝ`. -/ def IsPiecewiseAffine (B : Finset ℝ) (f : ℝ → ℝ) : Prop := Continuous f ∧ ∀ a b : ℝ, a ≤ b → (∀ x ∈ B, ¬ (a < x ∧ x < b)) → ∃ m c : ℝ, ∀ x ∈ Set.Icc a b, f x = m * x + c lemma isPiecewiseAffine_mono {B B' : Finset ℝ} {f : ℝ → ℝ} (hsub : B ⊆ B') (hf : IsPiecewiseAffine B f) : IsPiecewiseAffine B' f := ⟨hf.1, fun a b hab hdisj => hf.2 a b hab fun x hx => hdisj x (hsub hx)⟩ lemma isPiecewiseAffine_const (B : Finset ℝ) (c : ℝ) : IsPiecewiseAffine B (fun _ => c) := ⟨continuous_const, fun _ _ _ _ => ⟨0, c, fun _ _ => by ring⟩⟩ lemma isPiecewiseAffine_id (B : Finset ℝ) : IsPiecewiseAffine B id := ⟨continuous_id, fun _ _ _ _ => ⟨1, 0, fun _ _ => by simp⟩⟩ lemma isPiecewiseAffine_add {B : Finset ℝ} {f g : ℝ → ℝ} (hf : IsPiecewiseAffine B f) (hg : IsPiecewiseAffine B g) : IsPiecewiseAffine B (fun x => f x + g x) := by refine ⟨hf.1.add hg.1, fun a b hab hdisj => ?_⟩ obtain ⟨m₁, c₁, h₁⟩ := hf.2 a b hab hdisj obtain ⟨m₂, c₂, h₂⟩ := hg.2 a b hab hdisj exact ⟨m₁ + m₂, c₁ + c₂, fun x hx => by dsimp only; rw [h₁ x hx, h₂ x hx]; ring⟩ lemma isPiecewiseAffine_const_mul {B : Finset ℝ} {f : ℝ → ℝ} (α : ℝ) (hf : IsPiecewiseAffine B f) : IsPiecewiseAffine B (fun x => α * f x) := by refine ⟨continuous_const.mul hf.1, fun a b hab hdisj => ?_⟩ obtain ⟨m, c, h⟩ := hf.2 a b hab hdisj exact ⟨α * m, α * c, fun x hx => by dsimp only; rw [h x hx]; ring⟩ lemma isPiecewiseAffine_finset_sum {ι : Type*} (s : Finset ι) {B : Finset ℝ} (f : ι → ℝ → ℝ) (hf : ∀ i ∈ s, IsPiecewiseAffine B (f i)) : IsPiecewiseAffine B (fun x => ∑ i ∈ s, f i x) := by classical induction s using Finset.induction_on with | empty => simpa using isPiecewiseAffine_const B 0 | insert a s ha ih => have h1 : (fun x => ∑ i ∈ insert a s, f i x) = fun x => f a x + ∑ i ∈ s, f i x := by ext x; exact Finset.sum_insert ha rw [h1] exact isPiecewiseAffine_add (hf a (Finset.mem_insert_self a s)) (ih fun i hi => hf i (Finset.mem_insert_of_mem hi)) /-- An affine function on `[a, b]` whose unique root (if `m ≠ 0`) does not lie in `(a, b)` is affine after applying `relu`. -/ lemma relu_affine_of_no_root {a b m c : ℝ} (hab : a ≤ b) (hno : ∀ x : ℝ, a < x → x < b → m * x + c ≠ 0) : ∃ m' c' : ℝ, ∀ x ∈ Set.Icc a b, relu (m * x + c) = m' * x + c' := by rcases eq_or_lt_of_le hab with rfl | hlt · refine ⟨0, relu (m * a + c), fun x hx => ?_⟩ have hx_eq : x = a := le_antisymm hx.2 hx.1 rw [hx_eq]; ring · -- Check sign at midpoint (a + b) / 2 ∈ (a, b) set mid := (a + b) / 2 have hmid_lo : a < mid := by simp only [mid]; linarith have hmid_hi : mid < b := by simp only [mid]; linarith have hmid_ne : m * mid + c ≠ 0 := hno mid hmid_lo hmid_hi rcases lt_or_gt_of_ne hmid_ne with hneg | hpos · -- m*x + c ≤ 0 on all of [a, b] refine ⟨0, 0, fun x hx => ?_⟩ have hle : m * x + c ≤ 0 := by by_contra hgt push Not at hgt have hm_ne : m ≠ 0 := by intro hm0; rw [hm0] at hgt hneg; linarith set r := -c / m have hr_zero : m * r + c = 0 := by simp only [r]; field_simp [hm_ne]; ring have hr_btwn : a < r ∧ r < b := by rcases lt_or_gt_of_ne hm_ne with hm_neg | hm_pos · constructor · have : m * r < m * a := by nlinarith [hx.1] nlinarith · have : m * mid < m * r := by linarith nlinarith · constructor · have : m * mid < m * r := by linarith nlinarith · have : m * r < m * b := by nlinarith [hx.2] nlinarith exact hno r hr_btwn.1 hr_btwn.2 hr_zero rw [relu_of_nonpos hle]; ring · -- m*x + c ≥ 0 on all of [a, b] refine ⟨m, c, fun x hx => ?_⟩ have hge : 0 ≤ m * x + c := by by_contra hlt_x push Not at hlt_x have hm_ne : m ≠ 0 := by intro hm0; rw [hm0] at hlt_x hpos; linarith set r := -c / m have hr_zero : m * r + c = 0 := by simp only [r]; field_simp [hm_ne]; ring have hr_btwn : a < r ∧ r < b := by rcases lt_or_gt_of_ne hm_ne with hm_neg | hm_pos · constructor · have : m * r < m * mid := by linarith nlinarith · have : m * b < m * r := by nlinarith [hx.2] nlinarith · constructor · have : m * a < m * r := by nlinarith [hx.1] nlinarith · have : m * r < m * mid := by linarith nlinarith exact hno r hr_btwn.1 hr_btwn.2 hr_zero exact relu_of_nonneg hge /-- Key inductive lemma: applying a single `relu` neuron to a piecewise-affine function with breakpoint set `B` introduces at most `B.card + 1` new breakpoints! -/ lemma isPiecewiseAffine_relu_step (B : Finset ℝ) (h : ℝ → ℝ) (hh : IsPiecewiseAffine B h) : ∃ R : Finset ℝ, R.card ≤ B.card + 1 ∧ IsPiecewiseAffine (B ∪ R) (fun x => relu (h x)) := by classical induction B using Finset.induction_on_max generalizing h with | empty => -- h is globally affine: determine m, c from [0, 1] and prove h x = m*x + c for all x obtain ⟨m, c, h01⟩ := hh.2 0 1 (by norm_num) (by simp) have hglobal : ∀ x : ℝ, h x = m * x + c := by intro x set lo := min 0 x set hi := max 1 x obtain ⟨m', c', h'⟩ := hh.2 lo hi (le_trans (min_le_left 0 x) (le_trans (by norm_num) (le_max_left 1 x))) (by simp) have h0_mem : (0 : ℝ) ∈ Set.Icc lo hi := ⟨min_le_left _ _, le_trans (by norm_num) (le_max_left _ _)⟩ have h1_mem : (1 : ℝ) ∈ Set.Icc lo hi := ⟨le_trans (min_le_left _ _) (by norm_num), le_max_left _ _⟩ have hx_mem : x ∈ Set.Icc lo hi := ⟨min_le_right _ _, le_max_right _ _⟩ have e0 : m' * 0 + c' = m * 0 + c := by rw [← h' 0 h0_mem, h01 0 (by norm_num)] have e1 : m' * 1 + c' = m * 1 + c := by rw [← h' 1 h1_mem, h01 1 (by norm_num)] have hc : c' = c := by linarith have hm : m' = m := by linarith rw [h' x hx_mem, hm, hc] by_cases hm0 : m = 0 · refine ⟨∅, by simp, continuous_relu.comp hh.1, fun a b hab _ => ?_⟩ exact ⟨0, relu c, fun x _ => by dsimp only; rw [hglobal x, hm0]; ring_nf⟩ · refine ⟨{-c / m}, by simp, continuous_relu.comp hh.1, fun a b hab hdisj => ?_⟩ have hno : ∀ x : ℝ, a < x → x < b → m * x + c ≠ 0 := by intro x hax hxb hzero have hxr : x = -c / m := by field_simp [hm0]; linarith exact hdisj (-c / m) (by simp) ⟨hxr ▸ hax, hxr ▸ hxb⟩ obtain ⟨m', c', haff⟩ := relu_affine_of_no_root hab hno exact ⟨m', c', fun x hx => by dsimp only; rw [hglobal x]; exact haff x hx⟩ | insert M B' hM_gt ih => have hM_not_mem : M ∉ B' := fun hmem => lt_irrefl M (hM_gt M hmem) obtain ⟨mR, cR, hR01⟩ := hh.2 M (M + 1) (by linarith) fun x hx => by rcases Finset.mem_insert.mp hx with hxM | hx' · rw [hxM]; intro ⟨hlt, _⟩; exact lt_irrefl M hlt · intro ⟨hlt, _⟩; linarith [hM_gt x hx'] have hR_global : ∀ x : ℝ, M ≤ x → h x = mR * x + cR := by intro x hx obtain ⟨m', c', h'⟩ := hh.2 M (max (M + 1) x) (le_trans (by linarith) (le_max_left _ _)) fun y hy => by rcases Finset.mem_insert.mp hy with hyM | hy' · rw [hyM]; intro ⟨hlt, _⟩; exact lt_irrefl M hlt · intro ⟨hlt, _⟩; linarith [hM_gt y hy'] have e0 : m' * M + c' = mR * M + cR := by rw [← h' M ⟨le_rfl, le_trans (by linarith) (le_max_left _ _)⟩, hR01 M ⟨le_rfl, by linarith⟩] have e1 : m' * (M + 1) + c' = mR * (M + 1) + cR := by rw [← h' (M + 1) ⟨by linarith, le_max_left _ _⟩, hR01 (M + 1) ⟨by linarith, le_rfl⟩] have hm' : m' = mR := by linarith have hc' : c' = cR := by rw [hm'] at e0; linarith rw [h' x ⟨hx, le_max_right _ _⟩, hm', hc'] have hex_L : ∃ L_pt : ℝ, L_pt < M ∧ ∀ x ∈ B', x < L_pt := by by_cases hne : B'.Nonempty · set M' := B'.max' hne have hM'_lt : M' < M := hM_gt M' (Finset.max'_mem B' hne) exact ⟨(M' + M) / 2, by linarith, fun x hx => by linarith [Finset.le_max' B' x hx]⟩ · exact ⟨M - 1, by linarith, fun x hx => absurd ⟨x, hx⟩ hne⟩ obtain ⟨L_pt, hL_lt, hL_gt⟩ := hex_L obtain ⟨mL, cL, hL_aff⟩ := hh.2 L_pt M (le_of_lt hL_lt) fun x hx => by rcases Finset.mem_insert.mp hx with hxM | hx' · rw [hxM]; intro ⟨_, hlt⟩; exact lt_irrefl M hlt · intro ⟨hlt, _⟩; linarith [hL_gt x hx'] -- Linearly extended function h_ext: agrees with h on (-∞, M], equals mL*x + cL on [M, ∞) let h_ext : ℝ → ℝ := fun x => if x ≤ M then h x else mL * x + cL have hL_at_M : h M = mL * M + cL := hL_aff M ⟨le_of_lt hL_lt, le_rfl⟩ have h_ext_eq_R : ∀ x, M ≤ x → h_ext x = mL * x + cL := by intro x hx by_cases hxM : x ≤ M · have heq : x = M := le_antisymm hxM hx subst heq; simp [h_ext, hL_at_M] · simp [h_ext, hxM] have h_ext_cont : Continuous h_ext := by have hcont1 : ContinuousOn h (Set.Iic M) := hh.1.continuousOn have hcont2 : ContinuousOn (fun x => mL * x + cL) (Set.Ici M) := ((continuous_const.mul continuous_id).add continuous_const).continuousOn have hmatch : ∀ x ∈ Set.Iic M ∩ Set.Ici M, h x = mL * x + cL := by intro x ⟨hx1, hx2⟩ have heq : x = M := le_antisymm hx1 hx2 rw [heq, hL_at_M] -- Use Continuous.if_le exact Continuous.if_le hh.1 ((continuous_const.mul continuous_id).add continuous_const) continuous_id continuous_const fun x hx => by rw [hx, hL_at_M] have h_ext_pa : IsPiecewiseAffine B' h_ext := by refine ⟨h_ext_cont, fun a b hab hdisj => ?_⟩ by_cases hbM : b ≤ M · obtain ⟨m, c, haff⟩ := hh.2 a b hab fun x hx => by rcases Finset.mem_insert.mp hx with rfl | hx' · intro ⟨_, hlt⟩; linarith · exact hdisj x hx' exact ⟨m, c, fun x hx => by simp [h_ext, le_trans hx.2 hbM, haff x hx]⟩ · by_cases haM : M ≤ a · exact ⟨mL, cL, fun x hx => h_ext_eq_R x (le_trans haM hx.1)⟩ · -- a < M < b: since (a, b) is disjoint from B', all of B' is ≤ a push Not at hbM haM obtain ⟨m, c, haff⟩ := hh.2 a M (le_of_lt haM) fun x hx => by rcases Finset.mem_insert.mp hx with hxM | hx' · rw [hxM]; intro ⟨_, hlt⟩; exact lt_irrefl M hlt · intro ⟨hax, hxM⟩; exact hdisj x hx' ⟨hax, lt_trans hxM hbM⟩ -- On [max a L_pt, M], h agrees with both m*x+c and mL*x+cL, so m = mL, c = cL! set lo := max a L_pt have hlo_lt : lo < M := max_lt haM hL_lt have e1 : m * lo + c = mL * lo + cL := by rw [← haff lo ⟨le_max_left _ _, le_of_lt hlo_lt⟩, hL_aff lo ⟨le_max_right _ _, le_of_lt hlo_lt⟩] have e2 : m * M + c = mL * M + cL := by rw [← haff M ⟨le_of_lt haM, le_rfl⟩, hL_at_M] have hm_eq : m = mL := by have : (m - mL) * (M - lo) = 0 := by linarith rcases mul_eq_zero.mp this with h0 | h0 · linarith · linarith have hc_eq : c = cL := by rw [hm_eq] at e2; linarith refine ⟨mL, cL, fun x hx => ?_⟩ by_cases hxM : x ≤ M · simp only [h_ext, hxM, ↓reduceIte, haff x ⟨hx.1, hxM⟩, hm_eq, hc_eq] · exact h_ext_eq_R x (le_of_lt (not_le.mp hxM)) obtain ⟨R', hR'_card, hR'_pa⟩ := ih h_ext h_ext_pa let R_right : Finset ℝ := if mR = 0 then ∅ else {-cR / mR} have hRr_card : R_right.card ≤ 1 := by by_cases hmR : mR = 0 <;> simp [R_right, hmR] refine ⟨R' ∪ R_right, ?_, continuous_relu.comp hh.1, ?_⟩ · calc (R' ∪ R_right).card ≤ R'.card + R_right.card := Finset.card_union_le R' R_right _ ≤ (B'.card + 1) + 1 := Nat.add_le_add hR'_card hRr_card _ = (insert M B').card + 1 := by rw [Finset.card_insert_of_notMem hM_not_mem] · intro a b hab hdisj have hM_in : M ∈ insert M B' ∪ (R' ∪ R_right) := Finset.mem_union_left _ (Finset.mem_insert_self M B') have hnot_split : ¬ (a < M ∧ M < b) := hdisj M hM_in by_cases hbM : b ≤ M · have hdisj' : ∀ x ∈ B' ∪ R', ¬ (a < x ∧ x < b) := fun x hx => hdisj x (by rcases Finset.mem_union.mp hx with hxB | hxR · exact Finset.mem_union_left _ (Finset.mem_insert_of_mem hxB) · exact Finset.mem_union_right _ (Finset.mem_union_left _ hxR)) obtain ⟨m, c, haff⟩ := hR'_pa.2 a b hab hdisj' exact ⟨m, c, fun x hx => by have hle : x ≤ M := le_trans hx.2 hbM simpa [h_ext, hle] using haff x hx⟩ · have haM : M ≤ a := by by_contra hlt; push Not at hlt; exact hnot_split ⟨hlt, not_le.mp hbM⟩ by_cases hmR : mR = 0 · refine ⟨0, relu cR, fun x hx => ?_⟩ dsimp only rw [hR_global x (le_trans haM hx.1), hmR]; ring_nf · have hno : ∀ x : ℝ, a < x → x < b → mR * x + cR ≠ 0 := by intro x hax hxb hzero have hxr : x = -cR / mR := by field_simp [hmR]; linarith have hmem : -cR / mR ∈ insert M B' ∪ (R' ∪ R_right) := by apply Finset.mem_union_right apply Finset.mem_union_right simp [R_right, hmR] exact hdisj (-cR / mR) hmem ⟨hxr ▸ hax, hxr ▸ hxb⟩ obtain ⟨m', c', haff⟩ := relu_affine_of_no_root hab hno exact ⟨m', c', fun x hx => by dsimp only; rw [hR_global x (le_trans haM hx.1)]; exact haff x hx⟩ /-- Feedforward 1D ReLU network hidden layers parameterized by layer-width list `ws : List ℕ` with input dimension `d_in` and output dimension `d_out`. -/ inductive ReLULayers : ℕ → List ℕ → ℕ → Type | nil {d : ℕ} : ReLULayers d [] d | cons {d_in w d_out : ℕ} {ws : List ℕ} (W : Fin w → Fin d_in → ℝ) (b : Fin w → ℝ) (rest : ReLULayers w ws d_out) : ReLULayers d_in (w :: ws) d_out /-- Evaluate hidden ReLU layers on an input vector `x : Fin d_in → ℝ`. -/ def ReLULayers.eval {d_in d_out : ℕ} : {ws : List ℕ} → ReLULayers d_in ws d_out → (Fin d_in → ℝ) → (Fin d_out → ℝ) | [], .nil, x => x | _ :: _, .cons W b rest, x => rest.eval (fun j => relu (∑ i, W j i * x i + b j)) /-- A complete 1D scalar feedforward ReLU network of depth `ws.length` and hidden widths `ws`. -/ structure ReLUNet1D (ws : List ℕ) where d_out : ℕ layers : ReLULayers 1 ws d_out outW : Fin d_out → ℝ outB : ℝ /-- Evaluate a 1D scalar ReLU network at `x : ℝ`. -/ def ReLUNet1D.eval {ws : List ℕ} (net : ReLUNet1D ws) (x : ℝ) : ℝ := ∑ i : Fin net.d_out, net.outW i * net.layers.eval (fun _ => x) i + net.outB /-- Inductive layer-wise piece-count bound for vector-valued ReLU layers. -/ lemma relu_layers_piece_count {d_in d_out : ℕ} {ws : List ℕ} (layers : ReLULayers d_in ws d_out) (B₀ : Finset ℝ) (z : Fin d_in → ℝ → ℝ) (hz : ∀ i : Fin d_in, IsPiecewiseAffine B₀ (z i)) : ∃ B : Finset ℝ, B.card + 1 ≤ (ws.map (· + 1)).prod * (B₀.card + 1) ∧ ∀ k : Fin d_out, IsPiecewiseAffine B (fun x => layers.eval (fun i => z i x) k) := by classical induction layers generalizing B₀ with | nil => refine ⟨B₀, by simp, fun k => hz k⟩ | @cons d_in w d_out ws W b rest ih => -- Each pre-activation h_j(x) = ∑_i W j i * z i x + b j is piecewise affine on B₀ have hpre : ∀ j : Fin w, IsPiecewiseAffine B₀ (fun x => ∑ i : Fin d_in, W j i * z i x + b j) := by intro j refine isPiecewiseAffine_add ?_ (isPiecewiseAffine_const B₀ (b j)) exact isPiecewiseAffine_finset_sum Finset.univ (fun i x => W j i * z i x) fun i _ => isPiecewiseAffine_const_mul (W j i) (hz i) -- For each neuron j : Fin w, pick R_j with |R_j| ≤ |B₀| + 1 have hstep : ∀ j : Fin w, ∃ R : Finset ℝ, R.card ≤ B₀.card + 1 ∧ IsPiecewiseAffine (B₀ ∪ R) (fun x => relu (∑ i : Fin d_in, W j i * z i x + b j)) := fun j => isPiecewiseAffine_relu_step B₀ _ (hpre j) choose R hR_card hR_pa using hstep set B₁ : Finset ℝ := B₀ ∪ Finset.univ.biUnion R have hB₁_card : B₁.card + 1 ≤ (w + 1) * (B₀.card + 1) := by have hu1 : B₁.card ≤ B₀.card + (Finset.univ.biUnion R).card := Finset.card_union_le _ _ have hu2 : (Finset.univ.biUnion R).card ≤ ∑ j : Fin w, (R j).card := Finset.card_biUnion_le have hu3 : ∑ j : Fin w, (R j).card ≤ ∑ _j : Fin w, (B₀.card + 1) := Finset.sum_le_sum fun j _ => hR_card j simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] at hu3 have : B₁.card + 1 ≤ B₀.card + w * (B₀.card + 1) + 1 := by omega linarith have hz₁ : ∀ j : Fin w, IsPiecewiseAffine B₁ (fun x => relu (∑ i : Fin d_in, W j i * z i x + b j)) := by intro j refine isPiecewiseAffine_mono ?_ (hR_pa j) exact Finset.union_subset_union_right (Finset.subset_biUnion_of_mem R (Finset.mem_univ j)) obtain ⟨B, hB_card, hB_pa⟩ := ih B₁ _ hz₁ refine ⟨B, ?_, hB_pa⟩ simp only [List.map_cons, List.prod_cons] calc B.card + 1 ≤ (ws.map (· + 1)).prod * (B₁.card + 1) := hB_card _ ≤ (ws.map (· + 1)).prod * ((w + 1) * (B₀.card + 1)) := Nat.mul_le_mul_left _ hB₁_card _ = (w + 1) * (ws.map (· + 1)).prod * (B₀.card + 1) := by ring /-- **Theorem 4.2 (Exact Multi-Layer ReLU Breakpoint & Linear-Region Upper Bound).** Every 1D feedforward ReLU network of depth `L` and hidden widths `w₁, ..., w_L` is continuous piecewise-affine with at most `∏ (w_ℓ + 1)` linear pieces (at most `∏ (w_ℓ + 1) - 1` breakpoints). -/ theorem relu_network_piece_count_upper_bound {ws : List ℕ} (net : ReLUNet1D ws) : ∃ B : Finset ℝ, B.card + 1 ≤ (ws.map (· + 1)).prod ∧ IsPiecewiseAffine B net.eval := by obtain ⟨B, hB_card, hB_pa⟩ := relu_layers_piece_count net.layers ∅ (fun _ x => x) (fun _ => isPiecewiseAffine_id ∅) simp only [Finset.card_empty, zero_add, mul_one] at hB_card refine ⟨B, hB_card, ?_⟩ unfold ReLUNet1D.eval refine isPiecewiseAffine_add ?_ (isPiecewiseAffine_const B net.outB) exact isPiecewiseAffine_finset_sum Finset.univ (fun i x => net.outW i * net.layers.eval (fun _ => x) i) fun i _ => isPiecewiseAffine_const_mul (net.outW i) (hB_pa i) /-- **Theorem 4.3 (Sharp `L^∞` Depth-Separation Lower Bound: Exact Constant `1 / 2`).** 1. For EVERY even `w ≥ 2`, `L ≥ 1`, and ANY piecewise-affine function `g` with breakpoint set `B` satisfying `2 * (B.card + 1) ≤ w ^ L` (in particular, any ReLU network with `2 * ∏(w'_ℓ + 1) ≤ w ^ L`), there exists `x ∈ [0, 1]` with `|g(x) - S_w^[L](x)| ≥ 1 / 2`. 2. This constant `1 / 2` is **EXACTLY SHARP**: `g ≡ 1 / 2` achieves `|1/2 - S_w^[L](x)| ≤ 1 / 2` for all `x ∈ [0, 1]`. -/ theorem sawtooth_linf_sharp_lower_bound {w L : ℕ} (hw2 : 2 ≤ w) (hweven : Even w) (hL : 1 ≤ L) : (∀ (B : Finset ℝ) (g : ℝ → ℝ), IsPiecewiseAffine B g → 2 * (B.card + 1) ≤ w ^ L → ∃ x ∈ Set.Icc (0 : ℝ) 1, 1 / 2 ≤ |g x - sawtoothIter w L x|) ∧ (∀ x ∈ Set.Icc (0 : ℝ) 1, |1 / 2 - sawtoothIter w L x| ≤ 1 / 2) := by have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L have h2_dvd : 2 ∣ w ^ L := by obtain ⟨m, hm⟩ := hweven have h2w : 2 ∣ w := ⟨m, by omega⟩ exact dvd_pow h2w (by omega) obtain ⟨N, hN_eq⟩ := h2_dvd constructor · intro B g hpa hB -- There are N = w^L / 2 disjoint open double-intervals (2j / w^L, (2j+2) / w^L), and B.card < N! have hB_lt : B.card < N := by omega -- Pigeonhole: some j < N has NO breakpoint in (2j / w^L, (2j+2) / w^L) have hex_clean : ∃ j : Fin N, ∀ x ∈ B, ¬ ((2 * (j.val : ℝ)) / (w : ℝ) ^ L < x ∧ x < (2 * (j.val : ℝ) + 2) / (w : ℝ) ^ L) := by by_contra hall push Not at hall choose f hf_mem hf_in using hall have hinj : Function.Injective f := by intro j₁ j₂ heq by_contra hne rcases lt_or_gt_of_ne (Fin.val_ne_of_ne hne) with hlt | hgt · have h1 := (hf_in j₁).2 have h2 := (hf_in j₂).1 rw [heq] at h1 have hle : (2 * (j₁.val : ℝ) + 2) / (w : ℝ) ^ L ≤ (2 * (j₂.val : ℝ)) / (w : ℝ) ^ L := by apply div_le_div_of_nonneg_right _ (le_of_lt hwL_pos) have : 2 * j₁.val + 2 ≤ 2 * j₂.val := by omega exact_mod_cast this linarith · have h1 := (hf_in j₂).2 have h2 := (hf_in j₁).1 rw [← heq] at h1 have hle : (2 * (j₂.val : ℝ) + 2) / (w : ℝ) ^ L ≤ (2 * (j₁.val : ℝ)) / (w : ℝ) ^ L := by apply div_le_div_of_nonneg_right _ (le_of_lt hwL_pos) have : 2 * j₂.val + 2 ≤ 2 * j₁.val := by omega exact_mod_cast this linarith have hcard_le : N ≤ B.card := by calc N = (Finset.univ : Finset (Fin N)).card := by simp _ = (Finset.univ.image f).card := (Finset.card_image_of_injective _ hinj).symm _ ≤ B.card := Finset.card_le_card (Finset.image_subset_iff.mpr fun j _ => hf_mem j) omega obtain ⟨j, hclean⟩ := hex_clean set a := (2 * (j.val : ℝ)) / (w : ℝ) ^ L set mid := (2 * (j.val : ℝ) + 1) / (w : ℝ) ^ L set b := (2 * (j.val : ℝ) + 2) / (w : ℝ) ^ L have hab : a ≤ b := div_le_div_of_nonneg_right (by linarith) (le_of_lt hwL_pos) obtain ⟨m, c, haff⟩ := hpa.2 a b hab hclean have hmid_mem : mid ∈ Set.Icc a b := ⟨div_le_div_of_nonneg_right (by linarith) (le_of_lt hwL_pos), div_le_div_of_nonneg_right (by linarith) (le_of_lt hwL_pos)⟩ have hlin : g mid = (g a + g b) / 2 := by rw [haff a ⟨le_rfl, hab⟩, haff b ⟨hab, le_rfl⟩, haff mid hmid_mem] simp only [a, b, mid]; ring -- Evaluate sawtoothIter at a (even 2j -> 0), mid (odd 2j+1 -> 1), b (even 2j+2 -> 0) have hgrid := (sawtoothIter_exact_piece_and_grid hw2 hweven L).2 have h2j_le : 2 * j.val ≤ w ^ L := by omega have h2j1_le : 2 * j.val + 1 ≤ w ^ L := by omega have h2j2_le : 2 * j.val + 2 ≤ w ^ L := by omega have hsa : sawtoothIter w L a = 0 := by have h := hgrid (2 * j.val) h2j_le have hev : Even (2 * j.val) := ⟨j.val, by omega⟩ rw [if_pos hev] at h simpa [a] using h have hsmid : sawtoothIter w L mid = 1 := by have h := hgrid (2 * j.val + 1) h2j1_le have hodd : ¬ Even (2 * j.val + 1) := by rw [Nat.even_add_one]; push Not; exact ⟨j.val, by omega⟩ rw [if_neg hodd] at h simpa [mid] using h have hsb : sawtoothIter w L b = 0 := by have h := hgrid (2 * j.val + 2) h2j2_le have hev : Even (2 * j.val + 2) := ⟨j.val + 1, by omega⟩ rw [if_pos hev] at h simpa [b] using h -- By triangle inequality: |g(mid) - 1| + (|g(a)| + |g(b)|)/2 ≥ 1, so max ≥ 1/2! have hsum_ge : 1 ≤ |g mid - sawtoothIter w L mid| + (1 / 2) * |g a - sawtoothIter w L a| + (1 / 2) * |g b - sawtoothIter w L b| := by rw [hsa, hsmid, hsb, sub_zero, sub_zero] have h1 : (1 : ℝ) = ((g a + g b) / 2 - g mid) + 1 := by linarith have h2 : (1 : ℝ) ≤ |g mid - 1| + |(g a + g b) / 2| := by have := abs_add_le (1 - g mid) ((g a + g b) / 2) have hsum1 : (1 - g mid) + (g a + g b) / 2 = 1 := by linarith rw [hsum1, abs_one, abs_sub_comm] at this exact this have h3 : |(g a + g b) / 2| ≤ (1 / 2) * |g a| + (1 / 2) * |g b| := by rw [abs_div, abs_of_pos (by norm_num : (0 : ℝ) < 2)] have := abs_add_le (g a) (g b) linarith linarith have ha_in : a ∈ Set.Icc (0 : ℝ) 1 := by refine ⟨div_nonneg (by positivity) (le_of_lt hwL_pos), (div_le_one hwL_pos).mpr ?_⟩ exact_mod_cast h2j_le have hmid_in : mid ∈ Set.Icc (0 : ℝ) 1 := by refine ⟨div_nonneg (by positivity) (le_of_lt hwL_pos), (div_le_one hwL_pos).mpr ?_⟩ exact_mod_cast h2j1_le have hb_in : b ∈ Set.Icc (0 : ℝ) 1 := by refine ⟨div_nonneg (by positivity) (le_of_lt hwL_pos), (div_le_one hwL_pos).mpr ?_⟩ exact_mod_cast h2j2_le by_cases h1 : 1 / 2 ≤ |g mid - sawtoothIter w L mid| · exact ⟨mid, hmid_in, h1⟩ · by_cases h2 : 1 / 2 ≤ |g a - sawtoothIter w L a| · exact ⟨a, ha_in, h2⟩ · exact ⟨b, hb_in, by linarith⟩ · -- Sharpness: S_w^[L]([0, 1]) ⊆ [0, 1], so |1/2 - S_w^[L](x)| ≤ 1/2 intro x hx have hpiece := (sawtoothIter_exact_piece_and_grid hw2 hweven L).1 have h01 : 0 ≤ sawtoothIter w L x ∧ sawtoothIter w L x ≤ 1 := by by_cases hx1 : x = 1 · subst hx1 have hgrid := (sawtoothIter_exact_piece_and_grid hw2 hweven L).2 (w ^ L) le_rfl have hdiv : ((w ^ L : ℕ) : ℝ) / (w : ℝ) ^ L = 1 := by push_cast; exact div_self (ne_of_gt hwL_pos) rw [hdiv] at hgrid rw [hgrid]; split_ifs <;> norm_num · have hxlt : x < 1 := lt_of_le_of_ne hx.2 hx1 set y := (w : ℝ) ^ L * x have hy_nn : 0 ≤ y := mul_nonneg (le_of_lt hwL_pos) hx.1 have hy_lt : y < (w : ℝ) ^ L := by nlinarith set k := Nat.floor y have hk_lt : k < w ^ L := by have h1 : (k : ℝ) ≤ y := Nat.floor_le hy_nn have h2 : (k : ℝ) < ((w ^ L : ℕ) : ℝ) := by push_cast; linarith exact_mod_cast h2 have hxlo : (k : ℝ) / (w : ℝ) ^ L ≤ x := (div_le_iff₀ hwL_pos).mpr (by rw [mul_comm]; exact Nat.floor_le hy_nn) have hxhi : x ≤ ((k : ℝ) + 1) / (w : ℝ) ^ L := (le_div_iff₀ hwL_pos).mpr (by rw [mul_comm]; exact le_of_lt (Nat.lt_floor_add_one y)) rw [hpiece k hk_lt x hxlo hxhi] have hlo : (k : ℝ) ≤ y := Nat.floor_le hy_nn have hhi : y ≤ (k : ℝ) + 1 := le_of_lt (Nat.lt_floor_add_one y) split_ifs <;> constructor <;> linarith rw [abs_le]; constructor <;> linarith /-- Elementary 3-line symmetry proof: on `[a, a + 2h]`, any affine function has `L¹` error at least `h / 2` against the unit triangle wave (with exact equality for `g ≡ 1/2`). -/ lemma triangle_wave_l1_lower {a h m c : ℝ} (hh : 0 < h) : h / 2 ≤ ∫ x in a..(a + 2 * h), |(m * x + c) - (if x ≤ a + h then (x - a) / h else (a + 2 * h - x) / h)| := by let T : ℝ → ℝ := fun x => if x ≤ a + h then (x - a) / h else (a + 2 * h - x) / h have hT_cont : Continuous T := by refine Continuous.if_le ((continuous_id.sub continuous_const).div_const h) ((continuous_const.sub continuous_id).div_const h) continuous_id continuous_const ?_ intro x hx; rw [hx]; ring have hT_sym : ∀ x : ℝ, T (2 * a + 2 * h - x) = T x := by intro x simp only [T] by_cases hx : x ≤ a + h · rcases eq_or_lt_of_le hx with rfl | hlt · have heq : 2 * a + 2 * h - (a + h) = a + h := by ring rw [heq, if_pos le_rfl] · have hgt : ¬ (2 * a + 2 * h - x ≤ a + h) := by linarith rw [if_neg hgt, if_pos hx]; ring · have hle : 2 * a + 2 * h - x ≤ a + h := by linarith rw [if_pos hle, if_neg hx]; ring have hcont_f : Continuous (fun x => |(m * x + c) - T x|) := (((continuous_const.mul continuous_id).add continuous_const).sub hT_cont).abs have hcont_ref : Continuous (fun x => |(m * (2 * a + 2 * h - x) + c) - T x|) := (((continuous_const.mul (continuous_const.sub continuous_id)).add continuous_const).sub hT_cont).abs -- Step 1: Symmetry around x = a + h reduces affine m*x + c to constant d = m*(a+h) + c set d := m * (a + h) + c have hsym_eq : (∫ x in a..(a + 2 * h), |(m * x + c) - T x|) = ∫ x in a..(a + 2 * h), |(m * (2 * a + 2 * h - x) + c) - T x| := by have hcomp := intervalIntegral.integral_comp_sub_left (fun x => |(m * x + c) - T x|) (2 * a + 2 * h) (a := a) (b := a + 2 * h) have h1 : 2 * a + 2 * h - (a + 2 * h) = a := by ring have h2 : 2 * a + 2 * h - a = a + 2 * h := by ring rw [h1, h2] at hcomp rw [← hcomp] refine intervalIntegral.integral_congr fun x _ => ?_ rw [hT_sym x] have hcont_d : Continuous (fun x => |d - T x|) := (continuous_const.sub hT_cont).abs have hstep1 : ∫ x in a..(a + 2 * h), |d - T x| ≤ ∫ x in a..(a + 2 * h), |(m * x + c) - T x| := by have h2 : 2 * ∫ x in a..(a + 2 * h), |d - T x| ≤ (∫ x in a..(a + 2 * h), |(m * x + c) - T x|) + (∫ x in a..(a + 2 * h), |(m * (2 * a + 2 * h - x) + c) - T x|) := by rw [← intervalIntegral.integral_const_mul, ← intervalIntegral.integral_add (hcont_f.intervalIntegrable _ _) (hcont_ref.intervalIntegrable _ _)] refine intervalIntegral.integral_mono_on (by linarith) ((continuous_const.mul hcont_d).intervalIntegrable _ _) ((hcont_f.add hcont_ref).intervalIntegrable _ _) fun x _ => ?_ have htri := abs_add_le ((m * x + c) - T x) ((m * (2 * a + 2 * h - x) + c) - T x) have hsum : ((m * x + c) - T x) + ((m * (2 * a + 2 * h - x) + c) - T x) = 2 * (d - T x) := by simp only [d]; ring rw [hsum, abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 2)] at htri exact htri linarith [hsym_eq] -- Step 2: Split [a, a + 2h] into [a, a + h] and [a + h, a + 2h]; each integral is ≥ h / 4 have hleft_ge : h / 4 ≤ ∫ x in a..(a + h), |d - (x - a) / h| := by have hcont_l : Continuous (fun x => |d - (x - a) / h|) := (continuous_const.sub ((continuous_id.sub continuous_const).div_const h)).abs have hcont_l2 : Continuous (fun x => |d - (a + h - x) / h|) := (continuous_const.sub ((continuous_const.sub continuous_id).div_const h)).abs have hsym_l : (∫ x in a..(a + h), |d - (x - a) / h|) = ∫ x in a..(a + h), |d - (a + h - x) / h| := by have hcomp := intervalIntegral.integral_comp_sub_left (fun x => |d - (x - a) / h|) (2 * a + h) (a := a) (b := a + h) have h1 : 2 * a + h - (a + h) = a := by ring have h2 : 2 * a + h - a = a + h := by ring rw [h1, h2] at hcomp rw [← hcomp] refine intervalIntegral.integral_congr fun x _ => ?_ congr 2; ring have hsum_l : ∫ x in a..(a + h), |1 - 2 * (x - a) / h| ≤ 2 * ∫ x in a..(a + h), |d - (x - a) / h| := by have hcont_mid : Continuous (fun x => |1 - 2 * (x - a) / h|) := (continuous_const.sub ((continuous_const.mul (continuous_id.sub continuous_const)).div_const h)).abs have hadd : (∫ x in a..(a + h), |d - (x - a) / h|) + (∫ x in a..(a + h), |d - (a + h - x) / h|) = ∫ x in a..(a + h), (|d - (x - a) / h| + |d - (a + h - x) / h|) := (intervalIntegral.integral_add (hcont_l.intervalIntegrable _ _) (hcont_l2.intervalIntegrable _ _)).symm rw [← hsym_l] at hadd rw [show 2 * ∫ x in a..(a + h), |d - (x - a) / h| = (∫ x in a..(a + h), |d - (x - a) / h|) + (∫ x in a..(a + h), |d - (x - a) / h|) by ring, hadd] refine intervalIntegral.integral_mono_on (by linarith) (hcont_mid.intervalIntegrable _ _) ((hcont_l.add hcont_l2).intervalIntegrable _ _) fun x _ => ?_ have htri := abs_add_le (d - (x - a) / h) ((a + h - x) / h - d) have hrew : (d - (x - a) / h) + ((a + h - x) / h - d) = 1 - 2 * (x - a) / h := by field_simp [ne_of_gt hh]; ring rw [hrew, abs_sub_comm ((a + h - x) / h) d] at htri exact htri -- Compute ∫_a^{a+h} |1 - 2(x-a)/h| dx = h / 2 by splitting at a + h/2 have hval : ∫ x in a..(a + h), |1 - 2 * (x - a) / h| = h / 2 := by have hcont_mid : Continuous (fun x => |1 - 2 * (x - a) / h|) := (continuous_const.sub ((continuous_const.mul (continuous_id.sub continuous_const)).div_const h)).abs rw [← intervalIntegral.integral_add_adjacent_intervals (hcont_mid.intervalIntegrable a (a + h / 2)) (hcont_mid.intervalIntegrable (a + h / 2) (a + h))] have hp1 : ∫ x in a..(a + h / 2), |1 - 2 * (x - a) / h| = ∫ x in a..(a + h / 2), (1 - 2 * (x - a) / h) := by refine intervalIntegral.integral_congr fun x hx => ?_ rw [Set.uIcc_of_le (by linarith)] at hx exact abs_of_nonneg (by have : 2 * (x - a) / h ≤ 1 := (div_le_one hh).mpr (by linarith [hx.2]) linarith) have hp2 : ∫ x in (a + h / 2)..(a + h), |1 - 2 * (x - a) / h| = ∫ x in (a + h / 2)..(a + h), (2 * (x - a) / h - 1) := by refine intervalIntegral.integral_congr fun x hx => ?_ rw [Set.uIcc_of_le (by linarith)] at hx rw [abs_of_nonpos (by have : 1 ≤ 2 * (x - a) / h := (one_le_div hh).mpr (by linarith [hx.1]) linarith)]; ring have hev1 : ∫ x in a..(a + h / 2), (1 - 2 * (x - a) / h) = h / 4 := by let F1 : ℝ → ℝ := fun x => x - (x - a) ^ 2 / h have hF1 : ∀ x ∈ Set.uIcc a (a + h / 2), HasDerivAt F1 (1 - 2 * (x - a) / h) x := by intro x _ have h1 := ((hasDerivAt_id' x).sub_const a).fun_pow 2 have h2 := (h1.div_const h).congr_deriv (show (2 * (x - a) ^ (2 - 1) * 1) / h = 2 * (x - a) / h by ring) exact (hasDerivAt_id' x).fun_sub h2 rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hF1 ((continuous_const.sub ((continuous_const.mul (continuous_id.sub continuous_const)).div_const h)).intervalIntegrable _ _)] simp only [F1]; field_simp [ne_of_gt hh]; ring have hev2 : ∫ x in (a + h / 2)..(a + h), (2 * (x - a) / h - 1) = h / 4 := by let F2 : ℝ → ℝ := fun x => (x - a) ^ 2 / h - x have hF2 : ∀ x ∈ Set.uIcc (a + h / 2) (a + h), HasDerivAt F2 (2 * (x - a) / h - 1) x := by intro x _ have h1 := ((hasDerivAt_id' x).sub_const a).fun_pow 2 have h2 := (h1.div_const h).congr_deriv (show (2 * (x - a) ^ (2 - 1) * 1) / h = 2 * (x - a) / h by ring) exact h2.fun_sub (hasDerivAt_id' x) rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hF2 ((((continuous_const.mul (continuous_id.sub continuous_const)).div_const h).sub continuous_const).intervalIntegrable _ _)] simp only [F2]; field_simp [ne_of_gt hh]; ring rw [hp1, hp2, hev1, hev2]; ring linarith have hsplit_d : ∫ x in a..(a + 2 * h), |d - T x| = (∫ x in a..(a + h), |d - T x|) + (∫ x in (a + h)..(a + 2 * h), |d - T x|) := (intervalIntegral.integral_add_adjacent_intervals (hcont_d.intervalIntegrable a (a + h)) (hcont_d.intervalIntegrable (a + h) (a + 2 * h))).symm have hpart1 : ∫ x in a..(a + h), |d - T x| = ∫ x in a..(a + h), |d - (x - a) / h| := by refine intervalIntegral.integral_congr fun x hx => ?_ rw [Set.uIcc_of_le (by linarith)] at hx simp only [T, if_pos hx.2] have hpart2 : ∫ x in (a + h)..(a + 2 * h), |d - T x| = ∫ x in a..(a + h), |d - (x - a) / h| := by have hcomp := intervalIntegral.integral_comp_sub_left (fun x => |d - T x|) (2 * a + 2 * h) (a := a) (b := a + h) have h1 : 2 * a + 2 * h - (a + h) = a + h := by ring have h2 : 2 * a + 2 * h - a = a + 2 * h := by ring rw [h1, h2] at hcomp rw [← hcomp, ← hpart1] refine intervalIntegral.integral_congr fun x _ => ?_ rw [hT_sym x] linarith /-- **Theorem 4.4 (Exact Optimal `L¹` Depth-Separation Lower Bound — Sharpening Telgarsky 2016 to `1/4`).** For EVERY even `w ≥ 2`, `L ≥ 1`, and ANY continuous piecewise-affine function `g` with breakpoint set `B`: `1 / 4 - |B| / (2 w^L) ≤ ∫ x in (0 : ℝ)..1, |g x - S_w^[L] x|`. In particular, for ANY depth-`L'` ReLU network `net : ReLUNet1D ws`: `1 / 4 - (∏(w'_ℓ + 1) - 1) / (2 w^L) ≤ ∫ x in (0 : ℝ)..1, |net.eval x - S_w^[L] x|`. (Telgarsky 2016 gave constant `1/32`; `1/4` is **EXACTLY OPTIMAL**, achieved by `g ≡ 1/2`!) -/ theorem sawtooth_l1_sharp_lower_bound {w L : ℕ} (hw2 : 2 ≤ w) (hweven : Even w) (hL : 1 ≤ L) (B : Finset ℝ) (g : ℝ → ℝ) (hpa : IsPiecewiseAffine B g) : 1 / 4 - (B.card : ℝ) / (2 * (w : ℝ) ^ L) ≤ ∫ x in (0 : ℝ)..1, |g x - sawtoothIter w L x| := by classical have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L have h2_dvd : 2 ∣ w ^ L := by obtain ⟨m, hm⟩ := hweven exact dvd_pow ⟨m, by omega⟩ (by omega) obtain ⟨N, hN_eq⟩ := h2_dvd set h : ℝ := 1 / (w : ℝ) ^ L have hh_pos : 0 < h := by positivity have hcont : Continuous (fun x => |g x - sawtoothIter w L x|) := (hpa.1.sub (continuous_sawtoothIter w L)).abs -- Split ∫_0^1 into ∑_{j : Fin N} ∫_{2jh}^{(2j+2)h} have hsum_split : ∀ k : ℕ, k ≤ N → (∫ x in (0 : ℝ)..(2 * (k : ℝ) * h), |g x - sawtoothIter w L x|) = ∑ j ∈ Finset.range k, ∫ x in (2 * (j : ℝ) * h)..(2 * ((j : ℝ) + 1) * h), |g x - sawtoothIter w L x| := by intro k induction k with | zero => intro _; simp | succ k ih => intro hk rw [Finset.sum_range_succ, ← ih (by omega)] have hcast : 2 * ((k + 1 : ℕ) : ℝ) * h = 2 * ((k : ℝ) + 1) * h := by push_cast; ring rw [hcast] exact (intervalIntegral.integral_add_adjacent_intervals (hcont.intervalIntegrable _ _) (hcont.intervalIntegrable _ _)).symm have h1_eq : 2 * (N : ℝ) * h = 1 := by have hNR : (w : ℝ) ^ L = 2 * (N : ℝ) := by exact_mod_cast hN_eq have hNpos : 0 < (N : ℝ) := by linarith simp only [h, hNR]; field_simp [ne_of_gt hNpos] have hfull_split : (∫ x in (0 : ℝ)..1, |g x - sawtoothIter w L x|) = ∑ j : Fin N, ∫ x in (2 * (j.val : ℝ) * h)..(2 * (j.val : ℝ) * h + 2 * h), |g x - sawtoothIter w L x| := by rw [← h1_eq, hsum_split N le_rfl, ← Fin.sum_univ_eq_sum_range] refine Finset.sum_congr rfl fun j _ => ?_ congr 1; ring rw [hfull_split] -- Partition Fin N into hit intervals (containing some b ∈ B) and clean intervals let hit : Finset (Fin N) := Finset.univ.filter fun j => ∃ x ∈ B, 2 * (j.val : ℝ) * h < x ∧ x < 2 * (j.val : ℝ) * h + 2 * h have hhit_card : hit.card ≤ B.card := by have hex : ∀ j ∈ hit, ∃ x ∈ B, 2 * (j.val : ℝ) * h < x ∧ x < 2 * (j.val : ℝ) * h + 2 * h := fun j hj => (Finset.mem_filter.mp hj).2 choose f hf_mem hf_in using fun j (hj : j ∈ hit) => hex j hj -- Map hit injectively into B have hinj : Set.InjOn (fun j => if hj : j ∈ hit then f j hj else 0) (hit : Set (Fin N)) := by intro j₁ hj₁ j₂ hj₂ heq simp only [Finset.mem_coe] at hj₁ hj₂ simp only [hj₁, hj₂, ↓reduceDIte] at heq by_contra hne rcases lt_or_gt_of_ne (Fin.val_ne_of_ne hne) with hlt | hgt · have h1 := (hf_in j₁ hj₁).2 have h2 := (hf_in j₂ hj₂).1 rw [heq] at h1 have hstep : 2 * (j₁.val : ℝ) + 2 ≤ 2 * (j₂.val : ℝ) := by exact_mod_cast (show 2 * j₁.val + 2 ≤ 2 * j₂.val by omega) nlinarith · have h1 := (hf_in j₂ hj₂).2 have h2 := (hf_in j₁ hj₁).1 rw [← heq] at h1 have hstep : 2 * (j₂.val : ℝ) + 2 ≤ 2 * (j₁.val : ℝ) := by exact_mod_cast (show 2 * j₂.val + 2 ≤ 2 * j₁.val by omega) nlinarith have hsub : hit.image (fun j => if hj : j ∈ hit then f j hj else 0) ⊆ B := by intro y hy rcases Finset.mem_image.mp hy with ⟨j, hj, rfl⟩ simp only [hj, ↓reduceDIte] exact hf_mem j hj calc hit.card = (hit.image (fun j => if hj : j ∈ hit then f j hj else 0)).card := (Finset.card_image_of_injOn hinj).symm _ ≤ B.card := Finset.card_le_card hsub -- On every clean interval j ∉ hit, integral ≥ h / 2; on hit intervals, integral ≥ 0 have hpiece := (sawtoothIter_exact_piece_and_grid hw2 hweven L).1 have hterm_ge : ∀ j : Fin N, (if j ∈ hit then (0 : ℝ) else h / 2) ≤ ∫ x in (2 * (j.val : ℝ) * h)..(2 * (j.val : ℝ) * h + 2 * h), |g x - sawtoothIter w L x| := by intro j by_cases hj : j ∈ hit · rw [if_pos hj] exact intervalIntegral.integral_nonneg (by linarith) fun x _ => abs_nonneg _ · rw [if_neg hj] have hdisj : ∀ x ∈ B, ¬ (2 * (j.val : ℝ) * h < x ∧ x < 2 * (j.val : ℝ) * h + 2 * h) := by intro x hx hin exact hj (Finset.mem_filter.mpr ⟨Finset.mem_univ j, x, hx, hin⟩) obtain ⟨m, c, haff⟩ := hpa.2 (2 * (j.val : ℝ) * h) (2 * (j.val : ℝ) * h + 2 * h) (by linarith) hdisj have hcongr : (∫ x in (2 * (j.val : ℝ) * h)..(2 * (j.val : ℝ) * h + 2 * h), |g x - sawtoothIter w L x|) = ∫ x in (2 * (j.val : ℝ) * h)..(2 * (j.val : ℝ) * h + 2 * h), |(m * x + c) - (if x ≤ 2 * (j.val : ℝ) * h + h then (x - 2 * (j.val : ℝ) * h) / h else (2 * (j.val : ℝ) * h + 2 * h - x) / h)| := by refine intervalIntegral.integral_congr fun x hx => ?_ rw [Set.uIcc_of_le (by linarith)] at hx rw [haff x hx] congr 2 have hrew1 : 2 * (j.val : ℝ) * h = (2 * (j.val : ℝ)) / (w : ℝ) ^ L := by simp only [h]; ring have hrew2 : 2 * (j.val : ℝ) * h + h = (2 * (j.val : ℝ) + 1) / (w : ℝ) ^ L := by simp only [h]; ring have hrew3 : 2 * (j.val : ℝ) * h + 2 * h = (2 * (j.val : ℝ) + 2) / (w : ℝ) ^ L := by simp only [h]; ring by_cases hmid : x ≤ 2 * (j.val : ℝ) * h + h · rw [if_pos hmid] have hlo : ((2 * j.val : ℕ) : ℝ) / (w : ℝ) ^ L ≤ x := by push_cast; linarith [hx.1, hrew1] have hhi : x ≤ (((2 * j.val : ℕ) : ℝ) + 1) / (w : ℝ) ^ L := by push_cast; linarith [hmid, hrew2] rw [hpiece (2 * j.val) (by omega) x hlo hhi, if_pos ⟨j.val, by omega⟩] simp only [h]; push_cast; field_simp [ne_of_gt hwL_pos] · rw [if_neg hmid] have hlo : ((2 * j.val + 1 : ℕ) : ℝ) / (w : ℝ) ^ L ≤ x := by push_cast; linarith [hmid, hrew2] have hhi : x ≤ (((2 * j.val + 1 : ℕ) : ℝ) + 1) / (w : ℝ) ^ L := by push_cast; linarith [hx.2, hrew3, show (2 * (j.val : ℝ) + 1 + 1) / (w : ℝ) ^ L = (2 * (j.val : ℝ) + 2) / (w : ℝ) ^ L by ring] have hodd : ¬ Even (2 * j.val + 1) := by rw [Nat.even_add_one]; push Not; exact ⟨j.val, by omega⟩ rw [hpiece (2 * j.val + 1) (by omega) x hlo hhi, if_neg hodd] simp only [h]; push_cast; field_simp [ne_of_gt hwL_pos]; ring rw [hcongr] exact triangle_wave_l1_lower hh_pos have hsum_ge := Finset.sum_le_sum fun j (_ : j ∈ Finset.univ) => hterm_ge j have hsum_eval : ∑ j : Fin N, (if j ∈ hit then (0 : ℝ) else h / 2) = ((N : ℝ) - (hit.card : ℝ)) * (h / 2) := by have hsplit : ∀ j : Fin N, (if j ∈ hit then (0 : ℝ) else h / 2) = h / 2 - (if j ∈ hit then h / 2 else 0) := by intro j; by_cases hj : j ∈ hit <;> simp [hj] simp_rw [hsplit, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Finset.sum_ite_mem, Finset.univ_inter, Finset.sum_const, nsmul_eq_mul] ring rw [hsum_eval] at hsum_ge have hhit_leR : (hit.card : ℝ) ≤ (B.card : ℝ) := by exact_mod_cast hhit_card have hNR : (N : ℝ) = (w : ℝ) ^ L / 2 := by have : (w : ℝ) ^ L = 2 * (N : ℝ) := by exact_mod_cast hN_eq linarith have hLHS : 1 / 4 - (B.card : ℝ) / (2 * (w : ℝ) ^ L) ≤ ((N : ℝ) - (hit.card : ℝ)) * (h / 2) := by have hstep : ((N : ℝ) - (B.card : ℝ)) * (h / 2) ≤ ((N : ℝ) - (hit.card : ℝ)) * (h / 2) := by nlinarith have heq : ((N : ℝ) - (B.card : ℝ)) * (h / 2) = 1 / 4 - (B.card : ℝ) / (2 * (w : ℝ) ^ L) := by simp only [h, hNR]; field_simp [ne_of_gt hwL_pos]; ring linarith exact le_trans hLHS hsum_ge /-- Corollary: Direct depth-separation `L¹` lower bound for arbitrary `ReLUNet1D ws`. -/ theorem relu_network_l1_depth_separation {w L : ℕ} (hw2 : 2 ≤ w) (hweven : Even w) (hL : 1 ≤ L) {ws : List ℕ} (net : ReLUNet1D ws) : 1 / 4 - (((ws.map (fun n : ℕ => n + 1)).prod : ℕ) - 1 : ℝ) / (2 * (w : ℝ) ^ L) ≤ ∫ x in (0 : ℝ)..1, |net.eval x - sawtoothIter w L x| := by obtain ⟨B, hB_card, hB_pa⟩ := relu_network_piece_count_upper_bound net have h := sawtooth_l1_sharp_lower_bound hw2 hweven hL B net.eval hB_pa have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L have hBle : (B.card : ℝ) ≤ (((ws.map (fun n : ℕ => n + 1)).prod : ℕ) : ℝ) - 1 := by have h1 : (B.card : ℝ) + 1 ≤ (((ws.map (fun n : ℕ => n + 1)).prod : ℕ) : ℝ) := by exact_mod_cast hB_card linarith have hdiv : (B.card : ℝ) / (2 * (w : ℝ) ^ L) ≤ ((((ws.map (fun n : ℕ => n + 1)).prod : ℕ) : ℝ) - 1) / (2 * (w : ℝ) ^ L) := div_le_div_of_nonneg_right hBle (by positivity) linarith /-- **Theorem 4.5 (Infinite-Width Barron / Path-Norm Depth Separation).** Even with **ARBITRARY** width `m : ℕ`, ANY shallow 1-hidden-layer ReLU network `g(x) = c₀ + ∑_{j : Fin m} a_j ReLU(u_j x + b_j)` with Barron/path norm `‖g‖_B = ∑_j |a_j| |u_j|` satisfies: `∃ x ∈ [0, 1], 1 / 2 - ‖g‖_B / (2 w^L) ≤ |g(x) - S_w^[L](x)|`. Hence achieving uniform error `< ε < 1/2` forces exponential path norm `‖g‖_B > (1 - 2ε) w^L`! -/ theorem barron_path_norm_infinite_width_depth_separation {w L m : ℕ} (hw2 : 2 ≤ w) (hweven : Even w) (c₀ : ℝ) (a u b : Fin m → ℝ) : let g : ℝ → ℝ := fun x => c₀ + ∑ j : Fin m, a j * relu (u j * x + b j) let barronNorm : ℝ := ∑ j : Fin m, |a j| * |u j| ∃ x ∈ Set.Icc (0 : ℝ) 1, 1 / 2 - barronNorm / (2 * (w : ℝ) ^ L) ≤ |g x - sawtoothIter w L x| := by dsimp only set g : ℝ → ℝ := fun x => c₀ + ∑ j : Fin m, a j * relu (u j * x + b j) set barronNorm : ℝ := ∑ j : Fin m, |a j| * |u j| have hw_pos : 0 < (w : ℝ) := by exact_mod_cast (show 0 < w by omega) have hwL_pos : 0 < (w : ℝ) ^ L := pow_pos hw_pos L -- Lipschitz bound: |g(x) - g(y)| ≤ barronNorm * |x - y| have hlip : ∀ x y : ℝ, |g x - g y| ≤ barronNorm * |x - y| := by intro x y have hdiff : g x - g y = ∑ j : Fin m, a j * (relu (u j * x + b j) - relu (u j * y + b j)) := by simp only [g, add_sub_add_left_eq_sub, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun j _ => ?_; ring rw [hdiff] simp only [barronNorm] rw [Finset.sum_mul] refine le_trans (Finset.abs_sum_le_sum_abs _ _) (Finset.sum_le_sum fun j _ => ?_) rw [abs_mul] calc |a j| * |relu (u j * x + b j) - relu (u j * y + b j)| ≤ |a j| * |(u j * x + b j) - (u j * y + b j)| := mul_le_mul_of_nonneg_left (relu_lip _ _) (abs_nonneg _) _ = |a j| * |u j| * |x - y| := by have : (u j * x + b j) - (u j * y + b j) = u j * (x - y) := by ring rw [this, abs_mul, mul_assoc] set N := w ^ L have hgrid := (sawtoothIter_exact_piece_and_grid hw2 hweven L).2 let xk : ℕ → ℝ := fun k => (k : ℝ) / (w : ℝ) ^ L have htv_S : ∑ k ∈ Finset.range N, |sawtoothIter w L (xk (k + 1)) - sawtoothIter w L (xk k)| = (w : ℝ) ^ L := by have hpt : ∀ k ∈ Finset.range N, |sawtoothIter w L (xk (k + 1)) - sawtoothIter w L (xk k)| = 1 := by intro k hk have hk_lt : k < N := Finset.mem_range.mp hk have h1 := hgrid k (le_of_lt hk_lt) have h2 := hgrid (k + 1) hk_lt simp only [xk] rw [h1, h2] by_cases hev : Even k · rw [if_pos hev, if_neg (by simp [Nat.even_add_one, hev])]; norm_num · rw [if_neg hev, if_pos (by simp [Nat.even_add_one, hev])]; norm_num rw [Finset.sum_congr rfl hpt, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one] simp [N] have htv_g : ∑ k ∈ Finset.range N, |g (xk (k + 1)) - g (xk k)| ≤ barronNorm := by have hpt : ∀ k ∈ Finset.range N, |g (xk (k + 1)) - g (xk k)| ≤ barronNorm / (w : ℝ) ^ L := by intro k _ have hstep : |xk (k + 1) - xk k| = 1 / (w : ℝ) ^ L := by have : xk (k + 1) - xk k = 1 / (w : ℝ) ^ L := by simp only [xk]; push_cast; field_simp [ne_of_gt hwL_pos]; ring rw [this, abs_of_pos (by positivity)] have hl := hlip (xk (k + 1)) (xk k) rw [hstep] at hl linarith [show barronNorm * (1 / (w : ℝ) ^ L) = barronNorm / (w : ℝ) ^ L by ring] calc ∑ k ∈ Finset.range N, |g (xk (k + 1)) - g (xk k)| ≤ ∑ _k ∈ Finset.range N, (barronNorm / (w : ℝ) ^ L) := Finset.sum_le_sum hpt _ = (N : ℝ) * (barronNorm / (w : ℝ) ^ L) := by rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] _ = barronNorm := by simp only [N]; push_cast; field_simp [ne_of_gt hwL_pos] -- By contradiction: if |g(xk) - S(xk)| < 1/2 - barronNorm / (2 w^L) for all k ≤ N, then w^L < w^L! by_contra hall push Not at hall have hgrid_lt : ∀ k : ℕ, k ≤ N → |g (xk k) - sawtoothIter w L (xk k)| < 1 / 2 - barronNorm / (2 * (w : ℝ) ^ L) := by intro k hk have hmem : xk k ∈ Set.Icc (0 : ℝ) 1 := by refine ⟨div_nonneg (Nat.cast_nonneg k) (le_of_lt hwL_pos), (div_le_one hwL_pos).mpr ?_⟩ exact_mod_cast hk exact hall (xk k) hmem have hsum_err : ∑ k ∈ Finset.range N, (|g (xk (k + 1)) - sawtoothIter w L (xk (k + 1))| + |g (xk k) - sawtoothIter w L (xk k)|) < (w : ℝ) ^ L - barronNorm := by have hN_ne : (Finset.range N).Nonempty := ⟨0, Finset.mem_range.mpr (by positivity)⟩ have hlt_each : ∀ k ∈ Finset.range N, |g (xk (k + 1)) - sawtoothIter w L (xk (k + 1))| + |g (xk k) - sawtoothIter w L (xk k)| < 1 - barronNorm / (w : ℝ) ^ L := by intro k hk have hk_lt : k < N := Finset.mem_range.mp hk have h1 := hgrid_lt (k + 1) hk_lt have h2 := hgrid_lt k (le_of_lt hk_lt) linarith [show 2 * (barronNorm / (2 * (w : ℝ) ^ L)) = barronNorm / (w : ℝ) ^ L by ring] have hsum := Finset.sum_lt_sum_of_nonempty hN_ne hlt_each rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at hsum have hsimp : (N : ℝ) * (1 - barronNorm / (w : ℝ) ^ L) = (w : ℝ) ^ L - barronNorm := by simp only [N]; push_cast; field_simp [ne_of_gt hwL_pos] linarith have htri_sum : (w : ℝ) ^ L ≤ barronNorm + ∑ k ∈ Finset.range N, (|g (xk (k + 1)) - sawtoothIter w L (xk (k + 1))| + |g (xk k) - sawtoothIter w L (xk k)|) := by rw [← htv_S] have hle : ∑ k ∈ Finset.range N, |sawtoothIter w L (xk (k + 1)) - sawtoothIter w L (xk k)| ≤ ∑ k ∈ Finset.range N, (|g (xk (k + 1)) - g (xk k)| + (|g (xk (k + 1)) - sawtoothIter w L (xk (k + 1))| + |g (xk k) - sawtoothIter w L (xk k)|)) := by refine Finset.sum_le_sum fun k _ => ?_ have hdecomp : sawtoothIter w L (xk (k + 1)) - sawtoothIter w L (xk k) = (g (xk (k + 1)) - g (xk k)) + ((sawtoothIter w L (xk (k + 1)) - g (xk (k + 1))) + (g (xk k) - sawtoothIter w L (xk k))) := by ring rw [hdecomp] have h1 := abs_add_le (g (xk (k + 1)) - g (xk k)) ((sawtoothIter w L (xk (k + 1)) - g (xk (k + 1))) + (g (xk k) - sawtoothIter w L (xk k))) have h2 := abs_add_le (sawtoothIter w L (xk (k + 1)) - g (xk (k + 1))) (g (xk k) - sawtoothIter w L (xk k)) rw [abs_sub_comm (sawtoothIter w L (xk (k + 1))) (g (xk (k + 1)))] at h2 linarith rw [Finset.sum_add_distrib] at hle linarith linarith /-- Helper: product distribution sum `∑_{σ : Fin m → Fin N} ∏ r, p (σ r) = (∑ k, p k)^m`. -/ lemma sum_prod_fintype {m N : ℕ} (p : Fin N → ℝ) : ∑ σ : Fin m → Fin N, ∏ r : Fin m, p (σ r) = (∑ k : Fin N, p k) ^ m := by have h := Fintype.prod_sum (fun (_ : Fin m) (k : Fin N) => p k) simpa using h.symm /-- **Theorem 4.6 (Exact Finite-`m` Barron–Maurey `O(1/m)` Approximation Theorem).** In any finite-dimensional real inner-product space `ℝ^d`, let `f = ∑_{k : Fin N} p_k φ_k` be any convex combination of dictionary atoms `φ_k` (`p_k ≥ 0`, `∑_k p_k = 1`). Then for EVERY width `m ≥ 1`, there exists an `m`-term empirical average `fbar(x) = (1/m) ∑_{r : Fin m} φ_{σ r}(x)` satisfying the **EXACT non-asymptotic Barron–Maurey variance bound**: `‖fbar - f‖₂² ≤ ((∑_k p_k ‖φ_k‖₂²) - ‖f‖₂²) / m`. -/ theorem barron_maurey_exact_existence {d N m : ℕ} (hm : 1 ≤ m) (p : Fin N → ℝ) (hp_nn : ∀ k, 0 ≤ p k) (hp_sum : ∑ k : Fin N, p k = 1) (φ : Fin N → Fin d → ℝ) : let f : Fin d → ℝ := fun i => ∑ k : Fin N, p k * φ k i ∃ σ : Fin m → Fin N, normSq ((fun i => (1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i) - f) ≤ ((∑ k : Fin N, p k * normSq (φ k)) - normSq f) / (m : ℝ) := by dsimp only set f : Fin d → ℝ := fun i => ∑ k : Fin N, p k * φ k i have hm_pos : 0 < (m : ℝ) := by exact_mod_cast (show 0 < m by omega) let wt : (Fin m → Fin N) → ℝ := fun σ => ∏ r : Fin m, p (σ r) have hwt_nn : ∀ σ, 0 ≤ wt σ := fun σ => Finset.prod_nonneg fun r _ => hp_nn (σ r) have hwt_sum : ∑ σ : Fin m → Fin N, wt σ = 1 := by simp only [wt, sum_prod_fintype, hp_sum, one_pow] -- Exact marginal expectation over a single coordinate r : Fin m have hmarg1 : ∀ (r : Fin m) (g : Fin N → ℝ), ∑ σ : Fin m → Fin N, wt σ * g (σ r) = ∑ k : Fin N, p k * g k := by intro r g have hsplit : ∀ σ : Fin m → Fin N, wt σ * g (σ r) = ∏ s : Fin m, (if s = r then p (σ s) * g (σ s) else p (σ s)) := by intro σ unfold wt rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ r), ← Finset.mul_prod_erase _ _ (Finset.mem_univ r)] simp only [↓reduceIte] have hrest : ∏ s ∈ Finset.univ.erase r, (if s = r then p (σ s) * g (σ s) else p (σ s)) = ∏ s ∈ Finset.univ.erase r, p (σ s) := Finset.prod_congr rfl fun s hs => by rw [if_neg (Finset.mem_erase.mp hs).1] rw [hrest]; ring simp_rw [hsplit] rw [← Fintype.prod_sum (fun (s : Fin m) (k : Fin N) => if s = r then p k * g k else p k)] rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ r)] simp only [↓reduceIte] have hrest : ∏ s ∈ Finset.univ.erase r, ∑ k : Fin N, (if s = r then p k * g k else p k) = 1 := by refine Finset.prod_eq_one fun s hs => ?_ simp only [if_neg (Finset.mem_erase.mp hs).1, hp_sum] rw [hrest, mul_one] -- Exact pair marginal expectation for distinct r₁ ≠ r₂ have hmarg2 : ∀ (r₁ r₂ : Fin m), r₁ ≠ r₂ → ∀ (g₁ g₂ : Fin N → ℝ), ∑ σ : Fin m → Fin N, wt σ * (g₁ (σ r₁) * g₂ (σ r₂)) = (∑ k : Fin N, p k * g₁ k) * (∑ k : Fin N, p k * g₂ k) := by intro r₁ r₂ hne g₁ g₂ have hsplit : ∀ σ : Fin m → Fin N, wt σ * (g₁ (σ r₁) * g₂ (σ r₂)) = ∏ s : Fin m, (if s = r₁ then p (σ s) * g₁ (σ s) else if s = r₂ then p (σ s) * g₂ (σ s) else p (σ s)) := by intro σ unfold wt have hmem2 : r₂ ∈ Finset.univ.erase r₁ := Finset.mem_erase.mpr ⟨hne.symm, Finset.mem_univ r₂⟩ rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ r₁), ← Finset.mul_prod_erase _ _ hmem2, ← Finset.mul_prod_erase (Finset.univ) (fun s => if s = r₁ then p (σ s) * g₁ (σ s) else if s = r₂ then p (σ s) * g₂ (σ s) else p (σ s)) (Finset.mem_univ r₁), ← Finset.mul_prod_erase (Finset.univ.erase r₁) (fun s => if s = r₁ then p (σ s) * g₁ (σ s) else if s = r₂ then p (σ s) * g₂ (σ s) else p (σ s)) hmem2] simp only [↓reduceIte, if_neg hne.symm] have hrest : ∏ s ∈ (Finset.univ.erase r₁).erase r₂, (if s = r₁ then p (σ s) * g₁ (σ s) else if s = r₂ then p (σ s) * g₂ (σ s) else p (σ s)) = ∏ s ∈ (Finset.univ.erase r₁).erase r₂, p (σ s) := by refine Finset.prod_congr rfl fun s hs => ?_ have hs2 : s ≠ r₂ := (Finset.mem_erase.mp hs).1 have hs1 : s ≠ r₁ := (Finset.mem_erase.mp (Finset.mem_erase.mp hs).2).1 rw [if_neg hs1, if_neg hs2] rw [hrest]; ring simp_rw [hsplit] rw [← Fintype.prod_sum (fun (s : Fin m) (k : Fin N) => if s = r₁ then p k * g₁ k else if s = r₂ then p k * g₂ k else p k)] have hmem2 : r₂ ∈ Finset.univ.erase r₁ := Finset.mem_erase.mpr ⟨hne.symm, Finset.mem_univ r₂⟩ rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ r₁), ← Finset.mul_prod_erase _ _ hmem2] simp only [↓reduceIte, if_neg hne.symm] have hrest : ∏ s ∈ (Finset.univ.erase r₁).erase r₂, ∑ k : Fin N, (if s = r₁ then p k * g₁ k else if s = r₂ then p k * g₂ k else p k) = 1 := by refine Finset.prod_eq_one fun s hs => ?_ have hs2 : s ≠ r₂ := (Finset.mem_erase.mp hs).1 have hs1 : s ≠ r₁ := (Finset.mem_erase.mp (Finset.mem_erase.mp hs).2).1 simp only [if_neg hs1, if_neg hs2, hp_sum] rw [hrest, mul_one] -- Exact expected squared error = ((∑ k, p k ‖φ k‖²) - ‖f‖²) / m have hexp : ∑ σ : Fin m → Fin N, wt σ * normSq ((fun i => (1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i) - f) = ((∑ k : Fin N, p k * normSq (φ k)) - normSq f) / (m : ℝ) := by have hcoord : ∀ i : Fin d, ∑ σ : Fin m → Fin N, wt σ * ((1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i - f i) ^ 2 = ((∑ k : Fin N, p k * (φ k i) ^ 2) - (f i) ^ 2) / (m : ℝ) := by intro i have hexpand : ∀ σ : Fin m → Fin N, wt σ * ((1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i - f i) ^ 2 = (1 / (m : ℝ) ^ 2) * ∑ r₁ : Fin m, ∑ r₂ : Fin m, wt σ * ((φ (σ r₁) i - f i) * (φ (σ r₂) i - f i)) := by intro σ have hsub : (1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i - f i = (1 / (m : ℝ)) * ∑ r : Fin m, (φ (σ r) i - f i) := by rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] field_simp [ne_of_gt hm_pos] rw [hsub] calc wt σ * ((1 / (m : ℝ)) * ∑ r : Fin m, (φ (σ r) i - f i)) ^ 2 = (1 / (m : ℝ) ^ 2) * (wt σ * ((∑ r₁ : Fin m, (φ (σ r₁) i - f i)) * (∑ r₂ : Fin m, (φ (σ r₂) i - f i)))) := by ring _ = (1 / (m : ℝ) ^ 2) * ∑ r₁ : Fin m, ∑ r₂ : Fin m, wt σ * ((φ (σ r₁) i - f i) * (φ (σ r₂) i - f i)) := by congr 1 rw [Finset.sum_mul, Finset.mul_sum] refine Finset.sum_congr rfl fun r₁ _ => ?_ rw [Finset.mul_sum, Finset.mul_sum] simp_rw [hexpand] rw [← Finset.mul_sum, Finset.sum_comm] have hzero_mean : ∑ k : Fin N, p k * (φ k i - f i) = 0 := by have h1 : ∀ k, p k * (φ k i - f i) = p k * φ k i - p k * f i := fun k => by ring simp_rw [h1, Finset.sum_sub_distrib, ← Finset.sum_mul, hp_sum, one_mul] simp [f] have hvar : ∑ k : Fin N, p k * (φ k i - f i) ^ 2 = (∑ k : Fin N, p k * (φ k i) ^ 2) - (f i) ^ 2 := by have h1 : ∀ k, p k * (φ k i - f i) ^ 2 = p k * (φ k i) ^ 2 - 2 * f i * (p k * φ k i) + p k * (f i) ^ 2 := fun k => by ring simp_rw [h1, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.sum_mul, hp_sum, one_mul] simp only [f]; ring have hinner : ∀ r₁ : Fin m, ∑ σ : Fin m → Fin N, ∑ r₂ : Fin m, wt σ * ((φ (σ r₁) i - f i) * (φ (σ r₂) i - f i)) = (∑ k : Fin N, p k * (φ k i) ^ 2) - (f i) ^ 2 := by intro r₁ rw [Finset.sum_comm] rw [Finset.sum_eq_single r₁] · have := hmarg1 r₁ (fun k => (φ k i - f i) ^ 2) simp_rw [← sq] rw [this, hvar] · intro r₂ _ hr₂ rw [hmarg2 r₁ r₂ hr₂.symm (fun k => φ k i - f i) (fun k => φ k i - f i), hzero_mean, mul_zero] · intro h; exact absurd (Finset.mem_univ _) h simp_rw [hinner, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] field_simp [ne_of_gt hm_pos] calc ∑ σ : Fin m → Fin N, wt σ * normSq ((fun i => (1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i) - f) = ∑ σ : Fin m → Fin N, ∑ i : Fin d, wt σ * ((1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i - f i) ^ 2 := by refine Finset.sum_congr rfl fun σ _ => ?_ simp only [normSq, Pi.sub_apply, Finset.mul_sum] _ = ∑ i : Fin d, ∑ σ : Fin m → Fin N, wt σ * ((1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i - f i) ^ 2 := Finset.sum_comm _ = ∑ i : Fin d, ((∑ k : Fin N, p k * (φ k i) ^ 2) - (f i) ^ 2) / (m : ℝ) := Finset.sum_congr rfl fun i _ => hcoord i _ = ((∑ k : Fin N, p k * normSq (φ k)) - normSq f) / (m : ℝ) := by rw [← Finset.sum_div, Finset.sum_sub_distrib] congr 2 unfold normSq rw [Finset.sum_comm] refine Finset.sum_congr rfl fun k _ => ?_ rw [Finset.mul_sum] -- Probabilistic method: since ∑ wt σ = 1 and wt ≥ 0, some σ achieves ≤ expectation! by_contra hall push Not at hall have hlt : ((∑ k : Fin N, p k * normSq (φ k)) - normSq f) / (m : ℝ) < ∑ σ : Fin m → Fin N, wt σ * normSq ((fun i => (1 / (m : ℝ)) * ∑ r : Fin m, φ (σ r) i) - f) := by have hex_pos : ∃ σ₀ : Fin m → Fin N, 0 < wt σ₀ := by by_contra h0 push Not at h0 have hsum0 : ∑ σ : Fin m → Fin N, wt σ = 0 := Finset.sum_eq_zero fun σ _ => le_antisymm (h0 σ) (hwt_nn σ) linarith [hwt_sum] obtain ⟨σ₀, hσ₀⟩ := hex_pos set E := ((∑ k : Fin N, p k * normSq (φ k)) - normSq f) / (m : ℝ) have hE_eq : E = ∑ σ : Fin m → Fin N, wt σ * E := by rw [← Finset.sum_mul, hwt_sum, one_mul] rw [hE_eq] refine Finset.sum_lt_sum (fun σ _ => mul_le_mul_of_nonneg_left (le_of_lt (hall σ)) (hwt_nn σ)) ?_ exact ⟨σ₀, Finset.mem_univ σ₀, mul_lt_mul_of_pos_left (hall σ₀) hσ₀⟩ linarith [hexp] end Pillar4 end NeuralImplicitBiasGrokking /-! ============================================================================ AXIOM VERIFICATION ON ALL HEADLINE THEOREMS ============================================================================ -/ #print axioms NeuralImplicitBiasGrokking.min_norm_interpolator_pythagorean #print axioms NeuralImplicitBiasGrokking.min_norm_interpolator_unique #print axioms NeuralImplicitBiasGrokking.ridgeless_bias_variance_exact #print axioms NeuralImplicitBiasGrokking.isotropic_double_descent_exact_sos #print axioms NeuralImplicitBiasGrokking.isotropic_double_descent_exact_minimum #print axioms NeuralImplicitBiasGrokking.isotropic_double_descent_phase_transition #print axioms NeuralImplicitBiasGrokking.parseval_exact_interpolation #print axioms NeuralImplicitBiasGrokking.benign_overfitting_exact_risk #print axioms NeuralImplicitBiasGrokking.benign_overfitting_optimal_self_ridge #print axioms NeuralImplicitBiasGrokking.exp_loss_shannon_entropy_identity #print axioms NeuralImplicitBiasGrokking.exp_gf_loss_decay_and_norm_growth #print axioms NeuralImplicitBiasGrokking.exp_gf_smooth_margin_deriv_nonneg #print axioms NeuralImplicitBiasGrokking.exp_gf_max_margin_directional_rate #print axioms NeuralImplicitBiasGrokking.diag_net_invariant_and_mirror_flow #print axioms NeuralImplicitBiasGrokking.hypentropy_kkt_unique_minimizer #print axioms NeuralImplicitBiasGrokking.hypentropy_l2_exact_sandwich #print axioms NeuralImplicitBiasGrokking.hypentropy_l2_interpolator_convergence #print axioms NeuralImplicitBiasGrokking.hypentropy_l1_exact_sandwich_and_tightness #print axioms NeuralImplicitBiasGrokking.hypentropy_l1_interpolator_convergence #print axioms NeuralImplicitBiasGrokking.hypentropy_2d_exact_phase_transition_witness #print axioms NeuralImplicitBiasGrokking.quad_neuron_sum_margin_eq_convolution #print axioms NeuralImplicitBiasGrokking.dft_parseval_and_convolution #print axioms NeuralImplicitBiasGrokking.modular_addition_universal_margin_upper_bound #print axioms NeuralImplicitBiasGrokking.fourier_circuit_exact_margin #print axioms NeuralImplicitBiasGrokking.sparse_memorization_margin_upper_bound #print axioms NeuralImplicitBiasGrokking.pair_memorization_subset_exact_margin #print axioms NeuralImplicitBiasGrokking.grokking_margin_separation_and_phase_transition #print axioms NeuralImplicitBiasGrokking.sawtoothIter_exact_piece_and_grid #print axioms NeuralImplicitBiasGrokking.relu_network_piece_count_upper_bound #print axioms NeuralImplicitBiasGrokking.sawtooth_linf_sharp_lower_bound #print axioms NeuralImplicitBiasGrokking.sawtooth_l1_sharp_lower_bound #print axioms NeuralImplicitBiasGrokking.relu_network_l1_depth_separation #print axioms NeuralImplicitBiasGrokking.barron_path_norm_infinite_width_depth_separation #print axioms NeuralImplicitBiasGrokking.barron_maurey_exact_existence