Lean / 0xOsprey/shub-smale-tau9 / L2ReflectionBound.lean
Lean reader

Research/PvsNP/Tau/L2ReflectionBound.lean

882 lines31 declarationsno sorry
  1. module
  2. public import Research.PvsNP.Tau.TauConjecture
  3. @[expose] public section
  4. namespace Research.PvsNP.Tau
  5. /-!
  6. # Pure-ℤ Algebraic `L₂`-Reflection Bound (`τ · z_ℤ(P) ≤ 3 · 2^τ`)
  7. This module proves an unconditional, completely elementary `O(2^τ / τ)` upper bound on the
  8. number of distinct integer roots of every constant-free, division-free straight-line program
  9. `P : SLP τ` over `ℤ[X]`, using **zero** real analysis, **zero** complex analysis, **zero**
  10. logarithms, and **zero** `p`-adic machinery:
  11. `∀ {τ : ℕ} (P : SLP τ), P.evalPoly ≠ 0 → τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`
  12. This sharpens `GapDominanceBound.lean` (`2^τ / τ^(1/28)`) by `28×` in the exponent of `τ`
  13. and matches the information-theoretic `Θ(2^τ / τ)` ceiling for all global degree/height/Mahler
  14. methods up to a small absolute constant.
  15. ### Proof Structure
  16. 1. **1-Step `L₂`-Reflection Identity (`l2Sq_mul_X_sub_eq_one_sub_mul_X`):**
  17. For every `f : Polynomial ℤ` and `r : ℤ`, `‖f · (X - r)‖₂² = ‖f · (1 - r X)‖₂²`.
  18. 2. **Multi-Root Reflection (`prod_natAbs_roots_le_l1Norm`):**
  19. Reflecting every integer root `r ∈ S` (`r ≠ 0`) turns `f = Q · ∏ (X - r)` into
  20. `f* = Q · ∏ (1 - r X)` with `∏ |r| ≤ |lc(f*)| ≤ ‖f*‖₂ = ‖f‖₂ ≤ ‖f‖₁`.
  21. 3. **SLP `L₁`-Norm Bound (`slp_l1Norm_le`):**
  22. Every nonzero `P : SLP τ` (`τ ≥ 1`) satisfies `l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1))`
  23. (and `≤ 2 ^ (2 ^ (τ - t₀ - 1))` if the first `t₀` gates are all multiplications).
  24. 4. **Pure-`ℕ` Factorial Pairing (`pow_self_le_prod_natAbs`):**
  25. For `S ⊆ {r ∈ ℤ : 2 ≤ |r|}` with `2 * m ≤ S.card`, `k = m + 1` satisfies
  26. `k ^ k ≤ (k!)^2 ≤ ∏ r ∈ S, r.natAbs`.
  27. 5. **Pure-`ℕ` Closure (`slp_intRootCount_l2_reflection`):**
  28. Combining (2)–(4) with `h = τ / 2` yields `τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`
  29. (and `(τ - t₀) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - t₀)` for a `t₀`-multiplication prefix).
  30. -/
  31. open Polynomial
  32. /-! ## 1. Polynomial `L₁`-Norm and Squared `L₂`-Norm over `ℤ[X]` -/
  33. /-- The `L₁`-norm (sum of absolute values of coefficients) of `f ∈ ℤ[X]`. -/
  34. noncomputable def l1Norm (f : Polynomial ℤ) : ℕ :=
  35. ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k).natAbs
  36. /-- The squared `L₂`-norm (sum of squares of coefficients) of `f ∈ ℤ[X]`. -/
  37. noncomputable def l2Sq (f : Polynomial ℤ) : ℕ :=
  38. ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k).natAbs ^ 2
  39. lemma l1Norm_eq_sum_range {f : Polynomial ℤ} {N : ℕ} (hN : f.natDegree + 1 ≤ N) :
  40. l1Norm f = ∑ k ∈ Finset.range N, (f.coeff k).natAbs := by
  41. unfold l1Norm
  42. refine Finset.sum_subset (Finset.range_mono hN) ?_
  43. intro k _ hk
  44. have hlt : f.natDegree < k := by
  45. simp only [Finset.mem_range, not_lt] at hk
  46. omega
  47. simp [Polynomial.coeff_eq_zero_of_natDegree_lt hlt]
  48. lemma l2Sq_eq_sum_range {f : Polynomial ℤ} {N : ℕ} (hN : f.natDegree + 1 ≤ N) :
  49. l2Sq f = ∑ k ∈ Finset.range N, (f.coeff k).natAbs ^ 2 := by
  50. unfold l2Sq
  51. refine Finset.sum_subset (Finset.range_mono hN) ?_
  52. intro k _ hk
  53. have hlt : f.natDegree < k := by
  54. simp only [Finset.mem_range, not_lt] at hk
  55. omega
  56. simp [Polynomial.coeff_eq_zero_of_natDegree_lt hlt]
  57. lemma l1Norm_one : l1Norm (1 : Polynomial ℤ) = 1 := by
  58. simp [l1Norm]
  59. lemma l1Norm_X : l1Norm (Polynomial.X : Polynomial ℤ) = 1 := by
  60. simp [l1Norm, Finset.sum_range_succ]
  61. lemma l1Norm_add_le (f g : Polynomial ℤ) : l1Norm (f + g) ≤ l1Norm f + l1Norm g := by
  62. let N := max f.natDegree g.natDegree + 1
  63. have hfg : (f + g).natDegree + 1 ≤ N := by
  64. have := Polynomial.natDegree_add_le f g; omega
  65. have hf : f.natDegree + 1 ≤ N := by omega
  66. have hg : g.natDegree + 1 ≤ N := by omega
  67. rw [l1Norm_eq_sum_range hfg, l1Norm_eq_sum_range hf, l1Norm_eq_sum_range hg,
  68. ← Finset.sum_add_distrib]
  69. refine Finset.sum_le_sum fun k _ => ?_
  70. rw [Polynomial.coeff_add]
  71. exact Int.natAbs_add_le _ _
  72. lemma l1Norm_sub_le (f g : Polynomial ℤ) : l1Norm (f - g) ≤ l1Norm f + l1Norm g := by
  73. let N := max f.natDegree g.natDegree + 1
  74. have hfg : (f - g).natDegree + 1 ≤ N := by
  75. have := Polynomial.natDegree_sub_le f g; omega
  76. have hf : f.natDegree + 1 ≤ N := by omega
  77. have hg : g.natDegree + 1 ≤ N := by omega
  78. rw [l1Norm_eq_sum_range hfg, l1Norm_eq_sum_range hf, l1Norm_eq_sum_range hg,
  79. ← Finset.sum_add_distrib]
  80. refine Finset.sum_le_sum fun k _ => ?_
  81. rw [Polynomial.coeff_sub, sub_eq_add_neg]
  82. calc (f.coeff k + -(g.coeff k)).natAbs
  83. ≤ (f.coeff k).natAbs + (-(g.coeff k)).natAbs := Int.natAbs_add_le _ _
  84. _ = (f.coeff k).natAbs + (g.coeff k).natAbs := by rw [Int.natAbs_neg]
  85. lemma natAbs_sum_le {ι : Type*} (s : Finset ι) (f : ι → ℤ) :
  86. (∑ i ∈ s, f i).natAbs ≤ ∑ i ∈ s, (f i).natAbs := by
  87. classical
  88. induction s using Finset.induction_on with
  89. | empty => simp
  90. | @insert a s ha ih =>
  91. rw [Finset.sum_insert ha, Finset.sum_insert ha]
  92. exact le_trans (Int.natAbs_add_le _ _) (Nat.add_le_add_left ih _)
  93. lemma l1Norm_mul_le (f g : Polynomial ℤ) : l1Norm (f * g) ≤ l1Norm f * l1Norm g := by
  94. let Nf := f.natDegree + 1
  95. let Ng := g.natDegree + 1
  96. have hfg : (f * g).natDegree + 1 ≤ Nf + Ng := by
  97. have := Polynomial.natDegree_mul_le (p := f) (q := g); omega
  98. rw [l1Norm_eq_sum_range hfg]
  99. unfold l1Norm
  100. rw [Finset.sum_mul]
  101. simp_rw [Finset.mul_sum]
  102. calc ∑ k ∈ Finset.range (Nf + Ng), ((f * g).coeff k).natAbs
  103. ≤ ∑ k ∈ Finset.range (Nf + Ng),
  104. ∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := by
  105. refine Finset.sum_le_sum fun k _ => ?_
  106. rw [Polynomial.coeff_mul]
  107. calc (∑ ij ∈ Finset.antidiagonal k, f.coeff ij.1 * g.coeff ij.2).natAbs
  108. ≤ ∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1 * g.coeff ij.2).natAbs :=
  109. natAbs_sum_le _ _
  110. _ = ∑ ij ∈ Finset.antidiagonal k, (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := by
  111. refine Finset.sum_congr rfl fun ij _ => Int.natAbs_mul _ _
  112. _ = ∑ k ∈ Finset.range (Nf + Ng),
  113. ∑ ij ∈ (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng),
  114. (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs := by
  115. refine Finset.sum_congr rfl fun k _ => ?_
  116. symm
  117. refine Finset.sum_subset (Finset.filter_subset _ _) ?_
  118. intro ij hij hnot
  119. simp only [Finset.mem_filter, hij, true_and, not_and_or, not_lt] at hnot
  120. rcases hnot with h1 | h2
  121. · have : f.natDegree < ij.1 := by omega
  122. simp [Polynomial.coeff_eq_zero_of_natDegree_lt this]
  123. · have : g.natDegree < ij.2 := by omega
  124. simp [Polynomial.coeff_eq_zero_of_natDegree_lt this]
  125. _ = ∑ i ∈ Finset.range Nf, ∑ j ∈ Finset.range Ng,
  126. (f.coeff i).natAbs * (g.coeff j).natAbs := by
  127. rw [show (∑ k ∈ Finset.range (Nf + Ng),
  128. ∑ ij ∈ (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng),
  129. (f.coeff ij.1).natAbs * (g.coeff ij.2).natAbs) =
  130. ∑ x ∈ (Finset.range (Nf + Ng)).sigma
  131. (fun k => (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng)),
  132. (f.coeff x.2.1).natAbs * (g.coeff x.2.2).natAbs from
  133. (Finset.sum_sigma (Finset.range (Nf + Ng))
  134. (fun k => (Finset.antidiagonal k).filter (fun ij => ij.1 < Nf ∧ ij.2 < Ng))
  135. (fun x => (f.coeff x.2.1).natAbs * (g.coeff x.2.2).natAbs)).symm,
  136. show (∑ i ∈ Finset.range Nf, ∑ j ∈ Finset.range Ng,
  137. (f.coeff i).natAbs * (g.coeff j).natAbs) =
  138. ∑ p ∈ Finset.range Nf ×ˢ Finset.range Ng,
  139. (f.coeff p.1).natAbs * (g.coeff p.2).natAbs from
  140. (Finset.sum_product (Finset.range Nf) (Finset.range Ng)
  141. (fun p => (f.coeff p.1).natAbs * (g.coeff p.2).natAbs)).symm]
  142. refine Finset.sum_bij
  143. (fun (x : Σ _ : ℕ, ℕ × ℕ) _ => x.2) ?_ ?_ ?_ ?_
  144. · intro x hx
  145. simp only [Finset.mem_sigma, Finset.mem_range, Finset.mem_filter,
  146. Finset.mem_product] at hx ⊢
  147. exact hx.2.2
  148. · intro x₁ hx₁ x₂ hx₂ heq
  149. simp only [Finset.mem_sigma, Finset.mem_filter, Finset.mem_antidiagonal] at hx₁ hx₂
  150. have hfst : x₁.1 = x₂.1 := by
  151. rw [← hx₁.2.1, ← hx₂.2.1, heq]
  152. exact Sigma.ext hfst (by simp [heq])
  153. · intro p hp
  154. simp only [Finset.mem_product, Finset.mem_range] at hp
  155. refine ⟨⟨p.1 + p.2, p⟩, ?_, rfl⟩
  156. simp only [Finset.mem_sigma, Finset.mem_range, Finset.mem_filter,
  157. Finset.mem_antidiagonal]
  158. exact ⟨by omega, trivial, hp.1, hp.2⟩
  159. · intro _ _; rfl
  160. lemma sum_sq_le_sq_sum (s : Finset ℕ) (a : ℕ → ℕ) :
  161. ∑ k ∈ s, (a k) ^ 2 ≤ (∑ k ∈ s, a k) ^ 2 := by
  162. classical
  163. induction s using Finset.induction_on with
  164. | empty => simp
  165. | @insert x s hx ih =>
  166. rw [Finset.sum_insert hx, Finset.sum_insert hx, add_sq]
  167. omega
  168. lemma l2Sq_le_l1Norm_sq (f : Polynomial ℤ) : l2Sq f ≤ (l1Norm f) ^ 2 :=
  169. sum_sq_le_sq_sum _ _
  170. lemma natAbs_leadingCoeff_sq_le_l2Sq (f : Polynomial ℤ) :
  171. f.leadingCoeff.natAbs ^ 2 ≤ l2Sq f := by
  172. unfold l2Sq
  173. rw [Polynomial.leadingCoeff]
  174. exact Finset.single_le_sum (f := fun k => (f.coeff k).natAbs ^ 2)
  175. (fun _ _ => Nat.zero_le _) (Finset.mem_range.mpr (Nat.lt_succ_self _))
  176. /-! ## 2. Exact 1-Step `L₂`-Reflection Identity over `ℤ[X]` -/
  177. /-- **1-Step `L₂`-Reflection Identity:**
  178. For every `f ∈ ℤ[X]` and every `r ∈ ℤ`,
  179. `‖f · (X - r)‖₂² = ‖f · (1 - r X)‖₂²`. -/
  180. theorem l2Sq_mul_X_sub_eq_one_sub_mul_X (f : Polynomial ℤ) (r : ℤ) :
  181. l2Sq (f * (Polynomial.X - Polynomial.C r)) =
  182. l2Sq (f * (1 - Polynomial.C r * Polynomial.X)) := by
  183. have hdeg1 : (f * (Polynomial.X - Polynomial.C r)).natDegree + 1 ≤ f.natDegree + 2 := by
  184. have h1 := Polynomial.natDegree_mul_le (p := f) (q := Polynomial.X - Polynomial.C r)
  185. have h2 : (Polynomial.X - Polynomial.C r).natDegree ≤ 1 := by
  186. calc (Polynomial.X - Polynomial.C r).natDegree
  187. ≤ max Polynomial.X.natDegree (Polynomial.C r).natDegree := Polynomial.natDegree_sub_le _ _
  188. _ ≤ 1 := by simp
  189. omega
  190. have hdeg2 : (f * (1 - Polynomial.C r * Polynomial.X)).natDegree + 1 ≤ f.natDegree + 2 := by
  191. have h1 := Polynomial.natDegree_mul_le (p := f) (q := 1 - Polynomial.C r * Polynomial.X)
  192. have h2 : (1 - Polynomial.C r * Polynomial.X).natDegree ≤ 1 := by
  193. calc (1 - Polynomial.C r * Polynomial.X).natDegree
  194. ≤ max (1 : Polynomial ℤ).natDegree (Polynomial.C r * Polynomial.X).natDegree :=
  195. Polynomial.natDegree_sub_le _ _
  196. _ ≤ 1 := by
  197. have h1' : (1 : Polynomial ℤ).natDegree = 0 := Polynomial.natDegree_one
  198. have h2' := Polynomial.natDegree_mul_le (p := Polynomial.C r) (q := Polynomial.X)
  199. have hC : (Polynomial.C r).natDegree = 0 := Polynomial.natDegree_C r
  200. have hX : (Polynomial.X : Polynomial ℤ).natDegree = 1 := Polynomial.natDegree_X
  201. omega
  202. omega
  203. rw [l2Sq_eq_sum_range hdeg1, l2Sq_eq_sum_range hdeg2]
  204. -- Cast to ℤ where (a.natAbs : ℤ)^2 = a^2 so `ring` closes the algebraic identity!
  205. apply (Nat.cast_inj (R := ℤ)).mp
  206. simp only [Nat.cast_sum, Nat.cast_pow, Int.natAbs_sq]
  207. have hcoeff1_zero : (f * (Polynomial.X - Polynomial.C r)).coeff 0 = -(r * f.coeff 0) := by
  208. rw [mul_sub, Polynomial.coeff_sub, Polynomial.coeff_mul_X_zero,
  209. Polynomial.coeff_mul_C]; ring
  210. have hcoeff1_succ : ∀ k : ℕ,
  211. (f * (Polynomial.X - Polynomial.C r)).coeff (k + 1) =
  212. f.coeff k - r * f.coeff (k + 1) := by
  213. intro k
  214. rw [mul_sub, Polynomial.coeff_sub, Polynomial.coeff_mul_X, Polynomial.coeff_mul_C]
  215. ring
  216. have hcoeff2_zero : (f * (1 - Polynomial.C r * Polynomial.X)).coeff 0 = f.coeff 0 := by
  217. rw [mul_sub, mul_one, ← mul_assoc, Polynomial.coeff_sub, Polynomial.coeff_mul_X_zero, sub_zero]
  218. have hcoeff2_succ : ∀ k : ℕ,
  219. (f * (1 - Polynomial.C r * Polynomial.X)).coeff (k + 1) =
  220. f.coeff (k + 1) - r * f.coeff k := by
  221. intro k
  222. rw [mul_sub, mul_one, ← mul_assoc, Polynomial.coeff_sub, Polynomial.coeff_mul_X,
  223. Polynomial.coeff_mul_C]
  224. ring
  225. have htop : f.coeff (f.natDegree + 1) = 0 :=
  226. Polynomial.coeff_eq_zero_of_natDegree_lt (Nat.lt_succ_self _)
  227. -- Split off k = 0 on both sides using `Finset.sum_range_succ'`
  228. conv_lhs => rw [Finset.sum_range_succ']
  229. conv_rhs => rw [Finset.sum_range_succ']
  230. rw [hcoeff1_zero, hcoeff2_zero]
  231. simp_rw [hcoeff1_succ, hcoeff2_succ]
  232. -- Expand squares and compare term-by-term!
  233. have hexp1 : ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff k - r * f.coeff (k + 1)) ^ 2 =
  234. (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2) +
  235. r ^ 2 * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) -
  236. 2 * r * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k * f.coeff (k + 1)) := by
  237. rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]
  238. refine Finset.sum_congr rfl fun k _ => by ring
  239. have hexp2 : ∑ k ∈ Finset.range (f.natDegree + 1), (f.coeff (k + 1) - r * f.coeff k) ^ 2 =
  240. (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) +
  241. r ^ 2 * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2) -
  242. 2 * r * (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k * f.coeff (k + 1)) := by
  243. rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]
  244. refine Finset.sum_congr rfl fun k _ => by ring
  245. have hshift :
  246. (∑ k ∈ Finset.range (f.natDegree + 1), f.coeff (k + 1) ^ 2) + f.coeff 0 ^ 2 =
  247. ∑ k ∈ Finset.range (f.natDegree + 1), f.coeff k ^ 2 := by
  248. have h1 := Finset.sum_range_succ' (fun k => f.coeff k ^ 2) (f.natDegree + 1)
  249. have h2 := Finset.sum_range_succ (fun k => f.coeff k ^ 2) (f.natDegree + 1)
  250. rw [htop] at h2
  251. linarith
  252. rw [hexp1, hexp2, ← hshift]
  253. ring
  254. /-! ## 3. Multi-Root Reflection & Product of Nonzero Roots Bound -/
  255. lemma l2Sq_mul_prod_X_sub_eq_reflected (Q : Polynomial ℤ) (S : Finset ℤ) :
  256. l2Sq (Q * ∏ r ∈ S, (Polynomial.X - Polynomial.C r)) =
  257. l2Sq (Q * ∏ r ∈ S, (1 - Polynomial.C r * Polynomial.X)) := by
  258. classical
  259. induction S using Finset.induction_on generalizing Q with
  260. | empty => simp
  261. | @insert a s ha ih =>
  262. rw [Finset.prod_insert ha, Finset.prod_insert ha]
  263. have h1 : Q * ((Polynomial.X - Polynomial.C a) * ∏ r ∈ s, (Polynomial.X - Polynomial.C r)) =
  264. (Q * (Polynomial.X - Polynomial.C a)) * ∏ r ∈ s, (Polynomial.X - Polynomial.C r) := by
  265. ring
  266. have h2 : Q * ((1 - Polynomial.C a * Polynomial.X) * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) =
  267. (Q * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) * (1 - Polynomial.C a * Polynomial.X) := by
  268. ring
  269. rw [h1, ih (Q * (Polynomial.X - Polynomial.C a))]
  270. have h3 : (Q * (Polynomial.X - Polynomial.C a)) * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X) =
  271. (Q * ∏ r ∈ s, (1 - Polynomial.C r * Polynomial.X)) * (Polynomial.X - Polynomial.C a) := by
  272. ring
  273. rw [h3, l2Sq_mul_X_sub_eq_one_sub_mul_X, ← h2]
  274. lemma exists_mul_prod_X_sub_of_roots (f : Polynomial ℤ) (hf : f ≠ 0) (S : Finset ℤ)
  275. (hS : ∀ r ∈ S, f.IsRoot r) :
  276. ∃ Q : Polynomial ℤ, Q ≠ 0 ∧ f = Q * ∏ r ∈ S, (Polynomial.X - Polynomial.C r) := by
  277. classical
  278. induction S using Finset.induction_on generalizing f with
  279. | empty =>
  280. exact ⟨f, hf, by simp⟩
  281. | @insert a s ha ih =>
  282. have ha_root : f.IsRoot a := hS a (Finset.mem_insert_self a s)
  283. rcases Polynomial.dvd_iff_isRoot.mpr ha_root with ⟨g, hg⟩
  284. have hg_ne : g ≠ 0 := by
  285. intro h0; rw [h0, mul_zero] at hg; exact hf hg
  286. have hs_root : ∀ r ∈ s, g.IsRoot r := by
  287. intro r hr
  288. have hfr : f.eval r = 0 := hS r (Finset.mem_insert_of_mem hr)
  289. rw [hg, Polynomial.eval_mul, Polynomial.eval_sub, Polynomial.eval_X,
  290. Polynomial.eval_C] at hfr
  291. have hne : r - a ≠ 0 := sub_ne_zero.mpr (fun h => ha (h ▸ hr))
  292. exact (mul_eq_zero.mp hfr).resolve_left hne
  293. rcases ih g hg_ne hs_root with ⟨Q, hQ_ne, hQ⟩
  294. refine ⟨Q, hQ_ne, ?_⟩
  295. rw [Finset.prod_insert ha, hg, hQ]
  296. ring
  297. lemma leadingCoeff_one_sub_C_mul_X {r : ℤ} (hr : r ≠ 0) :
  298. (1 - Polynomial.C r * Polynomial.X).leadingCoeff = -r := by
  299. have hcoeff1 : (1 - Polynomial.C r * Polynomial.X).coeff 1 = -r := by
  300. rw [Polynomial.coeff_sub, Polynomial.coeff_one, Polynomial.coeff_C_mul_X]
  301. simp
  302. have hdeg_le : (1 - Polynomial.C r * Polynomial.X).natDegree ≤ 1 := by
  303. have hsub := Polynomial.natDegree_sub_le (1 : Polynomial ℤ) (Polynomial.C r * Polynomial.X)
  304. have hmul := Polynomial.natDegree_mul_le (p := Polynomial.C r) (q := Polynomial.X)
  305. have h1' : (1 : Polynomial ℤ).natDegree = 0 := Polynomial.natDegree_one
  306. have hC : (Polynomial.C r).natDegree = 0 := Polynomial.natDegree_C r
  307. have hX : (Polynomial.X : Polynomial ℤ).natDegree = 1 := Polynomial.natDegree_X
  308. omega
  309. have hdeg_ge : 1 ≤ (1 - Polynomial.C r * Polynomial.X).natDegree :=
  310. Polynomial.le_natDegree_of_ne_zero (by rw [hcoeff1]; exact neg_ne_zero.mpr hr)
  311. have hdeg : (1 - Polynomial.C r * Polynomial.X).natDegree = 1 := le_antisymm hdeg_le hdeg_ge
  312. rw [Polynomial.leadingCoeff, hdeg, hcoeff1]
  313. lemma natAbs_prod_neg (S : Finset ℤ) :
  314. (∏ r ∈ S, (-r : ℤ)).natAbs = ∏ r ∈ S, r.natAbs := by
  315. classical
  316. induction S using Finset.induction_on with
  317. | empty => simp
  318. | @insert a s ha ih =>
  319. rw [Finset.prod_insert ha, Finset.prod_insert ha, Int.natAbs_mul, Int.natAbs_neg, ih]
  320. /-- **Multi-Root `L₁`-Norm Bound:**
  321. For every nonzero `f ∈ ℤ[X]` and any finite set `S` of nonzero integer roots of `f`,
  322. `∏ r ∈ S, r.natAbs ≤ l1Norm f`. -/
  323. theorem prod_natAbs_roots_le_l1Norm {f : Polynomial ℤ} (hf : f ≠ 0) (S : Finset ℤ)
  324. (hS : ∀ r ∈ S, f.IsRoot r) (hne : ∀ r ∈ S, r ≠ 0) :
  325. ∏ r ∈ S, r.natAbs ≤ l1Norm f := by
  326. rcases exists_mul_prod_X_sub_of_roots f hf S hS with ⟨Q, hQ_ne, hQ⟩
  327. let Pstar := Q * ∏ r ∈ S, (1 - Polynomial.C r * Polynomial.X)
  328. have hlc : Pstar.leadingCoeff = Q.leadingCoeff * ∏ r ∈ S, (-r) := by
  329. dsimp [Pstar]
  330. rw [Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_prod]
  331. congr 1
  332. refine Finset.prod_congr rfl fun r hr => leadingCoeff_one_sub_C_mul_X (hne r hr)
  333. have hQ_pos : 1 ≤ Q.leadingCoeff.natAbs := by
  334. have hlc_ne : Q.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr hQ_ne
  335. exact Nat.pos_of_ne_zero (Int.natAbs_ne_zero.mpr hlc_ne)
  336. have hprod_le : ∏ r ∈ S, r.natAbs ≤ Pstar.leadingCoeff.natAbs := by
  337. rw [hlc, Int.natAbs_mul, natAbs_prod_neg]
  338. exact Nat.le_mul_of_pos_left _ hQ_pos
  339. have hsq : (∏ r ∈ S, r.natAbs) ^ 2 ≤ (l1Norm f) ^ 2 := by
  340. calc (∏ r ∈ S, r.natAbs) ^ 2
  341. ≤ Pstar.leadingCoeff.natAbs ^ 2 := Nat.pow_le_pow_left hprod_le 2
  342. _ ≤ l2Sq Pstar := natAbs_leadingCoeff_sq_le_l2Sq Pstar
  343. _ = l2Sq f := by rw [hQ, l2Sq_mul_prod_X_sub_eq_reflected]
  344. _ ≤ (l1Norm f) ^ 2 := l2Sq_le_l1Norm_sq f
  345. nlinarith
  346. /-! ## 4. SLP `L₁`-Norm Upper Bound -/
  347. /-- For `τ ≥ 1`, every wire of `P : SLP τ` has `l1Norm ≤ 2 ^ (2 ^ (τ - 1))`. -/
  348. lemma slp_evalWire_l1Norm_le : ∀ {τ : ℕ} (P : SLP τ) (k : Fin (τ + 2)),
  349. l1Norm (P.evalWire k) ≤ if τ = 0 then 1 else 2 ^ (2 ^ (τ - 1))
  350. | 0, .nil, k => by
  351. simp only [SLP.evalWire, ↓reduceIte]
  352. split_ifs
  353. · simp [l1Norm_one]
  354. · simp [l1Norm_X]
  355. | τ + 1, .snoc P op i j, k => by
  356. simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel]
  357. simp only [SLP.evalWire]
  358. split_ifs with hk
  359. · have ih := slp_evalWire_l1Norm_le P ⟨k.val, hk⟩
  360. cases τ with
  361. | zero =>
  362. simp only [↓reduceIte] at ih
  363. exact le_trans ih (by norm_num)
  364. | succ m =>
  365. simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] at ih
  366. refine le_trans ih (Nat.pow_le_pow_right (by norm_num) ?_)
  367. exact Nat.pow_le_pow_right (by norm_num) (Nat.le_succ m)
  368. · have ihi := slp_evalWire_l1Norm_le P i
  369. have ihj := slp_evalWire_l1Norm_le P j
  370. cases τ with
  371. | zero =>
  372. simp only [↓reduceIte] at ihi ihj
  373. cases op with
  374. | add =>
  375. calc l1Norm (P.evalWire i + P.evalWire j)
  376. ≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_add_le _ _
  377. _ ≤ 1 + 1 := Nat.add_le_add ihi ihj
  378. _ = 2 ^ (2 ^ 0) := by norm_num
  379. | sub =>
  380. calc l1Norm (P.evalWire i - P.evalWire j)
  381. ≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_sub_le _ _
  382. _ ≤ 1 + 1 := Nat.add_le_add ihi ihj
  383. _ = 2 ^ (2 ^ 0) := by norm_num
  384. | mul =>
  385. calc l1Norm (P.evalWire i * P.evalWire j)
  386. ≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ _
  387. _ ≤ 1 * 1 := Nat.mul_le_mul ihi ihj
  388. _ ≤ 2 ^ (2 ^ 0) := by norm_num
  389. | succ m =>
  390. simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] at ihi ihj
  391. set B := 2 ^ (2 ^ m) with hB_def
  392. have hB2 : 2 ≤ B := by
  393. rw [hB_def]
  394. have : 1 ≤ 2 ^ m := Nat.one_le_two_pow
  395. calc 2 = 2 ^ 1 := by norm_num
  396. _ ≤ 2 ^ (2 ^ m) := Nat.pow_le_pow_right (by norm_num) this
  397. have hBsq : B * B = 2 ^ (2 ^ (m + 1)) := by
  398. rw [hB_def, ← pow_add, pow_succ, mul_two]
  399. cases op with
  400. | add =>
  401. calc l1Norm (P.evalWire i + P.evalWire j)
  402. ≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_add_le _ _
  403. _ ≤ B + B := Nat.add_le_add ihi ihj
  404. _ = 2 * B := by ring
  405. _ ≤ B * B := Nat.mul_le_mul_right B hB2
  406. _ = 2 ^ (2 ^ (m + 1)) := hBsq
  407. | sub =>
  408. calc l1Norm (P.evalWire i - P.evalWire j)
  409. ≤ l1Norm (P.evalWire i) + l1Norm (P.evalWire j) := l1Norm_sub_le _ _
  410. _ ≤ B + B := Nat.add_le_add ihi ihj
  411. _ = 2 * B := by ring
  412. _ ≤ B * B := Nat.mul_le_mul_right B hB2
  413. _ = 2 ^ (2 ^ (m + 1)) := hBsq
  414. | mul =>
  415. calc l1Norm (P.evalWire i * P.evalWire j)
  416. ≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ _
  417. _ ≤ B * B := Nat.mul_le_mul ihi ihj
  418. _ = 2 ^ (2 ^ (m + 1)) := hBsq
  419. /-- Every constant-free `P : SLP τ` (`τ ≥ 1`) satisfies `l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1))`. -/
  420. theorem slp_l1Norm_le {τ : ℕ} (hτ : 1 ≤ τ) (P : SLP τ) :
  421. l1Norm P.evalPoly ≤ 2 ^ (2 ^ (τ - 1)) := by
  422. have h := slp_evalWire_l1Norm_le P ⟨τ + 1, Nat.lt_succ_self _⟩
  423. have hne : τ ≠ 0 := by omega
  424. simpa [SLP.evalPoly, hne] using h
  425. /-- Count of leading `.mul` gates before the first `.add`/`.sub` gate (i.e. `t₀`). -/
  426. def SLP.mulPrefixLen : {τ : ℕ} → SLP τ → ℕ
  427. | 0, .nil => 0
  428. | τ + 1, .snoc P op _ _ =>
  429. if P.mulPrefixLen = τ ∧ op = .mul then τ + 1 else P.mulPrefixLen
  430. lemma SLP.mulPrefixLen_le : ∀ {τ : ℕ} (P : SLP τ), P.mulPrefixLen ≤ τ
  431. | 0, .nil => le_rfl
  432. | τ + 1, .snoc P op _ _ => by
  433. have ih := P.mulPrefixLen_le
  434. change (if P.mulPrefixLen = τ ∧ op = .mul then τ + 1 else P.mulPrefixLen) ≤ τ + 1
  435. split_ifs <;> omega
  436. /-- Refined `L₁`-norm bound accounting for a leading multiplication prefix of length `t₀`:
  437. every wire of `P : SLP τ` has `l1Norm ≤ 1` if `t₀ = τ`, else `≤ 2 ^ (2 ^ (τ - t₀ - 1))`. -/
  438. lemma slp_evalWire_l1Norm_le_shifted : ∀ {τ : ℕ} (P : SLP τ) (k : Fin (τ + 2)),
  439. l1Norm (P.evalWire k) ≤
  440. if P.mulPrefixLen = τ then 1 else 2 ^ (2 ^ (τ - P.mulPrefixLen - 1))
  441. | 0, .nil, k => by
  442. simp only [SLP.mulPrefixLen, ↓reduceIte, SLP.evalWire]
  443. split_ifs
  444. · simp [l1Norm_one]
  445. · simp [l1Norm_X]
  446. | τ + 1, .snoc P op i j, k => by
  447. have hple := P.mulPrefixLen_le
  448. by_cases hall : P.mulPrefixLen = τ ∧ op = .mul
  449. · rcases hall with ⟨hpt, hop⟩
  450. have hpref : (SLP.snoc P op i j).mulPrefixLen = τ + 1 := by
  451. simp [SLP.mulPrefixLen, hpt, hop]
  452. rw [hpref]; simp only [↓reduceIte, SLP.evalWire]
  453. split_ifs with hk
  454. · have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩
  455. simpa [hpt] using ih
  456. · have ihi := slp_evalWire_l1Norm_le_shifted P i
  457. have ihj := slp_evalWire_l1Norm_le_shifted P j
  458. simp only [hpt, ↓reduceIte] at ihi ihj
  459. rw [hop]
  460. calc l1Norm (P.evalWire i * P.evalWire j)
  461. ≤ l1Norm (P.evalWire i) * l1Norm (P.evalWire j) := l1Norm_mul_le _ _
  462. _ ≤ 1 * 1 := Nat.mul_le_mul ihi ihj
  463. _ = 1 := one_mul 1
  464. · have hpref : (SLP.snoc P op i j).mulPrefixLen = P.mulPrefixLen := by
  465. simp [SLP.mulPrefixLen, hall]
  466. have hne : P.mulPrefixLen ≠ τ + 1 := by omega
  467. rw [hpref]; simp only [hne, ↓reduceIte, SLP.evalWire]
  468. by_cases hpt : P.mulPrefixLen = τ
  469. · have hsub : τ + 1 - P.mulPrefixLen - 1 = 0 := by omega
  470. rw [hsub]
  471. split_ifs with hk
  472. · have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩
  473. simp only [hpt, ↓reduceIte] at ih
  474. exact le_trans ih (by norm_num)
  475. · have ihi := slp_evalWire_l1Norm_le_shifted P i
  476. have ihj := slp_evalWire_l1Norm_le_shifted P j
  477. simp only [hpt, ↓reduceIte] at ihi ihj
  478. cases op with
  479. | add => exact le_trans (l1Norm_add_le _ _) (by omega)
  480. | sub => exact le_trans (l1Norm_sub_le _ _) (by omega)
  481. | mul => exact False.elim (hall ⟨hpt, rfl⟩)
  482. · set e := τ - P.mulPrefixLen - 1 with he_def
  483. have hsub : τ + 1 - P.mulPrefixLen - 1 = e + 1 := by omega
  484. rw [hsub]
  485. set B := 2 ^ (2 ^ e) with hB_def
  486. have hB2 : 2 ≤ B := by
  487. rw [hB_def]
  488. have : 1 ≤ 2 ^ e := Nat.one_le_two_pow
  489. calc 2 = 2 ^ 1 := by norm_num
  490. _ ≤ 2 ^ (2 ^ e) := Nat.pow_le_pow_right (by norm_num) this
  491. have hBsq : B * B = 2 ^ (2 ^ (e + 1)) := by
  492. rw [hB_def, ← pow_add, pow_succ, mul_two]
  493. split_ifs with hk
  494. · have ih := slp_evalWire_l1Norm_le_shifted P ⟨k.val, hk⟩
  495. simp only [hpt, ↓reduceIte] at ih
  496. rw [← he_def] at ih
  497. exact le_trans ih (by rw [← hBsq]; exact Nat.le_mul_of_pos_right B (by omega))
  498. · have ihi := slp_evalWire_l1Norm_le_shifted P i
  499. have ihj := slp_evalWire_l1Norm_le_shifted P j
  500. simp only [hpt, ↓reduceIte] at ihi ihj
  501. rw [← he_def] at ihi ihj
  502. cases op with
  503. | add =>
  504. calc l1Norm (P.evalWire i + P.evalWire j)
  505. ≤ B + B := le_trans (l1Norm_add_le _ _) (Nat.add_le_add ihi ihj)
  506. _ = 2 * B := by ring
  507. _ ≤ B * B := Nat.mul_le_mul_right B hB2
  508. _ = 2 ^ (2 ^ (e + 1)) := hBsq
  509. | sub =>
  510. calc l1Norm (P.evalWire i - P.evalWire j)
  511. ≤ B + B := le_trans (l1Norm_sub_le _ _) (Nat.add_le_add ihi ihj)
  512. _ = 2 * B := by ring
  513. _ ≤ B * B := Nat.mul_le_mul_right B hB2
  514. _ = 2 ^ (2 ^ (e + 1)) := hBsq
  515. | mul =>
  516. calc l1Norm (P.evalWire i * P.evalWire j)
  517. ≤ B * B := le_trans (l1Norm_mul_le _ _) (Nat.mul_le_mul ihi ihj)
  518. _ = 2 ^ (2 ^ (e + 1)) := hBsq
  519. /-! ## 5. Pure-`ℕ` Factorial Pairing Bound -/
  520. /-- At most `2 * m` integers satisfy `2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1`. -/
  521. lemma card_filter_natAbs_between_le (S : Finset ℤ) (m : ℕ) :
  522. (S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1)).card ≤ 2 * m := by
  523. let posSet : Finset ℤ := (Finset.Icc 2 (m + 1)).image (fun n : ℕ => (n : ℤ))
  524. let negSet : Finset ℤ := (Finset.Icc 2 (m + 1)).image (fun n : ℕ => -(n : ℤ))
  525. have hsub : S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1) ⊆ posSet ∪ negSet := by
  526. intro r hr
  527. simp only [Finset.mem_filter] at hr
  528. rcases hr.2 with ⟨h2, hm⟩
  529. rw [Finset.mem_union]
  530. rcases Int.natAbs_eq r with hpos | hneg
  531. · left
  532. exact Finset.mem_image.mpr ⟨r.natAbs, Finset.mem_Icc.mpr ⟨h2, hm⟩, hpos.symm⟩
  533. · right
  534. exact Finset.mem_image.mpr ⟨r.natAbs, Finset.mem_Icc.mpr ⟨h2, hm⟩, by omega⟩
  535. calc (S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1)).card
  536. ≤ (posSet ∪ negSet).card := Finset.card_le_card hsub
  537. _ ≤ posSet.card + negSet.card := Finset.card_union_le _ _
  538. _ ≤ (Finset.Icc 2 (m + 1)).card + (Finset.Icc 2 (m + 1)).card :=
  539. Nat.add_le_add Finset.card_image_le Finset.card_image_le
  540. _ = 2 * m := by rw [Nat.card_Icc]; omega
  541. /-- For any `S : Finset ℤ` with `∀ r ∈ S, 2 ≤ r.natAbs` and `2 * m ≤ S.card`,
  542. `((m + 1)!)^2 ≤ ∏ r ∈ S, r.natAbs`. -/
  543. lemma factorial_sq_le_prod_natAbs :
  544. ∀ (m : ℕ) (S : Finset ℤ), (∀ r ∈ S, 2 ≤ r.natAbs) → 2 * m ≤ S.card →
  545. ((m + 1).factorial) ^ 2 ≤ ∏ r ∈ S, r.natAbs
  546. | 0, S, hge, _ => by
  547. simp only [zero_add, Nat.factorial_one, one_pow]
  548. exact Finset.one_le_prod fun r hr => by have := hge r hr; omega
  549. | m + 1, S, hge, hcard => by
  550. let Ssmall := S.filter (fun r => r.natAbs ≤ m + 1)
  551. let Sbig := S.filter (fun r => ¬ r.natAbs ≤ m + 1)
  552. have hsmall_eq : Ssmall = S.filter (fun r => 2 ≤ r.natAbs ∧ r.natAbs ≤ m + 1) := by
  553. ext r; simp only [Ssmall, Finset.mem_filter]
  554. exact ⟨fun ⟨hr, hle⟩ => ⟨hr, hge r hr, hle⟩, fun ⟨hr, _, hle⟩ => ⟨hr, hle⟩⟩
  555. have hsmall_le : Ssmall.card ≤ 2 * m := by
  556. rw [hsmall_eq]; exact card_filter_natAbs_between_le S m
  557. have hpart : Ssmall.card + Sbig.card = S.card :=
  558. Finset.card_filter_add_card_filter_not (s := S) (fun r : ℤ => r.natAbs ≤ m + 1)
  559. have hbig_ge : 2 ≤ Sbig.card := by omega
  560. rcases Finset.one_lt_card.mp (by omega : 1 < Sbig.card) with ⟨a, ha, b, hb, hab⟩
  561. have haS : a ∈ S := (Finset.mem_filter.mp ha).1
  562. have hbS : b ∈ S := (Finset.mem_filter.mp hb).1
  563. have ha_ge : m + 2 ≤ a.natAbs := by
  564. have := (Finset.mem_filter.mp ha).2; omega
  565. have hb_ge : m + 2 ≤ b.natAbs := by
  566. have := (Finset.mem_filter.mp hb).2; omega
  567. let S' := (S.erase a).erase b
  568. have hb_er : b ∈ S.erase a := Finset.mem_erase.mpr ⟨hab.symm, hbS⟩
  569. have hcard' : 2 * m ≤ S'.card := by
  570. rw [Finset.card_erase_of_mem hb_er, Finset.card_erase_of_mem haS]
  571. omega
  572. have hge' : ∀ r ∈ S', 2 ≤ r.natAbs := fun r hr =>
  573. hge r (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase hr))
  574. have ih := factorial_sq_le_prod_natAbs m S' hge' hcard'
  575. have hprod : ∏ r ∈ S, r.natAbs = a.natAbs * (b.natAbs * ∏ r ∈ S', r.natAbs) := by
  576. rw [← Finset.mul_prod_erase S _ haS]
  577. congr 1
  578. exact (Finset.mul_prod_erase (S.erase a) _ hb_er).symm
  579. rw [hprod, Nat.factorial_succ, mul_pow]
  580. have hab_mul : (m + 2) ^ 2 ≤ a.natAbs * b.natAbs := by nlinarith
  581. calc (m + 1 + 1) ^ 2 * (m + 1).factorial ^ 2
  582. ≤ (a.natAbs * b.natAbs) * ∏ r ∈ S', r.natAbs := Nat.mul_le_mul hab_mul ih
  583. _ = a.natAbs * (b.natAbs * ∏ r ∈ S', r.natAbs) := by ring
  584. /-- Pure-`ℕ` pairing inequality: `k ^ k ≤ (k!) ^ 2` for every `k : ℕ`. -/
  585. lemma pow_self_le_factorial_sq (k : ℕ) : k ^ k ≤ (k.factorial) ^ 2 := by
  586. have hprod_fact : ∏ i ∈ Finset.range k, (i + 1) = k.factorial := by
  587. induction k with
  588. | zero => simp
  589. | succ n ih => rw [Finset.prod_range_succ, ih, Nat.factorial_succ, mul_comm]
  590. have hprod_rev : ∏ i ∈ Finset.range k, (k - i) = k.factorial := by
  591. rw [← hprod_fact]
  592. refine Finset.prod_bij (fun i _ => k - 1 - i) ?_ ?_ ?_ ?_
  593. · intro i hi; simp only [Finset.mem_range] at hi ⊢; omega
  594. · intro i hi j hj hij; simp only [Finset.mem_range] at hi hj; omega
  595. · intro j hj; simp only [Finset.mem_range] at hj
  596. exact ⟨k - 1 - j, Finset.mem_range.mpr (by omega), by omega⟩
  597. · intro i hi; simp only [Finset.mem_range] at hi; omega
  598. calc k ^ k
  599. = ∏ _i ∈ Finset.range k, k := by simp
  600. _ ≤ ∏ i ∈ Finset.range k, ((i + 1) * (k - i)) := by
  601. refine Finset.prod_le_prod fun i hi => ?_
  602. have hi' : i < k := Finset.mem_range.mp hi
  603. have h1 : (i + 1) * (k - i) = k + i * (k - 1 - i) := by
  604. zify [show i ≤ k by omega, show i ≤ k - 1 by omega, show 1 ≤ k by omega]; ring
  605. omega
  606. _ = (∏ i ∈ Finset.range k, (i + 1)) * (∏ i ∈ Finset.range k, (k - i)) :=
  607. Finset.prod_mul_distrib
  608. _ = (k.factorial) ^ 2 := by rw [hprod_fact, hprod_rev, sq]
  609. /-- At most `3` integers have `r.natAbs < 2` (namely `-1, 0, 1`). -/
  610. lemma card_filter_natAbs_lt_two_le (T : Finset ℤ) :
  611. (T.filter (fun r => r.natAbs < 2)).card ≤ 3 := by
  612. have hsub : T.filter (fun r => r.natAbs < 2) ⊆ ({-1, 0, 1} : Finset ℤ) := by
  613. intro r hr
  614. have hlt := (Finset.mem_filter.mp hr).2
  615. simp only [Finset.mem_insert, Finset.mem_singleton]
  616. omega
  617. exact le_trans (Finset.card_le_card hsub) (by decide)
  618. /-! ## 6. Main Unconditional Elementary `O(2^τ / τ)` Theorems -/
  619. /-- Pure-`ℕ` arithmetic closure: if `k ^ k ≤ 2 ^ (2 ^ (n - 1))` and `z ≤ 2 * k + 2`
  620. and `z ≤ 2 ^ n`, then `n * z ≤ 3 * 2 ^ n`. -/
  621. lemma nat_l2_closure {n z k : ℕ} (hz_deg : z ≤ 2 ^ n) (hz_k : z ≤ 2 * k + 2)
  622. (hkk : n ≥ 1 → k ^ k ≤ 2 ^ (2 ^ (n - 1))) :
  623. n * z ≤ 3 * 2 ^ n := by
  624. by_cases hn3 : n ≤ 3
  625. · exact le_trans (Nat.mul_le_mul_right z hn3) (Nat.mul_le_mul_left 3 hz_deg)
  626. · push Not at hn3
  627. -- Now n ≥ 4!
  628. by_contra hgt
  629. push Not at hgt
  630. have hn1 : 1 ≤ n := by omega
  631. have hkk' := hkk hn1
  632. set h := n / 2 with hh_def
  633. have hh2 : 2 ≤ h := by omega
  634. -- Step A: show 2 ^ (n - 1) < h * k
  635. have h_two_n_ge : 2 * n ≤ 2 ^ (n - 1) + 2 := by
  636. -- For n ≥ 4: 2*4 = 8 ≤ 8 + 2 = 10; induction step doubles RHS
  637. have hind : ∀ m : ℕ, 4 ≤ m → 2 * m ≤ 2 ^ (m - 1) + 2 := by
  638. intro m hm
  639. induction m with
  640. | zero => omega
  641. | succ r ih =>
  642. by_cases hr : r = 3
  643. · subst hr; norm_num
  644. · have hr4 : 4 ≤ r := by omega
  645. have ihr := ih hr4
  646. have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := by
  647. conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]
  648. simp only [Nat.add_sub_cancel] at ihr ⊢
  649. omega
  650. exact hind n hn3
  651. have h_hk_gt : 2 ^ (n - 1) < h * k := by
  652. have hpow_n : 2 ^ n = 2 * 2 ^ (n - 1) := by
  653. conv_lhs => rw [← Nat.sub_add_cancel hn1, pow_succ, mul_comm]
  654. have hn_le : n ≤ 2 * h + 1 := by omega
  655. -- 6 * 2^(n-1) = 3 * 2^n < n * z ≤ n * (2k + 2) = 2*n*k + 2*n
  656. -- And 2*n*k ≤ (4*h + 2)*k ≤ 5*h*k (since h ≥ 2 => 2 ≤ h)
  657. -- Wait: at n = 4 (h = 2): 3*16 = 48 < 4*z => z ≥ 13 => k ≥ 6 => h*k = 12 > 8 = 2^3!
  658. by_cases hn4 : n = 4
  659. · subst hn4
  660. have : 13 ≤ z := by omega
  661. have : 6 ≤ k := by omega
  662. norm_num [h] at *; omega
  663. · have hn5 : 5 ≤ n := by omega
  664. have h2n_le : 2 * n ≤ 2 ^ (n - 1) := by
  665. have hind : ∀ m : ℕ, 5 ≤ m → 2 * m ≤ 2 ^ (m - 1) := by
  666. intro m hm
  667. induction m with
  668. | zero => omega
  669. | succ r ih =>
  670. by_cases hr : r = 4
  671. · subst hr; norm_num
  672. · have ihr := ih (by omega)
  673. have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := by
  674. conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]
  675. simp only [Nat.add_sub_cancel] at ihr ⊢
  676. omega
  677. exact hind n hn5
  678. have h1 : 6 * 2 ^ (n - 1) < n * (2 * k + 2) := by
  679. calc 6 * 2 ^ (n - 1) = 3 * 2 ^ n := by rw [hpow_n]; ring
  680. _ < n * z := hgt
  681. _ ≤ n * (2 * k + 2) := Nat.mul_le_mul_left n hz_k
  682. have h2 : n * (2 * k + 2) ≤ 5 * (h * k) + 2 ^ (n - 1) := by
  683. have hnk : 2 * n * k ≤ 5 * (h * k) := by
  684. have : 2 * n ≤ 5 * h := by omega
  685. calc 2 * n * k ≤ (5 * h) * k := Nat.mul_le_mul_right k this
  686. _ = 5 * (h * k) := by ring
  687. nlinarith
  688. omega
  689. -- Step B: show 2 ^ h ≤ k (since h ≤ 2 ^ (h - 1) ≤ 2 ^ (n - 1 - h))
  690. have h_le_pow : h ≤ 2 ^ (n - 1 - h) := by
  691. have h1 : ∀ m : ℕ, 2 ≤ m → m ≤ 2 ^ (m - 1) := by
  692. intro m hm
  693. induction m with
  694. | zero => omega
  695. | succ r ih =>
  696. by_cases hr : r = 1
  697. · subst hr; norm_num
  698. · have ihr := ih (by omega)
  699. have hpow : 2 ^ r = 2 * 2 ^ (r - 1) := by
  700. conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ r), pow_succ, mul_comm]
  701. simp only [Nat.add_sub_cancel] at ihr ⊢
  702. omega
  703. have h2 : h - 1 ≤ n - 1 - h := by omega
  704. exact le_trans (h1 h hh2) (Nat.pow_le_pow_right (by norm_num) h2)
  705. have h2h_le_k : 2 ^ h ≤ k := by
  706. by_contra hlt
  707. push Not at hlt
  708. have hmul : h * k ≤ 2 ^ (n - 1) := by
  709. calc h * k ≤ 2 ^ (n - 1 - h) * 2 ^ h := Nat.mul_le_mul h_le_pow (le_of_lt hlt)
  710. _ = 2 ^ (n - 1 - h + h) := (pow_add 2 _ _).symm
  711. _ = 2 ^ (n - 1) := by congr 1; omega
  712. omega
  713. -- Step C: Contradiction: 2^(2^(n-1)) < 2^(h*k) = (2^h)^k ≤ k^k ≤ 2^(2^(n-1))!
  714. have hcontra : 2 ^ (2 ^ (n - 1)) < k ^ k := by
  715. calc 2 ^ (2 ^ (n - 1))
  716. < 2 ^ (h * k) := Nat.pow_lt_pow_right (by norm_num) h_hk_gt
  717. _ = (2 ^ h) ^ k := pow_mul 2 h k
  718. _ ≤ k ^ k := Nat.pow_le_pow_left h2h_le_k k
  719. omega
  720. /-- **Unconditional Pure-`ℤ` `L₂`-Reflection Theorem (`τ · z_ℤ(P) ≤ 3 · 2^τ`):**
  721. For every `τ : ℕ` and every constant-free straight-line program `P : SLP τ` with
  722. `P.evalPoly ≠ 0`:
  723. `τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ`. -/
  724. theorem slp_intRootCount_l2_reflection {τ : ℕ} (P : SLP τ) (hP : P.evalPoly ≠ 0) :
  725. τ * intRootCount P.evalPoly ≤ 3 * 2 ^ τ := by
  726. let S := (intRootSet P.evalPoly).filter (fun r => 2 ≤ r.natAbs)
  727. have hpart : ((intRootSet P.evalPoly).filter (fun r => r.natAbs < 2)).card + S.card =
  728. intRootCount P.evalPoly := by
  729. have h := Finset.card_filter_add_card_filter_not
  730. (s := intRootSet P.evalPoly) (p := fun r => r.natAbs < 2)
  731. have hS_eq : S = (intRootSet P.evalPoly).filter (fun r => ¬ r.natAbs < 2) := by
  732. ext r; simp only [S, Finset.mem_filter, not_lt]
  733. rw [hS_eq]; exact h
  734. have hsmall := card_filter_natAbs_lt_two_le (intRootSet P.evalPoly)
  735. let m := S.card / 2
  736. let k := m + 1
  737. have hz_k : intRootCount P.evalPoly ≤ 2 * k + 2 := by omega
  738. have hz_deg : intRootCount P.evalPoly ≤ 2 ^ τ := slp_intRootCount_le_two_pow P hP
  739. refine nat_l2_closure hz_deg hz_k fun hτ => ?_
  740. have hS_roots : ∀ r ∈ S, P.evalPoly.IsRoot r := fun r hr =>
  741. (mem_intRootSet_iff.mp (Finset.mem_filter.mp hr).1).2
  742. have hS_ge2 : ∀ r ∈ S, 2 ≤ r.natAbs := fun r hr => (Finset.mem_filter.mp hr).2
  743. have hS_ne0 : ∀ r ∈ S, r ≠ 0 := fun r hr => by
  744. have := hS_ge2 r hr; omega
  745. calc k ^ k
  746. ≤ k.factorial ^ 2 := pow_self_le_factorial_sq k
  747. _ ≤ ∏ r ∈ S, r.natAbs := factorial_sq_le_prod_natAbs m S hS_ge2 (by omega)
  748. _ ≤ l1Norm P.evalPoly := prod_natAbs_roots_le_l1Norm hP S hS_roots hS_ne0
  749. _ ≤ 2 ^ (2 ^ (τ - 1)) := slp_l1Norm_le hτ P
  750. /-- **Multiplication-Prefix Shifted `L₂`-Reflection Theorem:**
  751. If `t₀ = P.mulPrefixLen` is the length of the leading all-multiplication prefix of `P : SLP τ`,
  752. then `(τ - t₀) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - t₀)`. -/
  753. theorem slp_intRootCount_l2_reflection_shifted {τ : ℕ} (P : SLP τ) (hP : P.evalPoly ≠ 0) :
  754. (τ - P.mulPrefixLen) * intRootCount P.evalPoly ≤ 3 * 2 ^ (τ - P.mulPrefixLen) := by
  755. by_cases hall : P.mulPrefixLen = τ
  756. · rw [hall, Nat.sub_self, zero_mul]; exact Nat.zero_le _
  757. · have hple := P.mulPrefixLen_le
  758. set n := τ - P.mulPrefixLen with hn_def
  759. have hn1 : 1 ≤ n := by omega
  760. let S := (intRootSet P.evalPoly).filter (fun r => 2 ≤ r.natAbs)
  761. have hpart : ((intRootSet P.evalPoly).filter (fun r => r.natAbs < 2)).card + S.card =
  762. intRootCount P.evalPoly := by
  763. have h := Finset.card_filter_add_card_filter_not
  764. (s := intRootSet P.evalPoly) (p := fun r => r.natAbs < 2)
  765. have hS_eq : S = (intRootSet P.evalPoly).filter (fun r => ¬ r.natAbs < 2) := by
  766. ext r; simp only [S, Finset.mem_filter, not_lt]
  767. rw [hS_eq]; exact h
  768. have hsmall := card_filter_natAbs_lt_two_le (intRootSet P.evalPoly)
  769. let m := S.card / 2
  770. let k := m + 1
  771. have hz_k : intRootCount P.evalPoly ≤ 2 * k + 2 := by omega
  772. have hkk : k ^ k ≤ 2 ^ (2 ^ (n - 1)) := by
  773. have hS_roots : ∀ r ∈ S, P.evalPoly.IsRoot r := fun r hr =>
  774. (mem_intRootSet_iff.mp (Finset.mem_filter.mp hr).1).2
  775. have hS_ge2 : ∀ r ∈ S, 2 ≤ r.natAbs := fun r hr => (Finset.mem_filter.mp hr).2
  776. have hS_ne0 : ∀ r ∈ S, r ≠ 0 := fun r hr => by
  777. have := hS_ge2 r hr; omega
  778. have hl1 : l1Norm P.evalPoly ≤ 2 ^ (2 ^ (n - 1)) := by
  779. have h := slp_evalWire_l1Norm_le_shifted P ⟨τ + 1, Nat.lt_succ_self _⟩
  780. simpa [SLP.evalPoly, hall, ← hn_def] using h
  781. calc k ^ k
  782. ≤ k.factorial ^ 2 := pow_self_le_factorial_sq k
  783. _ ≤ ∏ r ∈ S, r.natAbs := factorial_sq_le_prod_natAbs m S hS_ge2 (by omega)
  784. _ ≤ l1Norm P.evalPoly := prod_natAbs_roots_le_l1Norm hP S hS_roots hS_ne0
  785. _ ≤ 2 ^ (2 ^ (n - 1)) := hl1
  786. by_cases hn3 : n ≤ 3
  787. · by_cases hn1' : n = 1
  788. · rw [hn1'] at hkk ⊢
  789. have : k ≤ 1 := by
  790. by_contra h2; push Not at h2
  791. have : 4 ≤ k ^ k := calc 4 = 2 ^ 2 := by norm_num
  792. _ ≤ k ^ 2 := Nat.pow_le_pow_left h2 2
  793. _ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h2
  794. norm_num at hkk; omega
  795. omega
  796. · by_cases hn2' : n = 2
  797. · rw [hn2'] at hkk ⊢
  798. have : k ≤ 2 := by
  799. by_contra h3; push Not at h3
  800. have : 27 ≤ k ^ k := calc 27 = 3 ^ 3 := by norm_num
  801. _ ≤ k ^ 3 := Nat.pow_le_pow_left h3 3
  802. _ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h3
  803. norm_num at hkk; omega
  804. omega
  805. · have hn3' : n = 3 := by omega
  806. rw [hn3'] at hkk ⊢
  807. have : k ≤ 2 := by
  808. by_contra h3; push Not at h3
  809. have : 27 ≤ k ^ k := calc 27 = 3 ^ 3 := by norm_num
  810. _ ≤ k ^ 3 := Nat.pow_le_pow_left h3 3
  811. _ ≤ k ^ k := Nat.pow_le_pow_right (by omega) h3
  812. norm_num at hkk; omega
  813. omega
  814. · have hn4 : 4 ≤ n := by omega
  815. exact nat_l2_closure (n := n) (z := intRootCount P.evalPoly) (k := k)
  816. (by
  817. by_contra hgt; push Not at hgt
  818. have hk_ge : 2 ^ (n - 1) ≤ k := by
  819. have : 2 ^ n = 2 * 2 ^ (n - 1) := by
  820. conv_lhs => rw [← Nat.sub_add_cancel hn1, pow_succ, mul_comm]
  821. omega
  822. have hpow_ge : 2 ^ (n - 1) ≥ 8 := by
  823. have : 3 ≤ n - 1 := by omega
  824. calc 8 = 2 ^ 3 := by norm_num
  825. _ ≤ 2 ^ (n - 1) := Nat.pow_le_pow_right (by norm_num) this
  826. have : 2 ^ (2 ^ (n - 1)) < k ^ k := by
  827. calc 2 ^ (2 ^ (n - 1))
  828. < 4 ^ (2 ^ (n - 1)) := Nat.pow_lt_pow_left (by norm_num) (by omega)
  829. _ ≤ (2 ^ (n - 1)) ^ (2 ^ (n - 1)) := Nat.pow_le_pow_left (by omega) _
  830. _ ≤ k ^ (2 ^ (n - 1)) := Nat.pow_le_pow_left hk_ge _
  831. _ ≤ k ^ k := Nat.pow_le_pow_right (by omega) hk_ge
  832. omega)
  833. hz_k (fun _ => hkk)
  834. end Research.PvsNP.Tau