import PrimeRaceZeroBudget import Mathlib.Analysis.Complex.LocallyUniformLimit import Mathlib.Analysis.NormedSpace.MultipliableUniformlyOn import Mathlib.NumberTheory.Harmonic.GammaDeriv import Mathlib.Analysis.Calculus.LogDeriv /-! The logarithmic derivative of the completed cubic Euler product at two. -/ noncomputable section open Filter Topology Complex namespace CubicPrimeRace /-- The shift of a reciprocal local Euler polynomial from its constant term. -/ private def delta (r : ℕ) (t : ℂ) : ℂ := if r = 1 then -t^2 else if r = 0 then t+t^2 else -2*t+t^2 private def parameter (n : ℕ) (s : ℂ) : ℂ := Complex.exp (-(Real.log n : ℂ)*s) /-- The difference between the reciprocal Euler polynomial at p⁻ˢ and one. -/ def correction (n : ℕ) (s : ℂ) : ℂ := if 3 < n ∧ n.Prime then delta (rootCount n) (parameter n s) else 0 private def logLocal (n : ℕ) (s : ℂ) : ℂ := -Complex.log (1+correction n s) /-- This definition represents the cubic Euler product on the right half-plane. Values of this total Lean function outside convergence are never used. -/ def cubicEuler (s : ℂ) : ℂ := Complex.exp (∑' n, logLocal n s) def cubicConductorScale : ℝ := Real.sqrt 108 / (2 * Real.pi) def completedEuler (s : ℂ) : ℂ := Complex.exp ((Real.log cubicConductorScale : ℂ)*s) * Complex.Gamma s * cubicEuler s private def region : Set ℂ := {s | 3/2 < s.re} private theorem open_region : IsOpen region := isOpen_lt continuous_const Complex.continuous_re private theorem two_mem : (2 : ℂ) ∈ region := by norm_num [region] private theorem delta_norm (r : ℕ) (t : ℂ) (ht : ‖t‖ ≤ 1) : ‖delta r t‖ ≤ 3*‖t‖ := by have h : ‖t^2‖ ≤ ‖t‖ := by rw [norm_pow]; nlinarith [mul_nonneg (norm_nonneg t) (sub_nonneg.mpr ht)] unfold delta split_ifs · rw [norm_neg]; linarith [norm_nonneg t] · exact (norm_add_le _ _).trans (by linarith [norm_nonneg t]) · apply (norm_add_le _ _).trans rw [norm_mul, norm_neg, Complex.norm_ofNat] linarith private theorem correction_bounds (n : ℕ) {s : ℂ} (hs : s ∈ region) : ‖correction n s‖ ≤ 3*(n:ℝ)^(-(3/2):ℝ) ∧ ‖correction n s‖ ≤ 1/2 := by by_cases h : 3 < n ∧ n.Prime · have hn : (4:ℝ) ≤ n := by exact_mod_cast h.1 have hn0 : 0 < (n:ℝ) := by linarith have hu : ‖parameter n s‖ = (n:ℝ)^(-s.re) := by rw [parameter, Complex.norm_exp, Real.rpow_def_of_pos hn0] congr 1 simp only [Complex.mul_re, Complex.neg_re, Complex.neg_im, Complex.ofReal_re, Complex.ofReal_im]; ring have he : ‖parameter n s‖ ≤ (n:ℝ)^(-(3/2):ℝ) := by rw [hu] exact Real.rpow_le_rpow_of_exponent_le (by linarith) (neg_le_neg (le_of_lt hs)) have hb : (n:ℝ)^(-(3/2):ℝ) ≤ 1/8 := by calc _ ≤ (4:ℝ)^(-(3/2):ℝ) := Real.rpow_le_rpow_of_nonpos (by norm_num) hn (by norm_num) _ = _ := by rw [show (4:ℝ) = 2^(2:ℕ) by norm_num, ← Real.rpow_natCast_mul (by norm_num)] norm_num rw [correction, if_pos h] have hd := delta_norm (rootCount n) (parameter n s) (by linarith) constructor <;> linarith · simp only [correction, if_neg h, norm_zero] exact ⟨by positivity, by norm_num⟩ private theorem correction_diff (n : ℕ) : Differentiable ℂ (correction n) := by intro s unfold correction split_ifs · unfold delta parameter; split_ifs <;> fun_prop · fun_prop private theorem local_slit (n : ℕ) {s : ℂ} (hs : s ∈ region) : 1+correction n s ∈ Complex.slitPlane := by apply Or.inl have hk := (correction_bounds n hs).2 have h := Complex.abs_re_le_norm (correction n s) simp only [Complex.add_re, Complex.one_re] linarith [(abs_le.mp h).1] private theorem logLocal_diff (n : ℕ) : DifferentiableOn ℂ (logLocal n) region := by intro s hs have hg : DifferentiableAt ℂ (fun z => 1+correction n z) s := (correction_diff n s).const_add _ exact (hg.clog (local_slit n hs)).neg.differentiableWithinAt private theorem local_majorant (n : ℕ) {s : ℂ} (hs : s ∈ region) : ‖logLocal n s‖ ≤ 5*(n:ℝ)^(-(3/2):ℝ) := by rw [logLocal, norm_neg] have h := correction_bounds n hs have hlog := Complex.norm_log_one_add_half_le_self h.2 linarith [Real.rpow_nonneg (Nat.cast_nonneg n) (-(3/2):ℝ)] private theorem majorant_summable : Summable (fun n : ℕ => 5*(n:ℝ)^(-(3/2):ℝ)) := (Real.summable_nat_rpow.mpr (by norm_num)).mul_left _ private theorem sumLog_diff : DifferentiableOn ℂ (fun s => ∑' n, logLocal n s) region := Complex.differentiableOn_tsum_of_summable_norm majorant_summable logLocal_diff open_region (fun n _ hs => local_majorant n hs) /-- The prime-side function is genuinely the product of the reciprocal local factors. -/ theorem cubicEuler_eq_tprod {s : ℂ} (hs : 3/2 < s.re) : cubicEuler s = ∏' n, (1+correction n s)⁻¹ := by have hg : Summable (fun n => logLocal n s) := Summable.of_norm_bounded majorant_summable (fun n => local_majorant n hs) have h := hg.hasSum.cexp have he (n : ℕ) : Complex.exp (logLocal n s) = (1+correction n s)⁻¹ := by rw [logLocal, Complex.exp_neg, Complex.exp_log (Complex.slitPlane_ne_zero (local_slit n hs))] simpa only [Function.comp_apply, he, cubicEuler] using h.tprod_eq.symm private theorem parameter_two {n : ℕ} (hn : 0 < n) : parameter n 2 = ((1/(n:ℝ)^2 : ℝ) : ℂ) := by have h : 0 < (n:ℝ) := by exact_mod_cast hn rw [parameter, show -(Real.log n : ℂ)*2 = -((Real.log n : ℂ)+(Real.log n : ℂ)) by ring, Complex.exp_neg, Complex.exp_add, ← Complex.ofReal_exp, Real.exp_log h] push_cast ring private theorem delta_ofReal (r : ℕ) (t : ℝ) : 1+delta r t = (eulerDenominator r t : ℂ) := by unfold delta eulerDenominator split_ifs <;> push_cast <;> ring private theorem complexPoly_diff (r : ℕ) (t : ℂ) : DifferentiableAt ℂ (fun z => 1+delta r z) t := by unfold delta split_ifs <;> fun_prop private theorem local_derivative_two (n : ℕ) : deriv (logLocal n) 2 = (eulerTermAtTwo n : ℂ) := by by_cases h : 3 < n ∧ n.Prime · let t : ℝ := 1/(n:ℝ)^2 let P : ℂ → ℂ := fun z => 1+delta (rootCount n) z have hp : HasDerivAt P ((deriv (eulerDenominator (rootCount n)) t : ℝ) : ℂ) (t:ℂ) := by have hP := (complexPoly_diff (rootCount n) (t:ℂ)).hasDerivAt have hr := (complexPoly_diff (rootCount n) t).hasDerivAt.real_of_complex have heq : (fun u : ℝ => (P u).re) = eulerDenominator (rootCount n) := by ext u; simp only [P, delta_ofReal, Complex.ofReal_re] change HasDerivAt (fun u : ℝ => (P u).re) _ t at hr rw [heq] at hr have hf : (fun u : ℝ => P (u:ℂ)) = fun u : ℝ => ((eulerDenominator (rootCount n) u : ℝ):ℂ) := funext (delta_ofReal _) have hh := hP.comp_ofReal change HasDerivAt (fun u : ℝ => P (u:ℂ)) _ t at hh rw [hf] at hh exact hP.congr_deriv (hh.unique (hr.differentiableAt.hasDerivAt.ofReal_comp)) have ht : HasDerivAt (parameter n) ((t:ℂ) * (-(Real.log n : ℂ))) 2 := by have ht' := ((hasDerivAt_id (2:ℂ)).const_mul (-(Real.log n : ℂ))).cexp change HasDerivAt (parameter n) (parameter n 2 * (-(Real.log n : ℂ)*1)) 2 at ht' rw [parameter_two (show 0 < n by omega), mul_one] at ht' exact ht' have htval := parameter_two (show 0 < n by omega : 0 < n) change parameter n 2 = (t:ℂ) at htval have hp' := (htval.symm ▸ hp).comp 2 ht have hcut : P (parameter n 2) ∈ Complex.slitPlane := by simpa [P, correction, h] using local_slit n two_mem have hd := (hp'.clog hcut).neg have he := eulerTerm_eq_local_log_derivative h rw [he] simp only [Complex.ofReal_div, Complex.ofReal_mul] have hg : logLocal n = fun s => -Complex.log (P (parameter n s)) := by funext s; simp [logLocal, correction, h, P] rw [hg] rw [show deriv (fun s => -Complex.log (P (parameter n s))) 2 = _ from hd.deriv, Function.comp_apply, htval] change -( _ / (1+delta (rootCount n) (t:ℂ))) = _ rw [delta_ofReal] dsimp [t] push_cast ring · have he : logLocal n = fun _ => 0 := by ext; simp [logLocal, correction, h] rw [he]; simp [eulerTermAtTwo, h] private theorem euler_diff : DifferentiableAt ℂ cubicEuler 2 := ((sumLog_diff.differentiableAt (open_region.mem_nhds two_mem)).cexp) /-- No hypothesis on the zeros, continuation, or Euler product. -/ theorem logDeriv_cubicEuler_two : logDeriv cubicEuler 2 = ((∑' n, eulerTermAtTwo n : ℝ) : ℂ) := by have hd := Complex.hasSum_deriv_of_summable_norm majorant_summable logLocal_diff open_region (fun n _ hs => local_majorant n hs) two_mem simp_rw [local_derivative_two] at hd have he := (sumLog_diff.differentiableAt (open_region.mem_nhds two_mem)).hasDerivAt.cexp change deriv _ 2 / Complex.exp _ = _ rw [show deriv cubicEuler 2 = _ from he.deriv, mul_div_cancel_left₀ _ (Complex.exp_ne_zero _)] rw [← hd.tsum_eq, Complex.ofReal_tsum] private theorem gamma_two_value : Complex.Gamma 2 = 1 := by simp private theorem gamma_two_deriv : HasDerivAt Complex.Gamma ((1-Real.eulerMascheroniConstant : ℝ):ℂ) 2 := by convert Complex.hasDerivAt_Gamma_nat 1 using 1 <;> norm_num [harmonic_succ]; ring private theorem conductor_diff (s : ℂ) : HasDerivAt (fun z : ℂ => Complex.exp ((Real.log cubicConductorScale : ℂ)*z)) (Complex.exp ((Real.log cubicConductorScale : ℂ)*s) * (Real.log cubicConductorScale : ℂ)) s := by simpa only [mul_one] using ((hasDerivAt_id s).const_mul (Real.log cubicConductorScale : ℂ)).cexp theorem completed_two_ne : completedEuler 2 ≠ 0 := by unfold completedEuler cubicEuler rw [gamma_two_value]; exact mul_ne_zero (mul_ne_zero (Complex.exp_ne_zero _) one_ne_zero) (Complex.exp_ne_zero _) /-- This is the arithmetic side of the paper's identity as the logarithmic derivative of an actual holomorphic germ. -/ theorem logDeriv_completedEuler_two : logDeriv completedEuler 2 = ((Real.log cubicConductorScale + 1 - Real.eulerMascheroniConstant + ∑' n, eulerTermAtTwo n : ℝ):ℂ) := by let C := fun s : ℂ => Complex.exp ((Real.log cubicConductorScale : ℂ)*s) have hc : C 2 ≠ 0 := Complex.exp_ne_zero _ have hg : Complex.Gamma 2 ≠ 0 := gamma_two_value.trans_ne one_ne_zero have hf : cubicEuler 2 ≠ 0 := Complex.exp_ne_zero _ have hd := (conductor_diff 2).differentiableAt change logDeriv (fun s => (C s * Complex.Gamma s) * cubicEuler s) 2 = _ rw [logDeriv_mul (f := fun s => C s * Complex.Gamma s) (g := cubicEuler) 2 (mul_ne_zero hc hg) hf (hd.mul gamma_two_deriv.differentiableAt) euler_diff, logDeriv_mul (f := C) (g := Complex.Gamma) 2 hc hg hd gamma_two_deriv.differentiableAt, logDeriv_cubicEuler_two, logDeriv_apply, logDeriv_apply, (conductor_diff 2).deriv, gamma_two_deriv.deriv, gamma_two_value] change C 2 * _ / C 2 + _ / 1 + _ = _ rw [mul_div_cancel_left₀ _ hc] push_cast ring end CubicPrimeRace #print axioms CubicPrimeRace.cubicEuler_eq_tprod #print axioms CubicPrimeRace.logDeriv_cubicEuler_two #print axioms CubicPrimeRace.logDeriv_completedEuler_two