TL;DR
- Machine learnability can serve as a measure of order by showing how well a model learns patterns in sequences that look random.
- We trained and cross-tested an image model on prime-number regions represented as Ulam spirals up to 500 million; raw accuracy rose in the largest region mostly because the model identified composites.
- Learnable prime patterns declined most sharply between 25 and 50 million.
Key Takeaways
- The core methodological move is turning “is this pattern learnable” into a measurable, comparable quantity by controlling for confounds (image size, prime density, class imbalance) rather than reporting one model’s raw accuracy. That control is what lets the paper claim a real difference in learnable order between regions, rather than an artefact of easier or harder base rates.

(Note: this is a reduced-jargon/increased fun version of a paper published on arXiv (arXiv:2509.18103), summarised in our arXiv companion post on the Ulam spiral study. Thanks go to my co-authors: Michael Joedhitya, Adith Ramdas, Surender Suresh Kumar, Adarsh Singh Chauhan, Akira Rafhael, Wang Mingshu and Nordine Lotfi.)
Is maths invented or discovered?
Most non-mathematicians will say it is discovered. Here is one thing, and there is another thing, and now we have two things: tada. On the other hand, there is a small subset of theorists (such as Leopold Kronecker) who argue that while much of it is not true, it is nevertheless often useful: Negative numbers do not exist in nature, but they make the sums we need to parse nature a lot easier. There’s no such thing as the square root of a negative number but pretending there is provides us with a handy drawer in which to store multi-dimensional values and thus imaginary numbers were born.

This is the line taken by the publishers of the Nature journals, who, when they are asked why there is no Nature Mathematics, patiently explain that it is because maths is not a science, being a matter of logic rather than empirical investigation.
The problem with this clear division comes when the numbers start doing things that they weren’t designed to do, or, conversely, don’t do what you would expect them to: when deterministic processes yield seemingly random outputs, or when phenomena predicted by maths coincidentally pop up in physics (or vice versa). These cases are interesting because they seem to imply that both maths and physics are something like images projected onto the surface of a unified underlying structure: the manifold of the possible[1]. Invisible itself, it is the rule set that determines the possible rule sets, meaning that we can only guess at its shape by looking at the ways in which observable rules converge or diverge.
If you’re a statistician this is great insofar as it drags numbers back into the empirical world, putting them within reach of probabilistic analysis tools such as AI models. If they are simply a formal language built for expressing logic operations precisely, there’s not a lot we can do with them. If they’re shadows on the wall of nature, it’s perfectly reasonable to treat them as a dataset like any other, and while models aren’t necessarily great at solving equations or proving identities, they’re superlative when it comes to spotting patterns in the results once they’ve been found[2].
What Is Machine Learnability as a Measure of Order?
In this research, machine learnability means how well a model can learn to reconstruct a sequence from examples of it. We train the same model, in the same way, on different parts of a sequence and compare how well each version performs on data it has not seen.
That comparison is the measurement. If an identical model does better on one region than another, the first region contains more structure the model can use. Machine learnability as a measure of order turns “how ordered is this?” into an experimental question with a number attached.
It is a different question from whether a sequence is deterministic or random. The primes are fully deterministic, yet they look statistically random at small scales. Learnability asks something narrower and more practical: how much of that determinism is visible as a learnable pattern at a given scale.
Can Machine Learning Detect Order in Apparently Random Sequences?
One example of this would be the patterns in prime numbers, which have been tantalising mathematicians for centuries. Prime numbers aren’t predictable but do crop up at a pretty predictable rate.

Give me a number and I can tell you roughly how many primes there will be in the vicinity, but not easily predict with any reliability whether the next one will be two, three, four or five numbers away.
That’s not all, however. There are various ideas in number theory that suggest that not only do prime numbers become less frequent the further you go, they also settle into more predictable patterns, with small differences having big ripple effects near zero that gradually even out as you head further out. The theories suggest that this is not a product of true order, but rather because their irregularities obey reliable statistical laws that only become apparent at very high numbers.
Unlike physical systems, primes don’t “evolve” in time, but as you move along the number line, you see a statistical equilibrium emerge between order (the global density law, equidistribution in progressions) and disorder (random-looking gaps). Density measures like these describe the averages well, but they say little about local structure in one stretch of an aperiodic sequence.
We wanted to investigate this using AI models, not with the aim of predicting next primes accurately, but to try to isolate the underlying patterns and non-linearities that create this infuriating quasi-order.
How Does the Ulam Spiral Help Measure Prime Number Order?
To do this we started by arranging the numbers in an Ulam spiral format: a spiral representation in which primes are coded in one colour and composites another.

It produces intriguing suggestions of order to even a casual human observer:

If we run a fast Fourier transform on the image to give us a broad idea of the noise-to-signal ratio, it’s even more impressive, producing a beautifully ordered fractal snowflake that hints seductively at multiple overlapping signals/rulesets in the original that would be a great explanation for why accurate predictions are so hard to make. (If you want a basic guide to interpreting these patterns, there’s an introduction to the Fourier transform.)

This Ulam spiral format is definitely the layout in which humans find patterns easiest to identify, so the team reasoned that an in-painting model (an AI that tries to guess what is in a masked-out part of an image when given the remainder) would probably be even better. The model’s task is to fill in the hidden pixels of each block: to say which of the masked numbers are prime.

We built spirals for seven regions up to 500 million, because the theories above predict that prime patterns change as the numbers grow.
How Was Machine Learnability Tested Across Different Prime Number Regions?
We trained one simple model on blocks from seven regions of the Ulam spiral, tested every model on every region, and compared the results. The regions run from below 25 million to about 500 million, so each one samples the primes at a different scale.
Machine learnability as a measure of order only works if everything else stays fixed: the same architecture, the same block size and the same training split. Then a difference in performance points to the data, not the setup. We also repeated each run three times and resampled the results to put confidence intervals on every metric. A gap between regions has to clear that noise before it counts.
What Data Was Used for Training?
To train our model we generated black-and-white Ulam spiral images encoding consecutive integer sets:
- n < 25,010,001 (5001×5001 pixels),
- 25,010,001 ≤ n < 50,027,329 (7073×7073 pixels),
- 50,027,329 ≤ n < 100,020,001 (10,001×10,001 pixels),
- 100,020,001 ≤ n < 200,024,449 (14,143×14,143 pixels),
- 200,024,449 ≤ n < 300,017,041 (17,321×17,321 pixels),
- 300,020,041 ≤ n < 400,040,001 (20,001×20,001 pixels), and
- 400,040,001 ≤ n < 500,014,321 (22,361×22,361 pixels).
Each image was chopped into 350 non-overlapping blocks of 256×256 pixels each (a reasonable size to favour the learning of both local and global patterns). Each set of blocks was divided into training (300) and validation (50) sets.

How Were the Different Regions Compared?
We used these to train a two-dimensional U-Net with a ResNet-34 encoder pre-initialised on ImageNet. It’s a pretty basic model architecture, but the goal here was easy replication rather than high performance, given that our broader aim was to study the learnability of the patterns rather than to achieve the best possible predictions.
The same basic model was trained on each spiral and subsequently evaluated across all test sets. So the 25m model was tested on the 25m test set, but also on the 50m, 100m, 200m and other sets. Comparative performance was used as a proxy for the learnability of prime patterns within each numerical range.
To confirm broad trends and minimise chaotic fluctuations at the individual model level, the process was repeated three times and an average taken. To account for the limited dataset size, we employed resampling with n = 10,000 replicates and computed confidence intervals for all reported metrics, for the same reason any AI benchmark needs a known resolution before its gaps can be trusted. Likewise, to control for the differing proportion of primes in lower and higher areas of the spiral, we checked the threshold binarisation model against a top-k binarisation model[3].
For each test, the model produced five outputs: (i) the masked input, (ii) the in-painting reconstruction, (iii) the pixel-wise error map, (iv) the ground-truth image, and (v) summary statistics.

Which Machine Learning Metrics Were Measured?
If one attempts to maximise for raw accuracy on such a task, a problem immediately appears. Because any given image is around 5-6% white pixels and 94-95% black, a model that simply predicts nothing but black pixels will already be scoring almost 100% accuracy. It will most likely settle for this, since any attempt to do better will certainly result in worse scores, at least initially. Choosing the metric shapes the result. We met the same observer effect in AI benchmarking when testing a self-improving agent.
In place of this, we focused on maximising for mean class accuracy: a metric that overweights the white score to make it seem as if white pixels made up half of the total, rather than just a tiny fraction. We also tracked precision (what proportion of pixels predicted to be [colour] were actually [colour]), recall (what proportion of [colour] pixels were predicted to be [colour]) and F1 (precision times recall over precision plus recall, times two) for primes and composites separately.

What Did the Machine Learning Experiment Find?
In pure accuracy terms, models trained on blocks from the region around 500 million performed better than models trained on the region below 25 million. On that measure alone, the higher-number region contains more machine-learnable order.
You can see the dramatic difference the choice of metric makes in the tables below. Here the columns show the accuracy that a model trained around a particular region of the spiral (25m, 50m etc.) achieved when attempting to in-paint images taken from both the same and different regions (red = more accurate).


In other words, the model looks like it’s better at predicting primes at low numbers, and composites at high numbers.
Decomposed into precision and recall, the intuition is confirmed. The model starts out predicting primes, but shifts towards predicting composites, identifying primes only by elimination.






But there’s something else going on here too. There’s a clear step-change between the 25m set and the others. This was also visible in the training records.

Why Does Higher Learnability Suggest Greater Order?
This is the logic of machine learnability as a measure of order: a model that learns better from one region than another has found more usable structure there. That is the observed result. Why the structure is there is a separate question, and the answer comes from number theory rather than from the model.
The first check is whether the model learned anything beyond prime density. Given the known prime density at each region, it is possible to work out what scores a model would achieve if it knew the rough proportion of black-to-white pixels in a given region, but had no knowledge of pixel patterns.


A model that simply guessed based on white:black ratios would achieve similar black and overall scores to ours, but it would score significantly lower on white metrics. Our model shows a degree of pattern-awareness.
It also becomes possible to compare the rates at which prime prevalence and prime pattern learnability diminish.

When we do this we observe that the learnability of the prime patterns diminishes much faster than the prime density, with the biggest drop being between 25m and 50m.
What Does This Tell Us About Prime Number Patterns?
So what should we conclude from this?
1. Primality is not simply an absence of compositeness. It’s something else.
If this were the case one would expect the prime and composite F1 tables to be more or less identical. Instead they are mirror images of one another. The model is not simply learning white vs. non-white or black vs. non-black; it perceives white and black as separate categories with different sets of characteristics. This would fit with the idea that each is the product of multiple overlapping deterministic filters.
2. The importance of prime patterns declines faster than you’d expect.
When we started on this, we were prepared for the possibility that the learnable quasi-order in the primes may diminish so slowly that it would not be detectable at the scales to which our computing power grants us easy access. That is, the patterns would only be visible in spiral generations requiring unfeasible amounts of compute. This is not the case: a major part of the drop happens below 50m.
Both findings fit number theory conjectures in which averages come to dominate prime number patterns at higher magnitudes while local randomness regularises. The experiment measures learnability; the link to those conjectures is our interpretation, not something the model proves.
Can Machine Learning Be Used as an Experimental Tool for Number Theory?
This opens up a whole lot of fun cryptographic applications, whether defensive (improving the model to use as a pre-filter when searching for n-bit primes, spotting areas of strong and weak primes based on semi-prime spiral data) or offensive (training a discriminator model on primes generated by an existing algorithm vs. reference primes to spot non-uniformities). These are directions for future work, not results.
The idea of machine learnability as a measure of order also has potential when it comes to exploring Riemann/Chowla-related processes that are conjectured to behave like random coin-flips. If an appropriate model achieves anything better than 50% accuracy it is potential evidence of order: not necessarily disproving any of the relevant conjectures, but providing nuance. So, for example, Chowla says correlations like λ(n)λ(n+1) should average to 0; if the model consistently finds signal, it could be seeing slow convergence or hidden local structure. Likewise, Riemann implies specific bounds on prime irregularities; if a model beats random at predicting primes in certain windows, this helps to refine the bounds and identify specific fluctuations.
However, the same basic model also does well in entirely unrelated areas, even better in some cases. Here it is crushing state-of-the-art validation metrics in geological fault prediction:

