import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Real.Sqrt import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.Data.Nat.Choose.Sum /-! # Attention–SSM Memory Dynamics: Sharp Non-Asymptotic Rank-Collapse Contraction, # Sinkhorn–Birkhoff Geometry, Causal Metastability, Linear Associative-Recall # Trade-Offs, and SSM vs. Transformer Capacity Separations A self-contained, machine-checked Lean 4 formalization of a unified sharp non-asymptotic theory across four interconnected pillars: 1. **Dobrushin, Birkhoff–Hopf, & Exact Multi-Layer Self-Attention Rank Collapse**: - Exact dimension-free Dobrushin–diameter contraction `‖(AX)_i - (AX)_k‖ ≤ τ₁(A) · diam(X)` in any seminormed real vector space (`dobrushin_diameter_contraction`). - Exact sharp softmax Dobrushin contraction `τ₁(softmax(S)) ≤ tanh(Δ(S)/4)` with exact `N = 2` attainment (`softmax_dobrushin_le_tanh`, `softmax_dobrushin_tanh_sharp_two`). - Exact Birkhoff–Hopf nonlinear & linear projective contraction theorem `d_H(Kx, Ky) ≤ 2 log((ρ√μ + 1)/(√μ + ρ)) ≤ tanh(Δ/4) d_H(x, y)` via an exact sum-of-squares algebraic certificate (`birkhoff_nonlinear_contraction`, `birkhoff_linear_contraction`). - Shift-invariant cubic doubly-exponential `3^L` self-attention collapse law `D_{ℓ+1} ≤ γ D_ℓ tanh(c D_ℓ² / 4)`, exact `N = 2` antipodal equality at every layer, and exact supercritical bifurcation threshold `D_crit(γ, c) = √((2/c) log((γ+1)/(γ-1)))` (`self_attention_one_step_diam_bound`, `self_attention_cubic_collapse_rate`, `self_attention_antipodal_exact_dynamics`, `self_attention_bifurcation_threshold`). 2. **Sinkhorn–Birkhoff Doubly Stochastic Attention, Residual Rollout, & Causal Metastability**: - Exact Sinkhorn cross-ratio invariance `Δ(D_u K D_v) = Δ(K)` and identical sharp Dobrushin bound (`sinkhorn_cross_ratio_invariant`, `sinkhorn_dobrushin_le_tanh`). - Exact mean conservation and Dirichlet variance-decay identity `Var(x) - Var(Px) = (1/N) ∑_{i,j} P_{ij} ‖x_j - (Px)_i‖² ≥ 0` (`doubly_stochastic_mean_conservation`, `doubly_stochastic_dirichlet_variance_decay`). - Impossibility of uniform attention sinks in Sinkhorn attention (`min_i P_{i,s} ≤ 1/N`) vs. 1-layer `ε`-collapse of softmax under an attention sink (`doubly_stochastic_no_attention_sink`, `softmax_attention_sink_one_step_collapse`). - Universal trace lower bound `τ₁(A) ≥ (tr(A) - 1)/(N - 1)`, two-sided residual rollout bounds for all `α ∈ [0, 1]`, exact mutually-self-dominant equality characterization for all `α ∈ (0, 1)`, and PSD doubly-stochastic residual variance preservation vs. non-PSD 1-step annihilation (`dobrushin_trace_lower_bound`, `residual_rollout_dobrushin_two_sided`, `residual_rollout_equality_iff`, `psd_residual_variance_lower_bound`). - Exact uniform causal attention spectrum (binomial eigenbasis `v_k^(m) = C(k, m)` with eigenvalues `1/(m+1)`), exact 1-step `τ₁(C_N) = 1 - 1/N`, `L`-layer harmonic plateau `τ₁(C_N^L) ≥ 1 - H_N^(L-1)/N`, and sharp generating-function bound `τ₁(C_N^L) ≥ 1 - 2^L / √N` establishing the `Ω(log N)` non-normal metastability barrier (`causal_uniform_dobrushin_exact`, `causal_uniform_binomial_eigenvalue`, `causal_uniform_harmonic_plateau`, `causal_uniform_log_depth_barrier`). 3. **In-Context Linear / Kernel / Decaying Associative-Recall Width–Memory Trade-Offs**: - Exact Welch–Hebbian minimax MSE lower bound `≥ M/D - 1` (exact on tight frames) (`welch_gram_frobenius_lower_bound`, `welch_hebbian_mse_lower_bound`, `mercedes_benz_tight_frame_equality`). - Exact optimal-decoder / Delta-rule minimax MSE lower bound `≥ 1 - D/M` (`delta_rule_minimax_mse_lower_bound`). - Exact `M ≤ D` universal sign-recall wall via strict diagonal dominance and Gershgorin invertibility, even for asymmetric Q-K, unnormalized keys, and arbitrary affine biases (`linear_universal_sign_recall_iff_sdd`, `linear_universal_sign_recall_le_dim`). - Exact forgetting horizon `M - 1 ≥ log(1 + (1-γ)/μ) / log(1/γ)` for decaying linear attention / RetNet (`decay_linear_recall_forgetting_horizon`). 4. **Exact SSM (Finite-State GSSM & Infinite-Precision LTI Hankel) vs. Softmax Separations**: - Exact GSSM copy accuracy ceiling `≤ |H| / V^L` and Hamming-ball MQAR error lower bound (`finite_state_ssm_copy_accuracy_bound`, `finite_state_ssm_hamming_error_bound`). - Exact infinite-precision LTI SSM delay-line Hankel rank obstruction `N ≥ L`, attained at `N = L` by the shift register (`lti_ssm_delay_copy_state_dim_ge`, `shift_register_lti_achieves_delay`). - Constructive `2^d` vs. `d` exponential width separation via hypercube Softmax Attention (`hypercube_softmax_universal_recall`, `exponential_width_separation_softmax_vs_linear`). - Constructive `O(1)` (`d = 2`) vs. `L` unbounded-length copy/recall separation via 2D circular-key Softmax Attention (`circular_2d_softmax_universal_copy`, `unbounded_length_separation_2d_softmax_vs_ssm`). -/ open scoped BigOperators Matrix open Finset namespace AttentionSSMMemoryDynamics /-! ## Shared Basic Helpers -/ /-- Bipolar encoding `Bool → {-1, +1} ⊂ ℝ`. -/ def bipolar (b : Bool) : ℝ := if b then 1 else -1 @[simp] lemma bipolar_true : bipolar true = 1 := rfl @[simp] lemma bipolar_false : bipolar false = -1 := rfl lemma bipolar_sq (b : Bool) : bipolar b ^ 2 = 1 := by cases b <;> norm_num [bipolar] lemma bipolar_abs (b : Bool) : |bipolar b| = 1 := by cases b <;> norm_num [bipolar] lemma bipolar_not (b : Bool) : bipolar (!b) = -bipolar b := by cases b <;> norm_num [bipolar] /-- Standard Euclidean inner product on `Fin d → ℝ`. -/ def dotProd {d : ℕ} (x y : Fin d → ℝ) : ℝ := ∑ c : Fin d, x c * y c /-- Squared Euclidean norm on `Fin d → ℝ`. -/ def sqNorm {d : ℕ} (x : Fin d → ℝ) : ℝ := dotProd x x lemma sqNorm_nonneg {d : ℕ} (x : Fin d → ℝ) : 0 ≤ sqNorm x := by unfold sqNorm dotProd exact Finset.sum_nonneg fun c _ => mul_self_nonneg (x c) lemma dotProd_comm {d : ℕ} (x y : Fin d → ℝ) : dotProd x y = dotProd y x := by unfold dotProd exact Finset.sum_congr rfl fun c _ => mul_comm (x c) (y c) /-- Cauchy–Schwarz for `dotProd`. -/ lemma dotProd_sq_le {d : ℕ} (x y : Fin d → ℝ) : (dotProd x y) ^ 2 ≤ sqNorm x * sqNorm y := by unfold sqNorm dotProd simpa only [sq] using Finset.sum_mul_sq_le_sq_mul_sq Finset.univ x y lemma abs_dotProd_le_sqrt {d : ℕ} (x y : Fin d → ℝ) : |dotProd x y| ≤ Real.sqrt (sqNorm x) * Real.sqrt (sqNorm y) := by have h1 : (dotProd x y) ^ 2 ≤ (Real.sqrt (sqNorm x) * Real.sqrt (sqNorm y)) ^ 2 := by rw [mul_pow, Real.sq_sqrt (sqNorm_nonneg x), Real.sq_sqrt (sqNorm_nonneg y)] exact dotProd_sq_le x y have h2 : 0 ≤ Real.sqrt (sqNorm x) * Real.sqrt (sqNorm y) := mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _) have h3 := sq_le_sq.mp h1 rwa [abs_of_nonneg h2] at h3 /-- Helper: `tanh x = (exp (2x) - 1) / (exp (2x) + 1)`. -/ lemma tanh_eq_exp_sub_div_add (x : ℝ) : Real.tanh x = (Real.exp (2 * x) - 1) / (Real.exp (2 * x) + 1) := by rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] have hx : Real.exp x > 0 := Real.exp_pos x have h2x : Real.exp (2 * x) = Real.exp x * Real.exp x := by rw [two_mul, Real.exp_add] have hneg : Real.exp (-x) = (Real.exp x)⁻¹ := Real.exp_neg x rw [h2x, hneg] field_simp [hx.ne'] /-- Helper: `0 ≤ tanh x` for `0 ≤ x`. -/ lemma tanh_nonneg_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 0 ≤ Real.tanh x := by rw [tanh_eq_exp_sub_div_add] have he : 1 ≤ Real.exp (2 * x) := Real.one_le_exp (by linarith) exact div_nonneg (by linarith) (by linarith) /-- Helper: `tanh x < 1` for all `x : ℝ`. -/ lemma tanh_lt_one (x : ℝ) : Real.tanh x < 1 := by rw [tanh_eq_exp_sub_div_add] have hpos : 0 < Real.exp (2 * x) + 1 := by positivity rw [div_lt_one hpos] linarith /-- Helper: `tanh x ≤ x` for all `0 ≤ x`. -/ lemma tanh_le_self {x : ℝ} (hx : 0 ≤ x) : Real.tanh x ≤ x := by rw [tanh_eq_exp_sub_div_add] have hden : 0 < Real.exp (2 * x) + 1 := by positivity rw [div_le_iff₀ hden] -- Show f(t) = t * (exp(2t) + 1) - (exp(2t) - 1) ≥ 0 on [0, ∞): -- f(0) = 0 and f'(t) = (2t - 1) * exp(2t) + 1 ≥ 0 since exp(2t) ≥ 1 and 2t ≥ 0? -- Wait: use g(t) = t * (exp t + exp(-t)) - (exp t - exp(-t)): g(0) = 0, g'(t) = t * (exp t - exp(-t)) ≥ 0! suffices h : Real.exp x - Real.exp (-x) ≤ x * (Real.exp x + Real.exp (-x)) by have hexp : Real.exp x > 0 := Real.exp_pos x have hmul := mul_le_mul_of_nonneg_left h hexp.le have h2 : Real.exp x * Real.exp x = Real.exp (2 * x) := by rw [← Real.exp_add, two_mul] have h1 : Real.exp x * Real.exp (-x) = 1 := by rw [← Real.exp_add, add_neg_cancel, Real.exp_zero] nlinarith let g : ℝ → ℝ := fun t => t * (Real.exp t + Real.exp (-t)) - (Real.exp t - Real.exp (-t)) have hderiv : ∀ t, HasDerivAt g (t * (Real.exp t - Real.exp (-t))) t := by intro t have he1 : HasDerivAt Real.exp (Real.exp t) t := Real.hasDerivAt_exp t have he2 : HasDerivAt (fun s => Real.exp (-s)) (-Real.exp (-t)) t := by have := (hasDerivAt_neg t).exp simpa using this have hsum : HasDerivAt (fun s => Real.exp s + Real.exp (-s)) (Real.exp t + -Real.exp (-t)) t := he1.add he2 have hdiff : HasDerivAt (fun s => Real.exp s - Real.exp (-s)) (Real.exp t - -Real.exp (-t)) t := he1.sub he2 have hprod := (hasDerivAt_id t).mul hsum have hall := hprod.sub hdiff have hEq : t * (Real.exp t - Real.exp (-t)) = (1 * (Real.exp t + Real.exp (-t)) + t * (Real.exp t + -Real.exp (-t))) - (Real.exp t - -Real.exp (-t)) := by ring rwa [hEq] have hmono : MonotoneOn g (Set.Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) · exact fun t _ => (hderiv t).continuousAt.continuousWithinAt · exact fun t _ => (hderiv t).differentiableAt.differentiableWithinAt · intro t ht rw [interior_Ici] at ht have ht0 : 0 < t := Set.mem_Ioi.mp ht rw [(hderiv t).deriv] have hs : Real.exp (-t) ≤ Real.exp t := Real.exp_le_exp.mpr (by linarith) exact mul_nonneg ht0.le (by linarith) have hg0 : g 0 ≤ g x := hmono (Set.mem_Ici.mpr le_rfl) hx hx simp only [g, zero_mul, Real.exp_zero, neg_zero, sub_self] at hg0 linarith /-- Helper: `Real.tanh` is strictly increasing on `ℝ`. -/ lemma tanh_strictMono : StrictMono Real.tanh := by intro a b hab rw [tanh_eq_exp_sub_div_add, tanh_eq_exp_sub_div_add] have hlt : Real.exp (2 * a) < Real.exp (2 * b) := Real.exp_lt_exp.mpr (by linarith) have ha : 0 < Real.exp (2 * a) + 1 := by positivity have hb : 0 < Real.exp (2 * b) + 1 := by positivity rw [div_lt_div_iff₀ ha hb] nlinarith lemma tanh_mono : Monotone Real.tanh := tanh_strictMono.monotone /-! ## PART I: Dobrushin Contraction, Softmax–Birkhoff–Hopf Bounds, and Exact Multi-Layer Self-Attention Rank Collapse -/ /-- A matrix `A : Matrix (Fin N) (Fin N) ℝ` is row-stochastic if entries are nonnegative and every row sums to `1`. -/ def IsRowStochastic {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) : Prop := (∀ i j, 0 ≤ A i j) ∧ (∀ i, ∑ j : Fin N, A i j = 1) /-- A matrix `P : Matrix (Fin N) (Fin N) ℝ` is doubly stochastic if it is row-stochastic and every column also sums to `1`. -/ def IsDoublyStochastic {N : ℕ} (P : Matrix (Fin N) (Fin N) ℝ) : Prop := IsRowStochastic P ∧ (∀ j, ∑ i : Fin N, P i j = 1) /-- Pairwise total-variation distance between two rows `p, q : Fin N → ℝ`. -/ noncomputable def rowTV {N : ℕ} (p q : Fin N → ℝ) : ℝ := (1 / 2 : ℝ) * ∑ j : Fin N, |p j - q j| /-- Exact Dobrushin ergodicity (contraction) coefficient `τ₁(A)` of an `N × N` matrix. -/ noncomputable def dobrushinCoeff {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) : ℝ := if h : 0 < N then Finset.sup' (Finset.univ : Finset (Fin N × Fin N)) ⟨(⟨0, h⟩, ⟨0, h⟩), Finset.mem_univ _⟩ (fun ik => rowTV (A ik.1) (A ik.2)) else 0 lemma rowTV_nonneg {N : ℕ} (p q : Fin N → ℝ) : 0 ≤ rowTV p q := by unfold rowTV exact mul_nonneg (by norm_num) (Finset.sum_nonneg fun j _ => abs_nonneg _) lemma rowTV_le_dobrushin {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) (i k : Fin N) : rowTV (A i) (A k) ≤ dobrushinCoeff A := by have hN : 0 < N := i.pos unfold dobrushinCoeff rw [dif_pos hN] exact Finset.le_sup' (f := fun ik : Fin N × Fin N => rowTV (A ik.1) (A ik.2)) (Finset.mem_univ (i, k)) lemma dobrushin_le_iff {N : ℕ} (hN : 0 < N) (A : Matrix (Fin N) (Fin N) ℝ) (c : ℝ) : dobrushinCoeff A ≤ c ↔ ∀ i k : Fin N, rowTV (A i) (A k) ≤ c := by have hne : (Finset.univ : Finset (Fin N × Fin N)).Nonempty := ⟨(⟨0, hN⟩, ⟨0, hN⟩), Finset.mem_univ _⟩ have heq : dobrushinCoeff A = Finset.sup' (Finset.univ : Finset (Fin N × Fin N)) hne (fun ik => rowTV (A ik.1) (A ik.2)) := by unfold dobrushinCoeff; rw [dif_pos hN] rw [heq, Finset.sup'_le_iff] constructor · intro h i k; exact h (i, k) (Finset.mem_univ _) · intro h ik _; exact h ik.1 ik.2 lemma dobrushin_nonneg {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) : 0 ≤ dobrushinCoeff A := by by_cases hN : 0 < N · exact le_trans (rowTV_nonneg (A ⟨0, hN⟩) (A ⟨0, hN⟩)) (rowTV_le_dobrushin A ⟨0, hN⟩ ⟨0, hN⟩) · unfold dobrushinCoeff; rw [dif_neg hN] /-- **Theorem 1.1 (Exact TV–Overlap Identity)**: For any probability vectors `p, q`, `rowTV p q = 1 - ∑ j, min (p j) (q j)` and `rowTV p q ≤ 1`. -/ theorem dobrushin_tv_eq_one_sub_min {N : ℕ} (p q : Fin N → ℝ) (hp0 : ∀ j, 0 ≤ p j) (hq0 : ∀ j, 0 ≤ q j) (hp1 : ∑ j, p j = 1) (hq1 : ∑ j, q j = 1) : rowTV p q = 1 - ∑ j : Fin N, min (p j) (q j) ∧ rowTV p q ≤ 1 := by have hpt : ∀ j, |p j - q j| = (p j - min (p j) (q j)) + (q j - min (p j) (q j)) := by intro j rcases le_total (p j) (q j) with h | h · rw [abs_of_nonpos (sub_nonpos.mpr h), min_eq_left h]; ring · rw [abs_of_nonneg (sub_nonneg.mpr h), min_eq_right h]; ring have hsum : ∑ j : Fin N, |p j - q j| = 2 - 2 * ∑ j : Fin N, min (p j) (q j) := by calc ∑ j : Fin N, |p j - q j| = ∑ j : Fin N, ((p j - min (p j) (q j)) + (q j - min (p j) (q j))) := Finset.sum_congr rfl fun j _ => hpt j _ = ∑ j : Fin N, p j + ∑ j : Fin N, q j - 2 * ∑ j : Fin N, min (p j) (q j) := by simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib]; ring _ = 2 - 2 * ∑ j : Fin N, min (p j) (q j) := by rw [hp1, hq1]; ring have htv : rowTV p q = 1 - ∑ j : Fin N, min (p j) (q j) := by unfold rowTV; rw [hsum]; ring refine ⟨htv, ?_⟩ rw [htv] have hmin : 0 ≤ ∑ j : Fin N, min (p j) (q j) := Finset.sum_nonneg fun j _ => le_min (hp0 j) (hq0 j) linarith lemma dobrushin_le_one {N : ℕ} {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : dobrushinCoeff A ≤ 1 := by by_cases hN : 0 < N · rw [dobrushin_le_iff hN] intro i k exact (dobrushin_tv_eq_one_sub_min (A i) (A k) (hA.1 i) (hA.1 k) (hA.2 i) (hA.2 k)).2 · unfold dobrushinCoeff; rw [dif_neg hN]; norm_num /-- **Theorem 1.2 (Exact Dimension-Free Dobrushin–Diameter Contraction)**: For ANY seminormed real vector space `E`, ANY row-stochastic matrix `A`, and ANY token configuration `X : Fin N → E` with pairwise diameter bound `D`, `‖∑ j, A i j • X j - ∑ j, A k j • X j‖ ≤ rowTV (A i) (A k) * D ≤ τ₁(A) * D`. Completely dimension-free (no `√d` loss) and shift-invariant! -/ theorem dobrushin_diameter_contraction {N : ℕ} {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) (X : Fin N → E) (D : ℝ) (hD : ∀ a b : Fin N, ‖X a - X b‖ ≤ D) (i k : Fin N) : ‖(∑ j : Fin N, A i j • X j) - (∑ j : Fin N, A k j • X j)‖ ≤ dobrushinCoeff A * D := by set p := A i set q := A k set u : Fin N → ℝ := fun j => p j - min (p j) (q j) set w : Fin N → ℝ := fun j => q j - min (p j) (q j) have hu0 : ∀ j, 0 ≤ u j := fun j => sub_nonneg.mpr (min_le_left _ _) have hw0 : ∀ j, 0 ≤ w j := fun j => sub_nonneg.mpr (min_le_right _ _) have hp1 : ∑ j, p j = 1 := hA.2 i have hq1 : ∑ j, q j = 1 := hA.2 k have hα : rowTV p q = 1 - ∑ j, min (p j) (q j) := (dobrushin_tv_eq_one_sub_min p q (hA.1 i) (hA.1 k) hp1 hq1).1 have hsu : ∑ j, u j = rowTV p q := by simp only [u, Finset.sum_sub_distrib, hp1, hα] have hsw : ∑ j, w j = rowTV p q := by simp only [w, Finset.sum_sub_distrib, hq1, hα] have hdiff : (∑ j, p j • X j) - (∑ j, q j • X j) = ∑ j, (u j - w j) • X j := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun j _ => ?_ rw [← sub_smul] congr 1; simp only [u, w]; ring have hD0 : 0 ≤ D := by have := hD i i; simp only [sub_self, norm_zero] at this; exact this have htv_le : rowTV p q ≤ dobrushinCoeff A := rowTV_le_dobrushin A i k suffices hstep : ‖(∑ j, p j • X j) - (∑ j, q j • X j)‖ ≤ rowTV p q * D by exact le_trans hstep (mul_le_mul_of_nonneg_right htv_le hD0) by_cases hα0 : rowTV p q = 0 · have hu_zero : ∀ j, u j = 0 := fun j => (Finset.sum_eq_zero_iff_of_nonneg fun a _ => hu0 a).mp (hsu.trans hα0) j (Finset.mem_univ j) have hw_zero : ∀ j, w j = 0 := fun j => (Finset.sum_eq_zero_iff_of_nonneg fun a _ => hw0 a).mp (hsw.trans hα0) j (Finset.mem_univ j) rw [hdiff, hα0, zero_mul] have : ∑ j, (u j - w j) • X j = 0 := Finset.sum_eq_zero fun j _ => by rw [hu_zero j, hw_zero j, sub_self, zero_smul] rw [this, norm_zero] · have hα_pos : 0 < rowTV p q := lt_of_le_of_ne (rowTV_nonneg p q) (Ne.symm hα0) -- Coupling identity: α • ∑ (u j - w j) • X j = ∑ a, ∑ b, (u a * w b) • (X a - X b) have hcouple : rowTV p q • ∑ j : Fin N, (u j - w j) • X j = ∑ a : Fin N, ∑ b : Fin N, (u a * w b) • (X a - X b) := by have hterm1 : ∑ a : Fin N, ∑ b : Fin N, (u a * w b) • X a = (∑ b : Fin N, w b) • (∑ a : Fin N, u a • X a) := by rw [Finset.smul_sum] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_smul] refine Finset.sum_congr rfl fun b _ => by rw [smul_smul, mul_comm] have hterm2 : ∑ a : Fin N, ∑ b : Fin N, (u a * w b) • X b = (∑ a : Fin N, u a) • (∑ b : Fin N, w b • X b) := by rw [Finset.sum_comm, Finset.smul_sum] refine Finset.sum_congr rfl fun b _ => ?_ rw [Finset.sum_smul] refine Finset.sum_congr rfl fun a _ => by rw [smul_smul] have h1 : ∑ a : Fin N, ∑ b : Fin N, (u a * w b) • (X a - X b) = (∑ b : Fin N, w b) • (∑ a : Fin N, u a • X a) - (∑ a : Fin N, u a) • (∑ b : Fin N, w b • X b) := by simp only [smul_sub, Finset.sum_sub_distrib, hterm1, hterm2] rw [h1, hsu, hsw, ← smul_sub, ← Finset.sum_sub_distrib] congr 1 refine Finset.sum_congr rfl fun j _ => ?_ rw [← sub_smul] have hnorm : rowTV p q * ‖∑ j : Fin N, (u j - w j) • X j‖ ≤ (rowTV p q) ^ 2 * D := by calc rowTV p q * ‖∑ j, (u j - w j) • X j‖ = ‖rowTV p q • ∑ j, (u j - w j) • X j‖ := by rw [norm_smul, Real.norm_of_nonneg hα_pos.le] _ = ‖∑ a : Fin N, ∑ b : Fin N, (u a * w b) • (X a - X b)‖ := by rw [hcouple] _ ≤ ∑ a : Fin N, ‖∑ b : Fin N, (u a * w b) • (X a - X b)‖ := norm_sum_le _ _ _ ≤ ∑ a : Fin N, ∑ b : Fin N, ‖(u a * w b) • (X a - X b)‖ := Finset.sum_le_sum fun a _ => norm_sum_le _ _ _ = ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * ‖X a - X b‖ := by refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun b _ => ?_ rw [norm_smul, Real.norm_of_nonneg (mul_nonneg (hu0 a) (hw0 b))] _ ≤ ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * D := by refine Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => ?_ exact mul_le_mul_of_nonneg_left (hD a b) (mul_nonneg (hu0 a) (hw0 b)) _ = (∑ a : Fin N, u a) * (∑ b : Fin N, w b) * D := by simp only [← Finset.sum_mul, ← Finset.mul_sum] _ = (rowTV p q) ^ 2 * D := by rw [hsu, hsw, sq] rw [hdiff] nlinarith /-- Product of two row-stochastic matrices is row-stochastic. -/ lemma isRowStochastic_mul {N : ℕ} {A B : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) (hB : IsRowStochastic B) : IsRowStochastic (A * B) := by refine ⟨fun i j => ?_, fun i => ?_⟩ · rw [Matrix.mul_apply] exact Finset.sum_nonneg fun r _ => mul_nonneg (hA.1 i r) (hB.1 r j) · calc ∑ j : Fin N, (A * B) i j = ∑ j : Fin N, ∑ r : Fin N, A i r * B r j := by simp only [Matrix.mul_apply] _ = ∑ r : Fin N, A i r * ∑ j : Fin N, B r j := by rw [Finset.sum_comm]; simp only [← Finset.mul_sum] _ = ∑ r : Fin N, A i r := by simp only [hB.2, mul_one] _ = 1 := hA.2 i /-- **Theorem 1.3 (Submultiplicativity of Dobrushin's Contraction Coefficient)**: `τ₁(A B) ≤ τ₁(A) · τ₁(B)` for any row-stochastic `A` and any matrix `B`. -/ theorem dobrushin_submultiplicative {N : ℕ} {A B : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : dobrushinCoeff (A * B) ≤ dobrushinCoeff A * dobrushinCoeff B := by by_cases hN : 0 < N · rw [dobrushin_le_iff hN] intro i k -- Couple rows i and k of A just as in Theorem 1.2, applied to rows of B in ℓ¹ set p := A i set q := A k set u : Fin N → ℝ := fun r => p r - min (p r) (q r) set w : Fin N → ℝ := fun r => q r - min (p r) (q r) have hu0 : ∀ r, 0 ≤ u r := fun r => sub_nonneg.mpr (min_le_left _ _) have hw0 : ∀ r, 0 ≤ w r := fun r => sub_nonneg.mpr (min_le_right _ _) have hp1 : ∑ r, p r = 1 := hA.2 i have hq1 : ∑ r, q r = 1 := hA.2 k have hα : rowTV p q = 1 - ∑ r, min (p r) (q r) := (dobrushin_tv_eq_one_sub_min p q (hA.1 i) (hA.1 k) hp1 hq1).1 have hsu : ∑ r, u r = rowTV p q := by simp only [u, Finset.sum_sub_distrib, hp1, hα] have hsw : ∑ r, w r = rowTV p q := by simp only [w, Finset.sum_sub_distrib, hq1, hα] by_cases hα0 : rowTV p q = 0 · have hu_z : ∀ r, u r = 0 := fun r => (Finset.sum_eq_zero_iff_of_nonneg fun a _ => hu0 a).mp (hsu.trans hα0) r (Finset.mem_univ r) have hw_z : ∀ r, w r = 0 := fun r => (Finset.sum_eq_zero_iff_of_nonneg fun a _ => hw0 a).mp (hsw.trans hα0) r (Finset.mem_univ r) have hpq : ∀ r, A i r = A k r := fun r => by have h1 := hu_z r; have h2 := hw_z r; simp only [u, w, p, q] at h1 h2; linarith have hzero : rowTV ((A * B) i) ((A * B) k) = 0 := by unfold rowTV have : ∑ j, |(A * B) i j - (A * B) k j| = 0 := Finset.sum_eq_zero fun j _ => by simp only [Matrix.mul_apply] have : ∑ r, A i r * B r j = ∑ r, A k r * B r j := Finset.sum_congr rfl fun r _ => by rw [hpq r] rw [this, sub_self, abs_zero] rw [this, mul_zero] rw [hzero] exact mul_nonneg (dobrushin_nonneg A) (dobrushin_nonneg B) · have hα_pos : 0 < rowTV p q := lt_of_le_of_ne (rowTV_nonneg p q) (Ne.symm hα0) have hkey : ∀ j, rowTV p q * ((A * B) i j - (A * B) k j) = ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * (B a j - B b j) := by intro j have h1 : (A * B) i j - (A * B) k j = ∑ r, (u r - w r) * B r j := by simp only [Matrix.mul_apply, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun r _ => ?_ simp only [u, w, p, q]; ring rw [h1] have h2 : ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * (B a j - B b j) = (∑ b, w b) * (∑ a, u a * B a j) - (∑ a, u a) * (∑ b, w b * B b j) := by simp only [mul_sub, Finset.sum_sub_distrib] congr 1 · rw [Finset.sum_comm] calc ∑ b, ∑ a, u a * w b * B a j = ∑ b, w b * ∑ a, u a * B a j := by refine Finset.sum_congr rfl fun b _ => ?_ rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun a _ => by ring _ = (∑ b, w b) * ∑ a, u a * B a j := (Finset.sum_mul _ _ _).symm · calc ∑ a, ∑ b, u a * w b * B b j = ∑ a, u a * ∑ b, w b * B b j := by refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun b _ => by ring _ = (∑ a, u a) * ∑ b, w b * B b j := (Finset.sum_mul _ _ _).symm rw [h2, hsu, hsw, ← mul_sub, ← Finset.sum_sub_distrib] congr 1; refine Finset.sum_congr rfl fun r _ => by ring have hbound : rowTV p q * rowTV ((A * B) i) ((A * B) k) ≤ (rowTV p q) ^ 2 * dobrushinCoeff B := by calc rowTV p q * rowTV ((A * B) i) ((A * B) k) = (1 / 2 : ℝ) * ∑ j : Fin N, |rowTV p q * ((A * B) i j - (A * B) k j)| := by rw [show rowTV ((A * B) i) ((A * B) k) = (1 / 2 : ℝ) * ∑ j : Fin N, |(A * B) i j - (A * B) k j| from rfl] rw [mul_left_comm, Finset.mul_sum] congr 1; refine Finset.sum_congr rfl fun j _ => ?_ rw [abs_mul, abs_of_pos hα_pos] _ = (1 / 2 : ℝ) * ∑ j : Fin N, |∑ a : Fin N, ∑ b : Fin N, (u a * w b) * (B a j - B b j)| := by congr 1; exact Finset.sum_congr rfl fun j _ => by rw [hkey j] _ ≤ (1 / 2 : ℝ) * ∑ j : Fin N, ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * |B a j - B b j| := by apply mul_le_mul_of_nonneg_left _ (by norm_num) refine Finset.sum_le_sum fun j _ => ?_ calc |∑ a, ∑ b, (u a * w b) * (B a j - B b j)| ≤ ∑ a, |∑ b, (u a * w b) * (B a j - B b j)| := Finset.abs_sum_le_sum_abs _ _ _ ≤ ∑ a, ∑ b, |(u a * w b) * (B a j - B b j)| := Finset.sum_le_sum fun a _ => Finset.abs_sum_le_sum_abs _ _ _ = ∑ a, ∑ b, (u a * w b) * |B a j - B b j| := by refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun b _ => ?_ rw [abs_mul, abs_of_nonneg (mul_nonneg (hu0 a) (hw0 b))] _ = ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * rowTV (B a) (B b) := by simp only [rowTV, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_comm] refine Finset.sum_congr rfl fun b _ => Finset.sum_congr rfl fun j _ => by ring _ ≤ ∑ a : Fin N, ∑ b : Fin N, (u a * w b) * dobrushinCoeff B := by refine Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => ?_ exact mul_le_mul_of_nonneg_left (rowTV_le_dobrushin B a b) (mul_nonneg (hu0 a) (hw0 b)) _ = (∑ a, u a) * (∑ b, w b) * dobrushinCoeff B := by simp only [← Finset.sum_mul, ← Finset.mul_sum] _ = (rowTV p q) ^ 2 * dobrushinCoeff B := by rw [hsu, hsw, sq] have h1 : rowTV ((A * B) i) ((A * B) k) ≤ rowTV p q * dobrushinCoeff B := by nlinarith exact le_trans h1 (mul_le_mul_of_nonneg_right (rowTV_le_dobrushin A i k) (dobrushin_nonneg B)) · simp only [dobrushinCoeff, dif_neg hN]; norm_num /-- Row-wise softmax attention matrix `softmaxMatrix S`. -/ noncomputable def softmaxMatrix {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ := fun i j => Real.exp (S i j) / ∑ r : Fin N, Real.exp (S i r) lemma softmaxMatrix_pos {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) (i j : Fin N) : 0 < softmaxMatrix S i j := by unfold softmaxMatrix have hden : 0 < ∑ r : Fin N, Real.exp (S i r) := Finset.sum_pos (fun r _ => Real.exp_pos _) ⟨j, Finset.mem_univ j⟩ exact div_pos (Real.exp_pos _) hden lemma softmaxMatrix_isRowStochastic {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) : IsRowStochastic (softmaxMatrix S) := by refine ⟨fun i j => (softmaxMatrix_pos S i j).le, fun i => ?_⟩ unfold softmaxMatrix rw [← Finset.sum_div] have hden : 0 < ∑ r : Fin N, Real.exp (S i r) := Finset.sum_pos (fun r _ => Real.exp_pos _) ⟨i, Finset.mem_univ i⟩ exact div_self hden.ne' /-- Core 4-line algebraic lemma: any two probability distributions `p, q` with cross-ratio bounded by `exp Δ` satisfy `rowTV p q ≤ tanh (Δ / 4)`. -/ lemma tv_le_tanh_of_cross_ratio {N : ℕ} (p q : Fin N → ℝ) (Δ : ℝ) (hΔ : 0 ≤ Δ) (hp0 : ∀ j, 0 ≤ p j) (hq0 : ∀ j, 0 ≤ q j) (hp1 : ∑ j, p j = 1) (hq1 : ∑ j, q j = 1) (hcr : ∀ a b : Fin N, p a * q b ≤ Real.exp Δ * (p b * q a)) : rowTV p q ≤ Real.tanh (Δ / 4) := by classical let Spos : Finset (Fin N) := Finset.univ.filter (fun j => q j ≤ p j) let Sneg : Finset (Fin N) := Finset.univ.filter (fun j => ¬ (q j ≤ p j)) set Pp := ∑ j ∈ Spos, p j set Qp := ∑ j ∈ Spos, q j set Pm := ∑ j ∈ Sneg, p j set Qm := ∑ j ∈ Sneg, q j have hPsum : Pp + Pm = 1 := by have := Finset.sum_filter_add_sum_filter_not Finset.univ (fun j => q j ≤ p j) p linarith have hQsum : Qp + Qm = 1 := by have := Finset.sum_filter_add_sum_filter_not Finset.univ (fun j => q j ≤ p j) q linarith have htv_eq : rowTV p q = Pp - Qp := by unfold rowTV have hsplit : ∑ j : Fin N, |p j - q j| = (∑ j ∈ Spos, |p j - q j|) + (∑ j ∈ Sneg, |p j - q j|) := (Finset.sum_filter_add_sum_filter_not Finset.univ (fun j => q j ≤ p j) _).symm have h1 : ∑ j ∈ Spos, |p j - q j| = Pp - Qp := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun j hj => ?_ have hle : q j ≤ p j := (Finset.mem_filter.mp hj).2 exact abs_of_nonneg (sub_nonneg.mpr hle) have h2 : ∑ j ∈ Sneg, |p j - q j| = Qm - Pm := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun j hj => ?_ have hlt : p j < q j := lt_of_not_ge (Finset.mem_filter.mp hj).2 rw [abs_of_neg (sub_neg.mpr hlt)]; ring rw [hsplit, h1, h2] linarith have hcross : Pp * Qm ≤ Real.exp Δ * (Pm * Qp) := by calc Pp * Qm = ∑ a ∈ Spos, ∑ b ∈ Sneg, p a * q b := by simp only [Pp, Qm, Finset.sum_mul, Finset.mul_sum]; rw [Finset.sum_comm] _ ≤ ∑ a ∈ Spos, ∑ b ∈ Sneg, Real.exp Δ * (p b * q a) := Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => hcr a b _ = Real.exp Δ * ∑ a ∈ Spos, ∑ b ∈ Sneg, p b * q a := by simp only [← Finset.mul_sum] _ = Real.exp Δ * (Pm * Qp) := by congr 1 simp only [Pm, Qp, Finset.sum_mul, Finset.mul_sum] set ρ := Real.exp (Δ / 2) have hρ1 : 1 ≤ ρ := Real.one_le_exp (by linarith) have hρsq : ρ ^ 2 = Real.exp Δ := by rw [sq, ← Real.exp_add]; ring_nf have hPp0 : 0 ≤ Pp := Finset.sum_nonneg fun j _ => hp0 j have hQp0 : 0 ≤ Qp := Finset.sum_nonneg fun j _ => hq0 j have hPm0 : 0 ≤ Pm := Finset.sum_nonneg fun j _ => hp0 j have hQm0 : 0 ≤ Qm := Finset.sum_nonneg fun j _ => hq0 j set t := Pp - Qp set s := Pp + Qp have ht0 : 0 ≤ t := by rw [← htv_eq]; exact rowTV_nonneg p q have ht1 : t ≤ 1 := by linarith have hid1 : 4 * (Pp * Qm) = (1 + t) ^ 2 - (s - 1) ^ 2 := by have : Qm = 1 - Qp := by linarith rw [this]; simp only [t, s]; ring have hid2 : 4 * (Pm * Qp) = (1 - t) ^ 2 - (s - 1) ^ 2 := by have : Pm = 1 - Pp := by linarith rw [this]; simp only [t, s]; ring have hsq : (1 + t) ^ 2 ≤ (ρ * (1 - t)) ^ 2 := by have h0 : 0 ≤ (ρ ^ 2 - 1) * (s - 1) ^ 2 := mul_nonneg (by nlinarith) (sq_nonneg _) nlinarith [hcross, hρsq, hid1, hid2, h0] have hlin : 1 + t ≤ ρ * (1 - t) := by have hnonneg1 : 0 ≤ 1 + t := by linarith have hnonneg2 : 0 ≤ ρ * (1 - t) := mul_nonneg (by linarith) (by linarith) nlinarith [sq_nonneg (ρ * (1 - t) - (1 + t))] have htan : Real.tanh (Δ / 4) = (ρ - 1) / (ρ + 1) := by rw [tanh_eq_exp_sub_div_add] have : 2 * (Δ / 4) = Δ / 2 := by ring rw [this] rw [htv_eq, htan, le_div_iff₀ (by linarith : 0 < ρ + 1)] nlinarith /-- **Theorem 1.4 (Exact Sharp Softmax Dobrushin Bound)**: If the score matrix `S` has cross-ratio span `(S i a - S i b) - (S k a - S k b) ≤ Δ` (with `0 ≤ Δ`), then `τ₁(softmax(S)) ≤ tanh(Δ / 4)`. -/ theorem softmax_dobrushin_le_tanh {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) (Δ : ℝ) (hΔ : 0 ≤ Δ) (hspan : ∀ i k a b : Fin N, (S i a - S i b) - (S k a - S k b) ≤ Δ) : dobrushinCoeff (softmaxMatrix S) ≤ Real.tanh (Δ / 4) := by by_cases hN : 0 < N · rw [dobrushin_le_iff hN] intro i k have hst := softmaxMatrix_isRowStochastic S refine tv_le_tanh_of_cross_ratio _ _ Δ hΔ (hst.1 i) (hst.1 k) (hst.2 i) (hst.2 k) ?_ intro a b unfold softmaxMatrix have hZi : 0 < ∑ r : Fin N, Real.exp (S i r) := Finset.sum_pos (fun r _ => Real.exp_pos _) ⟨a, Finset.mem_univ a⟩ have hZk : 0 < ∑ r : Fin N, Real.exp (S k r) := Finset.sum_pos (fun r _ => Real.exp_pos _) ⟨a, Finset.mem_univ a⟩ rw [div_mul_div_comm, div_mul_div_comm, mul_div_assoc'] rw [div_le_div_iff_of_pos_right (mul_pos hZi hZk)] rw [← Real.exp_add, ← Real.exp_add, ← Real.exp_add] apply Real.exp_le_exp.mpr linarith [hspan i k a b] · unfold dobrushinCoeff; rw [dif_neg hN] exact tanh_nonneg_of_nonneg (by linarith) /-- **Theorem 1.5 (Exact Tightness at `N = 2`)**: For every `Δ ≥ 0`, the symmetric `2 × 2` score matrix `S = [[Δ/4, -Δ/4], [-Δ/4, Δ/4]]` has cross-ratio span `≤ Δ` and attains `τ₁(softmax(S)) = tanh(Δ / 4)` with exact equality. -/ theorem softmax_dobrushin_tanh_sharp_two (Δ : ℝ) (hΔ : 0 ≤ Δ) : let S : Matrix (Fin 2) (Fin 2) ℝ := fun i j => if i = j then Δ / 4 else -(Δ / 4) (∀ i k a b : Fin 2, (S i a - S i b) - (S k a - S k b) ≤ Δ) ∧ dobrushinCoeff (softmaxMatrix S) = Real.tanh (Δ / 4) := by intro S have hspan : ∀ i k a b : Fin 2, (S i a - S i b) - (S k a - S k b) ≤ Δ := by intro i k a b fin_cases i <;> fin_cases k <;> fin_cases a <;> fin_cases b <;> simp only [S, ↓reduceIte, Fin.zero_eta, Fin.mk_one, Fin.reduceEq] <;> linarith refine ⟨hspan, le_antisymm (softmax_dobrushin_le_tanh S Δ hΔ hspan) ?_⟩ have hle : rowTV (softmaxMatrix S 0) (softmaxMatrix S 1) ≤ dobrushinCoeff (softmaxMatrix S) := rowTV_le_dobrushin _ 0 1 refine le_trans ?_ hle unfold rowTV softmaxMatrix rw [Fin.sum_univ_two, Fin.sum_univ_two, Fin.sum_univ_two] simp only [S, ↓reduceIte, Fin.reduceEq] have hpos : 0 < Real.exp (Δ / 4) + Real.exp (-(Δ / 4)) := by positivity have hadd : Real.exp (-(Δ / 4)) + Real.exp (Δ / 4) = Real.exp (Δ / 4) + Real.exp (-(Δ / 4)) := add_comm _ _ have h1 : Real.exp (Δ / 4) / (Real.exp (Δ / 4) + Real.exp (-(Δ / 4))) - Real.exp (-(Δ / 4)) / (Real.exp (-(Δ / 4)) + Real.exp (Δ / 4)) = Real.tanh (Δ / 4) := by rw [Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq, hadd] field_simp [hpos.ne'] have h2 : Real.exp (-(Δ / 4)) / (Real.exp (Δ / 4) + Real.exp (-(Δ / 4))) - Real.exp (Δ / 4) / (Real.exp (-(Δ / 4)) + Real.exp (Δ / 4)) = -Real.tanh (Δ / 4) := by rw [hadd] at h1 ⊢; linarith [h1] rw [h1, h2, abs_neg, abs_of_nonneg (tanh_nonneg_of_nonneg (by linarith))] ring_nf; exact le_rfl /-! ### Exact Birkhoff–Hopf Nonlinear & Linear Projective Contraction Theorem -/ /-- Exact SOS algebraic certificate for Birkhoff's nonlinear projective contraction. -/ lemma birkhoff_sos_core {A B C D ρ u : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) (hD : 0 ≤ D) (hρ : 1 ≤ ρ) (hu : 1 ≤ u) (hAD : A * D ≤ ρ ^ 2 * (B * C)) : (u + ρ) ^ 2 * (A * u ^ 2 + B) * (C + D) ≤ (ρ * u + 1) ^ 2 * (A + B) * (C * u ^ 2 + D) := by set X := Real.sqrt (B * C) set Y := Real.sqrt (A * D) set P := Real.sqrt (A * C) set Q := Real.sqrt (B * D) have hX0 : 0 ≤ X := Real.sqrt_nonneg _ have hY0 : 0 ≤ Y := Real.sqrt_nonneg _ have hX2 : X ^ 2 = B * C := Real.sq_sqrt (mul_nonneg hB hC) have hY2 : Y ^ 2 = A * D := Real.sq_sqrt (mul_nonneg hA hD) have hP2 : P ^ 2 = A * C := Real.sq_sqrt (mul_nonneg hA hC) have hQ2 : Q ^ 2 = B * D := Real.sq_sqrt (mul_nonneg hB hD) have hPQ : P * Q = X * Y := by have h1 : (P * Q) ^ 2 = (X * Y) ^ 2 := by rw [mul_pow, mul_pow, hP2, hQ2, hX2, hY2]; ring have h2 := sq_eq_sq₀ (mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)) (mul_nonneg hX0 hY0) |>.mp h1 exact h2 have hYle : Y ≤ ρ * X := by have h1 : Y ^ 2 ≤ (ρ * X) ^ 2 := by rw [hY2, mul_pow, hX2]; exact hAD nlinarith [sq_nonneg (ρ * X - Y), mul_nonneg (by linarith : 0 ≤ ρ) hX0, hY0] have hcert : (ρ * u + 1) ^ 2 * (A + B) * (C * u ^ 2 + D) - (u + ρ) ^ 2 * (A * u ^ 2 + B) * (C + D) = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u * P - Q) ^ 2 + (ρ * X - Y) * ((ρ * u ^ 2 + 2 * u + ρ) * X + (u ^ 2 + 2 * ρ * u + 1) * Y)) := by have hAC : A * C = P ^ 2 := hP2.symm have hBD : B * D = Q ^ 2 := hQ2.symm have hBC : B * C = X ^ 2 := hX2.symm have hAD' : A * D = Y ^ 2 := hY2.symm calc (ρ * u + 1) ^ 2 * (A + B) * (C * u ^ 2 + D) - (u + ρ) ^ 2 * (A * u ^ 2 + B) * (C + D) = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u ^ 2 * (A * C) + (B * D)) + ρ * (ρ * u ^ 2 + 2 * u + ρ) * (B * C) - (u ^ 2 + 2 * ρ * u + 1) * (A * D)) := by ring _ = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u ^ 2 * P ^ 2 + Q ^ 2) + ρ * (ρ * u ^ 2 + 2 * u + ρ) * X ^ 2 - (u ^ 2 + 2 * ρ * u + 1) * Y ^ 2) := by rw [hAC, hBD, hBC, hAD'] _ = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u * P - Q) ^ 2 + (ρ ^ 2 - 1) * (2 * u * (P * Q)) + ρ * (ρ * u ^ 2 + 2 * u + ρ) * X ^ 2 - (u ^ 2 + 2 * ρ * u + 1) * Y ^ 2) := by ring _ = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u * P - Q) ^ 2 + (ρ ^ 2 - 1) * (2 * u * (X * Y)) + ρ * (ρ * u ^ 2 + 2 * u + ρ) * X ^ 2 - (u ^ 2 + 2 * ρ * u + 1) * Y ^ 2) := by rw [hPQ] _ = (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u * P - Q) ^ 2 + (ρ * X - Y) * ((ρ * u ^ 2 + 2 * u + ρ) * X + (u ^ 2 + 2 * ρ * u + 1) * Y)) := by ring have hnn : 0 ≤ (u ^ 2 - 1) * ((ρ ^ 2 - 1) * (u * P - Q) ^ 2 + (ρ * X - Y) * ((ρ * u ^ 2 + 2 * u + ρ) * X + (u ^ 2 + 2 * ρ * u + 1) * Y)) := by apply mul_nonneg (by nlinarith) apply add_nonneg · exact mul_nonneg (by nlinarith) (sq_nonneg _) · have hρ0 : 0 ≤ ρ := by linarith have hu0 : 0 ≤ u := by linarith exact mul_nonneg (by linarith) (by positivity) linarith /-- **Theorem 1.6 (Exact Birkhoff–Hopf Nonlinear Projective Contraction)**: For any strictly positive kernel `K` with projective cross-ratio bound `e^Δ` (`Δ ≥ 0`), and positive vectors `x, y` with `m ≤ x_j / y_j ≤ M` (`0 < m ≤ M`, `μ = M / m`), every cross-ratio of `Kx` against `Ky` satisfies the exact nonlinear Birkhoff bound `((Kx)_i / (Ky)_i) / ((Kx)_k / (Ky)_k) ≤ ((e^(Δ/2) √μ + 1) / (√μ + e^(Δ/2)))²`. -/ theorem birkhoff_nonlinear_contraction {N : ℕ} (K : Matrix (Fin N) (Fin N) ℝ) (x y : Fin N → ℝ) (Δ m M : ℝ) (hΔ : 0 ≤ Δ) (hm : 0 < m) (hmM : m ≤ M) (hK : ∀ i j, 0 < K i j) (hy : ∀ j, 0 < y j) (hcr : ∀ i k a b : Fin N, K i a * K k b ≤ Real.exp Δ * (K i b * K k a)) (hratio : ∀ j, m * y j ≤ x j ∧ x j ≤ M * y j) (i k : Fin N) : let Kx : Fin N → ℝ := fun r => ∑ j, K r j * x j let Ky : Fin N → ℝ := fun r => ∑ j, K r j * y j let ρ := Real.exp (Δ / 2) let u := Real.sqrt (M / m) Real.log ((Kx i / Ky i) / (Kx k / Ky k)) ≤ 2 * Real.log ((ρ * u + 1) / (u + ρ)) := by intro Kx Ky ρ u have hKy_pos : ∀ r, 0 < Ky r := fun r => Finset.sum_pos (fun j _ => mul_pos (hK r j) (hy j)) ⟨r, Finset.mem_univ r⟩ have hx_pos : ∀ j, 0 < x j := fun j => lt_of_lt_of_le (mul_pos hm (hy j)) (hratio j).1 have hKx_pos : ∀ r, 0 < Kx r := fun r => Finset.sum_pos (fun j _ => mul_pos (hK r j) (hx_pos j)) ⟨r, Finset.mem_univ r⟩ have hρ1 : 1 ≤ ρ := Real.one_le_exp (by linarith) have hu1 : 1 ≤ u := by rw [Real.one_le_sqrt]; exact (one_le_div hm).mpr hmM have hu2 : u ^ 2 = M / m := Real.sq_sqrt (div_nonneg (le_trans hm.le hmM) hm.le) have hnum_pos : 0 < ρ * u + 1 := by nlinarith have hden_pos : 0 < u + ρ := by nlinarith have hlog2 : 2 * Real.log ((ρ * u + 1) / (u + ρ)) = Real.log (((ρ * u + 1) / (u + ρ)) ^ 2) := by rw [Real.log_pow]; ring rw [hlog2] apply Real.log_le_log (div_pos (div_pos (hKx_pos i) (hKy_pos i)) (div_pos (hKx_pos k) (hKy_pos k))) by_cases heq : m = M · have hxe : ∀ j, x j = m * y j := fun j => by have := hratio j; rw [← heq] at this; linarith have hKxe : ∀ r, Kx r = m * Ky r := fun r => by simp only [Kx, Ky, Finset.mul_sum] refine Finset.sum_congr rfl fun j _ => by rw [hxe j]; ring rw [hKxe i, hKxe k, mul_div_cancel_right₀ _ (hKy_pos i).ne', mul_div_cancel_right₀ _ (hKy_pos k).ne', div_self hm.ne'] have : 1 ≤ (ρ * u + 1) / (u + ρ) := by rw [one_le_div hden_pos]; nlinarith nlinarith · have hlt : m < M := lt_of_le_of_ne hmM heq have hMm : 0 < M - m := sub_pos.mpr hlt let θ : Fin N → ℝ := fun j => (x j / y j - m) / (M - m) have hθ0 : ∀ j, 0 ≤ θ j := fun j => by apply div_nonneg _ hMm.le have := (hratio j).1; rw [sub_nonneg, le_div_iff₀ (hy j)]; exact this have hθ1 : ∀ j, θ j ≤ 1 := fun j => by rw [div_le_one hMm] have := (hratio j).2; rw [sub_le_sub_iff_right, div_le_iff₀ (hy j)]; exact this set A := ∑ j : Fin N, K i j * y j * θ j set B := ∑ j : Fin N, K i j * y j * (1 - θ j) set C := ∑ j : Fin N, K k j * y j * θ j set D := ∑ j : Fin N, K k j * y j * (1 - θ j) have hA0 : 0 ≤ A := Finset.sum_nonneg fun j _ => mul_nonneg (mul_nonneg (hK i j).le (hy j).le) (hθ0 j) have hB0 : 0 ≤ B := Finset.sum_nonneg fun j _ => mul_nonneg (mul_nonneg (hK i j).le (hy j).le) (sub_nonneg.mpr (hθ1 j)) have hC0 : 0 ≤ C := Finset.sum_nonneg fun j _ => mul_nonneg (mul_nonneg (hK k j).le (hy j).le) (hθ0 j) have hD0 : 0 ≤ D := Finset.sum_nonneg fun j _ => mul_nonneg (mul_nonneg (hK k j).le (hy j).le) (sub_nonneg.mpr (hθ1 j)) have hAB : A + B = Ky i := by simp only [A, B, Ky, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun j _ => by ring have hCD : C + D = Ky k := by simp only [C, D, Ky, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun j _ => by ring have hxj : ∀ j, x j = (M * θ j + m * (1 - θ j)) * y j := by intro j; simp only [θ]; field_simp [(hy j).ne', hMm.ne']; ring have hKxi : Kx i = m * (A * u ^ 2 + B) := by rw [hu2] simp only [Kx, A, B, Finset.mul_sum, Finset.sum_mul, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun j _ => ?_ rw [hxj j]; field_simp [hm.ne'] have hKxk : Kx k = m * (C * u ^ 2 + D) := by rw [hu2] simp only [Kx, C, D, Finset.mul_sum, Finset.sum_mul, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun j _ => ?_ rw [hxj j]; field_simp [hm.ne'] have hAD_cr : A * D ≤ ρ ^ 2 * (B * C) := by have hρsq : ρ ^ 2 = Real.exp Δ := by rw [sq, ← Real.exp_add]; ring_nf rw [hρsq] calc A * D = ∑ a : Fin N, ∑ b : Fin N, (K i a * K k b) * (y a * y b * θ a * (1 - θ b)) := by simp only [A, D, Finset.sum_mul, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun b _ => by ring _ ≤ ∑ a : Fin N, ∑ b : Fin N, (Real.exp Δ * (K i b * K k a)) * (y a * y b * θ a * (1 - θ b)) := by refine Finset.sum_le_sum fun a _ => Finset.sum_le_sum fun b _ => ?_ have hnn : 0 ≤ y a * y b * θ a * (1 - θ b) := mul_nonneg (mul_nonneg (mul_nonneg (hy a).le (hy b).le) (hθ0 a)) (sub_nonneg.mpr (hθ1 b)) exact mul_le_mul_of_nonneg_right (hcr i k a b) hnn _ = Real.exp Δ * ∑ a : Fin N, ∑ b : Fin N, (K i b * y b * (1 - θ b)) * (K k a * y a * θ a) := by rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun b _ => by ring _ = Real.exp Δ * (B * C) := by congr 1 simp only [B, C, Finset.sum_mul, Finset.mul_sum] have hcore := birkhoff_sos_core hA0 hB0 hC0 hD0 hρ1 hu1 hAD_cr have hfrac : (Kx i / Ky i) / (Kx k / Ky k) = (Kx i * Ky k) / (Ky i * Kx k) := by field_simp [(hKy_pos i).ne', (hKy_pos k).ne', (hKx_pos k).ne'] rw [hfrac, div_pow, div_le_div_iff₀ (mul_pos (hKy_pos i) (hKx_pos k)) (pow_pos hden_pos 2)] rw [hKxi, hKxk, ← hAB, ← hCD] nlinarith [hm] /-- **Theorem 1.7 (Exact Birkhoff–Hopf Linear Contraction `tanh(Δ/4)`)**: For every `Δ ≥ 0` and `h ≥ 0`, `2 log((e^(Δ/2) e^(h/2) + 1) / (e^(h/2) + e^(Δ/2))) ≤ tanh(Δ/4) · h`, completing the classical Birkhoff contraction theorem `d_H(Kx, Ky) ≤ tanh(Δ/4) · d_H(x, y)`. -/ theorem birkhoff_linear_contraction (Δ h : ℝ) (hΔ : 0 ≤ Δ) (hh : 0 ≤ h) : 2 * Real.log ((Real.exp (Δ / 2) * Real.exp (h / 2) + 1) / (Real.exp (h / 2) + Real.exp (Δ / 2))) ≤ Real.tanh (Δ / 4) * h := by set ρ := Real.exp (Δ / 2) have hρ1 : 1 ≤ ρ := Real.one_le_exp (by linarith) have hρpos : 0 < ρ := by linarith let f : ℝ → ℝ := fun t => Real.tanh (Δ / 4) * t - 2 * (Real.log (ρ * Real.exp (t / 2) + 1) - Real.log (Real.exp (t / 2) + ρ)) have hdiv_eq : 2 * Real.log ((ρ * Real.exp (h / 2) + 1) / (Real.exp (h / 2) + ρ)) = 2 * (Real.log (ρ * Real.exp (h / 2) + 1) - Real.log (Real.exp (h / 2) + ρ)) := by rw [Real.log_div (by positivity) (by positivity)] rw [hdiv_eq] suffices h0 : f 0 ≤ f h by have hf0 : f 0 = 0 := by simp only [f, mul_zero, zero_div, Real.exp_zero, mul_one, zero_sub] rw [add_comm 1 ρ, sub_self, mul_zero, neg_zero] rw [hf0] at h0 linarith have hderiv : ∀ t : ℝ, HasDerivAt f (Real.tanh (Δ / 4) - (ρ * Real.exp (t / 2) / (ρ * Real.exp (t / 2) + 1) - Real.exp (t / 2) / (Real.exp (t / 2) + ρ))) t := by intro t have he : HasDerivAt (fun s => Real.exp (s / 2)) (Real.exp (t / 2) * (1 / 2)) t := by have h1 : HasDerivAt (fun s : ℝ => s / 2) (1 / 2) t := (hasDerivAt_id t).div_const 2 simpa using h1.exp have hnum : HasDerivAt (fun s => ρ * Real.exp (s / 2) + 1) (ρ * (Real.exp (t / 2) * (1 / 2))) t := by simpa using (he.const_mul ρ).add_const 1 have hden : HasDerivAt (fun s => Real.exp (s / 2) + ρ) (Real.exp (t / 2) * (1 / 2)) t := by simpa using he.add_const ρ have hl1 : HasDerivAt (fun s => Real.log (ρ * Real.exp (s / 2) + 1)) (ρ * (Real.exp (t / 2) * (1 / 2)) / (ρ * Real.exp (t / 2) + 1)) t := hnum.log (by positivity) have hl2 : HasDerivAt (fun s => Real.log (Real.exp (s / 2) + ρ)) (Real.exp (t / 2) * (1 / 2) / (Real.exp (t / 2) + ρ)) t := hden.log (by positivity) have hlin : HasDerivAt (fun s => Real.tanh (Δ / 4) * s) (Real.tanh (Δ / 4)) t := by simpa using (hasDerivAt_id t).const_mul (Real.tanh (Δ / 4)) have hall := hlin.sub ((hl1.sub hl2).const_mul 2) have hEq : Real.tanh (Δ / 4) - (ρ * Real.exp (t / 2) / (ρ * Real.exp (t / 2) + 1) - Real.exp (t / 2) / (Real.exp (t / 2) + ρ)) = Real.tanh (Δ / 4) - 2 * (ρ * (Real.exp (t / 2) * (1 / 2)) / (ρ * Real.exp (t / 2) + 1) - Real.exp (t / 2) * (1 / 2) / (Real.exp (t / 2) + ρ)) := by ring rwa [hEq] have hmono : MonotoneOn f (Set.Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) · exact fun t _ => (hderiv t).continuousAt.continuousWithinAt · exact fun t _ => (hderiv t).differentiableAt.differentiableWithinAt · intro t _ rw [(hderiv t).deriv, sub_nonneg] set x := Real.exp (t / 2) have hx : 0 < x := Real.exp_pos _ have htan : Real.tanh (Δ / 4) = (ρ - 1) / (ρ + 1) := by rw [tanh_eq_exp_sub_div_add] have : 2 * (Δ / 4) = Δ / 2 := by ring rw [this] rw [htan] have h1 : 0 < ρ * x + 1 := by positivity have h2 : 0 < x + ρ := by positivity have h3 : 0 < ρ + 1 := by linarith have hcomb : ρ * x / (ρ * x + 1) - x / (x + ρ) = x * (ρ ^ 2 - 1) / ((ρ * x + 1) * (x + ρ)) := by field_simp [h1.ne', h2.ne']; ring rw [hcomb, div_le_div_iff₀ (mul_pos h1 h2) h3] have hsq : 0 ≤ ρ * (x - 1) ^ 2 * (ρ - 1) := mul_nonneg (mul_nonneg hρpos.le (sq_nonneg _)) (by linarith) nlinarith exact hmono (Set.mem_Ici.mpr le_rfl) hh hh /-! ### Exact Shift-Invariant Cubic Doubly-Exponential Self-Attention Collapse & Bifurcation -/ /-- One layer of pure single-head self-attention `X ↦ softmax(β (X W_Q)(X W_K)ᵀ) X W_V`. -/ noncomputable def selfAttnLayer {N d : ℕ} (β : ℝ) (WQ WK WV : Matrix (Fin d) (Fin d) ℝ) (X : Fin N → (Fin d → ℝ)) : Fin N → (Fin d → ℝ) := let S : Matrix (Fin N) (Fin N) ℝ := fun i j => β * dotProd (WQ.mulVec (X i)) (WK.mulVec (X j)) let A := softmaxMatrix S fun i => WV.mulVec (fun c => ∑ j : Fin N, A i j * X j c) /-- **Theorem 1.8 (Shift-Invariant One-Layer Self-Attention Diameter Contraction)**: If `X` has Euclidean diameter `≤ D`, `‖WQ‖ ≤ q`, `‖WK‖ ≤ k`, `‖WV‖ ≤ γ`, and `β ≥ 0`, then one pure self-attention layer contracts pairwise Euclidean diameter by the exact factor `D_next ≤ γ · D · tanh(β q k D² / 4)` — completely independent of token mean `‖X‖` and `N`! -/ theorem self_attention_one_step_diam_bound {N d : ℕ} (β q k γ D : ℝ) (hβ : 0 ≤ β) (hq : 0 ≤ q) (hk : 0 ≤ k) (hγ : 0 ≤ γ) (hD : 0 ≤ D) (WQ WK WV : Matrix (Fin d) (Fin d) ℝ) (hWQ : ∀ u, Real.sqrt (sqNorm (WQ.mulVec u)) ≤ q * Real.sqrt (sqNorm u)) (hWK : ∀ u, Real.sqrt (sqNorm (WK.mulVec u)) ≤ k * Real.sqrt (sqNorm u)) (hWV : ∀ u, Real.sqrt (sqNorm (WV.mulVec u)) ≤ γ * Real.sqrt (sqNorm u)) (X : Fin N → (Fin d → ℝ)) (hX : ∀ a b : Fin N, Real.sqrt (sqNorm (X a - X b)) ≤ D) (i m : Fin N) : Real.sqrt (sqNorm (selfAttnLayer β WQ WK WV X i - selfAttnLayer β WQ WK WV X m)) ≤ γ * D * Real.tanh (β * q * k * D ^ 2 / 4) := by let S : Matrix (Fin N) (Fin N) ℝ := fun r s => β * dotProd (WQ.mulVec (X r)) (WK.mulVec (X s)) let A := softmaxMatrix S have hspan : ∀ r s a b : Fin N, (S r a - S r b) - (S s a - S s b) ≤ β * q * k * D ^ 2 := by intro r s a b have hid : (S r a - S r b) - (S s a - S s b) = β * dotProd (WQ.mulVec (X r - X s)) (WK.mulVec (X a - X b)) := by simp only [S, dotProd, Matrix.mulVec_sub, Pi.sub_apply] rw [← mul_sub, ← mul_sub, ← mul_sub] congr 1 simp only [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun c _ => by ring rw [hid] have hcs := abs_dotProd_le_sqrt (WQ.mulVec (X r - X s)) (WK.mulVec (X a - X b)) have hle := le_trans (le_abs_self _) hcs have h1 : Real.sqrt (sqNorm (WQ.mulVec (X r - X s))) ≤ q * D := le_trans (hWQ _) (mul_le_mul_of_nonneg_left (hX r s) hq) have h2 : Real.sqrt (sqNorm (WK.mulVec (X a - X b))) ≤ k * D := le_trans (hWK _) (mul_le_mul_of_nonneg_left (hX a b) hk) have hprod : Real.sqrt (sqNorm (WQ.mulVec (X r - X s))) * Real.sqrt (sqNorm (WK.mulVec (X a - X b))) ≤ (q * D) * (k * D) := mul_le_mul h1 h2 (Real.sqrt_nonneg _) (mul_nonneg hq hD) nlinarith have htau : dobrushinCoeff A ≤ Real.tanh (β * q * k * D ^ 2 / 4) := softmax_dobrushin_le_tanh S (β * q * k * D ^ 2) (by positivity) hspan -- Embed Fin d → ℝ into EuclideanSpace ℝ (Fin d) to apply Theorem 1.2 directly! let Xe : Fin N → EuclideanSpace ℝ (Fin d) := fun r => (WithLp.equiv 2 (Fin d → ℝ)).symm (X r) have hnorm_eq : ∀ v : Fin d → ℝ, ‖(WithLp.equiv 2 (Fin d → ℝ)).symm v‖ = Real.sqrt (sqNorm v) := by intro v rw [EuclideanSpace.norm_eq] congr 1; unfold sqNorm dotProd refine Finset.sum_congr rfl fun c _ => ?_ change ‖v c‖ ^ 2 = v c * v c rw [Real.norm_eq_abs, sq_abs, sq] have hXe : ∀ a b : Fin N, ‖Xe a - Xe b‖ ≤ D := by intro a b have hsub : Xe a - Xe b = (WithLp.equiv 2 (Fin d → ℝ)).symm (X a - X b) := rfl rw [hsub, hnorm_eq] exact hX a b have hAX := dobrushin_diameter_contraction (softmaxMatrix_isRowStochastic S) Xe D hXe i m let avg : Fin N → (Fin d → ℝ) := fun r c => ∑ j : Fin N, A r j * X j c have havg_eq : (∑ j : Fin N, A i j • Xe j) - (∑ j : Fin N, A m j • Xe j) = (WithLp.equiv 2 (Fin d → ℝ)).symm (avg i - avg m) := by have hsum_apply : ∀ (r : Fin N) (s : Finset (Fin N)) (c : Fin d), (∑ j ∈ s, A r j • Xe j).ofLp c = ∑ j ∈ s, A r j * X j c := by intro r s c induction s using Finset.cons_induction with | empty => simp | cons a s ha ih => rw [Finset.sum_cons, Finset.sum_cons] change (A r a • Xe a).ofLp c + (∑ j ∈ s, A r j • Xe j).ofLp c = _ rw [ih]; rfl ext c change (∑ j : Fin N, A i j • Xe j).ofLp c - (∑ j : Fin N, A m j • Xe j).ofLp c = avg i c - avg m c rw [hsum_apply i Finset.univ c, hsum_apply m Finset.univ c] rw [havg_eq, hnorm_eq] at hAX have hdiff : selfAttnLayer β WQ WK WV X i - selfAttnLayer β WQ WK WV X m = WV.mulVec (avg i - avg m) := by simp only [selfAttnLayer, Matrix.mulVec_sub]; rfl rw [hdiff] calc Real.sqrt (sqNorm (WV.mulVec (avg i - avg m))) ≤ γ * Real.sqrt (sqNorm (avg i - avg m)) := hWV _ _ ≤ γ * (dobrushinCoeff A * D) := mul_le_mul_of_nonneg_left hAX hγ _ ≤ γ * (Real.tanh (β * q * k * D ^ 2 / 4) * D) := mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right htau hD) hγ _ = γ * D * Real.tanh (β * q * k * D ^ 2 / 4) := by ring /-- **Theorem 1.9 (Exact Cubic Doubly-Exponential `3^L` Collapse Rate)**: Any sequence `D : ℕ → ℝ` obeying `0 ≤ D (ℓ+1) ≤ γ * D ℓ * tanh(c * (D ℓ)² / 4)` with `γ, c ≥ 0` satisfies the exact cubic recurrence `D (ℓ+1) ≤ (γ c / 4) (D ℓ)³` and the closed-form doubly-exponential bound `D L ≤ (γ c / 4)^((3^L - 1) / 2) · (D 0)^(3^L)`. -/ theorem self_attention_cubic_collapse_rate (γ c : ℝ) (hγ : 0 ≤ γ) (hc : 0 ≤ c) (D : ℕ → ℝ) (hD0 : ∀ ℓ, 0 ≤ D ℓ) (hstep : ∀ ℓ, D (ℓ + 1) ≤ γ * D ℓ * Real.tanh (c * (D ℓ) ^ 2 / 4)) : ∀ L : ℕ, D L ≤ (γ * c / 4) ^ ((3 ^ L - 1) / 2) * (D 0) ^ (3 ^ L) := by have hcub : ∀ ℓ, D (ℓ + 1) ≤ (γ * c / 4) * (D ℓ) ^ 3 := by intro ℓ have htan : Real.tanh (c * (D ℓ) ^ 2 / 4) ≤ c * (D ℓ) ^ 2 / 4 := tanh_le_self (by positivity) calc D (ℓ + 1) ≤ γ * D ℓ * Real.tanh (c * (D ℓ) ^ 2 / 4) := hstep ℓ _ ≤ γ * D ℓ * (c * (D ℓ) ^ 2 / 4) := mul_le_mul_of_nonneg_left htan (mul_nonneg hγ (hD0 ℓ)) _ = (γ * c / 4) * (D ℓ) ^ 3 := by ring intro L induction L with | zero => simp | succ L ih => have hodd : ∃ k, 3 ^ L = 2 * k + 1 := by have : Odd (3 ^ L) := Odd.pow (by decide) exact this rcases hodd with ⟨k, hk⟩ have hexp : (3 ^ (L + 1) - 1) / 2 = 3 * ((3 ^ L - 1) / 2) + 1 := by rw [pow_succ, hk]; omega calc D (L + 1) ≤ (γ * c / 4) * (D L) ^ 3 := hcub L _ ≤ (γ * c / 4) * ((γ * c / 4) ^ ((3 ^ L - 1) / 2) * (D 0) ^ (3 ^ L)) ^ 3 := mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (hD0 L) ih 3) (by positivity) _ = (γ * c / 4) ^ (3 * ((3 ^ L - 1) / 2) + 1) * (D 0) ^ (3 ^ (L + 1)) := by rw [mul_pow, ← pow_mul, ← pow_mul, mul_comm (3 ^ L) 3, ← pow_succ', ← mul_assoc, ← pow_succ'] ring_nf _ = (γ * c / 4) ^ ((3 ^ (L + 1) - 1) / 2) * (D 0) ^ (3 ^ (L + 1)) := by rw [hexp] /-- **Theorem 1.10 (Exact `N = 2` Antipodal Self-Attention Dynamics)**: For two 1D antipodal tokens `X = [D/2, -D/2]` with `W_Q = W_K = I`, `W_V = γ I`, one self-attention layer attains exact equality `D_next = γ · D · tanh(β D² / 4)`! -/ theorem self_attention_antipodal_exact_dynamics (β γ D : ℝ) (hγ : 0 ≤ γ) (hD : 0 ≤ D) (hβ : 0 ≤ β) : let X : Fin 2 → (Fin 1 → ℝ) := fun i _ => if i = 0 then D / 2 else -(D / 2) let I1 : Matrix (Fin 1) (Fin 1) ℝ := 1 let X' := selfAttnLayer β I1 I1 (γ • I1) X Real.sqrt (sqNorm (X' 0 - X' 1)) = γ * D * Real.tanh (β * D ^ 2 / 4) := by intro X I1 X' have hval : X' 0 0 - X' 1 0 = γ * D * Real.tanh (β * D ^ 2 / 4) := by simp only [X', selfAttnLayer, I1, Matrix.smul_mulVec, Matrix.one_mulVec, Pi.smul_apply, smul_eq_mul, softmaxMatrix, dotProd, Fin.sum_univ_one, Fin.sum_univ_two, X, ↓reduceIte, Fin.reduceEq] have hmul : β * (D / 2 * (D / 2)) = β * D ^ 2 / 4 := by ring have hmul' : β * (D / 2 * -(D / 2)) = -(β * D ^ 2 / 4) := by ring have hmul'' : β * (-(D / 2) * (D / 2)) = -(β * D ^ 2 / 4) := by ring have hmul''' : β * (-(D / 2) * -(D / 2)) = β * D ^ 2 / 4 := by ring rw [hmul, hmul', hmul'', hmul'''] set t := β * D ^ 2 / 4 have hpos : 0 < Real.exp t + Real.exp (-t) := by positivity have hcomm : Real.exp (-t) + Real.exp t = Real.exp t + Real.exp (-t) := add_comm _ _ rw [hcomm, Real.tanh_eq_sinh_div_cosh, Real.sinh_eq, Real.cosh_eq] field_simp [hpos.ne'] ring have hnn : 0 ≤ γ * D * Real.tanh (β * D ^ 2 / 4) := mul_nonneg (mul_nonneg hγ hD) (tanh_nonneg_of_nonneg (by positivity)) have hsq : sqNorm (X' 0 - X' 1) = (γ * D * Real.tanh (β * D ^ 2 / 4)) ^ 2 := by unfold sqNorm dotProd rw [Fin.sum_univ_one, Pi.sub_apply, hval] ring rw [hsq, Real.sqrt_sq hnn] /-- **Theorem 1.11 (Exact Supercritical Bifurcation Threshold `D_crit(γ, c)`)**: For `γ > 1` and `c > 0`, define `D_crit = √((2/c) log((γ+1)/(γ-1)))` and `f(D) = γ · D · tanh(c D² / 4)`. Then: (1) `f(D_crit) = D_crit` (exact persistent nontrivial equilibrium); (2) For every `0 < D < D_crit`, `f(D) < D` (strict contraction to collapse); (3) For every `D > D_crit`, `f(D) > D` (strict expansion / explosion). -/ theorem self_attention_bifurcation_threshold (γ c : ℝ) (hγ : 1 < γ) (hc : 0 < c) : let Dcrit := Real.sqrt ((2 / c) * Real.log ((γ + 1) / (γ - 1))) let f : ℝ → ℝ := fun D => γ * D * Real.tanh (c * D ^ 2 / 4) (0 < Dcrit) ∧ (f Dcrit = Dcrit) ∧ (∀ D, 0 < D → D < Dcrit → f D < D) ∧ (∀ D, Dcrit < D → D < f D) := by intro Dcrit f have hratio : 1 < (γ + 1) / (γ - 1) := by rw [one_lt_div (by linarith)]; linarith have hlog : 0 < Real.log ((γ + 1) / (γ - 1)) := Real.log_pos hratio have harg : 0 < (2 / c) * Real.log ((γ + 1) / (γ - 1)) := mul_pos (div_pos two_pos hc) hlog have hDc_pos : 0 < Dcrit := Real.sqrt_pos.mpr harg have hDc_sq : Dcrit ^ 2 = (2 / c) * Real.log ((γ + 1) / (γ - 1)) := Real.sq_sqrt harg.le have htan_crit : Real.tanh (c * Dcrit ^ 2 / 4) = 1 / γ := by rw [tanh_eq_exp_sub_div_add, hDc_sq] have h2 : 2 * (c * ((2 / c) * Real.log ((γ + 1) / (γ - 1))) / 4) = Real.log ((γ + 1) / (γ - 1)) := by field_simp [hc.ne']; ring rw [h2, Real.exp_log (by positivity)] have hgm : γ - 1 ≠ 0 := by linarith have hgp : γ ≠ 0 := by linarith field_simp [hgm, hgp] ring refine ⟨hDc_pos, ?_, ?_, ?_⟩ · simp only [f, htan_crit]; field_simp [(by linarith : γ ≠ 0)] · intro D hD0 hDlt simp only [f] have hsq : c * D ^ 2 / 4 < c * Dcrit ^ 2 / 4 := by have : D ^ 2 < Dcrit ^ 2 := by nlinarith nlinarith have ht : Real.tanh (c * D ^ 2 / 4) < 1 / γ := by rw [← htan_crit]; exact tanh_strictMono hsq have h1 : γ * Real.tanh (c * D ^ 2 / 4) < 1 := by have := mul_lt_mul_of_pos_left ht (by linarith : 0 < γ) rwa [mul_one_div_cancel (by linarith : γ ≠ 0)] at this nlinarith · intro D hDgt simp only [f] have hD0 : 0 < D := lt_trans hDc_pos hDgt have hsq : c * Dcrit ^ 2 / 4 < c * D ^ 2 / 4 := by have : Dcrit ^ 2 < D ^ 2 := by nlinarith nlinarith have ht : 1 / γ < Real.tanh (c * D ^ 2 / 4) := by rw [← htan_crit]; exact tanh_strictMono hsq have h1 : 1 < γ * Real.tanh (c * D ^ 2 / 4) := by have := mul_lt_mul_of_pos_left ht (by linarith : 0 < γ) rwa [mul_one_div_cancel (by linarith : γ ≠ 0)] at this nlinarith /-! ## PART II: Sinkhorn–Birkhoff Doubly Stochastic Attention, Residual Rollout, and Exact Causal-Mask Non-Normal Metastability -/ /-- Diagonal scaling `D_u K D_v` (the Sinkhorn–Knopp operator family). -/ def diagScale {N : ℕ} (u v : Fin N → ℝ) (K : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ := fun i j => u i * K i j * v j /-- **Theorem 2.1 (Sinkhorn Cross-Ratio Invariance & Identical Sharp Dobrushin Bound)**: For ANY positive diagonal scalings `u, v > 0`, the cross-ratios of `P = D_u exp(S) D_v` are IDENTICAL to those of `exp(S)`. Hence ANY row-stochastic Sinkhorn iterate (including the doubly stochastic Sinkhorn limit) obeys the exact same sharp Dobrushin bound `τ₁(P) ≤ tanh(Δ(S) / 4)`. -/ theorem sinkhorn_cross_ratio_invariant {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) (u v : Fin N → ℝ) (hu : ∀ i, 0 < u i) (hv : ∀ j, 0 < v j) (i k a b : Fin N) : let K : Matrix (Fin N) (Fin N) ℝ := fun r s => Real.exp (S r s) let P := diagScale u v K (P i a * P k b) / (P i b * P k a) = Real.exp ((S i a - S i b) - (S k a - S k b)) := by intro K P simp only [P, K, diagScale] have hne : u i ≠ 0 ∧ u k ≠ 0 ∧ v a ≠ 0 ∧ v b ≠ 0 := ⟨(hu i).ne', (hu k).ne', (hv a).ne', (hv b).ne'⟩ have hene : Real.exp (S i b) * Real.exp (S k a) ≠ 0 := by positivity rw [show (S i a - S i b) - (S k a - S k b) = (S i a + S k b) - (S i b + S k a) by ring] rw [Real.exp_sub, Real.exp_add, Real.exp_add] field_simp [hne.1, hne.2.1, hne.2.2.1, hne.2.2.2, hene] theorem sinkhorn_dobrushin_le_tanh {N : ℕ} (S : Matrix (Fin N) (Fin N) ℝ) (u v : Fin N → ℝ) (hu : ∀ i, 0 < u i) (hv : ∀ j, 0 < v j) (Δ : ℝ) (hΔ : 0 ≤ Δ) (hspan : ∀ i k a b : Fin N, (S i a - S i b) - (S k a - S k b) ≤ Δ) (hst : IsRowStochastic (diagScale u v (fun r s => Real.exp (S r s)))) : dobrushinCoeff (diagScale u v (fun r s => Real.exp (S r s))) ≤ Real.tanh (Δ / 4) := by by_cases hN : 0 < N · rw [dobrushin_le_iff hN] intro i k refine tv_le_tanh_of_cross_ratio _ _ Δ hΔ (hst.1 i) (hst.1 k) (hst.2 i) (hst.2 k) ?_ intro a b have hinv := sinkhorn_cross_ratio_invariant S u v hu hv i k a b have hpos : 0 < diagScale u v (fun r s => Real.exp (S r s)) i b * diagScale u v (fun r s => Real.exp (S r s)) k a := by simp only [diagScale] exact mul_pos (mul_pos (mul_pos (hu i) (Real.exp_pos _)) (hv b)) (mul_pos (mul_pos (hu k) (Real.exp_pos _)) (hv a)) rw [← div_le_iff₀ hpos, hinv] exact Real.exp_le_exp.mpr (hspan i k a b) · unfold dobrushinCoeff; rw [dif_neg hN] exact tanh_nonneg_of_nonneg (by linarith) /-- Mean token vector `(1/N) ∑_i X_i`. -/ noncomputable def tokenMean {N d : ℕ} (X : Fin N → (Fin d → ℝ)) : Fin d → ℝ := fun c => (1 / (N : ℝ)) * ∑ i : Fin N, X i c /-- Token variance / Dirichlet energy `(1/N) ∑_i ‖X_i - mean(X)‖₂²`. -/ noncomputable def tokenVariance {N d : ℕ} (X : Fin N → (Fin d → ℝ)) : ℝ := (1 / (N : ℝ)) * ∑ i : Fin N, sqNorm (X i - tokenMean X) /-- Matrix-token action `(P X)_i = ∑_j P_{ij} X_j`. -/ def applyAttn {N d : ℕ} (P : Matrix (Fin N) (Fin N) ℝ) (X : Fin N → (Fin d → ℝ)) : Fin N → (Fin d → ℝ) := fun i c => ∑ j : Fin N, P i j * X j c /-- **Theorem 2.2 (Exact Mean Conservation & Dirichlet Variance-Decay Identity for Doubly Stochastic / Sinkhorn Attention)**: For ANY doubly stochastic matrix `P`, (1) `tokenMean (P X) = tokenMean X`, and (2) `tokenVariance X - tokenVariance (P X) = (1/N) ∑_i ∑_j P_{ij} ‖X_j - (P X)_i‖₂² ≥ 0`. -/ theorem doubly_stochastic_mean_conservation {N d : ℕ} {P : Matrix (Fin N) (Fin N) ℝ} (hP : IsDoublyStochastic P) (X : Fin N → (Fin d → ℝ)) : tokenMean (applyAttn P X) = tokenMean X := by ext c simp only [tokenMean, applyAttn] congr 1 calc ∑ i : Fin N, ∑ j : Fin N, P i j * X j c = ∑ j : Fin N, (∑ i : Fin N, P i j) * X j c := by rw [Finset.sum_comm]; simp only [Finset.sum_mul] _ = ∑ j : Fin N, X j c := by simp only [hP.2, one_mul] theorem doubly_stochastic_dirichlet_variance_decay {N d : ℕ} (hN : 0 < N) {P : Matrix (Fin N) (Fin N) ℝ} (hP : IsDoublyStochastic P) (X : Fin N → (Fin d → ℝ)) : tokenVariance X - tokenVariance (applyAttn P X) = (1 / (N : ℝ)) * ∑ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - applyAttn P X i) ∧ 0 ≤ tokenVariance X - tokenVariance (applyAttn P X) := by have hmean := doubly_stochastic_mean_conservation hP X set μ := tokenMean X have hid : ∑ i : Fin N, sqNorm (X i - μ) - ∑ i : Fin N, sqNorm (applyAttn P X i - μ) = ∑ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - applyAttn P X i) := by -- Expand per-coordinate identity: -- ∑_j P_{ij} (x_j - y_i)^2 = ∑_j P_{ij} (x_j - μ)^2 - (y_i - μ)^2 since y_i = ∑_j P_{ij} x_j have hrow : ∀ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - applyAttn P X i) = (∑ j : Fin N, P i j * sqNorm (X j - μ)) - sqNorm (applyAttn P X i - μ) := by intro i simp only [sqNorm, dotProd, Pi.sub_apply] simp only [Finset.mul_sum] rw [Finset.sum_comm, Finset.sum_comm (s := Finset.univ) (t := Finset.univ) (f := fun j c => P i j * ((X j c - μ c) * (X j c - μ c)))] rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl fun c _ => ?_ have hsum1 : ∑ j : Fin N, P i j = 1 := hP.1.2 i have hy : applyAttn P X i c = ∑ j : Fin N, P i j * X j c := rfl set y := applyAttn P X i c have hexp : ∀ j : Fin N, P i j * ((X j c - y) * (X j c - y)) = P i j * ((X j c - μ c) * (X j c - μ c)) - 2 * (y - μ c) * (P i j * X j c) + (y ^ 2 - μ c ^ 2) * P i j := by intro j; ring calc ∑ j : Fin N, P i j * ((X j c - y) * (X j c - y)) = ∑ j : Fin N, (P i j * ((X j c - μ c) * (X j c - μ c)) - 2 * (y - μ c) * (P i j * X j c) + (y ^ 2 - μ c ^ 2) * P i j) := Finset.sum_congr rfl fun j _ => hexp j _ = (∑ j : Fin N, P i j * ((X j c - μ c) * (X j c - μ c))) - 2 * (y - μ c) * (∑ j : Fin N, P i j * X j c) + (y ^ 2 - μ c ^ 2) * (∑ j : Fin N, P i j) := by simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] _ = (∑ j : Fin N, P i j * ((X j c - μ c) * (X j c - μ c))) - (y - μ c) * (y - μ c) := by rw [← hy, hsum1]; ring calc ∑ i : Fin N, sqNorm (X i - μ) - ∑ i : Fin N, sqNorm (applyAttn P X i - μ) = (∑ j : Fin N, (∑ i : Fin N, P i j) * sqNorm (X j - μ)) - ∑ i : Fin N, sqNorm (applyAttn P X i - μ) := by simp only [hP.2, one_mul] _ = (∑ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - μ)) - ∑ i : Fin N, sqNorm (applyAttn P X i - μ) := by congr 1; rw [Finset.sum_comm]; simp only [Finset.sum_mul] _ = ∑ i : Fin N, ((∑ j : Fin N, P i j * sqNorm (X j - μ)) - sqNorm (applyAttn P X i - μ)) := (Finset.sum_sub_distrib _ _).symm _ = ∑ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - applyAttn P X i) := Finset.sum_congr rfl fun i _ => (hrow i).symm have heq : tokenVariance X - tokenVariance (applyAttn P X) = (1 / (N : ℝ)) * ∑ i : Fin N, ∑ j : Fin N, P i j * sqNorm (X j - applyAttn P X i) := by unfold tokenVariance rw [hmean, ← mul_sub, hid] refine ⟨heq, ?_⟩ rw [heq] have hNpos : (0 : ℝ) < N := Nat.cast_pos.mpr hN exact mul_nonneg (by positivity) (Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => mul_nonneg (hP.1.1 i j) (sqNorm_nonneg _)) /-- **Theorem 2.3 (Sinkhorn No-Attention-Sink Bound vs. Softmax 1-Layer Sink Collapse)**: (1) In ANY doubly stochastic matrix `P`, no token `s` can receive uniform attention weight `> 1/N`: there always exists a row `i` with `P i s ≤ 1/N`. (2) Conversely, if a row-stochastic matrix `A` has an attention sink `s` with `A i s ≥ 1 - ε` for every row `i`, then `τ₁(A) ≤ ε` (1-layer `ε`-collapse!). -/ theorem doubly_stochastic_no_attention_sink {N : ℕ} (hN : 0 < N) {P : Matrix (Fin N) (Fin N) ℝ} (hP : IsDoublyStochastic P) (s : Fin N) : ∃ i : Fin N, P i s ≤ 1 / (N : ℝ) := by by_contra h push Not at h have hsum : ∑ i : Fin N, (1 / (N : ℝ)) < ∑ i : Fin N, P i s := Finset.sum_lt_sum_of_nonempty ⟨⟨0, hN⟩, Finset.mem_univ _⟩ fun i _ => h i rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one_div_cancel (Nat.cast_ne_zero.mpr hN.ne'), hP.2 s] at hsum exact lt_irrefl 1 hsum theorem softmax_attention_sink_one_step_collapse {N : ℕ} {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) (s : Fin N) (ε : ℝ) (hsink : ∀ i : Fin N, 1 - ε ≤ A i s) : dobrushinCoeff A ≤ ε := by have hN : 0 < N := s.pos rw [dobrushin_le_iff hN] intro i k have htv := (dobrushin_tv_eq_one_sub_min (A i) (A k) (hA.1 i) (hA.1 k) (hA.2 i) (hA.2 k)).1 rw [htv] have hle : min (A i s) (A k s) ≤ ∑ j : Fin N, min (A i j) (A k j) := Finset.single_le_sum (fun j _ => le_min (hA.1 i j) (hA.1 k j)) (Finset.mem_univ s) have hmin : 1 - ε ≤ min (A i s) (A k s) := le_min (hsink i) (hsink k) linarith /-! ### Residual Rollout Two-Sided Dobrushin Bounds, Trace Lower Bound, & PSD Anti-Collapse -/ /-- Residual rollout matrix `R_α(A) = (1 - α) I + α A`. -/ def residualRollout {N : ℕ} (α : ℝ) (A : Matrix (Fin N) (Fin N) ℝ) : Matrix (Fin N) (Fin N) ℝ := (1 - α) • (1 : Matrix (Fin N) (Fin N) ℝ) + α • A lemma residualRollout_isRowStochastic {N : ℕ} {α : ℝ} (hα0 : 0 ≤ α) (hα1 : α ≤ 1) {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : IsRowStochastic (residualRollout α A) := by refine ⟨fun i j => ?_, fun i => ?_⟩ · simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul] split_ifs <;> nlinarith [hA.1 i j] · simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, Finset.sum_add_distrib, ← Finset.mul_sum, hA.2 i, mul_one] have : ∑ j : Fin N, (if i = j then (1 : ℝ) else 0) = 1 := by simp [Finset.sum_ite_eq] rw [this]; ring /-- **Theorem 2.4 (Universal Trace Lower Bound on Dobrushin's Coefficient)**: For EVERY `N ≥ 2` and EVERY row-stochastic matrix `A`, `(tr(A) - 1) / (N - 1) ≤ τ₁(A)`. -/ theorem dobrushin_trace_lower_bound {N : ℕ} (hN : 2 ≤ N) {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : (Matrix.trace A - 1) / ((N : ℝ) - 1) ≤ dobrushinCoeff A := by have hN1 : (0 : ℝ) < (N : ℝ) - 1 := by have : (2 : ℝ) ≤ (N : ℝ) := Nat.ofNat_le_cast.mpr hN linarith have hNpos : (0 : ℝ) < (N : ℝ) := by linarith -- For every pair (i, k) with i ≠ k, rowTV (A i) (A k) ≥ (1/2) * ((A i i - A k i) + (A k k - A i k)) have hpair : ∀ i k : Fin N, i ≠ k → (1 / 2 : ℝ) * ((A i i - A k i) + (A k k - A i k)) ≤ dobrushinCoeff A := by intro i k hik refine le_trans ?_ (rowTV_le_dobrushin A i k) unfold rowTV apply mul_le_mul_of_nonneg_left _ (by norm_num) have hsub : ({i, k} : Finset (Fin N)) ⊆ Finset.univ := Finset.subset_univ _ have hsum2 : ∑ j ∈ ({i, k} : Finset (Fin N)), |A i j - A k j| ≤ ∑ j : Fin N, |A i j - A k j| := Finset.sum_le_sum_of_subset_of_nonneg hsub fun j _ _ => abs_nonneg _ rw [Finset.sum_pair hik] at hsum2 have h1 : A i i - A k i ≤ |A i i - A k i| := le_abs_self _ have h2 : A k k - A i k ≤ |A i k - A k k| := by rw [abs_sub_comm]; exact le_abs_self _ linarith -- Sum over all ordered pairs (i, k) with i ≠ k let S : Finset (Fin N × Fin N) := Finset.univ.filter (fun p => p.1 ≠ p.2) have hcard : (S.card : ℝ) = (N : ℝ) * ((N : ℝ) - 1) := by have hcomp : S.card + (Finset.univ.filter (fun p : Fin N × Fin N => p.1 = p.2)).card = (Finset.univ : Finset (Fin N × Fin N)).card := by have hdisj : Disjoint S (Finset.univ.filter (fun p : Fin N × Fin N => p.1 = p.2)) := by rw [Finset.disjoint_left]; intro p hp1 hp2 exact (Finset.mem_filter.mp hp1).2 (Finset.mem_filter.mp hp2).2 have hunion : S ∪ Finset.univ.filter (fun p : Fin N × Fin N => p.1 = p.2) = Finset.univ := by ext p; simp only [S, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] exact iff_true_intro (ne_or_eq p.1 p.2) rw [← Finset.card_union_of_disjoint hdisj, hunion] have hdiag : (Finset.univ.filter (fun p : Fin N × Fin N => p.1 = p.2)).card = N := by have : Finset.univ.filter (fun p : Fin N × Fin N => p.1 = p.2) = Finset.univ.image (fun i : Fin N => (i, i)) := by ext ⟨a, b⟩; simp [eq_comm] rw [this, Finset.card_image_of_injective _ (fun a b h => (Prod.mk.inj h).1), Finset.card_univ, Fintype.card_fin] have huniv : (Finset.univ : Finset (Fin N × Fin N)).card = N * N := by rw [Finset.card_univ, Fintype.card_prod, Fintype.card_fin] have hSc : S.card + N = N * N := by omega have : (S.card : ℝ) + (N : ℝ) = (N : ℝ) * (N : ℝ) := by exact_mod_cast hSc linarith have hsum_le : ∑ p ∈ S, (1 / 2 : ℝ) * ((A p.1 p.1 - A p.2 p.1) + (A p.2 p.2 - A p.1 p.2)) ≤ (S.card : ℝ) * dobrushinCoeff A := by calc ∑ p ∈ S, (1 / 2 : ℝ) * ((A p.1 p.1 - A p.2 p.1) + (A p.2 p.2 - A p.1 p.2)) ≤ ∑ _p ∈ S, dobrushinCoeff A := Finset.sum_le_sum fun p hp => hpair p.1 p.2 (Finset.mem_filter.mp hp).2 _ = (S.card : ℝ) * dobrushinCoeff A := by rw [Finset.sum_const, nsmul_eq_mul] -- Evaluate the LHS sum over ALL pairs (the diagonal terms i = k vanish!) have hsum_all : ∑ p ∈ S, (1 / 2 : ℝ) * ((A p.1 p.1 - A p.2 p.1) + (A p.2 p.2 - A p.1 p.2)) = ∑ i : Fin N, ∑ k : Fin N, (1 / 2 : ℝ) * ((A i i - A k i) + (A k k - A i k)) := by rw [← Fintype.sum_prod_type'] refine Finset.sum_subset (Finset.filter_subset _ _) fun p _ hp => ?_ have heq : p.1 = p.2 := by by_contra hne; exact hp (Finset.mem_filter.mpr ⟨Finset.mem_univ p, hne⟩) rw [heq]; ring have hsum_eval : ∑ i : Fin N, ∑ k : Fin N, (1 / 2 : ℝ) * ((A i i - A k i) + (A k k - A i k)) = (N : ℝ) * (Matrix.trace A - 1) := by have htr : Matrix.trace A = ∑ i : Fin N, A i i := rfl have hAall : ∑ i : Fin N, ∑ k : Fin N, A i k = (N : ℝ) := by simp only [hA.2, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] have hAall' : ∑ i : Fin N, ∑ k : Fin N, A k i = (N : ℝ) := by rw [Finset.sum_comm]; exact hAall have htr1 : ∑ i : Fin N, ∑ _k : Fin N, A i i = (N : ℝ) * Matrix.trace A := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← Finset.mul_sum, htr] have htr2 : ∑ _i : Fin N, ∑ k : Fin N, A k k = (N : ℝ) * Matrix.trace A := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, htr] calc ∑ i : Fin N, ∑ k : Fin N, (1 / 2 : ℝ) * ((A i i - A k i) + (A k k - A i k)) = (1 / 2 : ℝ) * ((∑ i : Fin N, ∑ _k : Fin N, A i i) - (∑ i : Fin N, ∑ k : Fin N, A k i) + ((∑ _i : Fin N, ∑ k : Fin N, A k k) - (∑ i : Fin N, ∑ k : Fin N, A i k))) := by simp only [← Finset.mul_sum] congr 1 simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] _ = (N : ℝ) * (Matrix.trace A - 1) := by rw [htr1, htr2, hAall, hAall']; ring rw [hsum_all, hsum_eval, hcard] at hsum_le rw [div_le_iff₀ hN1] nlinarith /-- **Theorem 2.5 (Exact Two-Sided Residual Rollout Dobrushin Bounds for ALL `α ∈ [0, 1]`)**: For every `N ≥ 2`, `α ∈ [0, 1]`, and row-stochastic `A`: `(1 - α) + α · (tr(A) - 1)/(N - 1) ≤ τ₁((1 - α) I + α A) ≤ (1 - α) + α · τ₁(A)`. -/ theorem residual_rollout_dobrushin_two_sided {N : ℕ} (hN : 2 ≤ N) {α : ℝ} (hα0 : 0 ≤ α) (hα1 : α ≤ 1) {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : (1 - α) + α * ((Matrix.trace A - 1) / ((N : ℝ) - 1)) ≤ dobrushinCoeff (residualRollout α A) ∧ dobrushinCoeff (residualRollout α A) ≤ (1 - α) + α * dobrushinCoeff A := by have hRst := residualRollout_isRowStochastic hα0 hα1 hA have htrR : Matrix.trace (residualRollout α A) = (1 - α) * (N : ℝ) + α * Matrix.trace A := by simp only [Matrix.trace, Matrix.diag, residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply_eq, smul_eq_mul, mul_one, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← Finset.mul_sum] ring have hlower : (1 - α) + α * ((Matrix.trace A - 1) / ((N : ℝ) - 1)) ≤ dobrushinCoeff (residualRollout α A) := by have hlb := dobrushin_trace_lower_bound hN hRst have hN1 : (N : ℝ) - 1 ≠ 0 := by have : (2 : ℝ) ≤ (N : ℝ) := Nat.ofNat_le_cast.mpr hN; linarith have heq : (Matrix.trace (residualRollout α A) - 1) / ((N : ℝ) - 1) = (1 - α) + α * ((Matrix.trace A - 1) / ((N : ℝ) - 1)) := by rw [htrR]; field_simp [hN1]; ring rwa [heq] at hlb have hupper : dobrushinCoeff (residualRollout α A) ≤ (1 - α) + α * dobrushinCoeff A := by have hNpos : 0 < N := by omega rw [dobrushin_le_iff hNpos] intro i k by_cases hik : i = k · rw [hik] have : rowTV (residualRollout α A k) (residualRollout α A k) = 0 := by unfold rowTV; simp rw [this]; nlinarith [dobrushin_nonneg A] · unfold rowTV have htri : ∑ j : Fin N, |residualRollout α A i j - residualRollout α A k j| ≤ 2 * (1 - α) + α * ∑ j : Fin N, |A i j - A k j| := by calc ∑ j : Fin N, |residualRollout α A i j - residualRollout α A k j| = ∑ j : Fin N, |(1 - α) * ((if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0)) + α * (A i j - A k j)| := by refine Finset.sum_congr rfl fun j _ => ?_ simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul] congr 1; ring _ ≤ ∑ j : Fin N, (|(1 - α) * ((if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0))| + |α * (A i j - A k j)|) := Finset.sum_le_sum fun j _ => abs_add_le _ _ _ = (1 - α) * ∑ j : Fin N, |(if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0)| + α * ∑ j : Fin N, |A i j - A k j| := by rw [Finset.sum_add_distrib, Finset.mul_sum, Finset.mul_sum] congr 1 · refine Finset.sum_congr rfl fun j _ => by rw [abs_mul, abs_of_nonneg (by linarith)] · refine Finset.sum_congr rfl fun j _ => by rw [abs_mul, abs_of_nonneg hα0] _ = 2 * (1 - α) + α * ∑ j : Fin N, |A i j - A k j| := by have h2 : ∑ j : Fin N, |(if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0)| = 2 := by have hsplit : ∑ j : Fin N, |(if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0)| = ∑ j ∈ ({i, k} : Finset (Fin N)), |(if i = j then (1 : ℝ) else 0) - (if k = j then (1 : ℝ) else 0)| := by symm refine Finset.sum_subset (Finset.subset_univ _) fun j _ hj => ?_ simp only [Finset.mem_insert, Finset.mem_singleton, not_or] at hj rw [if_neg (Ne.symm hj.1), if_neg (Ne.symm hj.2), sub_self, abs_zero] rw [hsplit, Finset.sum_pair hik] rw [if_pos rfl, if_neg (Ne.symm hik), if_neg hik, if_pos rfl] norm_num rw [h2]; ring have htvA : (1 / 2 : ℝ) * ∑ j : Fin N, |A i j - A k j| ≤ dobrushinCoeff A := rowTV_le_dobrushin A i k nlinarith exact ⟨hlower, hupper⟩ /-- **Theorem 2.6 (Exact Mutually-Self-Dominant Equality Characterization for ALL `α ∈ (0, 1)`)**: Generalizing Rola (Oct 2026) from `α = 1/2` to ALL `α ∈ (0, 1)`: `τ₁((1 - α) I + α A) = (1 - α) + α · τ₁(A)` if and only if there exists a distinct pair `i ≠ k` achieving `rowTV (A i) (A k) = τ₁(A)` that is mutually self-dominant (`A k i ≤ A i i` and `A i k ≤ A k k`). -/ theorem residual_rollout_equality_iff {N : ℕ} (hN : 2 ≤ N) {α : ℝ} (hα0 : 0 < α) (hα1 : α < 1) {A : Matrix (Fin N) (Fin N) ℝ} (hA : IsRowStochastic A) : dobrushinCoeff (residualRollout α A) = (1 - α) + α * dobrushinCoeff A ↔ ∃ i k : Fin N, i ≠ k ∧ rowTV (A i) (A k) = dobrushinCoeff A ∧ A k i ≤ A i i ∧ A i k ≤ A k k := by have hNpos : 0 < N := by omega have hR_pair_eq : ∀ i k : Fin N, i ≠ k → rowTV (residualRollout α A i) (residualRollout α A k) = (1 / 2 : ℝ) * (|(1 - α) + α * (A i i - A k i)| + |(1 - α) + α * (A k k - A i k)| + α * (∑ j : Fin N, |A i j - A k j| - |A i i - A k i| - |A i k - A k k|)) := by intro i k hik unfold rowTV congr 1 have hsplit : ∀ f : Fin N → ℝ, ∑ j : Fin N, f j = f i + f k + ∑ j ∈ Finset.univ.erase i |>.erase k, f j := by intro f have hk_mem : k ∈ Finset.univ.erase i := Finset.mem_erase.mpr ⟨hik.symm, Finset.mem_univ k⟩ rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i), ← Finset.add_sum_erase _ _ hk_mem] ring rw [hsplit (fun j => |residualRollout α A i j - residualRollout α A k j|), hsplit (fun j => |A i j - A k j|)] have hi : residualRollout α A i i - residualRollout α A k i = (1 - α) + α * (A i i - A k i) := by simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ↓reduceIte, if_neg (Ne.symm hik)]; ring have hk : |residualRollout α A i k - residualRollout α A k k| = |(1 - α) + α * (A k k - A i k)| := by rw [abs_sub_comm] congr 1 simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ↓reduceIte, if_neg hik]; ring have hrest : ∑ j ∈ (Finset.univ.erase i).erase k, |residualRollout α A i j - residualRollout α A k j| = α * ∑ j ∈ (Finset.univ.erase i).erase k, |A i j - A k j| := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun j hj => ?_ have hjk : j ≠ k := (Finset.mem_erase.mp hj).1 have hji : j ≠ i := (Finset.mem_erase.mp (Finset.mem_erase.mp hj).2).1 simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, if_neg hji.symm, if_neg hjk.symm] rw [show (1 - α) * 0 + α * A i j - ((1 - α) * 0 + α * A k j) = α * (A i j - A k j) by ring, abs_mul, abs_of_pos hα0] rw [hi, hk, hrest]; ring constructor · intro heq -- Obtain the pair (i, k) achieving the Finset.sup' in dobrushinCoeff (residualRollout α A) have hne : (Finset.univ : Finset (Fin N × Fin N)).Nonempty := ⟨(⟨0, hNpos⟩, ⟨0, hNpos⟩), Finset.mem_univ _⟩ obtain ⟨⟨i, k⟩, _, hmax⟩ := Finset.exists_mem_eq_sup' hne (fun ik : Fin N × Fin N => rowTV (residualRollout α A ik.1) (residualRollout α A ik.2)) have hRik : rowTV (residualRollout α A i) (residualRollout α A k) = (1 - α) + α * dobrushinCoeff A := by have hdef : dobrushinCoeff (residualRollout α A) = Finset.sup' Finset.univ hne (fun ik => rowTV (residualRollout α A ik.1) (residualRollout α A ik.2)) := by unfold dobrushinCoeff; rw [dif_pos hNpos] linarith [hdef, hmax, heq] have hik : i ≠ k := by intro h; rw [h] at hRik have hz : rowTV (residualRollout α A k) (residualRollout α A k) = 0 := by unfold rowTV; simp rw [hz] at hRik; nlinarith [dobrushin_nonneg A] have hform := hR_pair_eq i k hik have h1 : |(1 - α) + α * (A i i - A k i)| ≤ (1 - α) + α * |A i i - A k i| := by calc |(1 - α) + α * (A i i - A k i)| ≤ |1 - α| + |α * (A i i - A k i)| := abs_add_le _ _ _ = (1 - α) + α * |A i i - A k i| := by rw [abs_of_pos (by linarith), abs_mul, abs_of_pos hα0] have h2 : |(1 - α) + α * (A k k - A i k)| ≤ (1 - α) + α * |A i k - A k k| := by calc |(1 - α) + α * (A k k - A i k)| ≤ |1 - α| + |α * (A k k - A i k)| := abs_add_le _ _ _ = (1 - α) + α * |A i k - A k k| := by rw [abs_of_pos (by linarith), abs_mul, abs_of_pos hα0, abs_sub_comm] have htv_le : rowTV (A i) (A k) ≤ dobrushinCoeff A := rowTV_le_dobrushin A i k have htv_eq : rowTV (A i) (A k) = dobrushinCoeff A := by unfold rowTV at htv_le ⊢ nlinarith have heq1 : |(1 - α) + α * (A i i - A k i)| = (1 - α) + α * |A i i - A k i| := by unfold rowTV at htv_eq; nlinarith have heq2 : |(1 - α) + α * (A k k - A i k)| = (1 - α) + α * |A i k - A k k| := by unfold rowTV at htv_eq; nlinarith have hdom1 : A k i ≤ A i i := by by_contra hlt; push Not at hlt have hneg : A i i - A k i < 0 := by linarith rw [abs_of_neg hneg] at heq1 rcases le_or_gt 0 ((1 - α) + α * (A i i - A k i)) with hp | hn · rw [abs_of_nonneg hp] at heq1; nlinarith · rw [abs_of_neg hn] at heq1; nlinarith have hdom2 : A i k ≤ A k k := by by_contra hlt; push Not at hlt have hneg : A k k - A i k < 0 := by linarith rw [abs_sub_comm, abs_of_neg hneg] at heq2 rcases le_or_gt 0 ((1 - α) + α * (A k k - A i k)) with hp | hn · rw [abs_of_nonneg hp] at heq2; nlinarith · rw [abs_of_neg hn] at heq2; nlinarith exact ⟨i, k, hik, htv_eq, hdom1, hdom2⟩ · rintro ⟨i, k, hik, htv_eq, hdom1, hdom2⟩ refine le_antisymm (residual_rollout_dobrushin_two_sided hN hα0.le hα1.le hA).2 ?_ refine le_trans ?_ (rowTV_le_dobrushin (residualRollout α A) i k) rw [hR_pair_eq i k hik] have h1 : |(1 - α) + α * (A i i - A k i)| = (1 - α) + α * |A i i - A k i| := by rw [abs_of_nonneg (by nlinarith), abs_of_nonneg (by linarith)] have h2 : |(1 - α) + α * (A k k - A i k)| = (1 - α) + α * |A i k - A k k| := by rw [abs_of_nonneg (by nlinarith), abs_sub_comm, abs_of_nonneg (by linarith)] rw [h1, h2] unfold rowTV at htv_eq nlinarith /-- **Theorem 2.7 (PSD Doubly-Stochastic Residual Anti-Collapse vs. Non-PSD 1-Step Annihilation)**: (1) If `P` is doubly stochastic and positive-semidefinite on centered vectors (`∑_i ⟨u_i, (P u)_i⟩ ≥ 0`), then for EVERY `α ∈ [0, 1]`, `tokenVariance ((1 - α) X + α P X) ≥ (1 - α)² · tokenVariance X`. (2) By contrast, for the non-PSD doubly stochastic swap matrix `P = [[0,1],[1,0]]` at `α = 1/2`, `tokenVariance (R_{1/2}(P) X) = 0` in ONE layer even though `tokenVariance X > 0`! -/ theorem psd_residual_variance_lower_bound {N d : ℕ} (hN : 0 < N) {α : ℝ} (hα0 : 0 ≤ α) (hα1 : α ≤ 1) {P : Matrix (Fin N) (Fin N) ℝ} (hP : IsDoublyStochastic P) (hPSD : ∀ u : Fin N → (Fin d → ℝ), 0 ≤ ∑ i : Fin N, dotProd (u i) (applyAttn P u i)) (X : Fin N → (Fin d → ℝ)) : (1 - α) ^ 2 * tokenVariance X ≤ tokenVariance (applyAttn (residualRollout α P) X) := by have hRds : IsDoublyStochastic (residualRollout α P) := by refine ⟨residualRollout_isRowStochastic hα0 hα1 hP.1, fun j => ?_⟩ simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, Finset.sum_add_distrib, ← Finset.mul_sum, hP.2 j, mul_one] have : ∑ i : Fin N, (if i = j then (1 : ℝ) else 0) = 1 := by simp [Finset.sum_ite_eq'] rw [this]; ring have hmean := doubly_stochastic_mean_conservation hRds X set μ := tokenMean X let u : Fin N → (Fin d → ℝ) := fun i => X i - μ have hRu : ∀ i, applyAttn (residualRollout α P) X i - μ = (1 - α) • u i + α • applyAttn P u i := by intro i; ext c simp only [applyAttn, residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, Pi.sub_apply, Pi.add_apply, Pi.smul_apply, u] have h1 : ∑ j : Fin N, ((1 - α) * (if i = j then (1 : ℝ) else 0) + α * P i j) * X j c = (1 - α) * X i c + α * ∑ j : Fin N, P i j * X j c := by simp only [add_mul, Finset.sum_add_distrib, mul_assoc, ← Finset.mul_sum] congr 1 have : ∑ j : Fin N, (if i = j then (1 : ℝ) else 0) * X j c = X i c := by simp [Finset.sum_ite_eq] rw [this] have h2 : ∑ j : Fin N, P i j * (X j c - μ c) = (∑ j : Fin N, P i j * X j c) - μ c := by simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hP.1.2 i, one_mul] rw [h1, h2]; ring unfold tokenVariance rw [hmean] have hNpos : (0 : ℝ) < N := Nat.cast_pos.mpr hN rw [mul_left_comm] apply mul_le_mul_of_nonneg_left _ (by positivity) have hexp : ∑ i : Fin N, sqNorm (applyAttn (residualRollout α P) X i - μ) = (1 - α) ^ 2 * ∑ i : Fin N, sqNorm (u i) + 2 * (1 - α) * α * ∑ i : Fin N, dotProd (u i) (applyAttn P u i) + α ^ 2 * ∑ i : Fin N, sqNorm (applyAttn P u i) := by simp only [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun i _ => ?_ rw [hRu i] simp only [sqNorm, dotProd, Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl fun c _ => by ring rw [hexp] have h2 : 0 ≤ 2 * (1 - α) * α * ∑ i : Fin N, dotProd (u i) (applyAttn P u i) := mul_nonneg (by nlinarith) (hPSD u) have h3 : 0 ≤ α ^ 2 * ∑ i : Fin N, sqNorm (applyAttn P u i) := mul_nonneg (sq_nonneg _) (Finset.sum_nonneg fun i _ => sqNorm_nonneg _) linarith theorem non_psd_swap_rollout_annihilates_variance : let P : Matrix (Fin 2) (Fin 2) ℝ := fun i j => if i = j then 0 else 1 let X : Fin 2 → (Fin 1 → ℝ) := fun i _ => if i = 0 then 1 else -1 IsDoublyStochastic P ∧ tokenVariance X = 1 ∧ tokenVariance (applyAttn (residualRollout (1 / 2) P) X) = 0 := by intro P X refine ⟨⟨⟨?_, ?_⟩, ?_⟩, ?_, ?_⟩ · intro i j; fin_cases i <;> fin_cases j <;> simp [P] · intro i; fin_cases i <;> simp [P, Fin.sum_univ_two] · intro j; fin_cases j <;> simp [P, Fin.sum_univ_two] · unfold tokenVariance tokenMean sqNorm dotProd simp [X, Fin.sum_univ_two]; norm_num · have hR : ∀ i j : Fin 2, residualRollout (1 / 2) P i j = 1 / 2 := by intro i j simp only [residualRollout, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul] fin_cases i <;> fin_cases j <;> simp [P] <;> norm_num have hzero : applyAttn (residualRollout (1 / 2) P) X = fun _ _ => 0 := by ext i c fin_cases c unfold applyAttn rw [Fin.sum_univ_two, hR i 0, hR i 1] simp [X] rw [hzero] unfold tokenVariance tokenMean sqNorm dotProd simp /-! ### Exact Causal-Mask Uniform Attention Spectrum & `Ω(log N)` Non-Normal Metastability Barrier -/ /-- Uniform causal attention matrix `(C_N)_{ij} = 1/(i+1)` if `j ≤ i`, else `0`. -/ noncomputable def causalUniformAttn (N : ℕ) : Matrix (Fin N) (Fin N) ℝ := fun i j => if j.val ≤ i.val then 1 / ((i.val : ℝ) + 1) else 0 lemma causalUniformAttn_isRowStochastic (N : ℕ) : IsRowStochastic (causalUniformAttn N) := by refine ⟨fun i j => ?_, fun i => ?_⟩ · unfold causalUniformAttn; split_ifs <;> positivity · unfold causalUniformAttn have hcard : (Finset.univ.filter (fun j : Fin N => j.val ≤ i.val)).card = i.val + 1 := by have : Finset.univ.filter (fun j : Fin N => j.val ≤ i.val) = (Finset.range (i.val + 1)).attach.image (fun x => ⟨x.1, lt_of_lt_of_le (Finset.mem_range.mp x.2) i.isLt⟩) := by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image, Finset.mem_attach, Subtype.exists, Finset.mem_range] constructor · intro h; exact ⟨j.val, Nat.lt_succ_of_le h, Fin.ext rfl⟩ · rintro ⟨a, ha, hja⟩; have : j.val = a := congrArg Fin.val hja.symm; omega rw [this, Finset.card_image_of_injective _ (fun a b h => Subtype.ext (congrArg Fin.val h)), Finset.card_attach, Finset.card_range] rw [Finset.sum_ite, Finset.sum_const_zero, add_zero, Finset.sum_const, hcard, nsmul_eq_mul] push_cast exact mul_one_div_cancel (by positivity) /-- **Theorem 2.8 (Exact 1-Step Dobrushin Coefficient of Uniform Causal Attention)**: `τ₁(C_N) = 1 - 1/N` for every `N ≥ 1` (contrasting with `τ₁ = 0` for uniform bidirectional attention!). -/ theorem causal_uniform_dobrushin_exact (N : ℕ) (hN : 0 < N) : dobrushinCoeff (causalUniformAttn N) = 1 - 1 / (N : ℝ) := by have hst := causalUniformAttn_isRowStochastic N refine le_antisymm ?_ ?_ · rw [dobrushin_le_iff hN] intro i k have htv := (dobrushin_tv_eq_one_sub_min _ _ (hst.1 i) (hst.1 k) (hst.2 i) (hst.2 k)).1 rw [htv] have h0 : min (causalUniformAttn N i ⟨0, hN⟩) (causalUniformAttn N k ⟨0, hN⟩) ≤ ∑ j : Fin N, min (causalUniformAttn N i j) (causalUniformAttn N k j) := Finset.single_le_sum (fun j _ => le_min (hst.1 i j) (hst.1 k j)) (Finset.mem_univ _) have hmin0 : 1 / (N : ℝ) ≤ min (causalUniformAttn N i ⟨0, hN⟩) (causalUniformAttn N k ⟨0, hN⟩) := by simp only [causalUniformAttn, Nat.zero_le, ↓reduceIte, le_min_iff] constructor · exact one_div_le_one_div_of_le (by positivity) (by exact_mod_cast i.isLt) · exact one_div_le_one_div_of_le (by positivity) (by exact_mod_cast k.isLt) linarith · refine le_trans ?_ (rowTV_le_dobrushin (causalUniformAttn N) ⟨0, hN⟩ ⟨N - 1, by omega⟩) have htv := (dobrushin_tv_eq_one_sub_min _ _ (hst.1 ⟨0, hN⟩) (hst.1 ⟨N - 1, by omega⟩) (hst.2 ⟨0, hN⟩) (hst.2 ⟨N - 1, by omega⟩)).1 rw [htv] have hsum : ∑ j : Fin N, min (causalUniformAttn N ⟨0, hN⟩ j) (causalUniformAttn N ⟨N - 1, by omega⟩ j) = 1 / (N : ℝ) := by have honly : ∀ j : Fin N, j ≠ ⟨0, hN⟩ → min (causalUniformAttn N ⟨0, hN⟩ j) (causalUniformAttn N ⟨N - 1, by omega⟩ j) = 0 := by intro j hj have hpos : ¬ (j.val ≤ 0) := by intro h; apply hj; ext; exact Nat.eq_zero_of_le_zero h have h0 : causalUniformAttn N ⟨0, hN⟩ j = 0 := by unfold causalUniformAttn; exact if_neg hpos rw [h0, min_eq_left (hst.1 ⟨N - 1, by omega⟩ j)] rw [Finset.sum_eq_single ⟨0, hN⟩ (fun j _ hj => honly j hj) (fun h => absurd (Finset.mem_univ _) h)] simp only [causalUniformAttn, Nat.zero_le, ↓reduceIte, Nat.cast_zero, zero_add, div_one] have hNcast : ((N - 1 : ℕ) : ℝ) + 1 = (N : ℝ) := by rw [Nat.cast_sub (by omega : 1 ≤ N), Nat.cast_one]; ring have hle1 : 1 / (N : ℝ) ≤ 1 := (div_le_one (Nat.cast_pos.mpr hN)).mpr (Nat.one_le_cast.mpr hN) rw [hNcast, min_eq_right hle1] rw [hsum] /-- Hockey-stick identity `∑_{j=0}^k C(j, m) = C(k+1, m+1)`. -/ lemma sum_range_choose_eq (k m : ℕ) : ∑ j ∈ Finset.range (k + 1), j.choose m = (k + 1).choose (m + 1) := by induction k with | zero => cases m with | zero => simp | succ m => simp [Nat.choose_eq_zero_of_lt (by omega : 0 < m + 1), Nat.choose_eq_zero_of_lt (by omega : 1 < m + 2)] | succ k ih => rw [Finset.sum_range_succ, ih, add_comm, ← Nat.choose_succ_succ] /-- **Theorem 2.9 (Complete Exact Binomial Eigenbasis of Uniform Causal Attention)**: For every `N ≥ 1` and every `m < N`, the binomial vector `v_k^(m) = C(k, m)` is an EXACT eigenvector of `C_N` with eigenvalue `1 / (m + 1)`: `(C_N v^(m))_k = (1 / (m + 1)) · v_k^(m)`. -/ theorem causal_uniform_binomial_eigenvalue (N m : ℕ) (k : Fin N) : let v : Fin N → ℝ := fun j => (j.val.choose m : ℝ) (causalUniformAttn N).mulVec v k = (1 / ((m : ℝ) + 1)) * v k := by intro v rw [Matrix.mulVec, dotProduct] simp only [causalUniformAttn, v, ite_mul, zero_mul] have hsum : ∑ j : Fin N, (if j.val ≤ k.val then 1 / ((k.val : ℝ) + 1) * (j.val.choose m : ℝ) else 0) = (1 / ((k.val : ℝ) + 1)) * ∑ j ∈ Finset.range (k.val + 1), (j.choose m : ℝ) := by rw [Finset.mul_sum] rw [Finset.sum_ite, Finset.sum_const_zero, add_zero] symm refine Finset.sum_bij (fun j hj => ⟨j, lt_of_lt_of_le (Finset.mem_range.mp hj) k.isLt⟩) (fun j hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, Nat.lt_succ_iff.mp (Finset.mem_range.mp hj)⟩) (fun a _ b _ h => congrArg Fin.val h) (fun b hb => ⟨b.val, Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hb).2), Fin.ext rfl⟩) (fun j _ => rfl) rw [hsum, ← Nat.cast_sum, sum_range_choose_eq] have habs : (k.val + 1) * k.val.choose m = (m + 1) * (k.val + 1).choose (m + 1) := by have := Nat.add_one_mul_choose_eq k.val m linarith have hcast : ((k.val : ℝ) + 1) * (k.val.choose m : ℝ) = ((m : ℝ) + 1) * ((k.val + 1).choose (m + 1) : ℝ) := by exact_mod_cast habs have hk0 : (k.val : ℝ) + 1 ≠ 0 := by positivity have hm0 : (m : ℝ) + 1 ≠ 0 := by positivity field_simp [hk0, hm0] linarith /-- Harmonic number `H_n = ∑_{j=0}^{n-1} 1/(j+1)`. -/ noncomputable def harmonicReal (n : ℕ) : ℝ := ∑ j ∈ Finset.range n, (1 / ((j : ℝ) + 1)) lemma harmonicReal_nonneg (n : ℕ) : 0 ≤ harmonicReal n := Finset.sum_nonneg fun _ _ => by positivity lemma harmonicReal_mono {a b : ℕ} (hab : a ≤ b) : harmonicReal a ≤ harmonicReal b := Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono hab) fun _ _ _ => by positivity /-- Causal preservation of row 0 under powers of `C_N`: `(C_N^L)_{0, j} = δ_{0, j}`. -/ lemma causalUniformAttn_pow_row_zero (N : ℕ) (hN : 0 < N) : ∀ L : ℕ, ∀ j : Fin N, ((causalUniformAttn N) ^ L) ⟨0, hN⟩ j = if j.val = 0 then 1 else 0 := by intro L induction L with | zero => intro j simp only [pow_zero, Matrix.one_apply] by_cases hj : j.val = 0 · have hjeq : (⟨0, hN⟩ : Fin N) = j := Fin.ext hj.symm rw [if_pos hjeq, if_pos hj] · have hjne : (⟨0, hN⟩ : Fin N) ≠ j := fun h => hj (congrArg Fin.val h).symm rw [if_neg hjne, if_neg hj] | succ L ih => intro j rw [pow_succ', Matrix.mul_apply] have h0 : ∀ r : Fin N, r ≠ ⟨0, hN⟩ → causalUniformAttn N ⟨0, hN⟩ r = 0 := by intro r hr unfold causalUniformAttn rw [if_neg]; intro hle; apply hr; ext; exact Nat.eq_zero_of_le_zero hle rw [Finset.sum_eq_single ⟨0, hN⟩ (fun r _ hr => by rw [h0 r hr, zero_mul]) (fun h => absurd (Finset.mem_univ _) h)] have hdiag : causalUniformAttn N ⟨0, hN⟩ ⟨0, hN⟩ = 1 := by unfold causalUniformAttn; simp rw [hdiag, one_mul, ih j] lemma causalUniformAttn_pow_isRowStochastic (N : ℕ) : ∀ L : ℕ, IsRowStochastic ((causalUniformAttn N) ^ L) := by intro L induction L with | zero => refine ⟨fun i j => ?_, fun i => ?_⟩ · simp only [pow_zero, Matrix.one_apply]; split_ifs <;> norm_num · simp [pow_zero, Matrix.one_apply] | succ L ih => rw [pow_succ'] exact isRowStochastic_mul (causalUniformAttn_isRowStochastic N) ih /-- Lower bound `1 - (C_N^L)_{N-1, 0} ≤ τ₁(C_N^L)` for any `L ≥ 1`. -/ lemma causalUniformAttn_pow_dobrushin_ge (N : ℕ) (hN : 0 < N) (L : ℕ) : 1 - ((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ ⟨0, hN⟩ ≤ dobrushinCoeff ((causalUniformAttn N) ^ L) := by have hst := causalUniformAttn_pow_isRowStochastic N L refine le_trans ?_ (rowTV_le_dobrushin ((causalUniformAttn N) ^ L) ⟨0, hN⟩ ⟨N - 1, by omega⟩) have htv := (dobrushin_tv_eq_one_sub_min _ _ (hst.1 ⟨0, hN⟩) (hst.1 ⟨N - 1, by omega⟩) (hst.2 ⟨0, hN⟩) (hst.2 ⟨N - 1, by omega⟩)).1 rw [htv] have hsum : ∑ j : Fin N, min (((causalUniformAttn N) ^ L) ⟨0, hN⟩ j) (((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ j) = ((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ ⟨0, hN⟩ := by have honly : ∀ j : Fin N, j ≠ ⟨0, hN⟩ → min (((causalUniformAttn N) ^ L) ⟨0, hN⟩ j) (((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ j) = 0 := by intro j hj rw [causalUniformAttn_pow_row_zero N hN L j, if_neg (fun h => hj (Fin.ext h)), min_eq_left (hst.1 ⟨N - 1, by omega⟩ j)] rw [Finset.sum_eq_single ⟨0, hN⟩ (fun j _ hj => honly j hj) (fun h => absurd (Finset.mem_univ _) h)] rw [causalUniformAttn_pow_row_zero N hN L ⟨0, hN⟩, if_pos rfl] have hle1 : ((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ ⟨0, hN⟩ ≤ 1 := by rw [← hst.2 ⟨N - 1, by omega⟩] exact Finset.single_le_sum (fun j _ => hst.1 ⟨N - 1, by omega⟩ j) (Finset.mem_univ _) exact min_eq_right hle1 rw [hsum] /-- **Theorem 2.10 (Exact `L`-Layer Harmonic Plateau for Causal Attention)**: For every `N ≥ 1` and `L ≥ 1`, `(C_N^L)_{i, 0} ≤ H_{i+1}^(L-1) / (i + 1)` and hence `τ₁(C_N^L) ≥ 1 - H_N^(L-1) / N`. -/ theorem causal_uniform_harmonic_plateau (N : ℕ) (hN : 0 < N) (L : ℕ) (hL : 1 ≤ L) : (∀ i : Fin N, ((causalUniformAttn N) ^ L) i ⟨0, hN⟩ ≤ harmonicReal (i.val + 1) ^ (L - 1) / ((i.val : ℝ) + 1)) ∧ 1 - harmonicReal N ^ (L - 1) / (N : ℝ) ≤ dobrushinCoeff ((causalUniformAttn N) ^ L) := by have hmain : ∀ k : ℕ, ∀ i : Fin N, ((causalUniformAttn N) ^ (k + 1)) i ⟨0, hN⟩ ≤ harmonicReal (i.val + 1) ^ k / ((i.val : ℝ) + 1) := by intro k induction k with | zero => intro i simp only [zero_add, pow_one, pow_zero, causalUniformAttn, Nat.zero_le, ↓reduceIte, le_rfl] | succ k ih => intro i rw [pow_succ', Matrix.mul_apply] calc ∑ j : Fin N, causalUniformAttn N i j * ((causalUniformAttn N) ^ (k + 1)) j ⟨0, hN⟩ ≤ ∑ j : Fin N, causalUniformAttn N i j * (harmonicReal (j.val + 1) ^ k / ((j.val : ℝ) + 1)) := by refine Finset.sum_le_sum fun j _ => mul_le_mul_of_nonneg_left (ih j) ((causalUniformAttn_isRowStochastic N).1 i j) _ ≤ ∑ j : Fin N, causalUniformAttn N i j * (harmonicReal (i.val + 1) ^ k / ((j.val : ℝ) + 1)) := by refine Finset.sum_le_sum fun j _ => ?_ unfold causalUniformAttn split_ifs with hji · refine mul_le_mul_of_nonneg_left ?_ (by positivity) exact div_le_div_of_nonneg_right (pow_le_pow_left₀ (harmonicReal_nonneg _) (harmonicReal_mono (Nat.succ_le_succ hji)) k) (by positivity) · simp _ = (harmonicReal (i.val + 1) ^ k / ((i.val : ℝ) + 1)) * harmonicReal (i.val + 1) := by have h1 : ∑ j : Fin N, causalUniformAttn N i j * (harmonicReal (i.val + 1) ^ k / ((j.val : ℝ) + 1)) = (harmonicReal (i.val + 1) ^ k / ((i.val : ℝ) + 1)) * ∑ j : Fin N, (if j.val ≤ i.val then 1 / ((j.val : ℝ) + 1) else 0) := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun j _ => ?_ unfold causalUniformAttn; split_ifs <;> ring rw [h1] congr 1 rw [Finset.sum_ite, Finset.sum_const_zero, add_zero] unfold harmonicReal symm refine Finset.sum_bij (fun j hj => ⟨j, lt_of_lt_of_le (Finset.mem_range.mp hj) i.isLt⟩) (fun j hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, Nat.lt_succ_iff.mp (Finset.mem_range.mp hj)⟩) (fun a _ b _ h => congrArg Fin.val h) (fun b hb => ⟨b.val, Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hb).2), Fin.ext rfl⟩) (fun j _ => rfl) _ = harmonicReal (i.val + 1) ^ (k + 1) / ((i.val : ℝ) + 1) := by rw [pow_succ]; ring obtain ⟨k, rfl⟩ : ∃ k, L = k + 1 := ⟨L - 1, by omega⟩ have h1 := hmain k simp only [Nat.add_sub_cancel] at h1 ⊢ refine ⟨h1, ?_⟩ have hlast := h1 ⟨N - 1, by omega⟩ have hNcast : ((N - 1 : ℕ) : ℝ) + 1 = (N : ℝ) := by rw [Nat.cast_sub (by omega : 1 ≤ N), Nat.cast_one]; ring have hNnat : N - 1 + 1 = N := by omega rw [hNnat, hNcast] at hlast linarith [causalUniformAttn_pow_dobrushin_ge N hN (k + 1)] /-- Product `∏_{m=1}^n (2m / (2m - 1)) ≤ 2 √n` for every `n ≥ 1`. -/ lemma wallis_prod_le_two_sqrt (n : ℕ) (hn : 1 ≤ n) : ∏ m ∈ Finset.range n, ((2 * ((m : ℝ) + 1)) / (2 * ((m : ℝ) + 1) - 1)) ≤ 2 * Real.sqrt n := by induction n, hn using Nat.le_induction with | base => simp only [Finset.range_one, Finset.prod_singleton, Nat.cast_zero, zero_add, Nat.cast_one, Real.sqrt_one] norm_num | succ k hk ih => rw [Finset.prod_range_succ] have hkpos : (0 : ℝ) < k := Nat.cast_pos.mpr (by omega) have hden_pos : (0 : ℝ) < 2 * ((k : ℝ) + 1) - 1 := by linarith have hfac_pos : 0 < (2 * ((k : ℝ) + 1)) / (2 * ((k : ℝ) + 1) - 1) := div_pos (by linarith) hden_pos calc (∏ m ∈ Finset.range k, (2 * ((m : ℝ) + 1)) / (2 * ((m : ℝ) + 1) - 1)) * ((2 * ((k : ℝ) + 1)) / (2 * ((k : ℝ) + 1) - 1)) ≤ (2 * Real.sqrt k) * ((2 * ((k : ℝ) + 1)) / (2 * ((k : ℝ) + 1) - 1)) := mul_le_mul_of_nonneg_right ih hfac_pos.le _ ≤ 2 * Real.sqrt ((k + 1 : ℕ) : ℝ) := by have hsq : ((2 * Real.sqrt k) * ((2 * ((k : ℝ) + 1)) / (2 * ((k : ℝ) + 1) - 1))) ^ 2 ≤ (2 * Real.sqrt ((k + 1 : ℕ) : ℝ)) ^ 2 := by rw [mul_pow, mul_pow, mul_pow, div_pow, Real.sq_sqrt hkpos.le, Real.sq_sqrt (by positivity : (0 : ℝ) ≤ ((k + 1 : ℕ) : ℝ))] push_cast rw [mul_div_assoc', div_le_iff₀ (pow_pos hden_pos 2)] nlinarith have hnn : 0 ≤ 2 * Real.sqrt ((k + 1 : ℕ) : ℝ) := by positivity nlinarith [sq_nonneg (2 * Real.sqrt ((k + 1 : ℕ) : ℝ) - (2 * Real.sqrt k) * ((2 * ((k : ℝ) + 1)) / (2 * ((k : ℝ) + 1) - 1)))] /-- **Theorem 2.11 (Exact `Ω(log N)` Non-Normal Causal Metastability Barrier)**: Via the exact generating-function weight `∏_{m=1}^{i+1} 1/(1 - 1/(2m))`, for EVERY `N ≥ 1` and EVERY `L ≥ 1`: `(C_N^L)_{N-1, 0} ≤ 2^L / √N`, hence `τ₁(C_N^L) ≥ 1 - 2^L / √N`! In particular, achieving `τ₁(C_N^L) ≤ 1/2` requires `2^(L+1) ≥ √N` (i.e. `L = Ω(log N)`), despite every nontrivial eigenvalue of `C_N` being `≤ 1/2`! -/ theorem causal_uniform_log_depth_barrier (N : ℕ) (hN : 0 < N) (L : ℕ) (hL : 1 ≤ L) : ((causalUniformAttn N) ^ L) ⟨N - 1, by omega⟩ ⟨0, hN⟩ ≤ (2 : ℝ) ^ L / Real.sqrt N ∧ 1 - (2 : ℝ) ^ L / Real.sqrt N ≤ dobrushinCoeff ((causalUniformAttn N) ^ L) := by -- Define W(n) = ∏_{m=0}^{n-1} (2(m+1)) / (2(m+1) - 1) let W : ℕ → ℝ := fun n => ∏ m ∈ Finset.range n, ((2 * ((m : ℝ) + 1)) / (2 * ((m : ℝ) + 1) - 1)) -- Key telescoping identity: ∑_{j=0}^{i} W(j+1) / (j+1) = 2 * (W(i+1) - 1) ≤ 2 * W(i+1) have hWsum : ∀ n : ℕ, ∑ j ∈ Finset.range (n + 1), W (j + 1) / ((j : ℝ) + 1) ≤ 2 * W (n + 1) := by intro n induction n with | zero => simp only [Finset.range_one, Finset.sum_singleton, Nat.cast_zero, zero_add, div_one, W] norm_num | succ n ih => rw [Finset.sum_range_succ] have hrec : W (n + 2) = W (n + 1) * ((2 * ((n : ℝ) + 2)) / (2 * ((n : ℝ) + 2) - 1)) := by simp only [W, Finset.prod_range_succ]; push_cast; ring_nf have hden : (0 : ℝ) < 2 * ((n : ℝ) + 2) - 1 := by linarith [Nat.cast_nonneg (α := ℝ) n] have hstep : 2 * W (n + 1) + W (n + 2) / (((n + 1 : ℕ) : ℝ) + 1) = 2 * W (n + 2) := by rw [hrec] have hcast : ((n + 1 : ℕ) : ℝ) + 1 = (n : ℝ) + 2 := by push_cast; ring rw [hcast] field_simp [hden.ne', (by positivity : (n : ℝ) + 2 ≠ 0)] ring linarith -- Induction on k: (C_N^(k+1))_{i, 0} ≤ 2^k * W(i+1) / (i+1) have hbound : ∀ k : ℕ, ∀ i : Fin N, ((causalUniformAttn N) ^ (k + 1)) i ⟨0, hN⟩ ≤ (2 : ℝ) ^ k * W (i.val + 1) / ((i.val : ℝ) + 1) := by intro k induction k with | zero => intro i simp only [zero_add, pow_one, pow_zero, one_mul, causalUniformAttn, Nat.zero_le, ↓reduceIte] have hW1 : 1 ≤ W (i.val + 1) := by have : 1 = ∏ _m ∈ Finset.range (i.val + 1), (1 : ℝ) := by simp rw [this] refine Finset.prod_le_prod (fun _ _ => by norm_num) fun m _ => ?_ have hdm : (0 : ℝ) < 2 * ((m : ℝ) + 1) - 1 := by linarith [Nat.cast_nonneg (α := ℝ) m] rw [one_le_div hdm]; linarith exact div_le_div_of_nonneg_right hW1 (by positivity) | succ k ih => intro i rw [pow_succ', Matrix.mul_apply] calc ∑ j : Fin N, causalUniformAttn N i j * ((causalUniformAttn N) ^ (k + 1)) j ⟨0, hN⟩ ≤ ∑ j : Fin N, causalUniformAttn N i j * ((2 : ℝ) ^ k * W (j.val + 1) / ((j.val : ℝ) + 1)) := Finset.sum_le_sum fun j _ => mul_le_mul_of_nonneg_left (ih j) ((causalUniformAttn_isRowStochastic N).1 i j) _ = ((2 : ℝ) ^ k / ((i.val : ℝ) + 1)) * ∑ j ∈ Finset.range (i.val + 1), W (j + 1) / ((j : ℝ) + 1) := by have h1 : ∑ j : Fin N, causalUniformAttn N i j * ((2 : ℝ) ^ k * W (j.val + 1) / ((j.val : ℝ) + 1)) = ((2 : ℝ) ^ k / ((i.val : ℝ) + 1)) * ∑ j : Fin N, (if j.val ≤ i.val then W (j.val + 1) / ((j.val : ℝ) + 1) else 0) := by rw [Finset.mul_sum]; refine Finset.sum_congr rfl fun j _ => ?_ unfold causalUniformAttn; split_ifs <;> ring rw [h1]; congr 1 rw [Finset.sum_ite, Finset.sum_const_zero, add_zero] symm refine Finset.sum_bij (fun j hj => ⟨j, lt_of_lt_of_le (Finset.mem_range.mp hj) i.isLt⟩) (fun j hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, Nat.lt_succ_iff.mp (Finset.mem_range.mp hj)⟩) (fun a _ b _ h => congrArg Fin.val h) (fun b hb => ⟨b.val, Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hb).2), Fin.ext rfl⟩) (fun j _ => rfl) _ ≤ ((2 : ℝ) ^ k / ((i.val : ℝ) + 1)) * (2 * W (i.val + 1)) := mul_le_mul_of_nonneg_left (hWsum i.val) (by positivity) _ = (2 : ℝ) ^ (k + 1) * W (i.val + 1) / ((i.val : ℝ) + 1) := by rw [pow_succ]; ring obtain ⟨k, rfl⟩ : ∃ k, L = k + 1 := ⟨L - 1, by omega⟩ have hlast := hbound k ⟨N - 1, by omega⟩ have hNcast : ((N - 1 : ℕ) : ℝ) + 1 = (N : ℝ) := by rw [Nat.cast_sub (by omega : 1 ≤ N), Nat.cast_one]; ring have hNnat : N - 1 + 1 = N := by omega rw [hNnat, hNcast] at hlast have hwallis : W N ≤ 2 * Real.sqrt N := wallis_prod_le_two_sqrt N hN have hNpos : (0 : ℝ) < N := Nat.cast_pos.mpr hN have hsqrt_pos : 0 < Real.sqrt N := Real.sqrt_pos.mpr hNpos have hfinal : ((causalUniformAttn N) ^ (k + 1)) ⟨N - 1, by omega⟩ ⟨0, hN⟩ ≤ (2 : ℝ) ^ (k + 1) / Real.sqrt N := by calc ((causalUniformAttn N) ^ (k + 1)) ⟨N - 1, by omega⟩ ⟨0, hN⟩ ≤ (2 : ℝ) ^ k * W N / (N : ℝ) := hlast _ ≤ (2 : ℝ) ^ k * (2 * Real.sqrt N) / (N : ℝ) := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hwallis (by positivity)) hNpos.le _ = (2 : ℝ) ^ (k + 1) / Real.sqrt N := by have hsq : Real.sqrt N * Real.sqrt N = (N : ℝ) := Real.mul_self_sqrt hNpos.le rw [pow_succ] field_simp [hsqrt_pos.ne', hNpos.ne'] nlinarith [hsq] exact ⟨hfinal, by linarith [causalUniformAttn_pow_dobrushin_ge N hN (k + 1)]⟩ /-! ## PART III: In-Context Linear / Kernel / Decaying Associative-Recall Width–Memory Trade-Offs -/ /-- Exact Rademacher/bipolar orthogonality over `Fin M → Bool`: `∑ v : Fin M → Bool, bipolar (v a) * bipolar (v b) = if a = b then 2^M else 0`. -/ lemma sum_bipolar_mul (M : ℕ) (a b : Fin M) : ∑ v : Fin M → Bool, bipolar (v a) * bipolar (v b) = if a = b then (2 : ℝ) ^ M else 0 := by by_cases hab : a = b · rw [if_pos hab, hab] simp only [← sq, bipolar_sq, Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] · rw [if_neg hab] -- Involution flipping bit `a` negates every summand let flip : (Fin M → Bool) → (Fin M → Bool) := fun v j => if j = a then !v a else v j have hinv : Function.Involutive flip := by intro v; ext j; simp only [flip]; split_ifs with h · rw [h, Bool.not_not] · rfl have hsum_eq : ∑ v : Fin M → Bool, bipolar (v a) * bipolar (v b) = ∑ v : Fin M → Bool, bipolar (flip v a) * bipolar (flip v b) := (Equiv.sum_comp hinv.toPerm (fun v => bipolar (v a) * bipolar (v b))).symm have hneg : ∑ v : Fin M → Bool, bipolar (flip v a) * bipolar (flip v b) = -(∑ v : Fin M → Bool, bipolar (v a) * bipolar (v b)) := by rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl fun v _ => ?_ simp only [flip, ↓reduceIte, if_neg (Ne.symm hab), bipolar_not, neg_mul] linarith /-- Gram matrix of keys `Φ : Fin M → (Fin D → ℝ)`. -/ def gramMatrix {M D : ℕ} (Φ : Fin M → (Fin D → ℝ)) : Matrix (Fin M) (Fin M) ℝ := fun μ ν => dotProd (Φ μ) (Φ ν) /-- Standard Hebbian linear-attention readout `(∑_μ v_μ Φ_μ) · Φ_ν`. -/ def hebbianRecall {M D : ℕ} (Φ : Fin M → (Fin D → ℝ)) (v : Fin M → ℝ) (ν : Fin M) : ℝ := ∑ μ : Fin M, gramMatrix Φ ν μ * v μ /-- **Theorem 3.1 (Exact Welch Frobenius Lower Bound on Gram Matrix)**: For ANY `M` keys `Φ₁, …, Φ_M ∈ ℝ^D` (`D ≥ 1`), `(∑_μ ‖Φ_μ‖²)² / D ≤ ∑_{μ,ν} ⟨Φ_μ, Φ_ν⟩²`. In particular, for unit keys (`‖Φ_μ‖² = 1`), `M² / D ≤ ∑_{μ,ν} ⟨Φ_μ, Φ_ν⟩²`. -/ theorem welch_gram_frobenius_lower_bound {M D : ℕ} (hD : 0 < D) (Φ : Fin M → (Fin D → ℝ)) : (∑ μ : Fin M, sqNorm (Φ μ)) ^ 2 / (D : ℝ) ≤ ∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 := by let B : Matrix (Fin D) (Fin D) ℝ := fun a b => ∑ μ : Fin M, Φ μ a * Φ μ b have htr : ∑ a : Fin D, B a a = ∑ μ : Fin M, sqNorm (Φ μ) := by simp only [B, sqNorm, dotProd]; rw [Finset.sum_comm] have hfrob : ∑ a : Fin D, ∑ b : Fin D, (B a b) ^ 2 = ∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 := by have h1 : ∀ a b, (B a b) ^ 2 = ∑ μ : Fin M, ∑ ν : Fin M, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := by intro a b simp only [B, sq, Finset.sum_mul, Finset.mul_sum] refine Finset.sum_congr rfl fun μ _ => Finset.sum_congr rfl fun ν _ => by ring have h2 : ∀ μ ν, (gramMatrix Φ μ ν) ^ 2 = ∑ a : Fin D, ∑ b : Fin D, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := by intro μ ν simp only [gramMatrix, dotProd, sq, Finset.sum_mul, Finset.mul_sum] rw [Finset.sum_comm] simp only [h1, h2] calc ∑ a : Fin D, ∑ b : Fin D, ∑ μ : Fin M, ∑ ν : Fin M, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) = ∑ a : Fin D, ∑ μ : Fin M, ∑ b : Fin D, ∑ ν : Fin M, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := Finset.sum_congr rfl fun a _ => Finset.sum_comm _ = ∑ μ : Fin M, ∑ a : Fin D, ∑ b : Fin D, ∑ ν : Fin M, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := Finset.sum_comm _ = ∑ μ : Fin M, ∑ a : Fin D, ∑ ν : Fin M, ∑ b : Fin D, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := Finset.sum_congr rfl fun μ _ => Finset.sum_congr rfl fun a _ => Finset.sum_comm _ = ∑ μ : Fin M, ∑ ν : Fin M, ∑ a : Fin D, ∑ b : Fin D, (Φ μ a * Φ ν a) * (Φ μ b * Φ ν b) := Finset.sum_congr rfl fun μ _ => Finset.sum_comm have hdiag : ∑ a : Fin D, (B a a) ^ 2 ≤ ∑ a : Fin D, ∑ b : Fin D, (B a b) ^ 2 := Finset.sum_le_sum fun a _ => Finset.single_le_sum (fun b _ => sq_nonneg (B a b)) (Finset.mem_univ a) have hcs : (∑ a : Fin D, B a a) ^ 2 ≤ (D : ℝ) * ∑ a : Fin D, (B a a) ^ 2 := by have h := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset (Fin D)) (fun _ => (1 : ℝ)) (fun a => B a a) simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] at h exact h have hDpos : (0 : ℝ) < D := Nat.cast_pos.mpr hD rw [div_le_iff₀ hDpos, ← htr, ← hfrob] nlinarith /-- **Theorem 3.2 (Exact Welch–Hebbian Minimax MSE Lower Bound)**: For ANY `M ≥ 1` unit keys `Φ₁, …, Φ_M ∈ ℝ^D` (`D ≥ 1`), the exact average MSE of Hebbian linear attention over all `2^M` bipolar value tables equals `(1/M) ∑_{μ≠ν} ⟨Φ_μ, Φ_ν⟩²`, which is ALWAYS `≥ M/D - 1`. Hence there EXISTS `v : Fin M → Bool` with MSE `≥ M/D - 1`! -/ theorem welch_hebbian_mse_lower_bound {M D : ℕ} (hM : 0 < M) (hD : 0 < D) (Φ : Fin M → (Fin D → ℝ)) (hunit : ∀ μ, sqNorm (Φ μ) = 1) : ((1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2 = (1 / (M : ℝ)) * (∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 - (M : ℝ))) ∧ ((M : ℝ) / (D : ℝ) - 1 ≤ (1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2) ∧ (∃ v : Fin M → Bool, (M : ℝ) / (D : ℝ) - 1 ≤ (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2) := by have hMpos : (0 : ℝ) < M := Nat.cast_pos.mpr hM have hDpos : (0 : ℝ) < D := Nat.cast_pos.mpr hD have h2pos : (0 : ℝ) < (2 : ℝ) ^ M := by positivity -- Per-query exact bipolar average have hq : ∀ ν : Fin M, ∑ v : Fin M → Bool, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2 = (2 : ℝ) ^ M * ((∑ μ : Fin M, (gramMatrix Φ ν μ) ^ 2) - 1) := by intro ν have hdiff : ∀ v : Fin M → Bool, hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν) = ∑ μ : Fin M, (if μ = ν then (0 : ℝ) else gramMatrix Φ ν μ) * bipolar (v μ) := by intro v unfold hebbianRecall have hdiag : gramMatrix Φ ν ν = 1 := hunit ν rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ν), hdiag, one_mul, add_sub_cancel_left] rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ν), if_pos rfl, zero_mul, zero_add] refine Finset.sum_congr rfl fun μ hμ => by rw [if_neg (Finset.mem_erase.mp hμ).1] simp only [hdiff] let c : Fin M → ℝ := fun μ => if μ = ν then 0 else gramMatrix Φ ν μ have hexp : ∀ v : Fin M → Bool, (∑ μ : Fin M, c μ * bipolar (v μ)) ^ 2 = ∑ a : Fin M, ∑ b : Fin M, (c a * c b) * (bipolar (v a) * bipolar (v b)) := by intro v simp only [sq, Finset.sum_mul, Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun b _ => by ring calc ∑ v : Fin M → Bool, (∑ μ : Fin M, c μ * bipolar (v μ)) ^ 2 = ∑ v : Fin M → Bool, ∑ a : Fin M, ∑ b : Fin M, (c a * c b) * (bipolar (v a) * bipolar (v b)) := Finset.sum_congr rfl fun v _ => hexp v _ = ∑ a : Fin M, ∑ b : Fin M, (c a * c b) * ∑ v : Fin M → Bool, bipolar (v a) * bipolar (v b) := by rw [Finset.sum_comm] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_comm] refine Finset.sum_congr rfl fun b _ => (Finset.mul_sum _ _ _).symm _ = ∑ a : Fin M, ∑ b : Fin M, (c a * c b) * (if a = b then (2 : ℝ) ^ M else 0) := by simp only [sum_bipolar_mul] _ = (2 : ℝ) ^ M * ∑ a : Fin M, (c a) ^ 2 := by rw [Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_eq_single a (fun b _ hba => by rw [if_neg (Ne.symm hba), mul_zero]) (fun h => absurd (Finset.mem_univ _) h)] rw [if_pos rfl, sq]; ring _ = (2 : ℝ) ^ M * ((∑ μ : Fin M, (gramMatrix Φ ν μ) ^ 2) - 1) := by congr 1 have h1 := Finset.add_sum_erase Finset.univ (fun a => (c a) ^ 2) (Finset.mem_univ ν) have h2 := Finset.add_sum_erase Finset.univ (fun μ => (gramMatrix Φ ν μ) ^ 2) (Finset.mem_univ ν) rw [← h1, ← h2] have hcν : c ν = 0 := if_pos rfl have hgn : gramMatrix Φ ν ν = 1 := hunit ν rw [hcν, zero_pow two_ne_zero, zero_add, hgn, one_pow, add_sub_cancel_left] refine Finset.sum_congr rfl fun μ hμ => by simp [c, (Finset.mem_erase.mp hμ).1] have havg : (1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2 = (1 / (M : ℝ)) * (∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 - (M : ℝ)) := by rw [← Finset.mul_sum, Finset.sum_comm] simp only [hq, ← Finset.mul_sum, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] field_simp [h2pos.ne', hMpos.ne'] have hwelch : (M : ℝ) ^ 2 / (D : ℝ) ≤ ∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 := by have h := welch_gram_frobenius_lower_bound hD Φ have hsum1 : ∑ μ : Fin M, sqNorm (Φ μ) = (M : ℝ) := by simp [hunit] rwa [hsum1] at h have hlb : (M : ℝ) / (D : ℝ) - 1 ≤ (1 / (M : ℝ)) * (∑ μ : Fin M, ∑ ν : Fin M, (gramMatrix Φ μ ν) ^ 2 - (M : ℝ)) := by have : (1 / (M : ℝ)) * ((M : ℝ) ^ 2 / (D : ℝ) - (M : ℝ)) = (M : ℝ) / (D : ℝ) - 1 := by field_simp [hMpos.ne', hDpos.ne'] rw [← this] exact mul_le_mul_of_nonneg_left (by linarith) (by positivity) refine ⟨havg, by rw [havg]; exact hlb, ?_⟩ by_contra hnot push Not at hnot have hlt : ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2 < ∑ _v : Fin M → Bool, ((M : ℝ) / (D : ℝ) - 1) := Finset.sum_lt_sum_of_nonempty ⟨fun _ => true, Finset.mem_univ _⟩ fun v _ => hnot v rw [Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] at hlt have h1 : (1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (hebbianRecall Φ (fun μ => bipolar (v μ)) ν - bipolar (v ν)) ^ 2 < (M : ℝ) / (D : ℝ) - 1 := by have := mul_lt_mul_of_pos_left hlt (div_pos one_pos h2pos) rwa [← mul_assoc, one_div_mul_cancel h2pos.ne', one_mul] at this linarith /-- **Theorem 3.3 (Exact Tight-Frame Attainment of Welch Equality at `D = 2, M = 3`)**: The Mercedes-Benz equiangular tight frame in `ℝ²` (`M = 3, D = 2`) has unit keys and achieves exact equality `(1/M)(‖G‖_F² - M) = M/D - 1 = 1/2`. -/ theorem mercedes_benz_tight_frame_equality : let Φ : Fin 3 → (Fin 2 → ℝ) := fun μ => fun c => if c = 0 then Real.cos (2 * Real.pi * (μ.val : ℝ) / 3) else Real.sin (2 * Real.pi * (μ.val : ℝ) / 3) (∀ μ, sqNorm (Φ μ) = 1) ∧ (1 / (3 : ℝ)) * (∑ μ : Fin 3, ∑ ν : Fin 3, (gramMatrix Φ μ ν) ^ 2 - 3) = (3 : ℝ) / 2 - 1 := by intro Φ have hunit : ∀ μ : Fin 3, sqNorm (Φ μ) = 1 := by intro μ; unfold sqNorm dotProd; rw [Fin.sum_univ_two] simp only [Φ, ↓reduceIte, Fin.reduceEq] simpa [sq] using Real.cos_sq_add_sin_sq (2 * Real.pi * (μ.val : ℝ) / 3) refine ⟨hunit, ?_⟩ have hdot : ∀ μ ν : Fin 3, gramMatrix Φ μ ν = Real.cos (2 * Real.pi * ((μ.val : ℝ) - (ν.val : ℝ)) / 3) := by intro μ ν; unfold gramMatrix dotProd; rw [Fin.sum_univ_two] simp only [Φ, ↓reduceIte, Fin.reduceEq] have harg : 2 * Real.pi * ((μ.val : ℝ) - (ν.val : ℝ)) / 3 = 2 * Real.pi * (μ.val : ℝ) / 3 - 2 * Real.pi * (ν.val : ℝ) / 3 := by ring rw [harg, Real.cos_sub] have hcos23 : Real.cos (2 * Real.pi / 3) = -(1 / 2 : ℝ) := by have : 2 * Real.pi / 3 = Real.pi - Real.pi / 3 := by ring rw [this, Real.cos_pi_sub, Real.cos_pi_div_three] have hcos43 : Real.cos (4 * Real.pi / 3) = -(1 / 2 : ℝ) := by have : 4 * Real.pi / 3 = Real.pi / 3 + Real.pi := by ring rw [this, Real.cos_add_pi, Real.cos_pi_div_three] have hsq_off : ∀ μ ν : Fin 3, μ ≠ ν → (gramMatrix Φ μ ν) ^ 2 = 1 / 4 := by intro μ ν hne rw [hdot μ ν] fin_cases μ <;> fin_cases ν <;> try exact absurd rfl hne all_goals simp only [Nat.cast_zero, Nat.cast_one, Nat.cast_ofNat] · have : 2 * Real.pi * ((0 : ℝ) - 1) / 3 = -(2 * Real.pi / 3) := by ring rw [this, Real.cos_neg, hcos23]; norm_num · have : 2 * Real.pi * ((0 : ℝ) - 2) / 3 = -(4 * Real.pi / 3) := by ring rw [this, Real.cos_neg, hcos43]; norm_num · have : 2 * Real.pi * ((1 : ℝ) - 0) / 3 = 2 * Real.pi / 3 := by ring rw [this, hcos23]; norm_num · have : 2 * Real.pi * ((1 : ℝ) - 2) / 3 = -(2 * Real.pi / 3) := by ring rw [this, Real.cos_neg, hcos23]; norm_num · have : 2 * Real.pi * ((2 : ℝ) - 0) / 3 = 4 * Real.pi / 3 := by ring rw [this, hcos43]; norm_num · have : 2 * Real.pi * ((2 : ℝ) - 1) / 3 = 2 * Real.pi / 3 := by ring rw [this, hcos23]; norm_num rw [Fin.sum_univ_three] simp only [Fin.sum_univ_three] have hd0 : gramMatrix Φ 0 0 = 1 := hunit 0 have hd1 : gramMatrix Φ 1 1 = 1 := hunit 1 have hd2 : gramMatrix Φ 2 2 = 1 := hunit 2 rw [hd0, hd1, hd2, hsq_off 0 1 (by decide), hsq_off 0 2 (by decide), hsq_off 1 0 (by decide), hsq_off 1 2 (by decide), hsq_off 2 0 (by decide), hsq_off 2 1 (by decide)] norm_num /-- **Theorem 3.4 (Exact Optimal-Decoder / Delta-Rule Minimax MSE Lower Bound)**: For ANY keys `Φ₁, …, Φ_M ∈ ℝ^D` (`M ≥ 1`) and ANY (even omniscient, nonlinear) state selector `s : (Fin M → Bool) → (Fin D → ℝ)`, the average MSE over all `2^M` bipolar value tables is ALWAYS `≥ 1 - D/M`. Hence there EXISTS `v : Fin M → Bool` such that EVERY state `w ∈ ℝ^D` incurs MSE `≥ 1 - D/M`! -/ theorem delta_rule_minimax_mse_lower_bound {M D : ℕ} (hM : 0 < M) (Φ : Fin M → (Fin D → ℝ)) : (∀ s : (Fin M → Bool) → (Fin D → ℝ), 1 - (D : ℝ) / (M : ℝ) ≤ (1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (dotProd (s v) (Φ ν) - bipolar (v ν)) ^ 2) ∧ (∃ v : Fin M → Bool, ∀ w : Fin D → ℝ, 1 - (D : ℝ) / (M : ℝ) ≤ (1 / (M : ℝ)) * ∑ ν : Fin M, (dotProd w (Φ ν) - bipolar (v ν)) ^ 2) := by -- Define linear map T : (Fin D → ℝ) →ₗ[ℝ] EuclideanSpace ℝ (Fin M) sending w ↦ (ν ↦ ⟨w, Φ ν⟩) let T : (Fin D → ℝ) →ₗ[ℝ] EuclideanSpace ℝ (Fin M) := { toFun := fun w => (WithLp.equiv 2 (Fin M → ℝ)).symm (fun ν => dotProd w (Φ ν)) map_add' := fun x y => by ext ν; simp only [WithLp.equiv_symm_apply, PiLp.add_apply, dotProd, Pi.add_apply, add_mul, Finset.sum_add_distrib] map_smul' := fun r x => by ext ν; simp only [WithLp.equiv_symm_apply, RingHom.id_apply, PiLp.smul_apply, smul_eq_mul, dotProd, Pi.smul_apply, mul_assoc, ← Finset.mul_sum] } let W : Submodule ℝ (EuclideanSpace ℝ (Fin M)) := LinearMap.range T let r := Module.finrank ℝ W have hr_le : r ≤ D := by calc r = Module.finrank ℝ (LinearMap.range T) := rfl _ ≤ Module.finrank ℝ (Fin D → ℝ) := LinearMap.finrank_range_le T _ = D := Module.finrank_fin_fun ℝ let b : OrthonormalBasis (Fin r) ℝ W := stdOrthonormalBasis ℝ W -- Projection inequality: for any y ∈ EuclideanSpace ℝ (Fin M) and any x ∈ W, -- ‖x - y‖² ≥ ‖y‖² - ∑_a ⟨b a, y⟩² have hproj : ∀ (y : EuclideanSpace ℝ (Fin M)) (w : Fin D → ℝ), ‖y‖ ^ 2 - ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y) ^ 2 ≤ ‖T w - y‖ ^ 2 := by intro y w let x : W := ⟨T w, ⟨w, rfl⟩⟩ let p : EuclideanSpace ℝ (Fin M) := ∑ a : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y • (b a : EuclideanSpace ℝ (Fin M)) have hpW : p ∈ W := Submodule.sum_mem W fun a _ => Submodule.smul_mem W _ (b a).2 have horth : ∀ z ∈ W, inner ℝ z (y - p) = 0 := by intro z hz -- Express z in the orthonormal basis b have hz_eq : z = ∑ a : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) z • (b a : EuclideanSpace ℝ (Fin M)) := by have := b.sum_repr ⟨z, hz⟩ have hval := congrArg Subtype.val this simpa [OrthonormalBasis.repr_apply_apply] using hval.symm rw [hz_eq, sum_inner] refine Finset.sum_eq_zero fun a _ => ?_ rw [real_inner_smul_left, inner_sub_right, inner_sum] have hba : ∑ c : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y • (b c : EuclideanSpace ℝ (Fin M))) = inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y := by calc ∑ c : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y • (b c : EuclideanSpace ℝ (Fin M))) = ∑ c : Fin r, inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y * inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (b c : EuclideanSpace ℝ (Fin M)) := by refine Finset.sum_congr rfl fun c _ => real_inner_smul_right _ _ _ _ = ∑ c : Fin r, inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y * (if a = c then 1 else 0) := by refine Finset.sum_congr rfl fun c _ => ?_ have ho := b.orthonormal rw [orthonormal_iff_ite] at ho have : inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (b c : EuclideanSpace ℝ (Fin M)) = inner ℝ (b a) (b c) := rfl rw [this, ho a c] _ = inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y := by simp rw [hba, sub_self, mul_zero] have hpyth1 : ‖T w - y‖ ^ 2 = ‖T w - p‖ ^ 2 + ‖y - p‖ ^ 2 := by have hsub : T w - y = (T w - p) - (y - p) := by abel rw [hsub, norm_sub_sq_real, horth (T w - p) (Submodule.sub_mem W ⟨w, rfl⟩ hpW), mul_zero, sub_zero] have hpyth2 : ‖y‖ ^ 2 = ‖p‖ ^ 2 + ‖y - p‖ ^ 2 := by have hadd : y = p + (y - p) := by abel conv_lhs => rw [hadd] rw [norm_add_sq_real, horth p hpW, mul_zero, add_zero] have hpnorm : ‖p‖ ^ 2 = ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y) ^ 2 := by have h1 : ‖p‖ ^ 2 = inner ℝ p p := (real_inner_self_eq_norm_sq p).symm rw [h1, sum_inner] refine Finset.sum_congr rfl fun a _ => ?_ rw [real_inner_smul_left, inner_sum] have hba : ∑ c : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y • (b c : EuclideanSpace ℝ (Fin M))) = inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y := by calc ∑ c : Fin r, inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y • (b c : EuclideanSpace ℝ (Fin M))) = ∑ c : Fin r, inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y * inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (b c : EuclideanSpace ℝ (Fin M)) := by refine Finset.sum_congr rfl fun c _ => real_inner_smul_right _ _ _ _ = ∑ c : Fin r, inner ℝ (b c : EuclideanSpace ℝ (Fin M)) y * (if a = c then 1 else 0) := by refine Finset.sum_congr rfl fun c _ => ?_ have ho := b.orthonormal; rw [orthonormal_iff_ite] at ho have : inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (b c : EuclideanSpace ℝ (Fin M)) = inner ℝ (b a) (b c) := rfl rw [this, ho a c] _ = inner ℝ (b a : EuclideanSpace ℝ (Fin M)) y := by simp rw [hba, sq] nlinarith [sq_nonneg ‖T w - p‖] -- Define y(v) = bipolar(v) in EuclideanSpace ℝ (Fin M) let yv : (Fin M → Bool) → EuclideanSpace ℝ (Fin M) := fun v => (WithLp.equiv 2 (Fin M → ℝ)).symm (fun ν => bipolar (v ν)) have hyv_norm : ∀ v, ‖yv v‖ ^ 2 = (M : ℝ) := by intro v rw [EuclideanSpace.norm_sq_eq] simp [yv, bipolar_sq] have hdist_eq : ∀ v w, ‖T w - yv v‖ ^ 2 = ∑ ν : Fin M, (dotProd w (Φ ν) - bipolar (v ν)) ^ 2 := by intro v w rw [EuclideanSpace.norm_sq_eq] refine Finset.sum_congr rfl fun ν _ => by simp [T, yv, Real.norm_eq_abs, sq_abs] -- Exact bipolar sum of ∑_v ⟨u, yv v⟩² = 2^M * ‖u‖² have hsum_inner : ∀ u : EuclideanSpace ℝ (Fin M), ∑ v : Fin M → Bool, (inner ℝ u (yv v)) ^ 2 = (2 : ℝ) ^ M * ‖u‖ ^ 2 := by intro u have hcoord : ∀ v, inner ℝ u (yv v) = ∑ ν : Fin M, bipolar (v ν) * u ν := by intro v; rw [EuclideanSpace.inner_eq_star_dotProduct] simp only [dotProduct, star_trivial, yv, WithLp.equiv_symm_apply] simp only [hcoord] have hexp : ∀ v : Fin M → Bool, (∑ ν : Fin M, bipolar (v ν) * u ν) ^ 2 = ∑ a : Fin M, ∑ c : Fin M, (u a * u c) * (bipolar (v a) * bipolar (v c)) := by intro v; simp only [sq, Finset.sum_mul, Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => Finset.sum_congr rfl fun c _ => by ring calc ∑ v : Fin M → Bool, (∑ ν : Fin M, bipolar (v ν) * u ν) ^ 2 = ∑ a : Fin M, ∑ c : Fin M, (u a * u c) * ∑ v : Fin M → Bool, bipolar (v a) * bipolar (v c) := by simp only [hexp] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_comm] refine Finset.sum_congr rfl fun c _ => (Finset.mul_sum _ _ _).symm _ = (2 : ℝ) ^ M * ∑ a : Fin M, (u a) ^ 2 := by simp only [sum_bipolar_mul] rw [Finset.mul_sum] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_eq_single a (fun c _ hca => by rw [if_neg (Ne.symm hca), mul_zero]) (fun h => absurd (Finset.mem_univ _) h)] rw [if_pos rfl, sq]; ring _ = (2 : ℝ) ^ M * ‖u‖ ^ 2 := by congr 1; rw [EuclideanSpace.norm_sq_eq] refine Finset.sum_congr rfl fun a _ => by simp [Real.norm_eq_abs, sq_abs] have hsum_proj : ∑ v : Fin M → Bool, (‖yv v‖ ^ 2 - ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (yv v)) ^ 2) = (2 : ℝ) ^ M * ((M : ℝ) - (r : ℝ)) := by rw [Finset.sum_sub_distrib] have h1 : ∑ v : Fin M → Bool, ‖yv v‖ ^ 2 = (2 : ℝ) ^ M * (M : ℝ) := by simp [hyv_norm, Finset.sum_const, Fintype.card_bool, Fintype.card_fin] have h2 : ∑ v : Fin M → Bool, ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (yv v)) ^ 2 = (2 : ℝ) ^ M * (r : ℝ) := by rw [Finset.sum_comm] have hba1 : ∀ a : Fin r, ‖(b a : EuclideanSpace ℝ (Fin M))‖ ^ 2 = 1 := by intro a; have := b.orthonormal.1 a; rw [show ‖(b a : EuclideanSpace ℝ (Fin M))‖ = ‖b a‖ from rfl, this, one_pow] simp [hsum_inner, hba1, mul_comm] rw [h1, h2]; ring have hMpos : (0 : ℝ) < M := Nat.cast_pos.mpr hM have h2pos : (0 : ℝ) < (2 : ℝ) ^ M := by positivity have hr_cast : (r : ℝ) ≤ (D : ℝ) := Nat.cast_le.mpr hr_le have hpart1 : ∀ s : (Fin M → Bool) → (Fin D → ℝ), 1 - (D : ℝ) / (M : ℝ) ≤ (1 / (2 : ℝ) ^ M) * ∑ v : Fin M → Bool, (1 / (M : ℝ)) * ∑ ν : Fin M, (dotProd (s v) (Φ ν) - bipolar (v ν)) ^ 2 := by intro s have hle : ∑ v : Fin M → Bool, (‖yv v‖ ^ 2 - ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (yv v)) ^ 2) ≤ ∑ v : Fin M → Bool, ∑ ν : Fin M, (dotProd (s v) (Φ ν) - bipolar (v ν)) ^ 2 := Finset.sum_le_sum fun v _ => by rw [← hdist_eq]; exact hproj (yv v) (s v) rw [hsum_proj] at hle rw [← Finset.mul_sum] have hstep : 1 - (D : ℝ) / (M : ℝ) ≤ (1 / (2 : ℝ) ^ M) * ((1 / (M : ℝ)) * ((2 : ℝ) ^ M * ((M : ℝ) - (r : ℝ)))) := by have : (1 / (2 : ℝ) ^ M) * ((1 / (M : ℝ)) * ((2 : ℝ) ^ M * ((M : ℝ) - (r : ℝ)))) = 1 - (r : ℝ) / (M : ℝ) := by field_simp [h2pos.ne', hMpos.ne'] rw [this] exact sub_le_sub_left (div_le_div_of_nonneg_right hr_cast hMpos.le) 1 exact le_trans hstep (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hle (by positivity)) (by positivity)) refine ⟨hpart1, ?_⟩ -- Existence of worst-case v: choose v maximizing the lower bound (‖yv v‖² - ∑_a ⟨b a, yv v⟩²)/M have hex : ∃ v : Fin M → Bool, (M : ℝ) - (r : ℝ) ≤ ‖yv v‖ ^ 2 - ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (yv v)) ^ 2 := by by_contra hnot push Not at hnot have hlt : ∑ v : Fin M → Bool, (‖yv v‖ ^ 2 - ∑ a : Fin r, (inner ℝ (b a : EuclideanSpace ℝ (Fin M)) (yv v)) ^ 2) < ∑ _v : Fin M → Bool, ((M : ℝ) - (r : ℝ)) := Finset.sum_lt_sum_of_nonempty ⟨fun _ => true, Finset.mem_univ _⟩ fun v _ => hnot v rw [hsum_proj, Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] at hlt exact lt_irrefl _ hlt obtain ⟨v, hv⟩ := hex refine ⟨v, fun w => ?_⟩ have hpw := hproj (yv v) w rw [hdist_eq] at hpw have h1 : 1 - (D : ℝ) / (M : ℝ) ≤ (1 / (M : ℝ)) * ((M : ℝ) - (r : ℝ)) := by have : (1 / (M : ℝ)) * ((M : ℝ) - (r : ℝ)) = 1 - (r : ℝ) / (M : ℝ) := by field_simp [hMpos.ne'] rw [this]; exact sub_le_sub_left (div_le_div_of_nonneg_right hr_cast hMpos.le) 1 exact le_trans h1 (mul_le_mul_of_nonneg_left (le_trans hv hpw) (by positivity)) /-- **Theorem 3.5 (Exact Universal Sign-Recall Strict Diagonal Dominance Characterization)**: An interaction matrix `B : Matrix (Fin M) (Fin M) ℝ` with affine biases `b : Fin M → ℝ` achieves universal bipolar sign recall (`∀ v, ∀ ν, bipolar (v ν) * (∑ μ, B ν μ * bipolar (v μ) + b ν) > 0`) if and only if `∀ ν, ∑ μ ≠ ν, |B ν μ| + |b ν| < B ν ν`! -/ theorem linear_universal_sign_recall_iff_sdd {M : ℕ} (B : Matrix (Fin M) (Fin M) ℝ) (b : Fin M → ℝ) : (∀ v : Fin M → Bool, ∀ ν : Fin M, 0 < bipolar (v ν) * ((∑ μ : Fin M, B ν μ * bipolar (v μ)) + b ν)) ↔ (∀ ν : Fin M, (∑ μ ∈ Finset.univ.erase ν, |B ν μ|) + |b ν| < B ν ν) := by constructor · intro hall ν -- Construct adversarial v with v ν = true and for μ ≠ ν, bipolar (v μ) * B ν μ = -|B ν μ| let v : Fin M → Bool := fun μ => if μ = ν then true else decide (B ν μ < 0) let v' : Fin M → Bool := fun μ => !v μ have hv1 := hall v ν have hv2 := hall v' ν have hvν : bipolar (v ν) = 1 := by simp [v] have hv'ν : bipolar (v' ν) = -1 := by simp [v', v] have hsum_v' : ∑ μ : Fin M, B ν μ * bipolar (v' μ) = -(∑ μ : Fin M, B ν μ * bipolar (v μ)) := by rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl fun μ _ => by simp only [v', bipolar_not, mul_neg] have hpos1 : 0 < (∑ μ : Fin M, B ν μ * bipolar (v μ)) + b ν := by rw [hvν, one_mul] at hv1; exact hv1 have hpos2 : 0 < (∑ μ : Fin M, B ν μ * bipolar (v μ)) - b ν := by rw [hv'ν, hsum_v'] at hv2; linarith have hsum_val : ∑ μ : Fin M, B ν μ * bipolar (v μ) = B ν ν - ∑ μ ∈ Finset.univ.erase ν, |B ν μ| := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ν), hvν, mul_one, sub_eq_add_neg, ← Finset.sum_neg_distrib] congr 1 refine Finset.sum_congr rfl fun μ hμ => ?_ have hne : μ ≠ ν := (Finset.mem_erase.mp hμ).1 simp only [v, if_neg hne] by_cases hlt : B ν μ < 0 · simp [hlt, abs_of_neg hlt] · push Not at hlt simp [not_lt.mpr hlt, abs_of_nonneg hlt] rw [hsum_val] at hpos1 hpos2 rcases le_or_gt 0 (b ν) with hb | hb · rw [abs_of_nonneg hb]; linarith · rw [abs_of_neg hb]; linarith · intro hsdd v ν have h1 : bipolar (v ν) * ((∑ μ : Fin M, B ν μ * bipolar (v μ)) + b ν) = B ν ν + (∑ μ ∈ Finset.univ.erase ν, (B ν μ * (bipolar (v ν) * bipolar (v μ)))) + bipolar (v ν) * b ν := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ν), mul_add, mul_add, Finset.mul_sum] have hsq : bipolar (v ν) * (B ν ν * bipolar (v ν)) = B ν ν := by have hmul : bipolar (v ν) * (B ν ν * bipolar (v ν)) = B ν ν * bipolar (v ν) ^ 2 := by ring rw [hmul, bipolar_sq, mul_one] rw [hsq] congr 1; congr 1 refine Finset.sum_congr rfl fun μ _ => by ring rw [h1] have htail : -(∑ μ ∈ Finset.univ.erase ν, |B ν μ|) ≤ ∑ μ ∈ Finset.univ.erase ν, B ν μ * (bipolar (v ν) * bipolar (v μ)) := by rw [← Finset.sum_neg_distrib] refine Finset.sum_le_sum fun μ _ => ?_ have habs : |B ν μ * (bipolar (v ν) * bipolar (v μ))| = |B ν μ| := by rw [abs_mul, abs_mul, bipolar_abs, bipolar_abs, mul_one, mul_one] linarith [neg_abs_le (B ν μ * (bipolar (v ν) * bipolar (v μ)))] have hb : -|b ν| ≤ bipolar (v ν) * b ν := by have : |bipolar (v ν) * b ν| = |b ν| := by rw [abs_mul, bipolar_abs, one_mul] linarith [neg_abs_le (bipolar (v ν) * b ν)] linarith [hsdd ν] /-- **Theorem 3.6 (Exact `M ≤ D` Universal Sign-Recall Ceiling for ALL Linear-State Models)**: For ANY feature keys `Φ₁, …, Φ_M ∈ ℝ^D`, ANY asymmetric query vectors `w₁, …, w_M ∈ ℝ^D`, and ANY affine biases `b₁, …, b_M ∈ ℝ`: if the `D`-dimensional linear state `s(v) = ∑_μ v_μ Φ_μ` achieves universal exact sign recall across all `2^M` bipolar tables (`∀ v, ∀ ν, bipolar (v ν) * (⟨w_ν, s(v)⟩ + b_ν) > 0`), then **`M ≤ D`**! -/ theorem linear_universal_sign_recall_le_dim {M D : ℕ} (Φ w : Fin M → (Fin D → ℝ)) (b : Fin M → ℝ) (hrec : ∀ v : Fin M → Bool, ∀ ν : Fin M, 0 < bipolar (v ν) * (dotProd (w ν) (fun c => ∑ μ : Fin M, bipolar (v μ) * Φ μ c) + b ν)) : M ≤ D := by let B : Matrix (Fin M) (Fin M) ℝ := fun ν μ => dotProd (w ν) (Φ μ) have hrecB : ∀ v : Fin M → Bool, ∀ ν : Fin M, 0 < bipolar (v ν) * ((∑ μ : Fin M, B ν μ * bipolar (v μ)) + b ν) := by intro v ν have heq : dotProd (w ν) (fun c => ∑ μ : Fin M, bipolar (v μ) * Φ μ c) = ∑ μ : Fin M, B ν μ * bipolar (v μ) := by simp only [B, dotProd, Finset.mul_sum, Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun μ _ => Finset.sum_congr rfl fun c _ => by ring rw [← heq]; exact hrec v ν have hsdd := (linear_universal_sign_recall_iff_sdd B b).mp hrecB -- Define linear map Φlin : (Fin M → ℝ) →ₗ[ℝ] (Fin D → ℝ) sending x ↦ ∑_μ x_μ Φ_μ let Φlin : (Fin M → ℝ) →ₗ[ℝ] (Fin D → ℝ) := { toFun := fun x c => ∑ μ : Fin M, x μ * Φ μ c map_add' := fun x y => by ext c; simp [add_mul, Finset.sum_add_distrib] map_smul' := fun r x => by ext c; simp [mul_assoc, ← Finset.mul_sum] } -- Prove Φlin is injective via Gershgorin strict diagonal dominance of B! have hinj : Function.Injective Φlin := by rw [injective_iff_map_eq_zero] intro x hx by_contra hne have hMpos : 0 < M := by by_contra h0; push Not at h0 have hM0 : M = 0 := Nat.eq_zero_of_le_zero h0 apply hne; ext i; exact absurd i.isLt (by omega) -- Pick ν maximizing |x ν| obtain ⟨ν, _, hmax⟩ := Finset.exists_max_image Finset.univ (fun μ : Fin M => |x μ|) ⟨⟨0, hMpos⟩, Finset.mem_univ _⟩ have hxν_pos : 0 < |x ν| := by by_contra h0; push Not at h0 apply hne; ext μ have : |x μ| ≤ 0 := le_trans (hmax μ (Finset.mem_univ μ)) h0 exact abs_eq_zero.mp (le_antisymm this (abs_nonneg _)) -- From Φlin x = 0, we have (B *ᵥ x) ν = 0 have hBx : ∑ μ : Fin M, B ν μ * x μ = 0 := by have : ∑ μ : Fin M, B ν μ * x μ = dotProd (w ν) (Φlin x) := by simp only [B, Φlin, LinearMap.coe_mk, AddHom.coe_mk, dotProd, Finset.mul_sum, Finset.sum_mul] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun μ _ => Finset.sum_congr rfl fun c _ => by ring rw [this, hx]; simp [dotProd] rw [← Finset.add_sum_erase _ _ (Finset.mem_univ ν)] at hBx have heq : B ν ν * x ν = -(∑ μ ∈ Finset.univ.erase ν, B ν μ * x μ) := by linarith have hBpos : 0 < B ν ν := by have hnn : 0 ≤ (∑ μ ∈ Finset.univ.erase ν, |B ν μ|) + |b ν| := add_nonneg (Finset.sum_nonneg fun _ _ => abs_nonneg _) (abs_nonneg _) linarith [hsdd ν] have hle : B ν ν * |x ν| ≤ (∑ μ ∈ Finset.univ.erase ν, |B ν μ|) * |x ν| := by calc B ν ν * |x ν| = |B ν ν * x ν| := by rw [abs_mul, abs_of_pos hBpos] _ = |∑ μ ∈ Finset.univ.erase ν, B ν μ * x μ| := by rw [heq, abs_neg] _ ≤ ∑ μ ∈ Finset.univ.erase ν, |B ν μ * x μ| := Finset.abs_sum_le_sum_abs _ _ _ = ∑ μ ∈ Finset.univ.erase ν, |B ν μ| * |x μ| := Finset.sum_congr rfl fun μ _ => abs_mul _ _ _ ≤ ∑ μ ∈ Finset.univ.erase ν, |B ν μ| * |x ν| := Finset.sum_le_sum fun μ _ => mul_le_mul_of_nonneg_left (hmax μ (Finset.mem_univ μ)) (abs_nonneg _) _ = (∑ μ ∈ Finset.univ.erase ν, |B ν μ|) * |x ν| := (Finset.sum_mul _ _ _).symm have hsdd' : ∑ μ ∈ Finset.univ.erase ν, |B ν μ| < B ν ν := by linarith [hsdd ν, abs_nonneg (b ν)] nlinarith have hfin := LinearMap.finrank_le_finrank_of_injective hinj rwa [Module.finrank_fin_fun, Module.finrank_fin_fun] at hfin /-- **Theorem 3.7 (Exact Forgetting Horizon for Decaying Linear Attention / RetNet)**: In decaying linear attention `h_M = ∑_{t=0}^{M-1} γ^{M-1-t} v_t k_t` (`0 < γ < 1`), with unit oldest key `k₀` and uniform off-diagonal key coherence `|⟨k₀, k_t⟩| ≥ μ > 0` for `t ≥ 1`: strict sign recall of the oldest bit `v₀` across all `v ∈ {±1}^M` is **IMPOSSIBLE** whenever `M - 1 ≥ log(1 + (1 - γ) / μ) / log(1 / γ)`! -/ theorem decay_linear_recall_forgetting_horizon {M D : ℕ} (hM : 1 ≤ M) (γ μ : ℝ) (hγ0 : 0 < γ) (hγ1 : γ < 1) (hμ : 0 < μ) (k : Fin M → (Fin D → ℝ)) (hk0 : sqNorm (k ⟨0, by omega⟩) = 1) (hcoh : ∀ t : Fin M, t ≠ ⟨0, by omega⟩ → μ ≤ |dotProd (k ⟨0, by omega⟩) (k t)|) (hhor : Real.log (1 + (1 - γ) / μ) / Real.log (1 / γ) ≤ ((M - 1 : ℕ) : ℝ)) : ¬ (∀ v : Fin M → Bool, 0 < bipolar (v ⟨0, by omega⟩) * ∑ t : Fin M, γ ^ (M - 1 - t.val) * dotProd (k ⟨0, by omega⟩) (k t) * bipolar (v t)) := by intro hall -- Choose adversarial v with v 0 = true and for t ≠ 0, sign opposes dotProd (k 0) (k t) let t0 : Fin M := ⟨0, by omega⟩ let v : Fin M → Bool := fun t => if t = t0 then true else decide (dotProd (k t0) (k t) < 0) have hv := hall v have hv0 : bipolar (v t0) = 1 := by simp [v] rw [hv0, one_mul] at hv rw [← Finset.add_sum_erase _ _ (Finset.mem_univ t0)] at hv have hsig : γ ^ (M - 1 - t0.val) * dotProd (k t0) (k t0) * bipolar (v t0) = γ ^ (M - 1) := by simp only [t0, Nat.sub_zero, hv0, mul_one] have : dotProd (k ⟨0, by omega⟩) (k ⟨0, by omega⟩) = 1 := hk0 rw [this, mul_one] have hint : ∑ t ∈ Finset.univ.erase t0, γ ^ (M - 1 - t.val) * dotProd (k t0) (k t) * bipolar (v t) ≤ -(μ * ((1 - γ ^ (M - 1)) / (1 - γ))) := by have hterm : ∀ t ∈ Finset.univ.erase t0, γ ^ (M - 1 - t.val) * dotProd (k t0) (k t) * bipolar (v t) ≤ -(μ * γ ^ (M - 1 - t.val)) := by intro t ht have hne : t ≠ t0 := (Finset.mem_erase.mp ht).1 have hval : dotProd (k t0) (k t) * bipolar (v t) = -|dotProd (k t0) (k t)| := by simp only [v, if_neg hne] by_cases hlt : dotProd (k t0) (k t) < 0 · simp [hlt, abs_of_neg hlt] · push Not at hlt; simp [not_lt.mpr hlt, abs_of_nonneg hlt] rw [mul_assoc, hval] have hγpow : 0 ≤ γ ^ (M - 1 - t.val) := pow_nonneg hγ0.le _ have := hcoh t hne nlinarith calc ∑ t ∈ Finset.univ.erase t0, γ ^ (M - 1 - t.val) * dotProd (k t0) (k t) * bipolar (v t) ≤ ∑ t ∈ Finset.univ.erase t0, -(μ * γ ^ (M - 1 - t.val)) := Finset.sum_le_sum hterm _ = -(μ * ∑ t ∈ Finset.univ.erase t0, γ ^ (M - 1 - t.val)) := by rw [Finset.sum_neg_distrib, ← Finset.mul_sum] _ = -(μ * ((1 - γ ^ (M - 1)) / (1 - γ))) := by congr 2 have hbij : ∑ t ∈ Finset.univ.erase t0, γ ^ (M - 1 - t.val) = ∑ j ∈ Finset.range (M - 1), γ ^ j := by symm refine Finset.sum_bij (fun j hj => ⟨M - 1 - j, by have := Finset.mem_range.mp hj; omega⟩) (fun j hj => Finset.mem_erase.mpr ⟨by have := Finset.mem_range.mp hj intro heq; have := congrArg Fin.val heq; simp [t0] at this; omega, Finset.mem_univ _⟩) (fun a ha b hb h => by have ha' := Finset.mem_range.mp ha; have hb' := Finset.mem_range.mp hb have := congrArg Fin.val h; simp at this; omega) (fun t ht => ⟨M - 1 - t.val, Finset.mem_range.mpr (by have hne : t ≠ t0 := (Finset.mem_erase.mp ht).1 have htpos : 0 < t.val := Nat.pos_of_ne_zero (fun h => hne (Fin.ext h)) omega), Fin.ext (by simp; omega)⟩) (fun j hj => by have := Finset.mem_range.mp hj congr 1; simp; omega) rw [hbij, geom_sum_eq hγ1.ne] have : (γ ^ (M - 1) - 1) / (γ - 1) = (1 - γ ^ (M - 1)) / (1 - γ) := by field_simp [(by linarith : γ - 1 ≠ 0), (by linarith : 1 - γ ≠ 0)]; ring exact this -- From hhor, deduce γ^(M-1) ≤ μ * (1 - γ^(M-1)) / (1 - γ) have hlog_pos : 0 < Real.log (1 / γ) := Real.log_pos ((one_lt_div hγ0).mpr hγ1) have h1 : Real.log (1 + (1 - γ) / μ) ≤ ((M - 1 : ℕ) : ℝ) * Real.log (1 / γ) := (div_le_iff₀ hlog_pos).mp hhor have h2 : 1 + (1 - γ) / μ ≤ (1 / γ) ^ (M - 1) := by have hexp := Real.exp_le_exp.mpr h1 rw [Real.exp_log (by positivity), ← Real.log_pow, Real.exp_log (by positivity)] at hexp exact hexp have hγpow_pos : 0 < γ ^ (M - 1) := pow_pos hγ0 _ have h3 : (1 + (1 - γ) / μ) * γ ^ (M - 1) ≤ 1 := by have := mul_le_mul_of_nonneg_right h2 hγpow_pos.le rwa [one_div_pow, one_div_mul_cancel hγpow_pos.ne'] at this have h4 : γ ^ (M - 1) ≤ μ * ((1 - γ ^ (M - 1)) / (1 - γ)) := by have h1γ : 0 < 1 - γ := by linarith rw [mul_div_assoc', le_div_iff₀ h1γ] have h3' : (μ + (1 - γ)) * γ ^ (M - 1) ≤ μ := by have := mul_le_mul_of_nonneg_left h3 hμ.le have hl : μ * ((1 + (1 - γ) / μ) * γ ^ (M - 1)) = (μ + (1 - γ)) * γ ^ (M - 1) := by field_simp [hμ.ne'] linarith nlinarith linarith /-! ## PART IV: Exact SSM (Finite-State GSSM & Infinite-Precision LTI Hankel) vs. Softmax Transformer Copy & Recall Separations -/ /-- A Generalized State-Space Model (GSSM) compressing a sequence/prompt `X` into a finite state space `H` and decoding an output `Y`. -/ structure FiniteStateSSM (X H Y : Type*) where encode : X → H decode : H → Y /-- **Theorem 4.1 (Exact Finite-State GSSM Copy Accuracy Ceiling)**: For ANY finite-state GSSM with state space `H` copying length-`L` strings over alphabet `Fin V`, the number of strings copied without error is at most `|H|`. Hence exact copy accuracy is `≤ |H| / V^L`, and zero-error copying requires `V^L ≤ |H|`! -/ theorem finite_state_ssm_copy_accuracy_bound {L V : ℕ} {H : Type*} [Fintype H] [DecidableEq (Fin L → Fin V)] (M : FiniteStateSSM (Fin L → Fin V) H (Fin L → Fin V)) : ((Finset.univ.filter (fun w : Fin L → Fin V => M.decode (M.encode w) = w)).card : ℝ) ≤ (Fintype.card H : ℝ) ∧ ((∀ w, M.decode (M.encode w) = w) → V ^ L ≤ Fintype.card H) := by classical set Good := Finset.univ.filter (fun w : Fin L → Fin V => M.decode (M.encode w) = w) have hsub : Good ⊆ Finset.univ.image M.decode := by intro w hw rw [Finset.mem_image] exact ⟨M.encode w, Finset.mem_univ _, (Finset.mem_filter.mp hw).2⟩ have hcard : Good.card ≤ Fintype.card H := le_trans (Finset.card_le_card hsub) (Finset.card_image_le.trans (by simp)) refine ⟨Nat.cast_le.mpr hcard, fun hall => ?_⟩ have hGood : Good = Finset.univ := by ext w; simp [Good, hall w] rw [hGood, Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_fin] at hcard exact hcard /-- Hamming distance between two binary value tables `Fin M → Bool`. -/ def hammingDist {M : ℕ} (u v : Fin M → Bool) : ℕ := (Finset.univ.filter (fun i : Fin M => u i ≠ v i)).card /-- Exact cardinality of the Hamming ball of radius `r` around any `y : Fin M → Bool`. -/ lemma card_hammingBall {M : ℕ} (y : Fin M → Bool) (r : ℕ) : (Finset.univ.filter (fun v : Fin M → Bool => hammingDist v y ≤ r)).card = ∑ j ∈ Finset.range (r + 1), M.choose j := by classical -- Bijection with subsets S ⊆ Fin M of cardinality ≤ r via symmetric difference let φ : (Fin M → Bool) → Finset (Fin M) := fun v => Finset.univ.filter (fun i => v i ≠ y i) have hbij : (Finset.univ.filter (fun v : Fin M → Bool => hammingDist v y ≤ r)).card = ((Finset.univ : Finset (Finset (Fin M))).filter (fun S => S.card ≤ r)).card := by refine Finset.card_bij (fun v _ => φ v) (fun v hv => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hv).2⟩) (fun u _ v _ huv => by ext i have hi : (i ∈ φ u) ↔ (i ∈ φ v) := by rw [huv] simp only [φ, Finset.mem_filter, Finset.mem_univ, true_and] at hi cases h1 : u i <;> cases h2 : v i <;> cases h3 : y i <;> simp_all) (fun S hS => ⟨fun i => if i ∈ S then !y i else y i, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by have : φ (fun i => if i ∈ S then !y i else y i) = S := by ext i; simp only [φ, Finset.mem_filter, Finset.mem_univ, true_and] by_cases hi : i ∈ S <;> simp [hi] unfold hammingDist; rw [show Finset.univ.filter (fun i => (if i ∈ S then !y i else y i) ≠ y i) = S from this] exact (Finset.mem_filter.mp hS).2⟩, by ext i; simp only [φ, Finset.mem_filter, Finset.mem_univ, true_and]; by_cases hi : i ∈ S <;> simp [hi]⟩) rw [hbij] -- Partition subsets of size ≤ r by their exact cardinality j ∈ range (r + 1) have hpart : (Finset.univ : Finset (Finset (Fin M))).filter (fun S => S.card ≤ r) = (Finset.range (r + 1)).biUnion (fun j => Finset.powersetCard j (Finset.univ : Finset (Fin M))) := by ext S; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_biUnion, Finset.mem_range, Finset.mem_powersetCard, Finset.subset_univ] constructor · intro h; exact ⟨S.card, Nat.lt_succ_of_le h, rfl⟩ · rintro ⟨j, hj, hcard⟩; omega rw [hpart, Finset.card_biUnion] · refine Finset.sum_congr rfl fun j _ => by rw [Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] · intro a _ b _ hab change Disjoint _ _ rw [Finset.disjoint_left] intro S hSa hSb exact hab ((Finset.mem_powersetCard.mp hSa).2.symm.trans (Finset.mem_powersetCard.mp hSb).2) /-- **Theorem 4.2 (Exact Finite-State GSSM Hamming-Ball MQAR Error Bound)**: For ANY finite-state GSSM with state space `H` performing Multi-Query Associative Recall on `M` binary key-value pairs, the number of tables recalled with `≤ r` errors is at most `|H| · ∑_{j=0}^r C(M, j)`. Whenever `|H| · ∑_{j=0}^r C(M, j) < 2^M`, there MUST exist a key-value table on which the GSSM makes strictly more than `r` errors! -/ theorem finite_state_ssm_hamming_error_bound {M : ℕ} {H : Type*} [Fintype H] (ssm : FiniteStateSSM (Fin M → Bool) H (Fin M → Bool)) (r : ℕ) : (Finset.univ.filter (fun v : Fin M → Bool => hammingDist v (ssm.decode (ssm.encode v)) ≤ r)).card ≤ Fintype.card H * ∑ j ∈ Finset.range (r + 1), M.choose j ∧ (Fintype.card H * ∑ j ∈ Finset.range (r + 1), M.choose j < 2 ^ M → ∃ v : Fin M → Bool, r < hammingDist v (ssm.decode (ssm.encode v))) := by classical set Good := Finset.univ.filter (fun v : Fin M → Bool => hammingDist v (ssm.decode (ssm.encode v)) ≤ r) have hsub : Good ⊆ (Finset.univ : Finset H).biUnion (fun h => Finset.univ.filter (fun v : Fin M → Bool => hammingDist v (ssm.decode h) ≤ r)) := by intro v hv rw [Finset.mem_biUnion] exact ⟨ssm.encode v, Finset.mem_univ _, Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hv).2⟩⟩ have hcard : Good.card ≤ Fintype.card H * ∑ j ∈ Finset.range (r + 1), M.choose j := by calc Good.card ≤ ((Finset.univ : Finset H).biUnion (fun h => Finset.univ.filter (fun v : Fin M → Bool => hammingDist v (ssm.decode h) ≤ r))).card := Finset.card_le_card hsub _ ≤ ∑ h : H, (Finset.univ.filter (fun v : Fin M → Bool => hammingDist v (ssm.decode h) ≤ r)).card := Finset.card_biUnion_le _ = ∑ _h : H, ∑ j ∈ Finset.range (r + 1), M.choose j := Finset.sum_congr rfl fun h _ => card_hammingBall (ssm.decode h) r _ = Fintype.card H * ∑ j ∈ Finset.range (r + 1), M.choose j := by rw [Finset.sum_const, Finset.card_univ, smul_eq_mul] refine ⟨hcard, fun hlt => ?_⟩ by_contra hnot push Not at hnot have hGood : Good = Finset.univ := by ext v; simp [Good, hnot v] rw [hGood, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin] at hcard omega /-- An infinite-precision real Linear Time-Invariant (LTI) State-Space Model of state dimension `N`. -/ structure LTISSM (N : ℕ) where A : Matrix (Fin N) (Fin N) ℝ B : Fin N → ℝ C : Fin N → ℝ /-- Impulse response (Markov parameter) `Cᵀ A^k B` of an LTI SSM. -/ def ltiImpulse {N : ℕ} (sys : LTISSM N) (k : ℕ) : ℝ := dotProd sys.C ((sys.A ^ k).mulVec sys.B) /-- **Theorem 4.3 (Exact Infinite-Precision LTI SSM Delay-Line Hankel Obstruction `N ≥ L`)**: Any infinite-precision real LTI SSM `(A, B, C)` of state dimension `N` realizing a pure `L`-step delay-line copy (`Cᵀ A^m B = δ_{m, L-1}` for `0 ≤ m ≤ 2L - 2`) MUST have state dimension **`L ≤ N`**. Moreover, the `L`-dimensional shift register achieves `N = L`! -/ theorem lti_ssm_delay_copy_state_dim_ge {N L : ℕ} (sys : LTISSM N) (hdelay : ∀ m : ℕ, m ≤ 2 * L - 2 → ltiImpulse sys m = if m = L - 1 then 1 else 0) : L ≤ N := by -- Controllability map ctrl : (Fin L → ℝ) →ₗ[ℝ] (Fin N → ℝ), x ↦ ∑_j x_j (A^j B) let ctrl : (Fin L → ℝ) →ₗ[ℝ] (Fin N → ℝ) := { toFun := fun x r => ∑ j : Fin L, x j * ((sys.A ^ j.val).mulVec sys.B r) map_add' := fun x y => by ext r; simp [add_mul, Finset.sum_add_distrib] map_smul' := fun c x => by ext r; simp [mul_assoc, ← Finset.mul_sum] } -- Prove ctrl is injective: testing with Cᵀ A^i extracts x (L - 1 - i)! have hinj : Function.Injective ctrl := by rw [injective_iff_map_eq_zero] intro x hx ext k let i : Fin L := ⟨L - 1 - k.val, by omega⟩ have hzero : dotProd sys.C ((sys.A ^ i.val).mulVec (ctrl x)) = 0 := by rw [hx]; simp [dotProd, Matrix.mulVec_zero] have hcalc : dotProd sys.C ((sys.A ^ i.val).mulVec (ctrl x)) = ∑ j : Fin L, x j * ltiImpulse sys (i.val + j.val) := by have hvec : (sys.A ^ i.val).mulVec (ctrl x) = fun r => ∑ j : Fin L, x j * ((sys.A ^ (i.val + j.val)).mulVec sys.B r) := by ext r calc ((sys.A ^ i.val).mulVec (ctrl x)) r = ∑ s : Fin N, (sys.A ^ i.val) r s * ∑ j : Fin L, x j * ((sys.A ^ j.val).mulVec sys.B s) := rfl _ = ∑ j : Fin L, x j * ∑ s : Fin N, (sys.A ^ i.val) r s * ((sys.A ^ j.val).mulVec sys.B s) := by simp only [Finset.mul_sum]; rw [Finset.sum_comm] refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun s _ => by ring _ = ∑ j : Fin L, x j * ((sys.A ^ (i.val + j.val)).mulVec sys.B r) := by refine Finset.sum_congr rfl fun j _ => ?_ congr 1 change ((sys.A ^ i.val).mulVec ((sys.A ^ j.val).mulVec sys.B)) r = ((sys.A ^ (i.val + j.val)).mulVec sys.B) r rw [pow_add, Matrix.mulVec_mulVec] rw [hvec] simp only [dotProd, ltiImpulse, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun r _ => by ring rw [hcalc] at hzero have heval : ∑ j : Fin L, x j * ltiImpulse sys (i.val + j.val) = x k := by rw [Finset.sum_eq_single k] · have hik : i.val + k.val = L - 1 := by simp [i]; omega rw [hdelay (i.val + k.val) (by omega), if_pos hik, mul_one] · intro j _ hjk have hne : i.val + j.val ≠ L - 1 := by intro heq; apply hjk; ext; simp [i] at heq; omega rw [hdelay (i.val + j.val) (by have := i.isLt; have := j.isLt; omega), if_neg hne, mul_zero] · intro h; exact absurd (Finset.mem_univ k) h change x k = 0 linarith have hfin := LinearMap.finrank_le_finrank_of_injective hinj rwa [Module.finrank_fin_fun, Module.finrank_fin_fun] at hfin theorem shift_register_lti_achieves_delay (L : ℕ) (hL : 1 ≤ L) : let S : LTISSM L := { A := fun i j => if i.val = j.val + 1 then 1 else 0 B := fun i => if i.val = 0 then 1 else 0 C := fun i => if i.val = L - 1 then 1 else 0 } ∀ m : ℕ, ltiImpulse S m = if m = L - 1 then 1 else 0 := by intro S have hpow : ∀ m : ℕ, ∀ i : Fin L, ((S.A ^ m).mulVec S.B) i = if i.val = m then 1 else 0 := by intro m induction m with | zero => intro i; rw [pow_zero, Matrix.one_mulVec] | succ m ih => intro i rw [pow_succ', ← Matrix.mulVec_mulVec] change ∑ j : Fin L, S.A i j * ((S.A ^ m).mulVec S.B j) = if i.val = m + 1 then 1 else 0 by_cases hi : i.val = m + 1 · have hm : m < L := by omega rw [if_pos hi] rw [Finset.sum_eq_single ⟨m, hm⟩] · rw [ih ⟨m, hm⟩]; simp [S, hi] · intro j _ hj have hjne : j.val ≠ m := fun h => hj (Fin.ext h) rw [ih j, if_neg hjne, mul_zero] · intro h; exact absurd (Finset.mem_univ _) h · rw [if_neg hi] refine Finset.sum_eq_zero fun j _ => ?_ rw [ih j] by_cases hj : j.val = m · rw [if_pos hj, mul_one]; simp only [S]; rw [if_neg (by omega)] · rw [if_neg hj, mul_zero] intro m unfold ltiImpulse dotProd rw [Finset.sum_eq_single ⟨L - 1, by omega⟩] · rw [hpow m ⟨L - 1, by omega⟩] simp only [S, ↓reduceIte, one_mul] by_cases h : m = L - 1 · rw [if_pos h.symm, if_pos h] · rw [if_neg (Ne.symm h), if_neg h] · intro i _ hi have hne : i.val ≠ L - 1 := fun h => hi (Fin.ext h) simp [S, hne] · intro h; exact absurd (Finset.mem_univ _) h /-! ### Constructive Exponential & Unbounded-Length Softmax Transformer Separations -/ /-- Softmax attention universal sign recall criterion: if diagonal weights satisfy `A ν ν > 1/2` for every `ν`, then 1-layer Softmax Attention achieves exact universal sign recall across ALL `2^M` bipolar value tables! -/ lemma softmax_diag_gt_half_implies_universal_recall {M : ℕ} (S : Matrix (Fin M) (Fin M) ℝ) (hdiag : ∀ ν : Fin M, (1 / 2 : ℝ) < softmaxMatrix S ν ν) : ∀ v : Fin M → Bool, ∀ ν : Fin M, 0 < bipolar (v ν) * ∑ μ : Fin M, softmaxMatrix S ν μ * bipolar (v μ) := by have hst := softmaxMatrix_isRowStochastic S have hsdd : ∀ ν : Fin M, (∑ μ ∈ Finset.univ.erase ν, |softmaxMatrix S ν μ|) + |(0 : ℝ)| < softmaxMatrix S ν ν := by intro ν rw [abs_zero, add_zero] have hsum : ∑ μ ∈ Finset.univ.erase ν, |softmaxMatrix S ν μ| = 1 - softmaxMatrix S ν ν := by have h1 : ∑ μ ∈ Finset.univ.erase ν, |softmaxMatrix S ν μ| = ∑ μ ∈ Finset.univ.erase ν, softmaxMatrix S ν μ := Finset.sum_congr rfl fun μ _ => abs_of_nonneg (hst.1 ν μ) rw [h1] have h2 := Finset.add_sum_erase Finset.univ (fun μ => softmaxMatrix S ν μ) (Finset.mem_univ ν) rw [hst.2 ν] at h2 linarith linarith [hdiag ν] intro v ν have h := (linear_universal_sign_recall_iff_sdd (softmaxMatrix S) (fun _ => 0)).mpr hsdd v ν simpa only [add_zero] using h /-- Binary hypercube unit keys `k_u ∈ {±1/√d}^d` indexed by `Fin (2^d)` via bit representation. -/ noncomputable def hypercubeKey (d : ℕ) (u : Fin (2 ^ d)) : Fin d → ℝ := fun c => (if Nat.testBit u.val c.val then (1 : ℝ) else -1) / Real.sqrt (d : ℝ) /-- **Theorem 4.4 (Constructive `2^d` vs. `d` Exponential Width Separation — Softmax vs. Linear)**: For EVERY embedding dimension `d ≥ 1`, 1-layer Softmax Attention with `d`-dimensional hypercube keys (`M = 2^d` key-value pairs) and inverse temperature `β = d²` achieves **EXACT UNIVERSAL SIGN RECALL** across all `2^(2^d)` bipolar value tables. Meanwhile, by Theorem 3.6, EVERY linear attention / linear-readout SSM achieving universal sign recall on `M = 2^d` items MUST have state dimension **`D ≥ 2^d`**! -/ theorem hypercube_softmax_universal_recall (d : ℕ) (hd : 1 ≤ d) : let M := 2 ^ d let K := hypercubeKey d let S : Matrix (Fin M) (Fin M) ℝ := fun u w => ((d : ℝ) ^ 2) * dotProd (K u) (K w) (∀ u : Fin M, sqNorm (K u) = 1) ∧ (∀ v : Fin M → Bool, ∀ u : Fin M, 0 < bipolar (v u) * ∑ w : Fin M, softmaxMatrix S u w * bipolar (v w)) := by intro M K S have hdpos : (0 : ℝ) < d := Nat.cast_pos.mpr (by omega) have hunit : ∀ u : Fin M, sqNorm (K u) = 1 := by intro u unfold sqNorm dotProd K hypercubeKey have hterm : ∀ c : Fin d, ((if Nat.testBit u.val c.val then (1 : ℝ) else -1) / Real.sqrt d) * ((if Nat.testBit u.val c.val then (1 : ℝ) else -1) / Real.sqrt d) = 1 / (d : ℝ) := by intro c rw [div_mul_div_comm, Real.mul_self_sqrt hdpos.le] split_ifs <;> norm_num simp only [hterm, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] exact mul_one_div_cancel hdpos.ne' refine ⟨hunit, softmax_diag_gt_half_implies_universal_recall S ?_⟩ intro u -- For any w ≠ u, they differ in at least one bit c₀ < d, so dotProd (K u) (K w) ≤ 1 - 2/d have hoff : ∀ w : Fin M, w ≠ u → dotProd (K u) (K w) ≤ 1 - 2 / (d : ℝ) := by intro w hwu -- Since u.val ≠ w.val and both < 2^d, there exists bit c < d where testBit differs have hbit : ∃ c : Fin d, Nat.testBit u.val c.val ≠ Nat.testBit w.val c.val := by by_contra hall push Not at hall apply hwu; ext apply Nat.eq_of_testBit_eq intro k by_cases hk : k < d · exact (hall ⟨k, hk⟩).symm · have hu0 : Nat.testBit u.val k = false := Nat.testBit_lt_two_pow (lt_of_lt_of_le u.isLt (Nat.pow_le_pow_right (by omega) (Nat.not_lt.mp hk))) have hw0 : Nat.testBit w.val k = false := Nat.testBit_lt_two_pow (lt_of_lt_of_le w.isLt (Nat.pow_le_pow_right (by omega) (Nat.not_lt.mp hk))) rw [hu0, hw0] obtain ⟨c0, hc0⟩ := hbit unfold dotProd K hypercubeKey have hsplit := Finset.add_sum_erase Finset.univ (fun c : Fin d => ((if Nat.testBit u.val c.val then (1 : ℝ) else -1) / Real.sqrt d) * ((if Nat.testBit w.val c.val then (1 : ℝ) else -1) / Real.sqrt d)) (Finset.mem_univ c0) rw [← hsplit] have hc0_val : ((if Nat.testBit u.val c0.val then (1 : ℝ) else -1) / Real.sqrt d) * ((if Nat.testBit w.val c0.val then (1 : ℝ) else -1) / Real.sqrt d) = -(1 / (d : ℝ)) := by rw [div_mul_div_comm, Real.mul_self_sqrt hdpos.le] cases h1 : Nat.testBit u.val c0.val <;> cases h2 : Nat.testBit w.val c0.val <;> simp_all all_goals ring have hrest : ∑ c ∈ Finset.univ.erase c0, ((if Nat.testBit u.val c.val then (1 : ℝ) else -1) / Real.sqrt d) * ((if Nat.testBit w.val c.val then (1 : ℝ) else -1) / Real.sqrt d) ≤ ((d - 1 : ℕ) : ℝ) * (1 / (d : ℝ)) := by calc ∑ c ∈ Finset.univ.erase c0, _ ≤ ∑ _c ∈ Finset.univ.erase c0, (1 / (d : ℝ)) := by refine Finset.sum_le_sum fun c _ => ?_ rw [div_mul_div_comm, Real.mul_self_sqrt hdpos.le] apply div_le_div_of_nonneg_right _ hdpos.le split_ifs <;> norm_num _ = ((d - 1 : ℕ) : ℝ) * (1 / (d : ℝ)) := by rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ c0), Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have hdsub : ((d - 1 : ℕ) : ℝ) = (d : ℝ) - 1 := by rw [Nat.cast_sub hd, Nat.cast_one] rw [hc0_val] rw [hdsub] at hrest have hsimp : -(1 / (d : ℝ)) + ((d : ℝ) - 1) * (1 / (d : ℝ)) = 1 - 2 / (d : ℝ) := by field_simp [hdpos.ne']; ring linarith -- Show softmaxMatrix S u u > 1/2 by bounding off-diagonal sum < exp(S u u) unfold softmaxMatrix have hZpos : 0 < ∑ w : Fin M, Real.exp (S u w) := Finset.sum_pos (fun _ _ => Real.exp_pos _) ⟨u, Finset.mem_univ u⟩ rw [div_lt_div_iff₀ two_pos hZpos, one_mul, ← Finset.add_sum_erase _ _ (Finset.mem_univ u)] suffices htail : ∑ w ∈ Finset.univ.erase u, Real.exp (S u w) < Real.exp (S u u) by linarith have hSuu : S u u = (d : ℝ) ^ 2 := by change (d : ℝ) ^ 2 * sqNorm (K u) = (d : ℝ) ^ 2 rw [hunit u, mul_one] have hbound : ∑ w ∈ Finset.univ.erase u, Real.exp (S u w) ≤ ((M - 1 : ℕ) : ℝ) * Real.exp ((d : ℝ) ^ 2 - 2 * (d : ℝ)) := by calc ∑ w ∈ Finset.univ.erase u, Real.exp (S u w) ≤ ∑ _w ∈ Finset.univ.erase u, Real.exp ((d : ℝ) ^ 2 - 2 * (d : ℝ)) := by refine Finset.sum_le_sum fun w hw => Real.exp_le_exp.mpr ?_ have h1 := hoff w (Finset.mem_erase.mp hw).1 have h2 : (d : ℝ) ^ 2 * (1 - 2 / (d : ℝ)) = (d : ℝ) ^ 2 - 2 * (d : ℝ) := by field_simp [hdpos.ne'] rw [← h2] exact mul_le_mul_of_nonneg_left h1 (sq_nonneg _) _ = ((M - 1 : ℕ) : ℝ) * Real.exp ((d : ℝ) ^ 2 - 2 * (d : ℝ)) := by rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ u), Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] -- (2^d - 1) * exp(d^2 - 2d) < 2^d * exp(-2d) * exp(d^2) < exp(d^2) since 2 < exp(2) have h2lt : (2 : ℝ) < Real.exp 2 := by have := Real.add_one_le_exp (2 : ℝ); linarith have hpow_lt : (2 : ℝ) ^ d < Real.exp (2 * (d : ℝ)) := by calc (2 : ℝ) ^ d < (Real.exp 2) ^ d := pow_lt_pow_left₀ h2lt (by norm_num) (by omega) _ = Real.exp (2 * (d : ℝ)) := by rw [← Real.exp_nat_mul]; ring_nf have hMlt : ((M - 1 : ℕ) : ℝ) < (2 : ℝ) ^ d := by have h1 : 1 ≤ M := Nat.one_le_pow d 2 (by omega) rw [Nat.cast_sub h1, Nat.cast_one] simp only [M, Nat.cast_pow, Nat.cast_ofNat] linarith have hfin : ((M - 1 : ℕ) : ℝ) * Real.exp ((d : ℝ) ^ 2 - 2 * (d : ℝ)) < Real.exp ((d : ℝ) ^ 2) := by rw [Real.exp_sub] calc ((M - 1 : ℕ) : ℝ) * (Real.exp ((d : ℝ) ^ 2) / Real.exp (2 * (d : ℝ))) < Real.exp (2 * (d : ℝ)) * (Real.exp ((d : ℝ) ^ 2) / Real.exp (2 * (d : ℝ))) := mul_lt_mul_of_pos_right (lt_trans hMlt hpow_lt) (by positivity) _ = Real.exp ((d : ℝ) ^ 2) := by field_simp [(Real.exp_pos _).ne'] rw [hSuu] exact lt_of_le_of_lt hbound hfin theorem exponential_width_separation_softmax_vs_linear (d : ℕ) (hd : 1 ≤ d) : (∃ (K : Fin (2 ^ d) → (Fin d → ℝ)) (β : ℝ), let S : Matrix (Fin (2 ^ d)) (Fin (2 ^ d)) ℝ := fun u w => β * dotProd (K u) (K w) ∀ v : Fin (2 ^ d) → Bool, ∀ u : Fin (2 ^ d), 0 < bipolar (v u) * ∑ w : Fin (2 ^ d), softmaxMatrix S u w * bipolar (v w)) ∧ (∀ (D : ℕ) (Φ w : Fin (2 ^ d) → (Fin D → ℝ)) (b : Fin (2 ^ d) → ℝ), (∀ v : Fin (2 ^ d) → Bool, ∀ u : Fin (2 ^ d), 0 < bipolar (v u) * (dotProd (w u) (fun c => ∑ μ : Fin (2 ^ d), bipolar (v μ) * Φ μ c) + b u)) → 2 ^ d ≤ D) := ⟨⟨hypercubeKey d, (d : ℝ) ^ 2, (hypercube_softmax_universal_recall d hd).2⟩, fun _ Φ w b h => linear_universal_sign_recall_le_dim Φ w b h⟩ /-- Fixed `d = 2` circular positional keys `k_t = (cos(2π t / L), sin(2π t / L)) ∈ ℝ²`. -/ noncomputable def circularKey (L : ℕ) (t : Fin L) : Fin 2 → ℝ := fun c => if c = 0 then Real.cos (2 * Real.pi * (t.val : ℝ) / (L : ℝ)) else Real.sin (2 * Real.pi * (t.val : ℝ) / (L : ℝ)) /-- **Theorem 4.5 (Constructive Unbounded-Length `O(1)` vs. `L` Separation at Fixed `d = 2`)**: For EVERY sequence length `L ≥ 2`, a SINGLE 2-dimensional (`d = 2`, fixed independent of `L`!) Softmax Attention head with circular positional keys and `β = L² (log L + 1)` achieves **EXACT UNIVERSAL COPYING & ASSOCIATIVE RECALL** of ALL `2^L` binary strings of length `L`! Meanwhile, EVERY finite-state GSSM requires `|H| ≥ 2^L` states (`≥ L` bits), and EVERY linear-readout / LTI delay-line SSM requires state dimension `≥ L`! -/ theorem circular_2d_softmax_universal_copy (L : ℕ) (hL : 2 ≤ L) : let K := circularKey L let β := (L : ℝ) ^ 2 * (Real.log (L : ℝ) + 1) let S : Matrix (Fin L) (Fin L) ℝ := fun t s => β * dotProd (K t) (K s) (∀ t : Fin L, sqNorm (K t) = 1) ∧ (∀ v : Fin L → Bool, ∀ t : Fin L, 0 < bipolar (v t) * ∑ s : Fin L, softmaxMatrix S t s * bipolar (v s)) := by intro K β S have hLpos : (0 : ℝ) < L := Nat.cast_pos.mpr (by omega) have hL2 : (2 : ℝ) ≤ L := Nat.ofNat_le_cast.mpr hL have hunit : ∀ t : Fin L, sqNorm (K t) = 1 := by intro t; unfold sqNorm dotProd K circularKey rw [Fin.sum_univ_two] simp only [↓reduceIte, Fin.reduceEq] simpa [sq] using Real.cos_sq_add_sin_sq (2 * Real.pi * (t.val : ℝ) / (L : ℝ)) refine ⟨hunit, softmax_diag_gt_half_implies_universal_recall S ?_⟩ intro t -- Step 1: For any s ≠ t, dotProd (K t) (K s) ≤ 1 - 8 / L² have hoff : ∀ s : Fin L, s ≠ t → dotProd (K t) (K s) ≤ 1 - 8 / (L : ℝ) ^ 2 := by intro s hst have hdot : dotProd (K t) (K s) = Real.cos (2 * Real.pi * ((t.val : ℝ) - (s.val : ℝ)) / (L : ℝ)) := by unfold dotProd K circularKey rw [Fin.sum_univ_two] simp only [↓reduceIte, Fin.reduceEq] have harg : 2 * Real.pi * ((t.val : ℝ) - (s.val : ℝ)) / (L : ℝ) = 2 * Real.pi * (t.val : ℝ) / (L : ℝ) - 2 * Real.pi * (s.val : ℝ) / (L : ℝ) := by ring rw [harg, Real.cos_sub] rw [hdot] -- Set k = |t - s| ∈ {1, …, L - 1}, and m = min(k, L - k) ∈ {1, …, ⌊L/2⌋} let k : ℕ := if s.val ≤ t.val then t.val - s.val else s.val - t.val have hk1 : 1 ≤ k := by simp only [k]; split_ifs with h · have : s.val ≠ t.val := fun heq => hst (Fin.ext heq); omega · omega have hkL : k ≤ L - 1 := by have := t.isLt; have := s.isLt simp only [k]; split_ifs <;> omega let m : ℕ := min k (L - k) have hm1 : 1 ≤ m := le_min hk1 (by omega) have hmhalf : 2 * m ≤ L := by simp only [m]; omega have hcos_eq : Real.cos (2 * Real.pi * ((t.val : ℝ) - (s.val : ℝ)) / (L : ℝ)) = Real.cos (2 * Real.pi * (m : ℝ) / (L : ℝ)) := by have hk_cos : Real.cos (2 * Real.pi * ((t.val : ℝ) - (s.val : ℝ)) / (L : ℝ)) = Real.cos (2 * Real.pi * (k : ℝ) / (L : ℝ)) := by simp only [k]; split_ifs with h · rw [Nat.cast_sub h] · have hle : t.val ≤ s.val := Nat.le_of_not_ge h rw [Nat.cast_sub hle] have : 2 * Real.pi * ((t.val : ℝ) - (s.val : ℝ)) / (L : ℝ) = -(2 * Real.pi * ((s.val : ℝ) - (t.val : ℝ)) / (L : ℝ)) := by ring rw [this, Real.cos_neg] rw [hk_cos] rcases le_total k (L - k) with hkle | hklge · simp only [m, min_eq_left hkle] · simp only [m, min_eq_right hklge] have hsub : 2 * Real.pi * ((L - k : ℕ) : ℝ) / (L : ℝ) = 2 * Real.pi - 2 * Real.pi * (k : ℝ) / (L : ℝ) := by rw [Nat.cast_sub (by omega : k ≤ L)]; field_simp [hLpos.ne'] rw [hsub, Real.cos_two_pi_sub] rw [hcos_eq] -- Use cos(2θ) = 1 - 2 sin²(θ) with θ = π m / L ∈ [π/L, π/2] set θ := Real.pi * (m : ℝ) / (L : ℝ) have h2θ : 2 * Real.pi * (m : ℝ) / (L : ℝ) = 2 * θ := by ring rw [h2θ, Real.cos_two_mul'] have hθ0 : 0 ≤ θ := by positivity have hθpi2 : θ ≤ Real.pi / 2 := by have hm2 : 2 * (m : ℝ) ≤ (L : ℝ) := by exact_mod_cast hmhalf have hpi : 0 ≤ Real.pi := Real.pi_pos.le simp only [θ] rw [div_le_div_iff₀ hLpos two_pos] nlinarith have hsin_lb : 2 / (L : ℝ) ≤ Real.sin θ := by have h1 := Real.mul_le_sin hθ0 hθpi2 have h2 : 2 / Real.pi * θ = 2 * (m : ℝ) / (L : ℝ) := by simp only [θ]; field_simp [Real.pi_pos.ne', hLpos.ne'] have hm_ge1 : (1 : ℝ) ≤ (m : ℝ) := Nat.one_le_cast.mpr hm1 have h3 : 2 / (L : ℝ) ≤ 2 * (m : ℝ) / (L : ℝ) := div_le_div_of_nonneg_right (by linarith) hLpos.le linarith have hsin2 : 4 / (L : ℝ) ^ 2 ≤ Real.sin θ ^ 2 := by have : (2 / (L : ℝ)) ^ 2 = 4 / (L : ℝ) ^ 2 := by ring rw [← this] exact pow_le_pow_left₀ (by positivity) hsin_lb 2 have hcos_id : Real.cos θ ^ 2 - Real.sin θ ^ 2 = 1 - 2 * Real.sin θ ^ 2 := by linarith [Real.sin_sq_add_cos_sq θ] have h8 : 8 / (L : ℝ) ^ 2 = 2 * (4 / (L : ℝ) ^ 2) := by ring linarith -- Step 2: Deduce softmaxMatrix S t t > 1/2 unfold softmaxMatrix have hZpos : 0 < ∑ s : Fin L, Real.exp (S t s) := Finset.sum_pos (fun _ _ => Real.exp_pos _) ⟨t, Finset.mem_univ t⟩ rw [div_lt_div_iff₀ two_pos hZpos, one_mul, ← Finset.add_sum_erase _ _ (Finset.mem_univ t)] suffices htail : ∑ s ∈ Finset.univ.erase t, Real.exp (S t s) < Real.exp (S t t) by linarith have hlog0 : 0 ≤ Real.log (L : ℝ) := Real.log_nonneg (by linarith) have hβpos : 0 < β := by positivity have hStt : S t t = β := by change β * sqNorm (K t) = β rw [hunit t, mul_one] have hbound : ∑ s ∈ Finset.univ.erase t, Real.exp (S t s) ≤ ((L - 1 : ℕ) : ℝ) * Real.exp (β - 8 * (Real.log (L : ℝ) + 1)) := by calc ∑ s ∈ Finset.univ.erase t, Real.exp (S t s) ≤ ∑ _s ∈ Finset.univ.erase t, Real.exp (β - 8 * (Real.log (L : ℝ) + 1)) := by refine Finset.sum_le_sum fun s hs => Real.exp_le_exp.mpr ?_ have h1 := hoff s (Finset.mem_erase.mp hs).1 have h2 : β * (1 - 8 / (L : ℝ) ^ 2) = β - 8 * (Real.log (L : ℝ) + 1) := by simp only [β]; field_simp [hLpos.ne'] rw [← h2] exact mul_le_mul_of_nonneg_left h1 hβpos.le _ = ((L - 1 : ℕ) : ℝ) * Real.exp (β - 8 * (Real.log (L : ℝ) + 1)) := by rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ t), Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] have hLlt : ((L - 1 : ℕ) : ℝ) < (L : ℝ) := by rw [Nat.cast_sub (by omega : 1 ≤ L), Nat.cast_one]; linarith have hexp_ge : (L : ℝ) < Real.exp (8 * (Real.log (L : ℝ) + 1)) := by have h1 : Real.log (L : ℝ) < 8 * (Real.log (L : ℝ) + 1) := by linarith calc (L : ℝ) = Real.exp (Real.log (L : ℝ)) := (Real.exp_log hLpos).symm _ < Real.exp (8 * (Real.log (L : ℝ) + 1)) := Real.exp_lt_exp.mpr h1 have hfin : ((L - 1 : ℕ) : ℝ) * Real.exp (β - 8 * (Real.log (L : ℝ) + 1)) < Real.exp β := by rw [Real.exp_sub] calc ((L - 1 : ℕ) : ℝ) * (Real.exp β / Real.exp (8 * (Real.log (L : ℝ) + 1))) < Real.exp (8 * (Real.log (L : ℝ) + 1)) * (Real.exp β / Real.exp (8 * (Real.log (L : ℝ) + 1))) := mul_lt_mul_of_pos_right (lt_trans hLlt hexp_ge) (by positivity) _ = Real.exp β := by field_simp [(Real.exp_pos _).ne'] rw [hStt] exact lt_of_le_of_lt hbound hfin theorem unbounded_length_separation_2d_softmax_vs_ssm (L : ℕ) (hL : 2 ≤ L) : (∃ (K : Fin L → (Fin 2 → ℝ)) (β : ℝ), let S : Matrix (Fin L) (Fin L) ℝ := fun t s => β * dotProd (K t) (K s) ∀ v : Fin L → Bool, ∀ t : Fin L, 0 < bipolar (v t) * ∑ s : Fin L, softmaxMatrix S t s * bipolar (v s)) ∧ (∀ (H : Type) [Fintype H] (M : FiniteStateSSM (Fin L → Fin 2) H (Fin L → Fin 2)), (∀ w, M.decode (M.encode w) = w) → 2 ^ L ≤ Fintype.card H) ∧ (∀ (N : ℕ) (sys : LTISSM N), (∀ m, m ≤ 2 * L - 2 → ltiImpulse sys m = if m = L - 1 then 1 else 0) → L ≤ N) := ⟨⟨circularKey L, (L : ℝ) ^ 2 * (Real.log (L : ℝ) + 1), (circular_2d_softmax_universal_copy L hL).2⟩, fun _ _ M h => (finite_state_ssm_copy_accuracy_bound M).2 h, fun _ sys h => lti_ssm_delay_copy_state_dim_ge sys h⟩ end AttentionSSMMemoryDynamics /-! ## Axiom Verification Audit (All Headline Theorems) -/ #print axioms AttentionSSMMemoryDynamics.dobrushin_tv_eq_one_sub_min #print axioms AttentionSSMMemoryDynamics.dobrushin_diameter_contraction #print axioms AttentionSSMMemoryDynamics.dobrushin_submultiplicative #print axioms AttentionSSMMemoryDynamics.softmax_dobrushin_le_tanh #print axioms AttentionSSMMemoryDynamics.softmax_dobrushin_tanh_sharp_two #print axioms AttentionSSMMemoryDynamics.birkhoff_nonlinear_contraction #print axioms AttentionSSMMemoryDynamics.birkhoff_linear_contraction #print axioms AttentionSSMMemoryDynamics.self_attention_one_step_diam_bound #print axioms AttentionSSMMemoryDynamics.self_attention_cubic_collapse_rate #print axioms AttentionSSMMemoryDynamics.self_attention_antipodal_exact_dynamics #print axioms AttentionSSMMemoryDynamics.self_attention_bifurcation_threshold #print axioms AttentionSSMMemoryDynamics.sinkhorn_cross_ratio_invariant #print axioms AttentionSSMMemoryDynamics.sinkhorn_dobrushin_le_tanh #print axioms AttentionSSMMemoryDynamics.doubly_stochastic_mean_conservation #print axioms AttentionSSMMemoryDynamics.doubly_stochastic_dirichlet_variance_decay #print axioms AttentionSSMMemoryDynamics.doubly_stochastic_no_attention_sink #print axioms AttentionSSMMemoryDynamics.softmax_attention_sink_one_step_collapse #print axioms AttentionSSMMemoryDynamics.dobrushin_trace_lower_bound #print axioms AttentionSSMMemoryDynamics.residual_rollout_dobrushin_two_sided #print axioms AttentionSSMMemoryDynamics.residual_rollout_equality_iff #print axioms AttentionSSMMemoryDynamics.psd_residual_variance_lower_bound #print axioms AttentionSSMMemoryDynamics.non_psd_swap_rollout_annihilates_variance #print axioms AttentionSSMMemoryDynamics.causal_uniform_dobrushin_exact #print axioms AttentionSSMMemoryDynamics.causal_uniform_binomial_eigenvalue #print axioms AttentionSSMMemoryDynamics.causal_uniform_harmonic_plateau #print axioms AttentionSSMMemoryDynamics.causal_uniform_log_depth_barrier #print axioms AttentionSSMMemoryDynamics.welch_gram_frobenius_lower_bound #print axioms AttentionSSMMemoryDynamics.welch_hebbian_mse_lower_bound #print axioms AttentionSSMMemoryDynamics.mercedes_benz_tight_frame_equality #print axioms AttentionSSMMemoryDynamics.delta_rule_minimax_mse_lower_bound #print axioms AttentionSSMMemoryDynamics.linear_universal_sign_recall_iff_sdd #print axioms AttentionSSMMemoryDynamics.linear_universal_sign_recall_le_dim #print axioms AttentionSSMMemoryDynamics.decay_linear_recall_forgetting_horizon #print axioms AttentionSSMMemoryDynamics.finite_state_ssm_copy_accuracy_bound #print axioms AttentionSSMMemoryDynamics.finite_state_ssm_hamming_error_bound #print axioms AttentionSSMMemoryDynamics.lti_ssm_delay_copy_state_dim_ge #print axioms AttentionSSMMemoryDynamics.shift_register_lti_achieves_delay #print axioms AttentionSSMMemoryDynamics.hypercube_softmax_universal_recall #print axioms AttentionSSMMemoryDynamics.exponential_width_separation_softmax_vs_linear #print axioms AttentionSSMMemoryDynamics.circular_2d_softmax_universal_copy #print axioms AttentionSSMMemoryDynamics.unbounded_length_separation_2d_softmax_vs_ssm