All writing

Research & writing

Getting up to the frontier: what analysing prime gaps actually showed

July 2026. A prime gap is a delta — the distance from one prime to the next — and deltas are how you get at a rate of change. An outsider's week-long run at the frontier of that problem, entirely through AI agents. The average miss on the nth prime fell from 1.4 million to 275, the leftover error turned out to be built from Riemann zeta zeros, and two results had been built already — once in 1970, once in May 2026. What is classical, what is now closed, and what is genuinely still open.

July 2026.

A prime gap is a delta: the distance from one prime to the next. Deltas are how you get at a rate of change. So the question I care about is not "what is the next prime" but "how does the spacing between primes change, and how complicated is that change".

That might end in a formula. It might not. My honest expectation is that it does not — not a clean one. The work is to understand the structure anyway, and to know which parts are structure and which are noise.

This is a getting-up-to-the-frontier attempt. I am not a number theorist. I had a week, a lot of compute, and many AI agents running in parallel. The goal was to find the edge of what is already known and report which side of it each result landed on. Two landed on the wrong side.

No number theory assumed. School calculus is enough.

A gap is a delta

Two rows of boxes, one box per integer, showing the factorisation and smallest prime factor of every number inside the prime gaps 89 to 97 and 139 to 149, with 143 highlighted as the only number whose smallest prime factor exceeds its gap length.
A delta taken apart. Every number inside the gap from 89 to 97 is knocked out by a prime smaller than the gap itself. Between 139 and 149, one number is not: 143 is 11 x 13, and both factors exceed the gap length of 10.

Primes thin out as they get bigger. Near a number p, about one integer in ln(p) is prime, so the average gap near p is roughly ln(p) — about 18 at a hundred million.

That hides two things. There is a smooth trend: the average gap grows slowly and predictably. And there is the wobble: real gaps near a hundred million are 2, or 4, or 34, or a hundred-odd, in an order nobody can predict.

The trend is calculus. The wobble is where the open problems are.

Two questions, not one

A side-by-side diagram with two number lines, the left showing an estimate 275 away from the true prime and the right showing a gap of about 18 to the next prime with a predicted miss of about 8, each annotated with the mathematics that governs it.
Two questions that sound alike and are not. Locating the nth prime leaves a typical miss of 275 across 10 to 100 million. Predicting the next gap leaves a miss of about 8 against a typical gap of about 18. Separate layers.

Add up all the gaps and you get the primes back. So one gap sequence gives two problems, and they behave nothing alike.

The integral questionThe derivative question
AskWhere is the nth prime?How far to the next prime?
What it isThe running total of the gapsOne raw gap
Why that mattersWobbles cancel as they accumulateNothing to cancel against
Best result hereAverage miss of 275 near a hundred million1.2% of the variance explained
StatusAt its practical ceiling, and it is mappedEssentially unpredictable from local data

Most of the confusion about "predicting primes" is these two run together. The first is an integral and it is tractable. The second is the derivative itself and it is close to hopeless. The rest of this keeps them apart.

The integral question: how close you can get

Give me an index — the five-millionth prime, say — and ask for the prime itself. The best estimator here misses by 275 on average, over all 5,096,876 primes between 10 million and 100 million. The fitted curve from my 2024 article, on exactly those primes, misses by 1,384,696.

"Average miss" is mean absolute error: estimate minus true prime, sign dropped, averaged.

Primes in the range2024 article curveBest 2026 estimatorRatio
1,000 – 10,000205.83.4x
10,000 – 100,0007641168x
100,000 – 1 million11,68329409x
1 million – 10 million134,059861,558x
10 million – 100 million1,384,6962755,034x
100 million – 1 billion13,591,19088615,344x

Every band below 100 million is scored on every single prime in it, with no sampling. The 100 million – 1 billion band is scored on every 101st index, because doing it exhaustively costs about seventeen minutes of compute for the same answer.

The last column is the one that matters. Tuning helps most where you tuned and decays as you move away. This does the opposite: the advantage climbs by a factor of four thousand across the table. That is a structural change, not a better fit.

A logarithmic line chart of the average error of four ways of estimating the nth prime across six size ranges from a thousand to a billion; all four errors grow with the size of the prime, but the 2024 formula climbs to 1.4 million while the 500-zero estimate stays at 275.
Average miss by decade, from the 2024 article curve down to the 500-zero estimator.

