Pick a number, any number. Now imagine it as the White Rabbit from Alice in Wonderland, glancing nervously at its watch before swan-diving down an arithmetic rabbit hole: if it’s even, it politely halves itself; if it’s odd, it goes through the slightly more dramatic triple me and add one, then halve routine. Repeat this over and over and you get a Collatz journey, a mad zig-zag through the integers that feels like it might generally spiral upwards forever, yet somehow always seems to claw its way back to the same tiny loop at the surface: 4 → 2 → 1. It’s as if every rabbit, no matter where it starts, eventually scrambles out of the warren and lands on the same patch of grass, blinking in the sunlight and pretending nothing strange just happened.

Behind all this rabbit-hole whimsy lurks one of the most notorious open problems in mathematics. The Collatz conjecture asks whether our simple rule, halve if even and send odd numbers to 3n+1, always drags every positive integer, eventually, into the tiny loop 4→2→1. It’s been open since the 1930s, when it was formulated by German mathematician Lothar Collatz. It has been checked by computer for all starting values up to about 2.95×10^20, and yet we still have no proof that some colossal integer doesn’t wander off forever or get trapped in a different cycle. Over the decades, people have proved partial, statistical versions: for instance, earlier work of Terras, Allouche, and Korec showed that for almost all starting values (in a precise density sense), the orbit spends a lot of time at values far smaller than where it began. Tao’s 2019 breakthrough pushed this further: he showed that for any starting value n and any function f(n) that grows to infinity, no matter how slowly, almost every Collatz orbit eventually falls below f(n), so the conjecture is almost true for almost all numbers. And the story doesn’t stop there: more recent work has extended Tao’s methods to whole families of generalized Collatz maps (using different “divide by p and multiply by q recipes) and shown that their orbits are also almost always forced back down, reinforcing the sense that these rabbit holes are surprisingly well-behaved, just maddeningly hard to tame completely.
Let’s take a closer look at some concrete examples of Collatz sequences to better understand how they work. For instance, starting with 81, the sequence progresses as 3 x 81 + 1 = 244, then 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1… and the sequence goes into an infinite loop. Now start with 27, the sequence follows a thrilling journey through 111 steps, reaching values as high as 9232 before finally settling down to 1, where it loops endlessly between 1, 4, and 2.

If you explore different starting numbers, you’ll find that the sequence always seems to reach 1, sometimes after a long and wild ride through the positive integers. Whether this holds true for all integers is known as the Collatz conjecture, which is considered one of the simplest yet most intriguing open problems in mathematics. Young mathematicians are often advised not to tackle this problem because, although the Collatz sequences reveal many beautiful patterns, the question of whether they always reach one—the stopping problem—remains incredibly challenging. Paul Erdős famously remarked that mathematics is not yet ready for such problems, highlighting how tough and mysterious this puzzle still is.

