Skip to content

Lean formalization of the Riemann Hypothesis (Alpöge, 2026-11-20) being cleaned up by members of the Lean community.

Python
13.8 KB
Raw Blame
module

import Mathlib.MeasureTheory.Function.Floor
public import New.Reduction.Zeros.PrimeError
import TauCeti.NumberTheory.ArithmeticDirichletSeries.Riesz.SummatoryTail
import Lib.Analytic.PrimeNumberTheorem.Tauberian
import Lib.Analytic.PrimeNumberTheorem.ZeroFreeRegion

/-!
# The prime number theorem for the remainders `R_q`

Let `d` be a prime and `q ≥ 1`. The remainder `R_q(y)` is an integral of the error `𝓔_q(t)` in the
weighted count (`primeRemainder_eq_integral_countError_sub`), so it varies slowly. For odd `d` prime
to `q` its absolute value is at most `(log y) ^ (-B)` for all large `y`, for every natural number
`B`; so it tends to `0`, which characterises the constant `c_q` in its definition.

Notions from other files:
* `lambdaKResidueClass d q n` is `λ(n) = Λ(n) (1 - (n/d))` for `n ≡ 1` mod `q`, and `0` for other
  `n`.
* `entireL ψ` is `L(s, ψ)`, multiplied by `s - 1` if `ψ` is principal; `quadTwist ψ d` is the
  product of `ψ` and the Legendre symbol `(·/d)`.
* `logDerivMean d q` is the function `G_q` that continues `∑ λ(n) n ^ (-s) - s / (φ(q) (s - 1))`
  when `d` is odd and prime to `q`.
* `primeRemainder d q y` is `R_q(y) = ∑_{n ≤ y} λ(n) (1/n - 1/y) - log y / φ(q) - c_q` with
  `c_q = re G_q(1)`.

## Relation to the literature

Known result: Prime number theorem in arithmetic progressions with an error term that saves every
power of the logarithm. It is a case of the Siegel–Walfisz theorem. Source: Montgomery and Vaughan,
Multiplicative Number Theory I, 2007, Cor. 11.19. Form here: the modulus is fixed, and the count is
the smoothed sum `∑_{n ≤ y} λ(n) (1/n - 1/y)` over the prime powers `n ≡ 1` mod `q`; for `d ≡ 3` mod
`4` the primes that split in `ℚ(√-d)` have weight zero.
-/

@[expose] public section

open ArithmeticFunction.vonMangoldt Complex Filter Finset MeasureTheory Nat Real Topology

namespace New

variable {d : ℕ} [Fact d.Prime] {q : ℕ} [NeZero q]

/-- Chebyshev's bound with a round constant: `∑_{n ≤ z} Λ(n) ≤ 6 z` for `z ≥ 0`. -/
lemma sum_Icc_vonMangoldt_le_six_mul {z : ℝ} (hz : 0 ≤ z) : ∑ n ∈ Icc 0 ⌊z⌋₊, Λ n ≤ 6 * z :=
  calc ∑ n ∈ Icc 0 ⌊z⌋₊, Λ n = Chebyshev.psi z := (Chebyshev.psi_eq_sum_Icc z).symm
    _ ≤ (Real.log 4 + 4) * z := Chebyshev.psi_le_const_mul_self hz
    _ ≤ 6 * z := by gcongr; linarith [log_four_eq, log_two_lt_d9]

variable (d q) in
/-- The error `𝓔_q(t) = ∑_{n ≤ t} λ(n) - t / φ(q)` in the count with the weights
`λ = lambdaKResidueClass d q`, that is `λ(n) = Λ(n) (1 - (n/d))` for `n ≡ 1` mod `q` and `λ(n) = 0`
otherwise. -/
noncomputable def countError (t : ℝ) : ℝ := ∑ n ∈ Icc 0 ⌊t⌋₊, lambdaKResidueClass d q n - t / φ q