The knobs came off

The 2024 approach was a shape with three adjustable dials:

p_n ≈ (n·a) · ln(n·b) / ln(y)

Turn them until the curve sits on the primes you can see, and hope it keeps sitting on the ones you cannot.

Fitted knobs do not travel, and this project's own history is the evidence. Tprior — a two-coefficient tail correction fitted only on primes below a million — scores an average miss of 111 on its home range. That is genuinely excellent; an unfitted smooth Riemann curve scores 112 there. Tprior had hit the ceiling of what any smooth curve can do down there. Run it out to the 100 million – 1 billion band, where it was never fitted, and it scores 74,579, against 6,713 for an unfitted truncation of an asymptotic series going back to Cipolla in 1902. Eleven times worse, with nothing tuned on the other side.

An audit found the mechanism. Tprior's two basis functions are nearly the same function over its fit range, giving a condition number around 81,000, so its coefficients trade off against each other rather than recovering anything real. They would only agree with the true asymptotic coefficient around index 2.5 million — thirty times outside the fit range.

The replacement has no adjustable parameters at all. Riemann's R function, inverted numerically, plus a correction built from cosine waves whose frequencies are read straight off a published table of Riemann zeta zeros. Nothing fitted, nothing chosen by looking at the primes.

The difference shows without any mathematics. Divide the mean signed error, where overshoots and undershoots cancel, by the mean absolute error. Wrong in the same direction every time scores 1; honest scatter scores near 0. The 2024 curve scores 1.000 in every band above 10,000 — all five million estimates fall on the same side. The zero-corrected estimator scores 0.017 on the 100 million – 1 billion band.

Systematic bias has become honest noise, and that noise widens roughly like the square root of the prime. The measured exponent is near 0.5 on training and sealed bands alike, and an outside analyst handed the error series with no context measured 0.52.

The leftover error is made of waves

Subtract the smooth curve and what is left looks like static. It is not.

Run a periodogram on it — ordinary frequency analysis — and it has sharp lines. The first six land on the imaginary parts of the first six Riemann zeta zeros, matched against locations written down before the analysis ran, with amplitudes 0.9% to 13.5% from what classical theory predicts. Two controls built to have no such structure matched nothing. Total residual power is 0.04650 against a theoretical 0.04619 — a closed-form constant, not a fitted one, agreeing to 0.7%.

You can also read zeros back out of data you never put in. Subtract the theoretical contribution of the first 50 zeros, re-analyse, and 15 of the next 20 published zeros come back, their locations locked into the run record beforehand. One of the twenty sat outside the fixed scan range by construction; four of the rest are pairs sitting closer together than the analysis can resolve. A known resolution limit, not a failure.

The more striking version: the error series went out as an anonymous two-column CSV — no column names, no units, no mention of primes — to an agent working outside the repository. It reported a square-root envelope and sharp spectral lines that only hold still under logarithmic re-indexing. Projecting its peaks back into the right coordinate located zeta zeros 78 through 86.

Worth saying plainly: this is a re-derivation of classical mathematics, not a discovery. A very good check that the pipeline is sound, and nothing more.

The leftover error from the estimator overlaid with a wave built from published Riemann zeta zeros; the two curves rise and fall together.
The leftover error tracking a wave computed from published zeta zeros, with no fitted parameters.

The derivative question: the next gap resists

Now the other problem. Given a prime, how far to the next one?

On a sealed holdout of 2,479,254 primes that no model touched until scoring, the wheel modulo 210 — which just encodes that the next prime cannot be divisible by 2, 3, 5 or 7 — explains about 1.2% of the variance in the next gap.

Previous gaps. The prime modulo 4. Sign-run streak lengths. All of them together. Not one beat that by more than the noise threshold set in advance; the best margin was 0.0006 against a threshold of 0.0018.

Sieving much deeper — conditioning on divisibility by every odd prime up to 1000 — gets R² to 0.421. That sounds like a breakthrough and is not, and the finding document says so before it says anything else. The theoretical prediction for that model's one parameter, derived with no fitting, matches the fitted value to within 0.5% at every depth. The extra R² is bookkeeping: you removed candidates already known to be composite, and learned nothing about which survivor is prime.

