← Latest papers
💻 computer science

Grokking the Discrete Logarithm: Scaling Across Model Capacity and Mechanistic Analysis

This paper presents the first systematic demonstration that transformers can exhibit "grokking"—a delayed transition from memorization to algorithmic generalization—on the full variable-base discrete logarithm problem, revealing that this phenomenon scales non-monotonically with model capacity and is driven by the emergence of multiplicative-character and Fourier-aligned representations.

Original authors: David Vesterlund

Published 2026-10-13
📖 5 min read🧠 Deep dive

Original authors: David Vesterlund

Original paper licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). ✨ This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

In the vast landscape of artificial intelligence, researchers are constantly trying to understand how machines learn. A particularly puzzling behavior, known as "grokking," has recently captured their attention. Imagine a student who memorizes every single answer in a textbook for a test. They can recite the answers perfectly, yet if asked a slightly different question, they fail completely. Grokking is the moment, often occurring long after the student has already memorized the material, when they suddenly stop just reciting facts and begin to truly understand the underlying rules. This shift from rote memorization to genuine generalization happens abruptly, sometimes after thousands of hours of practice, leaving scientists to wonder how and why the machine's brain suddenly reorganizes itself to find the logic behind the data.

This phenomenon was first noticed in simple math tasks, but a new study by David Vesterlund takes it into much more difficult territory. The researcher set out to see if a computer model could grok a problem that is notoriously hard for humans and machines alike: the discrete logarithm. In simple terms, this is a reverse-engineering puzzle. If you know a starting number and a final number, the task is to figure out exactly how many times you had to multiply the starting number by itself to reach the final one. While the forward calculation is easy, working backward is incredibly difficult, especially when the numbers are large and the rules are strict. This specific type of math problem is the foundation of modern digital security, making it a serious test for any learning system. Vesterlund wanted to see if a neural network, a type of AI designed to mimic the human brain, could eventually crack this code not by memorizing every possible answer, but by discovering the hidden mathematical structure that connects them.

To investigate this, the researcher built a series of computer models, ranging from small to very large, and fed them a massive dataset of these reverse-engineering puzzles. The models were trained on a specific prime number, 113, which defines the rules of the game. The smallest successful model had about 427,000 adjustable settings, a number that represents the complexity of its internal brain. When training began, the model behaved exactly as expected for a machine learning system: it quickly memorized the answers it had seen before, achieving near-perfect scores on the practice problems. However, when tested on new, unseen puzzles, it performed no better than random guessing. For a very long time, the model seemed stuck in this state of memorization, unable to generalize.

Then, after thousands of additional training steps, something dramatic happened. The model suddenly began to solve the new puzzles correctly, jumping from random guessing to nearly perfect accuracy. This was the moment of grokking. The delay was striking; the model required roughly three hundred times more training steps to achieve true understanding than it did to simply memorize the answers. To understand if this was a fluke or a fundamental property of these systems, the researcher tested twelve different models of varying sizes, from tiny ones with 90,000 settings to massive ones with over 14 million. The results showed that grokking is not limited to a specific size. It appeared in the medium-sized models and again in the largest ones, provided they were given enough practice data. Interestingly, there was a middle range where the models failed to learn, suggesting that the relationship between the size of the brain and the amount of data needed is complex and not a simple straight line.

To figure out what was happening inside the model's mind during this transformation, the researcher looked closely at the internal signals the model used to make decisions. They found that as the model moved from memorization to understanding, its internal language changed. It stopped relying on simple, surface-level patterns and began organizing its knowledge around a specific type of mathematical rhythm, similar to how sound waves can be broken down into distinct frequencies. By using a technique that searches for simple equations to describe these internal signals, the researcher discovered that the model had spontaneously learned to use trigonometric patterns—waves of sine and cosine—to represent the solution. This was a profound finding because the model was never explicitly taught to use these waves; it discovered them on its own as the most efficient way to solve the puzzle.

The study also included rigorous checks to ensure the model wasn't just finding a shortcut specific to the numbers used. The researcher tested the models on a different version of the problem where the rules were slightly more complex and the numbers were prime, removing any easy shortcuts. The models still grokked, proving they had learned a general rule rather than a specific trick. Furthermore, when the models were tested on generators they had never seen before, they still succeeded, showing they had truly learned the underlying logic of the system. The research suggests that the key to this sudden leap in understanding was a specific training technique that gradually increased the pressure to simplify the model's internal connections, forcing it to discard memorized details and keep only the essential structure.

This work establishes the discrete logarithm as a powerful new tool for studying how artificial intelligence learns. It demonstrates that even for difficult, inverse problems where no simple rule exists, neural networks can eventually transition from rote memorization to deep structural understanding. The findings confirm that this transition is not a magical event but a measurable process involving the reorganization of internal representations into efficient, wave-like patterns. While the study was conducted on relatively small numbers and does not solve the problem of breaking real-world encryption, it provides a clear window into the mechanics of learning. It shows that given enough time and the right conditions, these systems can move beyond memorizing the past to understanding the rules that govern the future.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →