Mechanistic Interpretability of Discrete Logarithm Grokking: How Representation Determines the Internal Algorithm
This paper demonstrates that the input representation of the discrete logarithm problem fundamentally dictates the internal algorithm discovered by neural networks, revealing that algebraic alignment with the problem's true factorization is a prerequisite for rapid generalization (grokking) and that the necessary interaction-rich computational structures form during the memorization phase long before performance improves.
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 quiet corners of computer science, researchers are trying to understand how artificial intelligence actually thinks. For years, we have known that these systems can learn to solve complex puzzles, but the process often looks like magic: a model might fail repeatedly for a long time, suddenly memorize the answers, and then, after a strange pause, begin to generalize and solve new problems it has never seen. This phenomenon, where a machine seems to "grok" a concept long after it has simply memorized the data, has become a central mystery. To crack this code, scientists often use mathematical problems that have a clear, hidden structure, much like a lock with a specific key. One such problem is the discrete logarithm, a task that asks a computer to reverse a multiplication process to find a hidden number. While this sounds abstract, it is the kind of logical puzzle that reveals the inner machinery of neural networks. By watching how a computer learns to solve this specific riddle, researchers can see exactly what internal strategies the machine invents and whether the way we show it the problem changes the solution it finds.
A new study by David Vesterlund takes this investigation a step further by asking a simple but profound question: does the way we present information to a computer change the way it thinks? To find out, the researcher trained artificial intelligence models to solve the discrete logarithm problem using two very different methods of showing the data. In the first method, the model was given the raw numbers, just as a human might see them on a page, with no special hints about the underlying structure. In the second method, the researcher broke the problem down into its natural mathematical parts before showing it to the model, effectively handing the computer a pre-sorted toolkit. The results revealed that these two approaches led the models to discover completely different internal algorithms. The model trained on the raw data developed a complex, tangled web of connections where different parts of the problem were deeply intertwined. In contrast, the model given the pre-sorted, structured data developed a clean, separated organization where the different parts of the problem were handled independently.
Perhaps the most surprising discovery was the timing of this learning. The researchers found that the complex, tangled structure in the raw-data model began to form long before the model actually started to get the answers right. For thousands of steps, the model's internal connections were rearranging themselves into this intricate pattern while its test scores remained stuck at a low level. It was only much later, after this internal structure was fully built, that the model suddenly "clicked" and began to solve the problem correctly. This suggests that the machine was building the necessary machinery for understanding long before it could demonstrate that understanding. The study also showed that this internal architecture is not just a side effect but is essential for the task. When the researchers surgically removed specific parts of the model's internal math, the system failed completely, proving that these specific patterns were the actual engine driving the solution.
The study also corrected a misunderstanding from previous research regarding how to test these models. A common technique involved scrambling the labels of the data to see if the model relied on the specific order of numbers. The new analysis proved that this scrambling method was actually a trick; because the model learns its own dictionary of symbols, simply renaming the numbers did not actually change the underlying mathematical structure it was seeing. The model was still solving the same structured problem, just with different names. This finding was crucial because it cleared the way for a more honest test. The researchers then created a hierarchy of new tests, some of which kept the mathematical structure intact and others that deliberately broke it. They found that models could only learn to solve the problem quickly if the input preserved the true mathematical "partition" of the problem. If the input scrambled the relationship between the parts of the equation, the model would memorize the training data perfectly but would never learn to solve new problems, even after being trained for a very long time.
Ultimately, this work suggests that the input representation does not just speed up or slow down learning; it fundamentally determines the algorithm the machine discovers. When the problem is presented in a way that respects its natural mathematical divisions, the machine finds a simple, efficient path to the solution. When the problem is presented in a raw, unstructured way, the machine is forced to build a much more complex internal world to bridge the gaps, and it takes much longer to realize how to use that complexity. The study confirms that for these artificial systems, the path to understanding is paved by the structure of the information they are given. It is not merely a matter of how much data they see, but how that data is arranged. The machine does not just learn the answer; it learns a specific way of thinking that is dictated by the shape of the question itself.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.