Lean / 0xOsprey/shub-smale-tau9 / SubquadraticRefutation.lean
Lean readerResearch/PvsNP/Tau/SubquadraticRefutation.lean
modulepublic import Research.PvsNP.Tau.ChirpZpublic import Mathlib.Analysis.SpecialFunctions.Pow.Real@[expose] public sectionnamespace Research.PvsNP.Tau/-!# Division-Free Schönhage–Nussbaumer FFT & Unconditional Refutation of Every Sub-Quadratic Exponent (`c < 2`)This module formalizes:1. Negacyclic convolution `negConv N a b` over `R = ℤ[X]` (representing multiplication in`R[Y] / (Y^N + 1)`), together with exact shift-and-negate multiplication by `Y^s` (`negShift`).2. Division-free cyclic DFT of power-of-2 size `K = 2^p` over `R[Z] / (Z^(2M) + 1)` usingthe exact power-of-`Z` root of unity `ω = Z^(2 * step)` (`K * step = 2 * M`), provingboth Cooley–Tukey `CanBuild` gate complexity `O(p * 2^p * M)` and exact orthogonality`IDFT (DFT A) = K • A` over `ℤ[X]` without divisions.3. Recursive Schönhage–Nussbaumer negacyclic multiplication of size `2^k` (with base case`k ≤ 3`), achieving exact uniform positive power-of-2 scaling `2^(snScale k)` in`snCost k ≤ C_sn * k * (Nat.log 2 k + 1) * 2^k` constant-free gates.4. Combined with `ChirpZ.zMaxGe_of_chirp_engine` at `N_fft = 2 * m = 2^(k + 1)`:- `tau_subquadratic_growth`: `∃ C > 0, ∀ k ≥ 2, zMaxGe (C * k * (Nat.log 2 k + 1) * 2^k) (2 * 4^k + 1)`.- `tau_refutes_subquadratic`: for **every real exponent `c < 2`**,`¬ ∃ a : ℝ, ∀ (τ : ℕ) (P : SLP τ), P.evalPoly ≠ 0 → (intRootCount P.evalPoly : ℝ) ≤ a * ((τ : ℝ) + 1) ^ c`.-//-! ## 1. Negacyclic Convolution and Shifts over `ℤ[X]` -//-- Exact negacyclic convolution of length `N` over `ℤ[X]`, representing the coefficient of `Y^t`in `(∑_{i < N} a i * Y^i) * (∑_{j < N} b j * Y^j) mod (Y^N + 1)`. -/noncomputable def negConv (N : ℕ) (a b : ℕ → Polynomial ℤ) (t : ℕ) : Polynomial ℤ :=∑ i ∈ Finset.range N, if i ≤ t then a i * b (t - i) else -(a i * b (t + N - i))/-- Multiplication by `Y^s` in `(ℤ[X])[Y] / (Y^N + 1)`, evaluated at coefficient `t < N`. -/noncomputable def negShift (N s : ℕ) (a : ℕ → Polynomial ℤ) (t : ℕ) : Polynomial ℤ :=(-1 : Polynomial ℤ) ^ (s / N) *(if s % N ≤ t then a (t - s % N) else -(a (t + N - s % N)))theorem negConv_chirp_eq (m i : ℕ) (hm : 1 ≤ m) (_hi : i < m) :negConv (2 * m) (chirpA m) (chirpB m) (i + m) =∑ r ∈ Finset.range (m + 1), chirpA m r * chirpB m (i + m - r) := byunfold negConvhave hsub : Finset.range (m + 1) ⊆ Finset.range (2 * m) := Finset.range_mono (by omega)rw [← Finset.sum_subset hsub]· refine Finset.sum_congr rfl ?_intro r hrrw [Finset.mem_range] at hrhave hle : r ≤ i + m := by omegasimp [hle]· intro r hr hnotrw [Finset.mem_range] at hr hnothave hgt : ¬ r ≤ m := by omegasimp [chirpA, hgt]theorem negShift_zero (N : ℕ) (_hN : 0 < N) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N 0 a t = a t := bysimp [negShift, Nat.zero_div, Nat.zero_mod]theorem negShift_add_N (N s : ℕ) (hN : 0 < N) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N (s + N) a t = -(negShift N s a t) := byunfold negShiftrw [Nat.add_div_right s hN, Nat.add_mod_right, pow_succ]ringtheorem negShift_add_mul_N (N s q : ℕ) (hN : 0 < N) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N (s + q * N) a t = (-1 : Polynomial ℤ) ^ q * negShift N s a t := byinduction q with| zero => simp| succ q ih =>rw [show s + (q + 1) * N = (s + q * N) + N by ring, negShift_add_N N _ hN, ih, pow_succ]ringtheorem negShift_mod_two_N (N s₁ s₂ : ℕ) (hN : 0 < N)(hmod : s₁ % (2 * N) = s₂ % (2 * N)) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N s₁ a t = negShift N s₂ a t := byhave hred : ∀ s, negShift N s a t = negShift N (s % (2 * N)) a t := byintro shave hdiv := Nat.div_add_mod s (2 * N)have h1 : s = s % (2 * N) + (2 * (s / (2 * N))) * N := by linarithconv_lhs => rw [h1]rw [negShift_add_mul_N N _ _ hN, pow_mul]norm_numrw [hred s₁, hred s₂, hmod]theorem negShift_add (N s₁ s₂ : ℕ) (hN : 0 < N) (a : ℕ → Polynomial ℤ) (t : ℕ) (ht : t < N) :negShift N (s₁ + s₂) a t = negShift N s₁ (negShift N s₂ a) t := byhave hdecomp : ∀ s f x,negShift N s f x = (-1 : Polynomial ℤ) ^ (s / N) * negShift N (s % N) f x := byintro s f xhave hdiv := Nat.div_add_mod s Nhave h1 : s = s % N + (s / N) * N := by linarithconv_lhs => rw [h1]rw [negShift_add_mul_N N _ _ hN]rw [hdecomp s₁, hdecomp (s₁ + s₂)]have hlinear_smul : ∀ s (c : Polynomial ℤ) f x,negShift N s (fun y => c * f y) x = c * negShift N s f x := byintro s c f x; unfold negShift; split_ifs <;> ringhave hrhs : negShift N (s₁ % N) (negShift N s₂ a) t =(-1 : Polynomial ℤ) ^ (s₂ / N) * negShift N (s₁ % N) (negShift N (s₂ % N) a) t := byhave hfn : negShift N s₂ a = fun x => (-1 : Polynomial ℤ) ^ (s₂ / N) * negShift N (s₂ % N) a x := byfunext x; exact hdecomp s₂ a xrw [hfn, hlinear_smul]rw [hrhs]set r₁ := s₁ % Nset r₂ := s₂ % Nhave hr₁ : r₁ < N := Nat.mod_lt s₁ hNhave hr₂ : r₂ < N := Nat.mod_lt s₂ hNhave hq : (s₁ + s₂) / N = s₁ / N + s₂ / N + (r₁ + r₂) / N := byhave h1 := Nat.div_add_mod s₁ Nhave h2 := Nat.div_add_mod s₂ Nhave hr1_eq : r₁ = s₁ % N := rflhave hr2_eq : r₂ = s₂ % N := rflhave h3 : s₁ + s₂ = (r₁ + r₂) + (s₁ / N + s₂ / N) * N := by linarithrw [h3, Nat.add_mul_div_right _ _ hN]omegahave hr : (s₁ + s₂) % N = (r₁ + r₂) % N := Nat.add_mod s₁ s₂ Nrw [hq, hr, pow_add, pow_add]have hcore :(-1 : Polynomial ℤ) ^ ((r₁ + r₂) / N) * negShift N ((r₁ + r₂) % N) a t =negShift N r₁ (negShift N r₂ a) t := byunfold negShifthave hdiv1 : r₁ / N = 0 := Nat.div_eq_of_lt hr₁have hmod1 : r₁ % N = r₁ := Nat.mod_eq_of_lt hr₁have hdiv2 : r₂ / N = 0 := Nat.div_eq_of_lt hr₂have hmod2 : r₂ % N = r₂ := Nat.mod_eq_of_lt hr₂have hmod_lt : (r₁ + r₂) % N < N := Nat.mod_lt _ hNhave hdiv_m : ((r₁ + r₂) % N) / N = 0 := Nat.div_eq_of_lt hmod_lthave hmod_m : ((r₁ + r₂) % N) % N = (r₁ + r₂) % N := Nat.mod_eq_of_lt hmod_ltsimp only [hdiv1, hmod1, hdiv2, hmod2, hdiv_m, hmod_m, pow_zero, one_mul]by_cases hsum : r₁ + r₂ < N· have hd0 : (r₁ + r₂) / N = 0 := Nat.div_eq_of_lt hsumhave hm0 : (r₁ + r₂) % N = r₁ + r₂ := Nat.mod_eq_of_lt hsumrw [hd0, hm0, pow_zero, one_mul]by_cases ht1 : r₁ ≤ t· by_cases ht2 : r₂ ≤ t - r₁· have ht12 : r₁ + r₂ ≤ t := by omegahave hidx : t - (r₁ + r₂) = t - r₁ - r₂ := by omegasimp [ht1, ht2, ht12, hidx]· have ht12 : ¬ (r₁ + r₂ ≤ t) := by omegahave hidx : t + N - (r₁ + r₂) = t - r₁ + N - r₂ := by omegasimp [ht1, ht2, ht12, hidx]· have ht12 : ¬ (r₁ + r₂ ≤ t) := by omegahave ht2 : r₂ ≤ t + N - r₁ := by omegahave hidx : t + N - (r₁ + r₂) = t + N - r₁ - r₂ := by omegasimp [ht1, ht2, ht12, hidx]· have hlt2N : r₁ + r₂ - N < N := by omegahave hsum_eq : r₁ + r₂ = (r₁ + r₂ - N) + N := by omegahave hd1 : (r₁ + r₂) / N = 1 := byrw [hsum_eq, Nat.add_div_right _ hN, Nat.div_eq_of_lt hlt2N]have hm1 : (r₁ + r₂) % N = r₁ + r₂ - N := byconv_lhs => rw [hsum_eq]rw [Nat.add_mod_right, Nat.mod_eq_of_lt hlt2N]rw [hd1, hm1, pow_one]by_cases ht1 : r₁ ≤ t· have ht2 : ¬ (r₂ ≤ t - r₁) := by omegahave ht12 : r₁ + r₂ - N ≤ t := by omegahave hidx : t - (r₁ + r₂ - N) = t - r₁ + N - r₂ := by omegasimp [ht1, ht2, ht12, hidx]· by_cases ht2 : r₂ ≤ t + N - r₁· have ht12 : r₁ + r₂ - N ≤ t := by omegahave hidx : t - (r₁ + r₂ - N) = t + N - r₁ - r₂ := by omegasimp [ht1, ht2, ht12, hidx]· have ht12 : ¬ (r₁ + r₂ - N ≤ t) := by omegahave hidx : t + N - (r₁ + r₂ - N) = t + N - r₁ + N - r₂ := by omegasimp [ht1, ht2, ht12, hidx]calc(-1 : Polynomial ℤ) ^ (s₁ / N) * (-1 : Polynomial ℤ) ^ (s₂ / N) *(-1 : Polynomial ℤ) ^ ((r₁ + r₂) / N) * negShift N ((r₁ + r₂) % N) a t= (-1 : Polynomial ℤ) ^ (s₁ / N) * (-1 : Polynomial ℤ) ^ (s₂ / N) *((-1 : Polynomial ℤ) ^ ((r₁ + r₂) / N) * negShift N ((r₁ + r₂) % N) a t) := by ring_ = (-1 : Polynomial ℤ) ^ (s₁ / N) * ((-1 : Polynomial ℤ) ^ (s₂ / N) *negShift N r₁ (negShift N r₂ a) t) := by rw [hcore]; ringtheorem negShift_add_linear (N s : ℕ) (a b : ℕ → Polynomial ℤ) (t : ℕ) :negShift N s (fun x => a x + b x) t = negShift N s a t + negShift N s b t := byunfold negShift; split_ifs <;> ringtheorem negShift_neg_linear (N s : ℕ) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N s (fun x => -(a x)) t = -(negShift N s a t) := byunfold negShift; split_ifs <;> ringtheorem negShift_smul_linear (N s : ℕ) (c : Polynomial ℤ) (a : ℕ → Polynomial ℤ) (t : ℕ) :negShift N s (fun x => c * a x) t = c * negShift N s a t := byunfold negShift; split_ifs <;> ringtheorem negShift_finset_sum {ι : Type*} (S : Finset ι) (N s : ℕ)(f : ι → ℕ → Polynomial ℤ) (t : ℕ) :negShift N s (fun x => ∑ i ∈ S, f i x) t = ∑ i ∈ S, negShift N s (f i) t := byclassicalinduction S using Finset.induction_on with| empty => simp [negShift]| insert i S hi ih =>simp only [Finset.sum_insert hi]rw [negShift_add_linear, ih]theorem negConv_add_left (N : ℕ) (a₁ a₂ b : ℕ → Polynomial ℤ) (t : ℕ) :negConv N (fun i => a₁ i + a₂ i) b t = negConv N a₁ b t + negConv N a₂ b t := byunfold negConvrw [← Finset.sum_add_distrib]refine Finset.sum_congr rfl ?_intro i _; split_ifs <;> ringtheorem negConv_add_right (N : ℕ) (a b₁ b₂ : ℕ → Polynomial ℤ) (t : ℕ) :negConv N a (fun j => b₁ j + b₂ j) t = negConv N a b₁ t + negConv N a b₂ t := byunfold negConvrw [← Finset.sum_add_distrib]refine Finset.sum_congr rfl ?_intro i _; split_ifs <;> ringtheorem negConv_sum_left {ι : Type*} (S : Finset ι) (N : ℕ)(f : ι → ℕ → Polynomial ℤ) (b : ℕ → Polynomial ℤ) (t : ℕ) :negConv N (fun i => ∑ u ∈ S, f u i) b t = ∑ u ∈ S, negConv N (f u) b t := byclassicalinduction S using Finset.induction_on with| empty => simp [negConv]| insert u S hu ih =>simp only [Finset.sum_insert hu]rw [negConv_add_left, ih]theorem negConv_sum_right {ι : Type*} (S : Finset ι) (N : ℕ)(a : ℕ → Polynomial ℤ) (g : ι → ℕ → Polynomial ℤ) (t : ℕ) :negConv N a (fun j => ∑ v ∈ S, g v j) t = ∑ v ∈ S, negConv N a (g v) t := byclassicalinduction S using Finset.induction_on with| empty => simp [negConv]| insert v S hv ih =>simp only [Finset.sum_insert hv]rw [negConv_add_right, ih]theorem negConv_neg_left (N : ℕ) (a b : ℕ → Polynomial ℤ) (t : ℕ) :negConv N (fun i => -(a i)) b t = -(negConv N a b t) := byunfold negConvrw [← Finset.sum_neg_distrib]refine Finset.sum_congr rfl ?_intro i _; split_ifs <;> ringtheorem negConv_neg_right (N : ℕ) (a b : ℕ → Polynomial ℤ) (t : ℕ) :negConv N a (fun j => -(b j)) t = -(negConv N a b t) := byunfold negConvrw [← Finset.sum_neg_distrib]refine Finset.sum_congr rfl ?_intro i _; split_ifs <;> ringtheorem negConv_congr_left (N : ℕ) (a₁ a₂ b : ℕ → Polynomial ℤ)(h : ∀ i < N, a₁ i = a₂ i) (t : ℕ) :negConv N a₁ b t = negConv N a₂ b t := byunfold negConvrefine Finset.sum_congr rfl ?_intro i hirw [h i (Finset.mem_range.mp hi)]theorem negShift_congr (N s : ℕ) (hN : 0 < N) (a₁ a₂ : ℕ → Polynomial ℤ)(h : ∀ i < N, a₁ i = a₂ i) (t : ℕ) (ht : t < N) :negShift N s a₁ t = negShift N s a₂ t := byunfold negShifthave hmod : s % N < N := Nat.mod_lt s hNsplit_ifs with hst· rw [h (t - s % N) (by omega)]· rw [h (t + N - s % N) (by omega)]theorem negConv_comm (N : ℕ) (a b : ℕ → Polynomial ℤ) (t : ℕ) (ht : t < N) :negConv N a b t = negConv N b a t := byunfold negConvrefine Finset.sum_bij (fun i _ => if i ≤ t then t - i else t + N - i) ?_ ?_ ?_ ?_· intro i hi; rw [Finset.mem_range] at hi ⊢; split_ifs <;> omega· intro i₁ hi₁ i₂ hi₂ heq; rw [Finset.mem_range] at hi₁ hi₂; split_ifs at heq <;> omega· intro j hj; rw [Finset.mem_range] at hjby_cases hjt : j ≤ t· refine ⟨t - j, Finset.mem_range.mpr (by omega), ?_⟩have : t - j ≤ t := by omegasimp [this]; omega· refine ⟨t + N - j, Finset.mem_range.mpr (by omega), ?_⟩have : ¬ (t + N - j ≤ t) := by omegasimp [this]; omega· intro i hi; rw [Finset.mem_range] at hiby_cases hit : i ≤ t· have hj : t - i ≤ t := by omegahave hb : t - (t - i) = i := by omegasimp [hit, hj, hb, mul_comm]· have hj : ¬ (t + N - i ≤ t) := by omegahave hb : t + N - (t + N - i) = i := by omegasimp [hit, hj, hb, mul_comm]/-- Shifting `a` by `Y^s` commutes with `negConv N`. -/theorem negConv_negShift_left (N s : ℕ) (hN : 0 < N) (a b : ℕ → Polynomial ℤ)(t : ℕ) (ht : t < N) :negConv N (negShift N s a) b t = negShift N s (negConv N a b) t := byhave hstep1 : ∀ (f : ℕ → Polynomial ℤ) (u : ℕ), u < N →negConv N (negShift N 1 f) b u = negShift N 1 (negConv N f b) u := byintro f u huby_cases hN1 : N = 1· subst hN1have hu0 : u = 0 := by omegasubst hu0simp [negConv, negShift]· have h1lt : 1 < N := by omegahave hdiv1 : 1 / N = 0 := Nat.div_eq_of_lt h1lthave hmod1 : 1 % N = 1 := Nat.mod_eq_of_lt h1ltunfold negConv negShiftsimp only [hdiv1, hmod1, pow_zero, one_mul]have hLHS :∑ i ∈ Finset.range N,(if i ≤ u then (if 1 ≤ i then f (i - 1) else -f (i + N - 1)) * b (u - i)else -((if 1 ≤ i then f (i - 1) else -f (i + N - 1)) * b (u + N - i))) =∑ j ∈ Finset.range N,if 1 ≤ u thenif j ≤ u - 1 then f j * b (u - 1 - j) else -(f j * b (u - 1 + N - j))else-(if j ≤ u + N - 1 then f j * b (u + N - 1 - j) else -(f j * b (u + N - 1 + N - j))) := byrefine Finset.sum_bij (fun i _ => if 1 ≤ i then i - 1 else N - 1) ?_ ?_ ?_ ?_· intro i hi; rw [Finset.mem_range] at hi ⊢; split_ifs <;> omega· intro i₁ hi₁ i₂ hi₂ heq; rw [Finset.mem_range] at hi₁ hi₂; split_ifs at heq <;> omega· intro j hj; rw [Finset.mem_range] at hjby_cases hjN : j = N - 1· exact ⟨0, Finset.mem_range.mpr (by omega), by simp [hjN]⟩· exact ⟨j + 1, Finset.mem_range.mpr (by omega), by simp⟩· intro i hirw [Finset.mem_range] at hiby_cases hi1 : 1 ≤ i· by_cases hu1 : 1 ≤ u· by_cases hiu : i ≤ u· have hj : i - 1 ≤ u - 1 := by omegahave hb : u - i = u - 1 - (i - 1) := by omegasimp [hi1, hu1, hiu, hj, hb]· have hj : ¬ (i - 1 ≤ u - 1) := by omegahave hb : u + N - i = u - 1 + N - (i - 1) := by omegasimp [hi1, hu1, hiu, hj, hb]· have hu0 : u = 0 := by omegahave hiu : ¬ (i ≤ u) := by omegahave hj : i - 1 ≤ u + N - 1 := by omegahave hb : u + N - i = u + N - 1 - (i - 1) := by omegasimp [hi1, hu1, hiu, hj, hb]· have hi0 : i = 0 := by omegasubst hi0by_cases hu1 : 1 ≤ u· have hiu : 0 ≤ u := by omegahave hj : ¬ (N - 1 ≤ u - 1) := by omegahave hb : u - 0 = u - 1 + N - (N - 1) := by omegasimp only [Nat.not_le.mpr (by omega : 0 < 1), ↓reduceIte, hiu, hu1, hj, Nat.zero_add,hb]ring· have hu0 : u = 0 := by omegasubst hu0have hj : N - 1 ≤ 0 + N - 1 := by omegahave hb : 0 + N - 1 - (N - 1) = 0 := by omegasimprw [hLHS]by_cases hu1 : 1 ≤ u· simp [hu1]· simp [hu1, Finset.sum_neg_distrib]induction s generalizing t with| zero =>rw [negConv_congr_left N _ a b (fun i _ => negShift_zero N hN a i), negShift_zero N hN]| succ s ih =>rw [negConv_congr_left N _ (negShift N 1 (negShift N s a)) b(fun i hi => by rw [Nat.add_comm, negShift_add N 1 s hN a i hi])]rw [hstep1 (negShift N s a) t ht]rw [negShift_congr N 1 hN _ (negShift N s (negConv N a b)) (fun i hi => ih i hi) t ht]rw [← negShift_add N 1 s hN _ t ht, Nat.add_comm]/-- Shifting `b` by `Y^s` commutes with `negConv N`. -/theorem negConv_negShift_right (N s : ℕ) (hN : 0 < N) (a b : ℕ → Polynomial ℤ)(t : ℕ) (ht : t < N) :negConv N a (negShift N s b) t = negShift N s (negConv N a b) t := byrw [negConv_comm N a _ t ht, negConv_negShift_left N s hN b a t ht]exact negShift_congr N s hN _ _ (fun i hi => negConv_comm N b a i hi) t ht/-! ## 2. `CanBuild` for `negShift` and Schoolbook Base Case (`k ≤ 3`) -//-- Applying `negShift N s` to a length-`N` vector costs at most `N` gates (`0 - a j`). -/theorem canBuild_negShift (N s : ℕ) (hN : 0 < N) (a : ℕ → Polynomial ℤ) :CanBuild ({(0 : Polynomial ℤ)} ∪ ⋃ i < N, {a i}) N(⋃ t < N, {negShift N s a t}) := byhave h := canBuild_fin_union (n := N) (d := 1)(S := {(0 : Polynomial ℤ)} ∪ ⋃ i < N, {a i})(T := fun t => {negShift N s a t}) (byintro t hthave hmod : s % N < N := Nat.mod_lt s hNset j := if s % N ≤ t then t - s % N else t + N - s % Nhave hj : j < N := by dsimp only [j]; split_ifs <;> omegahave hval : negShift N s a t = a j ∨ negShift N s a t = -(a j) := byunfold negShiftrcases Nat.even_or_odd (s / N) with ⟨m, hm⟩ | ⟨m, hm⟩· rw [hm, show m + m = 2 * m by ring, pow_mul]norm_numsplit_ifs with hst· left; simp [j, hst]· right; simp [j, hst]· rw [hm, pow_add, pow_mul]norm_numsplit_ifs with hst· right; simp [j, hst]· left; simp [j, hst]rcases hval with hpos | hneg· refine canBuild_mono_cost (by omega : 0 ≤ 1) (canBuild_subset ?_)intro x hx; rw [Set.mem_singleton_iff] at hx; subst hxrw [hpos]; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨j, hj, rfl⟩· have hsub := canBuild_sub (0 : Polynomial ℤ) (a j)refine canBuild_mono_out (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; rw [hneg]; simp)(canBuild_mono_in ?_ hsub)intro x hxrcases hx with rfl | rfl· left; rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨j, hj, rfl⟩)simpa using h/-- Schoolbook negacyclic convolution of length `N` costs `3 * N * N` gates. -/theorem canBuild_negConv_schoolbook (N : ℕ) (a b : ℕ → Polynomial ℤ) :CanBuild ({(0 : Polynomial ℤ)} ∪ (⋃ i < N, {a i}) ∪ (⋃ j < N, {b j})) (3 * N * N)(⋃ t < N, {negConv N a b t}) := byhave h1 := canBuild_fin_union (n := N) (d := 3 * N)(S := {(0 : Polynomial ℤ)} ∪ (⋃ i < N, {a i}) ∪ (⋃ j < N, {b j}))(T := fun t => {negConv N a b t}) (byintro t htlet term : ℕ → Polynomial ℤ := fun i =>if i ≤ t then a i * b (t - i) else -(a i * b (t + N - i))have hterms : CanBuild ({(0 : Polynomial ℤ)} ∪ (⋃ i < N, {a i}) ∪ (⋃ j < N, {b j}))(N * 2) (⋃ i < N, {term i}) := byrefine canBuild_fin_union (n := N) (d := 2) (T := fun i => {term i}) ?_intro i hiby_cases hit : i ≤ t· have hm := canBuild_mul (a i) (b (t - i))refine canBuild_mono_cost (by omega : 1 ≤ 2)(canBuild_mono_out (by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; simp [term, hit])(canBuild_mono_in ?_ hm))intro x hxrcases hx with rfl | rfl· left; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨t - i, by omega, rfl⟩· have hm := canBuild_mul (a i) (b (t + N - i))have hn := canBuild_sub (0 : Polynomial ℤ) (a i * b (t + N - i))have hmn := canBuild_trans(canBuild_mono_in (S₂ := {(0 : Polynomial ℤ), a i, b (t + N - i)})(by intro x hx; rcases hx with rfl | rfl <;> simp) hm)(by intro x hx; rcases hx with rfl | rfl <;> simp) hnrefine canBuild_mono_out(by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; right; simp [term, hit])(canBuild_mono_in ?_ hmn)intro x hxrcases hx with rfl | rfl | rfl· left; left; rfl· left; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨t + N - i, by omega, rfl⟩have hsum := canBuild_fin_sum N termhave hcomb := canBuild_trans hterms (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; exact hx') hsumhave hcost : N * 2 + N = 3 * N := by ringrw [hcost] at hcombexact canBuild_mono_out (fun x hx => Or.inr hx) hcomb)have hcost : N * (3 * N) = 3 * N * N := by ringrwa [hcost] at h1/-! ## 3. Division-Free Cyclic DFT over `R[Z] / (Z^L + 1)` -//-- Exact cyclic DFT of length `K` in `R[Z] / (Z^L + 1)` using twiddle angle `ang`(multiplication by `Z^(ang * u * j)`):`ringDFT L K ang A u t = ∑_{j < K} negShift L (ang * u * j) (A j) t`. -/noncomputable def ringDFT (L K ang : ℕ) (A : ℕ → ℕ → Polynomial ℤ) (u t : ℕ) : Polynomial ℤ :=∑ j ∈ Finset.range K, negShift L (ang * u * j) (A j) t/-- Exact orthogonality of `ringDFT` over any commutative ring (zero divisions!):if `K = 2^p` and `K * step = L` (`L > 0`), then for `0 < d < K`:`∑_{u < K} negShift L (2 * step * u * d) x t = 0` for all `t < L`. -/theorem negShift_geom_sum_zero :∀ (p step L : ℕ), 0 < L → 2 ^ p * step = L →∀ (d : ℕ), 0 < d → d < 2 ^ p →∀ (x : ℕ → Polynomial ℤ) (t : ℕ), t < L →∑ u ∈ Finset.range (2 ^ p), negShift L (2 * step * u * d) x t = 0| 0, _, _, _, _, d, hd0, hd1, _, _, _ => by simp at hd1; omega| p + 1, step, L, hL, hKS, d, hd0, hd1, x, t, ht => byhave h2p : 2 ^ (p + 1) = 2 ^ p + 2 ^ p := by rw [pow_succ]; ringrw [h2p, Finset.sum_range_add, ← Finset.sum_add_distrib]have hshift_half : ∀ u : ℕ,negShift L (2 * step * (2 ^ p + u) * d) x t =(-1 : Polynomial ℤ) ^ d * negShift L (2 * step * u * d) x t := byintro uhave heq : 2 * step * (2 ^ p + u) * d = 2 * step * u * d + d * L := byhave : 2 * 2 ^ p * step = L := by rw [← hKS, pow_succ]; ringcalc 2 * step * (2 ^ p + u) * d = 2 * step * u * d + d * (2 * 2 ^ p * step) := by ring_ = 2 * step * u * d + d * L := by rw [this]rw [heq, negShift_add_mul_N L _ d hL]rcases Nat.even_or_odd d with ⟨d', hd'⟩ | ⟨d', hd'⟩· have hsum2 :∑ u ∈ Finset.range (2 ^ p),(negShift L (2 * step * u * d) x t + negShift L (2 * step * (2 ^ p + u) * d) x t) =2 * ∑ u ∈ Finset.range (2 ^ p), negShift L (2 * (2 * step) * u * d') x t := byrw [Finset.mul_sum]refine Finset.sum_congr rfl ?_intro u _rw [hshift_half u, hd', show d' + d' = 2 * d' by ring, pow_mul]have harg : 2 * step * u * (2 * d') = 2 * (2 * step) * u * d' := by ringrw [harg]norm_numringrw [hsum2]have hKS' : 2 ^ p * (2 * step) = L := by rw [← hKS, pow_succ]; ringhave hzero := negShift_geom_sum_zero p (2 * step) L hL hKS' d' (by omega) (by omega) x t htrw [hzero, mul_zero]· refine Finset.sum_eq_zero ?_intro u _rw [hshift_half u, hd', pow_add, pow_mul]norm_num/-- **Exact Inversion of Division-Free `ringDFT`:**If `K = 2^p`, `K * step = L` (`L > 0`), and `ang = 2 * step`, `angInv = 2 * step * (K - 1)`,then `ringDFT L K angInv (ringDFT L K ang A) v t = (K : Polynomial ℤ) * A v t` for all `v < K, t < L`. -/theorem ringDFT_inversion (p step L : ℕ) (hL : 0 < L) (hKS : 2 ^ p * step = L)(A : ℕ → ℕ → Polynomial ℤ) (v t : ℕ) (hv : v < 2 ^ p) (ht : t < L) :ringDFT L (2 ^ p) (2 * step * (2 ^ p - 1)) (ringDFT L (2 ^ p) (2 * step) A) v t =((2 ^ p : ℕ) : Polynomial ℤ) * A v t := byset K := 2 ^ phave hKpos : 1 ≤ K := Nat.one_le_two_powunfold ringDFT-- Push `negShift` inside the inner sum and swap sums over `u` and `j`have hpush :∑ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u)(fun x => ∑ j ∈ Finset.range K, negShift L (2 * step * u * j) (A j) x) t =∑ j ∈ Finset.range K,∑ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u + 2 * step * u * j) (A j) t := byhave h1 :∀ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u)(fun x => ∑ j ∈ Finset.range K, negShift L (2 * step * u * j) (A j) x) t =∑ j ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u + 2 * step * u * j) (A j) t := byintro u _rw [negShift_finset_sum]refine Finset.sum_congr rfl ?_intro j _rw [negShift_add L _ _ hL _ t ht]rw [Finset.sum_congr rfl h1, Finset.sum_comm]rw [hpush]-- Simplify the inner sum for each `j < K`: equals `K * A v t` if `j = v`, and `0` if `j ≠ v`have hinner :∀ j ∈ Finset.range K,(∑ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u + 2 * step * u * j) (A j) t) =if j = v then ((K : ℕ) : Polynomial ℤ) * A j t else 0 := byintro j hjrw [Finset.mem_range] at hjby_cases hjv : j = v· subst hjvsimp only [↓reduceIte]have hterm : ∀ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * j * u + 2 * step * u * j) (A j) t = A j t := byintro u _have hmod : (2 * step * (K - 1) * j * u + 2 * step * u * j) % (2 * L) = 0 % (2 * L) := byhave heq : 2 * step * (K - 1) * j * u + 2 * step * u * j = (j * u) * (2 * L) := byhave hK1 : (K - 1) + 1 = K := by omegacalc 2 * step * (K - 1) * j * u + 2 * step * u * j= 2 * step * ((K - 1) + 1) * j * u := by ring_ = 2 * step * K * j * u := by rw [hK1]_ = (j * u) * (2 * (K * step)) := by ring_ = (j * u) * (2 * L) := by rw [hKS]rw [heq, Nat.mul_mod_left, Nat.zero_mod]rw [negShift_mod_two_N L _ 0 hL hmod, negShift_zero L hL]rw [Finset.sum_congr rfl hterm, Finset.sum_const, Finset.card_range, nsmul_eq_mul]· simp only [hjv, ↓reduceIte]set d := (j + K - v) % Khave hd0 : 0 < d := bydsimp only [d]by_cases hlt : v < j· have : (j + K - v) % K = j - v := byrw [show j + K - v = (j - v) + K by omega, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)]omega· have : (j + K - v) % K = j + K - v := Nat.mod_eq_of_lt (by omega)omegahave hdK : d < K := Nat.mod_lt _ (by omega)have hmod_term : ∀ u ∈ Finset.range K,negShift L (2 * step * (K - 1) * v * u + 2 * step * u * j) (A j) t =negShift L (2 * step * u * d) (A j) t := byintro u _refine negShift_mod_two_N L _ _ hL ?_ (A j) t-- Both exponents are congruent mod `2 * L = 2 * K * step`have hmodK : ((K - 1) * v + j) % K = d := byrcases Nat.eq_zero_or_pos v with rfl | hvpos· simp [d]· have h1 : (K - 1) * v + j = (j + K - v) + (v - 1) * K := byzify [hKpos, hvpos, show v ≤ j + K by omega]; ringrw [h1, Nat.add_mul_mod_self_right]have hmul : (2 * step * u * ((K - 1) * v + j)) % (2 * L) = (2 * step * u * d) % (2 * L) := byhave hdiv := Nat.div_add_mod ((K - 1) * v + j) Khave h2 : (K - 1) * v + j = d + (((K - 1) * v + j) / K) * K := by linarithrw [h2, mul_add]have h3 : 2 * step * u * ((((K - 1) * v + j) / K) * K) =(u * (((K - 1) * v + j) / K)) * (2 * L) := byrw [← hKS]; ringrw [h3, Nat.add_mul_mod_self_right]have hcomm : 2 * step * (K - 1) * v * u + 2 * step * u * j =2 * step * u * ((K - 1) * v + j) := by ringrw [hcomm, hmul]rw [Finset.sum_congr rfl hmod_term]exact negShift_geom_sum_zero p step L hL hKS d hd0 hdK (A j) t htrw [Finset.sum_congr rfl hinner, Finset.sum_ite_eq']simp [hv]/-- **Convolution Theorem for `ringDFT`:**If `K = 2^p` and `K * step = L` (`L > 0`), then pointwise `negConv L` in the `ringDFT` domaininverts to `K` times the cyclic convolution in `R[Z]/(Z^L + 1)`. -/theorem ringDFT_convolution (p step L : ℕ) (hL : 0 < L) (hKS : 2 ^ p * step = L)(A B : ℕ → ℕ → Polynomial ℤ) (v t : ℕ) (hv : v < 2 ^ p) (ht : t < L) :ringDFT L (2 ^ p) (2 * step * (2 ^ p - 1))(fun u => negConv L (ringDFT L (2 ^ p) (2 * step) A u)(ringDFT L (2 ^ p) (2 * step) B u)) v t =((2 ^ p : ℕ) : Polynomial ℤ) *∑ j₁ ∈ Finset.range (2 ^ p),negConv L (A j₁) (B ((v + 2 ^ p - j₁) % 2 ^ p)) t := byset K := 2 ^ p-- Expand pointwise product as `ringDFT` of the cyclic convolution `C`!let C : ℕ → ℕ → Polynomial ℤ := fun w x =>∑ j₁ ∈ Finset.range K, negConv L (A j₁) (B ((w + K - j₁) % K)) xhave hpointwise : ∀ u < K, ∀ x < L,negConv L (ringDFT L K (2 * step) A u) (ringDFT L K (2 * step) B u) x =ringDFT L K (2 * step) C u x := byintro u _ x hxunfold ringDFTrw [negConv_sum_left]simp_rw [negConv_sum_right]have hshift :∑ j₁ ∈ Finset.range K, ∑ j₂ ∈ Finset.range K,negConv L (negShift L (2 * step * u * j₁) (A j₁))(negShift L (2 * step * u * j₂) (B j₂)) x =∑ j₁ ∈ Finset.range K, ∑ j₂ ∈ Finset.range K,negShift L (2 * step * u * (j₁ + j₂)) (negConv L (A j₁) (B j₂)) x := byrefine Finset.sum_congr rfl ?_intro j₁ _refine Finset.sum_congr rfl ?_intro j₂ _rw [negConv_negShift_left L _ hL _ _ x hx]rw [negShift_congr L _ hL _ _ (fun y hy => negConv_negShift_right L _ hL (A j₁) (B j₂) y hy) x hx]rw [← negShift_add L _ _ hL _ x hx]congr 1ringrw [hshift]have hrhs :∑ w ∈ Finset.range K, negShift L (2 * step * u * w) (C w) x =∑ j₁ ∈ Finset.range K, ∑ w ∈ Finset.range K,negShift L (2 * step * u * w) (negConv L (A j₁) (B ((w + K - j₁) % K))) x := bysimp_rw [C, negShift_finset_sum]exact Finset.sum_commrw [hrhs]refine Finset.sum_congr rfl ?_intro j₁ hj₁rw [Finset.mem_range] at hj₁refine Finset.sum_bij (fun j₂ _ => (j₁ + j₂) % K) ?_ ?_ ?_ ?_· intro j₂ _; exact Finset.mem_range.mpr (Nat.mod_lt _ (by positivity))· intro a ha b hb heqrw [Finset.mem_range] at ha hbhave hsub : ∀ z < K, ((j₁ + z) % K + K - j₁) % K = z := byintro z hzby_cases hlt : j₁ + z < K· rw [Nat.mod_eq_of_lt hlt, show j₁ + z + K - j₁ = z + K by omega,Nat.add_mod_right, Nat.mod_eq_of_lt hz]· have hmod_sub : (j₁ + z) % K = j₁ + z - K := byhave h1 : j₁ + z = (j₁ + z - K) + K := by omegaconv_lhs => rw [h1]rw [Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)]rw [hmod_sub, show j₁ + z - K + K - j₁ = z by omega, Nat.mod_eq_of_lt hz]rw [← hsub a ha, ← hsub b hb, heq]· intro w hwrw [Finset.mem_range] at hwrefine ⟨(w + K - j₁) % K, Finset.mem_range.mpr (Nat.mod_lt _ (by positivity)), ?_⟩by_cases hlt : j₁ ≤ w· rw [show w + K - j₁ = (w - j₁) + K by omega, Nat.add_mod_right,Nat.mod_eq_of_lt (by omega : w - j₁ < K), show j₁ + (w - j₁) = w by omega,Nat.mod_eq_of_lt hw]· rw [Nat.mod_eq_of_lt (by omega : w + K - j₁ < K),show j₁ + (w + K - j₁) = w + K by omega, Nat.add_mod_right, Nat.mod_eq_of_lt hw]· intro j₂ hj₂rw [Finset.mem_range] at hj₂have hback : ((j₁ + j₂) % K + K - j₁) % K = j₂ := byby_cases hlt : j₁ + j₂ < K· rw [Nat.mod_eq_of_lt hlt, show j₁ + j₂ + K - j₁ = j₂ + K by omega,Nat.add_mod_right, Nat.mod_eq_of_lt hj₂]· have hmod_sub : (j₁ + j₂) % K = j₁ + j₂ - K := byhave h1 : j₁ + j₂ = (j₁ + j₂ - K) + K := by omegaconv_lhs => rw [h1]rw [Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)]rw [hmod_sub, show j₁ + j₂ - K + K - j₁ = j₂ by omega, Nat.mod_eq_of_lt hj₂]rw [hback]refine negShift_mod_two_N L _ _ hL ?_ _ xhave hdiv := Nat.div_add_mod (j₁ + j₂) Khave h1 : j₁ + j₂ = (j₁ + j₂) % K + ((j₁ + j₂) / K) * K := by linarithconv_lhs => rw [h1]rw [mul_add]have h2 : 2 * step * u * (((j₁ + j₂) / K) * K) = (u * ((j₁ + j₂) / K)) * (2 * L) := byrw [← hKS]; ringrw [h2, Nat.add_mul_mod_self_right]have hcongr :ringDFT L K (2 * step * (K - 1))(fun u => negConv L (ringDFT L K (2 * step) A u) (ringDFT L K (2 * step) B u)) v t =ringDFT L K (2 * step * (K - 1)) (ringDFT L K (2 * step) C) v t := byunfold ringDFTrefine Finset.sum_congr rfl ?_intro u huexact negShift_congr L _ hL _ _ (fun x hx => hpointwise u (Finset.mem_range.mp hu) x hx) t htrw [hcongr]exact ringDFT_inversion p step L hL hKS C v t hv ht/-- Cooley–Tukey gate cost for `ringDFT` of size `2^p` on length-`L` vectors: `3 * p * 2^p * L`. -/def dftCost (p L : ℕ) : ℕ := 3 * p * 2 ^ p * L/-- **Cooley–Tukey Butterfly `CanBuild` for `ringDFT`:**Given `{0} ∪ {A j t | j < 2^p, t < L}`, computes `{ringDFT L (2^p) ang A u t | u < 2^p, t < L}`in `dftCost p L = 3 * p * 2^p * L` gates, whenever `2^p * ang` is a multiple of `2 * L`(Wait: specifically whenever `2^(p - 1) * ang ≡ L (mod 2 * L)`, i.e. `ang = 2 * step * c` with `c` oddand `2^p * step = L`!). -/theorem canBuild_ringDFT :∀ (p step c L : ℕ), 0 < L → 2 ^ p * step = L → Odd c →∀ (A : ℕ → ℕ → Polynomial ℤ),CanBuild({(0 : Polynomial ℤ)} ∪ ⋃ j < 2 ^ p, ⋃ t < L, {A j t})(dftCost p L)(⋃ u < 2 ^ p, ⋃ t < L, {ringDFT L (2 ^ p) (2 * step * c) A u t})| 0, step, c, L, hL, _, _, A => bysimp only [dftCost, mul_zero, zero_mul]refine canBuild_subset ?_intro x hxsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxrcases hx with ⟨u, hu, t, ht, rfl⟩have hu0 : u = 0 := by omegasubst hu0rightsimp only [Set.mem_iUnion, exists_prop]refine ⟨0, by omega, t, ht, ?_⟩simp [ringDFT, negShift_zero L hL]| p + 1, step, c, L, hL, hKS, hc, A => byset K' := 2 ^ phave hKS' : K' * (2 * step) = L := by rw [← hKS, pow_succ]; ringlet Aeven : ℕ → ℕ → Polynomial ℤ := fun j => A (2 * j)let Aodd : ℕ → ℕ → Polynomial ℤ := fun j => A (2 * j + 1)let E := ringDFT L K' (2 * (2 * step) * c) Aevenlet O := ringDFT L K' (2 * (2 * step) * c) Aoddlet T : ℕ → ℕ → Polynomial ℤ := fun u => negShift L (2 * step * c * u) (O u)set S0 : Set (Polynomial ℤ) :={(0 : Polynomial ℤ)} ∪ ⋃ j < 2 ^ (p + 1), ⋃ t < L, {A j t}-- Step 1: Recursive DFT on Aeven and Aodd (`2 * dftCost p L` gates)have hE := canBuild_ringDFT p (2 * step) c L hL hKS' hc Aevenhave hO := canBuild_ringDFT p (2 * step) c L hL hKS' hc Aoddhave c1 := canBuild_mono_in (S₂ := S0) (byintro x hx; rcases hx with rfl | hx'· left; rfl· right; simp only [Set.mem_iUnion, exists_prop] at hx' ⊢rcases hx' with ⟨j, hj, t, ht, hxt⟩exact ⟨2 * j, by rw [pow_succ]; omega, t, ht, hxt⟩) hEhave c2 := canBuild_trans c1 (byintro x hx; rcases hx with rfl | hx'· left; left; rfl· left; right; simp only [Set.mem_iUnion, exists_prop] at hx' ⊢rcases hx' with ⟨j, hj, t, ht, hxt⟩exact ⟨2 * j + 1, by rw [pow_succ]; omega, t, ht, hxt⟩) hO-- Step 2: Twiddle O u by `2 * step * c * u` for `u < K'` (`K' * L` gates)have hT :CanBuild ({(0 : Polynomial ℤ)} ∪ ⋃ u < K', ⋃ t < L, {O u t})(K' * L) (⋃ u < K', ⋃ t < L, {T u t}) := byrefine canBuild_fin_union (n := K') (d := L) (T := fun u => ⋃ t < L, {T u t}) ?_intro u hurefine canBuild_mono_in ?_ (canBuild_negShift L (2 * step * c * u) hL (O u))intro x hx; rcases hx with rfl | hx'· left; rfl· right; simp only [Set.mem_iUnion, exists_prop] at hx' ⊢rcases hx' with ⟨t, ht, hxt⟩; exact ⟨u, hu, t, ht, hxt⟩have c3 := canBuild_trans c2 (byintro x hx; rcases hx with rfl | hx'· left; left; rfl· right; right; exact hx') hT-- Step 3: Butterflies `E u t + T u t` and `E u t - T u t` for `u < K', t < L` (`2 * K' * L` gates)have hB :CanBuild ((⋃ u < K', ⋃ t < L, {E u t}) ∪ (⋃ u < K', ⋃ t < L, {T u t}))(K' * (L * 2))(⋃ u < K', ⋃ t < L, ({E u t + T u t, E u t - T u t} : Set (Polynomial ℤ))) := byrefine canBuild_fin_union (n := K') (d := L * 2)(T := fun u => ⋃ t < L, ({E u t + T u t, E u t - T u t} : Set (Polynomial ℤ))) ?_intro u hurefine canBuild_fin_union (n := L) (d := 2)(T := fun t => ({E u t + T u t, E u t - T u t} : Set (Polynomial ℤ))) ?_intro t hthave ha := canBuild_add (E u t) (T u t)have hs := canBuild_sub (E u t) (T u t)have has := canBuild_trans ha Set.subset_union_left hsrefine canBuild_mono_in ?_ hasintro x hxrcases hx with rfl | rfl· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨u, hu, t, ht, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨u, hu, t, ht, rfl⟩have c4 := canBuild_trans c3 (byintro x hx; rcases hx with hxE | hxT· right; left; left; exact hxE· right; right; exact hxT) hB-- Check butterfly identity:-- `ringDFT L (2*K') (2*step*c) A u t = E u t + T u t` (for `u < K'`)-- `ringDFT L (2*K') (2*step*c) A (u + K') t = E u t - T u t` (for `u < K'`)have hsplit_dft : ∀ u t, t < L →ringDFT L (2 ^ (p + 1)) (2 * step * c) A u t =E (u % K') t + negShift L (2 * step * c * u) (O (u % K')) t := byintro u t htunfold ringDFThave h2K : 2 ^ (p + 1) = 2 * K' := by rw [pow_succ]; ringrw [h2K]-- Split `range (2 * K')` into even `2 * j` and odd `2 * j + 1`have heven_odd : ∀ f : ℕ → Polynomial ℤ,∑ j ∈ Finset.range (2 * K'), f j =(∑ j ∈ Finset.range K', f (2 * j)) + (∑ j ∈ Finset.range K', f (2 * j + 1)) := byintro fclear h2Kinduction K' with| zero => simp| succ n ihn =>rw [show 2 * (n + 1) = 2 * n + 2 by ring, Finset.sum_range_succ, Finset.sum_range_succ,ihn, Finset.sum_range_succ, Finset.sum_range_succ]ringrw [heven_odd]congr 1· dsimp only [E, ringDFT, Aeven]refine Finset.sum_congr rfl ?_intro j _refine negShift_mod_two_N L _ _ hL ?_ _ thave hdiv := Nat.div_add_mod u K'have hu_eq : u = u % K' + (u / K') * K' := by linarithconv_lhs => rw [hu_eq]have h1 : 2 * step * c * (u % K' + u / K' * K') * (2 * j) =2 * (2 * step) * c * (u % K') * j + (c * (u / K') * j) * (2 * L) := byrw [← hKS']; ringrw [h1, Nat.add_mul_mod_self_right]· have hOfn : O (u % K') = fun x =>∑ j ∈ Finset.range K', negShift L (2 * (2 * step) * c * (u % K') * j) (Aodd j) x := rflrw [hOfn, negShift_finset_sum]dsimp only [Aodd]refine Finset.sum_congr rfl ?_intro j _rw [← negShift_add L _ _ hL _ t ht]refine negShift_mod_two_N L _ _ hL ?_ _ thave hdiv := Nat.div_add_mod u K'have hu_eq : u = u % K' + (u / K') * K' := by linarithhave h1 : 2 * step * c * u * (2 * j + 1) =2 * step * c * u + 2 * (2 * step) * c * u * j := by ringrw [h1]conv_lhs => rw [show 2 * (2 * step) * c * u * j =2 * (2 * step) * c * (u % K' + u / K' * K') * j by rw [← hu_eq]]have h2 : 2 * step * c * u + 2 * (2 * step) * c * (u % K' + u / K' * K') * j =(2 * step * c * u + 2 * (2 * step) * c * (u % K') * j) +(c * (u / K') * j) * (2 * L) := byrw [← hKS']; ringrw [h2, Nat.add_mul_mod_self_right]have hcost : dftCost p L + dftCost p L + K' * L + K' * (L * 2) ≤ dftCost (p + 1) L := bysimp only [dftCost, K', pow_succ]have h1 : 3 * p * 2 ^ p * L + 3 * p * 2 ^ p * L + 2 ^ p * L + 2 ^ p * (L * 2) =(6 * p + 3) * (2 ^ p * L) := by ringhave h2 : 3 * (p + 1) * (2 ^ p * 2) * L = (6 * p + 6) * (2 ^ p * L) := by ringrw [h1, h2]exact Nat.mul_le_mul_right (2 ^ p * L) (by omega)refine canBuild_mono_cost hcost (canBuild_mono_out ?_ c4)intro x hxsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxrcases hx with ⟨u, hu, t, ht, rfl⟩rw [hsplit_dft u t ht]by_cases huK : u < K'· rw [Nat.mod_eq_of_lt huK]right; simp only [Set.mem_iUnion, exists_prop]exact ⟨u, huK, t, ht, Or.inl rfl⟩· set u' := u - K'have hu' : u' < K' := by rw [pow_succ] at hu; omegahave hu_eq : u = u' + K' := by omegahave hmod : u % K' = u' := by rw [hu_eq, Nat.add_mod_right, Nat.mod_eq_of_lt hu']rw [hmod]have htw : negShift L (2 * step * c * u) (O u') t = -(T u' t) := bydsimp only [T]have harg : 2 * step * c * u = 2 * step * c * u' + c * L := byrw [hu_eq, ← hKS']; ringrw [harg, negShift_add_mul_N L _ c hL]rcases hc with ⟨m, rfl⟩rw [pow_add, pow_mul]norm_numrw [htw, ← sub_eq_add_neg]right; simp only [Set.mem_iUnion, exists_prop]exact ⟨u', hu', t, ht, Or.inr rfl⟩/-! ## 4. Recursive Schönhage–Nussbaumer Negacyclic Multiplication (`k ≥ 4`, Base `k ≤ 3`) -//-- Recursive size parameter `snSub k = (k + 1) / 2 + 1` (`2 * M` exponent).For `k ≥ 4`, `snSub k < k`. -/def snSub (k : ℕ) : ℕ := (k + 1) / 2 + 1theorem snSub_lt (k : ℕ) (hk : 4 ≤ k) : snSub k < k := byunfold snSub; omega/-- Uniform positive power-of-2 scale exponent `snScale k` produced by `canBuild_snMul`. -/def snScale : ℕ → ℕ| k =>if h : k ≤ 3 then 0else snScale (snSub k) + k / 2termination_by k => kdecreasing_by exact snSub_lt k (by omega)/-- Exact gate cost `snCost k` of division-free Schönhage–Nussbaumer negacyclic multiplicationof length `2^k`. -/def snCost : ℕ → ℕ| k =>if h : k ≤ 3 then 3 * (2 ^ k) * (2 ^ k)elselet p := k / 2let K := 2 ^ plet L := 2 ^ (snSub k)K * snCost (snSub k) + 3 * dftCost p L + 3 * K * L + 2 * 2 ^ ktermination_by k => kdecreasing_by exact snSub_lt k (by omega)/-- Chunk-recombination identity for Schönhage–Nussbaumer:splitting length `N = K * M` into `K` chunks of length `M` (zero-padded to `2 * M`),computing the negacyclic convolution of length `K` in `R[Z]/(Z^(2M) + 1)`, and recombiningoverlapping halves recovers `negConv (K * M) a b` identically. -/theorem negConv_chunk_recombine (K M : ℕ) (hK : 1 ≤ K) (hM : 1 ≤ M)(a b : ℕ → Polynomial ℤ) (q r : ℕ) (hq : q < K) (hr : r < M) :let A : ℕ → ℕ → Polynomial ℤ := fun j u => if u < M then a (j * M + u) else 0let B : ℕ → ℕ → Polynomial ℤ := fun j u => if u < M then b (j * M + u) else 0let C : ℕ → ℕ → Polynomial ℤ := fun w u =>∑ j₁ ∈ Finset.range K,if j₁ ≤ w then negConv (2 * M) (A j₁) (B (w - j₁)) uelse -(negConv (2 * M) (A j₁) (B (w + K - j₁)) u)negConv (K * M) a b (q * M + r) =C q r + (if 0 < q then C (q - 1) (r + M) else -(C (K - 1) (r + M))) := byintro A B C-- Helper: for any `j₁, j₂ < K`, compute `negConv (2*M) (A j₁) (B j₂) u` for `u = r` and `u = r + M`have hchunk_lo : ∀ j₁ j₂,negConv (2 * M) (A j₁) (B j₂) r =∑ r₁ ∈ Finset.range M, if r₁ ≤ r then a (j₁ * M + r₁) * b (j₂ * M + (r - r₁)) else 0 := byintro j₁ j₂unfold negConvhave hsub : Finset.range M ⊆ Finset.range (2 * M) := Finset.range_mono (by omega)rw [← Finset.sum_subset hsub]· refine Finset.sum_congr rfl ?_intro r₁ hr₁rw [Finset.mem_range] at hr₁by_cases hle : r₁ ≤ r· have hlt : r - r₁ < M := by omegasimp [hle, A, B, hr₁, hlt]· have hnot : ¬ (r + 2 * M - r₁ < M) := by omegasimp [hle, A, B, hr₁, hnot]· intro r₁ hr₁ hnotrw [Finset.mem_range] at hr₁ hnothave hge : ¬ (r₁ < M) := by omegasimp [A, hge]have hchunk_hi : ∀ j₁ j₂,negConv (2 * M) (A j₁) (B j₂) (r + M) =∑ r₁ ∈ Finset.range M, if r < r₁ then a (j₁ * M + r₁) * b (j₂ * M + (r + M - r₁)) else 0 := byintro j₁ j₂unfold negConvhave hsub : Finset.range M ⊆ Finset.range (2 * M) := Finset.range_mono (by omega)rw [← Finset.sum_subset hsub]· refine Finset.sum_congr rfl ?_intro r₁ hr₁rw [Finset.mem_range] at hr₁have hle : r₁ ≤ r + M := by omegaby_cases hgt : r < r₁· have hlt : r + M - r₁ < M := by omegasimp [hle, hgt, A, B, hr₁, hlt]· have hnot : ¬ (r + M - r₁ < M) := by omegasimp [hle, hgt, A, B, hr₁, hnot]· intro r₁ hr₁ hnotrw [Finset.mem_range] at hr₁ hnothave hge : ¬ (r₁ < M) := by omegasimp [A, hge]-- Rewrite LHS as double sum over `j₁ < K, r₁ < M`have hLHS :negConv (K * M) a b (q * M + r) =∑ j₁ ∈ Finset.range K, ∑ r₁ ∈ Finset.range M,if j₁ * M + r₁ ≤ q * M + r thena (j₁ * M + r₁) * b (q * M + r - (j₁ * M + r₁))else-(a (j₁ * M + r₁) * b (q * M + r + K * M - (j₁ * M + r₁))) := byunfold negConvrw [← Finset.sum_product']refine Finset.sum_bij (fun i _ => (i / M, i % M)) ?_ ?_ ?_ ?_· intro i hirw [Finset.mem_range] at hisimp only [Finset.mem_product, Finset.mem_range]exact ⟨Nat.div_lt_of_lt_mul (by rwa [mul_comm]), Nat.mod_lt i (by omega)⟩· intro i₁ hi₁ i₂ hi₂ heqhave h1 := congrArg Prod.fst heqhave h2 := congrArg Prod.snd heqhave d1 := Nat.div_add_mod i₁ Mhave d2 := Nat.div_add_mod i₂ Mdsimp at h1 h2rw [h1, h2] at d1linarith· intro p hpsimp only [Finset.mem_product, Finset.mem_range] at hprefine ⟨p.1 * M + p.2, Finset.mem_range.mpr (by nlinarith), ?_⟩ext· dsimprw [Nat.mul_comm, Nat.mul_add_div (by omega), Nat.div_eq_of_lt hp.2, add_zero]· dsimprw [Nat.mul_add_mod_self_right, Nat.mod_eq_of_lt hp.2]· intro i _have hi_eq : i / M * M + i % M = i := byhave := Nat.div_add_mod i M; linarithsimp [hi_eq]rw [hLHS]-- Push the `if 0 < q` inside the `j₁` sum on RHS and match term-by-term!have hRHS :C q r + (if 0 < q then C (q - 1) (r + M) else -(C (K - 1) (r + M))) =∑ j₁ ∈ Finset.range K,((if j₁ ≤ q then negConv (2 * M) (A j₁) (B (q - j₁)) relse -(negConv (2 * M) (A j₁) (B (q + K - j₁)) r)) +(if 0 < q thenif j₁ ≤ q - 1 then negConv (2 * M) (A j₁) (B (q - 1 - j₁)) (r + M)else -(negConv (2 * M) (A j₁) (B (q - 1 + K - j₁)) (r + M))else-(if j₁ ≤ K - 1 then negConv (2 * M) (A j₁) (B (K - 1 - j₁)) (r + M)else -(negConv (2 * M) (A j₁) (B (K - 1 + K - j₁)) (r + M))))) := bydsimp only [C]split_ifs with hq0· rw [← Finset.sum_add_distrib]· rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib]rw [hRHS]refine Finset.sum_congr rfl ?_intro j₁ hj₁rw [Finset.mem_range] at hj₁simp only [hchunk_lo, hchunk_hi]-- Split LHS inner sum into `r₁ ≤ r` and `r < r₁` and match each case of `j₁` vs `q`have hinner_split : ∀ (f : ℕ → Polynomial ℤ),∑ r₁ ∈ Finset.range M, f r₁ =(∑ r₁ ∈ Finset.range M, if r₁ ≤ r then f r₁ else 0) +(∑ r₁ ∈ Finset.range M, if r < r₁ then f r₁ else 0) := byintro frw [← Finset.sum_add_distrib]refine Finset.sum_congr rfl ?_intro r₁ _by_cases h : r₁ ≤ r· have h' : ¬ (r < r₁) := by omegasimp [h, h']· have h' : r < r₁ := by omegasimp [h, h']rw [hinner_split]congr 1· -- Lower half (`r₁ ≤ r`): `j₁ * M + r₁ ≤ q * M + r ↔ j₁ ≤ q`by_cases hjq : j₁ ≤ q· simp only [hjq, ↓reduceIte]refine Finset.sum_congr rfl ?_intro r₁ hr₁; rw [Finset.mem_range] at hr₁by_cases hle : r₁ ≤ r· have hmain : j₁ * M + r₁ ≤ q * M + r := by nlinarithhave hidx : q * M + r - (j₁ * M + r₁) = (q - j₁) * M + (r - r₁) := byzify [hjq, hle, hmain]; ringsimp [hle, hmain, hidx]· simp [hle]· simp only [hjq, ↓reduceIte, ← Finset.sum_neg_distrib]refine Finset.sum_congr rfl ?_intro r₁ hr₁; rw [Finset.mem_range] at hr₁by_cases hle : r₁ ≤ r· have hmain : ¬ (j₁ * M + r₁ ≤ q * M + r) := by nlinarithhave hidx : q * M + r + K * M - (j₁ * M + r₁) = (q + K - j₁) * M + (r - r₁) := byhave h1 : j₁ ≤ q + K := by omegahave h2 : j₁ * M + r₁ ≤ q * M + r + K * M := by nlinarithzify [h1, hle, h2]; ringsimp [hle, hmain, hidx]· simp [hle]· -- Upper half (`r < r₁`): `j₁ * M + r₁ ≤ q * M + r ↔ j₁ < q`by_cases hq0 : 0 < q· simp only [hq0, ↓reduceIte]by_cases hjq : j₁ ≤ q - 1· simp only [hjq, ↓reduceIte]refine Finset.sum_congr rfl ?_intro r₁ hr₁; rw [Finset.mem_range] at hr₁by_cases hgt : r < r₁· have hmain : j₁ * M + r₁ ≤ q * M + r := byhave : j₁ + 1 ≤ q := by omeganlinarithhave hidx : q * M + r - (j₁ * M + r₁) = (q - 1 - j₁) * M + (r + M - r₁) := byhave h1 : j₁ + 1 ≤ q := by omegahave h2 : r₁ ≤ r + M := by omegazify [h1, hq0, hjq, h2, hmain]; ringsimp [hgt, hmain, hidx]· simp [hgt]· simp only [hjq, ↓reduceIte, ← Finset.sum_neg_distrib]refine Finset.sum_congr rfl ?_intro r₁ hr₁; rw [Finset.mem_range] at hr₁by_cases hgt : r < r₁· have hmain : ¬ (j₁ * M + r₁ ≤ q * M + r) := byhave : q ≤ j₁ := by omeganlinarithhave hidx : q * M + r + K * M - (j₁ * M + r₁) = (q - 1 + K - j₁) * M + (r + M - r₁) := byhave h1 : j₁ ≤ q - 1 + K := by omegahave h2 : r₁ ≤ r + M := by omegahave h3 : j₁ * M + r₁ ≤ q * M + r + K * M := byhave : j₁ + 1 ≤ q + K := by omeganlinarithzify [hq0, h1, h2, h3]; ringsimp [hgt, hmain, hidx]· simp [hgt]· have hq_zero : q = 0 := by omegasubst hq_zerohave hjK : j₁ ≤ K - 1 := by omegasimp only [lt_self_iff_false, ↓reduceIte, hjK, ← Finset.sum_neg_distrib]refine Finset.sum_congr rfl ?_intro r₁ hr₁; rw [Finset.mem_range] at hr₁by_cases hgt : r < r₁· have hmain : ¬ (j₁ * M + r₁ ≤ r) := by nlinarithhave hidx : r + K * M - (j₁ * M + r₁) = (K - 1 - j₁) * M + (r + M - r₁) := byhave h2 : r₁ ≤ r + M := by omegahave h3 : j₁ * M + r₁ ≤ r + K * M := by nlinarithzify [hK, hjK, h2, h3]; ringsimp [hgt, hmain, hidx]· simp [hgt]/-- **Division-Free Schönhage–Nussbaumer Negacyclic Multiplication (`CanBuild`):**For every `k : ℕ`, given `{0} ∪ {a i | i < 2^k} ∪ {b j | j < 2^k}`, computes`{(2 : ℤ) ^ (snScale k) * negConv (2^k) a b t | t < 2^k}` in `snCost k` constant-free gates. -/theorem canBuild_snMul :∀ (k : ℕ) (a b : ℕ → Polynomial ℤ),CanBuild({(0 : Polynomial ℤ)} ∪ (⋃ i < 2 ^ k, {a i}) ∪ (⋃ j < 2 ^ k, {b j}))(snCost k)(⋃ t < 2 ^ k, {((2 : Polynomial ℤ) ^ snScale k) * negConv (2 ^ k) a b t})| k, a, b => byby_cases hk : k ≤ 3· rw [snCost, snScale]simp only [hk, ↓reduceDIte, pow_zero, one_mul]exact canBuild_negConv_schoolbook (2 ^ k) a b· have hk4 : 4 ≤ k := by omegahave hsub_lt : snSub k < k := snSub_lt k hk4set p := k / 2set K := 2 ^ pset M := 2 ^ (k - p)set L := 2 ^ snSub khave hKM : K * M = 2 ^ k := bysimp only [K, M, ← pow_add]; congr 1; omegahave hL2M : L = 2 * M := bysimp only [L, M, snSub]have : (k + 1) / 2 + 1 = (k - k / 2) + 1 := by omegarw [this, pow_succ]; ringhave hKpos : 1 ≤ K := Nat.one_le_two_powhave hMpos : 1 ≤ M := Nat.one_le_two_powhave hL : 0 < L := by positivity-- `step = L / K`: since `k - p = p` or `p + 1`, `L = 2 * M = K * 2` or `K * 4`set step := 2 ^ (snSub k - p)have hKS : K * step = L := bysimp only [K, step, L, ← pow_add]congr 1; unfold snSub; omega-- Chunk arrays `A, B` (size K, each length L = 2*M, zero-padded past M)let A : ℕ → ℕ → Polynomial ℤ := fun j u => if u < M then a (j * M + u) else 0let B : ℕ → ℕ → Polynomial ℤ := fun j u => if u < M then b (j * M + u) else 0-- Twist by `ζ^j = Z^(step * j)`let Atw : ℕ → ℕ → Polynomial ℤ := fun j => negShift L (step * j) (A j)let Btw : ℕ → ℕ → Polynomial ℤ := fun j => negShift L (step * j) (B j)-- Forward DFT with `ang = 2 * step * 1`let Ahat := ringDFT L K (2 * step * 1) Atwlet Bhat := ringDFT L K (2 * step * 1) Btw-- Pointwise scaled negacyclic products of size `L = 2^(snSub k)`let Phat : ℕ → ℕ → Polynomial ℤ := fun u t =>((2 : Polynomial ℤ) ^ snScale (snSub k)) * negConv L (Ahat u) (Bhat u) t-- Inverse DFT with `angInv = 2 * step * (K - 1)`let Ctw := ringDFT L K (2 * step * (K - 1)) Phat-- Untwist by `ζ^(-j) = Z^(step * (2*K - j))`let Cscaled : ℕ → ℕ → Polynomial ℤ := fun j => negShift L (step * (2 * K - j)) (Ctw j)-- Recombine overlapping chunks into length `2^k = K * M`let Out : ℕ → Polynomial ℤ := fun t =>let q := t / Mlet r := t % MCscaled q r + (if 0 < q then Cscaled (q - 1) (r + M) else -(Cscaled (K - 1) (r + M)))-- Prove algebraic correctness: `Out t = 2^(snScale k) * negConv (2^k) a b t` for all `t < 2^k`have hOut_eq : ∀ t < 2 ^ k,Out t = ((2 : Polynomial ℤ) ^ snScale k) * negConv (2 ^ k) a b t := byintro t hthave hsnScale : snScale k = snScale (snSub k) + p := byconv_lhs => rw [snScale]simp [hk, p]-- First compute `Cscaled j u` for `j < K, u < L`have hCscaled : ∀ j < K, ∀ u < L,Cscaled j u =((2 : Polynomial ℤ) ^ (snScale (snSub k) + p)) *∑ j₁ ∈ Finset.range K,if j₁ ≤ j then negConv (2 * M) (A j₁) (B (j - j₁)) uelse -(negConv (2 * M) (A j₁) (B (j + K - j₁)) u) := byintro j hj u hu-- Factor `2^(snScale (snSub k))` out of `Ctw` and `Cscaled`have hPhat_eq : Phat = fun w x =>((2 : Polynomial ℤ) ^ snScale (snSub k)) * negConv L (Ahat w) (Bhat w) x := rflhave hCtw_pull : ∀ w x,Ctw w x = ((2 : Polynomial ℤ) ^ snScale (snSub k)) *ringDFT L K (2 * step * (K - 1)) (fun z => negConv L (Ahat z) (Bhat z)) w x := byintro w xdsimp only [Ctw, ringDFT, Phat]rw [Finset.mul_sum]refine Finset.sum_congr rfl ?_intro z _rw [negShift_smul_linear]dsimp only [Cscaled]have hCtw_fn : Ctw j = fun x =>((2 : Polynomial ℤ) ^ snScale (snSub k)) *ringDFT L K (2 * step * (K - 1)) (fun z => negConv L (Ahat z) (Bhat z)) j x :=funext (hCtw_pull j)rw [hCtw_fn, negShift_smul_linear]-- Apply `ringDFT_convolution` to `Atw, Btw`have hAhat_eq : Ahat = ringDFT L K (2 * step) Atw := bysimp [Ahat]have hBhat_eq : Bhat = ringDFT L K (2 * step) Btw := bysimp [Bhat]have hconv_fn :∀ x < L,ringDFT L K (2 * step * (K - 1)) (fun z => negConv L (Ahat z) (Bhat z)) j x =((K : ℕ) : Polynomial ℤ) *∑ j₁ ∈ Finset.range K,negConv L (Atw j₁) (Btw ((j + K - j₁) % K)) x := byintro x hxrw [hAhat_eq, hBhat_eq]exact ringDFT_convolution p step L hL hKS Atw Btw j x hj hx-- Apply `negShift L (step * (2*K - j))` to `hconv_fn`have hsh_eq :negShift L (step * (2 * K - j))(ringDFT L K (2 * step * (K - 1)) (fun z => negConv L (Ahat z) (Bhat z)) j) u =negShift L (step * (2 * K - j))(fun x => ((K : ℕ) : Polynomial ℤ) *∑ j₁ ∈ Finset.range K, negConv L (Atw j₁) (Btw ((j + K - j₁) % K)) x) u :=negShift_congr L _ hL _ _ hconv_fn u hurw [hsh_eq, negShift_smul_linear, negShift_finset_sum]have hKcast : ((K : ℕ) : Polynomial ℤ) = (2 : Polynomial ℤ) ^ p := bysimp [K]rw [hKcast, ← mul_assoc, ← pow_add]congr 1refine Finset.sum_congr rfl ?_intro j₁ hj₁rw [Finset.mem_range] at hj₁dsimp only [Atw, Btw]have h3shift :negShift L (step * (2 * K - j))(negConv L (negShift L (step * j₁) (A j₁))(negShift L (step * ((j + K - j₁) % K)) (B ((j + K - j₁) % K)))) u =negShift L (step * (2 * K - j) + step * j₁ + step * ((j + K - j₁) % K))(negConv L (A j₁) (B ((j + K - j₁) % K))) u := byhave hinner_eq : ∀ x < L,negConv L (negShift L (step * j₁) (A j₁))(negShift L (step * ((j + K - j₁) % K)) (B ((j + K - j₁) % K))) x =negShift L (step * j₁ + step * ((j + K - j₁) % K))(negConv L (A j₁) (B ((j + K - j₁) % K))) x := byintro x hxrw [negConv_negShift_left L _ hL _ _ x hx]rw [negShift_congr L _ hL _ _ (fun y hy => negConv_negShift_right L _ hL (A j₁) _ y hy) x hx]rw [← negShift_add L _ _ hL _ x hx]have houter := negShift_congr L (step * (2 * K - j)) hL _ _ hinner_eq u hurw [houter, ← negShift_add L _ _ hL _ u hu, add_assoc]rw [h3shift, hL2M]by_cases hle : j₁ ≤ j· have hmod : (j + K - j₁) % K = j - j₁ := byrw [show j + K - j₁ = (j - j₁) + K by omega, Nat.add_mod_right,Nat.mod_eq_of_lt (by omega)]simp only [hle, ↓reduceIte, hmod]have hsum_exp : step * (2 * K - j) + step * j₁ + step * (j - j₁) = 2 * L := byrw [← hKS]zify [hle, show j ≤ 2 * K by omega]; ringrw [← hL2M, hsum_exp, show 2 * L = 0 + 2 * L by ring, negShift_add_mul_N L 0 2 hL,negShift_zero L hL]norm_num· have hmod : (j + K - j₁) % K = j + K - j₁ := Nat.mod_eq_of_lt (by omega)simp only [hle, ↓reduceIte, hmod]have hsum_exp : step * (2 * K - j) + step * j₁ + step * (j + K - j₁) = 3 * L := byrw [← hKS]zify [show j₁ ≤ j + K by omega, show j ≤ 2 * K by omega]; ringrw [← hL2M, hsum_exp, show 3 * L = 0 + 3 * L by ring, negShift_add_mul_N L 0 3 hL,negShift_zero L hL]norm_numhave hq : t / M < K := Nat.div_lt_of_lt_mul (by rwa [mul_comm, hKM])have hr : t % M < M := Nat.mod_lt t (by omega)have ht_eq : t = (t / M) * M + t % M := byhave := Nat.div_add_mod t M; linarithrw [hsnScale]dsimp only [Out]rw [hCscaled (t / M) hq (t % M) (by omega)]have h2nd :(if 0 < t / M then Cscaled (t / M - 1) (t % M + M)else -(Cscaled (K - 1) (t % M + M))) =((2 : Polynomial ℤ) ^ (snScale (snSub k) + p)) *(if 0 < t / M then∑ j₁ ∈ Finset.range K,if j₁ ≤ t / M - 1 then negConv (2 * M) (A j₁) (B (t / M - 1 - j₁)) (t % M + M)else -(negConv (2 * M) (A j₁) (B (t / M - 1 + K - j₁)) (t % M + M))else-(∑ j₁ ∈ Finset.range K,if j₁ ≤ K - 1 then negConv (2 * M) (A j₁) (B (K - 1 - j₁)) (t % M + M)else -(negConv (2 * M) (A j₁) (B (K - 1 + K - j₁)) (t % M + M)))) := bysplit_ifs with hq0· exact hCscaled (t / M - 1) (by omega) (t % M + M) (by omega)· rw [hCscaled (K - 1) (by omega) (t % M + M) (by omega)]; ringrw [h2nd, ← mul_add]congr 1conv_rhs => rw [← hKM, ht_eq]exact (negConv_chunk_recombine K M hKpos hMpos a b (t / M) (t % M) hq hr).symm-- Now chain the `CanBuild` steps!set S0 : Set (Polynomial ℤ) :={(0 : Polynomial ℤ)} ∪ (⋃ i < 2 ^ k, {a i}) ∪ (⋃ j < 2 ^ k, {b j})-- Step 1 (`K * L` gates): `Atw`have hAtw : CanBuild S0 (K * L) (⋃ j < K, ⋃ u < L, {Atw j u}) := byrefine canBuild_fin_union (n := K) (d := L) (T := fun j => ⋃ u < L, {Atw j u}) ?_intro j hjrefine canBuild_mono_in ?_ (canBuild_negShift L (step * j) hL (A j))intro x hx; rcases hx with rfl | hx'· left; left; rfl· simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hx'rcases hx' with ⟨u, hu, rfl⟩dsimp only [A]split_ifs with huM· left; right; simp only [Set.mem_iUnion, exists_prop]exact ⟨j * M + u, by rw [← hKM]; nlinarith, rfl⟩· left; left; rfl-- Step 2 (`K * L` gates): `Btw`have hBtw : CanBuild S0 (K * L) (⋃ j < K, ⋃ u < L, {Btw j u}) := byrefine canBuild_fin_union (n := K) (d := L) (T := fun j => ⋃ u < L, {Btw j u}) ?_intro j hjrefine canBuild_mono_in ?_ (canBuild_negShift L (step * j) hL (B j))intro x hx; rcases hx with rfl | hx'· left; left; rfl· simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hx'rcases hx' with ⟨u, hu, rfl⟩dsimp only [B]split_ifs with huM· right; simp only [Set.mem_iUnion, exists_prop]exact ⟨j * M + u, by rw [← hKM]; nlinarith, rfl⟩· left; left; rfl-- Step 3 (`2 * dftCost p L` gates): `Ahat` and `Bhat`have hOdd1 : Odd (1 : ℕ) := ⟨0, by omega⟩have hOddKm1 : Odd (K - 1) := byhave hp1 : 1 ≤ p := by omegahave hK2 : 2 ∣ K := dvd_pow_self 2 (by omega : p ≠ 0)rcases hK2 with ⟨m, hm⟩exact ⟨m - 1, by omega⟩have hAhat := canBuild_ringDFT p step 1 L hL hKS hOdd1 Atwhave hBhat := canBuild_ringDFT p step 1 L hL hKS hOdd1 Btw-- Step 4 (`K * snCost (snSub k)` gates): `K` recursive calls `Phat u`have hPhat :CanBuild({(0 : Polynomial ℤ)} ∪ (⋃ u < K, ⋃ t < L, {Ahat u t}) ∪(⋃ u < K, ⋃ t < L, {Bhat u t}))(K * snCost (snSub k))(⋃ u < K, ⋃ t < L, {Phat u t}) := byrefine canBuild_fin_union (n := K) (d := snCost (snSub k))(T := fun u => ⋃ t < L, {Phat u t}) ?_intro u hurefine canBuild_mono_in ?_ (canBuild_snMul (snSub k) (Ahat u) (Bhat u))intro x hx; rcases hx with (rfl | hxA) | hxB· left; left; rfl· left; right; simp only [Set.mem_iUnion, exists_prop] at hxA ⊢rcases hxA with ⟨t, ht, hxt⟩; exact ⟨u, hu, t, ht, hxt⟩· right; simp only [Set.mem_iUnion, exists_prop] at hxB ⊢rcases hxB with ⟨t, ht, hxt⟩; exact ⟨u, hu, t, ht, hxt⟩-- Step 5 (`dftCost p L` gates): `Ctw`have hCtw := canBuild_ringDFT p step (K - 1) L hL hKS hOddKm1 Phat-- Step 6 (`K * L` gates): `Cscaled`have hCsc :CanBuild ({(0 : Polynomial ℤ)} ∪ ⋃ j < K, ⋃ u < L, {Ctw j u})(K * L) (⋃ j < K, ⋃ u < L, {Cscaled j u}) := byrefine canBuild_fin_union (n := K) (d := L) (T := fun j => ⋃ u < L, {Cscaled j u}) ?_intro j hjrefine canBuild_mono_in ?_ (canBuild_negShift L (step * (2 * K - j)) hL (Ctw j))intro x hx; rcases hx with rfl | hx'· left; rfl· right; simp only [Set.mem_iUnion, exists_prop] at hx' ⊢rcases hx' with ⟨u, hu, hxu⟩; exact ⟨j, hj, u, hu, hxu⟩-- Step 7 (`2 * 2^k` gates): `Out t` for `t < 2^k`have hOut :CanBuild ({(0 : Polynomial ℤ)} ∪ ⋃ j < K, ⋃ u < L, {Cscaled j u})(2 ^ k * 2) (⋃ t < 2 ^ k, {Out t}) := byrefine canBuild_fin_union (n := 2 ^ k) (d := 2) (T := fun t => {Out t}) ?_intro t htset q := t / Mset r := t % Mhave hq : q < K := Nat.div_lt_of_lt_mul (by rwa [mul_comm, hKM])have hr : r < M := Nat.mod_lt t (by omega)by_cases hq0 : 0 < q· have ha := canBuild_add (Cscaled q r) (Cscaled (q - 1) (r + M))have hOut_eq' : Out t = Cscaled q r + Cscaled (q - 1) (r + M) := bychange Cscaled q r + (if 0 < q then Cscaled (q - 1) (r + M) else -(Cscaled (K - 1) (r + M))) = _simp only [hq0, ↓reduceIte]refine canBuild_mono_cost (by omega : 1 ≤ 2)(canBuild_mono_out (T₂ := {Cscaled q r + Cscaled (q - 1) (r + M)})(by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; rw [hOut_eq']; rfl)(canBuild_mono_in ?_ ha))intro x hx; rcases hx with rfl | rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨q, hq, r, by omega, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨q - 1, by omega, r + M, by omega, rfl⟩· have hs := canBuild_sub (Cscaled q r) (Cscaled (K - 1) (r + M))have hOut_eq' : Out t = Cscaled q r - Cscaled (K - 1) (r + M) := bychange Cscaled q r + (if 0 < q then Cscaled (q - 1) (r + M) else -(Cscaled (K - 1) (r + M))) = _simp only [hq0, ↓reduceIte, sub_eq_add_neg]refine canBuild_mono_cost (by omega : 1 ≤ 2)(canBuild_mono_out (T₂ := {Cscaled q r - Cscaled (K - 1) (r + M)})(by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; rw [hOut_eq']; rfl)(canBuild_mono_in ?_ hs))intro x hx; rcases hx with rfl | rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨q, hq, r, by omega, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨K - 1, by omega, r + M, by omega, rfl⟩-- Compose Steps 1..7have s12 := canBuild_trans hAtw Set.subset_union_left hBtwhave s13 := canBuild_trans s12 (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; left; exact hx') hAhathave s14 := canBuild_trans s13 (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; left; right; exact hx') hBhathave s15 := canBuild_trans s14 (byintro x hx; rcases hx with (rfl | hxA) | hxB· left; left; left; rfl· right; left; right; exact hxA· right; right; exact hxB) hPhathave s16 := canBuild_trans s15 (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; right; exact hx') hCtwhave s17 := canBuild_trans s16 (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; right; exact hx') hCschave s18 := canBuild_trans s17 (byintro x hx; rcases hx with rfl | hx'· left; left; left; rfl· right; right; exact hx') hOuthave hcost :K * L + K * L + dftCost p L + dftCost p L + K * snCost (snSub k) +dftCost p L + K * L + 2 ^ k * 2 = snCost k := byconv_rhs => rw [snCost]simp only [hk, ↓reduceDIte, p, K, L]ringrw [hcost] at s18refine canBuild_mono_out ?_ s18intro x hxsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxrcases hx with ⟨t, ht, rfl⟩rightsimp only [Set.mem_iUnion, exists_prop]exact ⟨t, ht, (hOut_eq t ht).symm⟩termination_by k => kdecreasing_by exact snSub_lt k (by omega)/-! ## 5. Asymptotic Bound on `snCost k` and Refutation of All Real Exponents `c < 2` -//-- Exact asymptotic upper bound on Schönhage–Nussbaumer gate cost:`snCost k ≤ 200 * k * (Nat.log 2 k + 1) * 2 ^ k` for every `k ≥ 1`. -/theorem snCost_le : ∀ k : ℕ, 1 ≤ k → snCost k ≤ 200 * k * (Nat.log 2 k + 1) * 2 ^ k := by-- Prove the sharper shifted invariant for all `k ≥ 1`:-- `snCost k ≤ (50 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48) * 2 ^ k`-- Check:-- k = 1: 3 * 2 * 2 = 12 ≤ 48 * 2 = 96-- k = 2: 3 * 4 * 4 = 48 ≤ 48 * 4 = 192-- k = 3: 3 * 8 * 8 = 192 ≤ 48 * 8 = 384-- k = 4: snSub 4 = 3, p = 2, K = 4, L = 8:-- snCost 4 = 4 * 192 + 3 * (3 * 2 * 4 * 8) + 3 * 4 * 8 + 32 = 768 + 576 + 96 + 32 = 1472-- RHS at k = 4: (50 * 1 * 1 + 48) * 16 = 98 * 16 = 1568 ≥ 1472!-- k ≥ 5: let k' = snSub k = (k + 1) / 2 + 1. Note K * 2^k' = 2^(k/2 + (k+1)/2 + 1) = 2 * 2^k,-- and 2 * (k' - 3) ≤ k - 3, and Nat.log 2 (k' - 3) + 1 ≤ Nat.log 2 (k - 3)!-- Extra work: 3 * dftCost p L + 3 * K * L + 2 * 2^k-- = (9 * p * 2 + 3 * 2 + 2) * 2^k = (18 * p + 8) * 2^k ≤ (9 * k + 8) * 2^k.-- Total / 2^k ≤ 2 * (50 * (k' - 3) * (log(k'-3) + 1) + 48) + 9 * k + 8-- ≤ 50 * (k - 3) * log(k - 3) + 96 + 9 * k + 8-- = 50 * (k - 3) * (log(k - 3) + 1) + 48 + (56 + 9 * k - 50 * (k - 3))-- and for k ≥ 5: 56 + 9 * k ≤ 101 ≤ 100? Wait: at k = 5: 56 + 45 = 101 > 50 * 2 = 100!-- Bump 50 → 60! At k = 5: 56 + 45 = 101 ≤ 60 * 2 = 120!-- And for all k ≥ 5: 56 + 9 * k ≤ 60 * (k - 3) ⟺ 236 ≤ 51 * k (51 * 5 = 255 ≥ 236)!-- And 60 * (k - 3) * (log(k-3) + 1) + 48 ≤ 200 * k * (log k + 1) for all k ≥ 1!have hstrong : ∀ k : ℕ, 1 ≤ k →snCost k ≤ (60 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48) * 2 ^ k := byintro kinduction k using Nat.strongRecOn with| ind k ih =>intro hk1by_cases hk3 : k ≤ 3· rw [snCost]simp only [hk3, ↓reduceDIte]have hpow : 2 ^ k ≤ 8 := bycalc 2 ^ k ≤ 2 ^ 3 := Nat.pow_le_pow_right (by omega) hk3_ = 8 := by norm_numhave h1 : 3 * 2 ^ k ≤ 60 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48 := by omegaexact Nat.mul_le_mul_right (2 ^ k) h1· by_cases hk4 : k = 4· subst hk4have hval : snCost 4 = 1472 := byrw [snCost]; simp only [show ¬ (4 ≤ 3) by omega, ↓reduceDIte, snSub, dftCost]rw [snCost]; simprw [hval]norm_num· have hk5 : 5 ≤ k := by omegahave hlt : snSub k < k := snSub_lt k (by omega)have hsub1 : 1 ≤ snSub k := by unfold snSub; omegahave hih := ih (snSub k) hlt hsub1set p := k / 2set K := 2 ^ pset L := 2 ^ snSub khave hKL : K * L = 2 * 2 ^ k := bysimp only [K, L, snSub, ← pow_add]rw [show p + ((k + 1) / 2 + 1) = k + 1 by omega, pow_succ]ringhave hdft : 3 * dftCost p L + 3 * K * L + 2 * 2 ^ k ≤ (9 * k + 8) * 2 ^ k := bysimp only [dftCost]have h1 : 3 * (3 * p * K * L) + 3 * K * L + 2 * 2 ^ k =(18 * p + 8) * 2 ^ k := byhave : 3 * (3 * p * K * L) + 3 * K * L = (9 * p + 3) * (K * L) := by ringrw [this, hKL]; ringhave h2 : 18 * p + 8 ≤ 9 * k + 8 := by omegarw [h1]exact Nat.mul_le_mul_right (2 ^ k) h2have hrec : K * snCost (snSub k) ≤(2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48)) * 2 ^ k := bycalc K * snCost (snSub k)≤ K * ((60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48) * L) :=Nat.mul_le_mul_left K hih_ = (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48) * (K * L) := by ring_ = (2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48)) * 2 ^ k := byrw [hKL]; ringhave hhalf : 2 * (snSub k - 3) ≤ k - 3 := by unfold snSub; omegahave hpos_sub : 1 ≤ snSub k - 3 := by unfold snSub; omegahave hlog : Nat.log 2 (snSub k - 3) + 1 ≤ Nat.log 2 (k - 3) := byhave h1 : Nat.log 2 (2 * (snSub k - 3)) = Nat.log 2 (snSub k - 3) + 1 := byrw [mul_comm, Nat.log_mul_base (by omega) (by omega)]rw [← h1]exact Nat.log_mono_right hhalfhave hmain_term :2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1)) ≤60 * (k - 3) * Nat.log 2 (k - 3) := bycalc 2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1))= 60 * (2 * (snSub k - 3)) * (Nat.log 2 (snSub k - 3) + 1) := by ring_ ≤ 60 * (k - 3) * Nat.log 2 (k - 3) := byexact Nat.mul_le_mul (Nat.mul_le_mul_left 60 hhalf) hloghave hcoeff :2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48) + (9 * k + 8) ≤60 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48 := byhave hlin : 56 + 9 * k ≤ 60 * (k - 3) := by omegahave hexp : 60 * (k - 3) * (Nat.log 2 (k - 3) + 1) =60 * (k - 3) * Nat.log 2 (k - 3) + 60 * (k - 3) := by ringomegaconv_lhs => rw [snCost]simp only [hk3, ↓reduceDIte]calc K * snCost (snSub k) + 3 * dftCost p L + 3 * K * L + 2 * 2 ^ k= K * snCost (snSub k) + (3 * dftCost p L + 3 * K * L + 2 * 2 ^ k) := by ring_ ≤ (2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48)) * 2 ^ k +(9 * k + 8) * 2 ^ k := Nat.add_le_add hrec hdft_ = (2 * (60 * (snSub k - 3) * (Nat.log 2 (snSub k - 3) + 1) + 48) + (9 * k + 8)) * 2 ^ k := byring_ ≤ (60 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48) * 2 ^ k :=Nat.mul_le_mul_right (2 ^ k) hcoeffintro k hk1have hs := hstrong k hk1have hlog : Nat.log 2 (k - 3) ≤ Nat.log 2 k := Nat.log_mono_right (Nat.sub_le k 3)have h1 : 60 * (k - 3) * (Nat.log 2 (k - 3) + 1) + 48 ≤ 200 * k * (Nat.log 2 k + 1) := byhave hmul1 : 60 * (k - 3) * (Nat.log 2 (k - 3) + 1) ≤ 60 * k * (Nat.log 2 k + 1) :=Nat.mul_le_mul (Nat.mul_le_mul_left 60 (Nat.sub_le k 3)) (Nat.add_le_add_right hlog 1)have h48 : 48 ≤ 140 * k * (Nat.log 2 k + 1) := byhave : 1 ≤ k * (Nat.log 2 k + 1) := Nat.mul_pos hk1 (by omega)nlinarithhave : 60 * k * (Nat.log 2 k + 1) + 140 * k * (Nat.log 2 k + 1) =200 * k * (Nat.log 2 k + 1) := by ringomegaexact hs.trans (Nat.mul_le_mul_right (2 ^ k) h1)/-- **Unconditional Near-Quadratic Growth (`z_max(τ) = Ω(τ^2 / (log^2 τ (log log τ)^2))`):**For every `k ≥ 2`, there exists a constant-free SLP of length `2000 * k * (Nat.log 2 k + 1) * 2 ^ k`computing a nonzero polynomial in `ℤ[X]` with at least `2 * 4 ^ k + 1` distinct integer roots. -/theorem tau_subquadratic_growth (k : ℕ) (hk : 2 ≤ k) :zMaxGe (2000 * k * (Nat.log 2 k + 1) * 2 ^ k) (2 * 4 ^ k + 1) := byset m := 2 ^ khave hm : 1 ≤ m := Nat.one_le_two_powhave hm2 : m * m = 4 ^ k := bysimp only [m, ← pow_add, show k + k = 2 * k by ring, pow_mul]norm_numhave h2m : 2 * m = 2 ^ (k + 1) := by simp [m, pow_succ, mul_comm]have hsn := canBuild_snMul (k + 1) (chirpA m) (chirpB m)have hSpos : (0 : ℤ) < (2 : ℤ) ^ snScale (k + 1) := by positivityhave hstep :CanBuild({(0 : Polynomial ℤ)} ∪ (⋃ r < m + 1, {chirpA m r}) ∪ (⋃ s < 2 * m, {chirpB m s}))(snCost (k + 1))(⋃ i < m, {Polynomial.C ((2 : ℤ) ^ snScale (k + 1)) *∑ r ∈ Finset.range (m + 1), chirpA m r * chirpB m (i + m - r)}) := byhave hin :({(0 : Polynomial ℤ)} ∪ (⋃ i < 2 ^ (k + 1), {chirpA m i}) ∪(⋃ j < 2 ^ (k + 1), {chirpB m j})) ⊆({(0 : Polynomial ℤ)} ∪ (⋃ r < m + 1, {chirpA m r}) ∪ (⋃ s < 2 * m, {chirpB m s})) := byintro x hxrcases hx with (rfl | hxA) | hxB· left; left; rfl· simp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxArcases hxA with ⟨r, _, rfl⟩by_cases hrm : r ≤ m· left; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨r, by omega, rfl⟩· left; left; simp [chirpA, hrm]· rightsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxB ⊢rcases hxB with ⟨s, hs, rfl⟩exact ⟨s, by omega, rfl⟩refine canBuild_mono_out ?_ (canBuild_mono_in hin hsn)intro x hxsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hx ⊢rcases hx with ⟨i, hi, rfl⟩refine ⟨i + m, by omega, ?_⟩rw [← h2m, negConv_chirp_eq m i hm hi]simp [map_pow]have hz := zMaxGe_of_chirp_engine hm ((2 : ℤ) ^ snScale (k + 1)) hSpos hsteprw [hm2] at hzhave hle : 17 * m + snCost (k + 1) + 14 ≤ 2000 * k * (Nat.log 2 k + 1) * 2 ^ k := byhave hsn_le := snCost_le (k + 1) (by omega)have hlog1 : Nat.log 2 (k + 1) ≤ Nat.log 2 k + 1 := byhave h1 : k + 1 ≤ k * 2 := by omegacalc Nat.log 2 (k + 1) ≤ Nat.log 2 (k * 2) := Nat.log_mono_right h1_ = Nat.log 2 k + 1 := Nat.log_mul_base (by omega) (by omega)have hkl : (k + 1) * (Nat.log 2 (k + 1) + 1) ≤ 4 * k * (Nat.log 2 k + 1) := byhave hk2 : k + 1 ≤ 2 * k := by omegahave hl2 : Nat.log 2 (k + 1) + 1 ≤ 2 * (Nat.log 2 k + 1) := by omegacalc (k + 1) * (Nat.log 2 (k + 1) + 1)≤ (2 * k) * (2 * (Nat.log 2 k + 1)) := Nat.mul_le_mul hk2 hl2_ = 4 * k * (Nat.log 2 k + 1) := by ringhave hsn_bound : snCost (k + 1) ≤ 1600 * k * (Nat.log 2 k + 1) * 2 ^ k := bycalc snCost (k + 1)≤ 200 * (k + 1) * (Nat.log 2 (k + 1) + 1) * 2 ^ (k + 1) := hsn_le_ = 400 * ((k + 1) * (Nat.log 2 (k + 1) + 1)) * 2 ^ k := by rw [pow_succ]; ring_ ≤ 400 * (4 * k * (Nat.log 2 k + 1)) * 2 ^ k :=Nat.mul_le_mul_right (2 ^ k) (Nat.mul_le_mul_left 400 hkl)_ = 1600 * k * (Nat.log 2 k + 1) * 2 ^ k := by ringhave hrem : 17 * m + 14 ≤ 400 * k * (Nat.log 2 k + 1) * 2 ^ k := byhave h1 : 17 * m + 14 ≤ 31 * 2 ^ k := by omegahave h2 : 31 ≤ 400 * k * (Nat.log 2 k + 1) := byhave : 1 ≤ k * (Nat.log 2 k + 1) := Nat.mul_pos (by omega) (by omega)nlinarithexact h1.trans (Nat.mul_le_mul_right (2 ^ k) h2)have hsum : 1600 * k * (Nat.log 2 k + 1) * 2 ^ k + 400 * k * (Nat.log 2 k + 1) * 2 ^ k =2000 * k * (Nat.log 2 k + 1) * 2 ^ k := by ringomegaobtain ⟨d, hd⟩ := Nat.exists_eq_add_of_le hlerw [hd]clear hd hleinduction d with| zero => simpa using hz| succ d ih => exact zMaxGe_succ ih/-- **Unconditional Refutation of Every Sub-Quadratic Exponent `c < 2` in Smale's 4th Problem:**For every real `c < 2`, there is NO real constant `a` such that every nonzero constant-free SLPof length `τ` satisfies `(intRootCount P.evalPoly : ℝ) ≤ a * ((τ : ℝ) + 1) ^ c`. -/theorem tau_refutes_subquadratic (c : ℝ) (hc : c < 2) :¬ ∃ a : ℝ, ∀ (τ : ℕ) (P : SLP τ), P.evalPoly ≠ 0 →(intRootCount P.evalPoly : ℝ) ≤ a * ((τ : ℝ) + 1) ^ c := byrintro ⟨a, ha⟩by_cases hc0 : c ≤ 0· -- When `c ≤ 0`, `(τ + 1)^c ≤ 1`, contradicting unbounded root countsobtain ⟨k, hk⟩ := exists_nat_gt (max a 0)let k' := k + 2rcases tau_subquadratic_growth k' (by omega) with ⟨P, hne, hcard⟩have hub := ha _ P hnehave htau_ge : (1 : ℝ) ≤ ((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1 := bylinarith [Nat.cast_nonneg (α := ℝ) (2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k')]have hrpow_le : (((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1) ^ c ≤ 1 :=Real.rpow_le_one_of_one_le_of_nonpos htau_ge hc0have h4gt : (k : ℝ) < (2 * 4 ^ k' + 1 : ℕ) := byhave h1 : k < 2 * 4 ^ k' + 1 := byhave : k' < 2 ^ k' := Nat.lt_two_pow_selfhave : 2 ^ k' ≤ 4 ^ k' := Nat.pow_le_pow_left (by omega) k'omegaexact_mod_cast h1have hcardR : ((2 * 4 ^ k' + 1 : ℕ) : ℝ) ≤ (intRootCount P.evalPoly : ℝ) := by exact_mod_cast hcardhave hle_a : a * (((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1) ^ c ≤ max a 0 := byhave hrpos : 0 ≤ (((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1) ^ c := by positivitycalc a * (((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1) ^ c≤ max a 0 * (((2000 * k' * (Nat.log 2 k' + 1) * 2 ^ k' : ℕ) : ℝ) + 1) ^ c :=mul_le_mul_of_nonneg_right (le_max_left a 0) hrpos_ ≤ max a 0 * 1 := mul_le_mul_of_nonneg_left hrpow_le (le_max_right a 0)_ = max a 0 := mul_one _linarith· push Not at hc0have hgap : 0 < 2 - c := by linarithobtain ⟨M0, hM0⟩ := exists_nat_gt (1 / (2 - c))let M := M0 + 1have hMpos : 1 ≤ M := by omegahave hMgap : (1 : ℝ) ≤ (2 - c) * (M : ℝ) := byhave h1 : 1 / (2 - c) < (M : ℝ) := byhave : (M0 : ℝ) < (M : ℝ) := by exact_mod_cast (by omega : M0 < M)linarithhave h2 := (div_lt_iff₀ hgap).mp h1linarithlet B : ℝ := max a 0 * ((2001 : ℝ) * ((5 * M + 1 : ℕ) : ℝ) ^ 2) ^ 2obtain ⟨t0, ht0⟩ := exists_nat_gt Blet t := t0 + 2let k := 5 * M * thave hk2 : 2 ≤ k := byhave h1 : 5 * 1 * 2 ≤ 5 * M * t :=Nat.mul_le_mul (Nat.mul_le_mul_left 5 hMpos) (by omega)exact le_trans (by omega : 2 ≤ 5 * 1 * 2) h1set τ := 2000 * k * (Nat.log 2 k + 1) * 2 ^ krcases tau_subquadratic_growth k hk2 with ⟨P, hne, hcard⟩have hub := ha τ P hnehave htau_nat : τ + 1 ≤ 2001 * (k + 1) ^ 2 * 2 ^ k := byhave hlog : Nat.log 2 k ≤ k := Nat.log_le_self 2 khave h1 : τ ≤ 2000 * (k + 1) ^ 2 * 2 ^ k := byhave hkk : k * (Nat.log 2 k + 1) ≤ (k + 1) ^ 2 := byhave : k * (Nat.log 2 k + 1) ≤ (k + 1) * (k + 1) :=Nat.mul_le_mul (by omega) (by omega)simpa [sq] using thiscalc τ = 2000 * (k * (Nat.log 2 k + 1)) * 2 ^ k := by ring_ ≤ 2000 * (k + 1) ^ 2 * 2 ^ k :=Nat.mul_le_mul_right (2 ^ k) (Nat.mul_le_mul_left 2000 hkk)have h2 : 1 ≤ (k + 1) ^ 2 * 2 ^ k := byhave ha1 : 1 ≤ (k + 1) ^ 2 := by nlinarithhave hb1 : 1 ≤ 2 ^ k := Nat.one_le_two_powexact Nat.mul_pos ha1 hb1linarithhave htau_R : ((τ : ℝ) + 1) ≤ ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) * (2 : ℝ) ^ k := byexact_mod_cast htau_nathave hbase_ge1 : (1 : ℝ) ≤ (2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2 := byhave h1 : (1 : ℝ) ≤ ((k + 1 : ℕ) : ℝ) ^ 2 := byexact_mod_cast (by nlinarith : 1 ≤ (k + 1) ^ 2)nlinarithhave hrpow_bound :((τ : ℝ) + 1) ^ c ≤((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2 * (2 : ℝ) ^ (c * (k : ℝ)) := byhave h1 : ((τ : ℝ) + 1) ^ c ≤(((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) * (2 : ℝ) ^ k) ^ c :=Real.rpow_le_rpow (by positivity) htau_R (le_of_lt hc0)rw [Real.mul_rpow (by positivity) (by positivity)] at h1have h2 : ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ c ≤((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ (2 : ℝ) :=Real.rpow_le_rpow_of_exponent_le hbase_ge1 (le_of_lt hc)have h2' : ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ (2 : ℝ) =((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2 := by norm_casthave h3 : ((2 : ℝ) ^ k) ^ c = (2 : ℝ) ^ (c * (k : ℝ)) := byrw [← Real.rpow_natCast (2 : ℝ) k, ← Real.rpow_mul (by norm_num : (0 : ℝ) ≤ 2), mul_comm]rw [h2'] at h2rw [h3] at h1exact h1.trans (mul_le_mul_of_nonneg_right h2 (by positivity))have hk_le : ((k + 1 : ℕ) : ℝ) ≤ ((5 * M + 1 : ℕ) : ℝ) * (t : ℝ) := byhave : k + 1 ≤ (5 * M + 1) * t := bydsimp only [k]have : 1 ≤ t := by omeganlinarithexact_mod_cast thishave hpoly_bound :max a 0 * ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2 ≤ B * (t : ℝ) ^ 4 := byhave hsq : ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2 ≤((2001 : ℝ) * (((5 * M + 1 : ℕ) : ℝ) * (t : ℝ)) ^ 2) ^ 2 := bygcongrcalc max a 0 * ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2≤ max a 0 * ((2001 : ℝ) * (((5 * M + 1 : ℕ) : ℝ) * (t : ℝ)) ^ 2) ^ 2 :=mul_le_mul_of_nonneg_left hsq (le_max_right a 0)_ = B * (t : ℝ) ^ 4 := by dsimp only [B]; ringhave h4eq : ((2 * 4 ^ k + 1 : ℕ) : ℝ) > (2 : ℝ) ^ (2 * k) := byhave h1 : 2 ^ (2 * k) < 2 * 4 ^ k + 1 := byhave hpow : 2 ^ (2 * k) = 4 ^ k := by rw [pow_mul]; norm_numomegaexact_mod_cast h1have hcardR : ((2 * 4 ^ k + 1 : ℕ) : ℝ) ≤ (intRootCount P.evalPoly : ℝ) := by exact_mod_cast hcardhave hLHS : (2 : ℝ) ^ ((2 : ℝ) * (k : ℝ)) < (intRootCount P.evalPoly : ℝ) := byhave h2k : (2 : ℝ) ^ ((2 : ℝ) * (k : ℝ)) = (2 : ℝ) ^ (2 * k) := byrw [← Real.rpow_natCast (2 : ℝ) (2 * k)]congr 1; push_cast; ringrw [h2k]linarithhave hRHS : (intRootCount P.evalPoly : ℝ) ≤ B * (t : ℝ) ^ 4 * (2 : ℝ) ^ (c * (k : ℝ)) := bycalc (intRootCount P.evalPoly : ℝ)≤ a * ((τ : ℝ) + 1) ^ c := hub_ ≤ max a 0 * ((τ : ℝ) + 1) ^ c :=mul_le_mul_of_nonneg_right (le_max_left a 0) (by positivity)_ ≤ max a 0 * (((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2 * (2 : ℝ) ^ (c * (k : ℝ))) :=mul_le_mul_of_nonneg_left hrpow_bound (le_max_right a 0)_ = (max a 0 * ((2001 : ℝ) * ((k + 1 : ℕ) : ℝ) ^ 2) ^ 2) * (2 : ℝ) ^ (c * (k : ℝ)) := by ring_ ≤ (B * (t : ℝ) ^ 4) * (2 : ℝ) ^ (c * (k : ℝ)) :=mul_le_mul_of_nonneg_right hpoly_bound (by positivity)-- Divide out `(2 : ℝ) ^ (c * k) > 0`: gives `(2 : ℝ) ^ ((2 - c) * k) < B * t^4`have h2split : (2 : ℝ) ^ ((2 : ℝ) * (k : ℝ)) =(2 : ℝ) ^ ((2 - c) * (k : ℝ)) * (2 : ℝ) ^ (c * (k : ℝ)) := byrw [← Real.rpow_add (by norm_num : (0 : ℝ) < 2)]congr 1; ringhave h2ck_pos : (0 : ℝ) < (2 : ℝ) ^ (c * (k : ℝ)) := by positivityhave hdiv : (2 : ℝ) ^ ((2 - c) * (k : ℝ)) < B * (t : ℝ) ^ 4 := byhave hlt : (2 : ℝ) ^ ((2 - c) * (k : ℝ)) * (2 : ℝ) ^ (c * (k : ℝ)) <(B * (t : ℝ) ^ 4) * (2 : ℝ) ^ (c * (k : ℝ)) := byrw [← h2split]; linarithexact lt_of_mul_lt_mul_right hlt (le_of_lt h2ck_pos)-- Meanwhile `(2 - c) * k = (2 - c) * M * (5 * t) ≥ 5 * t`, and `2^(5 * t) = 2^t * (2^t)^4 > B * t^4`!have hexp_ge : ((5 * t : ℕ) : ℝ) ≤ (2 - c) * (k : ℝ) := byhave hkR : (k : ℝ) = (M : ℝ) * ((5 * t : ℕ) : ℝ) := bydsimp only [k]; push_cast; ringrw [hkR, ← mul_assoc]calc ((5 * t : ℕ) : ℝ) = 1 * ((5 * t : ℕ) : ℝ) := (one_mul _).symm_ ≤ ((2 - c) * (M : ℝ)) * ((5 * t : ℕ) : ℝ) :=mul_le_mul_of_nonneg_right hMgap (by positivity)have h2_5t : (2 : ℝ) ^ (5 * t) ≤ (2 : ℝ) ^ ((2 - c) * (k : ℝ)) := byrw [← Real.rpow_natCast (2 : ℝ) (5 * t)]exact Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : ℝ) ≤ 2) hexp_gehave ht_lt_2t : (t : ℝ) < (2 : ℝ) ^ t := by exact_mod_cast (Nat.lt_two_pow_self (n := t))have hB_lt_2t : B < (2 : ℝ) ^ t := byhave : (t0 : ℝ) < (t : ℝ) := by exact_mod_cast (by omega : t0 < t)linarithhave hB_nonneg : 0 ≤ B := bydsimp only [B]exact mul_nonneg (le_max_right a 0) (sq_nonneg _)have hpow4 : (t : ℝ) ^ 4 ≤ ((2 : ℝ) ^ t) ^ 4 := by gcongrhave h2_5t_eq : (2 : ℝ) ^ (5 * t) = (2 : ℝ) ^ t * ((2 : ℝ) ^ t) ^ 4 := byrw [← pow_mul, ← pow_add]; congr 1; ringhave hcontra : B * (t : ℝ) ^ 4 < (2 : ℝ) ^ (5 * t) := byrw [h2_5t_eq]calc B * (t : ℝ) ^ 4 ≤ B * ((2 : ℝ) ^ t) ^ 4 := mul_le_mul_of_nonneg_left hpow4 hB_nonneg_ < (2 : ℝ) ^ t * ((2 : ℝ) ^ t) ^ 4 := mul_lt_mul_of_pos_right hB_lt_2t (by positivity)linarith/-! ## 6. Machine-Verified Concrete Finite Crossover (`z_max(1884) ≥ 2049 > 1884`) -//-- Exact middle product of length `n`:`midProd n P Q i = ∑ r < n, P r * Q (i + n - 1 - r)` for `i < n` (reading `P` on `0 .. n-1`and `Q` on `0 .. 2*n - 2`). -/noncomputable def midProd (n : ℕ) (P Q : ℕ → Polynomial ℤ) (i : ℕ) : Polynomial ℤ :=∑ r ∈ Finset.range n, P r * Q (i + n - 1 - r)/-- Exact gate cost of power-of-2 Karatsuba middle product with base case `k = 2` (`n = 4`):`midCost 2 = 28`, `midCost (k + 1) = 3 * midCost k + 7 * 2^k - 2`.At `k = 5` (`n = 32`): `midCost 5 = 1262`. -/def midCost : ℕ → ℕ| 0 => 1| 1 => 6| 2 => 28| k + 1 => 3 * midCost k + 7 * 2 ^ k - 2theorem midProd_even_lo (h : ℕ) (P Q : ℕ → Polynomial ℤ) (i : ℕ) :let P0 := fun r => P rlet P1 := fun r => P (r + h)let Psum := fun r => P0 r + P1 rlet Qlo := fun s => Q slet Qmid := fun s => Q (s + h)let Q1 := fun s => Qlo s - Qmid smidProd (2 * h) P Q i = midProd h Psum Qmid i + midProd h P1 Q1 i := byintro P0 P1 Psum Qlo Qmid Q1unfold midProdrw [show 2 * h = h + h by ring, Finset.sum_range_add]simp only [← Finset.sum_add_distrib]refine Finset.sum_congr rfl ?_intro r hrrw [Finset.mem_range] at hrhave h1 : i + (h + h) - 1 - r = i + h - 1 - r + h := by omegahave h2 : i + (h + h) - 1 - (h + r) = i + h - 1 - r := by omegahave h3 : h + r = r + h := by omegadsimp only [Psum, P0, P1, Qmid, Q1, Qlo]rw [h1, h2, h3]ringtheorem midProd_even_hi (h : ℕ) (P Q : ℕ → Polynomial ℤ) (i : ℕ) :let P0 := fun r => P rlet P1 := fun r => P (r + h)let Psum := fun r => P0 r + P1 rlet Qmid := fun s => Q (s + h)let Qhi := fun s => Q (s + 2 * h)let Q2 := fun s => Qhi s - Qmid smidProd (2 * h) P Q (i + h) = midProd h Psum Qmid i + midProd h P0 Q2 i := byintro P0 P1 Psum Qmid Qhi Q2unfold midProdrw [show 2 * h = h + h by ring, Finset.sum_range_add]simp only [← Finset.sum_add_distrib]refine Finset.sum_congr rfl ?_intro r hrrw [Finset.mem_range] at hrhave h1 : i + h + (h + h) - 1 - r = i + h - 1 - r + 2 * h := by omegahave h2 : i + h + (h + h) - 1 - (h + r) = i + h - 1 - r + h := by omegahave h3 : h + r = r + h := by omegadsimp only [Psum, P0, P1, Qmid, Q2, Qhi]rw [h1, h2, h3]ring/-- Helper: sum of `4` given wires `f 0 + f 1 + f 2 + f 3` in `3` gates (no `0` wire needed!). -/theorem canBuild_sum4 (a b c d : Polynomial ℤ) :CanBuild ({a, b, c, d} : Set (Polynomial ℤ)) 3 {a + b + c + d} := byhave s1 := canBuild_mono_in (S₂ := {a, b, c, d})(by intro x hx; rcases hx with rfl | rfl <;> simp) (canBuild_add a b)have s2 := canBuild_trans s1 (by intro x hx; rcases hx with rfl | rfl <;> simp)(canBuild_add (a + b) c)have s3 := canBuild_trans s2 (by intro x hx; rcases hx with rfl | rfl <;> simp)(canBuild_add (a + b + c) d)exact canBuild_mono_out (fun x hx => Or.inr hx) s3/-- Base case `k = 2` (`n = 4`): schoolbook `4 × 4` middle product in `28 = 4 * 7` gates. -/theorem canBuild_midProd_four (P Q : ℕ → Polynomial ℤ) :CanBuild ((⋃ r < 4, {P r}) ∪ (⋃ s < 7, {Q s})) 28 (⋃ i < 4, {midProd 4 P Q i}) := byrefine canBuild_fin_union (n := 4) (d := 7) (T := fun i => {midProd 4 P Q i}) ?_intro i hihave h4m :CanBuild ((⋃ r < 4, {P r}) ∪ (⋃ s < 7, {Q s})) 4(⋃ r < 4, {P r * Q (i + 3 - r)}) := bysimpa using canBuild_fin_union (n := 4) (d := 1)(S := (⋃ r < 4, {P r}) ∪ (⋃ s < 7, {Q s}))(T := fun r => {P r * Q (i + 3 - r)}) (byintro r hrrefine canBuild_mono_in ?_ (canBuild_mul (P r) (Q (i + 3 - r)))intro x hx; rcases hx with rfl | rfl· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨r, hr, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i + 3 - r, by omega, rfl⟩)have hs := canBuild_sum4 (P 0 * Q (i + 3 - 0)) (P 1 * Q (i + 3 - 1))(P 2 * Q (i + 3 - 2)) (P 3 * Q (i + 3 - 3))have hcomb := canBuild_trans h4m (byintro x hxrcases hx with rfl | rfl | rfl | rfl <;>· right; simp only [Set.mem_iUnion, exists_prop]first | exact ⟨0, by omega, rfl⟩ | exact ⟨1, by omega, rfl⟩| exact ⟨2, by omega, rfl⟩ | exact ⟨3, by omega, rfl⟩) hsrefine canBuild_mono_out ?_ hcombintro x hx; rw [Set.mem_singleton_iff] at hx; subst hxright; rw [Set.mem_singleton_iff]simp [midProd, Finset.sum_range_succ, add_assoc]/-- **Power-of-2 Karatsuba Middle Product (`CanBuild`) for `k ≥ 2`:**Computes `{midProd (2^k) P Q i | i < 2^k}` in `midCost k` gates (`midCost 5 = 1262`). -/theorem canBuild_karaMid :∀ (k : ℕ), 2 ≤ k →∀ (P Q : ℕ → Polynomial ℤ),CanBuild((⋃ r < 2 ^ k, {P r}) ∪ (⋃ s < 2 * 2 ^ k - 1, {Q s}))(midCost k)(⋃ i < 2 ^ k, {midProd (2 ^ k) P Q i})| 0, hk, _, _ => by omega| 1, hk, _, _ => by omega| 2, _, P, Q => bysimpa [midCost] using canBuild_midProd_four P Q| k + 3, _, P, Q => byset h := 2 ^ (k + 2)have hh : 2 ^ (k + 3) = 2 * h := by simp [h, pow_succ, mul_comm]have hpos : 1 ≤ h := Nat.one_le_two_powlet P0 := fun r => P rlet P1 := fun r => P (r + h)let Psum := fun r => P0 r + P1 rlet Qlo := fun s => Q slet Qmid := fun s => Q (s + h)let Qhi := fun s => Q (s + 2 * h)let Q1 := fun s => Qlo s - Qmid slet Q2 := fun s => Qhi s - Qmid slet M0 := midProd h Psum Qmidlet M1 := midProd h P1 Q1let M2 := midProd h P0 Q2set S0 : Set (Polynomial ℤ) :=(⋃ r < 2 ^ (k + 3), {P r}) ∪ (⋃ s < 2 * 2 ^ (k + 3) - 1, {Q s})-- Step 1 (`h` gates): Psumhave hPsum : CanBuild S0 h (⋃ r < h, {Psum r}) := bysimpa using canBuild_fin_union (n := h) (d := 1) (S := S0) (T := fun r => {Psum r}) (byintro r hrrefine canBuild_mono_in ?_ (canBuild_add (P0 r) (P1 r))intro x hx; rcases hx with rfl | rfl· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨r, by omega, rfl⟩· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨r + h, by omega, rfl⟩)-- Step 2 (`2*h - 1` gates): Q1have hQ1 : CanBuild S0 (2 * h - 1) (⋃ s < 2 * h - 1, {Q1 s}) := bysimpa using canBuild_fin_union (n := 2 * h - 1) (d := 1) (S := S0) (T := fun s => {Q1 s}) (byintro s hsrefine canBuild_mono_in ?_ (canBuild_sub (Qlo s) (Qmid s))intro x hx; rcases hx with rfl | rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨s, by omega, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨s + h, by omega, rfl⟩)-- Step 3 (`2*h - 1` gates): Q2have hQ2 : CanBuild S0 (2 * h - 1) (⋃ s < 2 * h - 1, {Q2 s}) := bysimpa using canBuild_fin_union (n := 2 * h - 1) (d := 1) (S := S0) (T := fun s => {Q2 s}) (byintro s hsrefine canBuild_mono_in ?_ (canBuild_sub (Qhi s) (Qmid s))intro x hx; rcases hx with rfl | rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨s + 2 * h, by omega, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨s + h, by omega, rfl⟩)-- Step 4 (`3 * midCost (k + 2)` gates): M0, M1, M2have hM0 := canBuild_karaMid (k + 2) (by omega) Psum Qmidhave hM1 := canBuild_karaMid (k + 2) (by omega) P1 Q1have hM2 := canBuild_karaMid (k + 2) (by omega) P0 Q2have c1 := canBuild_trans hPsum Set.subset_union_left hQ1have c2 := canBuild_trans c1 Set.subset_union_left hQ2have c3 := canBuild_trans c2 (byintro x hx; rcases hx with hxP | hxQ· right; left; left; exact hxP· left; right; simp only [Set.mem_iUnion, exists_prop] at hxQ ⊢rcases hxQ with ⟨s, hs, hxs⟩; exact ⟨s + h, by omega, hxs⟩) hM0have c4 := canBuild_trans c3 (byintro x hx; rcases hx with hxP | hxQ· left; left; simp only [Set.mem_iUnion, exists_prop] at hxP ⊢rcases hxP with ⟨r, hr, hxr⟩; exact ⟨r + h, by omega, hxr⟩· right; left; left; right; exact hxQ) hM1have c5 := canBuild_trans c4 (byintro x hx; rcases hx with hxP | hxQ· left; left; simp only [Set.mem_iUnion, exists_prop] at hxP ⊢rcases hxP with ⟨r, hr, hxr⟩; exact ⟨r, by omega, hxr⟩· right; left; left; right; exact hxQ) hM2-- Step 5 (`2 * h` gates): combine M0 + M1 and M0 + M2have hComb1 :CanBuild ((⋃ i < h, {M0 i}) ∪ (⋃ i < h, {M1 i})) h(⋃ i < h, {M0 i + M1 i}) := bysimpa using canBuild_fin_union (n := h) (d := 1) (T := fun i => {M0 i + M1 i}) (byintro i hirefine canBuild_mono_in ?_ (canBuild_add (M0 i) (M1 i))intro x hx; rcases hx with rfl | rfl· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩)have hComb2 :CanBuild ((⋃ i < h, {M0 i}) ∪ (⋃ i < h, {M2 i})) h(⋃ i < h, {M0 i + M2 i}) := bysimpa using canBuild_fin_union (n := h) (d := 1) (T := fun i => {M0 i + M2 i}) (byintro i hirefine canBuild_mono_in ?_ (canBuild_add (M0 i) (M2 i))intro x hx; rcases hx with rfl | rfl· left; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩)have c6 := canBuild_trans c5 (byintro x hx; rcases hx with hx0 | hx1· right; left; left; right; exact hx0· right; left; right; exact hx1) hComb1have c7 := canBuild_trans c6 (byintro x hx; rcases hx with hx0 | hx2· right; left; left; left; right; exact hx0· right; left; right; exact hx2) hComb2have hcost :h + (2 * h - 1) + (2 * h - 1) + midCost (k + 2) + midCost (k + 2) + midCost (k + 2) +h + h = midCost (k + 3) := bychange _ = 3 * midCost (k + 2) + 7 * 2 ^ (k + 2) - 2omegarw [hcost] at c7refine canBuild_mono_out ?_ c7intro x hxsimp only [Set.mem_iUnion, exists_prop, Set.mem_singleton_iff] at hxrcases hx with ⟨i, hi, rfl⟩by_cases hih : i < h· rw [hh, midProd_even_lo h P Q i]left; rightsimp only [Set.mem_iUnion, exists_prop]exact ⟨i, hih, rfl⟩· have hi_eq : i = (i - h) + h := by omegarw [hh, hi_eq, midProd_even_hi h P Q (i - h)]rightsimp only [Set.mem_iUnion, exists_prop]exact ⟨i - h, by omega, rfl⟩/-- **Machine-Verified Concrete Finite Crossover (`z_max(1884) ≥ 2049 > 1884`):**There exists a constant-free straight-line program of length `1884` over `ℤ[X]` computing anonzero polynomial with at least `2049` distinct integer roots (`2049 > 1884`, provingstrictly more distinct integer roots than gates at an explicit finite length). -/theorem tau_crossover_1884_2049 : zMaxGe 1884 2049 := by-- Use m = 32 = 2^5: `chirp_middle_product` = `midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i + chirpA 32 32 * chirpB 32 i`have hmid := canBuild_karaMid 5 (by omega) (chirpA 32) (fun s => chirpB 32 (s + 1))set S0 : Set (Polynomial ℤ) :={(0 : Polynomial ℤ)} ∪ (⋃ r < 32 + 1, {chirpA 32 r}) ∪ (⋃ s < 2 * 32, {chirpB 32 s})have h1 : CanBuild S0 (midCost 5) (⋃ i < 32, {midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i}) := byrefine canBuild_mono_in ?_ hmidintro x hx; rcases hx with hxA | hxB· left; right; simp only [Set.mem_iUnion, exists_prop] at hxA ⊢rcases hxA with ⟨r, hr, hxr⟩; exact ⟨r, by omega, hxr⟩· right; simp only [Set.mem_iUnion, exists_prop] at hxB ⊢rcases hxB with ⟨s, hs, hxs⟩; exact ⟨s + 1, by omega, hxs⟩-- Add the `r = 32` term `chirpA 32 32 * chirpB 32 i` (`2 * 32 = 64` gates)have h2 :CanBuild(S0 ∪ ⋃ i < 32, {midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i})(32 * 2)(⋃ i < 32, {Polynomial.C (1 : ℤ) *∑ r ∈ Finset.range (32 + 1), chirpA 32 r * chirpB 32 (i + 32 - r)}) := byrefine canBuild_fin_union (n := 32) (d := 2)(T := fun i => {Polynomial.C (1 : ℤ) *∑ r ∈ Finset.range (32 + 1), chirpA 32 r * chirpB 32 (i + 32 - r)}) ?_intro i hihave hm := canBuild_mul (chirpA 32 32) (chirpB 32 i)have ha := canBuild_add (midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i)(chirpA 32 32 * chirpB 32 i)have hma := canBuild_trans(canBuild_mono_in (S₂ := {midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i,chirpA 32 32, chirpB 32 i}) (by intro x hx; rcases hx with rfl | rfl <;> simp) hm)(by intro x hx; rcases hx with rfl | rfl <;> simp) hahave heq :midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i + chirpA 32 32 * chirpB 32 i =Polynomial.C (1 : ℤ) *∑ r ∈ Finset.range (32 + 1), chirpA 32 r * chirpB 32 (i + 32 - r) := byrw [map_one, one_mul, Finset.sum_range_succ, show i + 32 - 32 = i by omega]have hsum : midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i =∑ r ∈ Finset.range 32, chirpA 32 r * chirpB 32 (i + 32 - r) := byunfold midProdrefine Finset.sum_congr rfl ?_intro r hrrw [Finset.mem_range] at hrhave hidx : i + 32 - 1 - r + 1 = i + 32 - r := by omegadsimp onlyrw [hidx]rw [hsum]refine canBuild_mono_out(T₂ := {chirpA 32 32 * chirpB 32 i} ∪{midProd 32 (chirpA 32) (fun s => chirpB 32 (s + 1)) i + chirpA 32 32 * chirpB 32 i})(by intro x hx; rw [Set.mem_singleton_iff] at hx; subst hx; right; rw [Set.mem_singleton_iff, heq])(canBuild_mono_in ?_ hma)intro x hxrcases hx with rfl | rfl | rfl· right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, hi, rfl⟩· left; left; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨32, by omega, rfl⟩· left; right; simp only [Set.mem_iUnion, exists_prop]; exact ⟨i, by omega, rfl⟩have hstep := canBuild_mono_out Set.subset_union_right (canBuild_seq h1 h2)have hz := zMaxGe_of_chirp_engine (m := 32) (by omega) 1 (by omega) hstephave hcost : 17 * 32 + (midCost 5 + 32 * 2) + 14 = 1884 := by decidehave hroots : 2 * (32 * 32) + 1 = 2049 := by deciderwa [hcost, hroots] at hz/-- Existential witness that constant-free SLPs over `ℤ[X]` strictly beat `z_max(τ) ≤ τ`. -/theorem tau_exists_roots_gt_gates : ∃ τ r : ℕ, τ < r ∧ zMaxGe τ r :=⟨1884, 2049, by omega, tau_crossover_1884_2049⟩end Research.PvsNP.Tauend