/-- Let `d` be a prime and `q ≠ 0`, and let `λ(n) = lambdaKResidueClass d q n` be `Λ(n) (1 - (n/d))`
for `n ≡ 1` mod `q` and `0` otherwise. The error `𝓔_q(t) = countError d q t`, that is
`∑_{n ≤ t} λ(n) - t / φ(q)`, satisfies `|𝓔_q(t)| ≤ 13 t` for `t ≥ 0`, by Chebyshev's bound. -/
lemma abs_countError_le {t : ℝ} (ht : 0 ≤ t) : |countError d q t| ≤ 13 * t := by
  have h_sum : ∑ n ∈ Icc 0 ⌊t⌋₊, lambdaKResidueClass d q n ≤ 2 * (6 * t) := by
    grw [lambdaKResidueClass_le_two_mul_vonMangoldt, ← mul_sum, sum_Icc_vonMangoldt_le_six_mul ht]
  grw [countError, abs_sub, abs_of_nonneg (sum_nonneg fun n _ ↦ lambdaKResidueClass_nonneg d q n),
    abs_of_nonneg (by positivity), h_sum,
    div_le_self ht (mod_cast totient_pos.2 (NeZero.pos q) : (1 : ℝ) ≤ φ q)]
  linarith

omit [NeZero q] in
/-- Let `d` be a prime and let `λ(n) = lambdaKResidueClass d q n` be `Λ(n) (1 - (n/d))` for `n ≡ 1`
mod `q` and `0` otherwise. For the error `𝓔_q(t) = countError d q t`, that is
`∑_{n ≤ t} λ(n) - t / φ(q)`, the function `𝓔_q(t) t⁻²` is integrable on every interval `[y, z]` with
`1 ≤ y ≤ z`. -/
lemma intervalIntegrable_countError_div_sq {y z : ℝ} (hy : 1 ≤ y) (hyz : y ≤ z) :
    IntervalIntegrable (fun t : ℝ ↦ countError d q t / t ^ 2) volume y z := by
  have h_ne (t : ℝ) (ht : t ∈ Set.Icc y z) : t ^ 2 ≠ 0 := by positivity [hy.trans ht.1]
  have h_sum : IntegrableOn (fun t : ℝ ↦ (t ^ 2)⁻¹ * ∑ n ∈ Icc 0 ⌊t⌋₊, lambdaKResidueClass d q n)
      (Set.Icc y z) := integrableOn_mul_sum_Icc _ (zero_le_one.trans hy)
    (ContinuousOn.integrableOn_Icc (by fun_prop (disch := assumption)))
  have h_main : IntegrableOn (fun t : ℝ ↦ t / φ q / t ^ 2) (Set.Icc y z) :=
    ContinuousOn.integrableOn_Icc (by fun_prop (disch := assumption))
  rw [intervalIntegrable_iff_integrableOn_Icc_of_le hyz]
  exact (h_sum.sub h_main).congr (.of_forall fun t ↦ by simp [countError, field])

/-- For `y ≥ 1` the remainder `R_q = primeRemainder d q`, that is `R_q(y) = ∑_{n ≤ y} λ(n) (1/n -
1/y) - log y / φ(q) - c_q` with `c_q = re G_q(1)`, equals `∫₁^y 𝓔_q(t) t⁻² dt - c_q`, where
`𝓔_q(t) = countError d q t` is `∑_{n ≤ t} λ(n) - t / φ(q)`. -/
lemma primeRemainder_eq_integral_countError_sub {y : ℝ} (hy : 1 ≤ y) :
    primeRemainder d q y = (∫ t in 1..y, countError d q t / t ^ 2) - re (logDerivMean d q 1) := by
  have count (t : ℝ) : (countError d q t : ℂ) =
      (∑ n ∈ Icc 1 ⌊t⌋₊, (lambdaKResidueClass d q n : ℂ)) - (φ q : ℂ)⁻¹ * t := by
    simp [countError, Icc_eq_cons_Ioc (Nat.zero_le _), ← Icc_add_one_left_eq_Ioc,
      lambdaKResidueClass, residueClass, div_eq_inv_mul]
  apply Complex.ofReal_injective
  rw [primeRemainder_eq_normalized_rieszSum (zero_lt_one.trans_le hy),
    TauCeti.rieszSum_div_sub_log_eq_integral _ _ hy, Complex.ofReal_sub,
    intervalIntegral.integral_of_le hy]
  simp_rw [← integral_complex_ofReal, Complex.ofReal_div, Complex.ofReal_pow, count]