Imagine handing these rabbit-holes to transformers and asking them to guess where a rabbit might pop up after a long underground journey, skipping all the twists and turns in between. That’s what’s happening in Transformers know more than they can tell: Learning the Collatz sequence, a recent paper written by Axiom’s Francois Charton and Ashvni Narayanan, postdoc researcher at Sydney Mathematical Research Institute, where small transformer models are trained not just to follow the 3x+1 rules, but also to understand the hidden control structure of these tunnels: how long the loops are, when to keep falling, and when to climb back up. The researchers’ findings are quite fascinating: the models don’t really hallucinate, but rather follow the right rabbit into the wrong-length tunnel, making carefully reasoned, very specific mistakes that show just how much structure they’ve really learned.
First, it was observed that large language models often find integer arithmetic challenging, especially with operations like multiplication when numbers get larger. This happens because LLMs are essentially pattern matchers rather than true calculators. In public chatbots, we usually overcome this by letting the model use a calculator, but for those claiming to solve math olympiad problems or advancing mathematical research, it’s a bit of a missed opportunity. For instance, Collatz sequences, which are complex arithmetic objects, present a fascinating challenge for transformers to tackle.
Secondly, the way transformers learn to handle reasoning tasks is still not well understood. LLM are frequently subject to hallucinations, which can be quite embarrassing. There’s also debate about whether they can truly learn complete algorithms or just recognize specific examples or recurring patterns. Mathematical problems like Collatz serve as perfect testing grounds for exploring these interpretability issues. We can use our mathematical knowledge of these problems to better design experiments and understand the outcomes.
From a math discovery perspective, experimenting with challenging problems often brings unexpected insights and intuitions. Earlier this year, we noticed interesting, unexplained patterns in elliptic curves. In 2024, a model similar to this one used transformer technology to uncover new regularities in scattering amplitudes, an important part of quantum field theory, leading to several exciting discoveries. It’s truly intriguing to explore whether experimenting with Collatz sequences might offer fresh perspectives on this long-standing problem.
The goal of this paper is to predict the “long Collatz step." When you closely examine Collatz sequences, you’ll notice that a step from n to 3n+1 is always followed by a step from n to n/2, because if n is odd, 3n+1 becomes even. Starting with an odd integer, Collatz sequences tend to have a pattern: a series of n to (3n+1)/2 steps, repeated as long as the result stays odd, followed by a sequence of n to n/2 steps, repeated as long as the result remains even. We refer to this process—k steps of n to (3n+1)/2, followed by k’ steps of n to n/2, where k and k’ depend on the initial odd number n—as a long Collatz step. Our aim is to train transformers to predict this step for odd integers ranging from 1 to $10^{12}$, using only examples.
To obtain the results of the paper, 56 models were trained that only differ in the way of representing input and output. The long Collatz step maps positive odd integers onto positive long integers. We represent these numbers as sequences of digits in various bases, from 2 to 57. Interestingly, the models don’t have any mathematical knowledge; they are simply given sequences of digits in a particular base and are asked to predict the sequence of digits that represent their long Collatz successor in that same base.
Surprisingly, some models showed remarkable performance. Transformers that encode integers in base 24 or 32 were able to accurately predict the next step in the Collatz sequence for 99.8% of a test set of random integers they hadn’t encountered during training. These impressive results are quite surprising, especially considering that transformers typically don’t perform well on arithmetic tasks.
While not all bases perform equally well, there’s a fascinating pattern worth exploring. On average, models trained in even bases have a remarkable accuracy of over 90% on test examples, whereas models trained in odd bases tend to perform slightly lower. Here, accuracy simply reflects how often the model’s answers are exactly correct, in other words, 90% accuracy means it gets the right Collatz output about 9 out of 10 times. What’s truly intriguing is that as training progresses, all models, regardless of the base, reach the same key milestones: around 25%, then 37%, 55%, 71%, 88%, and so on. This pattern suggests that these milestones are deeply connected to the fundamental structure of Collatz sequences, rather than being dependent on the specific model or how the numbers are shown. Isn’t that fascinating?
Actually, all models tend to get very good at predicting certain classes of inputs, which are defined by their binary representation, while struggling with others. For example, they learn inputs ending in 001 first, then those ending in 1011, and so on. This pattern is quite different from what we usually see in deep learning models. Typically, when models learn a specific function, they do so by gradually improving their approximations and performing better across a wide range of inputs. In this case, however, the models focus on restricting the correct function to specific classes of inputs, which is a different approach.
Since these input classes are characterized by their binary forms, it’s understandable that models utilizing bases like 24 or 32, which are divisible by large powers of two, tend to perform optimally. What’s even more interesting is that odd-base models are capable of learning how to represent their inputs in base two.

These input classes map to a deep mathematical property of the Collatz sequence: they encode k and k’, the number of loops in the computation (i.e. the number of times each of the two transformations n → (3n+1)/2 and n → n/2 are performed). In other words, the model is learning the long Collatz step of inputs corresponding to particular values of k and k’: instead of learning the full algorithm, It learns special cases corresponding to specific values of k and k’.
An analysis of model errors really helps to understand what’s happening. Unlike LLMs, which sometimes make up facts or guess randomly when they’re unsure, our model’s mistakes follow clear patterns. In fact, about 90% of these errors can be traced back to just two simple rules.
For small values of k, the model incorrectly predicts k’ as the largest value it has learned so far. For instance, if the model, for k=2, can predict inputs with k’<3, it will predict as if k’=2 for all inputs with k=2 and larger k’.
For larger values of k, for which the model cannot predict inputs with k’=1 correctly, the model predicts k as the largest k it can predict, and k’ as 1.
These findings provide us with a full account of how transformers learn long Collatz steps. First, models learn to predict all inputs as if k=k’=1. This results in 25% accuracy, the lowest quantized value we observe. Then, models start learning larger values of k and k’, by classifying inputs by their binary representation. During training, inputs with k and k’ up to a certain value are correctly predicted, all others are predicted according to the two rules above. Model predictions are explainable, and there are no hallucinations.
What are these results telling us?
First, they challenge some common assumptions about language models. Transformers are capable of learning complex arithmetic functions, like the long Collatz successor, especially when given proper supervision and thoughtful encodings for numbers, going beyond the simple tokenization methods often used by LLMs. Additionally, model predictions can be understood through a small set of rules, and instances of hallucination are nearly nonexistent.
Secondly, these models have a small but important limitation: instead of mastering a universal method, they tend to learn specific cases, those associated with small values of k and k’ based on their training data. While they do a good job generalizing to inputs they have encountered before, they might not perform as well when it comes to new values of k and k’.
Third, these straightforward experiments can offer fascinating insights into the core challenges. In this case, observing quantized learning helped reveal the connection between the structure of the Collatz sequence, specifically, the loop lengths and the binary representation of the input.
Ultimately, this line of research offers exciting new directions for understanding how models work. While most interpretability studies focus on analyzing model weights, which is a challenging task as transformers become more complex, our approach uses foundational mathematical principles to design meaningful experiments and interpret the outcomes. We leverage our prior knowledge of the underlying mathematics to create experiments and analyze their results.
