module public import Research.PvsNP.Tau.TauConjecture public import Mathlib.Analysis.Calculus.Deriv.Polynomial public import Mathlib.Analysis.Calculus.Deriv.Inv public import Mathlib.Analysis.Calculus.LocalExtr.Rolle public import Mathlib.Analysis.Calculus.MeanValue @[expose] public section namespace 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 the Moonshot 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 Composition Bound (`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 the unconditional 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 := by by_contra hne let n := f.natDegree + 1 let 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) := by intro i _ j _ hij have hba : (0 : ℝ) < b - a := sub_pos.mpr hab have hn : (0 : ℝ) < (n + 1 : ℝ) := by positivity have h1 : ((i + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) = ((j + 1 : ℝ) * (b - a)) / (n + 1 : ℝ) := by linarith have h2 : (i + 1 : ℝ) * (b - a) = (j + 1 : ℝ) * (b - a) := (div_left_inj₀ (ne_of_gt hn)).mp h1 have h3 : (i + 1 : ℝ) = (j + 1 : ℝ) := mul_right_cancel₀ (ne_of_gt hba) h2 exact_mod_cast (by linarith : (i : ℝ) = (j : ℝ)) have hcard : pts.card = n := by rw [Finset.card_image_of_injOn hinj, Finset.card_range] have hsub : pts ⊆ f.roots.toFinset := by intro x hx rcases Finset.mem_image.mp hx with ⟨k, hk, rfl⟩ rw [Multiset.mem_toFinset, Polynomial.mem_roots hne, Polynomial.IsRoot.def] apply hvan have hk_lt : k < n := Finset.mem_range.mp hk have hba : (0 : ℝ) < b - a := sub_pos.mpr hab have hn : (0 : ℝ) < (n + 1 : ℝ) := by positivity constructor · have : (0 : ℝ) < (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) := by positivity linarith · have hk1 : (k + 1 : ℝ) < (n + 1 : ℝ) := by exact_mod_cast Nat.succ_lt_succ hk_lt have : (k + 1 : ℝ) * (b - a) / (n + 1 : ℝ) < b - a := by rw [div_lt_iff₀ hn] nlinarith linarith have hle := Finset.card_le_card hsub have hdeg := card_toFinset_roots_le_natDegree f omega /-- 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 := by have hcont : ContinuousOn (fun x => f.eval x) (Set.Icc a b) := (poly_continuous f).continuousOn have heq : f.eval a = f.eval b := by rw [ha, hb] obtain ⟨c, hc, hderiv⟩ := exists_deriv_eq_zero hab hcont heq refine ⟨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 := by by_cases h0 : S.card = 0 · omega let e : Fin S.card ↪o ℝ := S.orderEmbOfFin rfl have hchoice : ∀ i : Fin (S.card - 1), ∃ c ∈ T, e ⟨i.val, by omega⟩ < c ∧ c < e ⟨i.val + 1, by omega⟩ := by intro i apply 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 := by rw [Finset.range_orderEmbOfFin] exact hx rcases hx_rng with ⟨j, hj⟩ have hj1 : i.val < j.val := by by_contra hle have : e j ≤ e ⟨i.val, by omega⟩ := e.monotone (by simp [Fin.le_def]; omega) linarith have hj2 : j.val < i.val + 1 := by by_contra hle have : e ⟨i.val + 1, by omega⟩ ≤ e j := e.monotone (by simp [Fin.le_def]; omega) linarith omega choose g hgT hg1 hg2 using hchoice have hinj : Function.Injective g := by intro i j hij by_contra hne rcases 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 i have := hg1 j linarith · have hle : e ⟨j.val + 1, by omega⟩ ≤ e ⟨i.val, by omega⟩ := e.monotone (by simp [Fin.le_def]; exact hgt) have := hg2 j have := hg1 i linarith have hle_card : Fintype.card (Fin (S.card - 1)) ≤ T.card := by have hsub : Finset.univ.image g ⊆ T := by intro x hx rcases Finset.mem_image.mp hx with ⟨i, _, rfl⟩ exact hgT i calc 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 hsub simp only [Fintype.card_fin] at hle_card omega /-- 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 := by apply card_le_card_add_one_of_between intro a ha b hb hab _ rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at ha hb obtain ⟨c, ⟨hca, hcb⟩, hc⟩ := exists_deriv_root_between hab ha hb exact ⟨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 := by have hu : HasDerivAt (fun t => u.eval t) (u.derivative.eval x) x := u.hasDerivAt x have hv_d : HasDerivAt (fun t => v.eval t) (v.derivative.eval x) x := v.hasDerivAt x have huM : HasDerivAt (fun t => (u.eval t) ^ M) ((M : ℝ) * (u.eval x) ^ (M - 1) * u.derivative.eval x) x := HasDerivAt.pow hu M have hvN : HasDerivAt (fun t => (v.eval t) ^ N) ((N : ℝ) * (v.eval x) ^ (N - 1) * v.derivative.eval x) x := HasDerivAt.pow hv_d N have hvN_ne : (v.eval x) ^ N ≠ 0 := pow_ne_zero N hv have hdiv := HasDerivAt.div huM hvN hvN_ne convert hdiv using 1 have hM' : u.eval x ^ M = u.eval x ^ (M - 1) * u.eval x := by conv_lhs => rw [← Nat.sub_add_cancel hM, pow_succ] have hN' : v.eval x ^ N = v.eval x ^ (N - 1) * v.eval x := by conv_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) := by rw [sq, ← pow_add, ← pow_add] congr 1; omega have hv_pow_ne : v.eval x ^ (N - 1) ≠ 0 := pow_ne_zero _ hv have hv_pow1_ne : v.eval x ^ (N + 1) ≠ 0 := pow_ne_zero _ hv rw [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 independent of `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) := by set f : Polynomial ℝ := u ^ M + C s * v ^ N have hs0 : s ≠ 0 := by rcases hs with rfl | rfl <;> norm_num by_cases hu0 : u = 0 · subst hu0 have hM0 : M ≠ 0 := by omega have 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 := by intro x hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hv0, Polynomial.IsRoot.def] simp [hfeq, hs0] at hx exact hx.1 have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree v) simp; omega by_cases hv0 : v = 0 · subst hv0 have hN0 : N ≠ 0 := by omega have hfeq : f = u ^ M := by simp [f, zero_pow hN0] have hsub : f.roots.toFinset ⊆ u.roots.toFinset := by intro x hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hu0, Polynomial.IsRoot.def] simp [hfeq] at hx exact hx.1 have hcard := (Finset.card_le_card hsub).trans (card_toFinset_roots_le_natDegree u) simp; omega by_cases hdeg0 : u.natDegree + v.natDegree = 0 · have hu_c : u.natDegree = 0 := by omega have hv_c : v.natDegree = 0 := by omega have hf_deg : f.natDegree = 0 := by have h1 : (u ^ M).natDegree = 0 := by rw [natDegree_pow, hu_c, mul_zero] have h2 : (C s * v ^ N).natDegree ≤ 0 := by calc (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) omega have hcard := card_toFinset_roots_le_natDegree f omega -- Now u ≠ 0, v ≠ 0, and u.natDegree + v.natDegree ≥ 1. set S := f.roots.toFinset set Ru := u.roots.toFinset set Rv := v.roots.toFinset set U := Ru ∪ Rv set S0 := S ∩ U set S1 := S \ U have hS_card : S.card = S0.card + S1.card := by exact (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 := by intro x hx have hxS : x ∈ S := (Finset.mem_inter.mp hx).1 have hxU : x ∈ U := (Finset.mem_inter.mp hx).2 have hfx : u.eval x ^ M + s * v.eval x ^ N = 0 := by have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hxS) rw [Polynomial.IsRoot.def] at this simpa [f] using this rcases 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 := by rw [hu_x, zero_pow (by omega : M ≠ 0), zero_add] at hfx have hvn : v.eval x ^ N = 0 := (mul_eq_zero.mp hfx).resolve_left hs0 exact eq_zero_of_pow_eq_zero hvn exact 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 := by rw [hv_x, zero_pow (by omega : N ≠ 0), mul_zero, add_zero] at hfx exact eq_zero_of_pow_eq_zero hfx exact 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 := by have h1 : S0.card ≤ (Ru ∩ Rv).card := Finset.card_le_card hS0_sub have h2 : U.card + (Ru ∩ Rv).card = Ru.card + Rv.card := Finset.card_union_add_card_inter Ru Rv have h3 : Ru.card ≤ u.natDegree := card_toFinset_roots_le_natDegree u have h4 : Rv.card ≤ v.natDegree := card_toFinset_roots_le_natDegree v omega -- Define the Wronskian W = M * u' * v - N * u * v' set W : Polynomial ℝ := C (M : ℝ) * u.derivative * v - C (N : ℝ) * u * v.derivative have hW_deg : W.natDegree ≤ u.natDegree + v.natDegree - 1 := by have h1 : (C (M : ℝ) * u.derivative * v).natDegree ≤ u.natDegree + v.natDegree - 1 := by by_cases hdu : u.derivative = 0 · simp [hdu] · have hdu_pos : 1 ≤ u.natDegree := by by_contra h have : u.natDegree = 0 := by omega exact 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 := by rw [natDegree_C] exact Nat.add_le_add_right (Nat.add_le_add_left (natDegree_derivative_le u) _) _ _ = u.natDegree + v.natDegree - 1 := by omega have h2 : (C (N : ℝ) * u * v.derivative).natDegree ≤ u.natDegree + v.natDegree - 1 := by by_cases hdv : v.derivative = 0 · simp [hdv] · have hdv_pos : 1 ≤ v.natDegree := by by_contra h have : v.natDegree = 0 := by omega exact 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]; omega exact 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 := by apply card_le_card_add_one_of_between intro a ha b hb hab _ by_cases huv_in : ∃ c ∈ U, a < c ∧ c < b · obtain ⟨c, hcU, hca, hcb⟩ := huv_in exact ⟨c, Finset.mem_union_left _ hcU, hca, hcb⟩ · have haS : a ∈ S := (Finset.mem_sdiff.mp ha).1 have haU : a ∉ U := (Finset.mem_sdiff.mp ha).2 have hbS : b ∈ S := (Finset.mem_sdiff.mp hb).1 have hbU : b ∉ U := (Finset.mem_sdiff.mp hb).2 have hno_uv : ∀ x ∈ Set.Icc a b, u.eval x ≠ 0 ∧ v.eval x ≠ 0 := by intro x ⟨hax, hxb⟩ have hx_notU : x ∉ U := by intro hxU rcases 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 hux exact hx_notU (Finset.mem_union_left _ (Multiset.mem_toFinset.mpr ((Polynomial.mem_roots hu0).mpr hux))) · intro hvx exact 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) ^ N have hga : g a = -s := by have hfa : u.eval a ^ M + s * v.eval a ^ N = 0 := by have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp haS) rw [Polynomial.IsRoot.def] at this simpa [f] using this have hva : v.eval a ^ N ≠ 0 := pow_ne_zero N (hno_uv a (Set.left_mem_Icc.mpr (le_of_lt hab))).2 show u.eval a ^ M / v.eval a ^ N = -s rw [div_eq_iff hva]; linarith have hgb : g b = -s := by have hfb : u.eval b ^ M + s * v.eval b ^ N = 0 := by have := (Polynomial.mem_roots hf).mp (Multiset.mem_toFinset.mp hbS) rw [Polynomial.IsRoot.def] at this simpa [f] using this have hvb : v.eval b ^ N ≠ 0 := pow_ne_zero N (hno_uv b (Set.right_mem_Icc.mpr (le_of_lt hab))).2 show u.eval b ^ M / v.eval b ^ N = -s rw [div_eq_iff hvb]; linarith have hcont : ContinuousOn g (Set.Icc a b) := by apply 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 = 0 have hW_ne : W ≠ 0 := by intro hW0 have hconst : ∀ x ∈ Set.Ioo a b, g x = g a := by intro 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) := by have 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 := by simp 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).2 have hhd_lin : HasDerivAt (fun t : ℝ => m * (t - a)) m c := by simpa using ((hasDerivAt_id c).sub_const a).const_mul m have 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_lin have hWc : W.eval c = 0 := by rw [hW0]; simp have hWc' : (M : ℝ) * u.derivative.eval c * v.eval c - (N : ℝ) * u.eval c * v.derivative.eval c = 0 := by simpa [W] using hWc rw [hhd_h.deriv, hWc', mul_zero, zero_div, zero_sub, neg_eq_zero] at hderiv_h have hgx_sub : g x - g a = 0 := (div_eq_zero_iff.mp hderiv_h).resolve_right hxa linarith have hf0 : f = 0 := by apply poly_eq_zero_of_eq_zero_on_Ioo f hab intro x hx have 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)).2 have hux : u.eval x ^ M = -s * v.eval x ^ N := (div_eq_iff hvx).mp hgx show (u ^ M + C s * v ^ N).eval x = 0 simp [hux] exact hf hf0 obtain ⟨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).2 rw [hhd.deriv] at hgc have hvc_ne : (v.eval c) ^ (N + 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).2 have huc_ne : (u.eval c) ^ (M - 1) ≠ 0 := pow_ne_zero _ (hno_uv c hcIcc).1 have 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_ne have 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_ne have hWc : W.eval c = 0 := by simpa [W] using hWc_eq exact ⟨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.toFinset have hW_card : W.roots.toFinset.card ≤ u.natDegree + v.natDegree - 1 := (card_toFinset_roots_le_natDegree W).trans hW_deg omega /-- **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) := by let φ : ℤ →+* ℝ := Int.castRingHom ℝ have hφ_inj : Function.Injective φ := Int.cast_injective set f : Polynomial ℤ := u ^ M + C s * v ^ N set fR : Polynomial ℝ := f.map φ have hfR_eq : fR = (u.map φ) ^ M + C (s : ℝ) * (v.map φ) ^ N := by simp [fR, f, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow, φ] have hfR_ne : fR ≠ 0 := by intro h0 apply hf exact Polynomial.map_injective φ hφ_inj (by simpa [fR] using h0) have hsub : f.roots.toFinset.image (fun z : ℤ => (z : ℝ)) ⊆ fR.roots.toFinset := by intro x hx rcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩ rw [Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot.def] at hz rw [Multiset.mem_toFinset, Polynomial.mem_roots hfR_ne, Polynomial.IsRoot.def] show (f.map φ).eval (φ z) = 0 rw [Polynomial.eval_map, Polynomial.eval₂_hom, hz, map_zero] have hcard_int : intRootCount f ≤ fR.roots.toFinset.card := by unfold intRootCount intRootSet calc 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 hsub have hsR : (s : ℝ) = 1 ∨ (s : ℝ) = -1 := by rcases hs with rfl | rfl · left; norm_num · right; norm_num have hreal := real_roots_pow_add_le (u.map φ) (v.map φ) M N hM hN (s : ℝ) hsR (by rwa [← hfR_eq]) rw [← hfR_eq] at hreal have hdu : (u.map φ).natDegree ≤ u.natDegree := natDegree_map_le have hdv : (v.map φ).natDegree ≤ v.natDegree := natDegree_map_le omega /-! ## 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 := by have hne : (X ^ q - C a : Polynomial ℝ) ≠ 0 := by intro h0 have hdeg := congrArg Polynomial.natDegree h0 rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg · simp at hdeg; omega · simp; omega have hderiv : (X ^ q - C a : Polynomial ℝ).derivative = C (q : ℝ) * X ^ (q - 1) := by simp [derivative_pow, derivative_C] have hd_ne : (X ^ q - C a : Polynomial ℝ).derivative ≠ 0 := by rw [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_zero have hrolle := poly_real_roots_le_deriv_add_one hne hd_ne have hd_roots : (X ^ q - C a : Polynomial ℝ).derivative.roots.toFinset ⊆ {0} := by intro x hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hd_ne, Polynomial.IsRoot.def, hderiv] at hx simp only [eval_mul, eval_C, eval_pow, eval_X] at hx have hq0 : (q : ℝ) ≠ 0 := by exact_mod_cast (by omega : q ≠ 0) have hxp : x ^ (q - 1) = 0 := (mul_eq_zero.mp hx).resolve_left hq0 exact 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`) has at 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 := by set f : Polynomial ℝ := C c0 * X ^ p * (X ^ q + C c) ^ r - C t by_cases hdf : f.derivative = 0 · have hdeg : f.natDegree = 0 := by by_contra hpos have h1 : 1 ≤ f.natDegree := by omega have hcoeff : f.derivative.coeff (f.natDegree - 1) = (f.natDegree : ℝ) * f.leadingCoeff := by rw [coeff_derivative, Nat.sub_add_cancel h1] have hcast : ((f.natDegree - 1 : ℕ) : ℝ) + 1 = (f.natDegree : ℝ) := by exact_mod_cast Nat.sub_add_cancel h1 rw [hcast, Polynomial.coeff_natDegree, mul_comm] rw [hdf, coeff_zero] at hcoeff have hlead : f.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hne have hnd : (f.natDegree : ℝ) ≠ 0 := by exact_mod_cast (by omega : f.natDegree ≠ 0) exact mul_ne_zero hnd hlead hcoeff.symm have := card_toFinset_roots_le_natDegree f omega have hrolle := poly_real_roots_le_deriv_add_one hne hdf have hc0 : c0 ≠ 0 := by intro h0; apply hdf; simp [f, h0, derivative_C] have hpqr : p + q * r ≠ 0 := by intro h0 have hp0 : p = 0 := by omega have hr0 : r = 0 := by rcases Nat.mul_eq_zero.mp (by omega : q * r = 0) with hq0 | hr0 · omega · exact hr0 apply 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 := by intro h0; have hdeg := congrArg Polynomial.natDegree h0 rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg · simp at hdeg; omega · simp; omega have hB_ne : B ≠ 0 := by intro h0; have hdeg := congrArg Polynomial.natDegree h0 rw [natDegree_sub_eq_left_of_natDegree_lt] at hdeg · simp at hdeg; omega · simp; omega have hsub : f.derivative.roots.toFinset ⊆ ({0} : Finset ℝ) ∪ A.roots.toFinset ∪ B.roots.toFinset := by intro x hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hdf, Polynomial.IsRoot.def] at hx have 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 := by have h1 : HasDerivAt (fun y : ℝ => y ^ p) ((p : ℝ) * x ^ (p - 1)) x := hasDerivAt_pow p x have h2 : HasDerivAt (fun y : ℝ => y ^ q + c) ((q : ℝ) * x ^ (q - 1)) x := (hasDerivAt_pow q x).add_const c have h3 : HasDerivAt (fun y : ℝ => (y ^ q + c) ^ r) ((r : ℝ) * (x ^ q + c) ^ (r - 1) * ((q : ℝ) * x ^ (q - 1))) x := HasDerivAt.pow h2 r have h4 := (h1.mul h3).const_mul c0 simpa [mul_assoc, mul_add, add_mul] using h4.sub_const t have hf_fn : (fun y : ℝ => f.eval y) = (fun y : ℝ => c0 * y ^ p * (y ^ q + c) ^ r - t) := by ext 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 := by have h1 : deriv (fun y => f.eval y) x = f.derivative.eval x := Polynomial.deriv f rw [hf_fn] at h1 rw [hderiv_at.deriv] at h1 linarith have 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 hc0 by_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]; linarith have 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 := by rw [hinner, mul_zero] have hterm1 : x * ((p : ℝ) * x ^ (p - 1)) = (p : ℝ) * x ^ p := by cases p with | zero => simp | succ p' => simp [pow_succ]; ring have hterm2 : (x ^ q + c) * ((r : ℝ) * (x ^ q + c) ^ (r - 1)) = (r : ℝ) * (x ^ q + c) ^ r := by cases r with | zero => simp | succ r' => simp [pow_succ]; ring have hterm3 : x * ((q : ℝ) * x ^ (q - 1)) = (q : ℝ) * x ^ q := by have : x * x ^ (q - 1) = x ^ q := by conv_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 := by have 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))) := by ring rw [hrew, hterm1, hterm2, hterm3] at hmul push_cast linarith have hxp_ne : x ^ p ≠ 0 := pow_ne_zero p hx0 have hxqr_ne : (x ^ q + c) ^ r ≠ 0 := pow_ne_zero r hxq have 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 hpqr have : x ^ q = -(p : ℝ) * c / ((p + q * r : ℕ) : ℝ) := by rw [eq_div_iff hden]; linarith linarith have hcard_d : f.derivative.roots.toFinset.card ≤ 5 := by have h1 := Finset.card_le_card hsub have h2 := Finset.card_union_le (({0} : Finset ℝ) ∪ A.roots.toFinset) B.roots.toFinset have h3 := Finset.card_union_le ({0} : Finset ℝ) A.roots.toFinset have 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 h3 omega omega /-- **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 := by have hsub : (P.comp Q).roots.toFinset ⊆ P.roots.toFinset.biUnion (fun t => (Q - C t).roots.toFinset) := by intro x hx rw [Multiset.mem_toFinset, Polynomial.mem_roots hPQ, Polynomial.IsRoot.def, eval_comp] at hx refine 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 := by intro h0 have hQ_const : Q = C (Q.eval x) := sub_eq_zero.mp h0 have hcomp_const : P.comp Q = C (P.eval (Q.eval x)) := by conv_lhs => rw [hQ_const] rw [Polynomial.comp_C] rw [hx, map_zero] at hcomp_const exact hPQ hcomp_const rw [Multiset.mem_toFinset, Polynomial.mem_roots hQt_ne, Polynomial.IsRoot.def] simp calc (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 simp end Research.PvsNP.Tau