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

Research/PvsNP/Tau/UniformPadicBarrier.lean

1,411 lines32 declarationsno sorry
  1. module
  2. public import Research.PvsNP.Tau.ChirpZ
  3. public import Research.PvsNP.Tau.RealLowerBound
  4. public import Mathlib.NumberTheory.Padics.Hensel
  5. public import Mathlib.Analysis.SpecialFunctions.Log.Base
  6. public import Mathlib.Data.ZMod.Basic
  7. public import Mathlib.FieldTheory.Finite.Basic
  8. @[expose] public section
  9. namespace Research.PvsNP.Tau
  10. /-!
  11. # Cubic $2$-Adic Lower Bound and Uniform $p$-Adic Barrier (`lim_{p → ∞} α_{ℚ_p} = 1`)
  12. This module establishes two unconditional $p$-adic lower-bound theorems for constant-free
  13. straight-line programs (`SLP`) over `ℤ[X]`:
  14. 1. **Cubic `ℤ_[2]` Lower Bound (`tau_padic2_cubic`):**
  15. The homogenized cubic recurrence `P₀ = X`, `D₀ = 1`, `P_{n+1} = P_n(P_n² - D_n²)`,
  16. `D_{n+1} = 8 D_n³` has constant-free SLP length `τ(P_k) = 6k - 2` (`k ≥ 2`) and admits at
  17. least `3 ^ k` distinct roots in `ℤ_[2]`, improving `PadicBarrier.lean`'s rate from
  18. `α_{ℤ_2} ≥ 1/4 = 0.25` to `α_{ℤ_2} ≥ (log_2 3) / 6 ≈ 0.26416`.
  19. 2. **Uniform $p$-Adic Barrier (`tau_padic_fermat`, `tau_padic_rate_arbitrarily_close_to_one`):**
  20. For every odd prime `p`, the polynomial `Q_p(X) = X² ((p X)^(p - 1) - 1) ∈ ℤ[X]` maps each
  21. of the `p - 1` disjoint balls `(r + p ℤ_p) / p ⊂ ℚ_p` (`1 ≤ r < p`) bijectively onto
  22. `(1 / p) ℤ_p`, yielding `(p - 1) ^ k` distinct roots of `Q_p^[k]` in `ℚ_p`.
  23. - For Fermat primes `p = 2^m + 1` (`m ≥ 1`), this takes `(m + 3) * k + (m + 3)` gates,
  24. giving `α_{ℚ_{2^m+1}} ≥ m / (m + 3)` (e.g., `α_{ℚ_{65537}} ≥ 16/19 ≈ 0.8421`).
  25. - For arbitrary odd primes `p`, windowed base-`2^w` addition chains establish
  26. `lim_{p → ∞} α_{ℚ_p} = 1`, proving that **no uniform $p$-adic method can establish
  27. `z_{ℚ_p}(f) ≤ 2^((1 - ε) τ(f))` for any constant `ε > 0`**.
  28. -/
  29. /-! ## 1. Cubic `ℤ_[2]` Lower Bound (`z_max^{ℤ_2}(6k - 2) ≥ 3^k`) -/
  30. /-- Denominator sequence `D_0 = 1`, `D_{n+1} = 8 * D_n ^ 3`. -/
  31. def cubicD : ℕ → ℕ
  32. | 0 => 1
  33. | n + 1 => 8 * (cubicD n) ^ 3
  34. theorem cubicD_pos (n : ℕ) : 0 < cubicD n := by
  35. induction n with
  36. | zero => simp [cubicD]
  37. | succ n ih => simp [cubicD]; positivity
  38. /-- Polynomial family `P_0 = X`, `P_{n+1} = P_n * (P_n ^ 2 - D_n ^ 2)`. -/
  39. noncomputable def cubicPoly : ℕ → Polynomial ℤ
  40. | 0 => Polynomial.X
  41. | n + 1 => cubicPoly n * ((cubicPoly n) ^ 2 - (cubicD n : Polynomial ℤ) ^ 2)
  42. /-- Wire holding `D_{n+1}` in `cubicBaseSLP n`. -/
  43. def cubicDWire (n : ℕ) : ℕ :=
  44. if n = 0 then 4 else 6 * n + 6
  45. /-- Append one 6-gate cubic `ℤ_[2]` step computing `D_{n+2}` at wire `τ + 6` and `P_{n+2}` at
  46. wire `τ + 7`. -/
  47. def cubicStepSLP {τ : ℕ} (P : SLP τ) (i8 iD iP : Fin (τ + 2)) : SLP (τ + 6) :=
  48. let s1 : SLP (τ + 1) := .snoc P .mul iP iP -- w_{τ+2} = P^2
  49. let s2 : SLP (τ + 2) := .snoc s1 .mul ⟨iD.val, by omega⟩ ⟨iD.val, by omega⟩ -- w_{τ+3} = D^2
  50. let s3 : SLP (τ + 3) := .snoc s2 .sub ⟨τ + 2, by omega⟩ ⟨τ + 3, by omega⟩ -- w_{τ+4} = P^2 - D^2
  51. let s4 : SLP (τ + 4) := .snoc s3 .mul ⟨iD.val, by omega⟩ ⟨τ + 3, by omega⟩ -- w_{τ+5} = D^3
  52. let s5 : SLP (τ + 5) := .snoc s4 .mul ⟨i8.val, by omega⟩ ⟨τ + 5, by omega⟩ -- w_{τ+6} = 8 D^3
  53. .snoc s5 .mul ⟨iP.val, by omega⟩ ⟨τ + 4, by omega⟩ -- w_{τ+7} = P(P^2 - D^2)
  54. /-- Append the 4-gate final cubic `ℤ_[2]` step computing `P_{n+2}` at wire `τ + 5`. -/
  55. def cubicFinalSLP {τ : ℕ} (P : SLP τ) (iD iP : Fin (τ + 2)) : SLP (τ + 4) :=
  56. let s1 : SLP (τ + 1) := .snoc P .mul iP iP
  57. let s2 : SLP (τ + 2) := .snoc s1 .mul ⟨iD.val, by omega⟩ ⟨iD.val, by omega⟩
  58. let s3 : SLP (τ + 3) := .snoc s2 .sub ⟨τ + 2, by omega⟩ ⟨τ + 3, by omega⟩
  59. .snoc s3 .mul ⟨iP.val, by omega⟩ ⟨τ + 4, by omega⟩
  60. theorem cubicStepSLP_evalWire_lt {τ : ℕ} (P : SLP τ) (i8 iD iP : Fin (τ + 2))
  61. (k : Fin (τ + 8)) (hk : k.val < τ + 2) :
  62. (cubicStepSLP P i8 iD iP).evalWire k = P.evalWire ⟨k.val, hk⟩ := by
  63. unfold cubicStepSLP
  64. dsimp only
  65. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by omega),
  66. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  67. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  68. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  69. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  70. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega)]
  71. theorem cubicStepSLP_outputs {τ : ℕ} (P : SLP τ) (i8 iD iP : Fin (τ + 2))
  72. (h8 : P.evalWire i8 = 8) :
  73. (cubicStepSLP P i8 iD iP).evalWire ⟨τ + 6, by omega⟩ = 8 * (P.evalWire iD) ^ 3 ∧
  74. (cubicStepSLP P i8 iD iP).evalWire ⟨τ + 7, by omega⟩ =
  75. P.evalWire iP * ((P.evalWire iP) ^ 2 - (P.evalWire iD) ^ 2) := by
  76. unfold cubicStepSLP
  77. dsimp only
  78. set s1 : SLP (τ + 1) := .snoc P .mul iP iP
  79. set s2 : SLP (τ + 2) := .snoc s1 .mul ⟨iD.val, by omega⟩ ⟨iD.val, by omega⟩
  80. set s3 : SLP (τ + 3) := .snoc s2 .sub ⟨τ + 2, by omega⟩ ⟨τ + 3, by omega⟩
  81. set s4 : SLP (τ + 4) := .snoc s3 .mul ⟨iD.val, by omega⟩ ⟨τ + 3, by omega⟩
  82. set s5 : SLP (τ + 5) := .snoc s4 .mul ⟨i8.val, by omega⟩ ⟨τ + 5, by omega⟩
  83. have hiD : iD.val < τ + 2 := iD.isLt
  84. have hiP : iP.val < τ + 2 := iP.isLt
  85. have hi8 : i8.val < τ + 2 := i8.isLt
  86. have hs1 : s1.evalWire ⟨τ + 2, by omega⟩ = P.evalWire iP * P.evalWire iP := by
  87. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]; rfl
  88. have hs2 : s2.evalWire ⟨τ + 3, by omega⟩ = P.evalWire iD * P.evalWire iD := by
  89. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  90. simp only [SLPOp.applyPoly]
  91. rw [SLP.evalWire_snoc_lt _ _ _ _ _ hiD]
  92. have hs3 : s3.evalWire ⟨τ + 4, by omega⟩ =
  93. P.evalWire iP * P.evalWire iP - P.evalWire iD * P.evalWire iD := by
  94. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  95. simp only [SLPOp.applyPoly, hs2]
  96. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), hs1]
  97. have hs4 : s4.evalWire ⟨τ + 5, by omega⟩ = P.evalWire iD * (P.evalWire iD * P.evalWire iD) := by
  98. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  99. simp only [SLPOp.applyPoly]
  100. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  101. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  102. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  103. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), hs2]
  104. have hs5 : s5.evalWire ⟨τ + 6, by omega⟩ = 8 * (P.evalWire iD) ^ 3 := by
  105. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  106. simp only [SLPOp.applyPoly, hs4]
  107. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  108. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  109. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  110. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), h8]
  111. ring
  112. refine ⟨?_, ?_⟩
  113. · rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), hs5]
  114. · rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  115. simp only [SLPOp.applyPoly]
  116. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  117. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  118. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  119. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  120. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  121. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  122. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), hs3]
  123. ring
  124. theorem cubicFinalSLP_evalPoly {τ : ℕ} (P : SLP τ) (iD iP : Fin (τ + 2)) :
  125. (cubicFinalSLP P iD iP).evalPoly =
  126. P.evalWire iP * ((P.evalWire iP) ^ 2 - (P.evalWire iD) ^ 2) := by
  127. unfold SLP.evalPoly cubicFinalSLP
  128. dsimp only
  129. set s1 : SLP (τ + 1) := .snoc P .mul iP iP
  130. set s2 : SLP (τ + 2) := .snoc s1 .mul ⟨iD.val, by omega⟩ ⟨iD.val, by omega⟩
  131. set s3 : SLP (τ + 3) := .snoc s2 .sub ⟨τ + 2, by omega⟩ ⟨τ + 3, by omega⟩
  132. have hiD : iD.val < τ + 2 := iD.isLt
  133. have hiP : iP.val < τ + 2 := iP.isLt
  134. have hs1 : s1.evalWire ⟨τ + 2, by omega⟩ = P.evalWire iP * P.evalWire iP := by
  135. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]; rfl
  136. have hs2 : s2.evalWire ⟨τ + 3, by omega⟩ = P.evalWire iD * P.evalWire iD := by
  137. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  138. simp only [SLPOp.applyPoly]
  139. rw [SLP.evalWire_snoc_lt _ _ _ _ _ hiD]
  140. have hs3 : s3.evalWire ⟨τ + 4, by omega⟩ =
  141. P.evalWire iP * P.evalWire iP - P.evalWire iD * P.evalWire iD := by
  142. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  143. simp only [SLPOp.applyPoly, hs2]
  144. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega), hs1]
  145. rw [SLP.evalWire_snoc_last _ _ _ _ _ rfl]
  146. simp only [SLPOp.applyPoly, hs3]
  147. rw [SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  148. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega),
  149. SLP.evalWire_snoc_lt _ _ _ _ _ (by dsimp; omega)]
  150. ring
  151. /-- Constant-free SLP of length `6 * n + 6` computing `8` at wire `4`, `D_{n+1}` at
  152. `cubicDWire n`, and `cubicPoly (n + 1)` at wire `6 * n + 7`. -/
  153. def cubicBaseSLP : (n : ℕ) → SLP (6 * n + 6)
  154. | 0 =>
  155. let p1 : SLP 1 := .snoc .nil .add ⟨0, by omega⟩ ⟨0, by omega⟩ -- w2 = 2
  156. let p2 : SLP 2 := .snoc p1 .add ⟨2, by omega⟩ ⟨2, by omega⟩ -- w3 = 4
  157. let p3 : SLP 3 := .snoc p2 .add ⟨3, by omega⟩ ⟨3, by omega⟩ -- w4 = 8 = D_1
  158. let p4 : SLP 4 := .snoc p3 .mul ⟨1, by omega⟩ ⟨1, by omega⟩ -- w5 = X^2
  159. let p5 : SLP 5 := .snoc p4 .sub ⟨5, by omega⟩ ⟨0, by omega⟩ -- w6 = X^2 - 1
  160. .snoc p5 .mul ⟨1, by omega⟩ ⟨6, by omega⟩ -- w7 = X(X^2 - 1) = P_1
  161. | n + 1 =>
  162. cubicStepSLP (cubicBaseSLP n) ⟨4, by omega⟩
  163. ⟨cubicDWire n, by dsimp [cubicDWire]; split_ifs <;> omega⟩
  164. ⟨6 * n + 7, by omega⟩
  165. /-- Constant-free SLP of length `6 * n + 10 = 6 * (n + 2) - 2` computing `cubicPoly (n + 2)`. -/
  166. def cubicSLP (n : ℕ) : SLP (6 * n + 10) :=
  167. cubicFinalSLP (cubicBaseSLP n)
  168. ⟨cubicDWire n, by dsimp [cubicDWire]; split_ifs <;> omega⟩
  169. ⟨6 * n + 7, by omega⟩
  170. theorem cubicBaseSLP_wires (n : ℕ) :
  171. (cubicBaseSLP n).evalWire ⟨4, by omega⟩ = (8 : Polynomial ℤ) ∧
  172. (cubicBaseSLP n).evalWire ⟨cubicDWire n, by dsimp [cubicDWire]; split_ifs <;> omega⟩ =
  173. (cubicD (n + 1) : Polynomial ℤ) ∧
  174. (cubicBaseSLP n).evalWire ⟨6 * n + 7, by omega⟩ = cubicPoly (n + 1) := by
  175. induction n with
  176. | zero =>
  177. refine ⟨?_, ?_, ?_⟩
  178. · simp [cubicBaseSLP, SLP.evalWire, SLPOp.applyPoly]; norm_num
  179. · simp [cubicBaseSLP, cubicDWire, cubicD, SLP.evalWire, SLPOp.applyPoly]; norm_num
  180. · simp [cubicBaseSLP, cubicPoly, cubicD, SLP.evalWire, SLPOp.applyPoly]; ring
  181. | succ n ih =>
  182. rcases ih with ⟨h8, hD, hP⟩
  183. have houts := cubicStepSLP_outputs (cubicBaseSLP n) ⟨4, by omega⟩
  184. ⟨cubicDWire n, by dsimp [cubicDWire]; split_ifs <;> omega⟩
  185. ⟨6 * n + 7, by omega⟩ h8
  186. refine ⟨?_, ?_, ?_⟩
  187. · simpa [cubicBaseSLP] using
  188. (cubicStepSLP_evalWire_lt (cubicBaseSLP n) ⟨4, by omega⟩
  189. ⟨cubicDWire n, by dsimp [cubicDWire]; split_ifs <;> omega⟩
  190. ⟨6 * n + 7, by omega⟩ ⟨4, by omega⟩ (by dsimp; omega)).trans h8
  191. · have hfin : (⟨cubicDWire (n + 1), by dsimp [cubicDWire]; omega⟩ :
  192. Fin (6 * (n + 1) + 6 + 2)) = ⟨(6 * n + 6) + 6, by omega⟩ := by
  193. ext; simp [cubicDWire]; omega
  194. rw [hfin]
  195. have h := houts.1
  196. rw [hD] at h
  197. simpa [cubicBaseSLP, cubicD, Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] using h
  198. · have hfin : (⟨6 * (n + 1) + 7, by omega⟩ :
  199. Fin (6 * (n + 1) + 6 + 2)) = ⟨(6 * n + 6) + 7, by omega⟩ := by
  200. ext; dsimp; omega
  201. rw [hfin]
  202. have h := houts.2
  203. rw [hD, hP] at h
  204. simpa [cubicBaseSLP, cubicPoly] using h
  205. theorem cubicSLP_evalPoly (n : ℕ) : (cubicSLP n).evalPoly = cubicPoly (n + 2) := by
  206. unfold cubicSLP
  207. rw [cubicFinalSLP_evalPoly, (cubicBaseSLP_wires n).2.1, (cubicBaseSLP_wires n).2.2]
  208. rfl
  209. theorem cubicPoly_monic_and_deg (n : ℕ) :
  210. (cubicPoly n).Monic ∧ (cubicPoly n).natDegree = 3 ^ n := by
  211. induction n with
  212. | zero =>
  213. exact ⟨Polynomial.monic_X, Polynomial.natDegree_X⟩
  214. | succ n ih =>
  215. rcases ih with ⟨hm, hd⟩
  216. simp only [cubicPoly]
  217. have hsq_m : (cubicPoly n ^ 2).Monic := hm.pow 2
  218. have hsq_d : (cubicPoly n ^ 2).natDegree = 2 * 3 ^ n := by
  219. rw [Polynomial.natDegree_pow, hd]
  220. have hc_d : ((cubicD n : Polynomial ℤ) ^ 2).natDegree = 0 := by
  221. rw [show (cubicD n : Polynomial ℤ) = Polynomial.C (cubicD n : ℤ) by simp, ← map_pow,
  222. Polynomial.natDegree_C]
  223. have hc_lt : ((cubicD n : Polynomial ℤ) ^ 2).natDegree < (cubicPoly n ^ 2).natDegree := by
  224. rw [hc_d, hsq_d]; positivity
  225. have hdeg_lt : ((cubicD n : Polynomial ℤ) ^ 2).degree < (cubicPoly n ^ 2).degree := by
  226. have hc_le : ((cubicD n : Polynomial ℤ) ^ 2).degree ≤ 0 := by
  227. rw [show (cubicD n : Polynomial ℤ) = Polynomial.C (cubicD n : ℤ) by simp, ← map_pow]
  228. exact Polynomial.degree_C_le
  229. rw [Polynomial.degree_eq_natDegree hsq_m.ne_zero, hsq_d]
  230. exact lt_of_le_of_lt hc_le (by exact_mod_cast (by positivity : 0 < 2 * 3 ^ n))
  231. have hdiff_m : (cubicPoly n ^ 2 - (cubicD n : Polynomial ℤ) ^ 2).Monic :=
  232. hsq_m.sub_of_left hdeg_lt
  233. have hdiff_d : (cubicPoly n ^ 2 - (cubicD n : Polynomial ℤ) ^ 2).natDegree = 2 * 3 ^ n := by
  234. rw [Polynomial.natDegree_sub_eq_left_of_natDegree_lt hc_lt, hsq_d]
  235. refine ⟨hm.mul hdiff_m, ?_⟩
  236. rw [Polynomial.natDegree_mul hm.ne_zero hdiff_m.ne_zero, hd, hdiff_d, pow_succ]
  237. ring
  238. /-- For every `t ∈ ℤ_[2]`, the cubic `y(y² - 1) = 8t` has three distinct roots in `ℤ_[2]`
  239. (lifted by Hensel's lemma from `0`, `1`, and `-1`). -/
  240. theorem padic2_cubic_three_roots (t : ℤ_[2]) :
  241. ∃ y1 y2 y3 : ℤ_[2],
  242. y1 ≠ y2 ∧ y1 ≠ y3 ∧ y2 ≠ y3 ∧
  243. y1 * (y1 ^ 2 - 1) = 8 * t ∧
  244. y2 * (y2 ^ 2 - 1) = 8 * t ∧
  245. y3 * (y3 ^ 2 - 1) = 8 * t := by
  246. have : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
  247. let F : Polynomial ℤ_[2] := Polynomial.X ^ 3 - Polynomial.X - Polynomial.C (8 * t)
  248. have hderiv : F.derivative = 3 * Polynomial.X ^ 2 - 1 := by
  249. simp [F, Polynomial.derivative_pow, Polynomial.C_ofNat]
  250. have hnorm2 : ‖(2 : ℤ_[2])‖ = (1 / 2 : ℝ) := by
  251. simpa [PadicInt.norm_p] using (PadicInt.norm_p (p := 2))
  252. have hnorm8 : ‖(8 : ℤ_[2])‖ = (1 / 8 : ℝ) := by
  253. have h8 : (8 : ℤ_[2]) = (2 : ℤ_[2]) ^ 3 := by norm_num
  254. rw [h8, norm_pow, hnorm2]; norm_num
  255. have h8t : ‖(8 : ℤ_[2]) * t‖ ≤ (1 / 8 : ℝ) := by
  256. rw [norm_mul, hnorm8]
  257. have ht : ‖t‖ ≤ 1 := PadicInt.norm_le_one t
  258. nlinarith [norm_nonneg t]
  259. -- Root y1 near 0
  260. have hF0 : F.aeval (0 : ℤ_[2]) = -(8 * t) := by simp [F]
  261. have hFd0 : F.derivative.aeval (0 : ℤ_[2]) = (-1 : ℤ_[2]) := by simp [hderiv]
  262. have hlt0 : ‖F.aeval (0 : ℤ_[2])‖ < ‖F.derivative.aeval (0 : ℤ_[2])‖ ^ 2 := by
  263. rw [hF0, hFd0, norm_neg, norm_neg, norm_one]; linarith
  264. rcases hensels_lemma (p := 2) (F := F) (a := (0 : ℤ_[2])) hlt0 with
  265. ⟨y1, hy1_root, hy1_dist, _, _⟩
  266. rw [sub_zero, hFd0, norm_neg, norm_one] at hy1_dist
  267. -- Root y2 near 1
  268. have hF1 : F.aeval (1 : ℤ_[2]) = -(8 * t) := by simp [F]
  269. have hFd1 : F.derivative.aeval (1 : ℤ_[2]) = (2 : ℤ_[2]) := by simp [hderiv]; norm_num
  270. have hlt1 : ‖F.aeval (1 : ℤ_[2])‖ < ‖F.derivative.aeval (1 : ℤ_[2])‖ ^ 2 := by
  271. rw [hF1, hFd1, norm_neg, hnorm2]; linarith
  272. rcases hensels_lemma (p := 2) (F := F) (a := (1 : ℤ_[2])) hlt1 with
  273. ⟨y2, hy2_root, hy2_dist, _, _⟩
  274. rw [hFd1, hnorm2] at hy2_dist
  275. -- Root y3 near -1
  276. have hFm1 : F.aeval (-1 : ℤ_[2]) = -(8 * t) := by simp [F]; ring
  277. have hFdm1 : F.derivative.aeval (-1 : ℤ_[2]) = (2 : ℤ_[2]) := by simp [hderiv]; norm_num
  278. have hltm1 : ‖F.aeval (-1 : ℤ_[2])‖ < ‖F.derivative.aeval (-1 : ℤ_[2])‖ ^ 2 := by
  279. rw [hFm1, hFdm1, norm_neg, hnorm2]; linarith
  280. rcases hensels_lemma (p := 2) (F := F) (a := (-1 : ℤ_[2])) hltm1 with
  281. ⟨y3, hy3_root, hy3_dist, _, _⟩
  282. rw [hFdm1, hnorm2, sub_neg_eq_add] at hy3_dist
  283. -- Pairwise distinctness via ultrametric inequality
  284. have h12 : y1 ≠ y2 := by
  285. intro heq
  286. subst heq
  287. have h1 : (1 : ℤ_[2]) = y1 + -(y1 - 1) := by ring
  288. have hle : ‖(1 : ℤ_[2])‖ ≤ max ‖y1‖ ‖y1 - 1‖ := by
  289. calc
  290. ‖(1 : ℤ_[2])‖ = ‖y1 + -(y1 - 1)‖ := congrArg norm h1
  291. _ ≤ max ‖y1‖ ‖-(y1 - 1)‖ := PadicInt.nonarchimedean y1 (-(y1 - 1))
  292. _ = max ‖y1‖ ‖y1 - 1‖ := by rw [norm_neg]
  293. rw [norm_one] at hle
  294. have hmax : max ‖y1‖ ‖y1 - 1‖ < 1 := max_lt hy1_dist (by linarith)
  295. linarith
  296. have h13 : y1 ≠ y3 := by
  297. intro heq
  298. subst heq
  299. have h1 : (1 : ℤ_[2]) = (y1 + 1) + -y1 := by ring
  300. have hle : ‖(1 : ℤ_[2])‖ ≤ max ‖y1 + 1‖ ‖y1‖ := by
  301. calc
  302. ‖(1 : ℤ_[2])‖ = ‖(y1 + 1) + -y1‖ := congrArg norm h1
  303. _ ≤ max ‖y1 + 1‖ ‖-y1‖ := PadicInt.nonarchimedean (y1 + 1) (-y1)
  304. _ = max ‖y1 + 1‖ ‖y1‖ := by rw [norm_neg]
  305. rw [norm_one] at hle
  306. have hmax : max ‖y1 + 1‖ ‖y1‖ < 1 := max_lt (by linarith) hy1_dist
  307. linarith
  308. have h23 : y2 ≠ y3 := by
  309. intro heq
  310. subst heq
  311. have h2 : (2 : ℤ_[2]) = (y2 + 1) + -(y2 - 1) := by ring
  312. have hle : ‖(2 : ℤ_[2])‖ ≤ max ‖y2 + 1‖ ‖y2 - 1‖ := by
  313. calc
  314. ‖(2 : ℤ_[2])‖ = ‖(y2 + 1) + -(y2 - 1)‖ := congrArg norm h2
  315. _ ≤ max ‖y2 + 1‖ ‖-(y2 - 1)‖ := PadicInt.nonarchimedean (y2 + 1) (-(y2 - 1))
  316. _ = max ‖y2 + 1‖ ‖y2 - 1‖ := by rw [norm_neg]
  317. rw [hnorm2] at hle
  318. have hmax : max ‖y2 + 1‖ ‖y2 - 1‖ < 1 / 2 := max_lt hy3_dist hy2_dist
  319. linarith
  320. have hroot_eq : ∀ y : ℤ_[2], F.aeval y = 0 → y * (y ^ 2 - 1) = 8 * t := by
  321. intro y hy
  322. have h0 : y ^ 3 - y - 8 * t = 0 := by simpa [F] using hy
  323. linear_combination h0
  324. exact ⟨y1, y2, y3, h12, h13, h23, hroot_eq y1 hy1_root, hroot_eq y2 hy2_root,
  325. hroot_eq y3 hy3_root⟩
  326. /-- Ternary preimage tree in `ℤ_[2]`: for every `n : ℕ` and `t : ℤ_[2]`, `cubicPoly n = D_n * t`
  327. has at least `3 ^ n` distinct roots in `ℤ_[2]`. -/
  328. theorem cubicPoly_preimages (n : ℕ) :
  329. ∀ t : ℤ_[2],
  330. ∃ S : Finset ℤ_[2],
  331. S.card = 3 ^ n ∧
  332. ∀ r ∈ S, Polynomial.aeval r (cubicPoly n) = (cubicD n : ℤ_[2]) * t := by
  333. classical
  334. induction n with
  335. | zero =>
  336. intro t
  337. refine ⟨{t}, by simp, ?_⟩
  338. intro r hr
  339. rw [Finset.mem_singleton] at hr
  340. subst hr
  341. simp [cubicPoly, cubicD]
  342. | succ n ih =>
  343. intro t
  344. rcases padic2_cubic_three_roots t with ⟨y1, y2, y3, h12, h13, h23, hy1, hy2, hy3⟩
  345. rcases ih y1 with ⟨S1, hc1, hS1⟩
  346. rcases ih y2 with ⟨S2, hc2, hS2⟩
  347. rcases ih y3 with ⟨S3, hc3, hS3⟩
  348. have hDne : (cubicD n : ℤ_[2]) ≠ 0 := by
  349. exact_mod_cast (cubicD_pos n).ne'
  350. have hdisj : ∀ {A B : Finset ℤ_[2]} {a b : ℤ_[2]},
  351. a ≠ b →
  352. (∀ r ∈ A, Polynomial.aeval r (cubicPoly n) = (cubicD n : ℤ_[2]) * a) →
  353. (∀ r ∈ B, Polynomial.aeval r (cubicPoly n) = (cubicD n : ℤ_[2]) * b) →
  354. Disjoint A B := by
  355. intro A B a b hab hA hB
  356. rw [Finset.disjoint_left]
  357. intro r hrA hrB
  358. exact hab (mul_left_cancel₀ hDne ((hA r hrA).symm.trans (hB r hrB)))
  359. have hd12 : Disjoint S1 S2 := hdisj h12 hS1 hS2
  360. have hd13 : Disjoint S1 S3 := hdisj h13 hS1 hS3
  361. have hd23 : Disjoint S2 S3 := hdisj h23 hS2 hS3
  362. have hd12_3 : Disjoint (S1 ∪ S2) S3 := Finset.disjoint_union_left.mpr ⟨hd13, hd23⟩
  363. refine ⟨(S1 ∪ S2) ∪ S3, ?_, ?_⟩
  364. · rw [Finset.card_union_of_disjoint hd12_3, Finset.card_union_of_disjoint hd12,
  365. hc1, hc2, hc3, pow_succ]
  366. ring
  367. · intro r hr
  368. have hstep : ∀ {y : ℤ_[2]},
  369. Polynomial.aeval r (cubicPoly n) = (cubicD n : ℤ_[2]) * y →
  370. y * (y ^ 2 - 1) = 8 * t →
  371. Polynomial.aeval r (cubicPoly (n + 1)) = (cubicD (n + 1) : ℤ_[2]) * t := by
  372. intro y hr_eq hy_eq
  373. simp only [cubicPoly, cubicD, map_mul, map_sub, map_pow, map_natCast, Nat.cast_mul,
  374. Nat.cast_pow, Nat.cast_ofNat, hr_eq]
  375. calc
  376. (cubicD n : ℤ_[2]) * y * (((cubicD n : ℤ_[2]) * y) ^ 2 - (cubicD n : ℤ_[2]) ^ 2)
  377. = (cubicD n : ℤ_[2]) ^ 3 * (y * (y ^ 2 - 1)) := by ring
  378. _ = (cubicD n : ℤ_[2]) ^ 3 * (8 * t) := by rw [hy_eq]
  379. _ = 8 * (cubicD n : ℤ_[2]) ^ 3 * t := by ring
  380. rcases Finset.mem_union.mp hr with hr12 | hr3
  381. · rcases Finset.mem_union.mp hr12 with hr1 | hr2
  382. · exact hstep (hS1 r hr1) hy1
  383. · exact hstep (hS2 r hr2) hy2
  384. · exact hstep (hS3 r hr3) hy3
  385. /-- **Unconditional Cubic $2$-Adic Lower Bound (`z_max^{ℤ_2}(6k - 2) ≥ 3^k`):**
  386. For every `k ≥ 2`, there exists a constant-free SLP of length `6 * k - 2` computing a nonzero
  387. polynomial `f ∈ ℤ[X]` with at least `3 ^ k` distinct roots in `ℤ_[2]`. -/
  388. theorem tau_padic2_cubic (k : ℕ) (hk : 2 ≤ k) :
  389. ∃ P : SLP (6 * k - 2),
  390. P.evalPoly ≠ 0 ∧
  391. ∃ S : Finset ℤ_[2],
  392. S.card = 3 ^ k ∧ ∀ r ∈ S, Polynomial.aeval r P.evalPoly = 0 := by
  393. obtain ⟨n, rfl⟩ : ∃ n, k = n + 2 := ⟨k - 2, by omega⟩
  394. have hlen : 6 * (n + 2) - 2 = 6 * n + 10 := by omega
  395. rw [hlen]
  396. refine ⟨cubicSLP n, ?_, ?_⟩
  397. · rw [cubicSLP_evalPoly]
  398. exact (cubicPoly_monic_and_deg (n + 2)).1.ne_zero
  399. · rcases cubicPoly_preimages (n + 2) 0 with ⟨S, hcard, hS⟩
  400. refine ⟨S, hcard, ?_⟩
  401. intro r hr
  402. rw [cubicSLP_evalPoly, hS r hr, mul_zero]
  403. /-! ## 2. Uniform $p$-Adic Barrier (`Q_p(X) = X² ((p X)^(p - 1) - 1)`) -/
  404. /-- `k`-fold iterate of `Q_p(w) = w² · ((p w)^(p - 1) - 1)` in `ℤ[X]`. -/
  405. noncomputable def qpIter (p : ℕ) : ℕ → Polynomial ℤ
  406. | 0 => Polynomial.X
  407. | k + 1 => (qpIter p k) ^ 2 * ((Polynomial.C (p : ℤ) * qpIter p k) ^ (p - 1) - 1)
  408. theorem qpIter_lead_pos_and_deg (p : ℕ) (hp : p.Prime) (k : ℕ) :
  409. 0 < (qpIter p k).leadingCoeff ∧ 1 ≤ (qpIter p k).natDegree := by
  410. have hp2 : 2 ≤ p := hp.two_le
  411. have hp_pos : (0 : ℤ) < (p : ℤ) := by exact_mod_cast hp.pos
  412. induction k with
  413. | zero => simp [qpIter]
  414. | succ k ih =>
  415. rcases ih with ⟨hlc, hdeg⟩
  416. set f := qpIter p k
  417. have hf_ne : f ≠ 0 := by
  418. intro h0; rw [h0] at hlc; simp at hlc
  419. have hpf_lc : (Polynomial.C (p : ℤ) * f).leadingCoeff = (p : ℤ) * f.leadingCoeff := by
  420. rw [Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C]
  421. have hpf_pos : 0 < (Polynomial.C (p : ℤ) * f).leadingCoeff := by
  422. rw [hpf_lc]; positivity
  423. have hpf_deg : (Polynomial.C (p : ℤ) * f).natDegree = f.natDegree := by
  424. rw [Polynomial.natDegree_C_mul hp_pos.ne']
  425. have hpow_lc : ((Polynomial.C (p : ℤ) * f) ^ (p - 1)).leadingCoeff =
  426. ((Polynomial.C (p : ℤ) * f).leadingCoeff) ^ (p - 1) := by
  427. rw [Polynomial.leadingCoeff_pow]
  428. have hpow_pos : 0 < ((Polynomial.C (p : ℤ) * f) ^ (p - 1)).leadingCoeff := by
  429. rw [hpow_lc]; positivity
  430. have hpow_deg : ((Polynomial.C (p : ℤ) * f) ^ (p - 1)).natDegree =
  431. (p - 1) * f.natDegree := by
  432. rw [Polynomial.natDegree_pow, hpf_deg]
  433. have h1_lt : (1 : Polynomial ℤ).natDegree <
  434. ((Polynomial.C (p : ℤ) * f) ^ (p - 1)).natDegree := by
  435. rw [Polynomial.natDegree_one, hpow_deg]
  436. have : 1 ≤ p - 1 := by omega
  437. nlinarith
  438. have hsub_lc : ((Polynomial.C (p : ℤ) * f) ^ (p - 1) - 1).leadingCoeff =
  439. ((Polynomial.C (p : ℤ) * f) ^ (p - 1)).leadingCoeff := by
  440. exact Polynomial.leadingCoeff_sub_of_degree_lt
  441. (Polynomial.degree_lt_degree h1_lt)
  442. have hsub_deg : ((Polynomial.C (p : ℤ) * f) ^ (p - 1) - 1).natDegree =
  443. (p - 1) * f.natDegree := by
  444. rw [Polynomial.natDegree_sub_eq_left_of_natDegree_lt h1_lt, hpow_deg]
  445. have hsub_ne : (Polynomial.C (p : ℤ) * f) ^ (p - 1) - 1 ≠ 0 := by
  446. intro h0; rw [h0, Polynomial.leadingCoeff_zero] at hsub_lc; linarith
  447. have hsq_ne : f ^ 2 ≠ 0 := pow_ne_zero 2 hf_ne
  448. simp only [qpIter]
  449. refine ⟨?_, ?_⟩
  450. · rw [Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_pow, hsub_lc]
  451. positivity
  452. · rw [Polynomial.natDegree_mul hsq_ne hsub_ne, Polynomial.natDegree_pow, hsub_deg]
  453. omega
  454. theorem qpIter_ne_zero (p : ℕ) (hp : p.Prime) (k : ℕ) : qpIter p k ≠ 0 := by
  455. have h := (qpIter_lead_pos_and_deg p hp k).1
  456. intro h0
  457. rw [h0, Polynomial.leadingCoeff_zero] at h
  458. exact lt_irrefl 0 h
  459. /-- For every prime `p`, every `r ∈ {1, ..., p - 1}`, and every `w ∈ ℤ_[p]`, Hensel's lemma
  460. produces `v ∈ ℤ_[p]` such that `(r + p v)² ((r + p v)^(p - 1) - 1) = p · w` in `ℤ_[p]`. -/
  461. theorem padic_qp_ball_lift (p : ℕ) [Fact p.Prime] (r : ℕ) (hr1 : 1 ≤ r) (hrp : r < p)
  462. (w : ℤ_[p]) :
  463. ∃ v : ℤ_[p],
  464. ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 *
  465. (((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ (p - 1) - 1) = (p : ℤ_[p]) * w := by
  466. have hp : p.Prime := Fact.out
  467. have hp_ge2 : 2 ≤ p := hp.two_le
  468. -- Fermat's Little Theorem: p ∣ r^(p - 1) - 1 in ℤ
  469. have hrz_ne : ((r : ZMod p)) ≠ 0 := by
  470. intro h0
  471. have hdvd : p ∣ r := (ZMod.natCast_eq_zero_iff r p).mp h0
  472. exact absurd (Nat.le_of_dvd (by omega) hdvd) (by omega)
  473. have hflt_zmod : ((r : ZMod p)) ^ (p - 1) = 1 := ZMod.pow_card_sub_one_eq_one hrz_ne
  474. have hflt_dvd_nat : p ∣ r ^ (p - 1) - 1 := by
  475. have h1 : 1 ≤ r ^ (p - 1) := Nat.one_le_pow _ _ (by omega)
  476. rw [← ZMod.natCast_eq_zero_iff, Nat.cast_sub h1, Nat.cast_pow, Nat.cast_one, hflt_zmod,
  477. sub_self]
  478. obtain ⟨c_nat, hc_nat⟩ := hflt_dvd_nat
  479. have hc_int : ((r : ℤ) ^ (p - 1) - 1) = (p : ℤ) * (c_nat : ℤ) := by
  480. have h1 : 1 ≤ r ^ (p - 1) := Nat.one_le_pow _ _ (by omega)
  481. have hnat : r ^ (p - 1) = p * c_nat + 1 := by omega
  482. have hz : ((r ^ (p - 1) : ℕ) : ℤ) = ((p * c_nat + 1 : ℕ) : ℤ) := by exact_mod_cast hnat
  483. push_cast at hz
  484. linarith
  485. have hrpow : (r : ℤ_[p]) ^ (p - 1) = 1 + (p : ℤ_[p]) * (c_nat : ℤ_[p]) := by
  486. have hz : ((r : ℤ_[p]) ^ (p - 1) - 1) = (p : ℤ_[p]) * (c_nat : ℤ_[p]) := by
  487. exact_mod_cast hc_int
  488. linear_combination hz
  489. -- Construct `H ∈ ℤ_[p][X]` directly with `C p * H = (C r + C p * X)^(p - 1) - 1`
  490. let H : Polynomial ℤ_[p] :=
  491. Polynomial.C (c_nat : ℤ_[p]) +
  492. ∑ j ∈ Finset.Ico 1 p,
  493. Polynomial.C
  494. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 1)) *
  495. Polynomial.X ^ j
  496. have hH_mul :
  497. Polynomial.C (p : ℤ_[p]) * H =
  498. (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ (p - 1) - 1 := by
  499. rw [add_comm (Polynomial.C (r : ℤ_[p])),
  500. add_pow (Polynomial.C (p : ℤ_[p]) * Polynomial.X) (Polynomial.C (r : ℤ_[p])) (p - 1)]
  501. have hsub1 : p - 1 + 1 = p := by omega
  502. rw [Finset.range_eq_Ico, hsub1, Finset.sum_eq_sum_Ico_succ_bot (by omega : 0 < p)]
  503. simp only [Nat.choose_zero_right, Nat.cast_one, mul_one, Nat.sub_zero, pow_zero, one_mul,
  504. ← map_pow]
  505. have hfirst : Polynomial.C ((r : ℤ_[p]) ^ (p - 1)) - 1 =
  506. Polynomial.C (p : ℤ_[p]) * Polynomial.C (c_nat : ℤ_[p]) := by
  507. rw [hrpow, map_add, map_one, map_mul]
  508. ring
  509. calc
  510. Polynomial.C (p : ℤ_[p]) * H
  511. = Polynomial.C (p : ℤ_[p]) * Polynomial.C (c_nat : ℤ_[p]) +
  512. ∑ j ∈ Finset.Ico 1 p,
  513. Polynomial.C (p : ℤ_[p]) *
  514. (Polynomial.C (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) *
  515. (p : ℤ_[p]) ^ (j - 1)) * Polynomial.X ^ j) := by
  516. simp only [H, mul_add, Finset.mul_sum]
  517. _ = (Polynomial.C ((r : ℤ_[p]) ^ (p - 1)) - 1) +
  518. ∑ j ∈ Finset.Ico 1 p,
  519. (Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ j *
  520. Polynomial.C ((r : ℤ_[p]) ^ (p - 1 - j)) * ↑((p - 1).choose j) := by
  521. rw [hfirst]
  522. congr 1
  523. refine Finset.sum_congr rfl ?_
  524. intro j hj
  525. have hj1 : 1 ≤ j := (Finset.mem_Ico.mp hj).1
  526. have hpj : (p : ℤ_[p]) * (p : ℤ_[p]) ^ (j - 1) = (p : ℤ_[p]) ^ j := by
  527. conv_rhs => rw [show j = (j - 1) + 1 by omega, pow_succ']
  528. rw [mul_pow, ← map_pow, ← Polynomial.C_eq_natCast]
  529. have hC : Polynomial.C (p : ℤ_[p]) *
  530. Polynomial.C (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) *
  531. (p : ℤ_[p]) ^ (j - 1)) =
  532. Polynomial.C ((p : ℤ_[p]) ^ j) * Polynomial.C ((r : ℤ_[p]) ^ (p - 1 - j)) *
  533. Polynomial.C ((p - 1).choose j : ℤ_[p]) := by
  534. rw [← map_mul, ← map_mul, ← map_mul]
  535. congr 1
  536. calc
  537. (p : ℤ_[p]) * (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) *
  538. (p : ℤ_[p]) ^ (j - 1))
  539. = ((p : ℤ_[p]) * (p : ℤ_[p]) ^ (j - 1)) * (r : ℤ_[p]) ^ (p - 1 - j) *
  540. ((p - 1).choose j : ℤ_[p]) := by ring
  541. _ = (p : ℤ_[p]) ^ j * (r : ℤ_[p]) ^ (p - 1 - j) *
  542. ((p - 1).choose j : ℤ_[p]) := by rw [hpj]
  543. rw [← mul_assoc, hC]
  544. ring
  545. _ = Polynomial.C ((r : ℤ_[p]) ^ (p - 1)) +
  546. (∑ j ∈ Finset.Ico 1 p,
  547. (Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ j *
  548. Polynomial.C ((r : ℤ_[p]) ^ (p - 1 - j)) * ↑((p - 1).choose j)) - 1 := by ring
  549. let G : Polynomial ℤ_[p] :=
  550. (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ 2 * H - Polynomial.C w
  551. -- Evaluate `H` modulo `p`
  552. have hH_mod : ∀ v : ℤ_[p],
  553. ∃ q : ℤ_[p],
  554. Polynomial.eval v H =
  555. (c_nat : ℤ_[p]) + ((p - 1 : ℕ) : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 2) * v +
  556. (p : ℤ_[p]) * q := by
  557. intro v
  558. have hsplit : Finset.Ico 1 p = insert 1 (Finset.Ico 2 p) := by
  559. ext j; simp only [Finset.mem_Ico, Finset.mem_insert]; omega
  560. have h1not : (1 : ℕ) ∉ Finset.Ico 2 p := by simp
  561. have hev : Polynomial.eval v H =
  562. (c_nat : ℤ_[p]) +
  563. ∑ j ∈ Finset.Ico 1 p,
  564. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 1)) *
  565. v ^ j := by
  566. change (Polynomial.evalRingHom v) H = _
  567. simp only [H, map_add, map_sum, map_mul, map_pow, Polynomial.coe_evalRingHom,
  568. Polynomial.eval_C, Polynomial.eval_X]
  569. rw [hev, hsplit, Finset.sum_insert h1not]
  570. have hterm1 :
  571. (((p - 1).choose 1 : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - 1) * (p : ℤ_[p]) ^ (1 - 1)) *
  572. v ^ 1 = ((p - 1 : ℕ) : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 2) * v := by
  573. simp [Nat.choose_one_right, Nat.sub_sub]
  574. rw [hterm1]
  575. refine ⟨∑ j ∈ Finset.Ico 2 p,
  576. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 2)) *
  577. v ^ j, ?_⟩
  578. rw [Finset.mul_sum]
  579. have hsum : ∑ j ∈ Finset.Ico 2 p,
  580. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 1)) *
  581. v ^ j =
  582. ∑ j ∈ Finset.Ico 2 p,
  583. (p : ℤ_[p]) * ((((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) *
  584. (p : ℤ_[p]) ^ (j - 2)) * v ^ j) := by
  585. refine Finset.sum_congr rfl ?_
  586. intro j hj
  587. have hj2 : 2 ≤ j := (Finset.mem_Ico.mp hj).1
  588. have hpj : (p : ℤ_[p]) ^ (j - 1) = (p : ℤ_[p]) * (p : ℤ_[p]) ^ (j - 2) := by
  589. conv_lhs => rw [show j - 1 = (j - 2) + 1 by omega, pow_succ']
  590. rw [hpj]; ring
  591. rw [hsum]; ring
  592. -- Evaluate `H.derivative` modulo `p`
  593. have hHd_mod : ∀ v : ℤ_[p],
  594. ∃ q : ℤ_[p],
  595. Polynomial.eval v H.derivative =
  596. ((p - 1 : ℕ) : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 2) + (p : ℤ_[p]) * q := by
  597. intro v
  598. have hsplit : Finset.Ico 1 p = insert 1 (Finset.Ico 2 p) := by
  599. ext j; simp only [Finset.mem_Ico, Finset.mem_insert]; omega
  600. have h1not : (1 : ℕ) ∉ Finset.Ico 2 p := by simp
  601. have hderiv_H : H.derivative =
  602. ∑ j ∈ Finset.Ico 1 p,
  603. Polynomial.C (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) *
  604. (p : ℤ_[p]) ^ (j - 1)) * (Polynomial.C (j : ℤ_[p]) * Polynomial.X ^ (j - 1)) := by
  605. simp only [H, Polynomial.derivative_add, Polynomial.derivative_C, zero_add,
  606. Polynomial.derivative_sum, Polynomial.derivative_C_mul, Polynomial.derivative_X_pow]
  607. have hev : Polynomial.eval v H.derivative =
  608. ∑ j ∈ Finset.Ico 1 p,
  609. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 1)) *
  610. ((j : ℤ_[p]) * v ^ (j - 1)) := by
  611. change (Polynomial.evalRingHom v) H.derivative = _
  612. rw [hderiv_H]
  613. simp only [map_sum, map_mul, map_pow, Polynomial.coe_evalRingHom,
  614. Polynomial.eval_C, Polynomial.eval_X]
  615. rw [hev, hsplit, Finset.sum_insert h1not]
  616. have hterm1 :
  617. (((p - 1).choose 1 : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - 1) * (p : ℤ_[p]) ^ (1 - 1)) *
  618. (((1 : ℕ) : ℤ_[p]) * v ^ (1 - 1)) = ((p - 1 : ℕ) : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 2) := by
  619. simp [Nat.choose_one_right, Nat.sub_sub]
  620. rw [hterm1]
  621. refine ⟨∑ j ∈ Finset.Ico 2 p,
  622. (((p - 1).choose j : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1 - j) * (p : ℤ_[p]) ^ (j - 2)) *
  623. ((j : ℤ_[p]) * v ^ (j - 1)), ?_⟩
  624. rw [Finset.mul_sum]
  625. congr 1
  626. refine Finset.sum_congr rfl ?_
  627. intro j hj
  628. have hj2 : 2 ≤ j := (Finset.mem_Ico.mp hj).1
  629. have hpj : (p : ℤ_[p]) ^ (j - 1) = (p : ℤ_[p]) * (p : ℤ_[p]) ^ (j - 2) := by
  630. conv_lhs => rw [show j - 1 = (j - 2) + 1 by omega, pow_succ']
  631. rw [hpj]; ring
  632. -- `r` is a unit in `ℤ_[p]` since `1 ≤ r < p`
  633. have hr_norm : ‖(r : ℤ_[p])‖ = 1 := by
  634. have hndvd : ¬ (p : ℤ) ∣ (r : ℤ) := by
  635. intro hd
  636. have hnat : p ∣ r := by exact_mod_cast hd
  637. exact absurd (Nat.le_of_dvd (by omega) hnat) (by omega)
  638. have hcop : IsCoprime (r : ℤ) (p : ℤ) :=
  639. ((Nat.prime_iff_prime_int.mp hp).coprime_iff_not_dvd.mpr hndvd).symm
  640. simpa using PadicInt.norm_intCast_eq_one_iff.mpr hcop
  641. rcases PadicInt.isUnit_iff.mpr hr_norm with ⟨u, hu⟩
  642. let a : ℤ_[p] := (↑u⁻¹ : ℤ_[p]) * ((r : ℤ_[p]) ^ 2 * (c_nat : ℤ_[p]) - w)
  643. have hra : (r : ℤ_[p]) * a = (r : ℤ_[p]) ^ 2 * (c_nat : ℤ_[p]) - w := by
  644. dsimp [a]
  645. rw [← hu, ← mul_assoc, Units.mul_inv, one_mul]
  646. have hr_p2 : (r : ℤ_[p]) ^ 2 * (r : ℤ_[p]) ^ (p - 2) =
  647. (r : ℤ_[p]) + (p : ℤ_[p]) * ((r : ℤ_[p]) * (c_nat : ℤ_[p])) := by
  648. have hexp : 2 + (p - 2) = 1 + (p - 1) := by omega
  649. calc
  650. (r : ℤ_[p]) ^ 2 * (r : ℤ_[p]) ^ (p - 2)
  651. = (r : ℤ_[p]) ^ (2 + (p - 2)) := by rw [pow_add]
  652. _ = (r : ℤ_[p]) * (r : ℤ_[p]) ^ (p - 1) := by rw [hexp, pow_add, pow_one]
  653. _ = (r : ℤ_[p]) * (1 + (p : ℤ_[p]) * (c_nat : ℤ_[p])) := by rw [hrpow]
  654. _ = (r : ℤ_[p]) + (p : ℤ_[p]) * ((r : ℤ_[p]) * (c_nat : ℤ_[p])) := by ring
  655. have hpm1 : ((p - 1 : ℕ) : ℤ_[p]) = (p : ℤ_[p]) - 1 := by
  656. have h1 : (p - 1 : ℕ) + 1 = p := by omega
  657. have h2 : (((p - 1 : ℕ) + 1 : ℕ) : ℤ_[p]) = (p : ℤ_[p]) := by exact_mod_cast h1
  658. push_cast at h2
  659. linear_combination h2
  660. -- Show `G(a)` is divisible by `p`
  661. have hGa_dvd : ∃ q : ℤ_[p], G.aeval a = (p : ℤ_[p]) * q := by
  662. rcases hH_mod a with ⟨qH, hqH⟩
  663. rw [Polynomial.aeval_def, Polynomial.eval₂_eq_eval_map, Algebra.algebraMap_self,
  664. Polynomial.map_id]
  665. have hG_eval : Polynomial.eval a G =
  666. ((r : ℤ_[p]) + (p : ℤ_[p]) * a) ^ 2 * Polynomial.eval a H - w := by
  667. simp [G]
  668. rw [hG_eval, hqH, hpm1]
  669. set B := (c_nat : ℤ_[p]) + ((p : ℤ_[p]) - 1) * (r : ℤ_[p]) ^ (p - 2) * a + (p : ℤ_[p]) * qH
  670. refine ⟨(2 * (r : ℤ_[p]) * a + (p : ℤ_[p]) * a ^ 2) * B +
  671. (r : ℤ_[p]) ^ 2 * ((r : ℤ_[p]) ^ (p - 2) * a + qH) -
  672. (r : ℤ_[p]) * (c_nat : ℤ_[p]) * a, ?_⟩
  673. have hexpand :
  674. ((r : ℤ_[p]) + (p : ℤ_[p]) * a) ^ 2 * B - w =
  675. (r : ℤ_[p]) ^ 2 * (c_nat : ℤ_[p]) -
  676. ((r : ℤ_[p]) ^ 2 * (r : ℤ_[p]) ^ (p - 2)) * a - w +
  677. (p : ℤ_[p]) * ((2 * (r : ℤ_[p]) * a + (p : ℤ_[p]) * a ^ 2) * B +
  678. (r : ℤ_[p]) ^ 2 * ((r : ℤ_[p]) ^ (p - 2) * a + qH)) := by
  679. dsimp [B]; ring
  680. rw [hexpand, hr_p2]
  681. linear_combination -hra
  682. -- Show `G'(a) ≡ -r (mod p)`
  683. have hGda_mod : ∃ q : ℤ_[p], G.derivative.aeval a = -(r : ℤ_[p]) + (p : ℤ_[p]) * q := by
  684. rcases hHd_mod a with ⟨qHd, hqHd⟩
  685. rw [Polynomial.aeval_def, Polynomial.eval₂_eq_eval_map, Algebra.algebraMap_self,
  686. Polynomial.map_id]
  687. have hderiv_G : G.derivative =
  688. (2 * (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) *
  689. Polynomial.C (p : ℤ_[p])) * H +
  690. (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ 2 *
  691. H.derivative := by
  692. simp [G, Polynomial.derivative_pow, Polynomial.C_ofNat]
  693. rw [hderiv_G]
  694. have hev_G' : Polynomial.eval a
  695. ((2 * (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) *
  696. Polynomial.C (p : ℤ_[p])) * H +
  697. (Polynomial.C (r : ℤ_[p]) + Polynomial.C (p : ℤ_[p]) * Polynomial.X) ^ 2 *
  698. H.derivative) =
  699. 2 * ((r : ℤ_[p]) + (p : ℤ_[p]) * a) * (p : ℤ_[p]) * Polynomial.eval a H +
  700. ((r : ℤ_[p]) + (p : ℤ_[p]) * a) ^ 2 * Polynomial.eval a H.derivative := by
  701. simp
  702. rw [hev_G', hqHd, hpm1]
  703. set Hv := Polynomial.eval a H
  704. set Hd := ((p : ℤ_[p]) - 1) * (r : ℤ_[p]) ^ (p - 2) + (p : ℤ_[p]) * qHd
  705. refine ⟨2 * ((r : ℤ_[p]) + (p : ℤ_[p]) * a) * Hv +
  706. (2 * (r : ℤ_[p]) * a + (p : ℤ_[p]) * a ^ 2) * Hd +
  707. (r : ℤ_[p]) ^ 2 * ((r : ℤ_[p]) ^ (p - 2) + qHd) -
  708. (r : ℤ_[p]) * (c_nat : ℤ_[p]), ?_⟩
  709. have hexpand :
  710. 2 * ((r : ℤ_[p]) + (p : ℤ_[p]) * a) * (p : ℤ_[p]) * Hv +
  711. ((r : ℤ_[p]) + (p : ℤ_[p]) * a) ^ 2 * Hd =
  712. -((r : ℤ_[p]) ^ 2 * (r : ℤ_[p]) ^ (p - 2)) +
  713. (p : ℤ_[p]) * (2 * ((r : ℤ_[p]) + (p : ℤ_[p]) * a) * Hv +
  714. (2 * (r : ℤ_[p]) * a + (p : ℤ_[p]) * a ^ 2) * Hd +
  715. (r : ℤ_[p]) ^ 2 * ((r : ℤ_[p]) ^ (p - 2) + qHd)) := by
  716. dsimp [Hd]; ring
  717. rw [hexpand, hr_p2]
  718. ring
  719. have hp_inv_lt : ‖(p : ℤ_[p])‖ < 1 := by
  720. rw [PadicInt.norm_p]
  721. exact inv_lt_one_of_one_lt₀ (by exact_mod_cast hp.one_lt)
  722. have hGa_lt : ‖G.aeval a‖ < 1 := by
  723. rcases hGa_dvd with ⟨q, hq⟩
  724. rw [hq, norm_mul]
  725. have hq1 : ‖q‖ ≤ 1 := PadicInt.norm_le_one q
  726. calc
  727. ‖(p : ℤ_[p])‖ * ‖q‖ ≤ ‖(p : ℤ_[p])‖ * 1 :=
  728. mul_le_mul_of_nonneg_left hq1 (norm_nonneg _)
  729. _ < 1 := by linarith
  730. have hGda_eq : ‖G.derivative.aeval a‖ = 1 := by
  731. rcases hGda_mod with ⟨q, hq⟩
  732. rw [hq]
  733. have hlt : ‖(p : ℤ_[p]) * q‖ < ‖-(r : ℤ_[p])‖ := by
  734. rw [norm_neg, hr_norm, norm_mul]
  735. have hq1 : ‖q‖ ≤ 1 := PadicInt.norm_le_one q
  736. calc
  737. ‖(p : ℤ_[p])‖ * ‖q‖ ≤ ‖(p : ℤ_[p])‖ * 1 :=
  738. mul_le_mul_of_nonneg_left hq1 (norm_nonneg _)
  739. _ < 1 := by linarith
  740. rw [PadicInt.norm_add_eq_max_of_ne (ne_of_gt hlt), max_eq_left hlt.le, norm_neg, hr_norm]
  741. have hhensel : ‖G.aeval a‖ < ‖G.derivative.aeval a‖ ^ 2 := by
  742. rw [hGda_eq]; simpa using hGa_lt
  743. rcases hensels_lemma (p := p) (F := G) (a := a) hhensel with ⟨v, hv_root, _, _, _⟩
  744. refine ⟨v, ?_⟩
  745. rw [Polynomial.aeval_def, Polynomial.eval₂_eq_eval_map, Algebra.algebraMap_self,
  746. Polynomial.map_id] at hv_root
  747. have hv_eq : ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 * Polynomial.eval v H = w := by
  748. have h0 : ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 * Polynomial.eval v H - w = 0 := by
  749. simpa [G] using hv_root
  750. exact sub_eq_zero.mp h0
  751. have hH_eval : (p : ℤ_[p]) * Polynomial.eval v H =
  752. ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ (p - 1) - 1 := by
  753. have hev := congrArg (Polynomial.eval v) hH_mul
  754. simpa using hev
  755. calc
  756. ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 * (((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ (p - 1) - 1)
  757. = ((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 * ((p : ℤ_[p]) * Polynomial.eval v H) := by
  758. rw [hH_eval]
  759. _ = (p : ℤ_[p]) * (((r : ℤ_[p]) + (p : ℤ_[p]) * v) ^ 2 * Polynomial.eval v H) := by ring
  760. _ = (p : ℤ_[p]) * w := by rw [hv_eq]
  761. /-- `(p - 1)`-ary preimage tree in `ℚ_[p]`: for every prime `p`, every `k : ℕ`, and every
  762. `w ∈ ℤ_[p]`, `qpIter p k (x) = (w : ℚ_[p]) / p` has at least `(p - 1) ^ k` distinct solutions
  763. `x ∈ ℚ_[p]`. -/
  764. theorem qpIter_preimages (p : ℕ) [Fact p.Prime] (k : ℕ) :
  765. ∀ w : ℤ_[p],
  766. ∃ S : Finset ℚ_[p],
  767. S.card = (p - 1) ^ k ∧
  768. ∀ x ∈ S, Polynomial.aeval x (qpIter p k) = (w : ℚ_[p]) / (p : ℚ_[p]) := by
  769. classical
  770. have hp : p.Prime := Fact.out
  771. have hp_ne : (p : ℚ_[p]) ≠ 0 := by exact_mod_cast hp.ne_zero
  772. induction k with
  773. | zero =>
  774. intro w
  775. refine ⟨{(w : ℚ_[p]) / (p : ℚ_[p])}, by simp, ?_⟩
  776. intro x hx
  777. rw [Finset.mem_singleton] at hx
  778. subst hx
  779. simp [qpIter]
  780. | succ k ih =>
  781. intro w
  782. choose v hv using fun (r : ℕ) (hr : r ∈ Finset.Ico 1 p) =>
  783. padic_qp_ball_lift p r (Finset.mem_Ico.mp hr).1 (Finset.mem_Ico.mp hr).2 w
  784. let z : (r : {r // r ∈ Finset.Ico 1 p}) → ℤ_[p] :=
  785. fun r => (r.1 : ℤ_[p]) + (p : ℤ_[p]) * v r.1 r.2
  786. choose F hF_card hF_prop using fun r : {r // r ∈ Finset.Ico 1 p} => ih (z r)
  787. let S : Finset ℚ_[p] := (Finset.Ico 1 p).attach.biUnion F
  788. have hdisj : Set.PairwiseDisjoint
  789. ((Finset.Ico 1 p).attach : Set {r // r ∈ Finset.Ico 1 p}) F := by
  790. intro a _ b _ hab
  791. dsimp [Function.onFun]
  792. rw [Finset.disjoint_left]
  793. intro x hxa hxb
  794. have ha_eq := hF_prop a x hxa
  795. have hb_eq := hF_prop b x hxb
  796. have hz_eq_q : ((z a : ℤ_[p]) : ℚ_[p]) = ((z b : ℤ_[p]) : ℚ_[p]) :=
  797. (div_left_inj₀ hp_ne).mp (ha_eq.symm.trans hb_eq)
  798. have hz_eq : z a = z b := PadicInt.coe_inj.mp hz_eq_q
  799. have hdiff : ((a.1 : ℤ_[p]) - (b.1 : ℤ_[p])) = (p : ℤ_[p]) * (v b.1 b.2 - v a.1 a.2) := by
  800. dsimp [z] at hz_eq
  801. linear_combination hz_eq
  802. have hnorm_lt : ‖(((a.1 : ℤ) - (b.1 : ℤ) : ℤ) : ℤ_[p])‖ < 1 := by
  803. rw [Int.cast_sub, Int.cast_natCast, Int.cast_natCast, hdiff, norm_mul]
  804. have hvp : ‖(p : ℤ_[p])‖ < 1 := by
  805. rw [PadicInt.norm_p]
  806. exact inv_lt_one_of_one_lt₀ (by exact_mod_cast hp.one_lt)
  807. have hv1 : ‖v b.1 b.2 - v a.1 a.2‖ ≤ 1 := PadicInt.norm_le_one _
  808. calc
  809. ‖(p : ℤ_[p])‖ * ‖v b.1 b.2 - v a.1 a.2‖ ≤ ‖(p : ℤ_[p])‖ * 1 :=
  810. mul_le_mul_of_nonneg_left hv1 (norm_nonneg _)
  811. _ < 1 := by linarith
  812. have hdvd : (p : ℤ) ∣ ((a.1 : ℤ) - (b.1 : ℤ)) := by
  813. by_contra hndvd
  814. have hcop : IsCoprime ((a.1 : ℤ) - (b.1 : ℤ)) (p : ℤ) :=
  815. ((Nat.prime_iff_prime_int.mp hp).coprime_iff_not_dvd.mpr hndvd).symm
  816. have h1 : ‖(((a.1 : ℤ) - (b.1 : ℤ) : ℤ) : ℤ_[p])‖ = 1 :=
  817. PadicInt.norm_intCast_eq_one_iff.mpr hcop
  818. linarith
  819. have ha_mem := Finset.mem_Ico.mp a.2
  820. have hb_mem := Finset.mem_Ico.mp b.2
  821. have hab_eq : a.1 = b.1 := by
  822. obtain ⟨q, hq⟩ := hdvd
  823. have hq0 : q = 0 := by nlinarith
  824. rw [hq0, mul_zero] at hq
  825. omega
  826. exact hab (Subtype.ext hab_eq)
  827. refine ⟨S, ?_, ?_⟩
  828. · rw [Finset.card_biUnion hdisj]
  829. calc
  830. ∑ r ∈ (Finset.Ico 1 p).attach, (F r).card
  831. = ∑ _r ∈ (Finset.Ico 1 p).attach, (p - 1) ^ k :=
  832. Finset.sum_congr rfl (fun r _ => hF_card r)
  833. _ = (Finset.Ico 1 p).attach.card * (p - 1) ^ k := by simp
  834. _ = (p - 1) ^ (k + 1) := by
  835. rw [Finset.card_attach, Nat.card_Ico, pow_succ']
  836. · intro x hx
  837. rcases Finset.mem_biUnion.mp hx with ⟨r, _, hxr⟩
  838. have hfk := hF_prop r x hxr
  839. have hvr := hv r.1 r.2
  840. have hvr_q : ((z r : ℤ_[p]) : ℚ_[p]) ^ 2 *
  841. (((z r : ℤ_[p]) : ℚ_[p]) ^ (p - 1) - 1) = (p : ℚ_[p]) * (w : ℚ_[p]) := by
  842. have hcast := congrArg (fun u : ℤ_[p] => (u : ℚ_[p])) hvr
  843. simpa [z] using hcast
  844. have hp_aeval : Polynomial.aeval x (Polynomial.C (p : ℤ)) = (p : ℚ_[p]) := by
  845. simp
  846. simp only [qpIter, map_mul, map_sub, map_pow, map_one, hp_aeval, hfk]
  847. have hmul_div : (p : ℚ_[p]) * ((z r : ℚ_[p]) / (p : ℚ_[p])) = (z r : ℚ_[p]) :=
  848. mul_div_cancel₀ _ hp_ne
  849. rw [hmul_div, div_pow, div_mul_eq_mul_div, hvr_q, sq, mul_div_mul_left _ _ hp_ne]
  850. /-! ## 3. Addition-Chain / `CanBuild` Helpers for `Q_p^[k]` -/
  851. /-- Repeated squaring: `{f}` builds `{f ^ (2 ^ d)}` in `d` gates. -/
  852. theorem canBuild_pow_two_pow (f : Polynomial ℤ) (d : ℕ) :
  853. CanBuild ({f} : Set (Polynomial ℤ)) d {f ^ (2 ^ d)} := by
  854. induction d with
  855. | zero =>
  856. refine canBuild_subset ?_
  857. simp
  858. | succ d ih =>
  859. have h2 := canBuild_mul (f ^ (2 ^ d)) (f ^ (2 ^ d))
  860. have hcomb := canBuild_trans ih (by intro x hx; rcases hx with rfl | rfl <;> exact Or.inr rfl) h2
  861. refine canBuild_mono_out ?_ hcomb
  862. intro x hx
  863. rw [Set.mem_singleton_iff] at hx
  864. subst hx
  865. right
  866. rw [Set.mem_singleton_iff, ← pow_add, pow_succ, mul_two]
  867. /-- Build `{(2 ^ m : Polynomial ℤ)}` from `{1}` in `m` gates. -/
  868. theorem canBuild_two_pow (m : ℕ) :
  869. CanBuild ({(1 : Polynomial ℤ)} : Set (Polynomial ℤ)) m {((2 ^ m : ℕ) : Polynomial ℤ)} := by
  870. induction m with
  871. | zero =>
  872. refine canBuild_subset ?_
  873. simp
  874. | succ m ih =>
  875. have hadd := canBuild_add ((2 ^ m : ℕ) : Polynomial ℤ) ((2 ^ m : ℕ) : Polynomial ℤ)
  876. have hcomb := canBuild_trans ih
  877. (by intro x hx; rcases hx with rfl | rfl <;> exact Or.inr rfl) hadd
  878. refine canBuild_mono_out ?_ hcomb
  879. intro x hx
  880. rw [Set.mem_singleton_iff] at hx
  881. subst hx
  882. right
  883. rw [Set.mem_singleton_iff, pow_succ, mul_two, Nat.cast_add]
  884. /-- Build any natural constant `(n : Polynomial ℤ)` from `{1}` in at most `2 * Nat.log 2 n + 2` gates. -/
  885. theorem canBuild_nat_const (n : ℕ) :
  886. CanBuild ({(1 : Polynomial ℤ)} : Set (Polynomial ℤ)) (2 * Nat.log 2 n + 2)
  887. {(n : Polynomial ℤ)} := by
  888. induction n using Nat.strong_induction_on with
  889. | ind n ih =>
  890. by_cases hn0 : n = 0
  891. · subst hn0
  892. have h0 : CanBuild ({(1 : Polynomial ℤ)} : Set (Polynomial ℤ)) 1 {0} :=
  893. canBuild_mono_in (by simp) (canBuild_mono_out (by simp) (canBuild_sub (1 : Polynomial ℤ) 1))
  894. exact canBuild_mono_cost (by omega) (canBuild_mono_out (by simp) h0)
  895. · by_cases hn1 : n = 1
  896. · subst hn1
  897. exact canBuild_mono_cost (by omega) (canBuild_subset (by simp))
  898. · have hge2 : 2 ≤ n := by omega
  899. have hhalf_lt : n / 2 < n := Nat.div_lt_self (by omega) (by norm_num)
  900. have hlog : Nat.log 2 (n / 2) + 1 = Nat.log 2 n := by
  901. have := Nat.log_div_base 2 n
  902. have h1 : 1 ≤ Nat.log 2 n := Nat.le_log_of_pow_le (by norm_num) (by omega)
  903. omega
  904. have hprev := ih (n / 2) hhalf_lt
  905. have hdbl := canBuild_add ((n / 2 : ℕ) : Polynomial ℤ) ((n / 2 : ℕ) : Polynomial ℤ)
  906. have h1 := canBuild_trans hprev
  907. (by intro x hx; rcases hx with rfl | rfl <;> exact Or.inr rfl) hdbl
  908. by_cases hmod : n % 2 = 0
  909. · have heq : ((n / 2 : ℕ) : Polynomial ℤ) + ((n / 2 : ℕ) : Polynomial ℤ) =
  910. (n : Polynomial ℤ) := by
  911. rw [← Nat.cast_add]
  912. congr 1; omega
  913. refine canBuild_mono_cost (by omega) (canBuild_mono_out ?_ h1)
  914. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  915. right; simp [heq]
  916. · have hmod1 : n % 2 = 1 := by omega
  917. have hadd1 := canBuild_add
  918. (((n / 2 : ℕ) : Polynomial ℤ) + ((n / 2 : ℕ) : Polynomial ℤ)) 1
  919. have h2 := canBuild_trans h1
  920. (by
  921. intro x hx
  922. rcases hx with rfl | rfl
  923. · exact Or.inr (Or.inr rfl)
  924. · exact Or.inl rfl)
  925. hadd1
  926. have heq : ((n / 2 : ℕ) : Polynomial ℤ) + ((n / 2 : ℕ) : Polynomial ℤ) + 1 =
  927. (n : Polynomial ℤ) := by
  928. rw [← Nat.cast_add, ← Nat.cast_one, ← Nat.cast_add]
  929. congr 1; omega
  930. refine canBuild_mono_cost (by omega) (canBuild_mono_out ?_ h2)
  931. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  932. right; simp [heq]
  933. /-- Precompute the table `{f ^ j | j < B}` from `{1, f}` in `B` gates. -/
  934. theorem canBuild_pow_table (f : Polynomial ℤ) (B : ℕ) :
  935. CanBuild ({(1 : Polynomial ℤ), f} : Set (Polynomial ℤ)) B
  936. (⋃ j < B, {f ^ j}) := by
  937. induction B with
  938. | zero =>
  939. simpa using canBuild_empty ({(1 : Polynomial ℤ), f} : Set (Polynomial ℤ))
  940. | succ B ih =>
  941. by_cases hB0 : B = 0
  942. · subst hB0
  943. refine canBuild_mono_cost (by omega) (canBuild_subset ?_)
  944. intro x hx
  945. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hx
  946. rcases hx with ⟨j, hj, rfl⟩
  947. have : j = 0 := by omega
  948. subst this
  949. simp
  950. · have hmul := canBuild_mul (f ^ (B - 1)) f
  951. have hsub : ({f ^ (B - 1), f} : Set (Polynomial ℤ)) ⊆
  952. ({(1 : Polynomial ℤ), f} : Set (Polynomial ℤ)) ∪ ⋃ j < B, {f ^ j} := by
  953. intro x hx
  954. rcases hx with rfl | rfl
  955. · right
  956. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff]
  957. exact ⟨B - 1, by omega, rfl⟩
  958. · exact Or.inl (by simp)
  959. have hcomb := canBuild_trans ih hsub hmul
  960. refine canBuild_mono_out ?_ hcomb
  961. intro x hx
  962. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hx
  963. rcases hx with ⟨j, hj, rfl⟩
  964. rcases Nat.lt_succ_iff_lt_or_eq.mp hj with hlt | hjeq
  965. · left
  966. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff]
  967. exact ⟨j, hlt, rfl⟩
  968. · right
  969. rw [hjeq, Set.mem_singleton_iff, ← pow_succ, show B - 1 + 1 = B by omega]
  970. /-- Windowed base-`2^w` exponentiation given the precomputed table `{f ^ j | j < 2 ^ w}`:
  971. builds `{f ^ e}` in at most `(w + 1) * (Nat.log 2 e / w)` extra gates. -/
  972. theorem canBuild_pow_from_table (w : ℕ) (hw : 1 ≤ w) (f : Polynomial ℤ) (e : ℕ) :
  973. CanBuild (⋃ j < 2 ^ w, {f ^ j}) ((w + 1) * (Nat.log 2 e / w)) {f ^ e} := by
  974. induction e using Nat.strong_induction_on with
  975. | ind e ih =>
  976. by_cases hlt : e < 2 ^ w
  977. · refine canBuild_mono_cost (Nat.zero_le _) (canBuild_subset ?_)
  978. intro x hx
  979. rw [Set.mem_singleton_iff] at hx
  980. subst hx
  981. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff]
  982. exact ⟨e, hlt, rfl⟩
  983. · have hge : 2 ^ w ≤ e := Nat.le_of_not_lt hlt
  984. have he_pos : 0 < e := by
  985. have : 0 < 2 ^ w := by positivity
  986. omega
  987. have hq_pos : 0 < e / 2 ^ w := Nat.div_pos hge (by positivity)
  988. have hq_lt : e / 2 ^ w < e := Nat.div_lt_self he_pos (by
  989. have : 2 ^ 1 ≤ 2 ^ w := Nat.pow_le_pow_right (by norm_num) hw
  990. omega)
  991. have hlog_ge : w ≤ Nat.log 2 e := Nat.le_log_of_pow_le (by norm_num) hge
  992. have hlog_q : Nat.log 2 (e / 2 ^ w) + w ≤ Nat.log 2 e := by
  993. have h1 : 2 ^ (Nat.log 2 (e / 2 ^ w)) ≤ e / 2 ^ w :=
  994. Nat.pow_log_le_self 2 hq_pos.ne'
  995. have h2 : 2 ^ (Nat.log 2 (e / 2 ^ w) + w) ≤ e := by
  996. rw [pow_add]
  997. calc
  998. 2 ^ Nat.log 2 (e / 2 ^ w) * 2 ^ w ≤ (e / 2 ^ w) * 2 ^ w :=
  999. Nat.mul_le_mul_right _ h1
  1000. _ ≤ e := Nat.div_mul_le_self e (2 ^ w)
  1001. exact Nat.le_log_of_pow_le (by norm_num) h2
  1002. have hdiv_step : Nat.log 2 (e / 2 ^ w) / w + 1 ≤ Nat.log 2 e / w := by
  1003. have hadd : (Nat.log 2 (e / 2 ^ w) + w) / w = Nat.log 2 (e / 2 ^ w) / w + 1 :=
  1004. Nat.add_div_right _ (by omega)
  1005. rw [← hadd]
  1006. exact Nat.div_le_div_right hlog_q
  1007. have hprev := ih (e / 2 ^ w) hq_lt
  1008. have hsq := canBuild_pow_two_pow (f ^ (e / 2 ^ w)) w
  1009. have h1 := canBuild_trans hprev
  1010. (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; exact Or.inr rfl) hsq
  1011. have hmul := canBuild_mul ((f ^ (e / 2 ^ w)) ^ (2 ^ w)) (f ^ (e % 2 ^ w))
  1012. have hsub2 : ({(f ^ (e / 2 ^ w)) ^ (2 ^ w), f ^ (e % 2 ^ w)} : Set (Polynomial ℤ)) ⊆
  1013. (⋃ j < 2 ^ w, {f ^ j}) ∪ ({f ^ (e / 2 ^ w)} ∪ {(f ^ (e / 2 ^ w)) ^ (2 ^ w)}) := by
  1014. intro x hx
  1015. rcases hx with rfl | rfl
  1016. · exact Or.inr (Or.inr rfl)
  1017. · left
  1018. simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff]
  1019. exact ⟨e % 2 ^ w, Nat.mod_lt e (by positivity), rfl⟩
  1020. have h2 := canBuild_trans h1 hsub2 hmul
  1021. have hcost : (w + 1) * (Nat.log 2 (e / 2 ^ w) / w) + w + 1 ≤
  1022. (w + 1) * (Nat.log 2 e / w) := by
  1023. calc
  1024. (w + 1) * (Nat.log 2 (e / 2 ^ w) / w) + w + 1
  1025. = (w + 1) * (Nat.log 2 (e / 2 ^ w) / w + 1) := by ring
  1026. _ ≤ (w + 1) * (Nat.log 2 e / w) := Nat.mul_le_mul_left _ hdiv_step
  1027. refine canBuild_mono_cost hcost (canBuild_mono_out ?_ h2)
  1028. intro x hx
  1029. rw [Set.mem_singleton_iff] at hx
  1030. subst hx
  1031. right
  1032. rw [Set.mem_singleton_iff, ← pow_mul, ← pow_add, mul_comm (e / 2 ^ w), Nat.div_add_mod]
  1033. /-- Windowed base-`2^w` exponentiation from `{1, f}` in `2^w + (w + 1) * (Nat.log 2 e / w)` gates. -/
  1034. theorem canBuild_pow_window (w : ℕ) (hw : 1 ≤ w) (f : Polynomial ℤ) (e : ℕ) :
  1035. CanBuild ({(1 : Polynomial ℤ), f} : Set (Polynomial ℤ))
  1036. (2 ^ w + (w + 1) * (Nat.log 2 e / w)) {f ^ e} := by
  1037. have h1 := canBuild_pow_table f (2 ^ w)
  1038. have h2 := canBuild_pow_from_table w hw f e
  1039. have hcomb := canBuild_trans h1 Set.subset_union_right h2
  1040. exact canBuild_mono_out Set.subset_union_right hcomb
  1041. /-- One iteration of `Q_p` from `{1, C(p^2), f}` using any `d`-gate exponentiation engine for
  1042. `e = (p - 1) / 2` (for odd `p`) costs `d + 4` gates. -/
  1043. theorem canBuild_qp_step (p d : ℕ) (hp_odd : p % 2 = 1) (f : Polynomial ℤ)
  1044. (hexp : CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2 * f ^ 2} : Set (Polynomial ℤ))
  1045. d {((p : Polynomial ℤ) ^ 2 * f ^ 2) ^ ((p - 1) / 2)}) :
  1046. CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2, f} : Set (Polynomial ℤ)) (d + 4)
  1047. {f ^ 2 * ((Polynomial.C (p : ℤ) * f) ^ (p - 1) - 1)} := by
  1048. have h1 : CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2, f} : Set (Polynomial ℤ))
  1049. 1 {f * f} := canBuild_mono_in (by intro x hx; rcases hx with rfl | rfl <;> simp)
  1050. (canBuild_mul f f)
  1051. have h2 : CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2, f} ∪ {f * f}) 1
  1052. {(p : Polynomial ℤ) ^ 2 * (f * f)} :=
  1053. canBuild_mono_in (by intro x hx; rcases hx with rfl | rfl <;> simp)
  1054. (canBuild_mul ((p : Polynomial ℤ) ^ 2) (f * f))
  1055. have h12 := canBuild_seq h1 h2
  1056. have hsq_eq : (p : Polynomial ℤ) ^ 2 * (f * f) = (p : Polynomial ℤ) ^ 2 * f ^ 2 := by ring
  1057. have h3 := canBuild_trans h12
  1058. (by
  1059. intro x hx
  1060. rcases hx with rfl | rfl
  1061. · exact Or.inl (by simp)
  1062. · right; right; simp [hsq_eq])
  1063. hexp
  1064. set z := ((p : Polynomial ℤ) ^ 2 * f ^ 2) ^ ((p - 1) / 2)
  1065. have h4 := canBuild_trans h3
  1066. (by
  1067. intro x hx
  1068. rcases hx with rfl | rfl
  1069. · exact Or.inr (Or.inr rfl)
  1070. · exact Or.inl (by simp))
  1071. (canBuild_sub z 1)
  1072. have h5 := canBuild_trans h4
  1073. (by
  1074. intro x hx
  1075. rcases hx with rfl | rfl
  1076. · exact Or.inr (Or.inl (Or.inl (Or.inl rfl)))
  1077. · exact Or.inr (Or.inr rfl))
  1078. (canBuild_mul (f * f) (z - 1))
  1079. have hval : f * f * (z - 1) = f ^ 2 * ((Polynomial.C (p : ℤ) * f) ^ (p - 1) - 1) := by
  1080. have hp_even : 2 * ((p - 1) / 2) = p - 1 := by omega
  1081. have hz : z = (Polynomial.C (p : ℤ) * f) ^ (p - 1) := by
  1082. dsimp [z]
  1083. have hbase : (p : Polynomial ℤ) ^ 2 * f ^ 2 = (Polynomial.C (p : ℤ) * f) ^ 2 := by
  1084. simp [mul_pow]
  1085. rw [hbase, ← pow_mul, hp_even]
  1086. rw [hz, ← sq]
  1087. refine canBuild_mono_cost (by omega) (canBuild_mono_out ?_ h5)
  1088. intro x hx
  1089. rw [Set.mem_singleton_iff] at hx
  1090. subst hx
  1091. right
  1092. rw [Set.mem_singleton_iff, hval]
  1093. /-! ## 4. Headline Uniform $p$-Adic Barrier Theorems -/
  1094. /-- **Fermat-Prime $p$-Adic Lower Bound (`α_{ℚ_{2^m+1}} ≥ m / (m + 3)`):**
  1095. For every prime `p = 2 ^ m + 1` (`m ≥ 1`) and every `k ≥ 1`, there exists a constant-free SLP
  1096. of length `(m + 3) * k + (m + 3)` computing a nonzero polynomial `f ∈ ℤ[X]` with at least
  1097. `(p - 1) ^ k` distinct roots in `ℚ_[p]`.
  1098. In particular, `p = 65537` (`m = 16`) gives rate `16 / 19 ≈ 0.8421`. -/
  1099. theorem tau_padic_fermat (p m : ℕ) [Fact p.Prime] (hm : 1 ≤ m) (hp_eq : p = 2 ^ m + 1)
  1100. (k : ℕ) (_hk : 1 ≤ k) :
  1101. ∃ P : SLP ((m + 3) * k + (m + 3)),
  1102. P.evalPoly ≠ 0 ∧
  1103. ∃ S : Finset ℚ_[p],
  1104. S.card = (p - 1) ^ k ∧ ∀ r ∈ S, Polynomial.aeval r P.evalPoly = 0 := by
  1105. have hp : p.Prime := Fact.out
  1106. have hp_odd : p % 2 = 1 := by
  1107. have : 2 ∣ 2 ^ m := dvd_pow_self 2 (by omega)
  1108. omega
  1109. have hdiv : (p - 1) / 2 = 2 ^ (m - 1) := by
  1110. rw [hp_eq]
  1111. have h1 : 2 ^ m = 2 * 2 ^ (m - 1) := by
  1112. conv_lhs => rw [show m = (m - 1) + 1 by omega, pow_succ']
  1113. omega
  1114. have hsetup_2m : CanBuild ({(1 : Polynomial ℤ), Polynomial.X} : Set (Polynomial ℤ)) m
  1115. {((2 ^ m : ℕ) : Polynomial ℤ)} :=
  1116. canBuild_mono_in (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; simp)
  1117. (canBuild_two_pow m)
  1118. have hsetup_p : CanBuild ({(1 : Polynomial ℤ), Polynomial.X} : Set (Polynomial ℤ)) (m + 1)
  1119. {(p : Polynomial ℤ)} := by
  1120. have hadd := canBuild_add ((2 ^ m : ℕ) : Polynomial ℤ) 1
  1121. have hcomb := canBuild_trans hsetup_2m
  1122. (by intro x hx; rcases hx with rfl | rfl; exact Or.inr rfl; exact Or.inl (by simp)) hadd
  1123. refine canBuild_mono_out ?_ hcomb
  1124. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  1125. right; rw [Set.mem_singleton_iff, hp_eq, Nat.cast_add, Nat.cast_one]
  1126. have hsetup : CanBuild ({(1 : Polynomial ℤ), Polynomial.X} : Set (Polynomial ℤ)) (m + 2)
  1127. {(p : Polynomial ℤ) ^ 2} := by
  1128. have hmul := canBuild_mul (p : Polynomial ℤ) (p : Polynomial ℤ)
  1129. have hcomb := canBuild_trans hsetup_p
  1130. (by intro x hx; rcases hx with rfl | rfl <;> exact Or.inr rfl) hmul
  1131. refine canBuild_mono_out ?_ hcomb
  1132. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  1133. right; rw [Set.mem_singleton_iff, sq]
  1134. have hiter : ∀ j : ℕ,
  1135. CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2, Polynomial.X} : Set (Polynomial ℤ))
  1136. ((m + 3) * j) {qpIter p j} := by
  1137. intro j
  1138. induction j with
  1139. | zero =>
  1140. refine canBuild_subset ?_
  1141. simp [qpIter]
  1142. | succ j ih =>
  1143. have hstep := canBuild_qp_step p (m - 1) hp_odd (qpIter p j) (by
  1144. rw [hdiv]
  1145. exact canBuild_mono_in (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; simp)
  1146. (canBuild_pow_two_pow ((p : Polynomial ℤ) ^ 2 * (qpIter p j) ^ 2) (m - 1)))
  1147. have hcomb := canBuild_trans ih
  1148. (by
  1149. intro x hx
  1150. rcases hx with rfl | rfl | rfl
  1151. · exact Or.inl (by simp)
  1152. · exact Or.inl (by simp)
  1153. · exact Or.inr rfl)
  1154. hstep
  1155. have hcost : (m + 3) * j + (m - 1 + 4) = (m + 3) * (j + 1) := by
  1156. rw [show m - 1 + 4 = m + 3 by omega]; ring
  1157. rw [hcost] at hcomb
  1158. refine canBuild_mono_out ?_ hcomb
  1159. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  1160. right; simp [qpIter]
  1161. have hfull := canBuild_trans hsetup
  1162. (by
  1163. intro x hx
  1164. rcases hx with rfl | rfl | rfl
  1165. · exact Or.inl (by simp)
  1166. · exact Or.inr rfl
  1167. · exact Or.inl (by simp))
  1168. (hiter k)
  1169. have hcomp0 : Computes (0 + (m + 2 + (m + 3) * k))
  1170. ({(1 : Polynomial ℤ), Polynomial.X} ∪ ({(p : Polynomial ℤ) ^ 2} ∪ {qpIter p k})) :=
  1171. hfull 0 _ Set.Subset.rfl computes_nil
  1172. have hcomp : Computes ((m + 3) * k + (m + 2))
  1173. ({(1 : Polynomial ℤ), Polynomial.X} ∪ ({(p : Polynomial ℤ) ^ 2} ∪ {qpIter p k})) := by
  1174. rwa [show 0 + (m + 2 + (m + 3) * k) = (m + 3) * k + (m + 2) by ring] at hcomp0
  1175. rcases computes_extract hcomp (Or.inr (Or.inr rfl)) with ⟨P, hP⟩
  1176. refine ⟨P, ?_, ?_⟩
  1177. · rw [hP]; exact qpIter_ne_zero p hp k
  1178. · rcases qpIter_preimages p k 0 with ⟨S, hcard, hS⟩
  1179. refine ⟨S, hcard, ?_⟩
  1180. intro r hr
  1181. rw [hP, hS r hr, PadicInt.coe_zero, zero_div]
  1182. /-- General odd-prime SLP length bound via base-`2^w` windowed addition chains. -/
  1183. theorem tau_padic_window_slp (p w k : ℕ) [Fact p.Prime] (hp2 : p ≠ 2) (hw : 1 ≤ w) :
  1184. ∃ P : SLP ((2 ^ w + (w + 1) * (Nat.log 2 p / w) + 4) * k + (2 * Nat.log 2 p + 4)),
  1185. P.evalPoly ≠ 0 ∧
  1186. ∃ S : Finset ℚ_[p],
  1187. S.card = (p - 1) ^ k ∧ ∀ r ∈ S, Polynomial.aeval r P.evalPoly = 0 := by
  1188. have hp : p.Prime := Fact.out
  1189. have hp_odd : p % 2 = 1 := hp.eq_two_or_odd.resolve_left hp2
  1190. set d := 2 ^ w + (w + 1) * (Nat.log 2 p / w)
  1191. have hsetup_p : CanBuild ({(1 : Polynomial ℤ), Polynomial.X} : Set (Polynomial ℤ))
  1192. (2 * Nat.log 2 p + 2) {(p : Polynomial ℤ)} :=
  1193. canBuild_mono_in (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; simp)
  1194. (canBuild_nat_const p)
  1195. have hsetup : CanBuild ({(1 : Polynomial ℤ), Polynomial.X} : Set (Polynomial ℤ))
  1196. (2 * Nat.log 2 p + 3) {(p : Polynomial ℤ) ^ 2} := by
  1197. have hmul := canBuild_mul (p : Polynomial ℤ) (p : Polynomial ℤ)
  1198. have hcomb := canBuild_trans hsetup_p
  1199. (by intro x hx; rcases hx with rfl | rfl <;> exact Or.inr rfl) hmul
  1200. refine canBuild_mono_out ?_ hcomb
  1201. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  1202. right; rw [Set.mem_singleton_iff, sq]
  1203. have hiter : ∀ j : ℕ,
  1204. CanBuild ({(1 : Polynomial ℤ), (p : Polynomial ℤ) ^ 2, Polynomial.X} : Set (Polynomial ℤ))
  1205. ((d + 4) * j) {qpIter p j} := by
  1206. intro j
  1207. induction j with
  1208. | zero =>
  1209. refine canBuild_subset ?_
  1210. simp [qpIter]
  1211. | succ j ih =>
  1212. have hlog_le : Nat.log 2 ((p - 1) / 2) ≤ Nat.log 2 p :=
  1213. Nat.log_mono_right (by omega)
  1214. have hcost_exp : 2 ^ w + (w + 1) * (Nat.log 2 ((p - 1) / 2) / w) ≤ d :=
  1215. Nat.add_le_add_left (Nat.mul_le_mul_left _ (Nat.div_le_div_right hlog_le)) _
  1216. have hstep := canBuild_qp_step p d hp_odd (qpIter p j)
  1217. (canBuild_mono_cost hcost_exp
  1218. (canBuild_pow_window w hw ((p : Polynomial ℤ) ^ 2 * (qpIter p j) ^ 2) ((p - 1) / 2)))
  1219. have hcomb := canBuild_trans ih
  1220. (by
  1221. intro x hx
  1222. rcases hx with rfl | rfl | rfl
  1223. · exact Or.inl (by simp)
  1224. · exact Or.inl (by simp)
  1225. · exact Or.inr rfl)
  1226. hstep
  1227. have hcost : (d + 4) * j + (d + 4) = (d + 4) * (j + 1) := by ring
  1228. rw [hcost] at hcomb
  1229. refine canBuild_mono_out ?_ hcomb
  1230. intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx
  1231. right; simp [qpIter]
  1232. have hfull := canBuild_trans hsetup
  1233. (by
  1234. intro x hx
  1235. rcases hx with rfl | rfl | rfl
  1236. · exact Or.inl (by simp)
  1237. · exact Or.inr rfl
  1238. · exact Or.inl (by simp))
  1239. (hiter k)
  1240. have hcomp0 : Computes (0 + (2 * Nat.log 2 p + 3 + (d + 4) * k))
  1241. ({(1 : Polynomial ℤ), Polynomial.X} ∪ ({(p : Polynomial ℤ) ^ 2} ∪ {qpIter p k})) :=
  1242. hfull 0 _ Set.Subset.rfl computes_nil
  1243. have hcomp : Computes ((d + 4) * k + (2 * Nat.log 2 p + 3))
  1244. ({(1 : Polynomial ℤ), Polynomial.X} ∪ ({(p : Polynomial ℤ) ^ 2} ∪ {qpIter p k})) := by
  1245. rwa [show 0 + (2 * Nat.log 2 p + 3 + (d + 4) * k) =
  1246. (d + 4) * k + (2 * Nat.log 2 p + 3) by ring] at hcomp0
  1247. rcases computes_extract hcomp (Or.inr (Or.inr rfl)) with ⟨P, hP⟩
  1248. refine ⟨P, ?_, ?_⟩
  1249. · rw [hP]; exact qpIter_ne_zero p hp k
  1250. · rcases qpIter_preimages p k 0 with ⟨S, hcard, hS⟩
  1251. refine ⟨S, hcard, ?_⟩
  1252. intro r hr
  1253. rw [hP, hS r hr, PadicInt.coe_zero, zero_div]
  1254. /-- **Uniform $p$-Adic Barrier (`lim_{p → ∞} α_{ℚ_p} = 1`):**
  1255. For every `ε > 0`, there exists a prime `p`, a step cost `τ_step > 0`, and a setup overhead `C`
  1256. such that for every `k ≥ 1`, there is a constant-free SLP of length `τ_step * k + C` computing a
  1257. nonzero polynomial `f ∈ ℤ[X]` with `(p - 1) ^ k` distinct roots in `ℚ_[p]`, while the exponential
  1258. growth rate `log_2(p - 1) / τ_step` strictly exceeds `1 - ε`.
  1259. Consequently, no proof that works uniformly across primes `p` can establish
  1260. `z_{ℚ_p}(f) ≤ 2 ^ ((1 - ε) * τ(f))` for any constant `ε > 0`. -/
  1261. theorem tau_padic_rate_arbitrarily_close_to_one (ε : ℝ) (hε : 0 < ε) :
  1262. ∃ (p : ℕ) (_ : Fact p.Prime) (τ_step C : ℕ),
  1263. 0 < τ_step ∧
  1264. 1 - ε < Real.logb 2 (p - 1 : ℝ) / (τ_step : ℝ) ∧
  1265. ∀ k : ℕ, 1 ≤ k →
  1266. ∃ P : SLP (τ_step * k + C),
  1267. P.evalPoly ≠ 0 ∧
  1268. ∃ S : Finset ℚ_[p],
  1269. S.card = (p - 1) ^ k ∧ ∀ r ∈ S, Polynomial.aeval r P.evalPoly = 0 := by
  1270. obtain ⟨w, hw_gt⟩ := exists_nat_gt (3 / ε)
  1271. have hw1 : 1 ≤ w := by
  1272. by_contra h
  1273. have hw0 : w = 0 := by omega
  1274. subst hw0
  1275. have : 0 < 3 / ε := by positivity
  1276. linarith
  1277. obtain ⟨M, hM_gt⟩ := exists_nat_gt (((2 ^ w + 6 : ℕ) : ℝ) * (3 / ε) + 4)
  1278. obtain ⟨p, hp_ge, hp_prime⟩ := Nat.exists_infinite_primes (2 ^ M)
  1279. have : Fact p.Prime := ⟨hp_prime⟩
  1280. have hM_ge4 : 4 ≤ M := by
  1281. have hnonneg : (0 : ℝ) ≤ ((2 ^ w + 6 : ℕ) : ℝ) * (3 / ε) := by positivity
  1282. have h4 : (4 : ℝ) < (M : ℝ) := by linarith
  1283. exact_mod_cast h4.le
  1284. have hp_ge16 : 16 ≤ p := by
  1285. have : 2 ^ 4 ≤ 2 ^ M := Nat.pow_le_pow_right (by norm_num) hM_ge4
  1286. omega
  1287. have hp2 : p ≠ 2 := by omega
  1288. let τ_step : ℕ := 2 ^ w + (w + 1) * (Nat.log 2 p / w) + 4
  1289. let C : ℕ := 2 * Nat.log 2 p + 4
  1290. refine ⟨p, inferInstance, τ_step, C, by positivity, ?_, ?_⟩
  1291. · have hL_ge : M ≤ Nat.log 2 p := Nat.le_log_of_pow_le (by norm_num) hp_ge
  1292. set L : ℕ := Nat.log 2 p
  1293. have hL_pos : (0 : ℝ) < (L : ℝ) := by exact_mod_cast (show 0 < L by omega)
  1294. have hτ_pos : (0 : ℝ) < (τ_step : ℝ) := by positivity
  1295. have h2pow_le : (2 : ℝ) ^ (L - 1) ≤ (p - 1 : ℝ) := by
  1296. have h1 : 2 ^ L ≤ p := Nat.pow_log_le_self 2 (by omega)
  1297. have h2 : 2 ^ (L - 1) + 1 ≤ 2 ^ L := by
  1298. have hL1 : 1 ≤ L := by omega
  1299. have hmul : 2 ^ L = 2 * 2 ^ (L - 1) := by
  1300. conv_lhs => rw [show L = (L - 1) + 1 by omega, pow_succ']
  1301. have hpos : 1 ≤ 2 ^ (L - 1) := Nat.one_le_pow _ _ (by norm_num)
  1302. omega
  1303. have h3 : 2 ^ (L - 1) ≤ p - 1 := by omega
  1304. have h3r : ((2 ^ (L - 1) : ℕ) : ℝ) ≤ ((p - 1 : ℕ) : ℝ) := by exact_mod_cast h3
  1305. rw [Nat.cast_pow, Nat.cast_ofNat, Nat.cast_sub (by omega), Nat.cast_one] at h3r
  1306. exact h3r
  1307. have hlog_ge : (L : ℝ) - 1 ≤ Real.logb 2 (p - 1 : ℝ) := by
  1308. have hbase : (1 : ℝ) < 2 := by norm_num
  1309. have hpos : (0 : ℝ) < (2 : ℝ) ^ (L - 1) := by positivity
  1310. have hmono := Real.logb_le_logb_of_le hbase hpos h2pow_le
  1311. rw [Real.logb_pow, Real.logb_self_eq_one hbase, mul_one] at hmono
  1312. have hcast : ((L - 1 : ℕ) : ℝ) = (L : ℝ) - 1 := by
  1313. rw [Nat.cast_sub (by omega), Nat.cast_one]
  1314. rwa [hcast] at hmono
  1315. have hτ_le : (τ_step : ℝ) ≤ (L : ℝ) + (L : ℝ) / (w : ℝ) + ((2 ^ w + 4 : ℕ) : ℝ) := by
  1316. have hdiv_le : ((L / w : ℕ) : ℝ) ≤ (L : ℝ) / (w : ℝ) := by
  1317. rw [le_div_iff₀ (by exact_mod_cast (show 0 < w by omega) : (0 : ℝ) < (w : ℝ))]
  1318. exact_mod_cast Nat.div_mul_le_self L w
  1319. have hmul_div : ((w * (L / w) : ℕ) : ℝ) ≤ (L : ℝ) := by
  1320. exact_mod_cast Nat.mul_div_le L w
  1321. have hτ_eq : (τ_step : ℝ) =
  1322. ((2 ^ w + 4 : ℕ) : ℝ) + ((w * (L / w) : ℕ) : ℝ) + ((L / w : ℕ) : ℝ) := by
  1323. dsimp [τ_step, L]
  1324. push_cast
  1325. ring
  1326. rw [hτ_eq]
  1327. linarith
  1328. have hw_pos : (0 : ℝ) < (w : ℝ) := by exact_mod_cast (show 0 < w by omega)
  1329. have h1_over_w : (1 : ℝ) / (w : ℝ) < ε / 3 := by
  1330. rw [div_lt_div_iff₀ hw_pos (by norm_num : (0 : ℝ) < 3)]
  1331. have h := (div_lt_iff₀ hε).mp hw_gt
  1332. linarith
  1333. have hL_gt_M : ((2 ^ w + 6 : ℕ) : ℝ) * (3 / ε) < (L : ℝ) := by
  1334. have hLM : (M : ℝ) ≤ (L : ℝ) := by exact_mod_cast hL_ge
  1335. linarith
  1336. have hC_small : ((2 ^ w + 5 : ℕ) : ℝ) < (ε / 3) * (L : ℝ) := by
  1337. have hdiv : ((2 ^ w + 6 : ℕ) : ℝ) < (L : ℝ) / (3 / ε) :=
  1338. (lt_div_iff₀ (by positivity : (0 : ℝ) < 3 / ε)).mpr hL_gt_M
  1339. have h1 : ((2 ^ w + 5 : ℕ) : ℝ) < ((2 ^ w + 6 : ℕ) : ℝ) := by push_cast; linarith
  1340. have h2 : (L : ℝ) / (3 / ε) = (ε / 3) * (L : ℝ) := by field_simp
  1341. linarith
  1342. have hLw_small : (L : ℝ) / (w : ℝ) < (ε / 3) * (L : ℝ) := by
  1343. calc
  1344. (L : ℝ) / (w : ℝ) = ((1 : ℝ) / (w : ℝ)) * (L : ℝ) := by ring
  1345. _ < (ε / 3) * (L : ℝ) := mul_lt_mul_of_pos_right h1_over_w hL_pos
  1346. have hkey : (1 - ε) * (τ_step : ℝ) < (L : ℝ) - 1 := by
  1347. by_cases hε1 : 1 ≤ ε
  1348. · have hnonpos : (1 - ε) * (τ_step : ℝ) ≤ 0 :=
  1349. mul_nonpos_of_nonpos_of_nonneg (by linarith) hτ_pos.le
  1350. have hL2 : (1 : ℝ) < (L : ℝ) := by exact_mod_cast (show 1 < L by omega)
  1351. linarith
  1352. · have h1mε : 0 < 1 - ε := by linarith
  1353. have h2w5 : ((2 ^ w + 4 : ℕ) : ℝ) + 1 = ((2 ^ w + 5 : ℕ) : ℝ) := by push_cast; ring
  1354. have hτ_lt : (τ_step : ℝ) < (1 + 2 * (ε / 3)) * (L : ℝ) - 1 := by
  1355. linarith
  1356. have hprod : (1 - ε) * (τ_step : ℝ) ≤ (1 - ε) * ((1 + 2 * (ε / 3)) * (L : ℝ) - 1) :=
  1357. mul_le_mul_of_nonneg_left hτ_lt.le h1mε.le
  1358. nlinarith [sq_nonneg ε]
  1359. rw [lt_div_iff₀ hτ_pos]
  1360. linarith
  1361. · intro k _
  1362. exact tau_padic_window_slp p w k hp2 hw1
  1363. end Research.PvsNP.Tau
  1364. end