Learning the greatest common divisor: explaining transformer predictions
Abstract
The predictions of small transformers, trained to calculate the greatest common divisor (GCD) of two positive integers, can be fully characterized by looking at model inputs and outputs. As training proceeds, the model learns a list of integers, products of divisors of the base used to represent integers and small primes, and predicts the largest element of that divides both inputs. Training distributions impact performance. Models trained from uniform operands only learn a handful of GCD (up to GCD ). Log-uniform operands boost performance to GCD , and a log-uniform distribution of outcomes (i.e. GCD) to . However, training from uniform (balanced) GCD breaks explainability.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
11 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Dichotomy of Early and Late Phase Implicit Biases Can Provably Induce Grokking cites Towards Understanding Grokking: An Effective Theory of Representation Learning
- Teaching Arithmetic to Small Transformers cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networks cites Towards Understanding Grokking: An Effective Theory of Representation Learning
- Uncovering a Universal Abstract Algorithm for Modular Addition in Neural Networks cites Towards Understanding Grokking: An Effective Theory of Representation Learning
- Uncovering a Universal Abstract Algorithm for Modular Addition in Neural Networks cites Dichotomy of Early and Late Phase Implicit Biases Can Provably Induce Grokking
- Uncovering a Universal Abstract Algorithm for Modular Addition in Neural Networks cites The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networks
- Learning to compute Gröbner bases cites Deep Learning For Symbolic Mathematics
- Efficient numeracy in language models through single-token number embeddings cites Teaching Arithmetic to Small Transformers
- Efficient numeracy in language models through single-token number embeddings cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
Cited by top-tier papers11
- Dichotomy of Early and Late Phase Implicit Biases Can Provably Induce GrokkingKaifeng Lyu, Jikai Jin, Zhiyuan Li, Simon Shaolei Du et al.ICLR 2024 · 71 citations
- Uncovering a Universal Abstract Algorithm for Modular Addition in Neural NetworksGavin McCracken, Gabriela Moisescu-Pareja, Vincent Létourneau, Doina Precup et al.NeurIPS 2025 · 14 citations
- Learning to compute Gröbner basesHiroshi Kera, Yuki Ishihara, Yuta Kambe, Tristan Vaccon et al.NeurIPS 2024 · 9 citations
- Beyond Model Collapse: Scaling Up with Synthesized Data Requires VerificationYunzhen Feng, Elvis Dohmatob, Pu Yang, François Charton et al.ICLR 2025 · 6 citations
- Efficient numeracy in language models through single-token number embeddingsLinus Kreitner, Paul Hager, Jonathan Mengedoht, Georgios Kaissis et al.ICML 2026 · 5 citations
Builds on8
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- Deep Learning For Symbolic MathematicsGuillaume Lample, François ChartonICLR 2020 · 477 citations
- Towards Understanding Grokking: An Effective Theory of Representation LearningZiming Liu, Ouail Kitouni, Niklas Nolte, Eric J. Michaud et al.NeurIPS 2022 · 299 citations
- The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural NetworksZiqian Zhong, Ziming Liu, Max Tegmark, Jacob AndreasNeurIPS 2023 · 181 citations
- Teaching Arithmetic to Small TransformersNayoung Lee, Kartik Sreenivasan, Jason D. Lee, Kangwook Lee et al.ICLR 2024 · 128 citations
Related papers
- Algorithmic Capabilities of Random TransformersZiqian Zhong, Jacob AndreasNeurIPS 2024 · 23 citations
- (How) Can Transformers Predict Pseudo-Random Numbers?Tao Tao, Darshil Doshi, Dayal Singh Kalra, Tianyu He et al.ICML 2025
- Learning Pseudorandom Numbers with Transformers: Permuted Congruential Generators, Curricula, and InterpretabilityTao Tao, Maissam BarkeshliICLR 2026
- How does GPT-2 compute greater-than?: Interpreting mathematical abilities in a pre-trained language modelMichael Hanna, Ollie Liu, Alexandre VariengienNeurIPS 2023 · 251 citations
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasksTianyu He, Darshil Doshi, Aritra Das, Andrey GromovNeurIPS 2024 · 52 citations