In each case, however, the most interesting fact is not that this is possible but that it opens up the possibility of isolating features that contribute to the overall result. We didn’t do it here (because, well, it’s time-consuming and fiddly and we have day jobs), but it’s perfectly possible to work out how certain the model is about specific pixels and identify the commonalities, thereby working back to find the specific sieves that the AI thinks are most important.
Likewise, by layering geological datasets and feeding them into a model we can identify the precise features that are most important in locating mineral deposits. In each case the AI isn’t necessarily finding the answer, but it’s telling us why we should expect to find the answer in a given place. That is a more modest role than the headlines about self-improving AI suggest, but for machine learning and number theory it may be the more useful one.
FAQs
What is machine learnability?
Machine learnability is how well a model can learn a pattern from examples and apply it to data it has not seen. In this study it is measured by training the same image model on different regions of the Ulam spiral and comparing how accurately each version reconstructs hidden primes. Higher learnability means the model found more usable structure in that region.
How can machine learning measure order in a sequence?
By holding everything constant except the data. The same model architecture, training setup and metrics are applied to different parts of a sequence, and the results are compared. If one part is consistently easier to learn, it contains more learnable structure. The measurement is comparative, so it says which region is more ordered, not how ordered a region is in absolute terms.
What is the Ulam spiral?
The Ulam spiral writes the integers in a square spiral outward from the centre and marks the primes in a different colour. Diagonal lines and clusters appear that are not obvious from the number line, which is why it has long hinted at hidden order. In this study each spiral became a black-and-white image the model could learn from.
What did the study find about prime number distributions?
In pure accuracy terms, models trained around 500 million beat models trained below 25 million. Precision and recall showed a change of strategy: the model spots prime patterns at lower numbers and eliminates composites at higher ones. Learnable prime patterns also declined faster than prime density, with the sharpest drop between 25 and 50 million.
Does higher machine learnability prove that a sequence is more ordered?
No. It shows that a particular model found more usable structure in one region than another, under controlled conditions. That is evidence of order, not proof. Connecting the result to the underlying mathematics, such as conjectures about how prime irregularities even out at scale, is an interpretation that the broader number theory supports, not something the model demonstrates alone.
Can machine learning be used to study number theory?
It can serve as an experimental instrument. Models are good at finding patterns in results that are hard to analyse directly, and comparing learnability across regions gives number theorists a new kind of measurement. It does not replace proof. Possible uses include probing strong and weak primes for cryptography and testing where conjectured random behaviour shows hidden structure.
[1] One neat example of this would be string theory. Experience has shown us that when you break things down into their constituent parts you get a series of ever smaller particles, so you might expect that if you keep going you’ll eventually reach a dimensionless point-particle of pure essence. The problem with this is that if we insert it into our current load-bearing maths stack, it would produce a universe that was essentially a singularity at every point. We can’t change the maths without breaking other things, so the fundamental particles must be some other shape. Fortunately, if you simply assume that they’re a one dimensional string, not only do the equations work out and produce a reasonable universe, they also imply the existence of gravitons, which was implicitly confirmed by the observation of gravity waves in 2015. In this case the mathematical rules were established first, but turned out to be a projection of other fundamental physical properties of the universe.
[2] Deepmind in particular has been going hard on this angle lately, having hired Javier Gómez Serrano, probably the primary specialist on Navier-Stokes out there, with the specific goal of cracking a Millennium prize problem using AI. They haven’t cracked it yet, but they just published some neat unstable singularities.
[3] Where the base model assigns a given pixel as white if the likelihood of it being white passes 50%, the top-k model automatically assigns the top xx% of pixels white. This allows us to control for the effect of the different proportion of primes at different regions of the spiral. The full results can be found in the original paper.


