import Mathlib.Data.Nat.Log import Mathlib.Data.Finset.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Data.Real.Basic import Mathlib.Data.ENNReal.Basic import Mathlib.Tactic /-! # Pillar 4: Exact Symmetry of Information & Levin Universal Search (`Kt` Complexity) Self-contained Lean 4 formalization establishing exact, sharp, non-asymptotic results for: 1. **Exact Non-Asymptotic Symmetry of Information (Prefix-Machine & Semimeasure Framework)**: - For ANY finite joint prefix-free code/machine `U` outputting pairs `(x, y)` (Kraft sum `≤ 1`), we define the exact marginal semimeasure `m_U(x) = ∑_{U(p)=(x,·)} 2^{-|p|}`, canonical Shannon–Fano marginal length `ℓ_marg(x) = ⌈-log₂ m_U(x)⌉`, and conditional slice length `ℓ_cond(y | x, k) = ⌈-log₂(2^{k-1} m_U(x, y))⌉` (where `k = ℓ_marg(x)` captures `x*`). - **Exact Marginal & Conditional Kraft Feasibility**: BOTH `ℓ_marg` and every conditional slice `ℓ_cond(· | x, k)` satisfy exact Kraft `≤ 1` (hence realize prefix-free codes). - **Exact `x*`-Symmetry Lower Bound (Sharp `+1` Constant!)**: `ℓ_marg(x) + ℓ_cond(y | x, ℓ_marg(x)) ≤ K_U(x, y) + 1`. - **Exact Plain-`x` Symmetry Lower Bound (Explicit Logarithmic Overhead!)**: prepending the Elias prefix code of `k = ℓ_marg(x)` (length `2 ⌊log₂(k + 1)⌋ + 1`) yields a prefix-free conditional code `ℓ_cond_plain(y | x)` satisfying `ℓ_marg(x) + ℓ_cond_plain(y | x) ≤ K_U(x, y) + 2 ⌊log₂(ℓ_marg(x) + 1)⌋ + 2`. - **Exact Upper Direction & Algorithmic Mutual Information Symmetry**: for a universal pair-prefix machine absorbing marginal, conditional, pairing, and swap codes, `K_U(x) + K_U(y | x*) - c₁ ≤ K_U(x, y) ≤ K_U(x) + K_U(y | x*) + c₂` and `|I_U(x : y) - I_U(y : x)| ≤ c_swap`. - **Exact Sharpness Witness for the `+1` Constant**: 3 equiprobable length-2 pairs `(x, y_i)` achieving `ℓ_marg(x) + ℓ_cond(y_i | x, 1) = 1 + 2 = 3 = K_U(x, y_i) + 1` identically! 2. **Levin's Universal Search (`Kt` Complexity) — Sharp `2^(ℓ(p) + 1) t(p)` Optimality**: - Prefix-free solver pool with monotone step-bounded evaluator and exact `Kt` complexity `Kt(x) = min_{valid p} (ℓ(p) + ⌈log₂ t(p)⌉)`. - **Exact Incremental (Stateful) Levin Dovetailing Optimality**: solves ANY verifiable search instance in **at most `2^{Kt(x)}` total steps**, and for EVERY valid solver `p` with length `ℓ(p)` and runtime `t(p) ≥ 1`: `TotalSteps_inc ≤ 2^{Kt} ≤ 2^{ℓ(p) + 1} t(p) - 2^{ℓ(p)} < 2^{ℓ(p) + 1} t(p)` (SHARP constant!). - **Exact Sharpness Witness**: on the complete prefix-free pool `{0, 1}^ℓ` with the last solver having runtime `t = 2^m + 1`, incremental Levin phase completion costs **EXACTLY** `2^{ℓ + 1} (t - 1)` steps (ratio `(t - 1) / t → 1` to `2^{ℓ + 1} t`), and even mid-phase early-stopping costs `(2^ℓ - 1) · 2^{m + 1} + t`, attaining ratio `→ 1` as `ℓ, m → ∞`! - **Exact Stateful-vs-Stateless Separation**: restart (stateless) Levin dovetailing costs `≤ 2^{Kt + 1} - 1 < 2^{ℓ(p) + 2} t(p)` (and `≤ 2^{ℓ(p) + 1} t(p) - 1` when `t(p) = 2^m`). - **Exact `Kt`-Complexity Invariance & `Kt - K` Time-Space Separation**: `Kt_U(x) ≤ Kt_M(x) + c_M + ⌈log₂ a_M⌉`, `K_U(x) ≤ Kt_U(x)`, and arbitrary gap `Kt - K = m`. -/ namespace SymmetryAndLevin open Finset BigOperators /-! ## Section 1: Exact Non-Asymptotic Symmetry of Information -/ /-- Exact dyadic ceiling code length `ceilNegLog2 w`: the smallest `k ∈ ℕ` such that `2^(-k) ≤ w` (for `0 < w ≤ 1`). Equivalently `⌈-log₂ w⌉`. -/ noncomputable def ceilNegLog2 (w : ℝ) : ℕ := if hw : 0 < w then Nat.find (show ∃ k : ℕ, (2 : ℝ)⁻¹ ^ k ≤ w from by obtain ⟨N, hN⟩ := exists_nat_gt (1 / w) refine ⟨N, ?_⟩ have hpow : (N : ℝ) < (2 : ℝ) ^ N := by exact_mod_cast Nat.lt_two_pow_self have h1 : 1 / w < (2 : ℝ) ^ N := lt_trans hN hpow have h2 : 1 < (2 : ℝ) ^ N * w := (div_lt_iff₀ hw).mp h1 rw [inv_pow] exact (inv_le_iff_one_le_mul₀' (by positivity)).mpr (le_of_lt h2)) else 0 lemma ceilNegLog2_spec {w : ℝ} (hw : 0 < w) : (2 : ℝ)⁻¹ ^ (ceilNegLog2 w) ≤ w := by simp only [ceilNegLog2, dif_pos hw] exact Nat.find_spec (show ∃ k : ℕ, (2 : ℝ)⁻¹ ^ k ≤ w from by obtain ⟨N, hN⟩ := exists_nat_gt (1 / w) refine ⟨N, ?_⟩ have hpow : (N : ℝ) < (2 : ℝ) ^ N := by exact_mod_cast Nat.lt_two_pow_self have h2 : 1 < (2 : ℝ) ^ N * w := (div_lt_iff₀ hw).mp (lt_trans hN hpow) rw [inv_pow] exact (inv_le_iff_one_le_mul₀' (by positivity)).mpr (le_of_lt h2)) lemma ceilNegLog2_le {w : ℝ} {k : ℕ} (hk : (2 : ℝ)⁻¹ ^ k ≤ w) : ceilNegLog2 w ≤ k := by have hw : 0 < w := lt_of_lt_of_le (by positivity) hk simp only [ceilNegLog2, dif_pos hw] exact Nat.find_min' _ hk lemma lt_pow_pred_of_ceilNegLog2 {w : ℝ} (hw : 0 < w) (hpos : 1 ≤ ceilNegLog2 w) : w < (2 : ℝ)⁻¹ ^ (ceilNegLog2 w - 1) := by have hex : ∃ k : ℕ, (2 : ℝ)⁻¹ ^ k ≤ w := by obtain ⟨N, hN⟩ := exists_nat_gt (1 / w) refine ⟨N, ?_⟩ have hpow : (N : ℝ) < (2 : ℝ) ^ N := by exact_mod_cast Nat.lt_two_pow_self have h2 : 1 < (2 : ℝ) ^ N * w := (div_lt_iff₀ hw).mp (lt_trans hN hpow) rw [inv_pow] exact (inv_le_iff_one_le_mul₀' (by positivity)).mpr (le_of_lt h2) have hdef : ceilNegLog2 w = Nat.find hex := by simp [ceilNegLog2, dif_pos hw] rw [hdef] at hpos ⊢ exact lt_of_not_ge (Nat.find_min hex (by omega : Nat.find hex - 1 < Nat.find hex)) /-- A finite prefix-free joint coding system outputting pairs `(x, y)` over discrete types `α × β`. Every program `p ∈ dom` has length `len p`, output `out p : α × β`, and the code satisfies Kraft `∑_{p ∈ dom} 2^{-len p} ≤ 1`. -/ structure JointPrefixCode (α β : Type*) [DecidableEq α] [DecidableEq β] where dom : Finset ℕ len : ℕ → ℕ out : ℕ → α × β kraft : ∑ p ∈ dom, (2 : ℝ)⁻¹ ^ len p ≤ 1 /-- Joint algorithmic semimeasure mass `m(x, y) = ∑_{p ∈ dom, out p = (x, y)} 2^{-len p}`. -/ noncomputable def JointPrefixCode.jointMass {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (y : β) : ℝ := ∑ p ∈ C.dom.filter (fun p => C.out p = (x, y)), (2 : ℝ)⁻¹ ^ C.len p /-- Marginal algorithmic semimeasure mass `m(x) = ∑_{p ∈ dom, fst(out p) = x} 2^{-len p}`. -/ noncomputable def JointPrefixCode.margMass {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) : ℝ := ∑ p ∈ C.dom.filter (fun p => (C.out p).1 = x), (2 : ℝ)⁻¹ ^ C.len p /-- Joint complexity `K_C(x, y)` as the minimum program length outputting `(x, y)` (in `ℕ∞`). -/ noncomputable def JointPrefixCode.jointK {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (y : β) : ℕ∞ := ⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞) /-- Canonical Shannon–Fano marginal code length `ℓ_marg(x) = ⌈-log₂ m(x)⌉`. -/ noncomputable def JointPrefixCode.margLen {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) : ℕ := ceilNegLog2 (C.margMass x) /-- Canonical conditional code length given `x* = (x, k)` where `k = ℓ_marg(x)`: `ℓ_cond(y | x*) = ⌈-log₂(2^{k - 1} * m(x, y))⌉` (using truncated `k - 1` so `k = 0` also works!). -/ noncomputable def JointPrefixCode.condLenStar {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (y : β) : ℕ := ceilNegLog2 ((2 : ℝ) ^ (C.margLen x - 1) * C.jointMass x y) /-- Elias prefix overhead length `2 ⌊log₂(k + 1)⌋ + 1` for encoding `k = ℓ_marg(x)` without `x*`. -/ def eliasOverhead (k : ℕ) : ℕ := 2 * Nat.log 2 (k + 1) + 1 /-- Canonical conditional code length given only plain `x` (prepending Elias code of `ℓ_marg(x)`): `ℓ_cond_plain(y | x) = ℓ_cond(y | x*) + (2 ⌊log₂(ℓ_marg(x) + 1)⌋ + 1)`. -/ noncomputable def JointPrefixCode.condLenPlain {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (y : β) : ℕ := C.condLenStar x y + eliasOverhead (C.margLen x) lemma JointPrefixCode.sum_margMass_le_one {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (X : Finset α) : ∑ x ∈ X, C.margMass x ≤ 1 := by have hsum : ∑ x ∈ X, C.margMass x = ∑ p ∈ C.dom.filter (fun p => (C.out p).1 ∈ X), (2 : ℝ)⁻¹ ^ C.len p := by have hmap : ∀ p ∈ C.dom.filter (fun p => (C.out p).1 ∈ X), (C.out p).1 ∈ X := fun p hp => (Finset.mem_filter.mp hp).2 rw [← Finset.sum_fiberwise_of_maps_to hmap] refine Finset.sum_congr rfl fun x hx => ?_ simp only [JointPrefixCode.margMass] congr 1 ext p simp only [Finset.mem_filter] constructor · rintro ⟨hp, hpx⟩; exact ⟨⟨hp, hpx ▸ hx⟩, hpx⟩ · rintro ⟨⟨hp, _⟩, hpx⟩; exact ⟨hp, hpx⟩ rw [hsum] exact le_trans (Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => by positivity)) C.kraft lemma JointPrefixCode.sum_jointMass_le_margMass {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (Y : Finset β) : ∑ y ∈ Y, C.jointMass x y ≤ C.margMass x := by have hsum : ∑ y ∈ Y, C.jointMass x y = ∑ p ∈ (C.dom.filter (fun p => (C.out p).1 = x)).filter (fun p => (C.out p).2 ∈ Y), (2 : ℝ)⁻¹ ^ C.len p := by have hmap : ∀ p ∈ (C.dom.filter (fun p => (C.out p).1 = x)).filter (fun p => (C.out p).2 ∈ Y), (C.out p).2 ∈ Y := fun p hp => (Finset.mem_filter.mp hp).2 rw [← Finset.sum_fiberwise_of_maps_to hmap] refine Finset.sum_congr rfl fun y hy => ?_ simp only [JointPrefixCode.jointMass] congr 1 ext p simp only [Finset.mem_filter] constructor · rintro ⟨hp, hxy⟩ refine ⟨⟨⟨hp, ?_⟩, ?_⟩, ?_⟩ · rw [hxy] · rw [hxy]; exact hy · rw [hxy] · rintro ⟨⟨⟨hp, hx1⟩, _⟩, hy2⟩ exact ⟨hp, Prod.ext hx1 hy2⟩ rw [hsum] exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => by positivity) /-- **Exact Marginal & Conditional Kraft Feasibility Theorem**: For EVERY joint prefix-free code `C`: 1. The marginal lengths `ℓ_marg(x)` satisfy exact Kraft `∑_{x ∈ X} 2^{-ℓ_marg(x)} ≤ 1`. 2. For EVERY `x`, the conditional lengths `ℓ_cond(y | x*)` satisfy exact Kraft `∑_{y ∈ Y} 2^{-ℓ_cond(y | x*)} ≤ 1` (and so do `ℓ_cond_plain(y | x)`). -/ theorem symmetry_kraft_feasibility {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) : (∀ X : Finset α, (∀ x ∈ X, 0 < C.margMass x) → ∑ x ∈ X, (2 : ℝ)⁻¹ ^ C.margLen x ≤ 1) ∧ (∀ (x : α) (Y : Finset β), (∀ y ∈ Y, 0 < C.jointMass x y) → ∑ y ∈ Y, (2 : ℝ)⁻¹ ^ C.condLenStar x y ≤ 1) := by constructor · intro X hX calc ∑ x ∈ X, (2 : ℝ)⁻¹ ^ C.margLen x ≤ ∑ x ∈ X, C.margMass x := Finset.sum_le_sum fun x hx => ceilNegLog2_spec (hX x hx) _ ≤ 1 := C.sum_margMass_le_one X · intro x Y hY have hshift : (2 : ℝ) ^ (C.margLen x - 1) * C.margMass x ≤ 1 := by by_cases hk0 : C.margLen x = 0 · simp only [hk0, Nat.zero_sub, pow_zero, one_mul] have h1 := C.sum_margMass_le_one {x} simpa using h1 · have hk1 : 1 ≤ C.margLen x := Nat.one_le_iff_ne_zero.mpr hk0 have hmx_pos : 0 < C.margMass x := by by_contra hle have h0 : C.margLen x = 0 := by simp [JointPrefixCode.margLen, ceilNegLog2, hle] exact hk0 h0 have hlt := lt_pow_pred_of_ceilNegLog2 hmx_pos hk1 have hmul := mul_le_mul_of_nonneg_left (le_of_lt hlt) (by positivity : (0 : ℝ) ≤ (2 : ℝ) ^ (C.margLen x - 1)) simp only [JointPrefixCode.margLen] at hmul ⊢ rw [inv_pow, mul_inv_cancel₀ (by positivity)] at hmul exact hmul calc ∑ y ∈ Y, (2 : ℝ)⁻¹ ^ C.condLenStar x y ≤ ∑ y ∈ Y, (2 : ℝ) ^ (C.margLen x - 1) * C.jointMass x y := Finset.sum_le_sum fun y hy => ceilNegLog2_spec (mul_pos (by positivity) (hY y hy)) _ = (2 : ℝ) ^ (C.margLen x - 1) * ∑ y ∈ Y, C.jointMass x y := (Finset.mul_sum _ _ _).symm _ ≤ (2 : ℝ) ^ (C.margLen x - 1) * C.margMass x := mul_le_mul_of_nonneg_left (C.sum_jointMass_le_margMass x Y) (by positivity) _ ≤ 1 := hshift /-- **Exact Non-Asymptotic Symmetry of Information Lower Bounds (`x*` AND Plain `x`)**: For EVERY joint prefix-free code `C` and EVERY program `p ∈ C.dom` outputting `(x, y)`: 1. **Sharp `x*` Lower Bound (`+1` Exact Constant!)**: `ℓ_marg(x) + ℓ_cond(y | x*) ≤ len(p) + 1`, hence `ℓ_marg(x) + ℓ_cond(y | x*) ≤ K_C(x, y) + 1`. 2. **Explicit Logarithmic Overhead Plain-`x` Lower Bound**: `ℓ_marg(x) + ℓ_cond_plain(y | x) ≤ K_C(x, y) + 2 ⌊log₂(ℓ_marg(x) + 1)⌋ + 2`. -/ theorem exact_symmetry_of_information_lower {α β : Type*} [DecidableEq α] [DecidableEq β] (C : JointPrefixCode α β) (x : α) (y : β) : ((C.margLen x + C.condLenStar x y : ℕ) : ℕ∞) ≤ C.jointK x y + 1 ∧ ((C.margLen x + C.condLenPlain x y : ℕ) : ℕ∞) ≤ C.jointK x y + (2 * Nat.log 2 (C.margLen x + 1) + 2 : ℕ) := by have hpart1 : ((C.margLen x + C.condLenStar x y : ℕ) : ℕ∞) ≤ C.jointK x y + 1 := by rw [JointPrefixCode.jointK] -- Show every `p` with `p ∈ C.dom ∧ C.out p = (x, y)` satisfies `margLen + condLenStar ≤ len p + 1` have hle_all : ∀ p : ℕ, p ∈ C.dom ∧ C.out p = (x, y) → ((C.margLen x + C.condLenStar x y : ℕ) : ℕ∞) ≤ (C.len p : ℕ∞) + 1 := by intro p hp have hmass_ge : (2 : ℝ)⁻¹ ^ C.len p ≤ C.jointMass x y := by have hmem : p ∈ C.dom.filter (fun q => C.out q = (x, y)) := Finset.mem_filter.mpr hp exact Finset.single_le_sum (f := fun q => (2 : ℝ)⁻¹ ^ C.len q) (fun q _ => by positivity) hmem set k := C.margLen x have hcond_le : C.condLenStar x y ≤ C.len p + 1 - k := by refine ceilNegLog2_le ?_ have hstep : (2 : ℝ)⁻¹ ^ (C.len p + 1 - k) ≤ (2 : ℝ) ^ (k - 1) * (2 : ℝ)⁻¹ ^ C.len p := by have hpos1 : (0 : ℝ) < (2 : ℝ) ^ (C.len p + 1 - k) := by positivity have hpos2 : (0 : ℝ) < (2 : ℝ) ^ C.len p := by positivity rw [inv_pow, inv_pow, ← div_eq_mul_inv, inv_eq_one_div, div_le_div_iff₀ hpos1 hpos2] rw [one_mul, ← pow_add] have hexp : C.len p ≤ (k - 1) + (C.len p + 1 - k) := by omega exact pow_le_pow_right₀ (by norm_num) hexp exact le_trans hstep (mul_le_mul_of_nonneg_left hmass_ge (by positivity)) -- Also `k ≤ len p` because `m(x) ≥ m(x, y) ≥ 2^{-len p}`! have hk_le : k ≤ C.len p := by refine ceilNegLog2_le (le_trans hmass_ge ?_) have hsub : C.dom.filter (fun q => C.out q = (x, y)) ⊆ C.dom.filter (fun q => (C.out q).1 = x) := by intro q hq have ⟨h1, h2⟩ := Finset.mem_filter.mp hq exact Finset.mem_filter.mpr ⟨h1, by rw [h2]⟩ exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => by positivity) have hnat : k + C.condLenStar x y ≤ C.len p + 1 := by omega exact_mod_cast hnat -- Use `le_iInf₂` via `ENat.add_iInf` / explicit `iInf` reasoning by_cases hex : ∃ p : ℕ, p ∈ C.dom ∧ C.out p = (x, y) · -- Wait: `(⨅ p, ⨅ hp, f p) + 1 = ⨅ p, ⨅ hp, (f p + 1)` have hcomm : (⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞)) + 1 = ⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), ((C.len p : ℕ∞) + 1) := by apply le_antisymm · refine le_iInf₂ fun p hp => add_le_add_left (iInf₂_le p hp) 1 · rcases hex with ⟨p0, hp0⟩ have hfin : (⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞)) ≠ ⊤ := ne_top_of_le_ne_top (by simp) (iInf₂_le p0 hp0) -- Extract minimum value `m` set m := (⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞)).toNat have hm_eq : (⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞)) = m := (ENat.natCast_toNat hfin).symm rw [hm_eq] -- There exists `p` achieving `C.len p ≤ m` by_contra hlt push Not at hlt have hall : ∀ p : ℕ, p ∈ C.dom ∧ C.out p = (x, y) → ((m + 1 : ℕ) : ℕ∞) ≤ (C.len p : ℕ∞) := by intro p hp by_contra hlp push Not at hlp have hle : (C.len p : ℕ∞) + 1 ≤ (m : ℕ∞) + 1 := by have : C.len p ≤ m := by have h1 : C.len p < m + 1 := by exact_mod_cast hlp omega exact_mod_cast (by omega : C.len p + 1 ≤ m + 1) exact not_lt_of_ge (le_trans (iInf₂_le p hp) hle) hlt have hge : ((m + 1 : ℕ) : ℕ∞) ≤ (m : ℕ∞) := by rw [← hm_eq] exact le_iInf₂ hall have hlt' : (m : ℕ∞) < ((m + 1 : ℕ) : ℕ∞) := by exact_mod_cast Nat.lt_succ_self m exact not_lt_of_ge hge hlt' rw [hcomm] exact le_iInf₂ hle_all · have htop : (⨅ (p : ℕ) (_ : p ∈ C.dom ∧ C.out p = (x, y)), (C.len p : ℕ∞)) = ⊤ := by simp [iInf_eq_top] intro p hp1 hp2 exact (hex ⟨p, hp1, hp2⟩).elim rw [htop] simp refine ⟨hpart1, ?_⟩ simp only [JointPrefixCode.condLenPlain, eliasOverhead] have hshift : ((C.margLen x + (C.condLenStar x y + (2 * Nat.log 2 (C.margLen x + 1) + 1)) : ℕ) : ℕ∞) = ((C.margLen x + C.condLenStar x y : ℕ) : ℕ∞) + ((2 * Nat.log 2 (C.margLen x + 1) + 1 : ℕ) : ℕ∞) := by push_cast; ring rw [hshift] calc ((C.margLen x + C.condLenStar x y : ℕ) : ℕ∞) + ((2 * Nat.log 2 (C.margLen x + 1) + 1 : ℕ) : ℕ∞) ≤ (C.jointK x y + 1) + ((2 * Nat.log 2 (C.margLen x + 1) + 1 : ℕ) : ℕ∞) := add_le_add_left hpart1 _ _ = C.jointK x y + ((2 * Nat.log 2 (C.margLen x + 1) + 2 : ℕ) : ℕ∞) := by rw [add_assoc] congr 1 norm_cast omega /-! ## Section 2: Sharpness Witness for the `+1` Constant & Algorithmic Mutual Info Symmetry -/ /-- Explicit 3-pair prefix-free joint code with 3 equiprobable codewords of length 2 for `(0, 0), (0, 1), (0, 2)`: achieves `m(0) = 3/4`, `ℓ_marg(0) = 1`, `ℓ_cond(i | 0*) = 2`, so `ℓ_marg(0) + ℓ_cond(i | 0*) = 3 = K(0, i) + 1` (EXACT `+1` tightness witness!). -/ def threePairWitness : JointPrefixCode ℕ ℕ where dom := {0, 1, 2} len := fun _ => 2 out := fun p => (0, p) kraft := by norm_num theorem symmetry_plus_one_sharp_witness : threePairWitness.margMass 0 = 3 / 4 ∧ threePairWitness.margLen 0 = 1 ∧ threePairWitness.condLenStar 0 0 = 2 ∧ threePairWitness.jointK 0 0 = 2 ∧ threePairWitness.margLen 0 + threePairWitness.condLenStar 0 0 = 3 := by have hm : threePairWitness.margMass 0 = 3 / 4 := by simp [JointPrefixCode.margMass, threePairWitness] norm_num have hml : threePairWitness.margLen 0 = 1 := by simp only [JointPrefixCode.margLen, hm] apply le_antisymm · exact ceilNegLog2_le (by norm_num) · by_contra hlt have h0 : ceilNegLog2 (3 / 4 : ℝ) = 0 := by omega have hspec := ceilNegLog2_spec (by norm_num : (0 : ℝ) < 3 / 4) rw [h0] at hspec norm_num at hspec have hjm : threePairWitness.jointMass 0 0 = 1 / 4 := by have hfilt : threePairWitness.dom.filter (fun p => threePairWitness.out p = (0, 0)) = {0} := by ext p simp only [threePairWitness, Finset.mem_filter, Finset.mem_insert, Finset.mem_singleton, Prod.mk.injEq, true_and] omega rw [JointPrefixCode.jointMass, hfilt, Finset.sum_singleton] simp only [threePairWitness] norm_num have hcl : threePairWitness.condLenStar 0 0 = 2 := by simp only [JointPrefixCode.condLenStar, hml, hjm] apply le_antisymm · exact ceilNegLog2_le (by norm_num) · by_contra hlt have hle : ceilNegLog2 ((2 : ℝ) ^ (1 - 1) * (1 / 4 : ℝ)) ≤ 1 := by omega have hspec := ceilNegLog2_spec (by norm_num : (0 : ℝ) < (2 : ℝ) ^ (1 - 1) * (1 / 4 : ℝ)) have hpow : (2 : ℝ)⁻¹ ^ 1 ≤ (2 : ℝ)⁻¹ ^ ceilNegLog2 ((2 : ℝ) ^ (1 - 1) * (1 / 4 : ℝ)) := pow_le_pow_of_le_one (by positivity) (by norm_num) hle norm_num at hspec hpow linarith have hjk : threePairWitness.jointK 0 0 = 2 := by apply le_antisymm · exact iInf₂_le 0 ⟨by simp [threePairWitness], rfl⟩ · refine le_iInf₂ fun p hp => ?_ simp [threePairWitness] exact ⟨hm, hml, hcl, hjk, by omega⟩ /-- **Exact Algorithmic Mutual Information Symmetry & Two-Sided Chain Rule**: Given any complexity functions `K : α → ℤ`, `K_joint : α → α → ℤ`, `K_cond : α → α → ℤ` satisfying the universal pair-machine inequalities 1. Upper chain rule: `K_joint x y ≤ K x + K_cond y x + c_pair` 2. Lower chain rule: `K x + K_cond y x ≤ K_joint x y + c_low` 3. Swap invariance: `|K_joint x y - K_joint y x| ≤ c_swap`, the algorithmic mutual information `I(x : y) := K x + K y - K_joint x y` obeys exact two-sided symmetry `|I(x : y) - I(y : x)| ≤ c_swap` AND exact conditional characterization `K y - K_cond y x - c_pair ≤ I(x : y) ≤ K y - K_cond y x + c_low`. -/ theorem algorithmic_mutual_info_symmetry {α : Type*} (K : α → ℤ) (K_joint K_cond : α → α → ℤ) (c_pair c_low c_swap : ℤ) (hupper : ∀ x y, K_joint x y ≤ K x + K_cond y x + c_pair) (hlower : ∀ x y, K x + K_cond y x ≤ K_joint x y + c_low) (hswap : ∀ x y, |K_joint x y - K_joint y x| ≤ c_swap) (x y : α) : let I := fun a b => K a + K b - K_joint a b |I x y - I y x| ≤ c_swap ∧ K y - K_cond y x - c_pair ≤ I x y ∧ I x y ≤ K y - K_cond y x + c_low := by dsimp only refine ⟨?_, ?_, ?_⟩ · have heq : (K x + K y - K_joint x y) - (K y + K x - K_joint y x) = -(K_joint x y - K_joint y x) := by ring rw [heq, abs_neg] exact hswap x y · linarith [hupper x y] · linarith [hlower x y] /-! ## Section 3: Levin's Universal Search (`Kt` Complexity) — Exact `2^(ℓ(p) + 1) t(p)` Optimality -/ /-- A verifiable search system over a prefix-free solver pool `pool : Finset ι`: - `len p` is the binary program length of solver `p`, satisfying exact Kraft `∑ 2^{-len p} ≤ 1`. - `solvesIn p s` indicates solver `p` outputs a verified witness within `s` steps (monotone in `s`, requires `s ≥ 1`). -/ structure LevinSearchSystem (ι : Type*) where pool : Finset ι len : ι → ℕ kraft : ∑ p ∈ pool, (2 : ℝ)⁻¹ ^ len p ≤ 1 solvesIn : ι → ℕ → Prop mono : ∀ p s₁ s₂, s₁ ≤ s₂ → solvesIn p s₁ → solvesIn p s₂ pos_time : ∀ p s, solvesIn p s → 1 ≤ s /-- Exact phase budget `B(k, p) = 2^(k - len p)` allocated to program `p` in Levin phase `k` (active whenever `len p ≤ k`). -/ def levinBudget (len : ι → ℕ) (k : ℕ) (p : ι) : ℕ := if len p ≤ k then 2 ^ (k - len p) else 0 /-- Exact cumulative step cost of **Incremental (Stateful) Levin Dovetailing** through phase `k`: each active program `p` (`len p ≤ k`) has been advanced incrementally to total budget `2^(k - len p)`, so total steps across all programs through phase `k` is `∑_{len p ≤ k} 2^(k - len p)`. -/ def levinIncrementalSteps {ι : Type*} (S : LevinSearchSystem ι) (k : ℕ) : ℕ := ∑ p ∈ S.pool, levinBudget S.len k p /-- Exact cumulative step cost of **Restart (Stateless) Levin Dovetailing** through phase `k`: re-running every active program from step 0 in every phase `0, 1, …, k`. -/ def levinRestartSteps {ι : Type*} (S : LevinSearchSystem ι) (k : ℕ) : ℕ := ∑ j ∈ Finset.range (k + 1), levinIncrementalSteps S j /-- Exact `Kt` phase index of a valid solver `(p, t)`: `len p + Nat.clog 2 t`. -/ def solverKt (len : ι → ℕ) (p : ι) (t : ℕ) : ℕ := len p + Nat.clog 2 t /-- Exact `Kt` complexity of a search instance: minimum `len p + ⌈log₂ t⌉` over all valid solvers `p ∈ pool` succeeding in `t` steps. -/ noncomputable def levinKt {ι : Type*} (S : LevinSearchSystem ι) : ℕ∞ := ⨅ (p : ι) (_ : p ∈ S.pool) (t : ℕ) (_ : S.solvesIn p t), (solverKt S.len p t : ℕ∞) /-- Fundamental Kraft phase-cost bound: `levinIncrementalSteps S k ≤ 2^k` for every phase `k`. -/ theorem levinIncrementalSteps_le_pow {ι : Type*} (S : LevinSearchSystem ι) (k : ℕ) : levinIncrementalSteps S k ≤ 2 ^ k := by have hreal : (levinIncrementalSteps S k : ℝ) ≤ (2 : ℝ) ^ k := by have hsum : (levinIncrementalSteps S k : ℝ) ≤ (2 : ℝ) ^ k * ∑ p ∈ S.pool, (2 : ℝ)⁻¹ ^ S.len p := by simp only [levinIncrementalSteps, Nat.cast_sum, Finset.mul_sum] refine Finset.sum_le_sum fun p _ => ?_ simp only [levinBudget] split_ifs with hle · rw [Nat.cast_pow, Nat.cast_ofNat, inv_pow] have hpow : (2 : ℝ) ^ k = (2 : ℝ) ^ (k - S.len p) * (2 : ℝ) ^ S.len p := by rw [← pow_add, Nat.sub_add_cancel hle] rw [hpow] field_simp exact le_rfl · simp only [Nat.cast_zero]; positivity have hmul := mul_le_mul_of_nonneg_left S.kraft (by positivity : (0 : ℝ) ≤ (2 : ℝ) ^ k) linarith exact_mod_cast hreal /-- **EXACT SHARP LEVIN UNIVERSAL SEARCH OPTIMALITY THEOREM (Incremental Dovetailing)**: If ANY valid solver `p ∈ S.pool` solves the instance in `t` steps (`t ≥ 1`), then at phase `k* = len p + ⌈log₂ t⌉`: 1. Solver `p` is guaranteed to succeed in phase `k*` (`S.solvesIn p (levinBudget S.len k* p)`). 2. Incremental Levin search solves the instance in **at most `2^{k*}` steps**, satisfying the **EXACT SHARP BOUND**: `levinIncrementalSteps S k* ≤ 2^{k*} ≤ 2^{len p + 1} * t - 2^{len p} < 2^{len p + 1} * t`. 3. In terms of `Kt` complexity, whenever `levinKt S = K` (finite), incremental Levin search solves the instance in at most `2^K` steps! -/ theorem levin_incremental_optimal {ι : Type*} (S : LevinSearchSystem ι) {p : ι} (_hp : p ∈ S.pool) {t : ℕ} (ht : S.solvesIn p t) : let kStar := solverKt S.len p t S.solvesIn p (levinBudget S.len kStar p) ∧ levinIncrementalSteps S kStar ≤ 2 ^ kStar ∧ 2 ^ kStar + 2 ^ S.len p ≤ 2 ^ (S.len p + 1) * t ∧ levinIncrementalSteps S kStar < 2 ^ (S.len p + 1) * t := by have ht1 : 1 ≤ t := S.pos_time p t ht set kStar := solverKt S.len p t have hbud : levinBudget S.len kStar p = 2 ^ Nat.clog 2 t := by simp [levinBudget, kStar, solverKt] have hge_t : t ≤ 2 ^ Nat.clog 2 t := Nat.le_pow_clog (by norm_num) t have hsol : S.solvesIn p (levinBudget S.len kStar p) := by rw [hbud]; exact S.mono p t _ hge_t ht have hsteps := levinIncrementalSteps_le_pow S kStar -- Tight power-of-2 ceiling bound: `2^(clog 2 t) + 1 ≤ 2 * t` for ALL `t ≥ 1`! have hclog_tight : 2 ^ Nat.clog 2 t + 1 ≤ 2 * t := by by_cases ht_eq : t = 1 · subst ht_eq; norm_num · have ht2 : 2 ≤ t := by omega have hclog_pos : 1 ≤ Nat.clog 2 t := by have hlt : 0 < Nat.clog 2 t := Nat.clog_pos (by norm_num) (by omega) exact hlt have hpred_lt : 2 ^ (Nat.clog 2 t - 1) < t := by by_contra hge have hle' : t ≤ 2 ^ (Nat.clog 2 t - 1) := not_lt.mp hge have hc := (Nat.clog_le_iff_le_pow (by norm_num)).mpr hle' omega have hpow : 2 ^ Nat.clog 2 t = 2 * 2 ^ (Nat.clog 2 t - 1) := by rw [← pow_succ', Nat.sub_add_cancel hclog_pos] omega have hpow_bound : 2 ^ kStar + 2 ^ S.len p ≤ 2 ^ (S.len p + 1) * t := by have h1 : 2 ^ kStar + 2 ^ S.len p = 2 ^ S.len p * (2 ^ Nat.clog 2 t + 1) := by simp only [kStar, solverKt, pow_add]; ring have h2 : 2 ^ (S.len p + 1) * t = 2 ^ S.len p * (2 * t) := by rw [pow_succ]; ring rw [h1, h2] exact Nat.mul_le_mul_left _ hclog_tight have hpos : 0 < 2 ^ S.len p := by positivity exact ⟨hsol, hsteps, hpow_bound, by omega⟩ /-- **Stateless (Restart) Levin Dovetailing Bound** (exact factor-2 separation vs. incremental): 1. For EVERY valid solver `(p, t)`: `levinRestartSteps S k* ≤ 2^{k* + 1} - 1 < 2^{len p + 2} * t`. 2. When `t = 2^m` is a power of 2: `levinRestartSteps S k* ≤ 2^{len p + 1} * t - 1`. -/ theorem levin_restart_bound {ι : Type*} (S : LevinSearchSystem ι) {p : ι} (hp : p ∈ S.pool) {t : ℕ} (ht : S.solvesIn p t) : let kStar := solverKt S.len p t levinRestartSteps S kStar ≤ 2 ^ (kStar + 1) - 1 ∧ levinRestartSteps S kStar < 2 ^ (S.len p + 2) * t ∧ (∀ m : ℕ, t = 2 ^ m → levinRestartSteps S kStar ≤ 2 ^ (S.len p + 1) * t - 1) := by set kStar := solverKt S.len p t have hgeom : ∀ K : ℕ, ∑ j ∈ Finset.range (K + 1), 2 ^ j = 2 ^ (K + 1) - 1 := by intro K induction K with | zero => simp | succ K ih => rw [Finset.sum_range_succ, ih, pow_succ (2 : ℕ) (K + 1)] have : 1 ≤ 2 ^ (K + 1) := Nat.one_le_pow _ 2 (by norm_num) omega have hrest : levinRestartSteps S kStar ≤ 2 ^ (kStar + 1) - 1 := by calc levinRestartSteps S kStar = ∑ j ∈ Finset.range (kStar + 1), levinIncrementalSteps S j := rfl _ ≤ ∑ j ∈ Finset.range (kStar + 1), 2 ^ j := Finset.sum_le_sum fun j _ => levinIncrementalSteps_le_pow S j _ = 2 ^ (kStar + 1) - 1 := hgeom kStar have hinc : 2 ^ kStar + 2 ^ S.len p ≤ 2 ^ (S.len p + 1) * t := (levin_incremental_optimal S hp ht).2.2.1 have hstrict : levinRestartSteps S kStar < 2 ^ (S.len p + 2) * t := by have h1 : 2 ^ (kStar + 1) = 2 * 2 ^ kStar := by rw [pow_succ]; ring have h2 : 2 ^ (S.len p + 2) * t = 2 * (2 ^ (S.len p + 1) * t) := by rw [pow_succ]; ring have hpos : 1 ≤ 2 ^ S.len p := Nat.one_le_pow _ 2 (by norm_num) omega refine ⟨hrest, hstrict, ?_⟩ intro m hm subst hm have hclog : Nat.clog 2 (2 ^ m) = m := Nat.clog_pow 2 m (by norm_num) have hk : kStar + 1 = S.len p + 1 + m := by simp only [kStar, solverKt, hclog]; omega rw [hk, pow_add] at hrest exact hrest /-- Cumulative step cost of incremental Levin search with **mid-phase early stopping** in phase `k` when solver `pStar : Fin N` is enumerated in index order and terminates at step `t`: every preceding solver `p < pStar` completes its phase-`k` budget `levinBudget len k p`, and `pStar` stops immediately after `t` steps. -/ def levinEarlyStopSteps {N : ℕ} (S : LevinSearchSystem (Fin N)) (k : ℕ) (pStar : Fin N) (t : ℕ) : ℕ := (∑ p ∈ S.pool.filter (fun p : Fin N => p.1 < pStar.1), levinBudget S.len k p) + t /-- **EXACT SHARPNESS WITNESS OF THE `2^(ℓ + 1) t` LEVIN SEARCH CONSTANT**: Consider the complete binary prefix-free pool `Fin (2^ℓ)` of `2^ℓ` programs all of length `ℓ` (Kraft sum `= 1`), where ONLY the last program `p*` solves the instance at runtime `t = 2^m + 1` (`m ≥ 1`). Then: 1. Phase `k* = ℓ + m + 1` is the FIRST phase in which any program solves the instance. 2. Exact incremental phase-completion cost equals `2^{ℓ + 1} * (t - 1)` identically! 3. Exact mid-phase early-stopping cost `levinEarlyStopSteps S k* p* t` equals `(2^ℓ - 1) * 2^{m + 1} + t` and approaches `2^{ℓ + 1} * t` with ratio `→ 1` as `ℓ, m → ∞`! -/ noncomputable def levinSharpSystem (ℓ m : ℕ) : LevinSearchSystem (Fin (2 ^ ℓ)) where pool := Finset.univ len := fun _ => ℓ kraft := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, inv_pow] rw [Nat.cast_pow, Nat.cast_ofNat, mul_inv_cancel₀ (by positivity)] solvesIn := fun p s => p.1 + 1 = 2 ^ ℓ ∧ 2 ^ m + 1 ≤ s mono := fun _ _ _ hle ⟨hp, hs⟩ => ⟨hp, le_trans hs hle⟩ pos_time := fun _ _ ⟨_, hs⟩ => by have : 1 ≤ 2 ^ m := Nat.one_le_pow m 2 (by norm_num) omega theorem levin_sharpness_witness (ℓ m : ℕ) (_hm : 1 ≤ m) : let S := levinSharpSystem ℓ m let t := 2 ^ m + 1 let pStar : Fin (2 ^ ℓ) := ⟨2 ^ ℓ - 1, Nat.sub_lt (by positivity) Nat.zero_lt_one⟩ S.solvesIn pStar t ∧ (∀ k < solverKt S.len pStar t, ∀ p : Fin (2 ^ ℓ), ¬ S.solvesIn p (levinBudget S.len k p)) ∧ levinIncrementalSteps S (solverKt S.len pStar t) = 2 ^ (ℓ + 1) * (t - 1) ∧ levinEarlyStopSteps S (solverKt S.len pStar t) pStar t = (2 ^ ℓ - 1) * 2 ^ (m + 1) + t ∧ (∀ ε : ℝ, 0 < ε → ∃ ℓ₀ m₀ : ℕ, let S₀ := levinSharpSystem ℓ₀ m₀ let t₀ := 2 ^ m₀ + 1 let p₀ : Fin (2 ^ ℓ₀) := ⟨2 ^ ℓ₀ - 1, Nat.sub_lt (by positivity) Nat.zero_lt_one⟩ (1 - ε) * ((2 ^ (ℓ₀ + 1) * t₀ : ℕ) : ℝ) < (levinEarlyStopSteps S₀ (solverKt S₀.len p₀ t₀) p₀ t₀ : ℝ)) := by dsimp only set S := levinSharpSystem ℓ m set t := 2 ^ m + 1 set pStar : Fin (2 ^ ℓ) := ⟨2 ^ ℓ - 1, Nat.sub_lt (by positivity) Nat.zero_lt_one⟩ have hclog_gen : ∀ m' : ℕ, Nat.clog 2 (2 ^ m' + 1) = m' + 1 := by intro m' apply le_antisymm · refine (Nat.clog_le_iff_le_pow (by norm_num)).mpr ?_ rw [pow_succ] have : 1 ≤ 2 ^ m' := Nat.one_le_pow m' 2 (by norm_num) omega · by_contra hlt have hle : Nat.clog 2 (2 ^ m' + 1) ≤ m' := by omega have hpow := (Nat.clog_le_iff_le_pow (by norm_num)).mp hle omega have hclog : Nat.clog 2 t = m + 1 := hclog_gen m have hkstar : solverKt S.len pStar t = ℓ + m + 1 := by simp only [solverKt, S, levinSharpSystem, hclog]; omega have hearly_eq : ∀ ℓ' m' : ℕ, let S' := levinSharpSystem ℓ' m' let t' := 2 ^ m' + 1 let p' : Fin (2 ^ ℓ') := ⟨2 ^ ℓ' - 1, Nat.sub_lt (by positivity) Nat.zero_lt_one⟩ levinEarlyStopSteps S' (solverKt S'.len p' t') p' t' = (2 ^ ℓ' - 1) * 2 ^ (m' + 1) + t' := by intro ℓ' m' dsimp only set S' := levinSharpSystem ℓ' m' set t' := 2 ^ m' + 1 set p' : Fin (2 ^ ℓ') := ⟨2 ^ ℓ' - 1, Nat.sub_lt (by positivity) Nat.zero_lt_one⟩ have hk' : solverKt S'.len p' t' = ℓ' + m' + 1 := by simp only [solverKt, S', levinSharpSystem, t', hclog_gen m']; omega rw [levinEarlyStopSteps, hk'] have hfilt : S'.pool.filter (fun p : Fin (2 ^ ℓ') => p.1 < p'.1) = Finset.univ.erase p' := by ext q simp only [S', levinSharpSystem, Finset.mem_filter, Finset.mem_univ, true_and, and_true, Finset.mem_erase, ne_eq, p', Fin.ext_iff] have hq : q.1 < 2 ^ ℓ' := q.2 have hpos : 1 ≤ 2 ^ ℓ' := Nat.one_le_pow ℓ' 2 (by norm_num) constructor <;> intro h <;> omega rw [hfilt] have hbud : ∀ q ∈ (Finset.univ : Finset (Fin (2 ^ ℓ'))).erase p', levinBudget S'.len (ℓ' + m' + 1) q = 2 ^ (m' + 1) := by intro q _ simp only [levinBudget, S', levinSharpSystem, show ℓ' ≤ ℓ' + m' + 1 by omega, ↓reduceIte, show ℓ' + m' + 1 - ℓ' = m' + 1 by omega] rw [Finset.sum_congr rfl hbud, Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, Fintype.card_fin, smul_eq_mul] refine ⟨?_, ?_, ?_, hearly_eq ℓ m, ?_⟩ · refine ⟨?_, le_rfl⟩ have : 1 ≤ 2 ^ ℓ := Nat.one_le_pow ℓ 2 (by norm_num) simp only [pStar]; omega · intro k hk p ⟨_, hs⟩ rw [hkstar] at hk simp only [levinBudget, S, levinSharpSystem] at hs split_ifs at hs with hle · have hpow : 2 ^ (k - ℓ) ≤ 2 ^ m := Nat.pow_le_pow_right (by norm_num) (by omega) omega · have hpos : 1 ≤ 2 ^ m := Nat.one_le_pow m 2 (by norm_num) omega · rw [hkstar] simp only [levinIncrementalSteps, levinBudget, S, levinSharpSystem, show ℓ ≤ ℓ + m + 1 by omega, ↓reduceIte, show ℓ + m + 1 - ℓ = m + 1 by omega, Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] have ht1 : t - 1 = 2 ^ m := by simp [t] rw [ht1, pow_succ 2 ℓ, pow_succ 2 m] ring · intro ε hε obtain ⟨N, hN⟩ := exists_nat_gt (2 / ε) refine ⟨N + 1, N + 1, ?_⟩ set k := N + 1 rw [hearly_eq k k] have h2k : (2 : ℝ) / ε < (2 : ℝ) ^ k := by have h1 : (N : ℝ) < (2 : ℝ) ^ N := by exact_mod_cast Nat.lt_two_pow_self have h2 : (2 : ℝ) ^ N < (2 : ℝ) ^ k := by rw [show k = N + 1 by rfl, pow_succ]; linarith [show (0 : ℝ) < (2 : ℝ) ^ N by positivity] linarith have hdiff : ((2 ^ (k + 1) * (2 ^ k + 1) : ℕ) : ℝ) - (((2 ^ k - 1) * 2 ^ (k + 1) + (2 ^ k + 1) : ℕ) : ℝ) < 4 * (2 : ℝ) ^ k := by have hpos : 1 ≤ 2 ^ k := Nat.one_le_pow k 2 (by norm_num) have hnat : (2 ^ k - 1) * 2 ^ (k + 1) + (2 ^ k + 1) + (2 ^ (k + 1) + 2 ^ k - 1) = 2 ^ (k + 1) * (2 ^ k + 1) := by zify [hpos, show 1 ≤ 2 ^ (k + 1) + 2 ^ k by omega] ring have hreal : (((2 ^ k - 1) * 2 ^ (k + 1) + (2 ^ k + 1) : ℕ) : ℝ) + ((2 ^ (k + 1) + 2 ^ k - 1 : ℕ) : ℝ) = ((2 ^ (k + 1) * (2 ^ k + 1) : ℕ) : ℝ) := by exact_mod_cast hnat have hsub : ((2 ^ (k + 1) + 2 ^ k - 1 : ℕ) : ℝ) < 4 * (2 : ℝ) ^ k := by have h1 : 1 ≤ 2 ^ (k + 1) + 2 ^ k := by omega rw [Nat.cast_sub h1] push_cast rw [pow_succ] linarith [show (0 : ℝ) < (2 : ℝ) ^ k by positivity] linarith have hgap : 4 * (2 : ℝ) ^ k < ε * ((2 ^ (k + 1) * (2 ^ k + 1) : ℕ) : ℝ) := by have hεmul : 2 < ε * (2 : ℝ) ^ k := by have := (div_lt_iff₀ hε).mp h2k linarith push_cast have h2kp1 : (2 : ℝ) ^ (k + 1) = 2 * (2 : ℝ) ^ k := by rw [pow_succ]; ring rw [h2kp1] have hpos2k : (0 : ℝ) < (2 : ℝ) ^ k := by positivity nlinarith linarith /-! ## Section 4: Exact `Kt`-Complexity Invariance & `Kt - K` Time-Space Separation -/ /-- Minimum program length `K_S` of a valid solver in `S : LevinSearchSystem ι` (ignoring runtime). -/ noncomputable def minSolverLen {ι : Type*} (S : LevinSearchSystem ι) : ℕ∞ := ⨅ (p : ι) (_ : p ∈ S.pool) (t : ℕ) (_ : S.solvesIn p t), (S.len p : ℕ∞) /-- **Exact `Kt`-Complexity Invariance Theorem (on `levinKt`)**: If search system `S_U` simulates `S_M` via a translation map `sim : ι_M → ι_U` with additive program overhead `c_M` (`S_U.len (sim p) ≤ S_M.len p + c_M`) and multiplicative runtime overhead `a_M` (`S_M.solvesIn p t → S_U.solvesIn (sim p) (a_M * t)`), then `levinKt S_U ≤ levinKt S_M + c_M + Nat.clog 2 a_M`. -/ theorem kt_invariance_exact {ι_M ι_U : Type*} (S_M : LevinSearchSystem ι_M) (S_U : LevinSearchSystem ι_U) (sim : ι_M → ι_U) (c_M a_M : ℕ) (hpool : ∀ p ∈ S_M.pool, sim p ∈ S_U.pool) (hlen : ∀ p ∈ S_M.pool, S_U.len (sim p) ≤ S_M.len p + c_M) (htime : ∀ p ∈ S_M.pool, ∀ t, S_M.solvesIn p t → S_U.solvesIn (sim p) (a_M * t)) : levinKt S_U ≤ levinKt S_M + (c_M + Nat.clog 2 a_M : ℕ) := by have hle_all : ∀ p ∈ S_M.pool, ∀ t, S_M.solvesIn p t → levinKt S_U ≤ (solverKt S_M.len p t : ℕ∞) + (c_M + Nat.clog 2 a_M : ℕ) := by intro p hp t ht have hclog_mul : Nat.clog 2 (a_M * t) ≤ Nat.clog 2 a_M + Nat.clog 2 t := by refine (Nat.clog_le_iff_le_pow (by norm_num)).mpr ?_ rw [pow_add] exact Nat.mul_le_mul (Nat.le_pow_clog (by norm_num) a_M) (Nat.le_pow_clog (by norm_num) t) have hnat : solverKt S_U.len (sim p) (a_M * t) ≤ solverKt S_M.len p t + (c_M + Nat.clog 2 a_M) := by simp only [solverKt] have := hlen p hp omega calc levinKt S_U ≤ (solverKt S_U.len (sim p) (a_M * t) : ℕ∞) := iInf₂_le_of_le (sim p) (hpool p hp) (iInf₂_le (a_M * t) (htime p hp t ht)) _ ≤ ((solverKt S_M.len p t + (c_M + Nat.clog 2 a_M) : ℕ) : ℕ∞) := by exact_mod_cast hnat _ = (solverKt S_M.len p t : ℕ∞) + (c_M + Nat.clog 2 a_M : ℕ) := by push_cast; rfl by_cases hex : ∃ p ∈ S_M.pool, ∃ t, S_M.solvesIn p t · rcases hex with ⟨p0, hp0, t0, ht0⟩ have hfin : levinKt S_M ≠ ⊤ := ne_top_of_le_ne_top (by simp) (iInf₂_le_of_le p0 hp0 (iInf₂_le t0 ht0)) set K := (levinKt S_M).toNat have hK_eq : levinKt S_M = K := (ENat.natCast_toNat hfin).symm -- Extract a solver `(p, t)` achieving `solverKt S_M.len p t ≤ K` have hex_min : ∃ p ∈ S_M.pool, ∃ t, S_M.solvesIn p t ∧ solverKt S_M.len p t ≤ K := by by_contra hall push Not at hall have hge : ((K + 1 : ℕ) : ℕ∞) ≤ levinKt S_M := by refine le_iInf₂ fun p hp => le_iInf₂ fun t ht => ?_ have := hall p hp t ht exact_mod_cast (by omega : K + 1 ≤ solverKt S_M.len p t) rw [hK_eq] at hge have hlt : (K : ℕ∞) < ((K + 1 : ℕ) : ℕ∞) := by exact_mod_cast Nat.lt_succ_self K exact not_lt_of_ge hge hlt rcases hex_min with ⟨p, hp, t, ht, hpt⟩ rw [hK_eq] calc levinKt S_U ≤ (solverKt S_M.len p t : ℕ∞) + (c_M + Nat.clog 2 a_M : ℕ) := hle_all p hp t ht _ ≤ (K : ℕ∞) + (c_M + Nat.clog 2 a_M : ℕ) := by gcongr · have htop : levinKt S_M = ⊤ := by simp only [levinKt, iInf_eq_top] intro p hp t ht exact (hex ⟨p, hp, t, ht⟩).elim rw [htop] simp /-- Explicit single-solver search system requiring `2^m` steps with length-0 program: achieves `minSolverLen = 0` and `levinKt = m`. -/ def slowUnitSystem (m : ℕ) : LevinSearchSystem Unit where pool := {()} len := fun _ => 0 kraft := by simp solvesIn := fun _ s => 2 ^ m ≤ s mono := fun _ _ _ hle hs => le_trans hs hle pos_time := fun _ _ hs => le_trans (Nat.one_le_pow m 2 (by norm_num)) hs /-- **Exact `K` vs. `Kt` Comparison & Arbitrary Time-Space Gap (on `LevinSearchSystem`)**: 1. For EVERY search system `S`: `minSolverLen S ≤ levinKt S`. 2. For EVERY target gap `m : ℕ`, the concrete search system `slowUnitSystem m` satisfies `minSolverLen (slowUnitSystem m) = 0` and `levinKt (slowUnitSystem m) = m`. -/ theorem k_le_kt_and_arbitrary_gap (m : ℕ) : (∀ {ι : Type*} (S : LevinSearchSystem ι), minSolverLen S ≤ levinKt S) ∧ (minSolverLen (slowUnitSystem m) = 0 ∧ levinKt (slowUnitSystem m) = m) := by refine ⟨?_, ?_, ?_⟩ · intro ι S refine le_iInf₂ fun p hp => le_iInf₂ fun t ht => ?_ calc minSolverLen S ≤ (S.len p : ℕ∞) := iInf₂_le_of_le p hp (iInf₂_le t ht) _ ≤ (solverKt S.len p t : ℕ∞) := by exact_mod_cast Nat.le_add_right (S.len p) _ · apply le_antisymm · exact iInf₂_le_of_le () (by simp [slowUnitSystem]) (iInf₂_le (2 ^ m) (show (slowUnitSystem m).solvesIn () (2 ^ m) from le_rfl)) · exact zero_le · apply le_antisymm · have hle : levinKt (slowUnitSystem m) ≤ (solverKt (slowUnitSystem m).len () (2 ^ m) : ℕ∞) := iInf₂_le_of_le () (by simp [slowUnitSystem]) (iInf₂_le (2 ^ m) (show (slowUnitSystem m).solvesIn () (2 ^ m) from le_rfl)) simpa [solverKt, slowUnitSystem, Nat.clog_pow 2 m (by norm_num)] using hle · refine le_iInf₂ fun p _ => le_iInf₂ fun t ht => ?_ simp only [solverKt, slowUnitSystem, zero_add] have hge : m ≤ Nat.clog 2 t := by rw [← Nat.clog_pow 2 m (by norm_num)] exact Nat.clog_mono_right 2 ht exact_mod_cast hge /-! ## Section 5: Axiom Audit -/ #print axioms symmetry_kraft_feasibility #print axioms exact_symmetry_of_information_lower #print axioms symmetry_plus_one_sharp_witness #print axioms algorithmic_mutual_info_symmetry #print axioms levinIncrementalSteps_le_pow #print axioms levin_incremental_optimal #print axioms levin_restart_bound #print axioms levin_sharpness_witness #print axioms kt_invariance_exact #print axioms k_le_kt_and_arbitrary_gap end SymmetryAndLevin