Lean / 0xOsprey/shub-smale-tau9 / WronskianPowerElimination.lean
Lean readerResearch/PvsNP/Tau/WronskianPowerElimination.lean
modulepublic import Research.PvsNP.Tau.TauConjecturepublic import Mathlib.Analysis.Calculus.Deriv.Polynomialpublic import Mathlib.Analysis.Calculus.Deriv.Invpublic import Mathlib.Analysis.Calculus.LocalExtr.Rollepublic import Mathlib.Analysis.Calculus.MeanValue@[expose] public sectionnamespace Research.PvsNP.Tau/-!# Exact 1-Step Wronskian Power-Elimination & Width-1 Moonshot A over `ℝ`This module formalizes two unconditional real-root upper bounds established during theMoonshot A investigation:1. **Exact 1-Step Wronskian Power-Elimination (`real_roots_pow_add_le`, `int_roots_pow_add_le`):**For any `u, v : Polynomial ℝ`, exponents `M, N ≥ 1`, and sign `s ∈ {-1, 1}` with`f := u ^ M + C s * v ^ N ≠ 0`:`f.roots.toFinset.card ≤ 2 * (u.natDegree + v.natDegree)`,completely independent of `M` and `N`.Over `ℤ[X]`, `intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree)`.2. **1-Addition Block Preimage Bound (`one_add_block_preimage_le_six`) & Width-1 CompositionBound (`real_roots_comp_le_of_preimage_bound`):**Every univariate polynomial of the form `Q(y) = C c0 * X ^ p * (X ^ q + C c) ^ r` (`q ≥ 1`)satisfies `(Q - C t).roots.toFinset.card ≤ 6` whenever `Q - C t ≠ 0`, yielding theunconditional exponential-base bound for width-1 compositions of 1-addition blocks.-/open Polynomial/-! ## 1. Helper Lemmas on Real Roots and Rolle's Theorem -//-- A polynomial of degree `≤ d` has at most `d` distinct real roots. -/private lemma card_toFinset_roots_le_natDegree (f : Polynomial ℝ) :f.roots.toFinset.card ≤ f.natDegree :=(Multiset.toFinset_card_le f.roots).trans (Polynomial.card_roots' f)/-- If a polynomial `f : Polynomial ℝ` vanishes on a nonempty open interval `(a, b)`,then `f = 0`. -/private lemma poly_eq_zero_of_eq_zero_on_Ioo (f : Polynomial ℝ) {a b : ℝ} (hab : a < b)(hvan : ∀ x ∈ Set.Ioo a b, f.eval x = 0) : f = 0 := byby_contra hnelet n := f.natDegree + 1let pts : Finset ℝ :=(Finset.range n).image (fun k : ℕ => a + (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ))have hinj : Set.InjOn (fun k : ℕ => a + (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ))(Finset.range n) := byintro i _ j _ hijhave hba : (0 : ℝ) < b - a := sub_pos.mpr habhave hn : (0 : ℝ) < (n + 1 : ℝ) := by positivityhave h1 : ((i + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) = ((j + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) := bylinarithhave h2 : (i + 1 : ℝ) * (b - a) = (j + 1 : ℝ) * (b - a) := (div_left_inj₀ (ne_of_gt hn)).mp h1have h3 : (i + 1 : ℝ) = (j + 1 : ℝ) := mul_right_cancel₀ (ne_of_gt hba) h2exact_mod_cast (by linarith : (i : ℝ) = (j : ℝ))have hcard : pts.card = n := byrw [Finset.card_image_of_injOn hinj, Finset.card_range]have hsub : pts ⊆ f.roots.toFinset := byintro x hxrcases Finset.mem_image.mp hx with ⟨k, hk, rfl⟩rw [Multiset.mem_toFinset, Polynomial.mem_roots hne, Polynomial.IsRoot.def]apply hvanhave hk_lt : k < n := Finset.mem_range.mp hkhave hba : (0 : ℝ) < b - a := sub_pos.mpr habhave hn : (0 : ℝ) < (n + 1 : ℝ) := by positivityconstructor· have : (0 : ℝ) < (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) := by positivitylinarith· have hk1 : (k + 1 : ℝ) < (n + 1 : ℝ) := by exact_mod_cast Nat.succ_lt_succ hk_lthave : (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) < b - a := byrw [div_lt_iff₀ hn]nlinarithlinarithhave hle := Finset.card_le_card hsubhave hdeg := card_toFinset_roots_le_natDegree fomega/-- Every real polynomial defines a continuous function `ℝ → ℝ`. -/private lemma poly_continuous (f : Polynomial ℝ) : Continuous (fun x => f.eval x) :=continuous_iff_continuousAt.mpr fun x => (f.hasDerivAt x).continuousAt/-- Rolle's theorem for a polynomial `f : Polynomial ℝ` between two roots `a < b`. -/private lemma exists_deriv_root_between {f : Polynomial ℝ} {a b : ℝ} (hab : a < b)(ha : f.eval a = 0) (hb : f.eval b = 0) :∃ c ∈ Set.Ioo a b, f.derivative.eval c = 0 := byhave hcont : ContinuousOn (fun x => f.eval x) (Set.Icc a b) :=(poly_continuous f).continuousOnhave heq : f.eval a = f.eval b := by rw [ha, hb]obtain ⟨c, hc, hderiv⟩ := exists_deriv_eq_zero hab hcont heqrefine ⟨c, hc, ?_⟩rwa [Polynomial.deriv] at hderiv/-- General Rolle counting on a finite set `S : Finset ℝ`: if between every consecutive pair`a < b` of `S` there exists a point `c ∈ T` with `a < c < b`, then `S.card ≤ T.card + 1`. -/private lemma card_le_card_add_one_of_between {S T : Finset ℝ}(hbetween : ∀ a ∈ S, ∀ b ∈ S, a < b → (∀ x ∈ S, ¬ (a < x ∧ x < b)) →∃ c ∈ T, a < c ∧ c < b) :S.card ≤ T.card + 1 := byby_cases h0 : S.card = 0· omegalet e : Fin S.card ↪o ℝ := S.orderEmbOfFin rflhave hchoice : ∀ i : Fin (S.card - 1),∃ c ∈ T, e ⟨i.val, by omega⟩ < c ∧ c < e ⟨i.val + 1, by omega⟩ := byintro iapply hbetween (e ⟨i.val, by omega⟩) (Finset.orderEmbOfFin_mem S rfl _)(e ⟨i.val + 1, by omega⟩) (Finset.orderEmbOfFin_mem S rfl _)· exact e.strictMono (by simp [Fin.lt_def])· intro x hx ⟨h1, h2⟩have hx_rng : x ∈ Set.range e := byrw [Finset.range_orderEmbOfFin]exact hxrcases hx_rng with ⟨j, hj⟩have hj1 : i.val < j.val := byby_contra hlehave : e j ≤ e ⟨i.val, by omega⟩ := e.monotone (by simp [Fin.le_def]; omega)linarithhave hj2 : j.val < i.val + 1 := byby_contra hlehave : e ⟨i.val + 1, by omega⟩ ≤ e j := e.monotone (by simp [Fin.le_def]; omega)linarithomegachoose g hgT hg1 hg2 using hchoicehave hinj : Function.Injective g := byintro i j hijby_contra hnercases lt_or_gt_of_ne hne with hlt | hgt· have hle : e ⟨i.val + 1, by omega⟩ ≤ e ⟨j.val, by omega⟩ :=e.monotone (by simp [Fin.le_def]; exact hlt)have := hg2 ihave := hg1 jlinarith· have hle : e ⟨j.val + 1, by omega⟩ ≤ e ⟨i.val, by omega⟩ :=e.monotone (by simp [Fin.le_def]; exact hgt)have := hg2 jhave := hg1 ilinarithhave hle_card : Fintype.card (Fin (S.card - 1)) ≤ T.card := byhave hsub : Finset.univ.image g ⊆ T := byintro x hxrcases Finset.mem_image.mp hx with ⟨i, _, rfl⟩exact hgT icalc Fintype.card (Fin (S.card - 1))= (Finset.univ : Finset (Fin (S.card - 1))).card := rfl_ = (Finset.univ.image g).card := (Finset.card_image_of_injective _ hinj).symm_ ≤ T.card := Finset.card_le_card hsubsimp only [Fintype.card_fin] at hle_cardomega/-- Classical Rolle bound for real polynomials: if `f ≠ 0` and `f.derivative ≠ 0`, then`f.roots.toFinset.card ≤ f.derivative.roots.toFinset.card + 1`. -/theorem poly_real_roots_le_deriv_add_one {f : Polynomial ℝ}(hf : f ≠ 0) (hdf : f.derivative ≠ 0) :f.roots.toFinset.card ≤ f.derivative.roots.toFinset.card + 1 := byapply card_le_card_add_one_of_betweenintro a ha b hb hab _rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at ha hbobtain ⟨c, ⟨hca, hcb⟩, hc⟩ := exists_deriv_root_between hab ha hbexact ⟨c, Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hdf).mpr hc), hca, hcb⟩/-! ## 2. Exact 1-Step Wronskian Power-Elimination Theorem -//-- Derivative of `u(x)^M / v(x)^N` at a point where `v(x) ≠ 0`. -/private lemma hasDerivAt_pow_div_pow (u v : Polynomial ℝ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N){x : ℝ} (hv : v.eval x ≠ 0) :HasDerivAt (fun t => (u.eval t) ^ M / (v.eval t) ^ N)(((u.eval x) ^ (M - 1) * ((M : ℝ) * u.derivative.eval x * v.eval x -(N : ℝ) * u.eval x * v.derivative.eval x)) / (v.eval x) ^ (N + 1)) x := byhave hu : HasDerivAt (fun t => u.eval t) (u.derivative.eval x) x := u.hasDerivAt xhave hv_d : HasDerivAt (fun t => v.eval t) (v.derivative.eval x) x := v.hasDerivAt xhave huM : HasDerivAt (fun t => (u.eval t) ^ M)((M : ℝ) * (u.eval x) ^ (M - 1) * u.derivative.eval x) x := HasDerivAt.pow hu Mhave hvN : HasDerivAt (fun t => (v.eval t) ^ N)((N : ℝ) * (v.eval x) ^ (N - 1) * v.derivative.eval x) x := HasDerivAt.pow hv_d Nhave hvN_ne : (v.eval x) ^ N ≠ 0 := pow_ne_zero N hvhave hdiv := HasDerivAt.div huM hvN hvN_neconvert hdiv using 1have hM' : u.eval x ^ M = u.eval x ^ (M - 1) * u.eval x := byconv_lhs => rw [← Nat.sub_add_cancel hM, pow_succ]have hN' : v.eval x ^ N = v.eval x ^ (N - 1) * v.eval x := byconv_lhs => rw [← Nat.sub_add_cancel hN, pow_succ]have hN2 : (v.eval x ^ N) ^ 2 = v.eval x ^ (N - 1) * v.eval x ^ (N + 1) := byrw [sq, ← pow_add, ← pow_add]congr 1; omegahave hv_pow_ne : v.eval x ^ (N - 1) ≠ 0 := pow_ne_zero _ hvhave hv_pow1_ne : v.eval x ^ (N + 1) ≠ 0 := pow_ne_zero _ hvrw [hN2]field_simp [hv, hv_pow_ne, hv_pow1_ne]rw [hM', hN']ring/-- **Exact 1-Step Wronskian Power-Elimination Theorem over `ℝ`:**For any `u, v : Polynomial ℝ`, `M, N ≥ 1`, and `s ∈ {-1, 1}` with `f := u ^ M + C s * v ^ N ≠ 0`,`f` has at most `2 * (u.natDegree + v.natDegree)` distinct real roots — completely independentof `M` and `N`. -/theorem real_roots_pow_add_le (u v : Polynomial ℝ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N)(s : ℝ) (hs : s = 1 ∨ s = -1)(hf : u ^ M + C s * v ^ N ≠ 0) :(u ^ M + C s * v ^ N).roots.toFinset.card ≤ 2 * (u.natDegree + v.natDegree) := byset f : Polynomial ℝ := u ^ M + C s * v ^ Nhave hs0 : s ≠ 0 := by rcases hs with rfl | rfl <;> norm_numby_cases hu0 : u = 0· subst hu0have hM0 : M ≠ 0 := by omegahave hfeq : f = C s * v ^ N := by simp [f, zero_pow hM0]have hv0 : v ≠ 0 := by intro hv; apply hf; simp [hfeq, hv, zero_pow (by omega : N ≠ 0)]have hsub : f.roots.toFinset ⊆ v.roots.toFinset := byintro x hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hv0, Polynomial.IsRoot.def]simp [hfeq, hs0] at hxexact hx.1have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree v)simp; omegaby_cases hv0 : v = 0· subst hv0have hN0 : N ≠ 0 := by omegahave hfeq : f = u ^ M := by simp [f, zero_pow hN0]have hsub : f.roots.toFinset ⊆ u.roots.toFinset := byintro x hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hu0, Polynomial.IsRoot.def]simp [hfeq] at hxexact hx.1have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree u)simp; omegaby_cases hdeg0 : u.natDegree + v.natDegree = 0· have hu_c : u.natDegree = 0 := by omegahave hv_c : v.natDegree = 0 := by omegahave hf_deg : f.natDegree = 0 := byhave h1 : (u ^ M).natDegree = 0 := by rw [natDegree_pow, hu_c, mul_zero]have h2 : (C s * v ^ N).natDegree ≤ 0 := bycalc (C s * v ^ N).natDegree ≤ (C s).natDegree + (v ^ N).natDegree := natDegree_mul_le_ = 0 := by rw [natDegree_C, natDegree_pow, hv_c, mul_zero, zero_add]have h3 : f.natDegree ≤ max (u ^ M).natDegree (C s * v ^ N).natDegree :=natDegree_add_le (u ^ M) (C s * v ^ N)omegahave hcard := card_toFinset_roots_le_natDegree fomega-- Now u ≠ 0, v ≠ 0, and u.natDegree + v.natDegree ≥ 1.set S := f.roots.toFinsetset Ru := u.roots.toFinsetset Rv := v.roots.toFinsetset U := Ru ∪ Rvset S0 := S ∩ Uset S1 := S \ Uhave hS_card : S.card = S0.card + S1.card := byexact (Finset.card_inter_add_card_sdiff S U).symm-- Every root in S0 = S ∩ (Ru ∪ Rv) is a root of BOTH u and v!have hS0_sub : S0 ⊆ Ru ∩ Rv := byintro x hxhave hxS : x ∈ S := (Finset.mem_inter.mp hx).1have hxU : x ∈ U := (Finset.mem_inter.mp hx).2have hfx : u.eval x ^ M + s * v.eval x ^ N = 0 := byhave := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hxS)rw [Polynomial.IsRoot.def] at thissimpa [f] using thisrcases Finset.mem_union.mp hxU with hxu | hxv· have hu_x : u.eval x = 0 :=Polynomial.IsRoot.def.mp ((Polynomial.mem_roots hu0).mp (Multiset.mem_toFinset.mp hxu))have hv_x : v.eval x = 0 := byrw [hu_x, zero_pow (by omega : M ≠ 0), zero_add] at hfxhave hvn : v.eval x ^ N = 0 := (mul_eq_zero.mp hfx).resolve_left hs0exact eq_zero_of_pow_eq_zero hvnexact Finset.mem_inter.mpr⟨hxu, Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hv0).mpr hv_x)⟩· have hv_x : v.eval x = 0 :=Polynomial.IsRoot.def.mp ((Polynomial.mem_roots hv0).mp (Multiset.mem_toFinset.mp hxv))have hu_x : u.eval x = 0 := byrw [hv_x, zero_pow (by omega : N ≠ 0), mul_zero, add_zero] at hfxexact eq_zero_of_pow_eq_zero hfxexact Finset.mem_inter.mpr⟨Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hu0).mpr hu_x), hxv⟩-- Hence U.card + S0.card ≤ deg(u) + deg(v)!have hU_S0 : U.card + S0.card ≤ u.natDegree + v.natDegree := byhave h1 : S0.card ≤ (Ru ∩ Rv).card := Finset.card_le_card hS0_subhave h2 : U.card + (Ru ∩ Rv).card = Ru.card + Rv.card :=Finset.card_union_add_card_inter Ru Rvhave h3 : Ru.card ≤ u.natDegree := card_toFinset_roots_le_natDegree uhave h4 : Rv.card ≤ v.natDegree := card_toFinset_roots_le_natDegree vomega-- Define the Wronskian W = M * u' * v - N * u * v'set W : Polynomial ℝ := C (M : ℝ) * u.derivative * v - C (N : ℝ) * u * v.derivativehave hW_deg : W.natDegree ≤ u.natDegree + v.natDegree - 1 := byhave h1 : (C (M : ℝ) * u.derivative * v).natDegree ≤ u.natDegree + v.natDegree - 1 := byby_cases hdu : u.derivative = 0· simp [hdu]· have hdu_pos : 1 ≤ u.natDegree := byby_contra hhave : u.natDegree = 0 := by omegaexact hdu (natDegree_eq_zero.mp this |>.elim fun c hc => by rw [← hc, derivative_C])calc (C (M : ℝ) * u.derivative * v).natDegree≤ (C (M : ℝ) * u.derivative).natDegree + v.natDegree := natDegree_mul_le_ ≤ ((C (M : ℝ)).natDegree + u.derivative.natDegree) + v.natDegree :=Nat.add_le_add_right natDegree_mul_le __ ≤ (0 + (u.natDegree - 1)) + v.natDegree := byrw [natDegree_C]exact Nat.add_le_add_right (Nat.add_le_add_left (natDegree_derivative_le u) _) __ = u.natDegree + v.natDegree - 1 := by omegahave h2 : (C (N : ℝ) * u * v.derivative).natDegree ≤ u.natDegree + v.natDegree - 1 := byby_cases hdv : v.derivative = 0· simp [hdv]· have hdv_pos : 1 ≤ v.natDegree := byby_contra hhave : v.natDegree = 0 := by omegaexact hdv (natDegree_eq_zero.mp this |>.elim fun c hc => by rw [← hc, derivative_C])calc (C (N : ℝ) * u * v.derivative).natDegree≤ (C (N : ℝ) * u).natDegree + v.derivative.natDegree := natDegree_mul_le_ ≤ ((C (N : ℝ)).natDegree + u.natDegree) + (v.natDegree - 1) :=Nat.add_le_add natDegree_mul_le (natDegree_derivative_le v)_ = u.natDegree + v.natDegree - 1 := by rw [natDegree_C]; omegaexact le_trans (natDegree_sub_le _ _) (max_le h1 h2)-- Key Rolle claim on S1 using T = U ∪ W.roots.toFinset:have hS1_bound : S1.card ≤ (U ∪ W.roots.toFinset).card + 1 := byapply card_le_card_add_one_of_betweenintro a ha b hb hab _by_cases huv_in : ∃ c ∈ U, a < c ∧ c < b· obtain ⟨c, hcU, hca, hcb⟩ := huv_inexact ⟨c, Finset.mem_union_left _ hcU, hca, hcb⟩· have haS : a ∈ S := (Finset.mem_sdiff.mp ha).1have haU : a ∉ U := (Finset.mem_sdiff.mp ha).2have hbS : b ∈ S := (Finset.mem_sdiff.mp hb).1have hbU : b ∉ U := (Finset.mem_sdiff.mp hb).2have hno_uv : ∀ x ∈ Set.Icc a b, u.eval x ≠ 0 ∧ v.eval x ≠ 0 := byintro x ⟨hax, hxb⟩have hx_notU : x ∉ U := byintro hxUrcases eq_or_lt_of_le hax with rfl | hax'· exact haU hxU· rcases eq_or_lt_of_le hxb with rfl | hxb'· exact hbU hxU· exact huv_in ⟨x, hxU, hax', hxb'⟩constructor· intro huxexact hx_notU (Finset.mem_union_left _ (Multiset.mem_toFinset.mpr((Polynomial.mem_roots hu0).mpr hux)))· intro hvxexact hx_notU (Finset.mem_union_right _ (Multiset.mem_toFinset.mpr((Polynomial.mem_roots hv0).mpr hvx)))let g : ℝ → ℝ := fun t => (u.eval t) ^ M / (v.eval t) ^ Nhave hga : g a = -s := byhave hfa : u.eval a ^ M + s * v.eval a ^ N = 0 := byhave := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp haS)rw [Polynomial.IsRoot.def] at thissimpa [f] using thishave hva : v.eval a ^ N ≠ 0 :=pow_ne_zero N (hno_uv a (Set.left_mem_Icc.mpr (le_of_lt hab))).2show u.eval a ^ M / v.eval a ^ N = -srw [div_eq_iff hva]; linarithhave hgb : g b = -s := byhave hfb : u.eval b ^ M + s * v.eval b ^ N = 0 := byhave := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hbS)rw [Polynomial.IsRoot.def] at thissimpa [f] using thishave hvb : v.eval b ^ N ≠ 0 :=pow_ne_zero N (hno_uv b (Set.right_mem_Icc.mpr (le_of_lt hab))).2show u.eval b ^ M / v.eval b ^ N = -srw [div_eq_iff hvb]; linarithhave hcont : ContinuousOn g (Set.Icc a b) := byapply ContinuousOn.div· exact ((poly_continuous u).pow M).continuousOn· exact ((poly_continuous v).pow N).continuousOn· intro x hx; exact pow_ne_zero N (hno_uv x hx).2-- Rule out W = 0 via MVT: if W = 0 then g' = 0 on (a, b), so g = -s on (a, b), forcing f = 0have hW_ne : W ≠ 0 := byintro hW0have hconst : ∀ x ∈ Set.Ioo a b, g x = g a := byintro x ⟨hax, hxb⟩have hxa : x - a ≠ 0 := ne_of_gt (sub_pos.mpr hax)let m : ℝ := (g x - g a) / (x - a)let h : ℝ → ℝ := fun t => g t - g a - m * (t - a)have hcont_h : ContinuousOn h (Set.Icc a x) := byhave h1 : ContinuousOn g (Set.Icc a x) :=hcont.mono (Set.Icc_subset_Icc_right (le_of_lt hxb))exact (h1.sub continuousOn_const).sub(continuousOn_const.mul (continuousOn_id.sub continuousOn_const))have hha : h a = 0 := by simp [h]have hhx : h x = 0 := bysimp only [h, m]rw [div_mul_cancel₀ _ hxa, sub_self]obtain ⟨c, ⟨hac, hcx⟩, hderiv_h⟩ := exists_deriv_eq_zero hax hcont_h (by rw [hha, hhx])have hcIcc : c ∈ Set.Icc a b := ⟨le_of_lt hac, le_of_lt (lt_trans hcx hxb)⟩have hhd := hasDerivAt_pow_div_pow u v M N hM hN (hno_uv c hcIcc).2have hhd_lin : HasDerivAt (fun t : ℝ => m * (t - a)) m c := bysimpa using ((hasDerivAt_id c).sub_const a).const_mul mhave hhd_h : HasDerivAt h(((u.eval c) ^ (M - 1) * ((M : ℝ) * u.derivative.eval c * v.eval c -(N : ℝ) * u.eval c * v.derivative.eval c)) / (v.eval c) ^ (N + 1) - m) c :=(hhd.sub_const (g a)).sub hhd_linhave hWc : W.eval c = 0 := by rw [hW0]; simphave hWc' : (M : ℝ) * u.derivative.eval c * v.eval c -(N : ℝ) * u.eval c * v.derivative.eval c = 0 := bysimpa [W] using hWcrw [hhd_h.deriv, hWc', mul_zero, zero_div, zero_sub, neg_eq_zero] at hderiv_hhave hgx_sub : g x - g a = 0 := (div_eq_zero_iff.mp hderiv_h).resolve_right hxalinarithhave hf0 : f = 0 := byapply poly_eq_zero_of_eq_zero_on_Ioo f habintro x hxhave hgx : g x = -s := by rw [hconst x hx, hga]have hvx : v.eval x ^ N ≠ 0 := pow_ne_zero N (hno_uv x (Set.Ioo_subset_Icc_self hx)).2have hux : u.eval x ^ M = -s * v.eval x ^ N := (div_eq_iff hvx).mp hgxshow (u ^ M + C s * v ^ N).eval x = 0simp [hux]exact hf hf0obtain ⟨c, ⟨hca, hcb⟩, hgc⟩ := exists_deriv_eq_zero hab hcont (by rw [hga, hgb])have hcIcc : c ∈ Set.Icc a b := ⟨le_of_lt hca, le_of_lt hcb⟩have hhd := hasDerivAt_pow_div_pow u v M N hM hN (hno_uv c hcIcc).2rw [hhd.deriv] at hgchave hvc_ne : (v.eval c) ^ (N + 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).2have huc_ne : (u.eval c) ^ (M - 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).1have hnum : (u.eval c) ^ (M - 1) * ((M : ℝ) * u.derivative.eval c * v.eval c -(N : ℝ) * u.eval c * v.derivative.eval c) = 0 :=(div_eq_zero_iff.mp hgc).resolve_right hvc_nehave hWc_eq : (M : ℝ) * u.derivative.eval c * v.eval c -(N : ℝ) * u.eval c * v.derivative.eval c = 0 :=(mul_eq_zero.mp hnum).resolve_left huc_nehave hWc : W.eval c = 0 := by simpa [W] using hWc_eqexact ⟨c, Finset.mem_union_right _ (Multiset.mem_toFinset.mpr((Polynomial.mem_roots hW_ne).mpr hWc)), hca, hcb⟩have hunion : (U ∪ W.roots.toFinset).card ≤ U.card + W.roots.toFinset.card :=Finset.card_union_le U W.roots.toFinsethave hW_card : W.roots.toFinset.card ≤ u.natDegree + v.natDegree - 1 :=(card_toFinset_roots_le_natDegree W).trans hW_degomega/-- **Integer-Root Specialization (`int_roots_pow_add_le`):**For any `u, v : Polynomial ℤ`, `M, N ≥ 1`, and `s ∈ {-1, 1}` with `u ^ M + C s * v ^ N ≠ 0`,`intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree)`. -/theorem int_roots_pow_add_le (u v : Polynomial ℤ) (M N : ℕ) (hM : 1 ≤ M) (hN : 1 ≤ N)(s : ℤ) (hs : s = 1 ∨ s = -1)(hf : u ^ M + C s * v ^ N ≠ 0) :intRootCount (u ^ M + C s * v ^ N) ≤ 2 * (u.natDegree + v.natDegree) := bylet φ : ℤ →+* ℝ := Int.castRingHom ℝhave hφ_inj : Function.Injective φ := Int.cast_injectiveset f : Polynomial ℤ := u ^ M + C s * v ^ Nset fR : Polynomial ℝ := f.map φhave hfR_eq : fR = (u.map φ) ^ M + C (s : ℝ) * (v.map φ) ^ N := bysimp [fR, f, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow, φ]have hfR_ne : fR ≠ 0 := byintro h0apply hfexact Polynomial.map_injective φ hφ_inj (by simpa [fR] using h0)have hsub : f.roots.toFinset.image (fun z : ℤ => (z : ℝ)) ⊆ fR.roots.toFinset := byintro x hxrcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hzrw [Multiset.mem_toFinset, Polynomial.mem_roots hfR_ne, Polynomial.IsRoot.def]show (f.map φ).eval (φ z) = 0rw [Polynomial.eval_map, Polynomial.eval₂_hom, hz, map_zero]have hcard_int : intRootCount f ≤ fR.roots.toFinset.card := byunfold intRootCount intRootSetcalc f.roots.toFinset.card= (f.roots.toFinset.image (fun z : ℤ => (z : ℝ))).card :=(Finset.card_image_of_injective _ Int.cast_injective).symm_ ≤ fR.roots.toFinset.card := Finset.card_le_card hsubhave hsR : (s : ℝ) = 1 ∨ (s : ℝ) = -1 := byrcases hs with rfl | rfl· left; norm_num· right; norm_numhave hreal := real_roots_pow_add_le (u.map φ) (v.map φ) M N hM hN (s : ℝ) hsR(by rwa [← hfR_eq])rw [← hfR_eq] at hrealhave hdu : (u.map φ).natDegree ≤ u.natDegree := natDegree_map_lehave hdv : (v.map φ).natDegree ≤ v.natDegree := natDegree_map_leomega/-! ## 3. Exact 1-Addition Univariate Block Bound & Width-1 Composition Bound over `ℝ` -//-- A binomial `X ^ q - C a` (`q ≥ 1`) has at most `2` distinct real roots. -/private lemma real_roots_X_pow_sub_C_le_two (q : ℕ) (hq : 1 ≤ q) (a : ℝ) :(X ^ q - C a : Polynomial ℝ).roots.toFinset.card ≤ 2 := byhave hne : (X ^ q - C a : Polynomial ℝ) ≠ 0 := byintro h0have hdeg := congrArg Polynomial.natDegree h0rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg· simp at hdeg; omega· simp; omegahave hderiv : (X ^ q - C a : Polynomial ℝ).derivative = C (q : ℝ) * X ^ (q - 1) := bysimp [derivative_pow, derivative_C]have hd_ne : (X ^ q - C a : Polynomial ℝ).derivative ≠ 0 := byrw [hderiv]apply mul_ne_zero· exact Polynomial.C_ne_zero.mpr (by exact_mod_cast (by omega : q ≠ 0))· exact pow_ne_zero _ Polynomial.X_ne_zerohave hrolle := poly_real_roots_le_deriv_add_one hne hd_nehave hd_roots : (X ^ q - C a : Polynomial ℝ).derivative.roots.toFinset ⊆ {0} := byintro x hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hd_ne, Polynomial.IsRoot.def, hderiv] at hxsimp only [eval_mul, eval_C, eval_pow, eval_X] at hxhave hq0 : (q : ℝ) ≠ 0 := by exact_mod_cast (by omega : q ≠ 0)have hxp : x ^ (q - 1) = 0 := (mul_eq_zero.mp hx).resolve_left hq0exact Finset.mem_singleton.mpr (eq_zero_of_pow_eq_zero hxp)have hcard_d : (X ^ q - C a : Polynomial ℝ).derivative.roots.toFinset.card ≤ 1 :=(Finset.card_le_card hd_roots).trans (by simp)omega/-- **1-Addition Univariate Block Preimage Bound:**Every univariate polynomial `Q(y) = C c0 * X ^ p * (X ^ q + C c) ^ r` (`q ≥ 1`) hasat most `6` distinct real solutions to `Q(y) = t` whenever `Q - C t ≠ 0`. -/theorem one_add_block_preimage_le_six (c0 c t : ℝ) (p q r : ℕ) (hq : 1 ≤ q)(hne : C c0 * X ^ p * (X ^ q + C c) ^ r - C t ≠ 0) :(C c0 * X ^ p * (X ^ q + C c) ^ r - C t).roots.toFinset.card ≤ 6 := byset f : Polynomial ℝ := C c0 * X ^ p * (X ^ q + C c) ^ r - C tby_cases hdf : f.derivative = 0· have hdeg : f.natDegree = 0 := byby_contra hposhave h1 : 1 ≤ f.natDegree := by omegahave hcoeff : f.derivative.coeff (f.natDegree - 1) = (f.natDegree : ℝ) * f.leadingCoeff := byrw [coeff_derivative, Nat.sub_add_cancel h1]have hcast : ((f.natDegree - 1 : ℕ) : ℝ) + 1 = (f.natDegree : ℝ) := byexact_mod_cast Nat.sub_add_cancel h1rw [hcast, Polynomial.coeff_natDegree, mul_comm]rw [hdf, coeff_zero] at hcoeffhave hlead : f.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hnehave hnd : (f.natDegree : ℝ) ≠ 0 := by exact_mod_cast (by omega : f.natDegree ≠ 0)exact mul_ne_zero hnd hlead hcoeff.symmhave := card_toFinset_roots_le_natDegree fomegahave hrolle := poly_real_roots_le_deriv_add_one hne hdfhave hc0 : c0 ≠ 0 := byintro h0; apply hdf; simp [f, h0, derivative_C]have hpqr : p + q * r ≠ 0 := byintro h0have hp0 : p = 0 := by omegahave hr0 : r = 0 := byrcases Nat.mul_eq_zero.mp (by omega : q * r = 0) with hq0 | hr0· omega· exact hr0apply hdf; simp [f, hp0, hr0, derivative_C]set A : Polynomial ℝ := X ^ q - C (-c)set B : Polynomial ℝ := X ^ q - C (-(p : ℝ) * c / ((p + q * r : ℕ) : ℝ))have hA_ne : A ≠ 0 := byintro h0; have hdeg := congrArg Polynomial.natDegree h0rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg· simp at hdeg; omega· simp; omegahave hB_ne : B ≠ 0 := byintro h0; have hdeg := congrArg Polynomial.natDegree h0rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg· simp at hdeg; omega· simp; omegahave hsub :f.derivative.roots.toFinset ⊆ ({0} : Finset ℝ) ∪ A.roots.toFinset ∪ B.roots.toFinset := byintro x hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hdf, Polynomial.IsRoot.def] at hxhave hderiv_at : HasDerivAt (fun y : ℝ => c0 * y ^ p * (y ^ q + c) ^ r - t)(c0 * ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))))) x := byhave h1 : HasDerivAt (fun y : ℝ => y ^ p) ((p : ℝ) * x ^ (p - 1)) x := hasDerivAt_pow p xhave h2 : HasDerivAt (fun y : ℝ => y ^ q + c) ((q : ℝ) * x ^ (q - 1)) x :=(hasDerivAt_pow q x).add_const chave h3 : HasDerivAt (fun y : ℝ => (y ^ q + c) ^ r)((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))) x := HasDerivAt.pow h2 rhave h4 := (h1.mul h3).const_mul c0simpa [mul_assoc, mul_add, add_mul] using h4.sub_const thave hf_fn : (fun y : ℝ => f.eval y) = (fun y : ℝ => c0 * y ^ p * (y ^ q + c) ^ r - t) := byext y; simp [f]have hval0 : c0 * ((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) = 0 := byhave h1 : deriv (fun y => f.eval y) x = f.derivative.eval x := Polynomial.deriv frw [hf_fn] at h1rw [hderiv_at.deriv] at h1linarithhave hinner : (p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))) = 0 :=(mul_eq_zero.mp hval0).resolve_left hc0by_cases hx0 : x = 0· exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_singleton.mpr hx0))by_cases hxq : x ^ q + c = 0· apply Finset.mem_union_left _apply Finset.mem_union_right _rw [Multiset.mem_toFinset, Polynomial.mem_roots hA_ne, Polynomial.IsRoot.def]simp [A]; linarithhave hmul : (x * (x ^ q + c)) *((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) = 0 := byrw [hinner, mul_zero]have hterm1 : x * ((p : ℝ) * x ^ (p - 1)) = (p : ℝ) * x ^ p := bycases p with| zero => simp| succ p' => simp [pow_succ]; ringhave hterm2 : (x ^ q + c) * ((r : ℝ) * (x ^ q + c) ^ (r - 1)) = (r : ℝ) * (x ^ q + c) ^ r := bycases r with| zero => simp| succ r' => simp [pow_succ]; ringhave hterm3 : x * ((q : ℝ) * x ^ (q - 1)) = (q : ℝ) * x ^ q := byhave : x * x ^ (q - 1) = x ^ q := byconv_rhs => rw [← Nat.sub_add_cancel hq, pow_succ, mul_comm]calc x * ((q : ℝ) * x ^ (q - 1)) = (q : ℝ) * (x * x ^ (q - 1)) := by ring_ = (q : ℝ) * x ^ q := by rw [this]have hfact : x ^ p * (x ^ q + c) ^ r *(((p + q * r : ℕ) : ℝ) * x ^ q + (p : ℝ) * c) = 0 := byhave hrew : (x * (x ^ q + c)) *((p : ℝ) * x ^ (p - 1) * (x ^ q + c) ^ r +x ^ p * ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1)))) =(x ^ q + c) * (x * ((p : ℝ) * x ^ (p - 1))) * (x ^ q + c) ^ r +x ^ p * ((x ^ q + c) * ((r : ℝ) * (x ^ q + c) ^ (r - 1))) *(x * ((q : ℝ) * x ^ (q - 1))) := byringrw [hrew, hterm1, hterm2, hterm3] at hmulpush_castlinarithhave hxp_ne : x ^ p ≠ 0 := pow_ne_zero p hx0have hxqr_ne : (x ^ q + c) ^ r ≠ 0 := pow_ne_zero r hxqhave hlin : ((p + q * r : ℕ) : ℝ) * x ^ q + (p : ℝ) * c = 0 :=(mul_eq_zero.mp hfact).resolve_left (mul_ne_zero hxp_ne hxqr_ne)apply Finset.mem_union_right _rw [Multiset.mem_toFinset, Polynomial.mem_roots hB_ne, Polynomial.IsRoot.def]simp only [B, eval_sub, eval_pow, eval_X, eval_C]have hden : ((p + q * r : ℕ) : ℝ) ≠ 0 := by exact_mod_cast hpqrhave : x ^ q = -(p : ℝ) * c / ((p + q * r : ℕ) : ℝ) := byrw [eq_div_iff hden]; linarithlinarithhave hcard_d : f.derivative.roots.toFinset.card ≤ 5 := byhave h1 := Finset.card_le_card hsubhave h2 := Finset.card_union_le (({0} : Finset ℝ) ∪ A.roots.toFinset) B.roots.toFinsethave h3 := Finset.card_union_le ({0} : Finset ℝ) A.roots.toFinsethave hA : A.roots.toFinset.card ≤ 2 := real_roots_X_pow_sub_C_le_two q hq (-c)have hB : B.roots.toFinset.card ≤ 2 :=real_roots_X_pow_sub_C_le_two q hq (-(p : ℝ) * c / ((p + q * r : ℕ) : ℝ))simp only [Finset.card_singleton] at h3omegaomega/-- **Width-1 Composition Real-Root Counting Lemma:**If every level set `Q(x) = t` has at most `B` distinct real solutions, then for any `P ≠ 0`with `P.comp Q ≠ 0`, `(P.comp Q).roots.toFinset.card ≤ P.roots.toFinset.card * B`. -/theorem real_roots_comp_le_of_preimage_bound (P Q : Polynomial ℝ) (B : ℕ)(hP : P ≠ 0) (hPQ : P.comp Q ≠ 0)(hpre : ∀ t : ℝ, (Q - C t).roots.toFinset.card ≤ B) :(P.comp Q).roots.toFinset.card ≤ P.roots.toFinset.card * B := byhave hsub : (P.comp Q).roots.toFinset ⊆P.roots.toFinset.biUnion (fun t => (Q - C t).roots.toFinset) := byintro x hxrw [Multiset.mem_toFinset, Polynomial.mem_roots hPQ, Polynomial.IsRoot.def, eval_comp] at hxrefine Finset.mem_biUnion.mpr ⟨Q.eval x, ?_, ?_⟩· rw [Multiset.mem_toFinset, Polynomial.mem_roots hP, Polynomial.IsRoot.def]exact hx· have hQt_ne : Q - C (Q.eval x) ≠ 0 := byintro h0have hQ_const : Q = C (Q.eval x) := sub_eq_zero.mp h0have hcomp_const : P.comp Q = C (P.eval (Q.eval x)) := byconv_lhs => rw [hQ_const]rw [Polynomial.comp_C]rw [hx, map_zero] at hcomp_constexact hPQ hcomp_constrw [Multiset.mem_toFinset, Polynomial.mem_roots hQt_ne, Polynomial.IsRoot.def]simpcalc (P.comp Q).roots.toFinset.card≤ (P.roots.toFinset.biUnion (fun t => (Q - C t).roots.toFinset)).card :=Finset.card_le_card hsub_ ≤ ∑ t ∈ P.roots.toFinset, (Q - C t).roots.toFinset.card := Finset.card_biUnion_le_ ≤ ∑ _t ∈ P.roots.toFinset, B := Finset.sum_le_sum (fun t _ => hpre t)_ = P.roots.toFinset.card * B := by simpend Research.PvsNP.Tau