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

Research/PvsNP/Tau/WronskianPowerElimination.lean

661 lines12 declarationsno sorry
  1. module
  2. public import Research.PvsNP.Tau.TauConjecture
  3. public import Mathlib.Analysis.Calculus.Deriv.Polynomial
  4. public import Mathlib.Analysis.Calculus.Deriv.Inv
  5. public import Mathlib.Analysis.Calculus.LocalExtr.Rolle
  6. public import Mathlib.Analysis.Calculus.MeanValue
  7. @[expose] public section
  8. namespace Research.PvsNP.Tau
  9. /-!
  10. # Exact 1-Step Wronskian Power-Elimination & Width-1 Moonshot A over `ℝ`
  11. This module formalizes two unconditional real-root upper bounds established during the
  12. Moonshot A investigation:
  13. 1. **Exact 1-Step Wronskian Power-Elimination (`real_roots_pow_add_le`, `int_roots_pow_add_le`):**
  14. For any `u, v : Polynomial ℝ`, exponents `M, N ≥ 1`, and sign `s ∈ {-1, 1}` with
  15. `f := u ^ M + C s * v ^ N ≠ 0`:
  16. `f.roots.toFinset.card ≤ 2 * (u.natDegree + v.natDegree)`,
  17. completely independent of `M` and `N`.
  18. Over `ℤ[X]`, `intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree)`.
  19. 2. **1-Addition Block Preimage Bound (`one_add_block_preimage_le_six`) & Width-1 Composition
  20. Bound (`real_roots_comp_le_of_preimage_bound`):**
  21. Every univariate polynomial of the form `Q(y) = C c0 * X ^ p * (X ^ q + C c) ^ r` (`q ≥ 1`)
  22. satisfies `(Q - C t).roots.toFinset.card ≤ 6` whenever `Q - C t ≠ 0`, yielding the
  23. unconditional exponential-base bound for width-1 compositions of 1-addition blocks.
  24. -/
  25. open Polynomial
  26. /-! ## 1. Helper Lemmas on Real Roots and Rolle's Theorem -/
  27. /-- A polynomial of degree `≤ d` has at most `d` distinct real roots. -/
  28. private lemma card_toFinset_roots_le_natDegree (f : Polynomial ℝ) :
  29. f.roots.toFinset.card ≤ f.natDegree :=
  30. (Multiset.toFinset_card_le f.roots).trans (Polynomial.card_roots' f)
  31. /-- If a polynomial `f : Polynomial ℝ` vanishes on a nonempty open interval `(a, b)`,
  32. then `f = 0`. -/
  33. private lemma poly_eq_zero_of_eq_zero_on_Ioo (f : Polynomial ℝ) {a b : ℝ} (hab : a < b)
  34. (hvan : ∀ x ∈ Set.Ioo a b, f.eval x = 0) : f = 0 := by
  35. by_contra hne
  36. let n := f.natDegree + 1
  37. let pts : Finset ℝ :=
  38. (Finset.range n).image (fun k : ℕ => a + (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ))
  39. have hinj : Set.InjOn (fun k : ℕ => a + (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ))
  40. (Finset.range n) := by
  41. intro i _ j _ hij
  42. have hba : (0 : ℝ) < b - a := sub_pos.mpr hab
  43. have hn : (0 : ℝ) < (n + 1 : ℝ) := by positivity
  44. have h1 : ((i + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) = ((j + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) := by
  45. linarith
  46. have h2 : (i + 1 : ℝ) * (b - a) = (j + 1 : ℝ) * (b - a) := (div_left_inj₀ (ne_of_gt hn)).mp h1
  47. have h3 : (i + 1 : ℝ) = (j + 1 : ℝ) := mul_right_cancel₀ (ne_of_gt hba) h2
  48. exact_mod_cast (by linarith : (i : ℝ) = (j : ℝ))
  49. have hcard : pts.card = n := by
  50. rw [Finset.card_image_of_injOn hinj, Finset.card_range]
  51. have hsub : pts ⊆ f.roots.toFinset := by
  52. intro x hx
  53. rcases Finset.mem_image.mp hx with ⟨k, hk, rfl⟩
  54. rw [Multiset.mem_toFinset, Polynomial.mem_roots hne, Polynomial.IsRoot.def]
  55. apply hvan
  56. have hk_lt : k < n := Finset.mem_range.mp hk
  57. have hba : (0 : ℝ) < b - a := sub_pos.mpr hab
  58. have hn : (0 : ℝ) < (n + 1 : ℝ) := by positivity
  59. constructor
  60. · have : (0 : ℝ) < (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) := by positivity
  61. linarith
  62. · have hk1 : (k + 1 : ℝ) < (n + 1 : ℝ) := by exact_mod_cast Nat.succ_lt_succ hk_lt
  63. have : (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) < b - a := by
  64. rw [div_lt_iff₀ hn]
  65. nlinarith
  66. linarith
  67. have hle := Finset.card_le_card hsub
  68. have hdeg := card_toFinset_roots_le_natDegree f
  69. omega
  70. /-- Every real polynomial defines a continuous function `ℝ → ℝ`. -/
  71. private lemma poly_continuous (f : Polynomial ℝ) : Continuous (fun x => f.eval x) :=
  72. continuous_iff_continuousAt.mpr fun x => (f.hasDerivAt x).continuousAt
  73. /-- Rolle's theorem for a polynomial `f : Polynomial ℝ` between two roots `a < b`. -/
  74. private lemma exists_deriv_root_between {f : Polynomial ℝ} {a b : ℝ} (hab : a < b)
  75. (ha : f.eval a = 0) (hb : f.eval b = 0) :
  76. ∃ c ∈ Set.Ioo a b, f.derivative.eval c = 0 := by
  77. have hcont : ContinuousOn (fun x => f.eval x) (Set.Icc a b) :=
  78. (poly_continuous f).continuousOn
  79. have heq : f.eval a = f.eval b := by rw [ha, hb]
  80. obtain ⟨c, hc, hderiv⟩ := exists_deriv_eq_zero hab hcont heq
  81. refine ⟨c, hc, ?_⟩
  82. rwa [Polynomial.deriv] at hderiv
  83. /-- General Rolle counting on a finite set `S : Finset ℝ`: if between every consecutive pair
  84. `a < b` of `S` there exists a point `c ∈ T` with `a < c < b`, then `S.card ≤ T.card + 1`. -/
  85. private lemma card_le_card_add_one_of_between {S T : Finset ℝ}
  86. (hbetween : ∀ a ∈ S, ∀ b ∈ S, a < b → (∀ x ∈ S, ¬ (a < x ∧ x < b)) →
  87. ∃ c ∈ T, a < c ∧ c < b) :
  88. S.card ≤ T.card + 1 := by
  89. by_cases h0 : S.card = 0
  90. · omega
  91. let e : Fin S.card ↪o ℝ := S.orderEmbOfFin rfl
  92. have hchoice : ∀ i : Fin (S.card - 1),
  93. ∃ c ∈ T, e ⟨i.val, by omega⟩ < c ∧ c < e ⟨i.val + 1, by omega⟩ := by
  94. intro i
  95. apply hbetween (e ⟨i.val, by omega⟩) (Finset.orderEmbOfFin_mem S rfl _)
  96. (e ⟨i.val + 1, by omega⟩) (Finset.orderEmbOfFin_mem S rfl _)
  97. · exact e.strictMono (by simp [Fin.lt_def])
  98. · intro x hx ⟨h1, h2⟩
  99. have hx_rng : x ∈ Set.range e := by
  100. rw [Finset.range_orderEmbOfFin]
  101. exact hx
  102. rcases hx_rng with ⟨j, hj⟩
  103. have hj1 : i.val < j.val := by
  104. by_contra hle
  105. have : e j ≤ e ⟨i.val, by omega⟩ := e.monotone (by simp [Fin.le_def]; omega)
  106. linarith
  107. have hj2 : j.val < i.val + 1 := by
  108. by_contra hle
  109. have : e ⟨i.val + 1, by omega⟩ ≤ e j := e.monotone (by simp [Fin.le_def]; omega)
  110. linarith
  111. omega
  112. choose g hgT hg1 hg2 using hchoice
  113. have hinj : Function.Injective g := by
  114. intro i j hij
  115. by_contra hne
  116. rcases lt_or_gt_of_ne hne with hlt | hgt
  117. · have hle : e ⟨i.val + 1, by omega⟩ ≤ e ⟨j.val, by omega⟩ :=
  118. e.monotone (by simp [Fin.le_def]; exact hlt)
  119. have := hg2 i
  120. have := hg1 j
  121. linarith
  122. · have hle : e ⟨j.val + 1, by omega⟩ ≤ e ⟨i.val, by omega⟩ :=
  123. e.monotone (by simp [Fin.le_def]; exact hgt)
  124. have := hg2 j
  125. have := hg1 i
  126. linarith
  127. have hle_card : Fintype.card (Fin (S.card - 1)) ≤ T.card := by
  128. have hsub : Finset.univ.image g ⊆ T := by
  129. intro x hx
  130. rcases Finset.mem_image.mp hx with ⟨i, _, rfl⟩
  131. exact hgT i
  132. calc Fintype.card (Fin (S.card - 1))
  133. = (Finset.univ : Finset (Fin (S.card - 1))).card := rfl
  134. _ = (Finset.univ.image g).card := (Finset.card_image_of_injective _ hinj).symm
  135. _ ≤ T.card := Finset.card_le_card hsub
  136. simp only [Fintype.card_fin] at hle_card
  137. omega
  138. /-- Classical Rolle bound for real polynomials: if `f ≠ 0` and `f.derivative ≠ 0`, then
  139. `f.roots.toFinset.card ≤ f.derivative.roots.toFinset.card + 1`. -/
  140. theorem poly_real_roots_le_deriv_add_one {f : Polynomial ℝ}
  141. (hf : f ≠ 0) (hdf : f.derivative ≠ 0) :
  142. f.roots.toFinset.card ≤ f.derivative.roots.toFinset.card + 1 := by
  143. apply card_le_card_add_one_of_between
  144. intro a ha b hb hab _
  145. rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at ha hb
  146. obtain ⟨c, ⟨hca, hcb⟩, hc⟩ := exists_deriv_root_between hab ha hb
  147. exact ⟨c, Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hdf).mpr hc), hca, hcb⟩
  148. /-! ## 2. Exact 1-Step Wronskian Power-Elimination Theorem -/
  149. /-- Derivative of `u(x)^M / v(x)^N` at a point where `v(x) ≠ 0`. -/
  150. private lemma hasDerivAt_pow_div_pow (u v : Polynomial ℝ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N)
  151. {x : ℝ} (hv : v.eval x ≠ 0) :
  152. HasDerivAt (fun t => (u.eval t) ^ M / (v.eval t) ^ N)
  153. (((u.eval x) ^ (M - 1) * ((M : ℝ) * u.derivative.eval x * v.eval x -
  154. (N : ℝ) * u.eval x * v.derivative.eval x)) / (v.eval x) ^ (N + 1)) x := by
  155. have hu : HasDerivAt (fun t => u.eval t) (u.derivative.eval x) x := u.hasDerivAt x
  156. have hv_d : HasDerivAt (fun t => v.eval t) (v.derivative.eval x) x := v.hasDerivAt x
  157. have huM : HasDerivAt (fun t => (u.eval t) ^ M)
  158. ((M : ℝ) * (u.eval x) ^ (M - 1) * u.derivative.eval x) x := HasDerivAt.pow hu M
  159. have hvN : HasDerivAt (fun t => (v.eval t) ^ N)
  160. ((N : ℝ) * (v.eval x) ^ (N - 1) * v.derivative.eval x) x := HasDerivAt.pow hv_d N
  161. have hvN_ne : (v.eval x) ^ N ≠ 0 := pow_ne_zero N hv
  162. have hdiv := HasDerivAt.div huM hvN hvN_ne
  163. convert hdiv using 1
  164. have hM' : u.eval x ^ M = u.eval x ^ (M - 1) * u.eval x := by
  165. conv_lhs => rw [← Nat.sub_add_cancel hM, pow_succ]
  166. have hN' : v.eval x ^ N = v.eval x ^ (N - 1) * v.eval x := by
  167. conv_lhs => rw [← Nat.sub_add_cancel hN, pow_succ]
  168. have hN2 : (v.eval x ^ N) ^ 2 = v.eval x ^ (N - 1) * v.eval x ^ (N + 1) := by
  169. rw [sq, ← pow_add, ← pow_add]
  170. congr 1; omega
  171. have hv_pow_ne : v.eval x ^ (N - 1) ≠ 0 := pow_ne_zero _ hv
  172. have hv_pow1_ne : v.eval x ^ (N + 1) ≠ 0 := pow_ne_zero _ hv
  173. rw [hN2]
  174. field_simp [hv, hv_pow_ne, hv_pow1_ne]
  175. rw [hM', hN']
  176. ring
  177. /-- **Exact 1-Step Wronskian Power-Elimination Theorem over `ℝ`:**
  178. For any `u, v : Polynomial ℝ`, `M, N ≥ 1`, and `s ∈ {-1, 1}` with `f := u ^ M + C s * v ^ N ≠ 0`,
  179. `f` has at most `2 * (u.natDegree + v.natDegree)` distinct real roots — completely independent
  180. of `M` and `N`. -/
  181. theorem real_roots_pow_add_le (u v : Polynomial ℝ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N)
  182. (s : ℝ) (hs : s = 1 ∨ s = -1)
  183. (hf : u ^ M + C s * v ^ N ≠ 0) :
  184. (u ^ M + C s * v ^ N).roots.toFinset.card ≤ 2 * (u.natDegree + v.natDegree) := by
  185. set f : Polynomial ℝ := u ^ M + C s * v ^ N
  186. have hs0 : s ≠ 0 := by rcases hs with rfl | rfl <;> norm_num
  187. by_cases hu0 : u = 0
  188. · subst hu0
  189. have hM0 : M ≠ 0 := by omega
  190. have hfeq : f = C s * v ^ N := by simp [f, zero_pow hM0]
  191. have hv0 : v ≠ 0 := by intro hv; apply hf; simp [hfeq, hv, zero_pow (by omega : N ≠ 0)]
  192. have hsub : f.roots.toFinset ⊆ v.roots.toFinset := by
  193. intro x hx
  194. rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hx
  195. rw [Multiset.mem_toFinset, Polynomial.mem_roots hv0, Polynomial.IsRoot.def]
  196. simp [hfeq, hs0] at hx
  197. exact hx.1
  198. have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree v)
  199. simp; omega
  200. by_cases hv0 : v = 0
  201. · subst hv0
  202. have hN0 : N ≠ 0 := by omega
  203. have hfeq : f = u ^ M := by simp [f, zero_pow hN0]
  204. have hsub : f.roots.toFinset ⊆ u.roots.toFinset := by
  205. intro x hx
  206. rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hx
  207. rw [Multiset.mem_toFinset, Polynomial.mem_roots hu0, Polynomial.IsRoot.def]
  208. simp [hfeq] at hx
  209. exact hx.1
  210. have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree u)
  211. simp; omega
  212. by_cases hdeg0 : u.natDegree + v.natDegree = 0
  213. · have hu_c : u.natDegree = 0 := by omega
  214. have hv_c : v.natDegree = 0 := by omega
  215. have hf_deg : f.natDegree = 0 := by
  216. have h1 : (u ^ M).natDegree = 0 := by rw [natDegree_pow, hu_c, mul_zero]
  217. have h2 : (C s * v ^ N).natDegree ≤ 0 := by
  218. calc (C s * v ^ N).natDegree ≤ (C s).natDegree + (v ^ N).natDegree := natDegree_mul_le
  219. _ = 0 := by rw [natDegree_C, natDegree_pow, hv_c, mul_zero, zero_add]
  220. have h3 : f.natDegree ≤ max (u ^ M).natDegree (C s * v ^ N).natDegree :=
  221. natDegree_add_le (u ^ M) (C s * v ^ N)
  222. omega
  223. have hcard := card_toFinset_roots_le_natDegree f
  224. omega
  225. -- Now u ≠ 0, v ≠ 0, and u.natDegree + v.natDegree ≥ 1.
  226. set S := f.roots.toFinset
  227. set Ru := u.roots.toFinset
  228. set Rv := v.roots.toFinset
  229. set U := Ru ∪ Rv
  230. set S0 := S ∩ U
  231. set S1 := S \ U
  232. have hS_card : S.card = S0.card + S1.card := by
  233. exact (Finset.card_inter_add_card_sdiff S U).symm
  234. -- Every root in S0 = S ∩ (Ru ∪ Rv) is a root of BOTH u and v!
  235. have hS0_sub : S0 ⊆ Ru ∩ Rv := by
  236. intro x hx
  237. have hxS : x ∈ S := (Finset.mem_inter.mp hx).1
  238. have hxU : x ∈ U := (Finset.mem_inter.mp hx).2
  239. have hfx : u.eval x ^ M + s * v.eval x ^ N = 0 := by
  240. have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hxS)
  241. rw [Polynomial.IsRoot.def] at this
  242. simpa [f] using this
  243. rcases Finset.mem_union.mp hxU with hxu | hxv
  244. · have hu_x : u.eval x = 0 :=
  245. Polynomial.IsRoot.def.mp ((Polynomial.mem_roots hu0).mp (Multiset.mem_toFinset.mp hxu))
  246. have hv_x : v.eval x = 0 := by
  247. rw [hu_x, zero_pow (by omega : M ≠ 0), zero_add] at hfx
  248. have hvn : v.eval x ^ N = 0 := (mul_eq_zero.mp hfx).resolve_left hs0
  249. exact eq_zero_of_pow_eq_zero hvn
  250. exact Finset.mem_inter.mpr
  251. ⟨hxu, Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hv0).mpr hv_x)⟩
  252. · have hv_x : v.eval x = 0 :=
  253. Polynomial.IsRoot.def.mp ((Polynomial.mem_roots hv0).mp (Multiset.mem_toFinset.mp hxv))
  254. have hu_x : u.eval x = 0 := by
  255. rw [hv_x, zero_pow (by omega : N ≠ 0), mul_zero, add_zero] at hfx
  256. exact eq_zero_of_pow_eq_zero hfx
  257. exact Finset.mem_inter.mpr
  258. ⟨Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hu0).mpr hu_x), hxv⟩
  259. -- Hence U.card + S0.card ≤ deg(u) + deg(v)!
  260. have hU_S0 : U.card + S0.card ≤ u.natDegree + v.natDegree := by
  261. have h1 : S0.card ≤ (Ru ∩ Rv).card := Finset.card_le_card hS0_sub
  262. have h2 : U.card + (Ru ∩ Rv).card = Ru.card + Rv.card :=
  263. Finset.card_union_add_card_inter Ru Rv
  264. have h3 : Ru.card ≤ u.natDegree := card_toFinset_roots_le_natDegree u
  265. have h4 : Rv.card ≤ v.natDegree := card_toFinset_roots_le_natDegree v
  266. omega
  267. -- Define the Wronskian W = M * u' * v - N * u * v'
  268. set W : Polynomial ℝ := C (M : ℝ) * u.derivative * v - C (N : ℝ) * u * v.derivative
  269. have hW_deg : W.natDegree ≤ u.natDegree + v.natDegree - 1 := by
  270. have h1 : (C (M : ℝ) * u.derivative * v).natDegree ≤ u.natDegree + v.natDegree - 1 := by
  271. by_cases hdu : u.derivative = 0
  272. · simp [hdu]
  273. · have hdu_pos : 1 ≤ u.natDegree := by
  274. by_contra h
  275. have : u.natDegree = 0 := by omega
  276. exact hdu (natDegree_eq_zero.mp this |>.elim fun c hc => by rw [← hc, derivative_C])
  277. calc (C (M : ℝ) * u.derivative * v).natDegree
  278. ≤ (C (M : ℝ) * u.derivative).natDegree + v.natDegree := natDegree_mul_le
  279. _ ≤ ((C (M : ℝ)).natDegree + u.derivative.natDegree) + v.natDegree :=
  280. Nat.add_le_add_right natDegree_mul_le _
  281. _ ≤ (0 + (u.natDegree - 1)) + v.natDegree := by
  282. rw [natDegree_C]
  283. exact Nat.add_le_add_right (Nat.add_le_add_left (natDegree_derivative_le u) _) _
  284. _ = u.natDegree + v.natDegree - 1 := by omega
  285. have h2 : (C (N : ℝ) * u * v.derivative).natDegree ≤ u.natDegree + v.natDegree - 1 := by
  286. by_cases hdv : v.derivative = 0
  287. · simp [hdv]
  288. · have hdv_pos : 1 ≤ v.natDegree := by
  289. by_contra h
  290. have : v.natDegree = 0 := by omega
  291. exact hdv (natDegree_eq_zero.mp this |>.elim fun c hc => by rw [← hc, derivative_C])
  292. calc (C (N : ℝ) * u * v.derivative).natDegree
  293. ≤ (C (N : ℝ) * u).natDegree + v.derivative.natDegree := natDegree_mul_le
  294. _ ≤ ((C (N : ℝ)).natDegree + u.natDegree) + (v.natDegree - 1) :=
  295. Nat.add_le_add natDegree_mul_le (natDegree_derivative_le v)
  296. _ = u.natDegree + v.natDegree - 1 := by rw [natDegree_C]; omega
  297. exact le_trans (natDegree_sub_le _ _) (max_le h1 h2)
  298. -- Key Rolle claim on S1 using T = U ∪ W.roots.toFinset:
  299. have hS1_bound : S1.card ≤ (U ∪ W.roots.toFinset).card + 1 := by
  300. apply card_le_card_add_one_of_between
  301. intro a ha b hb hab _
  302. by_cases huv_in : ∃ c ∈ U, a < c ∧ c < b
  303. · obtain ⟨c, hcU, hca, hcb⟩ := huv_in
  304. exact ⟨c, Finset.mem_union_left _ hcU, hca, hcb⟩
  305. · have haS : a ∈ S := (Finset.mem_sdiff.mp ha).1
  306. have haU : a ∉ U := (Finset.mem_sdiff.mp ha).2
  307. have hbS : b ∈ S := (Finset.mem_sdiff.mp hb).1
  308. have hbU : b ∉ U := (Finset.mem_sdiff.mp hb).2
  309. have hno_uv : ∀ x ∈ Set.Icc a b, u.eval x ≠ 0 ∧ v.eval x ≠ 0 := by
  310. intro x ⟨hax, hxb⟩
  311. have hx_notU : x ∉ U := by
  312. intro hxU
  313. rcases eq_or_lt_of_le hax with rfl | hax'
  314. · exact haU hxU
  315. · rcases eq_or_lt_of_le hxb with rfl | hxb'
  316. · exact hbU hxU
  317. · exact huv_in ⟨x, hxU, hax', hxb'⟩
  318. constructor
  319. · intro hux
  320. exact hx_notU (Finset.mem_union_left _ (Multiset.mem_toFinset.mpr
  321. ((Polynomial.mem_roots hu0).mpr hux)))
  322. · intro hvx
  323. exact hx_notU (Finset.mem_union_right _ (Multiset.mem_toFinset.mpr
  324. ((Polynomial.mem_roots hv0).mpr hvx)))
  325. let g : ℝ → ℝ := fun t => (u.eval t) ^ M / (v.eval t) ^ N
  326. have hga : g a = -s := by
  327. have hfa : u.eval a ^ M + s * v.eval a ^ N = 0 := by
  328. have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp haS)
  329. rw [Polynomial.IsRoot.def] at this
  330. simpa [f] using this
  331. have hva : v.eval a ^ N ≠ 0 :=
  332. pow_ne_zero N (hno_uv a (Set.left_mem_Icc.mpr (le_of_lt hab))).2
  333. show u.eval a ^ M / v.eval a ^ N = -s
  334. rw [div_eq_iff hva]; linarith
  335. have hgb : g b = -s := by
  336. have hfb : u.eval b ^ M + s * v.eval b ^ N = 0 := by
  337. have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hbS)
  338. rw [Polynomial.IsRoot.def] at this
  339. simpa [f] using this
  340. have hvb : v.eval b ^ N ≠ 0 :=
  341. pow_ne_zero N (hno_uv b (Set.right_mem_Icc.mpr (le_of_lt hab))).2
  342. show u.eval b ^ M / v.eval b ^ N = -s
  343. rw [div_eq_iff hvb]; linarith
  344. have hcont : ContinuousOn g (Set.Icc a b) := by
  345. apply ContinuousOn.div
  346. · exact ((poly_continuous u).pow M).continuousOn
  347. · exact ((poly_continuous v).pow N).continuousOn
  348. · intro x hx; exact pow_ne_zero N (hno_uv x hx).2
  349. -- Rule out W = 0 via MVT: if W = 0 then g' = 0 on (a, b), so g = -s on (a, b), forcing f = 0
  350. have hW_ne : W ≠ 0 := by
  351. intro hW0
  352. have hconst : ∀ x ∈ Set.Ioo a b, g x = g a := by
  353. intro x ⟨hax, hxb⟩
  354. have hxa : x - a ≠ 0 := ne_of_gt (sub_pos.mpr hax)
  355. let m : ℝ := (g x - g a) / (x - a)
  356. let h : ℝ → ℝ := fun t => g t - g a - m * (t - a)
  357. have hcont_h : ContinuousOn h (Set.Icc a x) := by
  358. have h1 : ContinuousOn g (Set.Icc a x) :=
  359. hcont.mono (Set.Icc_subset_Icc_right (le_of_lt hxb))
  360. exact (h1.sub continuousOn_const).sub
  361. (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
  362. have hha : h a = 0 := by simp [h]
  363. have hhx : h x = 0 := by
  364. simp only [h, m]
  365. rw [div_mul_cancel₀ _ hxa, sub_self]
  366. obtain ⟨c, ⟨hac, hcx⟩, hderiv_h⟩ := exists_deriv_eq_zero hax hcont_h (by rw [hha, hhx])
  367. have hcIcc : c ∈ Set.Icc a b := ⟨le_of_lt hac, le_of_lt (lt_trans hcx hxb)⟩
  368. have hhd := hasDerivAt_pow_div_pow u v M N hM hN (hno_uv c hcIcc).2
  369. have hhd_lin : HasDerivAt (fun t : ℝ => m * (t - a)) m c := by
  370. simpa using ((hasDerivAt_id c).sub_const a).const_mul m
  371. have hhd_h : HasDerivAt h
  372. (((u.eval c) ^ (M - 1) * ((M : ℝ) * u.derivative.eval c * v.eval c -
  373. (N : ℝ) * u.eval c * v.derivative.eval c)) / (v.eval c) ^ (N + 1) - m) c :=
  374. (hhd.sub_const (g a)).sub hhd_lin
  375. have hWc : W.eval c = 0 := by rw [hW0]; simp
  376. have hWc' : (M : ℝ) * u.derivative.eval c * v.eval c -
  377. (N : ℝ) * u.eval c * v.derivative.eval c = 0 := by
  378. simpa [W] using hWc
  379. rw [hhd_h.deriv, hWc', mul_zero, zero_div, zero_sub, neg_eq_zero] at hderiv_h
  380. have hgx_sub : g x - g a = 0 := (div_eq_zero_iff.mp hderiv_h).resolve_right hxa
  381. linarith
  382. have hf0 : f = 0 := by
  383. apply poly_eq_zero_of_eq_zero_on_Ioo f hab
  384. intro x hx
  385. have hgx : g x = -s := by rw [hconst x hx, hga]
  386. have hvx : v.eval x ^ N ≠ 0 := pow_ne_zero N (hno_uv x (Set.Ioo_subset_Icc_self hx)).2
  387. have hux : u.eval x ^ M = -s * v.eval x ^ N := (div_eq_iff hvx).mp hgx
  388. show (u ^ M + C s * v ^ N).eval x = 0
  389. simp [hux]
  390. exact hf hf0
  391. obtain ⟨c, ⟨hca, hcb⟩, hgc⟩ := exists_deriv_eq_zero hab hcont (by rw [hga, hgb])
  392. have hcIcc : c ∈ Set.Icc a b := ⟨le_of_lt hca, le_of_lt hcb⟩
  393. have hhd := hasDerivAt_pow_div_pow u v M N hM hN (hno_uv c hcIcc).2
  394. rw [hhd.deriv] at hgc
  395. have hvc_ne : (v.eval c) ^ (N + 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).2
  396. have huc_ne : (u.eval c) ^ (M - 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).1
  397. have hnum : (u.eval c) ^ (M - 1) * ((M : ℝ) * u.derivative.eval c * v.eval c -
  398. (N : ℝ) * u.eval c * v.derivative.eval c) = 0 :=
  399. (div_eq_zero_iff.mp hgc).resolve_right hvc_ne
  400. have hWc_eq : (M : ℝ) * u.derivative.eval c * v.eval c -
  401. (N : ℝ) * u.eval c * v.derivative.eval c = 0 :=
  402. (mul_eq_zero.mp hnum).resolve_left huc_ne
  403. have hWc : W.eval c = 0 := by simpa [W] using hWc_eq
  404. exact ⟨c, Finset.mem_union_right _ (Multiset.mem_toFinset.mpr
  405. ((Polynomial.mem_roots hW_ne).mpr hWc)), hca, hcb⟩
  406. have hunion : (U ∪ W.roots.toFinset).card ≤ U.card + W.roots.toFinset.card :=
  407. Finset.card_union_le U W.roots.toFinset
  408. have hW_card : W.roots.toFinset.card ≤ u.natDegree + v.natDegree - 1 :=
  409. (card_toFinset_roots_le_natDegree W).trans hW_deg
  410. omega
  411. /-- **Integer-Root Specialization (`int_roots_pow_add_le`):**
  412. For any `u, v : Polynomial ℤ`, `M, N ≥ 1`, and `s ∈ {-1, 1}` with `u ^ M + C s * v ^ N ≠ 0`,
  413. `intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree)`. -/
  414. theorem int_roots_pow_add_le (u v : Polynomial ℤ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N)
  415. (s : ℤ) (hs : s = 1 ∨ s = -1)
  416. (hf : u ^ M + C s * v ^ N ≠ 0) :
  417. intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree) := by
  418. let φ : ℤ →+* ℝ := Int.castRingHom ℝ
  419. have hφ_inj : Function.Injective φ := Int.cast_injective
  420. set f : Polynomial ℤ := u ^ M + C s * v ^ N
  421. set fR : Polynomial ℝ := f.map φ
  422. have hfR_eq : fR = (u.map φ) ^ M + C (s : ℝ) * (v.map φ) ^ N := by
  423. simp [fR, f, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow, φ]
  424. have hfR_ne : fR ≠ 0 := by
  425. intro h0
  426. apply hf
  427. exact Polynomial.map_injective φ hφ_inj (by simpa [fR] using h0)
  428. have hsub : f.roots.toFinset.image (fun z : ℤ => (z : ℝ)) ⊆ fR.roots.toFinset := by
  429. intro x hx
  430. rcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩
  431. rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hz
  432. rw [Multiset.mem_toFinset, Polynomial.mem_roots hfR_ne, Polynomial.IsRoot.def]
  433. show (f.map φ).eval (φ z) = 0
  434. rw [Polynomial.eval_map, Polynomial.eval₂_hom, hz, map_zero]
  435. have hcard_int : intRootCount f ≤ fR.roots.toFinset.card := by
  436. unfold intRootCount intRootSet
  437. calc f.roots.toFinset.card
  438. = (f.roots.toFinset.image (fun z : ℤ => (z : ℝ))).card :=
  439. (Finset.card_image_of_injective _ Int.cast_injective).symm
  440. _ ≤ fR.roots.toFinset.card := Finset.card_le_card hsub
  441. have hsR : (s : ℝ) = 1 ∨ (s : ℝ) = -1 := by
  442. rcases hs with rfl | rfl
  443. · left; norm_num
  444. · right; norm_num
  445. have hreal := real_roots_pow_add_le (u.map φ) (v.map φ) M N hM hN (s : ℝ) hsR
  446. (by rwa [← hfR_eq])
  447. rw [← hfR_eq] at hreal
  448. have hdu : (u.map φ).natDegree ≤ u.natDegree := natDegree_map_le
  449. have hdv : (v.map φ).natDegree ≤ v.natDegree := natDegree_map_le
  450. omega
  451. /-! ## 3. Exact 1-Addition Univariate Block Bound & Width-1 Composition Bound over `ℝ` -/
  452. /-- A binomial `X ^ q - C a` (`q ≥ 1`) has at most `2` distinct real roots. -/
  453. private lemma real_roots_X_pow_sub_C_le_two (q : ℕ) (hq : 1 ≤ q) (a : ℝ) :
  454. (X ^ q - C a : Polynomial ℝ).roots.toFinset.card ≤ 2 := by
  455. have hne : (X ^ q - C a : Polynomial ℝ) ≠ 0 := by
  456. intro h0
  457. have hdeg := congrArg Polynomial.natDegree h0
  458. rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg
  459. · simp at hdeg; omega
  460. · simp; omega
  461. have hderiv : (X ^ q - C a : Polynomial ℝ).derivative = C (q : ℝ) * X ^ (q - 1) := by
  462. simp [derivative_pow, derivative_C]
  463. have hd_ne : (X ^ q - C a : Polynomial ℝ).derivative ≠ 0 := by
  464. rw [hderiv]
  465. apply mul_ne_zero
  466. · exact Polynomial.C_ne_zero.mpr (by exact_mod_cast (by omega : q ≠ 0))
  467. · exact pow_ne_zero _ Polynomial.X_ne_zero
  468. have hrolle := poly_real_roots_le_deriv_add_one hne hd_ne
  469. have hd_roots : (X ^ q - C a : Polynomial ℝ).derivative.roots.toFinset ⊆ {0} := by
  470. intro x hx
  471. rw [Multiset.mem_toFinset, Polynomial.mem_roots hd_ne, Polynomial.IsRoot.def, hderiv] at hx
  472. simp only [eval_mul, eval_C, eval_pow, eval_X] at hx
  473. have hq0 : (q : ℝ) ≠ 0 := by exact_mod_cast (by omega : q ≠ 0)
  474. have hxp : x ^ (q - 1) = 0 := (mul_eq_zero.mp hx).resolve_left hq0
  475. exact Finset.mem_singleton.mpr (eq_zero_of_pow_eq_zero hxp)
  476. have hcard_d : (X ^ q - C a : Polynomial ℝ).derivative.roots.toFinset.card ≤ 1 :=
  477. (Finset.card_le_card hd_roots).trans (by simp)
  478. omega
  479. /-- **1-Addition Univariate Block Preimage Bound:**
  480. Every univariate polynomial `Q(y) = C c0 * X ^ p * (X ^ q + C c) ^ r` (`q ≥ 1`) has
  481. at most `6` distinct real solutions to `Q(y) = t` whenever `Q - C t ≠ 0`. -/
  482. theorem one_add_block_preimage_le_six (c0 c t : ℝ) (p q r : ℕ) (hq : 1 ≤ q)
  483. (hne : C c0 * X ^ p * (X ^ q + C c) ^ r - C t ≠ 0) :
  484. (C c0 * X ^ p * (X ^ q + C c) ^ r - C t).roots.toFinset.card ≤ 6 := by
  485. set f : Polynomial ℝ := C c0 * X ^ p * (X ^ q + C c) ^ r - C t
  486. by_cases hdf : f.derivative = 0
  487. · have hdeg : f.natDegree = 0 := by
  488. by_contra hpos
  489. have h1 : 1 ≤ f.natDegree := by omega
  490. have hcoeff : f.derivative.coeff (f.natDegree - 1) = (f.natDegree : ℝ) * f.leadingCoeff := by
  491. rw [coeff_derivative, Nat.sub_add_cancel h1]
  492. have hcast : ((f.natDegree - 1 : ℕ) : ℝ) + 1 = (f.natDegree : ℝ) := by
  493. exact_mod_cast Nat.sub_add_cancel h1
  494. rw [hcast, Polynomial.coeff_natDegree, mul_comm]
  495. rw [hdf, coeff_zero] at hcoeff
  496. have hlead : f.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hne
  497. have hnd : (f.natDegree : ℝ) ≠ 0 := by exact_mod_cast (by omega : f.natDegree ≠ 0)
  498. exact mul_ne_zero hnd hlead hcoeff.symm
  499. have := card_toFinset_roots_le_natDegree f
  500. omega
  501. have hrolle := poly_real_roots_le_deriv_add_one hne hdf
  502. have hc0 : c0 ≠ 0 := by
  503. intro h0; apply hdf; simp [f, h0, derivative_C]
  504. have hpqr : p + q * r ≠ 0 := by
  505. intro h0
  506. have hp0 : p = 0 := by omega
  507. have hr0 : r = 0 := by
  508. rcases Nat.mul_eq_zero.mp (by omega : q * r = 0) with hq0 | hr0
  509. · omega
  510. · exact hr0
  511. apply hdf; simp [f, hp0, hr0, derivative_C]
  512. set A : Polynomial ℝ := X ^ q - C (-c)
  513. set B : Polynomial ℝ := X ^ q - C (-(p : ℝ) * c / ((p + q * r : ℕ) : ℝ))
  514. have hA_ne : A ≠ 0 := by
  515. intro h0; have hdeg := congrArg Polynomial.natDegree h0
  516. rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg
  517. · simp at hdeg; omega
  518. · simp; omega
  519. have hB_ne : B ≠ 0 := by
  520. intro h0; have hdeg := congrArg Polynomial.natDegree h0
  521. rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg
  522. · simp at hdeg; omega
  523. · simp; omega
  524. have hsub :
  525. f.derivative.roots.toFinset ⊆ ({0} : Finset ℝ) ∪ A.roots.toFinset ∪ B.roots.toFinset := by
  526. intro x hx
  527. rw [Multiset.mem_toFinset, Polynomial.mem_roots hdf, Polynomial.IsRoot.def] at hx
  528. have hderiv_at : HasDerivAt (fun y : ℝ => c0 * y ^ p * (y ^ q + c) ^ r - t)
  529. (c0 * ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +
  530. x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))))) x := by
  531. have h1 : HasDerivAt (fun y : ℝ => y ^ p) ((p : ℝ) * x ^ (p - 1)) x := hasDerivAt_pow p x
  532. have h2 : HasDerivAt (fun y : ℝ => y ^ q + c) ((q : ℝ) * x ^ (q - 1)) x :=
  533. (hasDerivAt_pow q x).add_const c
  534. have h3 : HasDerivAt (fun y : ℝ => (y ^ q + c) ^ r)
  535. ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))) x := HasDerivAt.pow h2 r
  536. have h4 := (h1.mul h3).const_mul c0
  537. simpa [mul_assoc, mul_add, add_mul] using h4.sub_const t
  538. have hf_fn : (fun y : ℝ => f.eval y) = (fun y : ℝ => c0 * y ^ p * (y ^ q + c) ^ r - t) := by
  539. ext y; simp [f]
  540. have hval0 : c0 * ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +
  541. x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) = 0 := by
  542. have h1 : deriv (fun y => f.eval y) x = f.derivative.eval x := Polynomial.deriv f
  543. rw [hf_fn] at h1
  544. rw [hderiv_at.deriv] at h1
  545. linarith
  546. have hinner : (p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +
  547. x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))) = 0 :=
  548. (mul_eq_zero.mp hval0).resolve_left hc0
  549. by_cases hx0 : x = 0
  550. · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_singleton.mpr hx0))
  551. by_cases hxq : x ^ q + c = 0
  552. · apply Finset.mem_union_left _
  553. apply Finset.mem_union_right _
  554. rw [Multiset.mem_toFinset, Polynomial.mem_roots hA_ne, Polynomial.IsRoot.def]
  555. simp [A]; linarith
  556. have hmul : (x * (x ^ q + c)) *
  557. ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +
  558. x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) = 0 := by
  559. rw [hinner, mul_zero]
  560. have hterm1 : x * ((p : ℝ) * x ^ (p - 1)) = (p : ℝ) * x ^ p := by
  561. cases p with
  562. | zero => simp
  563. | succ p' => simp [pow_succ]; ring
  564. have hterm2 : (x ^ q + c) * ((r : ℝ) * (x ^ q + c) ^ (r - 1)) = (r : ℝ) * (x ^ q + c) ^ r := by
  565. cases r with
  566. | zero => simp
  567. | succ r' => simp [pow_succ]; ring
  568. have hterm3 : x * ((q : ℝ) * x ^ (q - 1)) = (q : ℝ) * x ^ q := by
  569. have : x * x ^ (q - 1) = x ^ q := by
  570. conv_rhs => rw [← Nat.sub_add_cancel hq, pow_succ, mul_comm]
  571. calc x * ((q : ℝ) * x ^ (q - 1)) = (q : ℝ) * (x * x ^ (q - 1)) := by ring
  572. _ = (q : ℝ) * x ^ q := by rw [this]
  573. have hfact : x ^ p * (x ^ q + c) ^ r *
  574. (((p + q * r : ℕ) : ℝ) * x ^ q + (p : ℝ) * c) = 0 := by
  575. have hrew : (x * (x ^ q + c)) *
  576. ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +
  577. x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) =
  578. (x ^ q + c) * (x * ((p : ℝ) * x ^ (p - 1))) * (x ^ q + c) ^ r +
  579. x ^ p * ((x ^ q + c) * ((r : ℝ) * (x ^ q + c) ^ (r - 1))) *
  580. (x * ((q : ℝ) * x ^ (q - 1))) := by
  581. ring
  582. rw [hrew, hterm1, hterm2, hterm3] at hmul
  583. push_cast
  584. linarith
  585. have hxp_ne : x ^ p ≠ 0 := pow_ne_zero p hx0
  586. have hxqr_ne : (x ^ q + c) ^ r ≠ 0 := pow_ne_zero r hxq
  587. have hlin : ((p + q * r : ℕ) : ℝ) * x ^ q + (p : ℝ) * c = 0 :=
  588. (mul_eq_zero.mp hfact).resolve_left (mul_ne_zero hxp_ne hxqr_ne)
  589. apply Finset.mem_union_right _
  590. rw [Multiset.mem_toFinset, Polynomial.mem_roots hB_ne, Polynomial.IsRoot.def]
  591. simp only [B, eval_sub, eval_pow, eval_X, eval_C]
  592. have hden : ((p + q * r : ℕ) : ℝ) ≠ 0 := by exact_mod_cast hpqr
  593. have : x ^ q = -(p : ℝ) * c / ((p + q * r : ℕ) : ℝ) := by
  594. rw [eq_div_iff hden]; linarith
  595. linarith
  596. have hcard_d : f.derivative.roots.toFinset.card ≤ 5 := by
  597. have h1 := Finset.card_le_card hsub
  598. have h2 := Finset.card_union_le (({0} : Finset ℝ) ∪ A.roots.toFinset) B.roots.toFinset
  599. have h3 := Finset.card_union_le ({0} : Finset ℝ) A.roots.toFinset
  600. have hA : A.roots.toFinset.card ≤ 2 := real_roots_X_pow_sub_C_le_two q hq (-c)
  601. have hB : B.roots.toFinset.card ≤ 2 :=
  602. real_roots_X_pow_sub_C_le_two q hq (-(p : ℝ) * c / ((p + q * r : ℕ) : ℝ))
  603. simp only [Finset.card_singleton] at h3
  604. omega
  605. omega
  606. /-- **Width-1 Composition Real-Root Counting Lemma:**
  607. If every level set `Q(x) = t` has at most `B` distinct real solutions, then for any `P ≠ 0`
  608. with `P.comp Q ≠ 0`, `(P.comp Q).roots.toFinset.card ≤ P.roots.toFinset.card * B`. -/
  609. theorem real_roots_comp_le_of_preimage_bound (P Q : Polynomial ℝ) (B : ℕ)
  610. (hP : P ≠ 0) (hPQ : P.comp Q ≠ 0)
  611. (hpre : ∀ t : ℝ, (Q - C t).roots.toFinset.card ≤ B) :
  612. (P.comp Q).roots.toFinset.card ≤ P.roots.toFinset.card * B := by
  613. have hsub : (P.comp Q).roots.toFinset ⊆
  614. P.roots.toFinset.biUnion (fun t => (Q - C t).roots.toFinset) := by
  615. intro x hx
  616. rw [Multiset.mem_toFinset, Polynomial.mem_roots hPQ, Polynomial.IsRoot.def, eval_comp] at hx
  617. refine Finset.mem_biUnion.mpr ⟨Q.eval x, ?_, ?_⟩
  618. · rw [Multiset.mem_toFinset, Polynomial.mem_roots hP, Polynomial.IsRoot.def]
  619. exact hx
  620. · have hQt_ne : Q - C (Q.eval x) ≠ 0 := by
  621. intro h0
  622. have hQ_const : Q = C (Q.eval x) := sub_eq_zero.mp h0
  623. have hcomp_const : P.comp Q = C (P.eval (Q.eval x)) := by
  624. conv_lhs => rw [hQ_const]
  625. rw [Polynomial.comp_C]
  626. rw [hx, map_zero] at hcomp_const
  627. exact hPQ hcomp_const
  628. rw [Multiset.mem_toFinset, Polynomial.mem_roots hQt_ne, Polynomial.IsRoot.def]
  629. simp
  630. calc (P.comp Q).roots.toFinset.card
  631. ≤ (P.roots.toFinset.biUnion (fun t => (Q - C t).roots.toFinset)).card :=
  632. Finset.card_le_card hsub
  633. _ ≤ ∑ t ∈ P.roots.toFinset, (Q - C t).roots.toFinset.card := Finset.card_biUnion_le
  634. _ ≤ ∑ _t ∈ P.roots.toFinset, B := Finset.sum_le_sum (fun t _ => hpre t)
  635. _ = P.roots.toFinset.card * B := by simp
  636. end Research.PvsNP.Tau