/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil

Shanks's asymptotic conjecture for maximal prime gaps

Writing $p_n$ for the $n$-th prime ($0$-indexed, $p_0 = 2$) and $g_n = p_{n+1} - p_n$ (primeGap n) for the $n$-th prime gap, let $G(x) = \max_{p_n < x} g_n$ (sup_primeGap x) denote the largest prime gap starting below $x$ (which has the same asymptotic growth as $\max_{p_n \le x} g_n$). An index $n$ marks a record (maximal) gap whenever $g_m < g_n$ for all $m < n$. Strengthening Cramér's prime-gap heuristic, Daniel Shanks (1964) conjectured that $G(x) \sim (\log x)^2$ as $x \to \infty$. By contrast, Andrew Granville's (1995) sieve-adjusted model predicts $\limsup_{n \to \infty} g_n / (\log p_n)^2 \ge 2e^{-\gamma} \approx 1.1229$, contradicting Shanks's conjecture. See also Erdos5.

References:

    Wikipedia

    Wikipedia: Prime gap

    D. Shanks, On maximal gaps between successive primes, Math. Comp. 18 (1964), no. 88, 646–651.

    A. Granville, Harald Cramér and the distribution of prime numbers, Scand. Actuar. J. 1995 (1995), no. 1, 12–28.

@[expose] public sectionopen scoped Asymptoticsnamespace MaximalPrimeGap

Predicate that index $n$ achieves a strictly larger primeGap than all earlier indices $m < n$.

def IsMaximalPrimeGapIndex (n : ℕ) : Prop := ∀ m : ℕ, m < n → primeGap m < primeGap n

Checks the first three indices and sup_primeGap at $x = 6$: $g_0 = 1$ and $g_1 = 2$ are record gaps, $g_2 = 2$ is not, and $G(6) = \max(1, 2, 2) = 2$.

hp0:Nat.nth Nat.Prime 0 = 2hp1:Nat.nth Nat.Prime 1 = 3hp2:Nat.nth Nat.Prime 2 = 5hp3:Nat.nth Nat.Prime 3 = 7hg0:primeGap 0 = 1hg1:primeGap 1 = 2hg2:primeGap 2 = 2hc:⌈6⌉₊ = 6hpc:Nat.primeCounting' 6 = 3⊢ (Finset.range 3).sup primeGap = 2 All goals completed! 🐙

Index $0$ ($g_0 = 3 - 2 = 1$) is vacuously a record prime gap index.

@[category API, AMS 11] theorem isMaximalPrimeGapIndex_zero : IsMaximalPrimeGapIndex 0 := maximal_prime_gap_initial_indices.1

Infinitely many indices $n$ achieve a new record prime gap, since prime gaps are unbounded.

@[category textbook, AMS 11] theorem infinite_maximalPrimeGapIndex : {n : ℕ | IsMaximalPrimeGapIndex n}.Infinite := ⊢ {n | IsMaximalPrimeGapIndex n}.Infinite All goals completed! 🐙

Shanks's maximal prime gap conjecture (1964): the maximal prime gap $G(x)$ starting below $x$ satisfies $G(x) \sim (\log x)^2$ as $x \to \infty$ (contradicted by Granville's refinement predicting $\limsup_{n \to \infty} g_n / (\log p_n)^2 \ge 2e^{-\gamma}$).

@[category research open, AMS 11] theorem shanks_maximal_prime_gap_conjecture : (fun x : ℝ => (sup_primeGap x : ℝ)) ~[Filter.atTop] (fun x : ℝ => (Real.log x) ^ 2) := ⊢ (fun x ↦ ↑(sup_primeGap x)) ~[Filter.atTop] fun x ↦ Real.log x ^ 2 All goals completed! 🐙

Record-index consequence of Shanks's conjecture (derived as a corollary of shanks_maximal_prime_gap_conjecture rather than stated directly on Wikipedia): as $n$ runs through indices with IsMaximalPrimeGapIndex n, the ratio $g_n / (\log p_n)^2$ converges to $1$.

@[category research open, AMS 11] theorem shanks_maximal_prime_gap_conjecture.variants.record_indices : Filter.Tendsto (fun k : {n : ℕ // IsMaximalPrimeGapIndex n} => (primeGap k.1 : ℝ) / (Real.log (Nat.nth Nat.Prime k.1 : ℝ)) ^ 2) Filter.atTop (nhds 1) := ⊢ Filter.Tendsto (fun k ↦ ↑(primeGap ↑k) / Real.log ↑(Nat.nth Nat.Prime ↑k) ^ 2) Filter.atTop (nhds 1) All goals completed! 🐙end MaximalPrimeGap