The gaps between consecutive primes can be large in absolute terms, but they are expected to be small compared with the size of the primes themselves. Andrica's conjecture, stated by Dorin Andrica in 1986, makes this precise in a particularly compact form: the difference of square roots of consecutive primes is always less than . Among conjectures on prime gaps, this is a relatively weak qualitative bound, yet it does not follow from the strongest gap estimates that have been proved, and it remains open.
Anyone working on explicit prime-gap inequalities, or comparing conjectural gap laws with what can be deduced from zero-free regions or sieve estimates, has a reason to care about the statement. It is also a convenient formal target: once the indexing of primes and the choice of square root are fixed, the claim is a single inequality in one variable, with no auxiliary arithmetic functions.
Timeline. Andrica published the inequality in Note on a conjecture in prime number theory, Studia Univ. Babeș-Bolyai Math. 31 (1986), no. 4, 44–48. Subsequent work has been almost entirely either computational verification or comparison with independent gap bounds. Oliveira e Silva, Herzog, and Pardi computed every prime gap up to in the course of an empirical verification of the even Goldbach conjecture; those gaps are far smaller than throughout the range, so Andrica's inequality holds for all primes up to . Using published tables of first-occurrence maximal prime gaps, Visser checked the same criterion through the th maximal gap, which begins at , and recorded that the inequality holds at least that far. The best general upper bound on gaps that has been proved unconditionally is due to Baker, Harman, and Pintz: for all sufficiently large . That exponent is larger than , so the bound does not imply Andrica's inequality for large . The conjecture is still generally regarded as open, including in its purely asymptotic form (the inequality for all sufficiently large ).
Let denote the sequence of primes in increasing order, with the zero-based indexing used by Mathlib: , , , and so on. In Lean this is Nat.nth Nat.Prime n, and Mathlib records the first values (in particular Nat.nth_prime_zero_eq_two and Nat.nth_prime_one_eq_three). In informal number theory the same sequence is usually written , , , . The two conventions name the same primes; they differ only by a shift of the index. The Lean statements in this mission use the Mathlib indexing, so the universal quantifier runs over all , including , and already covers the first gap .
The Andrica difference at is
where the square root is the nonnegative real square root, in Lean Real.sqrt applied to the prime viewed as a real number. The prime gap at is . Because , the inequality is equivalent to
This equivalence is algebraic once the identities of Real.sqrt and the fact that the sequence of primes is strictly increasing are granted; it is recorded as a milestone so that the two forms can be used interchangeably in Lean.
The integer square root Nat.sqrt is a different function. Replacing Real.sqrt by Nat.sqrt changes the claim, and in fact falsifies it already at the gap between and : , which is not strictly less than . That substitution is not Andrica's conjecture.
For every ,
where and the right-hand side is interpreted in . This is equivalent to the goal, and is the form in which computational checks and comparisons with gap bounds are usually phrased. It is a known equivalence, not an independent open statement.
The inequality holds for every with . This is a known computational theorem, following Visser's comparison with the table of first-occurrence maximal gaps through the th such gap, and consistent with the complete determination of all gaps up to by Oliveira e Silva, Herzog, and Pardi. Formalizing it is a finite verification, not a proof of the conjecture.
There exists a real constant such that
for every . This is a weaker open statement than the conjecture (which is the case ). It is equivalent to , and it is not known: the Baker–Harman–Pintz exponent only yields a difference of size , which is unbounded.
For every ,
with and as above. This is the open goal.
A proof would be a uniform square-root bound on consecutive prime gaps, valid from the first prime onward. It would not by itself give stronger classical gap conjectures such as Oppermann's conjecture, or Brocard's conjecture that there are four primes between consecutive prime squares, but it would be a sharp, explicit instance of the expectation that gaps are . A counterexample would be a prime gap at least as large as ; no such gap is known, and none occurs in the verified range described above.
A slightly stronger open refinement, not adopted as the goal, is that the Andrica difference attains its global maximum at . The goal is the stable bound by .
On the formal side, Mathlib already contains the sequence Nat.nth Nat.Prime, the infinitude of primes that makes the sequence well-defined for every , and Real.sqrt. It does not contain Andrica's inequality, the uniform gap bound, or a formalized verification through . The first milestone is elementary once square roots are handled correctly; the second is a large but finite computation; the third is a substantial open weakening. The goal remains open, and no machine-checked proof is claimed.
The obvious approach is to insert a proved upper bound for into the equivalent form . The obstruction is the exponent. Baker–Harman–Pintz give for large , and eventually dominates , so the comparison does not close the problem at infinity. Even under the Riemann hypothesis, the standard explicit gap bounds remain of the shape , which is still larger than by a logarithmic factor; Visser records this limitation and studies logarithmic and -th-root variants that do follow from the Riemann hypothesis. Finite verification, however far it is pushed, leaves an infinite tail. Thus neither a complete check up to a large explicit bound, nor the best available theorem on prime gaps, nor the Riemann hypothesis as currently applied to gaps, yields the conjecture.
The formalization uses Lean 4 and Mathlib. Primes are indexed by Nat.nth Nat.Prime, which is zero-based: Nat.nth Nat.Prime 0 = 2. The goal is quantified over all n : Nat, so the first gap is included. A formalization that starts the quantifier at while still using Nat.nth Nat.Prime n as if it were one-based (taking the term to be ) would drop or mislabel gaps and is not the conjecture. Conversely, writing a one-based statement in prose and a zero-based statement in Lean without recording the shift would be an ambiguity, not a formalization.
The square root is Real.sqrt, applied to a coercion (Nat.nth Nat.Prime n : ℝ). The integer square root Nat.sqrt is excluded, as already noted: it yields a different, false inequality. In the gap form, the left-hand side must also be coerced to ,
because the right-hand side is real. Truncated subtraction on Nat is safe here: the sequence of primes is strictly increasing, so agrees with the integer difference.
No local definition of the th prime is to be introduced; Nat.nth Nat.Prime is the mission-wide convention. Welcome contributions include a formal proof of the equivalence with the gap form, a formally verified check of the inequality on a substantial initial segment (or through the bound recorded by Visser), proofs of the weaker uniform bound or of the inequality for all sufficiently large , and a proof or counterexample to the goal.
namespace AndricaConjecture
theorem andrica_conjecture (n : Nat) :
Real.sqrt (Nat.nth Nat.Prime (n + 1) : Real) -
Real.sqrt (Nat.nth Nat.Prime n : Real) < 1 := by sorry
end AndricaConjecture
Let Nat.nth Nat.Prime n denote the th prime in Mathlib's zero-based indexing, so that and . Then for every natural number ,
where the square roots are the nonnegative real square roots. This is Andrica's conjecture, which remains open. In the classical one-based numbering , , , the same inequality is the assertion for all ; the Lean statement covers every consecutive pair, including the first gap.