The old world we once knew is no more. Modulo results of Gödel, we live in the wildest of Hilbert's dream worlds and are sure to slide further into even more fantastical happenings. Perhaps the world we will soon inhabit should not be thought of as one of Hilbert's dreams but rather Hilbert's hero dose ayahuasca trip.
RH is Dead [Alp26]; what lies ahead for mathematics I cannot claim to know. The two things that I can confidently say at this point are general pieces of wisdom that apply outside of mathematics alone:
- Things will only get weirder
- The only way out is through
I decided to take the fall of GRH as an opportunity to do some vibe-math. I originally set out wanting to formalize correctness of the deterministic Miller–Rabin test with a polynomial (in bits) number of bases which was proven as an implication of GRH [Mil76, Bac90] and is now the deterministic primality test with the best proven running time. In the process of doing so over the weekend I decided to set Claude loose on some more open ended problems it saw potential in. Seeing the progress that Claude made here I decided to point it at a more well known problem where GRH moved the needle a bit but still needed serious work to be done, the Erdős–Odlyzko–Sárközy conjecture. The rest of the article will outline what Claude accomplished and how it compares to previous results. To be clear I had very little to no mathematical involvement in this process whatsoever.
Headline result 1 (deterministic primality testing). Under GRH (and hence unconditionally, via Alpöge's Lean proof [Alp26]), every odd composite
$n \geq 10^{11}$ has a Miller–Rabin witness below $0.7(\ln n)^2$, and below $0.642(\ln n)^2$ for all
sufficiently large $n$, improving Bach's 1990 constant of $2$ [Bac90] and the best previously published
constant of $1$ [LLS15], with the entire proof machine-checked in Lean (theorems witness_70 and
witness_eventually in the
primality repository).
Headline result 2 (the Erdős–Odlyzko–Sárközy conjecture). A separate problem: the conjecture
[EOS87] that for all sufficiently large $m$, every residue $a$ coprime to $m$ is a product $pq$ of two primes $p, q \le m$ modulo $m$
remains open, even under GRH. As partial progress, under GRH every such $a$ is a product $pqs$ of
three primes with $p, q \le m$ and $s \ll (\ln m)^2(\ln\ln m)^2$. Banks and Shparlinski [BS26], a month
earlier, stated $(\ln m)^4$, and their results implicitly give $(\ln m)^3 \ln\ln m$; this improves
both. This is formalized in Lean
(coveredBy_three_primes in the
EOS repository),
but from a standard explicit consequence of GRH taken as a hypothesis, not yet from GRH itself, and its
proof is a refinement of known techniques rather than a new idea.
Free-range Claude#
I did not guide the mathematics. Beyond choosing the two problems (deterministic Miller–Rabin and its dependence on GRH, and the Erdős–Odlyzko–Sárközy conjecture) and a few scoping decisions, the ideas and the proofs below are Claude's. I have not yet had time to digest the mathematics myself. All of this work was done in under two days. What gives me confidence is that every headline result is machine-checked in Lean (for the EOS work, relative to named hypotheses whose truth was checked on paper). Having watched Claude's formalization capabilities progress the past months, I feel quite good that the formalizations it produced for these problems are semantically faithful.
The Miller–Rabin test#
The starting point is Fermat's little theorem: if $p$ is prime and $p \nmid a$, then $a^{p-1} \equiv 1 \pmod p$. Read backwards, it is a test for compositeness. If $a^{n-1} \not\equiv 1 \pmod n$ for some $a$, then $n$ is composite, even though we never found a factor.
The trouble is that the converse fails, and fails badly. The Carmichael numbers pass the Fermat check for every base coprime to them. The smallest is $561 = 3 \cdot 11 \cdot 17$: for instance $2^{560} \equiv 1 \pmod{561}$, so base 2 calls 561 prime.
Miller–Rabin repairs this with one more fact about primes. Modulo a prime $p$, the only square roots of $1$ are $\pm 1$: if $x^2 \equiv 1$, then $p$ divides $(x - 1)(x + 1)$, so it divides one of the factors. Modulo a composite, $1$ can have other square roots as well. For odd $n$ with $k$ distinct prime factors, $1$ has $2^k$ square roots mod $n$, so mod $561 = 3 \cdot 11 \cdot 17$ it has eight. One of them is $67$, since $67^2 = 4489 = 8 \cdot 561 + 1$.
To use this, let $n > 2$ be odd and write $n - 1 = 2^s d$ with $d$ odd. Instead of computing $a^{n-1}$ in one go, compute $a^d$ and square it $s$ times: $$a^d,\ a^{2d},\ a^{4d},\ \dots,\ a^{2^s d} = a^{n-1} \pmod n.$$ If $n$ is prime, Fermat says this sequence ends at $1$. Look at the first $1$ in it. Either the sequence starts at $1$, or the entry just before the first $1$ is a square root of $1$ that is not $1$, so it must be $-1$. That gives a condition every prime satisfies, and failing it proves $n$ composite:
Definition 1 (strong witness). An integer $1 < a < n$ is a strong witness for $n$ if $$a^d \not\equiv 1 \pmod n \quad\text{and}\quad a^{2^r d} \not\equiv -1 \pmod n \ \text{ for all } 0 \le r < s.$$ If $n$ is composite and $a$ is not a strong witness, $a$ is a strong liar.
A prime has no strong witnesses, so a single witness is a proof that $n$ is composite. There are two ways for $a$ to be one. The sequence can end at something other than $1$, which means $a$ already fails Fermat. Or it can reach $1$ from a square root of $1$ other than $\pm 1$, which is exactly the case Fermat misses. Take 561 with $a = 2$. Here $560 = 2^4 \cdot 35$, and the sequence is $263, 166, 67, 1, 1$. It reaches $1$ from $67$, so base 2 is a strong witness for 561, though it passes the Fermat check. As a bonus, $\gcd(67 - 1, 561) = 33$ is a factor.
One round of the test checks a single base. It costs one modular exponentiation and at most $s - 1$ squarings, so $O(\log n)$ multiplications mod $n$:
def passes_round(n, a):
# True if a is NOT a strong witness for odd n > 2
d, s = n - 1, 0
while d % 2 == 0:
d, s = d // 2, s + 1
x = pow(a, d, n)
if x == 1 or x == n - 1:
return True
for _ in range(s - 1):
x = x * x % n
if x == n - 1:
return True
return False
Everything now depends on how the bases are chosen. Rabin's version [Rab80] picks them at random. That works because strong liars are rare: for odd composite $n$, at most a quarter of the bases $1 \le a \le n - 1$ are strong liars.1 So $k$ random rounds mistake a composite for a prime with probability at most $4^{-k}$. Forty rounds put the error below $10^{-24}$, which is why this is the primality test in practice.
But a probability is not a proof. A composite number passing forty rounds is astronomically unlikely, yet nothing rules it out. Miller's version [Mil76] asks for something stronger: a fixed, short list of bases guaranteed to contain a witness for every odd composite. Check them all, and a pass becomes a proof of primality. Whether such a list exists, and how long it has to be, is where GRH comes in.
What GRH buys#
The quarter bound of Monier and Rabin [Mon80, Rab80] says witnesses are common, but not where they are. To make the test deterministic we need to know that a witness always appears among the first few bases. The structure that makes this tractable is that, for odd composite $n$, the strong liars all lie in a proper subgroup $H$ of the units $G = (\mathbb{Z}/n\mathbb{Z})^\times$: a subset that contains $1$, is closed under multiplication mod $n$, and is not all of $G$. So every base $a$ that is not an element of $H$ is a witness, and it is enough to show that some small $a$ lies in $G$ but outside $H$. (A base sharing a factor with $n$ is not a unit at all, and is trivially a witness.)
Membership in $H$ can be tested with a Dirichlet character: a map $\chi$ from $G$ to the nonzero complex numbers with $\chi(ab) = \chi(a)\chi(b)$. Because $H$ is a proper subgroup, there is a character $\chi$ that equals $1$ on every element of $H$ but is not $1$ everywhere. Then any $a$ with $\chi(a) \ne 1$ is not in $H$, and so is a witness.
The question becomes: how long can a character that is not identically $1$ keep taking the value $1$? Since $\chi$ is multiplicative, it is determined by its values at the primes: if $\chi(p) = 1$ for every prime $p < X$, then $\chi(a) = 1$ for every $a < X$, because $a$ is a product of primes below $X$. So the first $a$ with $\chi(a) \ne 1$ is always a prime, and the question is really about the values of $\chi$ at primes. That is also where we have analytic control, and where GRH2 comes in. Think of the values $\chi(2), \chi(3), \chi(5), \dots$ at the primes as the steps of a walk on the unit circle. GRH says, in effect, that these steps cancel about as well as random steps would: added up over the primes below $X$ (weighted by $\ln p$), they total only about $\sqrt{X}\,\ln n$ instead of $X$. But if $\chi(a) = 1$ for every $a < X$, there is no cancellation at all below $X$: every step is $+1$ and the total is about $X$. Something of size $X$ can only be as small as $\sqrt{X}\,\ln n$ if $X$ is at most a constant times $(\ln n)^2$. So some base below a constant times $(\ln n)^2$ has $\chi(a) \ne 1$, and it is a witness.
Theorem 2 (Bach 1990, after Miller 1976 [Bac90, Mil76]). Assume GRH. Every odd composite $n$ has a strong witness $a$ with
The constant $2$ is what the first half of this post is about. Miller only showed $O((\ln n)^2)$ [Mil76]; Bach made it explicit [Bac90]. Lamzouri, Li and Soundararajan lowered it to $1$ in 2015 [LLS15], and the results below push it further.
Results: primality testing and non-residues#
Every result below is proved in Lean, using Alpöge's Lean proof of GRH [Alp26] in the proof, except where noted. The first goal was the known result: deterministic Miller–Rabin with Lamzouri, Li and Soundararajan's constant $1$ [LLS15], i.e. about $(\ln n)^2$ bases for every $n$, together with deterministic Tonelli–Shanks for square roots mod $p$. From there Claude pushed the constants below $1$.
Two ideas carry most of the improvement. For Miller–Rabin, the strong liars of an odd composite $n \ne 9$ lie in a subgroup of index at least $4$, not just $2$, so one can average over four characters at once instead of one. For a single character, a family of smoothing weights whose sum over the zeros of $L(s,\chi)$ is an exact identity makes every constant explicit, and pushing that family to its limit beats the best published asymptotic constant. Each entry below is the constant $c$ in "some $a < c(\ln n)^2$ works".
| Problem | Prior best (published) | This work (Lean-verified) |
|---|---|---|
| Miller–Rabin witness, explicit | $2$ for all $n$ [Bac90]; $1$ for $n \ge 3000$ [LLS15] | $1$ for all $n$; $0.7$ for $n \ge 10^{11}$; $0.65$ for $n \ge 10^{13}$ |
| Miller–Rabin witness, asymptotic | $1 + o(1)$ [Bac90] | any $c > 0.6417$ |
| Least character non-residue, explicit | $1$ for $n \ge 3000$ [LLS15] | $0.8$ for $n \ge 10^{13}$; $0.78$ for $n \ge 10^{14}$ |
| Least character non-residue, asymptotic | $0.7615$ [CMQR24] | any $c > 0.760753$ |
| Limit of the CMQR method | $\ge 0.7596$ [CMQR24] | $\ge 0.760748$ (with the record above, the limit is in $[0.760748,\ 0.760753]$) |
| Non-residue search for Tonelli–Shanks | $1$ [LLS15] | $1$, now formalized |
"Least character non-residue" is the least $a$ with $\chi(a) \ne 1$ for a single character $\chi \ne 1$ mod $n$; a base sharing a factor with $n$ counts, since then $\chi(a) = 0$. For a prime modulus $p$ that cannot happen below $p$, so for the quadratic character mod $p$ this is exactly the least quadratic non-residue (for composite $n$ with a small prime factor the bound is trivial, that prime being a witness), the setting of the 0.7615 record [CMQR24]. The limit of the CMQR method: the lower end $0.760748$ is a Lean theorem about their extremal problem; the upper end comes from Claude's record, whose test function is an admissible choice in that problem, a step checked on paper but not in Lean. The asymptotic constants come with no explicit starting point, while the explicit ones hold for every $n$ past the stated bound. The full list, with the exact Lean statements, is in the repository README.
Timing#
Back to the problem we started with: deciding whether $n$ is prime, deterministically, by running Miller–Rabin on every base below $c\,(\ln n)^2$. The witness bounds above say how small $c$ can be while still guaranteeing that a composite $n$ is caught; here is what that costs. Each base costs one modular exponentiation plus at most $s - 1$ squarings, so $O(\log n)$ multiplications mod $n$, and there are $c\,(\ln n)^2$ bases. With $M(b)$ the cost of multiplying two $b$-bit numbers, the deterministic test runs in
which is $(\log n)^{4 + o(1)}$ bit operations with fast multiplication. The constant $c$ does not change the exponent, but it is the whole multiplier in front: halving $c$ halves the work. Here is the number of bases each constant requires:
| Bits of $n$ | Bach ($c = 2$) | LLS ($c = 1$) | This work ($c = 0.65$) |
|---|---|---|---|
| 64 | 3,934 | 1,966 | 1,278 |
| 256 | 62,973 | 31,486 | 20,465 |
| 1024 | 1,007,584 | 503,791 | 327,464 |
| 4096 | 16,121,360 | 8,060,679 | 5,239,441 |
That is 35% fewer bases than $c = 1$ and about two thirds fewer than Bach's bound.3 It is still the price of a proof rather than a probability: the randomized test from earlier uses forty bases at every size, so at 4096 bits the deterministic test does over a hundred thousand times more work. Miller–Rabin with GRH is the deterministic test with the best proven running time, not the fastest one in practice.
Results: the Erdős–Odlyzko–Sárközy conjecture#
In a separate session I pointed Claude at a famous open problem. Erdős, Odlyzko and Sárközy conjectured [EOS87] that for every large $m$, every residue coprime to $m$ is a product $pq$ of two primes $p, q \le m$ modulo $m$. It is open even under GRH, and it is still open. Claude's main partial result is a three-prime version with a very small third prime, improving on a paper posted a month earlier [BS26]. Along the way it sharpened the known explanation of why the problem is hard [Ban26], and checked the conjecture numerically for every $m$ from $402$ to $10^6$ ($m = 401$ is the largest known failure).
| Result (all large $m$, every residue $a$ coprime to $m$) | Prior best | Assumes |
|---|---|---|
| $a \equiv pqs$, primes with $p, q \le m$ and $s \ll (\ln m)^2(\ln\ln m)^2$ | $s \ll (\ln m)^3 \ln\ln m$, implicit in [BS26] (stated: $(\ln m)^4$)4 | GRH* |
| $a \equiv pq$ with $p, q \le K m (\ln m)^2$ | $p, q \le C m (\ln m)^4$ for prime $m$ [EOS87] | GRH* |
| $a \equiv pq$ with $p \le m$ and $q \le K m (\ln m)^3$ | not stated; about $m(\ln m)^5$ follows from classical bounds | GRH* |
| $a \equiv ps$ with $p \le m$ prime, $s \le 56\, m \ln m$ squarefree | $s < m$ is known [Yau19] | nothing |
*Unlike the primality results, these are not derived from GRH itself in Lean. They assume standard estimates that are widely accepted consequences of GRH, without formalizing that step.5
An independent Claude instance, acting as referee, found the first result correct and apparently new, but an easy refinement by a standard argument; the next two are new statements with routine proofs.
What's next#
Since I did not drive the mathematics here I won't opine on what would be a suitable followup to this work. Instead I simply make the observation that Claude was able to autonomously produce modest new results quickly: mostly improvements of known bounds by standard techniques, plus a clear map of why the EOS problem is hard. It is my suspicion that much of the gains Claude made in the Miller–Rabin theorem were mostly from tightening up existing analytic arguments, and that in the EOS work neither the diagnosis of why the problem is hard (which is Banks's [Ban26]) nor the techniques behind the partial results are new. What Claude added is a sharper form of that diagnosis and some modest improvements. The one concrete next step is formalizing the GRH implications that the EOS work uses directly. I will have Claude push on this passively. I will not claim in vain to know what is next for mathematics or even for these problems. I leave you only with some github links.
Source code: the Primality Lean source and the EOS Lean source.
References#
- [Alp26]L. Alpöge. Announcement of a Lean proof of the Riemann Hypothesis and GRH for Dirichlet $L$-functions (November 20, 2026). alpo.ge/remark.pdf; Lean source published at alpo.ge (
lean.tar.gz.part01–part14), also browsable via the unofficial GitHub mirror CocoSgt/riemann-hypothesis-lean, which is the copy built and checked for this post. - [Bac90]E. Bach. Explicit bounds for primality testing and related problems. Math. Comp. 55 (1990), 355–380.
- [Ban26]W. D. Banks. Products of two elements of Granville's random model in residue classes. arXiv:2609.37434 (September 2026).
- [BS26]W. Banks, I. E. Shparlinski. On the Erdős–Odlyzko–Sárközy conjecture for prime-power moduli. arXiv:2610.19597 (October 2026).
- [CMQR24]E. Carneiro, M. B. Milinovich, E. Quesada-Herrera, A. P. Ramos. Fourier optimization, the least quadratic non-residue, and the least prime in an arithmetic progression. arXiv:2404.08380 (2024).
- [EOS87]P. Erdős, A. M. Odlyzko, A. Sárközy. On the residues of products of prime numbers. Period. Math. Hungar. 18 (1987), 229–239.
- [LLS15]Y. Lamzouri, X. Li, K. Soundararajan. Conditional bounds for the least quadratic non-residue and related problems. Math. Comp. 84 (2015), 2391–2412; corrigendum Math. Comp. 86 (2017). arXiv:1309.3595.
- [Mil76]G. L. Miller. Riemann's hypothesis and tests for primality. J. Comput. System Sci. 13 (1976), 300–317.
- [Mon80]L. Monier. Evaluation and comparison of two efficient probabilistic primality testing algorithms. Theoret. Comput. Sci. 12 (1980), 97–108.
- [Rab80]M. O. Rabin. Probabilistic algorithm for testing primality. J. Number Theory 12 (1980), 128–138.
- [Yau19]K. H. Yau. On products of primes and square-free integers in arithmetic progressions. arXiv:1907.06016 (2019).
Proved independently by Monier and by Rabin in 1980 [Mon80, Rab80]. The bound is sharp: mod 9 the strong liars among $1 \le a \le 8$ are $1$ and $8$, exactly a quarter. ↩
Here GRH means: every zero of every Dirichlet $L$-function $L(s,\chi)$, including $\zeta(s)$, with $0 < \mathrm{Re}\, s < 1$ lies on the line $\mathrm{Re}\, s = 1/2$. In Lean this is the proposition
DirichletLZerosOnLine. ↩The counts are exact for the formalized algorithm, which tests every base $2 \le a < \min\big(n, \lceil c \cdot 0.480454\,(\lfloor \log_2 n \rfloor + 1)^2 \rceil\big)$, about $c\,(\ln n)^2$ (the factor $0.480454$ is a rational upper bound for $(\ln 2)^2$, which converts $\log_2$ to $\ln$). The constant $0.65$ is proved for $n \ge 10^{13}$, roughly 44 bits, so it applies to every row. ↩
Theorem 1.4 of [BS26] combined with a pigeonhole argument already gives $s \ll (\ln m)^3 \ln\ln m$, although they do not state it. The novelty check behind "new" was a targeted literature search without access to MathSciNet or zbMATH. ↩
The GRH input is
GRHSmoothBound, an explicit bound for prime sums twisted by Dirichlet characters; deriving it from GRH in Lean is in progress. Other results in the EOS repository assume published sieve estimates (TypeISifted,RoughCounts), and its conditional reductions assume open hypotheses (TypeIHalf,H4). ↩