Lean / 0xOsprey/shub-smale-tau9 / L2ReflectionBound.lean
Lean readerResearch/PvsNP/Tau/L2ReflectionBound.lean
modulepublic import Research.PvsNP.Tau.TauConjecture@[expose] public sectionnamespace Research.PvsNP.Tau/-!# Pure-ℤ Algebraic `L₂`-Reflection Bound (`τ · z_ℤ(P) ≤ 3 · 2^τ`)This module proves an unconditional, completely elementary `O(2^τ / τ)` upper bound on thenumber of distinct integer roots of every constant-free, division-free straight-line program`P : SLP τ` over `ℤ[X]`, using **zero** real analysis, **zero** complex analysis, **zero**logarithms, and **zero** `p`-adic machinery:`∀ {τ : ℕ} (P : SLP τ), P.evalPoly ≠ 0 → τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`This sharpens `GapDominanceBound.lean` (`2^τ / τ^(1/28)`) by `28×` in the exponent of `τ`and matches the information-theoretic `Θ(2^τ / τ)` ceiling for all global degree/height/Mahlermethods up to a small absolute constant.### Proof Structure1. **1-Step `L₂`-Reflection Identity (`l2Sq_mul_X_sub_eq_one_sub_mul_X`):**For every `f : Polynomial ℤ` and `r : ℤ`, `‖f · (X - r)‖₂² = ‖f · (1 - r X)‖₂²`.2. **Multi-Root Reflection (`prod_natAbs_roots_le_l1Norm`):**Reflecting every integer root `r ∈ S` (`r ≠ 0`) turns `f = Q · ∏ (X - r)` into`f* = Q · ∏ (1 - r X)` with `∏ |r| ≤ |lc(f*)| ≤ ‖f*‖₂ = ‖f‖₂ ≤ ‖f‖₁`.3. **SLP `L₁`-Norm Bound (`slp_l1Norm_le`):**Every nonzero `P : SLP τ` (`τ ≥ 1`) satisfies `l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1))`(and `≤ 2 ^ (2 ^ (τ - t₀ - 1))` if the first `t₀` gates are all multiplications).4. **Pure-`ℕ` Factorial Pairing (`pow_self_le_prod_natAbs`):**For `S ⊆ {r ∈ ℤ : 2 ≤ |r|}` with `2 * m ≤ S.card`, `k = m + 1` satisfies`k ^ k ≤ (k!)^2 ≤ ∏ r ∈ S, r.natAbs`.5. **Pure-`ℕ` Closure (`slp_intRootCount_l2_reflection`):**Combining (2)–(4) with `h = τ / 2` yields `τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`(and `(τ - t₀) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - t₀)` for a `t₀`-multiplication prefix).-/open Polynomial/-! ## 1. Polynomial `L₁`-Norm and Squared `L₂`-Norm over `ℤ[X]` -//-- The `L₁`-norm (sum of absolute values of coefficients) of `f ∈ ℤ[X]`. -/noncomputable def l1Norm (f : Polynomial ℤ) : ℕ :=∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k).natAbs/-- The squared `L₂`-norm (sum of squares of coefficients) of `f ∈ ℤ[X]`. -/noncomputable def l2Sq (f : Polynomial ℤ) : ℕ :=∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k).natAbs ^ 2lemma l1Norm_eq_sum_range {f : Polynomial ℤ} {N : ℕ} (hN : f.natDegree + 1 ≤ N) :l1Norm f = ∑ k ∈ Finset.range N, (f.coeff k).natAbs := byunfold l1Normrefine Finset.sum_subset (Finset.range_mono hN) ?_intro k _ hkhave hlt : f.natDegree < k := bysimp only [Finset.mem_range, not_lt] at hkomegasimp [Polynomial.coeff_eq_zero_of_natDegree_lt hlt]lemma l2Sq_eq_sum_range {f : Polynomial ℤ} {N : ℕ} (hN : f.natDegree + 1 ≤ N) :l2Sq f = ∑ k ∈ Finset.range N, (f.coeff k).natAbs ^ 2 := byunfold l2Sqrefine Finset.sum_subset (Finset.range_mono hN) ?_intro k _ hkhave hlt : f.natDegree < k := bysimp only [Finset.mem_range, not_lt] at hkomegasimp [Polynomial.coeff_eq_zero_of_natDegree_lt hlt]lemma l1Norm_one : l1Norm (1 : Polynomial ℤ) = 1 := bysimp [l1Norm]lemma l1Norm_X : l1Norm (Polynomial.X : Polynomial ℤ) = 1 := bysimp [l1Norm, Finset.sum_range_succ]lemma l1Norm_add_le (f g : Polynomial ℤ) : l1Norm (f + g) ≤ l1Norm f + l1Norm g := bylet N := max f.natDegree g.natDegree + 1have hfg : (f + g).natDegree + 1 ≤ N := byhave := Polynomial.natDegree_add_le f g; omegahave hf : f.natDegree + 1 ≤ N := by omegahave hg : g.natDegree + 1 ≤ N := by omegarw [l1Norm_eq_sum_range hfg, l1Norm_eq_sum_range hf, l1Norm_eq_sum_range hg,← Finset.sum_add_distrib]refine Finset.sum_le_sum fun k _ => ?_rw [Polynomial.coeff_add]exact Int.natAbs_add_le _ _lemma l1Norm_sub_le (f g : Polynomial ℤ) : l1Norm (f - g) ≤ l1Norm f + l1Norm g := bylet N := max f.natDegree g.natDegree + 1have hfg : (f - g).natDegree + 1 ≤ N := byhave := Polynomial.natDegree_sub_le f g; omegahave hf : f.natDegree + 1 ≤ N := by omegahave hg : g.natDegree + 1 ≤ N := by omegarw [l1Norm_eq_sum_range hfg, l1Norm_eq_sum_range hf, l1Norm_eq_sum_range hg,← Finset.sum_add_distrib]refine Finset.sum_le_sum fun k _ => ?_rw [Polynomial.coeff_sub, sub_eq_add_neg]calc (f.coeff k + -(g.coeff k)).natAbs≤ (f.coeff k).natAbs + (-(g.coeff k)).natAbs := Int.natAbs_add_le _ __ = (f.coeff k).natAbs + (g.coeff k).natAbs := by rw [Int.natAbs_neg]lemma natAbs_sum_le {ι : Type*} (s : Finset ι) (f : ι → ℤ) :(∑ i ∈ s, f i).natAbs ≤ ∑ i ∈ s, (f i).natAbs := byclassicalinduction s using Finset.induction_on with| empty => simp| @insert a s ha ih =>rw [Finset.sum_insert ha, Finset.sum_insert ha]exact le_trans (Int.natAbs_add_le _ _) (Nat.add_le_add_left ih _)lemma l1Norm_mul_le (f g : Polynomial ℤ) : l1Norm (f * g) ≤ l1Norm f * l1Norm g := bylet Nf := f.natDegree + 1let Ng := g.natDegree + 1have hfg : (f * g).natDegree + 1 ≤ Nf + Ng := byhave := Polynomial.natDegree_mul_le (p := f) (q := g); omegarw [l1Norm_eq_sum_range hfg]unfold l1Normrw [Finset.sum_mul]simp_rw [Finset.mul_sum]calc ∑ k ∈ Finset.range (Nf + Ng), ((f * g).coeff k).natAbs≤ ∑ k ∈ Finset.range (Nf + Ng),∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := byrefine Finset.sum_le_sum fun k _ => ?_rw [Polynomial.coeff_mul]calc (∑ ij ∈ Finset.antidiagonal k, f.coeff ij.1 * g.coeff ij.2).natAbs≤ ∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1 * g.coeff ij.2).natAbs :=natAbs_sum_le _ __ = ∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := byrefine Finset.sum_congr rfl fun ij _ => Int.natAbs_mul _ __ = ∑ k ∈ Finset.range (Nf + Ng),∑ ij ∈ (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng),(f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := byrefine Finset.sum_congr rfl fun k _ => ?_symmrefine Finset.sum_subset (Finset.filter_subset _ _) ?_intro ij hij hnotsimp only [Finset.mem_filter, hij, true_and, not_and_or, not_lt] at hnotrcases hnot with h1 | h2· have : f.natDegree < ij.1 := by omegasimp [Polynomial.coeff_eq_zero_of_natDegree_lt this]· have : g.natDegree < ij.2 := by omegasimp [Polynomial.coeff_eq_zero_of_natDegree_lt this]_ = ∑ i ∈ Finset.range Nf, ∑ j ∈ Finset.range Ng,(f.coeff i).natAbs * (g.coeff j).natAbs := byrw [show (∑ k ∈ Finset.range (Nf + Ng),∑ ij ∈ (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng),(f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs) =∑ x ∈ (Finset.range (Nf + Ng)).sigma(fun k => (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng)),(f.coeff x.2.1).natAbs * (g.coeff x.2.2).natAbs from(Finset.sum_sigma (Finset.range (Nf + Ng))(fun k => (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng))(fun x => (f.coeff x.2.1).natAbs * (g.coeff x.2.2).natAbs)).symm,show (∑ i ∈ Finset.range Nf, ∑ j ∈ Finset.range Ng,(f.coeff i).natAbs * (g.coeff j).natAbs) =∑ p ∈ Finset.range Nf ×ˢ Finset.range Ng,(f.coeff p.1).natAbs * (g.coeff p.2).natAbs from(Finset.sum_product (Finset.range Nf) (Finset.range Ng)(fun p => (f.coeff p.1).natAbs * (g.coeff p.2).natAbs)).symm]refine Finset.sum_bij(fun (x : Σ _ : ℕ, ℕ × ℕ) _ => x.2) ?_ ?_ ?_ ?_· intro x hxsimp only [Finset.mem_sigma, Finset.mem_range, Finset.mem_filter,Finset.mem_product] at hx ⊢exact hx.2.2· intro x₁ hx₁ x₂ hx₂ heqsimp only [Finset.mem_sigma, Finset.mem_filter, Finset.mem_antidiagonal] at hx₁ hx₂have hfst : x₁.1 = x₂.1 := byrw [← hx₁.2.1, ← hx₂.2.1, heq]exact Sigma.ext hfst (by simp [heq])· intro p hpsimp only [Finset.mem_product, Finset.mem_range] at hprefine ⟨⟨p.1 + p.2, p⟩, ?_, rfl⟩simp only [Finset.mem_sigma, Finset.mem_range, Finset.mem_filter,Finset.mem_antidiagonal]exact ⟨by omega, trivial, hp.1, hp.2⟩· intro _ _; rfllemma sum_sq_le_sq_sum (s : Finset ℕ) (a : ℕ → ℕ) :∑ k ∈ s, (a k) ^ 2 ≤ (∑ k ∈ s, a k) ^ 2 := byclassicalinduction s using Finset.induction_on with| empty => simp| @insert x s hx ih =>rw [Finset.sum_insert hx, Finset.sum_insert hx, add_sq]omegalemma l2Sq_le_l1Norm_sq (f : Polynomial ℤ) : l2Sq f ≤ (l1Norm f) ^ 2 :=sum_sq_le_sq_sum _ _lemma natAbs_leadingCoeff_sq_le_l2Sq (f : Polynomial ℤ) :f.leadingCoeff.natAbs ^ 2 ≤ l2Sq f := byunfold l2Sqrw [Polynomial.leadingCoeff]exact Finset.single_le_sum (f := fun k => (f.coeff k).natAbs ^ 2)(fun _ _ => Nat.zero_le _) (Finset.mem_range.mpr (Nat.lt_succ_self _))/-! ## 2. Exact 1-Step `L₂`-Reflection Identity over `ℤ[X]` -//-- **1-Step `L₂`-Reflection Identity:**For every `f ∈ ℤ[X]` and every `r ∈ ℤ`,`‖f · (X - r)‖₂² = ‖f · (1 - r X)‖₂²`. -/theorem l2Sq_mul_X_sub_eq_one_sub_mul_X (f : Polynomial ℤ) (r : ℤ) :l2Sq (f * (Polynomial.X - Polynomial.C r)) =l2Sq (f * (1 - Polynomial.C r * Polynomial.X)) := byhave hdeg1 : (f * (Polynomial.X - Polynomial.C r)).natDegree + 1 ≤ f.natDegree + 2 := byhave h1 := Polynomial.natDegree_mul_le (p := f) (q := Polynomial.X - Polynomial.C r)have h2 : (Polynomial.X - Polynomial.C r).natDegree ≤ 1 := bycalc (Polynomial.X - Polynomial.C r).natDegree≤ max Polynomial.X.natDegree (Polynomial.C r).natDegree := Polynomial.natDegree_sub_le _ __ ≤ 1 := by simpomegahave hdeg2 : (f * (1 - Polynomial.C r * Polynomial.X)).natDegree + 1 ≤ f.natDegree + 2 := byhave h1 := Polynomial.natDegree_mul_le (p := f) (q := 1 - Polynomial.C r * Polynomial.X)have h2 : (1 - Polynomial.C r * Polynomial.X).natDegree ≤ 1 := bycalc (1 - Polynomial.C r * Polynomial.X).natDegree≤ max (1 : Polynomial ℤ).natDegree (Polynomial.C r * Polynomial.X).natDegree :=Polynomial.natDegree_sub_le _ __ ≤ 1 := byhave h1' : (1 : Polynomial ℤ).natDegree = 0 := Polynomial.natDegree_onehave h2' := Polynomial.natDegree_mul_le (p := Polynomial.C r) (q := Polynomial.X)have hC : (Polynomial.C r).natDegree = 0 := Polynomial.natDegree_C rhave hX : (Polynomial.X : Polynomial ℤ).natDegree = 1 := Polynomial.natDegree_Xomegaomegarw [l2Sq_eq_sum_range hdeg1, l2Sq_eq_sum_range hdeg2]-- Cast to ℤ where (a.natAbs : ℤ)^2 = a^2 so `ring` closes the algebraic identity!apply (Nat.cast_inj (R := ℤ)).mpsimp only [Nat.cast_sum, Nat.cast_pow, Int.natAbs_sq]have hcoeff1_zero : (f * (Polynomial.X - Polynomial.C r)).coeff 0 = -(r * f.coeff 0) := byrw [mul_sub, Polynomial.coeff_sub, Polynomial.coeff_mul_X_zero,Polynomial.coeff_mul_C]; ringhave hcoeff1_succ : ∀ k : ℕ,(f * (Polynomial.X - Polynomial.C r)).coeff (k + 1) =f.coeff k - r * f.coeff (k + 1) := byintro krw [mul_sub, Polynomial.coeff_sub, Polynomial.coeff_mul_X, Polynomial.coeff_mul_C]ringhave hcoeff2_zero : (f * (1 - Polynomial.C r * Polynomial.X)).coeff 0 = f.coeff 0 := byrw [mul_sub, mul_one, ← mul_assoc, Polynomial.coeff_sub, Polynomial.coeff_mul_X_zero, sub_zero]have hcoeff2_succ : ∀ k : ℕ,(f * (1 - Polynomial.C r * Polynomial.X)).coeff (k + 1) =f.coeff (k + 1) - r * f.coeff k := byintro krw [mul_sub, mul_one, ← mul_assoc, Polynomial.coeff_sub, Polynomial.coeff_mul_X,Polynomial.coeff_mul_C]ringhave htop : f.coeff (f.natDegree + 1) = 0 :=Polynomial.coeff_eq_zero_of_natDegree_lt (Nat.lt_succ_self _)-- Split off k = 0 on both sides using `Finset.sum_range_succ'`conv_lhs => rw [Finset.sum_range_succ']conv_rhs => rw [Finset.sum_range_succ']rw [hcoeff1_zero, hcoeff2_zero]simp_rw [hcoeff1_succ, hcoeff2_succ]-- Expand squares and compare term-by-term!have hexp1 : ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k - r * f.coeff (k + 1)) ^ 2 =(∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2) +r ^ 2 * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) -2 * r * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k * f.coeff (k + 1)) := byrw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]refine Finset.sum_congr rfl fun k _ => by ringhave hexp2 : ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff (k + 1) - r * f.coeff k) ^ 2 =(∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) +r ^ 2 * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2) -2 * r * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k * f.coeff (k + 1)) := byrw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]refine Finset.sum_congr rfl fun k _ => by ringhave hshift :(∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) + f.coeff 0 ^ 2 =∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2 := byhave h1 := Finset.sum_range_succ' (fun k => f.coeff k ^ 2) (f.natDegree + 1)have h2 := Finset.sum_range_succ (fun k => f.coeff k ^ 2) (f.natDegree + 1)rw [htop] at h2linarithrw [hexp1, hexp2, ← hshift]ring/-! ## 3. Multi-Root Reflection & Product of Nonzero Roots Bound -/lemma l2Sq_mul_prod_X_sub_eq_reflected (Q : Polynomial ℤ) (S : Finset ℤ) :l2Sq (Q * ∏ r ∈ S, (Polynomial.X - Polynomial.C r)) =l2Sq (Q * ∏ r ∈ S, (1 - Polynomial.C r * Polynomial.X)) := byclassicalinduction S using Finset.induction_on generalizing Q with| empty => simp| @insert a s ha ih =>rw [Finset.prod_insert ha, Finset.prod_insert ha]have h1 : Q * ((Polynomial.X - Polynomial.C a) * ∏ r ∈ s, (Polynomial.X - Polynomial.C r)) =(Q * (Polynomial.X - Polynomial.C a)) * ∏ r ∈ s, (Polynomial.X - Polynomial.C r) := byringhave h2 : Q * ((1 - Polynomial.C a * Polynomial.X) * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) =(Q * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) * (1 - Polynomial.C a * Polynomial.X) := byringrw [h1, ih (Q * (Polynomial.X - Polynomial.C a))]have h3 : (Q * (Polynomial.X - Polynomial.C a)) * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X) =(Q * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) * (Polynomial.X - Polynomial.C a) := byringrw [h3, l2Sq_mul_X_sub_eq_one_sub_mul_X, ← h2]lemma exists_mul_prod_X_sub_of_roots (f : Polynomial ℤ) (hf : f ≠ 0) (S : Finset ℤ)(hS : ∀ r ∈ S, f.IsRoot r) :∃ Q : Polynomial ℤ, Q ≠ 0 ∧ f = Q * ∏ r ∈ S, (Polynomial.X - Polynomial.C r) := byclassicalinduction S using Finset.induction_on generalizing f with| empty =>exact ⟨f, hf, by simp⟩| @insert a s ha ih =>have ha_root : f.IsRoot a := hS a (Finset.mem_insert_self a s)rcases Polynomial.dvd_iff_isRoot.mpr ha_root with ⟨g, hg⟩have hg_ne : g ≠ 0 := byintro h0; rw [h0, mul_zero] at hg; exact hf hghave hs_root : ∀ r ∈ s, g.IsRoot r := byintro r hrhave hfr : f.eval r = 0 := hS r (Finset.mem_insert_of_mem hr)rw [hg, Polynomial.eval_mul, Polynomial.eval_sub, Polynomial.eval_X,Polynomial.eval_C] at hfrhave hne : r - a ≠ 0 := sub_ne_zero.mpr (fun h => ha (h ▸ hr))exact (mul_eq_zero.mp hfr).resolve_left hnercases ih g hg_ne hs_root with ⟨Q, hQ_ne, hQ⟩refine ⟨Q, hQ_ne, ?_⟩rw [Finset.prod_insert ha, hg, hQ]ringlemma leadingCoeff_one_sub_C_mul_X {r : ℤ} (hr : r ≠ 0) :(1 - Polynomial.C r * Polynomial.X).leadingCoeff = -r := byhave hcoeff1 : (1 - Polynomial.C r * Polynomial.X).coeff 1 = -r := byrw [Polynomial.coeff_sub, Polynomial.coeff_one, Polynomial.coeff_C_mul_X]simphave hdeg_le : (1 - Polynomial.C r * Polynomial.X).natDegree ≤ 1 := byhave hsub := Polynomial.natDegree_sub_le (1 : Polynomial ℤ) (Polynomial.C r * Polynomial.X)have hmul := Polynomial.natDegree_mul_le (p := Polynomial.C r) (q := Polynomial.X)have h1' : (1 : Polynomial ℤ).natDegree = 0 := Polynomial.natDegree_onehave hC : (Polynomial.C r).natDegree = 0 := Polynomial.natDegree_C rhave hX : (Polynomial.X : Polynomial ℤ).natDegree = 1 := Polynomial.natDegree_Xomegahave hdeg_ge : 1 ≤ (1 - Polynomial.C r * Polynomial.X).natDegree :=Polynomial.le_natDegree_of_ne_zero (by rw [hcoeff1]; exact neg_ne_zero.mpr hr)have hdeg : (1 - Polynomial.C r * Polynomial.X).natDegree = 1 := le_antisymm hdeg_le hdeg_gerw [Polynomial.leadingCoeff, hdeg, hcoeff1]lemma natAbs_prod_neg (S : Finset ℤ) :(∏ r ∈ S, (-r : ℤ)).natAbs = ∏ r ∈ S, r.natAbs := byclassicalinduction S using Finset.induction_on with| empty => simp| @insert a s ha ih =>rw [Finset.prod_insert ha, Finset.prod_insert ha, Int.natAbs_mul, Int.natAbs_neg, ih]/-- **Multi-Root `L₁`-Norm Bound:**For every nonzero `f ∈ ℤ[X]` and any finite set `S` of nonzero integer roots of `f`,`∏ r ∈ S, r.natAbs ≤ l1Norm f`. -/theorem prod_natAbs_roots_le_l1Norm {f : Polynomial ℤ} (hf : f ≠ 0) (S : Finset ℤ)(hS : ∀ r ∈ S, f.IsRoot r) (hne : ∀ r ∈ S, r ≠ 0) :∏ r ∈ S, r.natAbs ≤ l1Norm f := byrcases exists_mul_prod_X_sub_of_roots f hf S hS with ⟨Q, hQ_ne, hQ⟩let Pstar := Q * ∏ r ∈ S, (1 - Polynomial.C r * Polynomial.X)have hlc : Pstar.leadingCoeff = Q.leadingCoeff * ∏ r ∈ S, (-r) := bydsimp [Pstar]rw [Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_prod]congr 1refine Finset.prod_congr rfl fun r hr => leadingCoeff_one_sub_C_mul_X (hne r hr)have hQ_pos : 1 ≤ Q.leadingCoeff.natAbs := byhave hlc_ne : Q.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr hQ_neexact Nat.pos_of_ne_zero (Int.natAbs_ne_zero.mpr hlc_ne)have hprod_le : ∏ r ∈ S, r.natAbs ≤ Pstar.leadingCoeff.natAbs := byrw [hlc, Int.natAbs_mul, natAbs_prod_neg]exact Nat.le_mul_of_pos_left _ hQ_poshave hsq : (∏ r ∈ S, r.natAbs) ^ 2 ≤ (l1Norm f) ^ 2 := bycalc (∏ r ∈ S, r.natAbs) ^ 2≤ Pstar.leadingCoeff.natAbs ^ 2 := Nat.pow_le_pow_left hprod_le 2_ ≤ l2Sq Pstar := natAbs_leadingCoeff_sq_le_l2Sq Pstar_ = l2Sq f := by rw [hQ, l2Sq_mul_prod_X_sub_eq_reflected]_ ≤ (l1Norm f) ^ 2 := l2Sq_le_l1Norm_sq fnlinarith/-! ## 4. SLP `L₁`-Norm Upper Bound -//-- For `τ ≥ 1`, every wire of `P : SLP τ` has `l1Norm ≤ 2 ^ (2 ^ (τ - 1))`. -/lemma slp_evalWire_l1Norm_le : ∀ {τ : ℕ} (P : SLP τ) (k : Fin (τ + 2)),l1Norm (P.evalWire k) ≤ if τ = 0 then 1 else 2 ^ (2 ^ (τ - 1))| 0, .nil, k => bysimp only [SLP.evalWire, ↓reduceIte]split_ifs· simp [l1Norm_one]· simp [l1Norm_X]| τ + 1, .snoc P op i j, k => bysimp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel]simp only [SLP.evalWire]split_ifs with hk· have ih := slp_evalWire_l1Norm_le P ⟨k.val, hk⟩cases τ with| zero =>simp only [↓reduceIte] at ihexact le_trans ih (by norm_num)| succ m =>simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] at ihrefine le_trans ih (Nat.pow_le_pow_right (by norm_num) ?_)exact Nat.pow_le_pow_right (by norm_num) (Nat.le_succ m)· have ihi := slp_evalWire_l1Norm_le P ihave ihj := slp_evalWire_l1Norm_le P jcases τ with| zero =>simp only [↓reduceIte] at ihi ihjcases op with| add =>calc l1Norm (P.evalWire i + P.evalWire j)≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_add_le _ __ ≤ 1 + 1 := Nat.add_le_add ihi ihj_ = 2 ^ (2 ^ 0) := by norm_num| sub =>calc l1Norm (P.evalWire i - P.evalWire j)≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_sub_le _ __ ≤ 1 + 1 := Nat.add_le_add ihi ihj_ = 2 ^ (2 ^ 0) := by norm_num| mul =>calc l1Norm (P.evalWire i * P.evalWire j)≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ __ ≤ 1 * 1 := Nat.mul_le_mul ihi ihj_ ≤ 2 ^ (2 ^ 0) := by norm_num| succ m =>simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] at ihi ihjset B := 2 ^ (2 ^ m) with hB_defhave hB2 : 2 ≤ B := byrw [hB_def]have : 1 ≤ 2 ^ m := Nat.one_le_two_powcalc 2 = 2 ^ 1 := by norm_num_ ≤ 2 ^ (2 ^ m) := Nat.pow_le_pow_right (by norm_num) thishave hBsq : B * B = 2 ^ (2 ^ (m + 1)) := byrw [hB_def, ← pow_add, pow_succ, mul_two]cases op with| add =>calc l1Norm (P.evalWire i + P.evalWire j)≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_add_le _ __ ≤ B + B := Nat.add_le_add ihi ihj_ = 2 * B := by ring_ ≤ B * B := Nat.mul_le_mul_right B hB2_ = 2 ^ (2 ^ (m + 1)) := hBsq| sub =>calc l1Norm (P.evalWire i - P.evalWire j)≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_sub_le _ __ ≤ B + B := Nat.add_le_add ihi ihj_ = 2 * B := by ring_ ≤ B * B := Nat.mul_le_mul_right B hB2_ = 2 ^ (2 ^ (m + 1)) := hBsq| mul =>calc l1Norm (P.evalWire i * P.evalWire j)≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ __ ≤ B * B := Nat.mul_le_mul ihi ihj_ = 2 ^ (2 ^ (m + 1)) := hBsq/-- Every constant-free `P : SLP τ` (`τ ≥ 1`) satisfies `l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1))`. -/theorem slp_l1Norm_le {τ : ℕ} (hτ : 1 ≤ τ) (P : SLP τ) :l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1)) := byhave h := slp_evalWire_l1Norm_le P ⟨τ + 1, Nat.lt_succ_self _⟩have hne : τ ≠ 0 := by omegasimpa [SLP.evalPoly, hne] using h/-- Count of leading `.mul` gates before the first `.add`/`.sub` gate (i.e. `t₀`). -/def SLP.mulPrefixLen : {τ : ℕ} → SLP τ → ℕ| 0, .nil => 0| τ + 1, .snoc P op _ _ =>if P.mulPrefixLen = τ ∧ op = .mul then τ + 1 else P.mulPrefixLenlemma SLP.mulPrefixLen_le : ∀ {τ : ℕ} (P : SLP τ), P.mulPrefixLen ≤ τ| 0, .nil => le_rfl| τ + 1, .snoc P op _ _ => byhave ih := P.mulPrefixLen_lechange (if P.mulPrefixLen = τ ∧ op = .mul then τ + 1 else P.mulPrefixLen) ≤ τ + 1split_ifs <;> omega/-- Refined `L₁`-norm bound accounting for a leading multiplication prefix of length `t₀`:every wire of `P : SLP τ` has `l1Norm ≤ 1` if `t₀ = τ`, else `≤ 2 ^ (2 ^ (τ - t₀ - 1))`. -/lemma slp_evalWire_l1Norm_le_shifted : ∀ {τ : ℕ} (P : SLP τ) (k : Fin (τ + 2)),l1Norm (P.evalWire k) ≤if P.mulPrefixLen = τ then 1 else 2 ^ (2 ^ (τ - P.mulPrefixLen - 1))| 0, .nil, k => bysimp only [SLP.mulPrefixLen, ↓reduceIte, SLP.evalWire]split_ifs· simp [l1Norm_one]· simp [l1Norm_X]| τ + 1, .snoc P op i j, k => byhave hple := P.mulPrefixLen_leby_cases hall : P.mulPrefixLen = τ ∧ op = .mul· rcases hall with ⟨hpt, hop⟩have hpref : (SLP.snoc P op i j).mulPrefixLen = τ + 1 := bysimp [SLP.mulPrefixLen, hpt, hop]rw [hpref]; simp only [↓reduceIte, SLP.evalWire]split_ifs with hk· have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩simpa [hpt] using ih· have ihi := slp_evalWire_l1Norm_le_shifted P ihave ihj := slp_evalWire_l1Norm_le_shifted P jsimp only [hpt, ↓reduceIte] at ihi ihjrw [hop]calc l1Norm (P.evalWire i * P.evalWire j)≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ __ ≤ 1 * 1 := Nat.mul_le_mul ihi ihj_ = 1 := one_mul 1· have hpref : (SLP.snoc P op i j).mulPrefixLen = P.mulPrefixLen := bysimp [SLP.mulPrefixLen, hall]have hne : P.mulPrefixLen ≠ τ + 1 := by omegarw [hpref]; simp only [hne, ↓reduceIte, SLP.evalWire]by_cases hpt : P.mulPrefixLen = τ· have hsub : τ + 1 - P.mulPrefixLen - 1 = 0 := by omegarw [hsub]split_ifs with hk· have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩simp only [hpt, ↓reduceIte] at ihexact le_trans ih (by norm_num)· have ihi := slp_evalWire_l1Norm_le_shifted P ihave ihj := slp_evalWire_l1Norm_le_shifted P jsimp only [hpt, ↓reduceIte] at ihi ihjcases op with| add => exact le_trans (l1Norm_add_le _ _) (by omega)| sub => exact le_trans (l1Norm_sub_le _ _) (by omega)| mul => exact False.elim (hall ⟨hpt, rfl⟩)· set e := τ - P.mulPrefixLen - 1 with he_defhave hsub : τ + 1 - P.mulPrefixLen - 1 = e + 1 := by omegarw [hsub]set B := 2 ^ (2 ^ e) with hB_defhave hB2 : 2 ≤ B := byrw [hB_def]have : 1 ≤ 2 ^ e := Nat.one_le_two_powcalc 2 = 2 ^ 1 := by norm_num_ ≤ 2 ^ (2 ^ e) := Nat.pow_le_pow_right (by norm_num) thishave hBsq : B * B = 2 ^ (2 ^ (e + 1)) := byrw [hB_def, ← pow_add, pow_succ, mul_two]split_ifs with hk· have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩simp only [hpt, ↓reduceIte] at ihrw [← he_def] at ihexact le_trans ih (by rw [← hBsq]; exact Nat.le_mul_of_pos_right B (by omega))· have ihi := slp_evalWire_l1Norm_le_shifted P ihave ihj := slp_evalWire_l1Norm_le_shifted P jsimp only [hpt, ↓reduceIte] at ihi ihjrw [← he_def] at ihi ihjcases op with| add =>calc l1Norm (P.evalWire i + P.evalWire j)≤ B + B := le_trans (l1Norm_add_le _ _) (Nat.add_le_add ihi ihj)_ = 2 * B := by ring_ ≤ B * B := Nat.mul_le_mul_right B hB2_ = 2 ^ (2 ^ (e + 1)) := hBsq| sub =>calc l1Norm (P.evalWire i - P.evalWire j)≤ B + B := le_trans (l1Norm_sub_le _ _) (Nat.add_le_add ihi ihj)_ = 2 * B := by ring_ ≤ B * B := Nat.mul_le_mul_right B hB2_ = 2 ^ (2 ^ (e + 1)) := hBsq| mul =>calc l1Norm (P.evalWire i * P.evalWire j)≤ B * B := le_trans (l1Norm_mul_le _ _) (Nat.mul_le_mul ihi ihj)_ = 2 ^ (2 ^ (e + 1)) := hBsq/-! ## 5. Pure-`ℕ` Factorial Pairing Bound -//-- At most `2 * m` integers satisfy `2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1`. -/lemma card_filter_natAbs_between_le (S : Finset ℤ) (m : ℕ) :(S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1)).card ≤ 2 * m := bylet posSet : Finset ℤ := (Finset.Icc 2 (m + 1)).image (fun n : ℕ => (n : ℤ))let negSet : Finset ℤ := (Finset.Icc 2 (m + 1)).image (fun n : ℕ => -(n : ℤ))have hsub : S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1) ⊆ posSet ∪ negSet := byintro r hrsimp only [Finset.mem_filter] at hrrcases hr.2 with ⟨h2, hm⟩rw [Finset.mem_union]rcases Int.natAbs_eq r with hpos | hneg· leftexact Finset.mem_image.mpr ⟨r.natAbs, Finset.mem_Icc.mpr ⟨h2, hm⟩, hpos.symm⟩· rightexact Finset.mem_image.mpr ⟨r.natAbs, Finset.mem_Icc.mpr ⟨h2, hm⟩, by omega⟩calc (S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1)).card≤ (posSet ∪ negSet).card := Finset.card_le_card hsub_ ≤ posSet.card + negSet.card := Finset.card_union_le _ __ ≤ (Finset.Icc 2 (m + 1)).card + (Finset.Icc 2 (m + 1)).card :=Nat.add_le_add Finset.card_image_le Finset.card_image_le_ = 2 * m := by rw [Nat.card_Icc]; omega/-- For any `S : Finset ℤ` with `∀ r ∈ S, 2 ≤ r.natAbs` and `2 * m ≤ S.card`,`((m + 1)!)^2 ≤ ∏ r ∈ S, r.natAbs`. -/lemma factorial_sq_le_prod_natAbs :∀ (m : ℕ) (S : Finset ℤ), (∀ r ∈ S, 2 ≤ r.natAbs) → 2 * m ≤ S.card →((m + 1).factorial) ^ 2 ≤ ∏ r ∈ S, r.natAbs| 0, S, hge, _ => bysimp only [zero_add, Nat.factorial_one, one_pow]exact Finset.one_le_prod fun r hr => by have := hge r hr; omega| m + 1, S, hge, hcard => bylet Ssmall := S.filter (fun r => r.natAbs ≤ m + 1)let Sbig := S.filter (fun r => ¬ r.natAbs ≤ m + 1)have hsmall_eq : Ssmall = S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1) := byext r; simp only [Ssmall, Finset.mem_filter]exact ⟨fun ⟨hr, hle⟩ => ⟨hr, hge r hr, hle⟩, fun ⟨hr, _, hle⟩ => ⟨hr, hle⟩⟩have hsmall_le : Ssmall.card ≤ 2 * m := byrw [hsmall_eq]; exact card_filter_natAbs_between_le S mhave hpart : Ssmall.card + Sbig.card = S.card :=Finset.card_filter_add_card_filter_not (s := S) (fun r : ℤ => r.natAbs ≤ m + 1)have hbig_ge : 2 ≤ Sbig.card := by omegarcases Finset.one_lt_card.mp (by omega : 1 < Sbig.card) with ⟨a, ha, b, hb, hab⟩have haS : a ∈ S := (Finset.mem_filter.mp ha).1have hbS : b ∈ S := (Finset.mem_filter.mp hb).1have ha_ge : m + 2 ≤ a.natAbs := byhave := (Finset.mem_filter.mp ha).2; omegahave hb_ge : m + 2 ≤ b.natAbs := byhave := (Finset.mem_filter.mp hb).2; omegalet S' := (S.erase a).erase bhave hb_er : b ∈ S.erase a := Finset.mem_erase.mpr ⟨hab.symm, hbS⟩have hcard' : 2 * m ≤ S'.card := byrw [Finset.card_erase_of_mem hb_er, Finset.card_erase_of_mem haS]omegahave hge' : ∀ r ∈ S', 2 ≤ r.natAbs := fun r hr =>hge r (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase hr))have ih := factorial_sq_le_prod_natAbs m S' hge' hcard'have hprod : ∏ r ∈ S, r.natAbs = a.natAbs * (b.natAbs * ∏ r ∈ S', r.natAbs) := byrw [← Finset.mul_prod_erase S _ haS]congr 1exact (Finset.mul_prod_erase (S.erase a) _ hb_er).symmrw [hprod, Nat.factorial_succ, mul_pow]have hab_mul : (m + 2) ^ 2 ≤ a.natAbs * b.natAbs := by nlinarithcalc (m + 1 + 1) ^ 2 * (m + 1).factorial ^ 2≤ (a.natAbs * b.natAbs) * ∏ r ∈ S', r.natAbs := Nat.mul_le_mul hab_mul ih_ = a.natAbs * (b.natAbs * ∏ r ∈ S', r.natAbs) := by ring/-- Pure-`ℕ` pairing inequality: `k ^ k ≤ (k!) ^ 2` for every `k : ℕ`. -/lemma pow_self_le_factorial_sq (k : ℕ) : k ^ k ≤ (k.factorial) ^ 2 := byhave hprod_fact : ∏ i ∈ Finset.range k, (i + 1) = k.factorial := byinduction k with| zero => simp| succ n ih => rw [Finset.prod_range_succ, ih, Nat.factorial_succ, mul_comm]have hprod_rev : ∏ i ∈ Finset.range k, (k - i) = k.factorial := byrw [← hprod_fact]refine Finset.prod_bij (fun i _ => k - 1 - i) ?_ ?_ ?_ ?_· intro i hi; simp only [Finset.mem_range] at hi ⊢; omega· intro i hi j hj hij; simp only [Finset.mem_range] at hi hj; omega· intro j hj; simp only [Finset.mem_range] at hjexact ⟨k - 1 - j, Finset.mem_range.mpr (by omega), by omega⟩· intro i hi; simp only [Finset.mem_range] at hi; omegacalc k ^ k= ∏ _i ∈ Finset.range k, k := by simp_ ≤ ∏ i ∈ Finset.range k, ((i + 1) * (k - i)) := byrefine Finset.prod_le_prod fun i hi => ?_have hi' : i < k := Finset.mem_range.mp hihave h1 : (i + 1) * (k - i) = k + i * (k - 1 - i) := byzify [show i ≤ k by omega, show i ≤ k - 1 by omega, show 1 ≤ k by omega]; ringomega_ = (∏ i ∈ Finset.range k, (i + 1)) * (∏ i ∈ Finset.range k, (k - i)) :=Finset.prod_mul_distrib_ = (k.factorial) ^ 2 := by rw [hprod_fact, hprod_rev, sq]/-- At most `3` integers have `r.natAbs < 2` (namely `-1, 0, 1`). -/lemma card_filter_natAbs_lt_two_le (T : Finset ℤ) :(T.filter (fun r => r.natAbs < 2)).card ≤ 3 := byhave hsub : T.filter (fun r => r.natAbs < 2) ⊆ ({-1, 0, 1} : Finset ℤ) := byintro r hrhave hlt := (Finset.mem_filter.mp hr).2simp only [Finset.mem_insert, Finset.mem_singleton]omegaexact le_trans (Finset.card_le_card hsub) (by decide)/-! ## 6. Main Unconditional Elementary `O(2^τ / τ)` Theorems -//-- Pure-`ℕ` arithmetic closure: if `k ^ k ≤ 2 ^ (2 ^ (n - 1))` and `z ≤ 2 * k + 2`and `z ≤ 2 ^ n`, then `n * z ≤ 3 * 2 ^ n`. -/lemma nat_l2_closure {n z k : ℕ} (hz_deg : z ≤ 2 ^ n) (hz_k : z ≤ 2 * k + 2)(hkk : n ≥ 1 → k ^ k ≤ 2 ^ (2 ^ (n - 1))) :n * z ≤ 3 * 2 ^ n := byby_cases hn3 : n ≤ 3· exact le_trans (Nat.mul_le_mul_right z hn3) (Nat.mul_le_mul_left 3 hz_deg)· push Not at hn3-- Now n ≥ 4!by_contra hgtpush Not at hgthave hn1 : 1 ≤ n := by omegahave hkk' := hkk hn1set h := n / 2 with hh_defhave hh2 : 2 ≤ h := by omega-- Step A: show 2 ^ (n - 1) < h * khave h_two_n_ge : 2 * n ≤ 2 ^ (n - 1) + 2 := by-- For n ≥ 4: 2*4 = 8 ≤ 8 + 2 = 10; induction step doubles RHShave hind : ∀ m : ℕ, 4 ≤ m → 2 * m ≤ 2 ^ (m - 1) + 2 := byintro m hminduction m with| zero => omega| succ r ih =>by_cases hr : r = 3· subst hr; norm_num· have hr4 : 4 ≤ r := by omegahave ihr := ih hr4have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := byconv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]simp only [Nat.add_sub_cancel] at ihr ⊢omegaexact hind n hn3have h_hk_gt : 2 ^ (n - 1) < h * k := byhave hpow_n : 2 ^ n = 2 * 2 ^ (n - 1) := byconv_lhs => rw [← Nat.sub_add_cancel hn1, pow_succ, mul_comm]have hn_le : n ≤ 2 * h + 1 := by omega-- 6 * 2^(n-1) = 3 * 2^n < n * z ≤ n * (2k + 2) = 2*n*k + 2*n-- And 2*n*k ≤ (4*h + 2)*k ≤ 5*h*k (since h ≥ 2 => 2 ≤ h)-- Wait: at n = 4 (h = 2): 3*16 = 48 < 4*z => z ≥ 13 => k ≥ 6 => h*k = 12 > 8 = 2^3!by_cases hn4 : n = 4· subst hn4have : 13 ≤ z := by omegahave : 6 ≤ k := by omeganorm_num [h] at *; omega· have hn5 : 5 ≤ n := by omegahave h2n_le : 2 * n ≤ 2 ^ (n - 1) := byhave hind : ∀ m : ℕ, 5 ≤ m → 2 * m ≤ 2 ^ (m - 1) := byintro m hminduction m with| zero => omega| succ r ih =>by_cases hr : r = 4· subst hr; norm_num· have ihr := ih (by omega)have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := byconv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]simp only [Nat.add_sub_cancel] at ihr ⊢omegaexact hind n hn5have h1 : 6 * 2 ^ (n - 1) < n * (2 * k + 2) := bycalc 6 * 2 ^ (n - 1) = 3 * 2 ^ n := by rw [hpow_n]; ring_ < n * z := hgt_ ≤ n * (2 * k + 2) := Nat.mul_le_mul_left n hz_khave h2 : n * (2 * k + 2) ≤ 5 * (h * k) + 2 ^ (n - 1) := byhave hnk : 2 * n * k ≤ 5 * (h * k) := byhave : 2 * n ≤ 5 * h := by omegacalc 2 * n * k ≤ (5 * h) * k := Nat.mul_le_mul_right k this_ = 5 * (h * k) := by ringnlinarithomega-- Step B: show 2 ^ h ≤ k (since h ≤ 2 ^ (h - 1) ≤ 2 ^ (n - 1 - h))have h_le_pow : h ≤ 2 ^ (n - 1 - h) := byhave h1 : ∀ m : ℕ, 2 ≤ m → m ≤ 2 ^ (m - 1) := byintro m hminduction m with| zero => omega| succ r ih =>by_cases hr : r = 1· subst hr; norm_num· have ihr := ih (by omega)have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := byconv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]simp only [Nat.add_sub_cancel] at ihr ⊢omegahave h2 : h - 1 ≤ n - 1 - h := by omegaexact le_trans (h1 h hh2) (Nat.pow_le_pow_right (by norm_num) h2)have h2h_le_k : 2 ^ h ≤ k := byby_contra hltpush Not at hlthave hmul : h * k ≤ 2 ^ (n - 1) := bycalc h * k ≤ 2 ^ (n - 1 - h) * 2 ^ h := Nat.mul_le_mul h_le_pow (le_of_lt hlt)_ = 2 ^ (n - 1 - h + h) := (pow_add 2 _ _).symm_ = 2 ^ (n - 1) := by congr 1; omegaomega-- Step C: Contradiction: 2^(2^(n-1)) < 2^(h*k) = (2^h)^k ≤ k^k ≤ 2^(2^(n-1))!have hcontra : 2 ^ (2 ^ (n - 1)) < k ^ k := bycalc 2 ^ (2 ^ (n - 1))< 2 ^ (h * k) := Nat.pow_lt_pow_right (by norm_num) h_hk_gt_ = (2 ^ h) ^ k := pow_mul 2 h k_ ≤ k ^ k := Nat.pow_le_pow_left h2h_le_k komega/-- **Unconditional Pure-`ℤ` `L₂`-Reflection Theorem (`τ · z_ℤ(P) ≤ 3 · 2^τ`):**For every `τ : ℕ` and every constant-free straight-line program `P : SLP τ` with`P.evalPoly ≠ 0`:`τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`. -/theorem slp_intRootCount_l2_reflection {τ : ℕ} (P : SLP τ) (hP : P.evalPoly ≠ 0) :τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ := bylet S := (intRootSet P.evalPoly).filter (fun r => 2 ≤ r.natAbs)have hpart : ((intRootSet P.evalPoly).filter (fun r => r.natAbs < 2)).card + S.card =intRootCount P.evalPoly := byhave h := Finset.card_filter_add_card_filter_not(s := intRootSet P.evalPoly) (p := fun r => r.natAbs < 2)have hS_eq : S = (intRootSet P.evalPoly).filter (fun r => ¬ r.natAbs < 2) := byext r; simp only [S, Finset.mem_filter, not_lt]rw [hS_eq]; exact hhave hsmall := card_filter_natAbs_lt_two_le (intRootSet P.evalPoly)let m := S.card / 2let k := m + 1have hz_k : intRootCount P.evalPoly ≤ 2 * k + 2 := by omegahave hz_deg : intRootCount P.evalPoly ≤ 2 ^ τ := slp_intRootCount_le_two_pow P hPrefine nat_l2_closure hz_deg hz_k fun hτ => ?_have hS_roots : ∀ r ∈ S, P.evalPoly.IsRoot r := fun r hr =>(mem_intRootSet_iff.mp (Finset.mem_filter.mp hr).1).2have hS_ge2 : ∀ r ∈ S, 2 ≤ r.natAbs := fun r hr => (Finset.mem_filter.mp hr).2have hS_ne0 : ∀ r ∈ S, r ≠ 0 := fun r hr => byhave := hS_ge2 r hr; omegacalc k ^ k≤ k.factorial ^ 2 := pow_self_le_factorial_sq k_ ≤ ∏ r ∈ S, r.natAbs := factorial_sq_le_prod_natAbs m S hS_ge2 (by omega)_ ≤ l1Norm P.evalPoly := prod_natAbs_roots_le_l1Norm hP S hS_roots hS_ne0_ ≤ 2 ^ (2 ^ (τ - 1)) := slp_l1Norm_le hτ P/-- **Multiplication-Prefix Shifted `L₂`-Reflection Theorem:**If `t₀ = P.mulPrefixLen` is the length of the leading all-multiplication prefix of `P : SLP τ`,then `(τ - t₀) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - t₀)`. -/theorem slp_intRootCount_l2_reflection_shifted {τ : ℕ} (P : SLP τ) (hP : P.evalPoly ≠ 0) :(τ - P.mulPrefixLen) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - P.mulPrefixLen) := byby_cases hall : P.mulPrefixLen = τ· rw [hall, Nat.sub_self, zero_mul]; exact Nat.zero_le _· have hple := P.mulPrefixLen_leset n := τ - P.mulPrefixLen with hn_defhave hn1 : 1 ≤ n := by omegalet S := (intRootSet P.evalPoly).filter (fun r => 2 ≤ r.natAbs)have hpart : ((intRootSet P.evalPoly).filter (fun r => r.natAbs < 2)).card + S.card =intRootCount P.evalPoly := byhave h := Finset.card_filter_add_card_filter_not(s := intRootSet P.evalPoly) (p := fun r => r.natAbs < 2)have hS_eq : S = (intRootSet P.evalPoly).filter (fun r => ¬ r.natAbs < 2) := byext r; simp only [S, Finset.mem_filter, not_lt]rw [hS_eq]; exact hhave hsmall := card_filter_natAbs_lt_two_le (intRootSet P.evalPoly)let m := S.card / 2let k := m + 1have hz_k : intRootCount P.evalPoly ≤ 2 * k + 2 := by omegahave hkk : k ^ k ≤ 2 ^ (2 ^ (n - 1)) := byhave hS_roots : ∀ r ∈ S, P.evalPoly.IsRoot r := fun r hr =>(mem_intRootSet_iff.mp (Finset.mem_filter.mp hr).1).2have hS_ge2 : ∀ r ∈ S, 2 ≤ r.natAbs := fun r hr => (Finset.mem_filter.mp hr).2have hS_ne0 : ∀ r ∈ S, r ≠ 0 := fun r hr => byhave := hS_ge2 r hr; omegahave hl1 : l1Norm P.evalPoly ≤ 2 ^ (2 ^ (n - 1)) := byhave h := slp_evalWire_l1Norm_le_shifted P ⟨τ + 1, Nat.lt_succ_self _⟩simpa [SLP.evalPoly, hall, ← hn_def] using hcalc k ^ k≤ k.factorial ^ 2 := pow_self_le_factorial_sq k_ ≤ ∏ r ∈ S, r.natAbs := factorial_sq_le_prod_natAbs m S hS_ge2 (by omega)_ ≤ l1Norm P.evalPoly := prod_natAbs_roots_le_l1Norm hP S hS_roots hS_ne0_ ≤ 2 ^ (2 ^ (n - 1)) := hl1by_cases hn3 : n ≤ 3· by_cases hn1' : n = 1· rw [hn1'] at hkk ⊢have : k ≤ 1 := byby_contra h2; push Not at h2have : 4 ≤ k ^ k := calc 4 = 2 ^ 2 := by norm_num_ ≤ k ^ 2 := Nat.pow_le_pow_left h2 2_ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h2norm_num at hkk; omegaomega· by_cases hn2' : n = 2· rw [hn2'] at hkk ⊢have : k ≤ 2 := byby_contra h3; push Not at h3have : 27 ≤ k ^ k := calc 27 = 3 ^ 3 := by norm_num_ ≤ k ^ 3 := Nat.pow_le_pow_left h3 3_ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h3norm_num at hkk; omegaomega· have hn3' : n = 3 := by omegarw [hn3'] at hkk ⊢have : k ≤ 2 := byby_contra h3; push Not at h3have : 27 ≤ k ^ k := calc 27 = 3 ^ 3 := by norm_num_ ≤ k ^ 3 := Nat.pow_le_pow_left h3 3_ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h3norm_num at hkk; omegaomega· have hn4 : 4 ≤ n := by omegaexact nat_l2_closure (n := n) (z := intRootCount P.evalPoly) (k := k)(byby_contra hgt; push Not at hgthave hk_ge : 2 ^ (n - 1) ≤ k := byhave : 2 ^ n = 2 * 2 ^ (n - 1) := byconv_lhs => rw [← Nat.sub_add_cancel hn1, pow_succ, mul_comm]omegahave hpow_ge : 2 ^ (n - 1) ≥ 8 := byhave : 3 ≤ n - 1 := by omegacalc 8 = 2 ^ 3 := by norm_num_ ≤ 2 ^ (n - 1) := Nat.pow_le_pow_right (by norm_num) thishave : 2 ^ (2 ^ (n - 1)) < k ^ k := bycalc 2 ^ (2 ^ (n - 1))< 4 ^ (2 ^ (n - 1)) := Nat.pow_lt_pow_left (by norm_num) (by omega)_ ≤ (2 ^ (n - 1)) ^ (2 ^ (n - 1)) := Nat.pow_le_pow_left (by omega) __ ≤ k ^ (2 ^ (n - 1)) := Nat.pow_le_pow_left hk_ge __ ≤ k ^ k := Nat.pow_le_pow_right (by omega) hk_geomega)hz_k (fun _ => hkk)end Research.PvsNP.Tau