There is a nice confirmation buried in it. At the shallowest setting the model's discrepancy against reality is a factor of 0.660417; the twin prime constant, computed independently elsewhere in the same codebase, is 0.660162. The one place a genuine correlation shows up is exactly where the model has not yet been given the arithmetic that explains it, and it vanishes as soon as it is.

A warning about layers. The same project computed a constant nobody had published: c = 2.74161075, from a 2025 paper of Gafni and Tao that brackets it only between 2.7 and 2.8. That story — including the eleven-digit overclaim a hostile review caught — is the companion article, I computed a number nobody had computed. What matters here is that it does not help predict primes. It governs structure inside gaps, an effect of size roughly ln(p), about 18 at these scales. The error that dominates the integral question is the square-root zero wobble, still worth 275 after 500 zeros of correction and over a thousand before them. Right quantity, wrong layer.

What is classical, and what is only new to me

This section decides whether the rest is worth anything, so I will lead with the embarrassing part.

The project rebuilt something that already existed. Twice.

The zero-correction machinery is entirely classical. Riemann wrote the explicit formula down in 1859 and von Mangoldt proved it in 1895; the numerical version was done in 1970. Two full days of earlier work here turned out to be a careful re-derivation of that 1970 paper.

Worse and much more recent: mid-run, an agent checking prior art found that the estimator used here is the first Newton step of a routine that has been shipping in the primecount tool since May 2026. Not similar — algebraically identical, term for term, verified against the C++ source and pinned in a test. That tool uses a hardcoded table of 512 zero ordinates; this project used 500. Nobody set out to reimplement it; it fell out of doing the obvious thing.

So nothing above is new mathematics. The measurements are new, the discipline around them is the point, and the machinery is a century and a half old.

That is not a counsel of despair, and there is one place this project went looking that it can speak to from its own data.

Maximal gaps, and how far the conjectures sit from anything measured. Cramér's model says the largest gap near a prime p grows like ln(p)², with the leading constant tending to 1. Granville argues that constant must reach at least 2e^(−γ), about 1.1229. So this project built the table: all 85 known record gaps, each one re-verified end to end — both endpoints tested for primality, every integer between them confirmed composite.

Across all 85, the largest ratio ever observed is 0.9206, at the gap of 1,132 starting at 1,693,182,318,746,371 — a record set in 1999 and still standing. Both conjectures sit above every observation ever recorded. On its own two computed bands this project measured 0.63 and 0.71, and neither number bears on the dispute; the scales where it becomes decidable are far past anything a laptop reaches.

That is the honest shape of the frontier from here: the machinery is old, one genuinely open number got computed, and the rest of the map is still to be drawn. Where else the open ground lies is a question for the next run, not a claim this one has earned.

The pattern is the same wherever it did work. "Predict prime numbers" is not a research question, but rather a fun experiment in chaos. "Compute the thing these two authors said they could only bracket" is one — and it is exactly what an outsider with good computational hygiene can do, because the theorists who stated it had no interest in spending a week on numerics and computation.

Three directions now closed

Each closure is worth more than a marginal improvement, because it stops the next person spending a week.

Route triedThe number that closed it
More terms in the classical asymptotic seriesTruncation error falls S2 → S3 → S4 as 18,924 → 4,196 → 1,416, but a fixed +8,840 bias means S4 is the better approximation and scores worse. S3's win is sign luck; an S5 term would not help.
Mining local patterns for the next gapBest candidate margin 0.0006 against a threshold of 0.0018 set in advance, on the sealed holdout above.
Evaluating the zero correction at a better pointAn oracle that cheats — it evaluates at the true answer, so it bounds any possible phase fix — moved the average miss by 0.045 units out of 275, closing 0.9% of a 1.82% discrepancy and missing the pre-registered failure threshold by a factor of 120.
Reweighting the zero sum with a taper22 alternative windows across six truncation depths, 132 configurations, including six fitted families given up to 1,000 free parameters and frozen before scoring. Not one beat plain rectangular on held-out data; the best was 0.72% worse, and a Fejér window costs 23%.

Two of those deserve a sentence of explanation.