/-- Let `d` be prime and `q ≠ 0`. Write `λ(n) = Λ(n) (1 - (n/d))` for `n ≡ 1` mod `q` and
`λ(n) = 0` otherwise. The remainder `R_q(y) = ∑_{n ≤ y} λ(n) (1/n - 1/y) - log y / φ(q) - c_q`
satisfies `|R_q(z) - R_q(y)| ≤ 13 log (z / y)` for `1 ≤ y ≤ z`, by integrating
`|countError d q t| / t² ≤ 13 / t`. -/
lemma abs_primeRemainder_sub_le_log {y z : ℝ} (hy : 1 ≤ y) (hyz : y ≤ z) :
    |primeRemainder d q z - primeRemainder d q y| ≤ 13 * Real.log (z / y) := by
  have hy_pos : 0 < y := zero_lt_one.trans_le hy
  calc |primeRemainder d q z - primeRemainder d q y| = ‖∫ t in y..z, countError d q t / t ^ 2‖ := by
        rw [primeRemainder_eq_integral_countError_sub hy,
          primeRemainder_eq_integral_countError_sub (hy.trans hyz),
          sub_sub_sub_cancel_right, intervalIntegral.integral_interval_sub_left
            (intervalIntegrable_countError_div_sq le_rfl (hy.trans hyz))
            (intervalIntegrable_countError_div_sq le_rfl hy), norm_eq_abs]
    _ ≤ ∫ t in y..z, 13 * (1 / t) := by
      apply intervalIntegral.norm_integral_le_of_norm_le hyz
      · refine .of_forall fun t ht ↦ ?_
        have ht_pos : 0 < t := hy_pos.trans ht.1
        rw [Real.norm_eq_abs, abs_div, abs_of_pos (pow_pos ht_pos 2)]
        calc |countError d q t| / t ^ 2 ≤ (13 * t) / t ^ 2 :=
              div_le_div_of_nonneg_right (abs_countError_le ht_pos.le) (sq_nonneg t)
          _ = 13 * (1 / t) := by field_simp
      · exact ContinuousOn.intervalIntegrable_of_Icc hyz
          (continuousOn_const.mul (continuousOn_const.div continuousOn_id
            fun t ht ↦ (hy_pos.trans_le ht.1).ne'))
    _ = 13 * Real.log (z / y) := by
      rw [intervalIntegral.integral_const_mul, integral_one_div_of_pos hy_pos (hy_pos.trans_le hyz)]

/-- For `1 ≤ y ≤ z`, the change in the weighted prime remainder is at most `13 (z - y) / y`. -/
lemma abs_primeRemainder_sub_le {y z : ℝ} (hy : 1 ≤ y) (hyz : y ≤ z) :
    |primeRemainder d q z - primeRemainder d q y| ≤ 13 * ((z - y) / y) := by
  have hy_pos : 0 < y := zero_lt_one.trans_le hy
  calc |primeRemainder d q z - primeRemainder d q y| ≤ 13 * Real.log (z / y) :=
        abs_primeRemainder_sub_le_log hy hyz
    _ ≤ 13 * (z / y - 1) := by
      grw [Real.log_le_sub_one_of_pos (div_pos (hy_pos.trans_le hyz) hy_pos)]
    _ = 13 * ((z - y) / y) := by rw [sub_div, div_self hy_pos.ne']

/-- In logarithmic coordinates the weighted prime remainder is 13-Lipschitz on `[0, ∞)`. -/
lemma abs_primeRemainder_exp_sub_le {u v : ℝ} (hu : 0 ≤ u) (huv : u ≤ v) :
    |primeRemainder d q (rexp v) - primeRemainder d q (rexp u)| ≤ 13 * (v - u) := by
  simpa only [← Real.exp_sub, Real.log_exp] using
    (abs_primeRemainder_sub_le_log (d := d) (q := q) (one_le_exp hu) (exp_le_exp.2 huv))

/-- For a character `ψ` mod `q` let `L_ψ = entireL ψ` be `L(s, ψ)`, times `s - 1` if `ψ` is
principal, and let `ψ' = quadTwist ψ d` be `ψ (·/d)`. If all `logDeriv L_ψ` and `logDeriv L_ψ'` have
norm at most `C` at `s`, then `logDerivMean d q = (∑_ψ (logDeriv L_ψ' - logDeriv L_ψ) - 1) / φ(q)`
has norm at most `2 C + 1` at `s`, since there are `φ(q)` characters mod `q`. -/
lemma norm_logDerivMean_le {s : ℂ} {C : ℝ}
    (h_char : ∀ ψ : DirichletCharacter ℂ q, ‖logDeriv (entireL ψ) s‖ ≤ C)
    (h_twist : ∀ ψ : DirichletCharacter ℂ q, ‖logDeriv (entireL (quadTwist ψ d)) s‖ ≤ C) :
    ‖logDerivMean d q s‖ ≤ 2 * C + 1 := by
  have hφ : (1 : ℝ) ≤ φ q := mod_cast totient_pos.2 (NeZero.pos q)
  have h_sum := norm_sum_le_of_le univ fun ψ _ ↦ norm_sub_le_of_le (h_twist ψ) (h_char ψ)
  rw [logDerivMean, norm_div, Complex.norm_natCast, div_le_iff₀ (zero_lt_one.trans_le hφ)]
  refine (norm_sub_le_of_le h_sum norm_one.le).trans ?_
  rw [sum_const, nsmul_eq_mul, Finset.card_univ, ← Nat.card_eq_fintype_card,
    DirichletCharacter.card_eq_totient_of_hasEnoughRootsOfUnity]
  linarith

/-- Let `d` be a prime and `q ≠ 0`. Let `G_q = logDerivMean d q` be the mean over the characters `ψ`
mod `q` of the logarithmic derivatives of `L(s, ψ (·/d)) / L(s, ψ)`, less `1 / φ(q)`; here the
`L`-function of a principal character is multiplied by `s - 1`. For all large `l` the function
`G_q(s) / s` is holomorphic and of norm at most `l²⁶` on `re s ≥ 1 - l⁻²⁶`, `|s| ≤ e^l`. -/
lemma eventually_norm_logDerivMean_div_le : ∀ᶠ l : ℝ in atTop, ∀ s : ℂ,
    1 - 1 / l ^ 26 ≤ s.re → ‖s‖ ≤ rexp l →
      DifferentiableAt ℂ (fun z : ℂ ↦ logDerivMean d q z / z) s ∧
        ‖logDerivMean d q s / s‖ ≤ l ^ 26 := by
  -- The region lies in the zero-free regions `re s ≥ 1 - l⁻²⁵` of the finitely many `L`-functions;
  -- the exponent `26` in place of `25` absorbs the constants.
  have h_char : ∀ᶠ l : ℝ in atTop, ∀ (ψ : DirichletCharacter ℂ q) (s : ℂ),
      1 - 1 / l ^ 25 ≤ s.re → ‖s‖ ≤ rexp l →
        entireL ψ s ≠ 0 ∧ ‖logDeriv (entireL ψ) s‖ ≤ 2 * l ^ 25 :=
    eventually_all.2 eventually_norm_logDeriv_entireL_le
  have h_twist : ∀ᶠ l : ℝ in atTop, ∀ (ψ : DirichletCharacter ℂ q) (s : ℂ),
      1 - 1 / l ^ 25 ≤ s.re → ‖s‖ ≤ rexp l →
        entireL (quadTwist ψ d) s ≠ 0 ∧ ‖logDeriv (entireL (quadTwist ψ d)) s‖ ≤ 2 * l ^ 25 :=
    eventually_all.2 fun ψ ↦ eventually_norm_logDeriv_entireL_le (quadTwist ψ d)
  filter_upwards [h_char, h_twist, eventually_ge_atTop (10 : ℝ)]
    with l hl_char hl_twist hl s h_re h_norm
  have hl_two : 2 ≤ l := by linarith
  have hl_one : 1 ≤ l := one_le_two.trans hl_two
  have h_re' : 1 - 1 / l ^ 25 ≤ s.re := by
    linarith [one_div_pow_le_one_div_pow_of_le hl_one (show 25 ≤ 26 by norm_num)]
  have h_half : 1 / 2 ≤ s.re := by
    have h_pow : 2 ≤ l ^ 25 := hl_two.trans (le_self_pow₀ hl_one (by simp))
    linarith [one_div_le_one_div_of_le two_pos h_pow]
  obtain ⟨h_char_ne, h_char_le⟩ := forall_and.1 fun ψ ↦ hl_char ψ s h_re' h_norm
  obtain ⟨h_twist_ne, h_twist_le⟩ := forall_and.1 fun ψ ↦ hl_twist ψ s h_re' h_norm
  constructor
  · exact (analyticAt_logDerivMean h_char_ne h_twist_ne).differentiableAt.fun_div
      differentiableAt_id (ne_zero_of_re_pos (by linarith))
  · calc ‖logDerivMean d q s / s‖ ≤ (2 * (2 * l ^ 25) + 1) / (1 / 2) := by
          grw [norm_div, norm_logDerivMean_le h_char_le h_twist_le, ← re_le_norm s, ← h_half]
      _ ≤ 10 * l ^ 25 := by linarith [one_le_pow₀ hl_one (n := 25)]
      _ ≤ l ^ 26 := by grw [hl, pow_succ' l 25]

/-- The weighted prime remainder at `exp v` decays faster than any fixed inverse power of
the logarithmic variable `v`. -/
theorem eventually_abs_primeRemainder_exp_le_inv_pow (hd : d ≠ 2) (h_cop : q.Coprime d) (B : ℕ) :
    ∀ᶠ v : ℝ in atTop, |primeRemainder d q (rexp v)| ≤ 1 / v ^ B := by
  -- Apply the Tauberian theorem to `v ↦ R_q(e^v)` and `F(s) = logDerivMean d q s / s`.
  let F : ℂ → ℂ := fun s ↦ logDerivMean d q s / s
  have h_transform (s : ℂ) (hs : 2 < s.re) : (F s - F 1) / (s - 1) =
      ∫ v : ℝ in Set.Ioi 0, (primeRemainder d q (rexp v) : ℂ) * cexp ((1 - s) * v) := by
    simp [F, integral_primeRemainder hd h_cop hs, ofReal_re_logDerivMean_one hd h_cop]
  exact eventually_abs_le_inv_pow_of_transform (by fun_prop [primeRemainder, lambdaKSum])
    (fun _ _ hu huv _ ↦ abs_primeRemainder_exp_sub_le hu huv)
    h_transform eventually_norm_logDerivMean_div_le B

/-- **Prime number theorem** in the class `1` mod `q`, with weights `λ(n) = Λ(n) (1 - (n/d))`. Let
`d` be an odd prime and `q` prime to `d`. For every natural number `B` the remainder
`primeRemainder d q`, that is `R_q(y) = ∑_{n ≤ y, n ≡ 1} λ(n) (1/n - 1/y) - log y / φ(q) - c_q`,
satisfies `|R_q(y)| ≤ (log y) ^ (-B)` for all large `y`, by a Tauberian theorem applied to the
Laplace transform of `v ↦ R_q(e ^ v)`; it also follows from the Siegel–Walfisz theorem. -/
theorem eventually_abs_primeRemainder_le (hd : d ≠ 2) (h_cop : q.Coprime d) (B : ℕ) :
    ∀ᶠ y : ℝ in atTop, |primeRemainder d q y| ≤ 1 / y.log ^ B := by
  have h_bound := eventually_abs_primeRemainder_exp_le_inv_pow hd h_cop B
  filter_upwards [tendsto_log_atTop.eventually h_bound, eventually_gt_atTop 0] with y hy hy_pos
  rwa [Real.exp_log hy_pos] at hy

end New