@@ -5,10 +5,15 @@ Authors: Alastair Irving, Terry Tao, Ruben Van de Velde
55-/
66module
77
8+ public import Mathlib.Algebra.Order.Floor.Semifield
89public import Mathlib.Analysis.SpecialFunctions.Pow.Real
10+ public import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
11+ public import Mathlib.NumberTheory.AbelSummation
12+ public import Mathlib.NumberTheory.PrimeCounting
913public import Mathlib.NumberTheory.Primorial
1014public import Mathlib.NumberTheory.ArithmeticFunction.VonMangoldt
1115
16+ import Mathlib.Analysis.SpecialFunctions.Log.InvLog
1217import Mathlib.Data.Nat.Prime.Int
1318
1419/-!
@@ -28,6 +33,8 @@ These give logarithmically weighted sums of primes and prime powers.
2833- `Chebyshev.theta_le_log4_mul_x` gives Chebyshev's upper bound on `θ`
2934- `Chebyshev.psi_eq_sum_theta` and `Chebyshev.psi_eq_theta_add_sum_theta` relate `psi` to `theta`.
3035- `Chebyshev.psi_le_const_mul_self` gives Chebyshev's upper bound on `ψ`.
36+ - `Chebyshev.primeCounting_eq_theta_div_log_add_integral` relates the prime counting function to `θ`
37+ - `Chebyshev.eventually_primeCounting_le` gives an upper bound on the prime counting function.
3138
3239 ## Notation
3340
@@ -40,14 +47,14 @@ Parts of this file were upstreamed from the PrimeNumberTheoremAnd project by Kon
4047
4148## TODOS
4249
43- - Upstream the results relating `theta` and `psi` to the prime counting function.
4450- Prove Chebyshev's lower bound.
4551 -/
4652@[expose] public section
4753
4854open Nat hiding log
4955open Finset Real
5056open ArithmeticFunction hiding log
57+ open scoped Nat.Prime
5158
5259namespace Chebyshev
5360
@@ -269,4 +276,172 @@ theorem psi_sub_theta_eq_sum_not_prime (x : ℝ) :
269276 · simp [h, vonMangoldt_apply_prime]
270277 · simp
271278
279+ section PrimeCounting
280+
281+ /-! ## Relation to prime counting
282+
283+ We relate `θ` to the prime counting function `π`.-/
284+
285+ open Asymptotics Filter MeasureTheory
286+
287+ /-- Integrability for the integral in `Chebyshev.primeCounting_eq_theta_div_log_add_integral`. -/
288+ theorem integrableOn_theta_div_id_mul_log_sq (x : ℝ) :
289+ IntegrableOn (fun t ↦ θ t / (t * log t ^ 2 )) (Set.Icc 2 x) volume := by
290+ conv => arg 1 ; ext; rw [theta, div_eq_mul_one_div, mul_comm, sum_filter]
291+ refine integrableOn_mul_sum_Icc _ (by norm_num) <| ContinuousOn.integrableOn_Icc fun x hx ↦
292+ ContinuousAt.continuousWithinAt ?_
293+ have : x ≠ 0 := by linarith [hx.1 ]
294+ have : x * log x ^ 2 ≠ 0 := mul_ne_zero this <| by simp; grind
295+ fun_prop (disch := assumption)
296+
297+ /-- Expresses the prime counting function `π` in terms of `θ` by using Abel summation. -/
298+ theorem primeCounting_eq_theta_div_log_add_integral {x : ℝ} (hx : 2 ≤ x) :
299+ π ⌊x⌋₊ = θ x / log x + ∫ t in 2 ..x, θ t / (t * log t ^ 2 ) := by
300+ -- Rewrite in a form to which Abel summation can be applied
301+ simp only [primeCounting, primeCounting', count_eq_card_filter_range]
302+ rw [card_eq_sum_ones, range_succ_eq_Icc_zero, sum_filter]
303+ push_cast
304+ let a : ℕ → ℝ := Set.indicator (setOf Nat.Prime) (fun n ↦ log n)
305+ trans ∑ n ∈ Icc 0 ⌊x⌋₊, (log n)⁻¹ * a n
306+ · refine sum_congr rfl fun n hn ↦ ?_
307+ split_ifs with h
308+ · have : log n ≠ 0 := log_ne_zero_of_pos_of_ne_one (mod_cast h.pos) (mod_cast h.ne_one)
309+ simp [a, h, field]
310+ · simp [a, h]
311+ rw [sum_mul_eq_sub_integral_mul₁ a (f := fun n ↦ (log n)⁻¹) (by simp [a]) (by simp [a]),
312+ ← intervalIntegral.integral_of_le hx]
313+ · -- Rewrite the derivative inside the intigral
314+ have int_deriv (f : ℝ → ℝ) :
315+ ∫ u in 2 ..x, deriv (fun x ↦ (log x)⁻¹) u * f u =
316+ ∫ u in 2 ..x, f u * -(u * log u ^ 2 )⁻¹ :=
317+ intervalIntegral.integral_congr fun u _ ↦ by simp [deriv_inv_log, field]
318+ simp [int_deriv, a, Set.indicator_apply, sum_filter, theta_eq_sum_Icc]
319+ grind
320+ · -- Differentiability
321+ intro z ⟨hz, _⟩
322+ have : z ≠ 0 := by linarith
323+ have : log z ≠ 0 := by apply log_ne_zero_of_pos_of_ne_one <;> linarith
324+ fun_prop (disch := assumption)
325+ · -- Integrability of the derivative
326+ refine ContinuousOn.integrableOn_Icc fun z ⟨hz, _⟩ ↦ ContinuousWithinAt.congr ?_
327+ (fun _ _ ↦ deriv_inv_log) deriv_inv_log
328+ have hz₀ : z ≠ 0 := by linarith
329+ have : log z ^ 2 ≠ 0 := by
330+ refine pow_ne_zero 2 <| log_ne_zero_of_pos_of_ne_one ?_ ?_ <;> linarith
331+ exact ContinuousAt.continuousWithinAt <| by fun_prop (disch := assumption)
332+
333+ theorem intervalIntegrable_one_div_log_sq {a b : ℝ} (one_lt_a : 1 < a) (one_lt_b : 1 < b) :
334+ IntervalIntegrable (fun x ↦ 1 / log x ^ 2 ) MeasureTheory.volume a b := by
335+ refine ContinuousOn.intervalIntegrable fun x hx ↦ ContinuousAt.continuousWithinAt ?_
336+ rw [Set.mem_uIcc] at hx
337+ have : x ≠ 0 := by grind
338+ have : log x ^ 2 ≠ 0 := pow_ne_zero _ (log_ne_zero.mpr (by grind))
339+ fun_prop (disch := assumption)
340+
341+ /- Simple bound on the integral from monotonicity.
342+ We will bound the integral on 2..x by splitting into two intervals and using this result on both. -/
343+ private theorem integral_1_div_log_sq_le {a b : ℝ} (hab : a ≤ b) (one_lt : 1 < a) :
344+ ∫ x in a..b, 1 / log x ^ 2 ≤ (b - a) / log a ^ 2 := by
345+ calc
346+ _ ≤ ∫ x in a..b, 1 / log a ^ 2 := by
347+ refine intervalIntegral.integral_mono_on hab ?_ (by simp) fun x ⟨hx, _⟩ ↦ by gcongr <;> bound
348+ apply intervalIntegrable_one_div_log_sq <;> linarith
349+ _ ≤ _ := by simp [field]
350+
351+ /- Explicit integral bound, we expose a BigO version below since the constants and lower order term
352+ aren't very convenient. -/
353+ private theorem integral_one_div_log_sq_le_explicit {x : ℝ} (hx : 4 ≤ x) :
354+ ∫ t in 2 ..x, 1 / log t ^ 2 ≤ 4 * x / (log x) ^ 2 + x.sqrt / log 2 ^ 2 := by
355+ have two_le_sqrt : 2 ≤ x.sqrt := Real.le_sqrt_of_sq_le <| by norm_num [hx]
356+ have sqrt_le_x : x.sqrt ≤ x := sqrt_le_left (by linarith) |>.mpr (by bound)
357+ rw [← intervalIntegral.integral_add_adjacent_intervals (b := x.sqrt)]
358+ · grw [integral_1_div_log_sq_le two_le_sqrt (by linarith),
359+ integral_1_div_log_sq_le sqrt_le_x (by linarith)]
360+ rw [log_sqrt (by linarith), add_comm, div_pow, ← div_mul, mul_comm, mul_div_assoc]
361+ norm_num
362+ gcongr <;> linarith
363+ all_goals apply intervalIntegrable_one_div_log_sq <;> linarith
364+
365+ -- Somewhat arbitrary bound which we use to estimate the second term.
366+ private theorem sqrt_isLittleO :
367+ Real.sqrt =o[atTop] (fun x ↦ x / log x ^ 2 ) := by
368+ apply isLittleO_mul_iff_isLittleO_div _|>.mp
369+ · conv => arg 2 ; ext; rw [mul_comm]
370+ apply isLittleO_mul_iff_isLittleO_div _|>.mpr
371+ · simp_rw [div_sqrt, sqrt_eq_rpow, ← rpow_two]
372+ apply isLittleO_log_rpow_rpow_atTop _ (by norm_num)
373+ filter_upwards [eventually_gt_atTop 0 ] with x hx using sqrt_ne_zero'.mpr hx
374+ filter_upwards [eventually_gt_atTop 1 ] with x hx
375+ apply pow_ne_zero _ <| log_ne_zero.mpr ⟨_, _, _⟩ <;> linarith
376+
377+ theorem integral_one_div_log_sq_isBigO :
378+ (fun x ↦ ∫ t in 2 ..x, 1 / log t ^ 2 ) =O[atTop] (fun x ↦ x / log x ^ 2 ) := by
379+ trans (fun x ↦ 4 * x / log x ^ 2 + √x / log 2 ^ 2 )
380+ · apply IsBigO.of_bound'
381+ filter_upwards [eventually_ge_atTop 4 ] with x hx
382+ apply le_trans <| intervalIntegral.abs_integral_le_integral_abs (by linarith)
383+ rw [intervalIntegral.integral_congr (g := (fun t ↦ 1 / log t ^ 2 ))]
384+ · grw [integral_one_div_log_sq_le_explicit hx, norm_of_nonneg]
385+ positivity
386+ intro t ht
387+ simp
388+ refine IsBigO.add ?_ ?_
389+ · simp_rw [mul_div_assoc]
390+ apply isBigO_const_mul_self
391+ conv => arg 2 ; ext; rw [← mul_one_div, mul_comm]
392+ apply IsBigO.const_mul_left sqrt_isLittleO.isBigO
393+
394+ /-- Bound on the integral in `Chebyshev.primeCounting_eq_theta_div_log_add_integral`. -/
395+ theorem integral_theta_div_log_sq_isBigO :
396+ (fun x ↦ ∫ t in 2 ..x, θ t / (t * log t ^ 2 )) =O[atTop] (fun x ↦ x / log x ^ 2 ) := by
397+ refine (IsBigO.of_bound (log 4 ) ?_).trans integral_one_div_log_sq_isBigO
398+ filter_upwards [eventually_ge_atTop 4 ] with x hx
399+ simp_rw [norm_eq_abs]
400+ calc |∫ (t : ℝ) in 2 ..x, θ t / (t * log t ^ 2 )|
401+ _ ≤ ∫ (x : ℝ) in 2 ..x, |θ x / (x * log x ^ 2 )| :=
402+ intervalIntegral.abs_integral_le_integral_abs (by linarith)
403+ _ ≤ ∫ (x : ℝ) in 2 ..x, log 4 * (1 / log x ^ 2 ) :=
404+ intervalIntegral.integral_mono_on (by linarith) ?hf ?hg fun t ⟨ht, _⟩ ↦ ?hh
405+ _ = log 4 * |∫ (t : ℝ) in 2 ..x, 1 / log t ^ 2 | := by
406+ rw [intervalIntegral.integral_const_mul, abs_of_nonneg]
407+ exact intervalIntegral.integral_nonneg (by linarith) fun u _ ↦ by positivity
408+ case hf =>
409+ refine (intervalIntegrable_iff.mpr ?_).abs
410+ rw [Set.uIoc_of_le (by linarith), ← integrableOn_Icc_iff_integrableOn_Ioc]
411+ exact integrableOn_theta_div_id_mul_log_sq x
412+ case hg =>
413+ refine (intervalIntegrable_one_div_log_sq ?_ ?_).const_mul _ <;> linarith
414+ case hh =>
415+ calc |θ t / (t * log t ^ 2 )|
416+ _ = θ t / (t * log t ^ 2 ) := abs_of_nonneg (by positivity [theta_nonneg t])
417+ _ ≤ log 4 * t / (t * log t ^ 2 ) := by grw [theta_le_log4_mul_x (by linarith)]
418+ _ = log 4 * (1 / log t ^ 2 ) := by field
419+
420+ theorem integral_theta_div_log_sq_isLittleO :
421+ (fun x ↦ ∫ t in 2 ..x, θ t / (t * log t ^ 2 )) =o[atTop] (fun x ↦ x / log x) := by
422+ refine integral_theta_div_log_sq_isBigO.trans_isLittleO ?_
423+ refine isLittleO_iff_tendsto' (by simp) |>.mpr ?_
424+ refine Tendsto.congr' (f₁ := fun x ↦ (log x)⁻¹) ?_ tendsto_log_atTop.inv_tendsto_atTop
425+ filter_upwards [eventually_gt_atTop 0 ] with x hx
426+ field
427+
428+ theorem primeCounting_sub_theta_div_log_isBigO :
429+ (fun x ↦ π ⌊x⌋₊ - θ x / log x) =O[atTop] (fun x ↦ x / log x ^ 2 ) := by
430+ apply integral_theta_div_log_sq_isBigO.congr' _ (by rfl)
431+ filter_upwards [eventually_ge_atTop 2 ] with x hx
432+ rw [primeCounting_eq_theta_div_log_add_integral hx]
433+ simp
434+
435+ /-- Chebyshev's upper bound on the prime counting function -/
436+ theorem eventually_primeCounting_le {ε : ℝ} (εpos : 0 < ε) :
437+ ∀ᶠ x in atTop, π ⌊x⌋₊ ≤ (log 4 + ε) * x / log x := by
438+ have := integral_theta_div_log_sq_isLittleO.bound εpos
439+ filter_upwards [eventually_ge_atTop 2 , this] with x hx hx2
440+ rw [primeCounting_eq_theta_div_log_add_integral hx, add_mul, add_div]
441+ have hl : 0 ≤ log x := by bound
442+ rw [norm_of_nonneg (show 0 ≤ x / log x by bound), ← mul_div_assoc] at hx2
443+ grw [theta_le_log4_mul_x (by linarith), ← hx2]
444+ grind [le_norm_self]
445+
446+ end PrimeCounting
272447end Chebyshev
0 commit comments