WorksMathematics
An explicit prime gap under the Riemann hypothesis, formalized in Lean with its prime power input made elementary
Abstract
We report on a Lean 4 formalization of Theorem 2 of Dudek, 2015, as numbered in arXiv v2, which states that if the Riemann hypothesis is true, then for every real there is a prime in the interval . In the formalization, Theorem 2 is proved assuming the Riemann hypothesis and one cited explicit zero-counting bound of Hasanalizade, Shen and Wong, arXiv:2107.06506. Four cited inputs of the printed proof are replaced in the formal proof. The two that carry the argument are these: first, the prime power contribution is required only across the moving window and is proved outright in Lean by an elementary counting argument with no cited input and without assuming the Riemann hypothesis; second, the sum over nontrivial zeros is bounded from the cited Hasanalizade, Shen and Wong zero count for by trading slack between the head and tail sums at the split point . The Riemann hypothesis is open and this note makes no progress on it.
The paper
This note documents a formalization in Lean 4 of the main explicit prime gap theorem from A. W. Dudek, On the Riemann hypothesis and the difference between primes, Int. J. Number Theory 11, 2015, no. 3, 771–778, doi:10.1142/S1793042115500426; preprint arXiv:1402.6417, v2, 20 May 2014 [1]. That paper improves the constant of Ramaré and Saouter [RaSa, Theorem 1] to . Later work went further: Dudek, Grenié and Molteni [5 Theorem 1.1] proved a prime in a symmetric interval of total length , and Carneiro, Milinovich and Soundararajan [3 Theorem 5] proved, under the Riemann hypothesis, that for there is a prime in . Theorem 2 of [1] is therefore not the best known constant, and this note is about the formal record of its proof. It is written for readers who use or check formal proofs in analytic number theory.
All theorem, lemma and page numbers of [1] in this note are those of arXiv v2. The journal numbering may differ: [3] cites the journal paper with Theorem 1.3 for Theorem 3 of arXiv v2.
The primary focus of this note is Theorem 2 of arXiv v2 of [1]:
Theorem 1.1 (Dudek [1], Theorem 2 of arXiv v2). Suppose the Riemann hypothesis is true. Then there is a prime in the interval
for all .
In addition to Theorem 2, Theorem 1 of [1], which Dudek quotes from Cramér, gives a constant such that
for all , and Dudek’s Theorem 3 gives a prime in the interval
for all sufficiently large . The same Lean entry also proves Theorems 1 and 3 under the same two hypotheses, with for Theorem 1, whereas the remark of the paper that works for large is not part of the entry.
The purpose of this note is to record which inputs the formal proof took and how they differ from those printed in [1]. No discrepancy was found in the steps of Dudek’s argument that were formalized. Theorem 2 is proved assuming the Riemann hypothesis and one cited zero count. The Riemann hypothesis is open and this note makes no progress on it. The binary Goldbach conjecture also remains open and is not treated here.
The mathematical content of this note is two observations. The proof uses only across a short window, where the prime power mass is by counting; this is a simplification of this proof over citing Rosser and Schoenfeld. The zero sum can be closed with a zero count whose constant is too large for the separate head and tail bounds, by trading slack at the split point; this is a convenience forced by the chosen input. Neither is claimed as new. The rest of the Lean entry is formalization work.
Outline of the paper’s proof. Section 2 of [1] establishes Theorem 2 using a weight on the open interval together with the integrated Chebyshev function
The argument in Section 2 of [1] proceeds through the following steps:
Explicit formula for , Lemma 4 of [1]. For , with not an integer,
where the sum runs over the nontrivial zeros of the Riemann zeta function. The printed argument bounds a sum over zeros by and quotes the value of this sum from Davenport [4].
Weighted prime-power sum via second differences, Lemma 5 of [1]. For and ,
where is the von Mangoldt function and
(3) Splitting the sum over zeros. Writing under the Riemann hypothesis, the sum over nontrivial zeros is split at . To bound the head of the sum, the paper uses a zero count, specifically
cited as Corollary 1 of Trudgian, Math. Comp. 81, 2012 [Tr]. To bound the tail of the sum, the paper uses Lemma 1 (ii) of Skewes [6].
(4) Passing from to primes. To pass from the von Mangoldt function to primes, the paper uses, in the paper’s words, Theorem 14 and equation 5.5 of its reference [7], Rosser and Schoenfeld, 1962 [7], namely the two-sided bound
(5) Positivity of the lower bound for and finite verification. Choosing and
the display at the foot of page 6 of arXiv v2 of [1] states that , the sum of over primes in , exceeds
which is positive for all . Positivity of guarantees the existence of a prime in . Replacing by then yields Theorem 2 from about 66798.7, namely
The remaining values of below this threshold were checked by computer in the paper, using Mathematica, with no table printed.
What the formal proof does
In the Lean 4 formalization [Palomar, Repo], the main theorem corresponding to Theorem 2 of [1] has the full name
LeanLab.PNTPort.ExplicitPsi1.Trivial.theorem2_of_RH_hsw.
Its exact Lean declaration, together with the interval predicate and width function, is as follows:
theorem theorem2_of_RH_hsw (hRH : RiemannHypothesis)
(hN : LeanLab.Dudek2014.SigmaH.HSWN70 gZ) :
∀ x : R, 2 ≤ x → LeanLab.Dudek2014.PrimeInDudekInterval x
with
def PrimeInDudekInterval (x : R) : Prop :=
∃ p : N, p.Prime ∧ x - dudekH x < p ∧ (p : R) ≤ x
noncomputable def dudekH (x : R) : R := 4 / π * √x * Real.log x
The hypotheses and objects appearing in this statement are defined as follows:
RiemannHypothesisis the standard statement of the Riemann hypothesis from Mathlib [Mathlib].gZis the family of imaginary parts of the zeros ofriemannZetawith real part at least , which are the nontrivial zeros, indexed with multiplicity given byanalyticOrderNatAt.HSWN70 gZis the one cited input, included explicitly as a hypothesis to the theorem and never declared as an axiom.
The predicate HSWN70 is defined in Lean by:
def HSWN70 (γ : ι → ℝ) : Prop :=
(∀ T : ℝ, 70 ≤ T → ∀ s : Finset ι,
((s.filter (fun i => |γ i| ≤ T)).card : ℝ) ≤ 2 * (Mt T + Rt T)) ∧
(∀ T t : ℝ, 70 ≤ T → T ≤ t → ∀ s : Finset ι,
((s.filter (fun i => T < |γ i| ∧ |γ i| ≤ t)).card : ℝ) ≤
2 * ((Mt t + Rt t) - (Mt T - Rt T)))
where the main term and remainder bound are given by
This hypothesis encodes Corollary 1.2 of Hasanalizade, Shen and Wong, arXiv:2107.06506 [2], which states that
In the Lean formalization, this bound is used only for . The Lean definitions add to the main term and to the remainder, so that
Thus is exactly the printed lower bound for , and is the printed upper bound plus . The factor 2 counts ordinates of both signs, and , since counts only . Zeros are counted with multiplicity, the standard reading of , which [2] prints as a set count. Consequently, the hypothesis HSWN70 gZ holds for the actual nontrivial zeros of the Riemann zeta function given Corollary 1.2 of [2], ensuring that theorem2_of_RH_hsw is not vacuous. The cited zero count itself is not proved in Lean.
Table 1 summarizes the relationship between the printed proof in [1] and the formal proof. Four cited inputs of the printed proof are replaced: the zero count of [Tr], the bound of [7], the tail bound of [6] and the value from [4]. The zero count of [2] is a choice of input, not a correction; this note does not examine whether the input of [Tr] also suffices. The smaller differences are these. The Lean definition of is the sum , which has the same value as the printed integral for . The Lean form of Lemma 5 adds the side condition , which holds for . Lemma 4 is proved by its own route, and integer is allowed. Zeros are counted with multiplicity. We present the mathematics of the prime power step and the zero sum in the following two subsections.
| Component | Printed paper [1] | Lean 4 formalization |
| Zero hypothesis | Riemann hypothesis | RiemannHypothesis (Mathlib) |
| Zero count input | Trudgian [Tr], | HSWN70_gZ from [2], |
| Prime power step | Cited from [7] for | window_holds, proved outright |
| error bound | error bound | |
| Sum | Value from Davenport [4] | Not used, the route of error bound differs |
| Tail of | Lemma 1 (ii) of Skewes [6] | tail_inv_sq, from HSWN70 |
| Large range | () | rhs_pos (), |
| Small range | Mathematica check (unprinted) | small_range (, kernel) |
Table 1. Comparison between the inputs and verification steps printed in Dudek [1] and those used in the Lean 4 formalization.
The prime power step, proved with no cited input
A key observation of the formalization is that the proof of Theorem 2 uses the difference only through its increment across the window . In Lean, this windowed inequality is named SchoenfeldWindow and is proved as the theorem LeanLab.PrimePowerWindow.window_holds:
def SchoenfeldWindow : Prop :=
∀ x : ℝ, 65000 ≤ x →
(psiF (x + hD x) - thetaF (x + hD x)) -
(psiF (x - hD x) - thetaF (x - hD x)) <
1.11 * √(x + hD x) + 3 * (x + hD x) ^ (1 / 3 : ℝ) -
0.98 * √(x - hD x)
where
The theorem window_holds is proved outright in Lean, assuming no Riemann hypothesis and using no cited input. A companion lemma, schoenfeld_window_of, records that the two-sided bound of Rosser and Schoenfeld [7] cited in the paper implies SchoenfeldWindow; thus the window form is a logical weakening of the printed input and is all that Dudek’s argument requires.
Proposition 2.1 (LeanLab.PrimePowerWindow.window_holds). For every real , with ,
The proof goes through the following bound on the mass of the window.
Lemma 2.2 (LeanLab.PrimePowerWindow.mass_le_with_diff_eq). Let be real numbers with . Then
Proof. Since and , the difference is the sum of over non-prime integers . Consequently, the left side of the lemma is precisely the von Mangoldt mass of the prime powers with lying in the interval .
First, the lemma sum_nonprime_le bounds the non-prime von Mangoldt mass over a natural-number interval with :
Indeed, every non-prime with is of the form for a prime and an integer satisfying . For such , its von Mangoldt weight satisfies
and for each fixed exponent , the map is injective.
Second, the lemma count_le bounds the number of -th powers in the integer interval for real numbers :
Applying these two bounds separates the prime powers in into squares, , and higher powers, :
For , there are at most squares in , each carrying weight .
For each , the bound follows from the case by
rpow_sub_mono, so there is at most one -th power in , bycount_le_one, carrying weight .
There are at most exponents , which gives the last term. □
Proof of Proposition 2.1. Let , , , , and . For all ,
These give , so and . Hence , and gives . Also gives , so Lemma 2.2 applies. Further .
Since and , the target satisfies
By Lemma 2.2 and , the window mass is at most
Substituting , the proof closes with the polynomial inequality
which is checked in Lean. □
The zero sum, from the Hasanalizade, Shen and Wong count
The bound on the zero sum is formalized as LeanLab.Dudek2014.SigmaH.sigmaBd_of_hsw, with conclusion SigmaBd, which is the bound of Section 2.2 of [1] at , on page 5 of the arXiv version:
Proposition 2.3 (LeanLab.Dudek2014.SigmaH.sigmaBd_of_hsw). Let be any family of real ordinates satisfying HSWN70, and let be the sum of Dudek’s Lemma 5 over , written Zr in Lean. For every , with ,
This theorem takes no Riemann hypothesis. The hypothesis enters only in theorem2_of_RH_hsw, through Zr_eq_Zreal, which identifies the sum over the family gZ with the sum over the nontrivial zeros.
The final bound has the same form as the bound in Dudek’s paper. The route differs. From the count HSWN70, with its constant 10.2425, the separate head and tail estimates that would give this form do not both hold near : the tail inequality
needs about , while at the split point with we only know .
The formal proof keeps the split at and trades slack between head and tail through four lemmas:
Head slack,
head_count. For all , the zero count hypothesis HSWN70 implies
so the head count has a positive slack of about below the main term . Indeed, HSWN70 gives , where
For , the lemma Rt_le gives , so , and . Write for this slack.
Tail with excess,
tail_inv_sq. For , partial summation against the second count in HSWN70 gives
and the excess is positive until about . The lemma slack gives and for .
Comparison of head and tail weights,
weight_ratio. Let
denote the head weight and tail weight, respectively. If , which is equivalent to , then
(4) Combined split bound, split_bound. Let denote the second-difference term
for the -th zero. Each head term has , by second_diff_small, and each tail term has , by second_diff_large. The head count and the tail bound give
Using and , the excess from the tail sum is absorbed into the slack of the head count, which yields
Since , substituting , , and , this upper bound equals the displayed formula in SigmaBd.
The rest of the formal proof
The remaining steps of the formalization connect the explicit formula, the positivity of rhs(x), and the finite prime gap verification to assemble Theorem 2 for all :
Lemma 4 and Lemma 5,
lemma4_Zpatch. Lemma 4 of [1] is proved in Lean aslemma4_Zpatch, combining the explicit formulapsi1_formulaand the error estimateerror_boundfor all in the form
which is strictly below the printed bound . Here is the zero sum for ; for the Lean definition Zpatch takes the value that makes the identity exact, and the proof of Theorem 2 uses only for . Lemma 5 of [1] then follows by taking the second difference across , giving the error bound .
Positivity for ,
rhs_pos. The lemmarhs_posproves by explicit analytic bounds in Lean thatrhs(x) > 0for every real .
Large range transfer,
theorem2_large_of. From the existence of a prime in for all , the theoremtheorem2_large_ofdeducesPrimeInDudekInterval Xfor all via the intermediate value theorem and monotonicity, since is about .
Small range verification,
small_range. The theoremsmall_rangeprovesPrimeInDudekInterval xfor every real satisfying , with no Riemann hypothesis, by a prime gap scan evaluated by the Lean kernel throughdecide +kernel. The functiongapScanwalks the integers of a tier, keeps the last prime seen, and checks at each , so every such has a prime with . Table 2 lists the six tiers;
| Integers | Gap | dudekH() at the start , about |
| 2 | 1 | 1.25 |
| 3 to 4 | 2 | 2.42 |
| 5 to 6 | 2 | 4.58 |
| 7 to 22 | 4 | 6.56 |
| 23 to 199 | 14 | 19.15 |
| 200 to 67000 | 72 | 95.40 |
Table 2. The tiers of small_range. Each integer in a tier has a prime with .
the lemma gaps_big is the last one. Since dudekH() at the start of each tier and dudekH is increasing, the lemma tier gives a prime in the interval. Because the small range and the large range overlap, theorem2_of_RH_hsw covers all .
Status, cited inputs and data availability
Status of each claim. In Table 3, Kernel means checked by the Lean kernel at the commit below, Text means argued in this note and not in Lean, and Cited means taken from the source and not proved.
| Claim | Status | Lean name |
| Theorem 1.1 | Kernel, given hRH and hN | theorem2_of_RH_hsw |
| Proposition 2.1 | Kernel, no hypothesis | window_holds |
| Lemma 2.2 | Kernel, no hypothesis | mass_le |
| Proposition 2.3 | Kernel, given HSWN70 | sigmaBd_of_hsw |
| Lemma 4 in the form with 2.393 | Kernel, no hypothesis | lemma4_Zpatch |
Positivity of rhs() | Kernel, no hypothesis | rhs_pos |
| Small range | Kernel, no hypothesis | small_range |
HSWN70 gZ follows from Corollary 1.2 of [2] | Text | none |
| Corollary 1.2 of [2] | Cited | hypothesis hN |
Table 3. Status of the claims of this note.
Cited inputs. Table 4 lists every cited input of the printed proof and of the formal proof. Corollary 1.2 of [2] was read in arXiv v1. The other four sources were not read for this note; they are quoted as [1] states them, by page of its arXiv v2.
| Input | Page | Printed statement | Use | Lean form |
| Corollary 1.2 of [2] | arXiv v1, p. 2, display 1.5 | for | Used for , both signs, 7/8 added to Mt and to Rt | HSWN70 gZ |
| Corollary 1 of [Tr] | [1], p. 5 | for | Replaced by HSWN70 | none |
| Theorem 14 and 5.5 of [7] | [1], p. 6 | for | Replaced by the window bound | window_holds |
| Lemma 1 (ii) of [6] | [1], p. 5 | Gives the bound on the tail of the zero sum | Replaced from HSWN70 | tail_inv_sq |
| Value of , [4] | [1], p. 4 | The value of the sum is explicitly known | Not used | none |
Table 4. Cited inputs. Printed statement, page, how the proof uses it, and Lean form.
Data availability.
Registry entry: Palomar registry
PALOMAR-2026-11-01-000028, version 1, https://palomar-registry.org/entry.html?id=PALOMAR-2026-11-01-000028&version=1 [Palomar].Repository: https://github.com/sthubbar/goldbach-lean, directory
entries/dudek2014, commitda5cf9edad7896290771dfcab8feee2906399e3d[Repo].
Toolchain: Lean and Mathlib version v4.35.0-rc3 [Mathlib].
Build: in that directory, run
lake exe cache get,lake buildandlake comparator --config=comparator-dudek2014.json. A fresh public clone of this commit built 9036 jobs in 1196 s of wall time on a 2 core machine.Axioms and comparator check: The axioms of the compared theorems are solely the standard Lean foundational axioms
propext,Quot.sound, andClassical.choice, with 0 sorry. The comparator passed against the challenge fileChallengeDudek2014.lean.Ported files: sixteen files under
LeanLab/PNTPort/StrongPNTare from the PrimeNumberTheoremAnd project [PNT], commitc39a751132c88b6e8080b74c74023fd95b3d8be0, Apache-2.0, credited to its contributors.
Steve Hubbard designed the research program and directed this work. AI tools, Claude and Gemini, were used to write the Lean code and draft the text. AI agents also did the checks of the Lean against the source, and no human expert has reviewed the mathematics. The author takes full responsibility for the content.
Independent Researcher
References
- [1][Dudek] A. W. Dudek, On the Riemann hypothesis and the difference between primes, Int. J. Number Theory 11 (2015), no. 3, 771–778, doi:10.1142/S1793042115000426, arXiv:1402.6417.arxiv.org/abs/1402.6417
- [2][HSW] E. Hasanalizade, Q. S.-N. and P.-J. Wong, Counting zeroes of the Riemann zeta function, J. Number Theory 235 (2022), 219–241, arXiv:2107.06506.
- [3][CMS] E. Carneiro, M. B. Milinovich and K. Soundararajan, Fourier optimization and prime gaps, arXiv:1708.04122v2, first posted 2017, doi:10.1417/CMH/467.DOI
- [4][Da] H. Davenport, Multiplicative Number Theory, Springer, 1980.DOI
- [5][DGM] A. W. Dudek, L. Grenié and G. Molteni, Primes in explicit short intervals on RH, Int. J. Number Theory 12 (2016), no. 5, 1391–1407, arXiv:1503.05403.DOI
- [6][Sk] S. Skewes, On the difference π(x) − li(x) II, Proc. London Math. Soc. (3) 5 (1955), 48–70.DOI
- [7][RS] J. B. Rosser and L. Schoenfeld, Approximate formulas for some functions of prime numbers, Illinois J. Math. 6, 1962, no. 1, 64–94.