A phase offset costs variance at second order rather than first, which is why an intuition about a 2% amplitude loss turned out to be a 0.02% variance loss.

And a window suppresses leakage caused by estimation error. Here the zeros are known exactly, from a published table, so there is no estimation error to suppress — only signal to discard. The taper penalty grows with the number of zeros, which is the signature of exactly that. Given complete freedom to reweight, least squares declined to reweight.

A dense cloud of nearly 100,000 points showing the signed error of the 500-zeta-zero estimator against the prime on a logarithmic axis, symmetric about zero and fanning out decade by decade inside a shaded square-root envelope.
What would not shrink. The cloud stays centred on zero from ten thousand to a billion, so the estimate is not drifting, it is spreading - and the spread widens only as fast as the square root of the prime.

How this was done: tooling as method

The claim is not that AI solved anything about primes. It is narrower and more useful: this kind of tooling lets one person reach the frontier of a field fast enough to find out what is genuinely unknown there.

Over a week that meant sieving billions of integers and running many agents in parallel. Claude Fable 5 set direction, chose what to attack next, reviewed every result and wrote the interpretation. Claude Opus 5 did infrastructure, creative ideation and adversarial review. Claude Sonnet 5 did implementation and the repetitive work — runs, sweeps, harness.

Four details carried most of the weight.

Self-contained briefs, written to be executable cold. An agent that comes back to ask has already cost you the round trip.

Attack, not check. The review instruction is "break this, across these named angles".

Novelty checks before investing, not after. Learned the hard way, twice, as above.

Pre-registration and sealed holdouts. Every prediction written with its thresholds and failure conditions before the run; holdout data no model could see until scoring. Several predictions came back wrong and are recorded as wrong rather than quietly revised. One predicted that a fitted parameter would exceed its theoretical counterpart by a growing margin; the ratio was flat within noise, and the finding says so in the same breath as the result it supports.

And now the part that makes the rest credible: the agents produced several confident wrong answers.

A hostile reviewer caught an eleven-digit overclaim on the constant — the published value was a partial sum whose remaining terms had been measured and then never added on. Another agent then caught an error in that reviewer's own correction: the uncertainty range it proposed excluded both its own proved lower bound and its own best estimate. In a separate sprint an explanation for a curvature anomaly was recorded internally and retracted the same day, when a brute-force check found the "exact fact" it rested on was false at a five-line counterexample.

None of that argues against using agents. It argues that the adversarial structure, not the individual model, is what makes the output trustworthy. Every result that survived here survived something actively trying to kill it.

The work was carried out by AI agents under my direction, and this article was drafted the same way. The repository holds a written finding for each experiment with its question, protocol, numbers and caveats, plus the pre-registrations and the run records — including the ones that came back negative.

What is left is the residual

On the integral question the estimator is at its practical ceiling, and the ceiling is mapped rather than mysterious. More accuracy costs more zeros on a known square-root schedule, and past roughly 150 zeros each additional one buys less than a single unit of average miss. The two ways round that, above, were measured shut rather than guessed at — which is the difference between a wall and a mystery.

And close is not solved. Even with 50 zeros of correction and full wheel arithmetic, the estimator names the exact next prime 0.26% of the time on the 10 million – 100 million band. What it does well is rank: the true prime lands in a checkable top-100 shortlist a quarter of the time on that band, and 99.7% of the time below a million. Good at narrowing the field, bad at naming the answer — and the distance between those is the honest measure of how far "solved" still is.

So here is where we are at the moment. Not with a function. With a residual — what is left once the best function we have has taken out everything it can.

That residual has no systematic bias left in it. It widens like the square root of the prime, exactly as the Riemann Hypothesis says it should. Its structure is a sum of waves whose frequencies were written down in 1859. And all of it is error accounting on primes below one billion, on an already-sieved dataset; none of it is a claim about primes beyond that.

That is the object. Understanding its rate of change is the work, and the work is not finished. To me (Jack writing) it looks like a particle wave, but I am not sure how to test this so I will keep experimenting.

A scatter of primes from ten thousand to a billion showing the signed error of the current estimate; the cloud falls on both sides of zero and fans out slowly, from an average miss of 11 at the small end to 886 at the large end.
The residual of the errors now, with the best function we have: no systematic bias left, widening slowly with scale.