Lean / Reader
Lean reader

PrimeRaceZeroBudget.lean

320 lines18 declarationsno sorryimports PrimeRace Mathlib.Analysis.PSeries Mathlib.Analysis.Real.Pi.Bounds Mathlib.NumberTheory.Harmonic.EulerMascheroni

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports PrimeRace, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import PrimeRace
  2. import Mathlib.Analysis.PSeries
  3. import Mathlib.Analysis.Real.Pi.Bounds
  4. import Mathlib.NumberTheory.Harmonic.EulerMascheroni
  5. /-! Zero budget for the cube-root-of-two race, using the sign of each Euler factor.
  6. At s = 2 only a prime with no cube root of two can contribute positively to
  7. F'/F. Such a prime is 1 modulo 6. The final theorem displays the analytic
  8. identification of the weighted zero sum as a hypothesis. -/
  9. noncomputable section
  10. open Filter Topology
  11. namespace CubicPrimeRace
  12. /-- Grouped prime-power contribution to the *positive* logarithmic derivative
  13. F'/F at 2. The three reciprocal Euler polynomials are 1+t+t², 1-t²,
  14. and (1-t)²; t = p⁻². The ramified primes have local factor one. -/
  15. def eulerTermAtTwo (n : ℕ) : ℝ :=
  16. if 3 < n ∧ n.Prime then
  17. let a := (n : ℝ)^2
  18. let l := Real.log n
  19. if rootCount n = 1 then -2*l/(a^2-1)
  20. else if rootCount n = 0 then l*(a+2)/(a^2+a+1)
  21. else -2*l/(a-1)
  22. else 0
  23. /-- Reciprocal local Euler polynomials of the standard representation, written
  24. as functions of t = p⁻ˢ. The number of fixed roots specifies the cycle type. -/
  25. def eulerDenominator (r : ℕ) : ℝ → ℝ :=
  26. if r = 1 then fun t => 1-t^2
  27. else if r = 0 then fun t => 1+t+t^2
  28. else fun t => (1-t)^2
  29. /-- The signed term agrees with log(p) t P'(t)/P(t) for the indicated local
  30. Euler polynomial P, evaluated at t = p⁻². -/
  31. theorem eulerTerm_eq_local_log_derivative {p : ℕ} (hp : 3 < p ∧ p.Prime) :
  32. let t : ℝ := 1/(p:ℝ)^2
  33. let P := eulerDenominator (rootCount p)
  34. eulerTermAtTwo p = Real.log p * t * deriv P t / P t := by
  35. let a := (p:ℝ)^2
  36. let t : ℝ := 1/a
  37. have hp' : (3:ℝ) < p := by exact_mod_cast hp.1
  38. have ha : 1 < a := by dsimp [a]; nlinarith
  39. have ha0 : a ≠ 0 := by linarith
  40. have ht : t < 1 := (div_lt_one (by linarith : 0 < a)).2 ha
  41. have ht0 : 0 < t := one_div_pos.mpr (by linarith)
  42. have ht2 : 1-t^2 ≠ 0 := by nlinarith [mul_pos ht0 (sub_pos.mpr ht)]
  43. have hplus : 1+t+t^2 ≠ 0 := by positivity
  44. have hsub : 1-t ≠ 0 := by linarith
  45. have hden₁ : a^2-1 ≠ 0 := by nlinarith
  46. have hden₂ : a^2+a+1 ≠ 0 := by positivity
  47. have hden₃ : a-1 ≠ 0 := by linarith
  48. change eulerTermAtTwo p = Real.log p * t * deriv _ t / _
  49. rw [eulerTermAtTwo, if_pos hp]
  50. by_cases h : rootCount p = 1
  51. · have hd := ((hasDerivAt_const t (1:ℝ)).sub ((hasDerivAt_id t).pow 2)).deriv
  52. simp only [eulerDenominator, h, if_true]
  53. rw [show deriv (fun u : ℝ => 1-u^2) t = _ from hd]
  54. change -2*Real.log p/(a^2-1) = Real.log p*t*(0-2*t^(2-1)*1)/(1-t^2)
  55. field_simp
  56. all_goals dsimp [t]; field_simp; ring
  57. · by_cases h' : rootCount p = 0
  58. · have hd := (((hasDerivAt_const t (1:ℝ)).add (hasDerivAt_id t)).add
  59. ((hasDerivAt_id t).pow 2)).deriv
  60. simp only [eulerDenominator, h', Nat.zero_ne_one, if_false, if_true]
  61. rw [show deriv (fun u : ℝ => 1+u+u^2) t = _ from hd]
  62. change Real.log p*(a+2)/(a^2+a+1) = Real.log p*t*(0+1+2*t^(2-1)*1)/(1+t+t^2)
  63. field_simp
  64. all_goals dsimp [t]; field_simp; ring
  65. · have hd := (((hasDerivAt_const t (1:ℝ)).sub (hasDerivAt_id t)).pow 2).deriv
  66. simp only [eulerDenominator, h, h', if_false]
  67. rw [show deriv (fun u : ℝ => (1-u)^2) t = _ from hd]
  68. change -2*Real.log p/(a-1) = Real.log p*t*(2*(1-t)^(2-1)*(0-1))/(1-t)^2
  69. field_simp
  70. all_goals dsimp [t]; field_simp; ring
  71. private theorem local_bounds {n : ℕ} (hn : 3 < n) :
  72. |eulerTermAtTwo n| ≤ 2 * Real.log n / ((n : ℝ)^2 - 1) ∧
  73. eulerTermAtTwo n ≤ Real.log n / ((n : ℝ)^2 - 1) := by
  74. have hn' : (3 : ℝ) < n := by exact_mod_cast hn
  75. let a := (n : ℝ)^2
  76. have ha : 1 < a := by dsimp [a]; nlinarith
  77. have hden : 0 < a - 1 := by linarith
  78. have hsq : 0 < a^2 - 1 := by nlinarith
  79. have hplus : 0 < a^2 + a + 1 := by positivity
  80. have hl : 0 ≤ Real.log n := Real.log_nonneg (by linarith)
  81. have h0 : 0 ≤ Real.log n / (a-1) := by positivity
  82. have h1 : 2 * Real.log n / (a^2-1) ≤ 2 * Real.log n / (a-1) :=
  83. div_le_div_of_nonneg_left (by positivity) hden (by nlinarith)
  84. have h2 : Real.log n * (a+2) / (a^2+a+1) ≤ Real.log n / (a-1) := by
  85. rw [div_le_div_iff₀ hplus hden]
  86. nlinarith
  87. change |eulerTermAtTwo n| ≤ 2 * Real.log n / (a-1) ∧
  88. eulerTermAtTwo n ≤ Real.log n / (a-1)
  89. simp only [eulerTermAtTwo, ← (show a = (n : ℝ)^2 from rfl)]
  90. split_ifs
  91. · constructor
  92. · rwa [show -2 * Real.log n / (a^2-1) = -(2*Real.log n / (a^2-1)) by ring,
  93. abs_neg, abs_of_nonneg (by positivity)]
  94. · exact le_trans (div_nonpos_of_nonpos_of_nonneg (by nlinarith) hsq.le) h0
  95. · rw [abs_of_nonneg (by positivity : 0 ≤ Real.log n * (a+2) / (a^2+a+1))]
  96. exact ⟨h2.trans (by rw [mul_div_assoc]; linarith), h2⟩
  97. · rw [show -2 * Real.log n / (a-1) = -(2*Real.log n / (a-1)) by ring,
  98. abs_neg, abs_of_nonneg (by positivity)]
  99. exact ⟨le_rfl, (neg_nonpos.mpr (by positivity)).trans h0⟩
  100. · simp only [abs_zero]
  101. exact ⟨by positivity, h0⟩
  102. private theorem nonpos_off_one {n : ℕ} (hc : n % 6 ≠ 1) : eulerTermAtTwo n ≤ 0 := by
  103. by_cases h : 3 < n ∧ n.Prime
  104. · have hodd := h.2.eq_two_or_odd
  105. have hthree : ¬3 ∣ n := by
  106. intro hd
  107. rcases h.2.eq_one_or_self_of_dvd 3 hd with hh | hh <;> omega
  108. have hmod : n % 3 = 2 := by
  109. rw [Nat.dvd_iff_mod_eq_zero] at hthree
  110. omega
  111. rw [eulerTermAtTwo, if_pos h]
  112. simp only [rootCount_eq_one h.2 hmod, if_true]
  113. have hn : (3 : ℝ) < n := by exact_mod_cast h.1
  114. apply div_nonpos_of_nonpos_of_nonneg
  115. · exact mul_nonpos_of_nonpos_of_nonneg (by norm_num) (Real.log_nonneg (by linarith))
  116. · nlinarith [sq_nonneg (((n : ℝ)^2) - 1)]
  117. · simp [eulerTermAtTwo, h]
  118. private theorem log_le_sqrt {x : ℝ} (hx : 0 < x) : Real.log x ≤ Real.sqrt x := by
  119. have hs := Real.sqrt_pos.2 hx
  120. have h := Real.log_le_sub_one_of_pos (div_pos hs (Real.exp_pos 1))
  121. rw [Real.log_div hs.ne' (Real.exp_pos 1).ne', Real.log_exp, Real.log_sqrt hx.le] at h
  122. have he : (2:ℝ) < Real.exp 1 := by linarith [Real.exp_one_gt_d9]
  123. have hr : Real.sqrt x / Real.exp 1 ≤ Real.sqrt x / 2 :=
  124. div_le_div_of_nonneg_left hs.le (by norm_num) he.le
  125. linarith
  126. /-- For each block of six only its second entry can contribute positively. -/
  127. private theorem block_le {k : ℕ} (hk : 0 < k) :
  128. (∑ i ∈ Finset.range 6, eulerTermAtTwo (6*k+i)) ≤
  129. (1/12 : ℝ) / ((k : ℝ)*Real.sqrt k) := by
  130. have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk
  131. have h := (local_bounds (n := 6*k+1) (by omega)).2
  132. push_cast at h
  133. have hs : Real.sqrt (6*(k:ℝ)+1) ≤ 3 * Real.sqrt k := by
  134. apply (Real.sqrt_le_iff).2
  135. exact ⟨by positivity, by nlinarith [Real.sq_sqrt (by positivity : (0:ℝ) ≤ k)]⟩
  136. have hr : Real.log (6*(k:ℝ)+1) / ((6*(k:ℝ)+1)^2-1) ≤
  137. (1/12:ℝ) / ((k:ℝ) * Real.sqrt k) := by
  138. calc
  139. _ ≤ (3 * Real.sqrt k) / (36*(k:ℝ)^2) := by
  140. apply div_le_div₀ (by positivity) ((log_le_sqrt (by positivity)).trans hs)
  141. (by positivity) (by nlinarith)
  142. _ = _ := by
  143. have hs' := Real.sq_sqrt (by positivity : (0:ℝ) ≤ k)
  144. field_simp
  145. nlinarith
  146. have off (i : ℕ) (hi : i < 6) (hi' : i ≠ 1) : eulerTermAtTwo (6*k+i) ≤ 0 :=
  147. nonpos_off_one (by omega)
  148. simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, Nat.add_zero]
  149. have hzero : eulerTermAtTwo (6*k) ≤ 0 := by simpa using off 0 (by decide) (by decide)
  150. linarith [off 2 (by decide) (by decide),
  151. off 3 (by decide) (by decide), off 4 (by decide) (by decide), off 5 (by decide) (by decide)]
  152. private theorem recip_step {k : ℝ} (hk : 1 ≤ k) :
  153. 1 / ((k+1)*Real.sqrt (k+1)) ≤ 2/Real.sqrt k - 2/Real.sqrt (k+1) := by
  154. let a := Real.sqrt k
  155. let b := Real.sqrt (k+1)
  156. have ha : 0 < a := Real.sqrt_pos.2 (by linarith)
  157. have hb : 0 < b := Real.sqrt_pos.2 (by linarith)
  158. have ha2 : a^2 = k := Real.sq_sqrt (by linarith)
  159. have hb2 : b^2 = k+1 := Real.sq_sqrt (by linarith)
  160. have hab : a ≤ b := Real.sqrt_le_sqrt (by linarith)
  161. have hdiff : (b-a)*(b+a) = 1 := by nlinarith
  162. have haux : a * (b+a) ≤ 2*(k+1) := by nlinarith [mul_nonneg hb.le (sub_nonneg.mpr hab)]
  163. change 1 / ((k+1)*b) ≤ 2/a - 2/b
  164. have hsmall : a ≤ (2*(k+1))*(b-a) := by
  165. calc
  166. a = (a*(b+a))*(b-a) := by linear_combination -a*hdiff
  167. _ ≤ _ := mul_le_mul_of_nonneg_right haux (sub_nonneg.mpr hab)
  168. rw [show 2/a - 2/b = 2*(b-a)/(a*b) by field_simp]
  169. rw [div_le_div_iff₀ (by positivity) (by positivity)]
  170. nlinarith [mul_le_mul_of_nonneg_right hsmall hb.le]
  171. private def partialEuler (blocks : ℕ) : ℝ :=
  172. ∑ n ∈ Finset.range (6*blocks), eulerTermAtTwo n
  173. private theorem partial_succ (k : ℕ) : partialEuler (k+1) =
  174. partialEuler k + ∑ i ∈ Finset.range 6, eulerTermAtTwo (6*k+i) := by
  175. simp [partialEuler, Nat.mul_add, Finset.sum_range_add]
  176. private theorem partial_initial : partialEuler 1 ≤ 0 := by
  177. unfold partialEuler
  178. apply Finset.sum_nonpos
  179. intro i hi
  180. have hi' : i < 6 := by simpa using hi
  181. by_cases he : i = 1
  182. · simp [he, eulerTermAtTwo]
  183. · exact nonpos_off_one (by omega)
  184. private theorem partial_bound (j : ℕ) :
  185. partialEuler (j+2) ≤ (1/12 : ℝ)*(3 - 2/Real.sqrt (j+1 : ℕ)) := by
  186. induction j with
  187. | zero =>
  188. have h := block_le (k := 1) (by decide)
  189. rw [partial_succ 1]
  190. norm_num at h ⊢
  191. linarith [partial_initial]
  192. | succ j ih =>
  193. rw [show j.succ + 2 = (j+2)+1 by omega, partial_succ]
  194. have h := block_le (k := j+2) (by omega)
  195. have hj : (1:ℝ) ≤ (j:ℝ)+1 := by linarith [Nat.cast_nonneg (α := ℝ) j]
  196. have ht := recip_step hj
  197. push_cast at *
  198. have hs : (j:ℝ)+1+1 = j+2 := by ring
  199. rw [hs] at ht
  200. simp only [hs, div_eq_mul_inv] at *
  201. linarith
  202. /-- Absolute convergence of the explicit arithmetic Euler sum. -/
  203. theorem summable_eulerTermAtTwo : Summable eulerTermAtTwo := by
  204. apply Summable.of_norm_bounded (g := fun n : ℕ => 4*(n:ℝ)^(-(3/2):ℝ))
  205. ((Real.summable_nat_rpow.mpr (by norm_num : -(3/2:ℝ) < -1)).mul_left 4)
  206. intro n
  207. rw [Real.norm_eq_abs]
  208. by_cases h : 3 < n
  209. · have hn : (3:ℝ) < n := by exact_mod_cast h
  210. have hn' : 0 < (n:ℝ) := by linarith
  211. have hab := (local_bounds h).1
  212. have hr : (n:ℝ)^(-(3/2):ℝ) = Real.sqrt n / (n:ℝ)^2 := by
  213. rw [show -(3/2:ℝ) = 1/2 - (2:ℕ) by norm_num, Real.rpow_sub hn',
  214. ← Real.sqrt_eq_rpow, Real.rpow_natCast]
  215. rw [hr]
  216. apply hab.trans
  217. have hd : 0 < (n:ℝ)^2-1 := by nlinarith
  218. rw [show (4:ℝ)*(Real.sqrt n / (n:ℝ)^2) = 4*Real.sqrt n/(n:ℝ)^2 by ring,
  219. div_le_div_iff₀ hd (by positivity)]
  220. nlinarith [mul_le_mul_of_nonneg_right (log_le_sqrt hn') (sq_nonneg (n:ℝ)),
  221. mul_nonneg (Real.sqrt_nonneg (n:ℝ)) (show 0 ≤ (n:ℝ)^2-2 by nlinarith)]
  222. · simp only [eulerTermAtTwo, h, false_and, if_false, abs_zero]
  223. positivity
  224. /-- The arithmetic sum is at most one quarter, with all primes and all powers included. -/
  225. theorem eulerTermAtTwo_sum_le : ∑' n, eulerTermAtTwo n ≤ (1/4 : ℝ) := by
  226. have h := summable_eulerTermAtTwo.hasSum.tendsto_sum_nat
  227. have ht : Tendsto (fun j : ℕ => 6*(j+2)) atTop atTop :=
  228. tendsto_atTop_mono (fun j => show j ≤ 6*(j+2) by omega) tendsto_id
  229. apply le_of_tendsto (h.comp ht)
  230. filter_upwards with j
  231. change partialEuler (j+2) ≤ _
  232. have hj := partial_bound j
  233. have hs : 0 ≤ 2 / Real.sqrt ((j+1:ℕ):ℝ) := by positivity
  234. linarith
  235. /-- The signed arithmetic upper bound for the Hadamard zero budget.
  236. The identification of this expression with a zero sum is a separate theorem. -/
  237. theorem arithmetic_budget_lt :
  238. Real.log (Real.sqrt 108 / (2 * Real.pi)) + 1 - Real.eulerMascheroniConstant +
  239. (∑' n, eulerTermAtTwo n) < 1.32 := by
  240. have hp := Real.pi_gt_three
  241. have hq : Real.sqrt 108 / (2 * Real.pi) ≤ 7/4 := by
  242. rw [div_le_iff₀ (by positivity)]
  243. have hs : Real.sqrt 108 ≤ 10.5 := (Real.sqrt_le_iff).2 ⟨by norm_num, by norm_num⟩
  244. linarith
  245. have hl := Real.log_le_log (by positivity) hq
  246. have hu := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ) < 7/8)
  247. have hlog : Real.log (7/4) = Real.log (7/8) + Real.log 2 := by
  248. rw [← Real.log_mul (by norm_num) (by norm_num)]
  249. norm_num
  250. rw [hlog] at hl
  251. linarith [Real.log_two_lt_d9, Real.one_half_lt_eulerMascheroniConstant, eulerTermAtTwo_sum_le]
  252. /-- The summand in the audit, with real and imaginary parts written out. -/
  253. theorem zero_weight_eq (z : ℂ) :
  254. ((2-z)⁻¹).re = (2-z.re)/((2-z.re)^2+z.im^2) := by
  255. rw [Complex.inv_re, Complex.normSq_apply]
  256. simp
  257. ring
  258. /-- Transfer to a family of complex zeros, counted with multiplicity. The
  259. displayed Hadamard/Euler identity for the actual cubic L-function is external. -/
  260. theorem zero_budget_of_identity {ι : Type*} (ρ : ι → ℂ)
  261. (hadamardEuler : (∑' i, ((2-ρ i)⁻¹).re) =
  262. Real.log (Real.sqrt 108 / (2*Real.pi)) + 1 - Real.eulerMascheroniConstant +
  263. (∑' n, eulerTermAtTwo n)) :
  264. (∑' i, ((2-ρ i)⁻¹).re) < 1.32 := hadamardEuler.trans_lt arithmetic_budget_lt
  265. /-- Each entry of a pair of real reflected zeros is counted with its own index;
  266. this also covers a double central zero. -/
  267. theorem no_reflected_real_entries {ι : Type*} (β γ : ι → ℝ)
  268. (strip : ∀ i, 0 ≤ β i ∧ β i ≤ 1)
  269. (hw : Summable (fun i => (2-β i)/((2-β i)^2+(γ i)^2)))
  270. (hadamardEuler : (∑' i, (2-β i)/((2-β i)^2+(γ i)^2)) =
  271. Real.log (Real.sqrt 108 / (2*Real.pi)) + 1 - Real.eulerMascheroniConstant +
  272. (∑' n, eulerTermAtTwo n))
  273. {i j : ι} (hij : i ≠ j) (hi : γ i = 0) (hj : γ j = 0) (href : β j = 1-β i) : False := by
  274. classical
  275. have hn (k : ι) : 0 ≤ (2-β k)/((2-β k)^2+(γ k)^2) := by
  276. have hk := (strip k).2
  277. apply div_nonneg (by linarith) (by positivity)
  278. have hl := hw.sum_le_tsum ({i,j} : Finset ι) (fun k _ => hn k)
  279. rw [Finset.sum_pair hij, hi, hj, href, hadamardEuler] at hl
  280. have hs := strip i
  281. have h1 : 0 < 2-β i := by linarith
  282. have h2 : 0 < 1+β i := by linarith
  283. simp only [ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, add_zero] at hl
  284. rw [show (2:ℝ)-(1-β i) = 1+β i by ring] at hl
  285. have hr : (4/3:ℝ) ≤ (2-β i)/(2-β i)^2 + (1+β i)/(1+β i)^2 := by
  286. field_simp
  287. nlinarith [sq_nonneg (2*β i-1), mul_nonneg (sq_nonneg (2*β i-1)) (mul_nonneg h1.le h2.le)]
  288. linarith [arithmetic_budget_lt]
  289. end CubicPrimeRace
  290. #print axioms CubicPrimeRace.eulerTerm_eq_local_log_derivative
  291. #print axioms CubicPrimeRace.summable_eulerTermAtTwo
  292. #print axioms CubicPrimeRace.eulerTermAtTwo_sum_le
  293. #print axioms CubicPrimeRace.arithmetic_budget_lt
  294. #print axioms CubicPrimeRace.zero_weight_eq
  295. #print axioms CubicPrimeRace.zero_budget_of_identity
  296. #print axioms CubicPrimeRace.no_reflected_real_entries