import Mathlib import OAI.NumberTheory.CubicGauss.PowerBounds import OAI.NumberTheory.CubicGauss.ScalarBounds namespace OAI /-! Gaussian power factoring and the cubic-sieve exponent recurrence. -/ noncomputable section open scoped BigOperators open Module Complex UniqueFactorizationMonoid attribute [local instance] Classical.propDecidable namespace CubicFirstMoment lemma cubic_conjugate_row_energy (S : Finset Eisenstein) (u : Eisenstein → ℂ) (m : Eisenstein) : ‖∑ a ∈ S,u a*star (cubicSymbol a m)‖^2 = cubicRowEnergy S (fun a => star (u a)) m := by change _ = ‖∑ a ∈ S,star (u a)*cubicSymbol a m‖^2 have he : (∑ a ∈ S,u a*star (cubicSymbol a m)) = star (∑ a ∈ S,star (u a)*cubicSymbol a m) := by simp rw [he,norm_star] lemma full_power_cutoff {α ε C X Y : ℝ} (hC : 0≤C) (hY : 1≤Y) (hbound : ∀ (X Y : ℝ) (S : Finset Eisenstein) (u : Eisenstein → ℂ), 1≤X → 1≤Y → S ⊆ squarefreePrimaryBall Y → ∑ m ∈ nonzeroNormBall X,cubicRowEnergy S u m ≤ C*(X*Y)^ε*(X^α+Y*X^(1/3:ℝ)+(X*Y)^(2/3:ℝ))*∑ b ∈ S,‖u b‖^2) (hX : 0 norm m norm m sq_nonneg _)).trans apply (hbound X Y S u hX1 hY hS).trans_eq rw [Real.mul_rpow hX.le hY0,Real.mul_rpow hX.le hY0] simp only [Real.rpow_add hX] ring · have he : ((H.filter (· ≠ 0)).filter (fun m => norm m 1+C*Y^ε*((2/r)^(α+ε)+Y*(2/r)^((1/3:ℝ)+ε)+Y^(2/3:ℝ)*(2/r)^((2/3:ℝ)+ε))) := by obtain ⟨C,hC,hbound⟩ := hB ε hε let G : ℝ := Real.Gamma (α+ε+1)+Real.Gamma ((1/3:ℝ)+ε+1)+Real.Gamma ((2/3:ℝ)+ε+1) have hg1 : 0 sq_nonneg _ have hEs : (∑ a ∈ S,‖star (u a)‖^2) = E := by simp [E] let X : ℝ := 2/r have hX : 0 cubicRowEnergy S (fun a => star (u a)) m) (X := X) (a := C*Y^ε*E) (b := C*Y^ε*Y*E) (c := C*Y^ε*Y^(2/3:ℝ)*E) (p := α+ε) (q := (1/3:ℝ)+ε) (s := (2/3:ℝ)+ε) hX (by linarith) (by linarith) (by linarith) (fun m _ => norm_nonneg m) (by intro T hT have hb := full_power_cutoff hC.le hY hbound hT S H hS (fun a => star (u a)) rw [hEs] at hb apply hb.trans_eq ring) have hn : (∑ m ∈ H0,Real.exp (-r*norm m/2)*‖∑ a ∈ S,u a*star (cubicSymbol a m)‖^2) ≤ (C*G)*Y^ε*(X^(α+ε)+Y*X^((1/3:ℝ)+ε)+Y^(2/3:ℝ)*X^((2/3:ℝ)+ε))*E := by have he (m : Eisenstein) : -norm m/X = -r*norm m/2 := by dsimp [X]; field_simp simp_rw [he] at hb simp_rw [cubic_conjugate_row_energy] apply hb.trans have h1 : Real.Gamma (α+ε+1) ≤ G := by dsimp [G]; linarith have h2 : Real.Gamma ((1/3:ℝ)+ε+1) ≤ G := by dsimp [G]; linarith have h3 : Real.Gamma ((2/3:ℝ)+ε+1) ≤ G := by dsimp [G]; linarith calc _ ≤ (C*Y^ε*E)*X^(α+ε)*G+(C*Y^ε*Y*E)*X^((1/3:ℝ)+ε)*G+ (C*Y^ε*Y^(2/3:ℝ)*E)*X^((2/3:ℝ)+ε)*G := by gcongr _ = _ := by ring have hsub : H ⊆ insert 0 H0 := by intro m hm by_cases h0 : m=0 · simp [h0] · exact Finset.mem_insert_of_mem (Finset.mem_filter.mpr ⟨hm,h0⟩) have hz := cubic_zero_row_bound S (fun a ha => (mem_squarefreePrimaryBall.mp (hS ha)).1) u have hb' := Finset.sum_le_sum_of_subset_of_nonneg hsub (f := fun m => Real.exp (-r*norm m/2)*‖∑ a ∈ S,u a*star (cubicSymbol a m)‖^2) (fun m _ _ => by positivity) rw [Finset.sum_insert (show (0:Eisenstein)∉H0 by simp [H0])] at hb' have hn0 : norm (0:Eisenstein)=0 := by simp [norm] simp only [hn0,mul_zero,zero_div,Real.exp_zero,one_mul] at hb' apply hb'.trans calc _ ≤ E+(C*G)*Y^ε*(X^(α+ε)+Y*X^((1/3:ℝ)+ε)+Y^(2/3:ℝ)*X^((2/3:ℝ)+ε))*E := add_le_add hz hn _ = _ := by dsimp only [E,X]; ring open SieveScalar def recurrenceEnvelope (M N α : ℝ) : ℝ := M+M^(1-α)*N^(2*α-1)+(M*N)^(2/3:ℝ)+M^(1/3:ℝ)*N lemma recurrenceEnvelope_nonneg {M N α : ℝ} (hM : 0≤M) (hN : 0≤N) : 0≤recurrenceEnvelope M N α := by unfold recurrenceEnvelope; positivity lemma gaussian_power_factor_abstract {M N k d α ε C P X : ℝ} (hM : 1≤M) (hN : 1≤N) (hk : 1≤k) (hkN : k≤N) (hd : 1≤d) (hdk : d≤k) (hα : 1≤α) (hε : 0≤ε) (hC : 0≤C) (hP : 0≤P) (hX : 0 (mem_squarefreePrimaryBall.mp (hS ha)).1 let K : ℝ → ℝ → ℝ := fun Y r => 1+C*Y^δ*((2/r)^(α+δ)+Y*(2/r)^((1/3:ℝ)+δ)+Y^(2/3:ℝ)*(2/r)^((2/3:ℝ)+δ)) have hb := cubic_gaussian_positive_bound hN0 S hS hthin u (1/M) ht K hK apply (cubic_cutoff_le_gaussian hM0 S hs u).trans apply (mul_le_mul_of_nonneg_left hb (Real.exp_pos _).le).trans have hh : (∑ k ∈ squarefreePrimaryBall N,∑ d ∈ primaryDivisors k, (2/(Real.sqrt 3*(1/M)*norm d)) * (7*K (N/norm k) (4*Real.pi/(3*((1/M)*norm d)*((9/10:ℝ)*N/norm k)^2))/((9/10:ℝ)*N/norm k)) * ∑ l ∈ squarefreePrimaryBall (N/norm k), ∑ a ∈ (sieveFiber N S k).filter (l ∣ ·),‖u (k*a)‖^2) ≤ (16*(1+C)*N^(3*δ)*recurrenceEnvelope M N α)*(D*N^δ*∑ b ∈ S,‖u b‖^2) := by calc _ ≤ ∑ k ∈ squarefreePrimaryBall N,∑ _d ∈ primaryDivisors k, (16*(1+C)*N^(3*δ)*recurrenceEnvelope M N α)* ∑ l ∈ squarefreePrimaryBall (N/norm k), ∑ a ∈ (sieveFiber N S k).filter (l ∣ ·),‖u (k*a)‖^2 := by apply Finset.sum_le_sum intro k hk obtain ⟨hkp,hks,hkn⟩ := mem_squarefreePrimaryBall.mp hk apply Finset.sum_le_sum intro d hd obtain ⟨hdp,hdk⟩ := (mem_primaryDivisors (primary_ne_zero hkp)).mp hd apply mul_le_mul_of_nonneg_right _ (Finset.sum_nonneg fun l _ => Finset.sum_nonneg fun a _ => sq_nonneg _) exact gaussian_power_factor hM hN (one_le_norm (primary_ne_zero hkp)) hkn (one_le_norm (primary_ne_zero hdp)) (norm_le_of_dvd (primary_ne_zero hkp) hdk) hα hδ.le hC.le _ = (16*(1+C)*N^(3*δ)*recurrenceEnvelope M N α)* (∑ k ∈ squarefreePrimaryBall N,∑ _d ∈ primaryDivisors k, ∑ l ∈ squarefreePrimaryBall (N/norm k), ∑ a ∈ (sieveFiber N S k).filter (l ∣ ·),‖u (k*a)‖^2) := by simp only [Finset.mul_sum] _ ≤ _ := mul_le_mul_of_nonneg_left (hDsum N S u hN hS) (by have := recurrenceEnvelope_nonneg hM0.le hN0.le (α := α) positivity) apply (mul_le_mul_of_nonneg_left hh (Real.exp_pos _).le).trans_eq have hp : N^(3*δ)*N^δ=N^ε := by rw [← Real.rpow_add hN0] congr 1 dsimp [δ] ring calc _ = (Real.exp Real.pi*16*(1+C)*D)*(N^(3*δ)*N^δ)*recurrenceEnvelope M N α*∑ b ∈ S,‖u b‖^2 := by ring _ = _ := by rw [hp] lemma recurrenceEnvelope_mono {M α : ℝ} (hM : 0≤M) (hα : 1≤α) : MonotoneOn (fun N => recurrenceEnvelope M N α) (Set.Ici 1) := by intro X hX Y hY hXY change 1≤X at hX change 1≤Y at hY dsimp only [recurrenceEnvelope] gcongr linarith lemma recurrenceEnvelope_scale {M N α q : ℝ} (hM : 0≤M) (hN : 0≤N) (hα : 1≤α) (hq : 1≤q) : recurrenceEnvelope M (q*N) α ≤ q^(2*α)*recurrenceEnvelope M N α := by have hq0 : 0 C*X^(ε/2)*recurrenceEnvelope M X α have hK (X : ℝ) (hX : 1≤X) : 0≤K X := by have := recurrenceEnvelope_nonneg hM0 (show 0≤X by linarith) (α := α) dsimp [K] positivity have hmono : MonotoneOn K (Set.Ici 1) := by intro X hX Y hY hXY have hXE : 0≤recurrenceEnvelope M X α := recurrenceEnvelope_nonneg hM0 (by change 1≤X at hX; linarith) have he := recurrenceEnvelope_mono hM0 hα hX hY hXY change 1≤X at hX change 1≤Y at hY dsimp [K] gcongr have hb := hbins N S (squarefreePrimaryBall M) u K hN hS hK hmono (by intro X T hX hT hn exact hthin M X T u hM hX hT hn) change (∑ m ∈ squarefreePrimaryBall M,cubicRowEnergy S u m) ≤ _ at hb apply hb.trans apply mul_le_mul_of_nonneg_right _ (Finset.sum_nonneg fun b _ => sq_nonneg _) dsimp only [K] rw [Real.mul_rpow (by linarith : 0≤q) hN0.le] calc _ = D*C*q^(ε/2)*(N^(ε/2)*N^(ε/2))*recurrenceEnvelope M (q*N) α := by ring _ ≤ D*C*q^(ε/2)*(N^(ε/2)*N^(ε/2))*(q^(2*α)*recurrenceEnvelope M N α) := by apply mul_le_mul_of_nonneg_left (recurrenceEnvelope_scale hM0 hN0.le hα hq) positivity _ = _ := by rw [← Real.rpow_add hN0,show ε/2+ε/2=ε by ring] ring def sieveStep (α : ℝ) : ℝ := (6*α-4)/(3*α-1) def sieveThreshold (α : ℝ) : ℝ := (6*α-5)/(3*α-1) lemma sieveStep_algebra {α : ℝ} (hα : (4/3:ℝ)≤α) : 1≤ sieveThreshold α ∧ sieveThreshold α≤ sieveStep α ∧ (sieveThreshold α+1)*(2/3:ℝ)=sieveStep α ∧ sieveThreshold α*(α-(1/3:ℝ))=2*α-(5/3:ℝ) ∧ (4/3:ℝ)≤ sieveStep α ∧ sieveStep α-(4/3:ℝ)≤(2/3:ℝ)*(α-(4/3:ℝ)) := by have hd : 0<3*α-1 := by linarith unfold sieveThreshold sieveStep refine ⟨(le_div_iff₀ hd).mpr (by linarith),?_,?_,?_,?_,?_⟩ · exact div_le_div_of_nonneg_right (by linarith) hd.le · field_simp [ne_of_gt hd, show α*3-1 ≠ 0 by linarith] ring · field_simp [ne_of_gt hd, show α*3-1 ≠ 0 by linarith] ring · apply (le_div_iff₀ hd).mpr linarith · apply (sub_le_iff_le_add).mpr apply (div_le_iff₀ hd).mpr nlinarith [sq_nonneg (α-(4/3:ℝ))] lemma sieve_recurrence_cross {M N α : ℝ} (hM : 1≤ M) (hN : 1≤ N) (hα : (4/3:ℝ)≤α) (hMN : N^(sieveThreshold α)≤ M) : M^(1-α)*N^(2*α-1) ≤ (M*N)^(2/3:ℝ) := by have hM0 : 0 congr 1 <;> ring rw [←he] exact mul_le_of_le_one_right (by positivity) hpow lemma sieve_recurrence_last {M N : ℝ} (hM : 1≤ M) (hN : 1≤ N) (hNM : N≤ M) : M^(1/3:ℝ)*N ≤ (M*N)^(2/3:ℝ) := by have hM0 : 0