Large language models do addition with trigonometric functionsLanguage Models Use Trigonometry to Do Addition
Through causal intervention, the authors found that models such as GPT-J represent numbers as generalized helices and complete two-digit addition through a trigonometric rotation mechanism similar to a "clock" algorithm.
- Understanding how large language models perform basic mathematical tasks is crucial for ensuring their reliability and interpretability, but the field still lacks mechanistic explanations at the representation level.
- The authors reverse engineered GPT-J, Pythia-6.9B, and Llama3.1-8B, proposing that numbers are represented as multi-period generalized helices, and that addition is implemented through a "clock" algorithm that manipulates the helices.
- Causal interventions show the helix fit reaches a log-odds difference of 7.21 in GPT-J addition, with clear division of labor between MLP and attention heads; 45.7% of GPT-J's common numerical errors are off by 10.
- The authors note that the specific trigonometric operations for constructing and adding helices have not yet been isolated; experiments cover only 3 open-source models, single-token integers within 100, and a specific prompt format.
- Evaluated models
- GPT-JPythia-6.9BLlama3.1-8B
- Benchmarks
- a + b (a, b ∈ [0, 99]) 两位数加法数据集五项数值任务(a - 23, a // 5, a * 1.5, a mod 2, x - a = 0)单 token 整数数据集(a ∈ [0, 360])
- Metrics
- AccuracyLogit Difference (LD)Total Effect (TE)Direct Effect (DE)NRMSE
MIT researchers used mechanistic interpretability methods to reverse-engineer how GPT-J, Pythia-6.9B, and Llama3.1-8B compute addition, finding that these models represent numbers as generalized spirals and use a Clock algorithm to rotate the spirals of a and b to obtain the result spiral of a+b. The study tested 10,000 addition problems with a and b ranging from 0 to 99, and the three models achieved accuracies of 80.5%, 77.2%, and 98.0%, respectively. The authors provide causal evidence using activation patching, path patching, and neuron fitting; the spiral fit outperforms the PCA baseline in most settings. In GPT-J, they further localized the attention heads that transport the spirals of a and b, the MLP layers 14-18 that construct the a+b spiral, and the MLP layers 19-27 that output the answer to logits. The authors note that the exact mechanism by which the model computes the a+b spiral from the a and b spirals remains undetermined, and the causality of the a+b spiral in Llama3.1-8B is weaker than in the other two models.
Why it was selectedThe paper uses activation patching, path patching, and neuron fitting to provide a representation-level explanation of how LLMs compute addition, which can serve as a transferable method for studying other arithmetic capabilities.
Related events and news
0 events · 5 news mentions
News that mentions this paper
- Goodfire Researchcites the paper's id or linkGoodfire 用 CLTs 复现 GPT-2 Small 电路追踪,发现与既有机制存在差异
representations found in Kantamneni & Tegmark [8]Language Models Use Trigonometry to Do Addition[link]Subhash Kantamneni and Max Tegmark, 2025.
- Goodfire Researchcites the paper's id or linkGoodfire 研究揭示 Evo 2 如何在几何流形中编码生命树
, and helical manifolds for numbers [14]Language Models Use Trigonometry to Do AdditionSubhash Kantamneni and Max Tegmark, 2025. arXiv. [link]
- Goodfire Researchcites the paper's id or linkGoodfire 提出神经几何:神经网络内部世界呈弯曲流形结构
Zhong et al. 2023, Zhou et al. 2024, Zhou et al. 2025, Kantamneni and Tegmark 2025, Levy and Geva 2025, Fu et al. 2026, days of the week, and months of the year[3]Engels et al. 2024, Modell et al.
Show 2 more news items
- Goodfire Researchcites the paper's id or linkGoodfire 在 Llama 3.1 8B 中发现通用加法模块
Zhong et al. 2023, Zhou et al. 2024, Zhou et al. 2025, Kantamneni and Tegmark 2025, Levy and Geva 2025, Fu et al. 2026
- Transformer Circuitscites the paper's id or linkAnthropic 提出稀疏线性变换混合 MOLT 替代 transcoder 解释 MLP 计算
Other work suggests that transformers embed their representations of numbers in a geometric structure such that simple transformations can be used to compute arithmetic operations.
Paper analysis
What problem does this paper attempt to solve?
The authors attempt to reverse engineer the internal mechanism by which large language models compute two-digit addition, and the authors state that this is the first algorithm-level explanation at the representation level.
This paper attempts to reverse engineer how large language models compute two-digit addition, explaining the underlying algorithm at the representation and neuron levels.
- Scenario and importance: The authors believe that mathematical reasoning has become a key benchmark for measuring the capabilities of large models, and understanding how models handle basic mathematical tasks such as addition is crucial for reliability, interpretability, and alignment in high-risk scenarios.
- Shortcomings of existing methods: Most mechanistic interpretability research either only identifies the minimal set of circuit components required for computation, or only studies human-understandable feature representations; the authors state that a true mechanistic explanation requires clarifying both how features are represented and how downstream components manipulate features.
- Core observation and hypothesis: The authors observed that numbers exhibit both periodic and linear structure in model activations, and hypothesized that numbers are represented as generalized helices (Generalized Helix), with computation completed through a "clock" algorithm similar to modular addition in single-layer Transformers.
- Main contributions of the paper: The authors validated the causal importance of the helix representation on GPT-J, Pythia-6.9B, and Llama3.1-8B, and used GPT-J as the core for an in-depth analysis of how attention heads, MLPs, and individual neurons construct and read the sum helix in stages.
What related research exists?
The paper reviews three lines of work—circuit analysis, feature geometry, and addition reverse-engineering—and the authors state that this paper connects feature representations with operational algorithms.
Circuit research
- Olah et al. (2020) and Elhage et al. (2021) — proposed the circuit analysis framework, aiming to find the key attention heads and MLP components that implement specific functions.
- Olsson et al. (2022) and Wang et al. (2023) — respectively identified the induction heads that drive in-context learning, and the sparse circuits of attention heads in GPT-2 that perform the indirect object identification task.
- Nanda et al. (2023b) and Hanna et al. (2023) — respectively explored the mechanisms of MLPs in fact recall, and the role of MLP outputs when GPT-2 performs greater-than comparison operations.
Feature geometry research
- Park et al. (2023) and Elhage et al. (2022) — proposed the linear representation hypothesis, which holds that model features are stored as linear directions; subsequent work used sparse autoencoders (SAEs) to decompose model activations into sparse combinations of linear features.
- Engels et al. (2024) — found that some features exist as nonlinear manifolds (e.g., days of the week form a circular distribution). Levy & Geva (2024) and Zhu et al. (2025) respectively modeled numbers as a decimal circle and a straight line; the authors noted that these two works have relatively little causal validation.
- Marks et al. (2024) and Makelov et al. (2024) — connected features with circuits, using SAE features to build interpretable circuits.
Addition reverse engineering
- Liu et al. (2022) — found that a single-layer Transformer can generalize on modular addition tasks when it learns a circular representation of numbers.
- Nanda et al. (2023a) and Zhong et al. (2023) — the former proposed the "clock" algorithm for explaining the angular displacement mechanism of modular addition in single-layer models; the latter found a competing "pizza" algorithm.
- Stolfo et al. (2023), Nikankin et al. (2024) and Zhou et al. (2024) — Stolfo et al. identified addition circuits; Nikankin et al. argued that models solve the task through neuron heuristics rather than deterministic algorithms; Zhou et al. found that Fourier features are crucial for addition.
Baseline methods and benchmarks
- In causal activation patching experiments, full-layer patching (Layer Patch), principal component analysis (PCA), pure circle fitting (Circle), and polynomial fitting (Polynomial) baselines were compared, evaluated on 10,000 addition problems with a, b ∈ [0, 99] and 5 extended tasks.
The authors state that previous work mostly focused on isolated circuits or isolated features; this paper is the first to combine spiral feature representations with clock algorithm circuits, providing a mechanism explanation at the representation level.
How does the paper address this problem?
The authors propose a generalized helix representation and a four-stage clock algorithm, locating the addition circuit through attribution pruning and pre-activation fitting.
The overall approach is to first prove through causal intervention that numbers are represented in the residual stream as a Generalized Helix, and then prove through circuit and neuron analysis that the model completes addition by manipulating the helix through a Clock algorithm.
Parameterization and fitting of the generalized helix for numbers
- Formal definition of the helix: The residual stream is modeled as a basis function expansion composed of a linear component and multiple Fourier periodic components, of the form hal = CB(a)T, where the basis functions are B(a) = [a, cos((2π)/T1a), sin((2π)/T1a), …, cos((2π)/Tka), sin((2π)/Tka)], and the matrix C maps this into the residual stream space.
- Basis for period selection: Based on the Fourier spectrum of the layer-0 residual stream, the high-amplitude significant periods T = [2, 5, 10] are selected, combined with the decimal inductive bias and large-magnitude features introducing the low-frequency period T = 100.
- Dimensionality reduction fitting process: At each layer, PCA is first used to reduce the residual stream to 100 dimensions to prevent overfitting; after fitting the coefficient matrix via linear regression, the result is projected back to the full residual dimension through the inverse PCA transform.
Four-stage process of the clock algorithm
- Input embedding: The model embeds input tokens a and b as helices at their respective positions.
- Cross-position movement: Sparse attention heads mainly located in layers 9–14 move the helix information of a and b to the final equals token position.
- Sum synthesis: MLPs in layers 14–18 manipulate the helices of a and b to construct the sum helix of a + b, with a few mixed attention heads providing assistance at this stage.
- Result reading: MLPs in layers 19–27 and some attention heads read the a + b helix, projecting and mapping it to the final vocabulary logits.
Attention head and MLP circuit division
- Attention head classification criteria: By computing the ratio of direct effect to total effect (DE/TE), combined with the proportion of total effect recovered when retaining only the a, b helices or the a + b helix, key attention heads are classified into a, b heads, a + b heads, and mixed heads.
- MLP stage functional division: Based on the explanatory power of the sum helix for MLP outputs and the DE/TE ratio, early MLPs are dominated by indirect effects and are highly explained by the sum helix, while later MLPs see an increase in direct effects and dominate the logits output.
Neuron pre-activation modeling and attribution pruning
- Attribution patching screening: For all neurons in the network, a gradient-based attribution patching method is used to select approximately 1% of the total (4,587) high-impact neurons for analysis.
- Pre-activation parameter fitting: The pre-activations of key neurons are modeled as $N_n^l(a, b) = \sum_{t=a,b,a+b} c_t t + \sum_{T \in [2,5,10,100]} c_{T,t} \cos(\frac{2\pi}{T}(t - d_{T,t})) $, using an SGD optimizer with learning rate 0.1 and a cosine annealing scheduler for 2,500 iterations to complete parameter fitting.
What experiments did the paper conduct?
Causal intervention shows that helix fitting surpasses PCA in addition, MLPs dominate in the circuit, and common errors are mostly deviations of 10.
Experimental setup
- Models tested: GPT-J (6B parameters), Pythia-6.9B, and Llama3.1-8B, a total of 3 autoregressive models, with the detailed analysis focused on GPT-J, which uses a standard MLP.
- Dataset and scale: The main task is 10,000 two-digit addition problems with a, b ∈ [0, 99]; the extended tasks include a - 23 (77 problems), a // 5 (100 problems), a * 1.5 (50 problems), a mod 2 (100 problems), and x - a = 0 (100 problems), a total of 5 univariate arithmetic tasks (Table 3).
- Comparison baselines: In residual stream patching, full-layer patching (Full/Layer Patch), principal component analysis baselines (PCA, with 9 and 27 dimensions), pure circle fitting (Circle), and 9th-order polynomial fitting (Poly) are compared.
- Metric definitions: Task accuracy (Accuracy); logit difference (Logit Difference, LD) in activation patching; total effect (TE) and direct effect (DE); normalized root mean square error (NRMSE) for pre-activation fitting.
- Evaluation and prompting method: Causal activation patching is used, selecting 100 pairs of clean and corrupted prompts that the model can answer correctly to compute the average logit difference; the prompts include an additional instruction guiding the model to output a number (Table 2).
- Computing environment and repetition: Experiments were run on a single NVIDIA RTX A6000 GPU with 48GB of memory; the paper does not report multiple random repetitions.
Main results
Swipe horizontally to read the table
Task Full layer patching (Full) PCA baseline Helix fitting (Helix) Circle fitting (Circle) Polynomial fitting (Poly) a + b = 8.34 6.13 7.21 6.83 3.09 a - 23 = 7.45 6.16 7.05 6.52 2.93 a // 5 = 5.48 5.24 4.55 4.25 4.55 a * 1.5 = 7.86 6.65 5.16 4.85 4.84 a mod 2 = 0.98 1.00 1.11 1.12 0.88 x - a = 0, x = 6.70 4.77 4.56 4.34 2.98 (According to Table 1, showing the maximum causal effect maxl LDla of various representation fittings at input a on GPT-J)
- Helix fitting surpasses PCA in addition and subtraction: On the a + b task, the 9-parameter helix fitting reaches 7.21, higher than the 9-dimensional PCA's 6.13, close to full-layer patching's 8.34; on the a - 23 task it also exceeds PCA's 6.16 with 7.05.
- Weaker performance on division and multiplication tasks: On a // 5 (4.55 vs. 5.24), a * 1.5 (5.16 vs. 6.65), and the equation task (4.56 vs. 4.77), helix fitting is lower than the PCA baseline; the authors speculate that the number representation may contain additional structure not captured by the helix.
- Fourier features dominate computation: The effect of pure circle fitting (6.83 for addition) closely follows helix fitting, while polynomial fitting (3.09) lags significantly in causal effect; the authors state this indicates the model mainly uses Fourier periodic features rather than high-order polynomials to perform the operations.
Causal validation of attention head and MLP circuits
- Attention head pruning and classification: Among all 448 attention heads in GPT-J, patching the top 20 attention heads recovers 83.9% of the effect of full attention layer patching (Figure 25); the authors classify them into 11 a, b heads, 5 a + b heads, and 4 mixed heads; retaining only the 4 mixed heads achieves 80% of the recovery effect of all 20 heads (Figure 27).
- Key MLP circuits: Among the 28 MLP layers in GPT-J, patching 11 key MLPs (layers 14–27, excluding layers 15, 24, 25) achieves 95% of the effect of full MLP layer patching (Figure 30); among these, layers 14–18 are mainly used to construct the a + b helix, and the sum of direct effects of layers 19–27 reaches 8.20, dominating the final output (Figure 6).
- Neuron-level attribution pruning and fitting: Using only approximately 1% (4,587) of neurons in GPT-J and mean-ablating the remaining neurons yields correct results on 80% of samples (Figure 31); fitting these key neurons with helix pre-activations recovers approximately 75% of the performance of real neuron pre-activations in patching (Figure 9).
Cross-model generalization and ablation tests
- Multi-model replication: On Pythia-6.9B and Llama3.1-8B, helix and circle fitting for the a token also surpass the PCA baseline (Figure 19); however, on the last token, the a + b helix fitting for Llama3.1-8B is weaker than for GPT-J and Pythia-6.9B (Figure 23), which the authors speculate may be due to its gated MLP leading to a different algorithm.
- Ablation of helix representation necessity: Ablating the helix projection dimensions from the residual stream damages model performance to a degree comparable to ablating an entire network layer (Figure 21); the authors state this provides causal evidence that the helix representation is essential for addition.
- Data splitting and randomization validation: Using an 80% training set and 20% test set split to test the fitting of a, helix and circle fitting still surpass PCA; after shuffling the order of a for fitting, the causal logit difference is close to 0 (Figure 20), which the authors state indicates that the helix form itself is not overfitted or overly expressive.
Error patterns and analysis of linear addition failure
- Main error distribution: Among samples where GPT-J gives an incorrect numeric answer, errors of -10 account for 45.7% and errors of +10 account for 27.9%, together exceeding 70% (Figure 37).
- Carry hypothesis rejected: The authors initially hypothesized that errors of -10 stem from carry failure, but a chi-square test shows no significant difference in whether the sum of the ones digits is greater than or equal to 10 between errors of -10 and other cases (p = 0.14, Figure 38), rejecting the carry error hypothesis.
- Small-number bias and fragility of linear addition: The slope of the fitted line for the logits of all a + b results is basically negative, showing a systematic bias toward smaller numbers (Figure 42); experiments show that even performing linear addition on a high-precision linear representation with R² = 0.997, accuracy within the threshold of 100 is still below 20%, far lower than GPT-J's above 80% (Figure 36); the authors infer that the model adopts periodic circular addition to provide fault-tolerant redundancy.
Other ablations and analyses
- Sensitivity to analysis sample size: When performing Fourier decomposition at layer 0 of GPT-J, analyzing 360 tokens identifies the T = 2 period, while analyzing 361 tokens fails to identify it (Figure 12).
- Polynomial fitting parameter ablation: Using up to 9th-order polynomial fitting for input a on the addition task, the maximum causal logit difference is only 3.09, significantly lower than the 4-period helix's 7.21 (Table 1).
- Attention head count ablation: When patching attention heads with a single token, k = 8, k = 13, and k = 17 recover 50%, 70%, and 80% of the model effect, respectively (Figure 25).
- Distribution of key direct-effect neurons: Among the top 4,587 key neurons, only 693 neurons are needed to recover 80% of the direct effect, and 84% of them are distributed in layer 19 and beyond (Figure 33).
- Correspondence between neuron dominant frequencies and LogitLens: For key pre-activation neurons with period Ti, the dominant Fourier period of their LogitLens is also concentrated at Ti, with a peak at 200 (Figure 40).
What are some points that can be further explored?
The authors note limitations such as trigonometric operations not being isolated and the algorithm possibly not being unique; future work could explore error-correcting code mechanisms.
Limitations and future directions noted by the authors
- The specific implementation mechanism of trigonometric operations was not isolated: The authors note that although they can prove that key components generate the a + b helix from the a, b helices, they were unable to isolate the specific underlying computational steps by which the model implements trigonometric identity operations (Section 5.5).
- The clock algorithm may be only part of an ensemble method: The authors note that even if the model uses the clock algorithm, it may be only one among an ensemble of approaches; in gated MLP models, the causality of the sum helix is relatively weaker, and other algorithms may exist (Section 5.5).
- Limitations of the algorithm due to tokenization differences: The authors note that for models such as Gemma-2-9B that tokenize numbers digit by digit, additional algorithms are required to reconcile and integrate number tokens, and the mechanism cannot be directly transferred (Section 5.5).
- Influence of model parameter scale: The authors note that at different parameter scales, large models may learn different arithmetic algorithms, and the clock algorithm may not be the only explanation for addition in large models (Section 5.5).
- The internal error-correcting code hypothesis remains to be tested: The authors propose that future work could investigate whether large language models contain error-correcting code structures similar to biological grid cells to assist addition operations (Section 6).
- Fourier decomposition is sensitive to sample length: The authors note that analyzing 360 numbers can detect period 2, but analyzing 361 numbers cannot, acknowledging that this frequency-domain analysis is sensitive to the analysis sample size (Appendix B).
Experimental coverage
- The tested models cover GPT-J (6B), Pythia-6.9B, and Llama3.1-8B, a total of 3 open-source models; fine-grained circuit and neuron analysis was performed only on GPT-J.
- The addition task only covers the integer range a, b ∈ [0, 99], and the numbers are all encoded as single tokens in the vocabulary.
- Helix fitting fixedly uses four preset periods T = [2, 5, 10, 100], and the extended tasks cover only 5 specific univariate numerical tasks.
- Prompt evaluation all uses an addition instruction template; the paper does not evaluate mechanisms in multi-turn dialogue or complex chain-of-thought scenarios.
- The paper does not report variance statistics across multiple random seeds; all experiments were run once on a single GPU for reproduction.
Summarize the main content of the paper
The paper reverse engineered the addition mechanism of decoder models, finding that numbers are encoded as multi-period helices and manipulated by a clock algorithm to solve the task.
- Positioning and core question: this study is a mechanistic interpretability work on the basic arithmetic ability of large language models, aiming to reverse-engineer the specific representational geometry and underlying computational circuits the model uses to perform two-digit addition.
- Core method design: the study finds that digit representations are both linear and multi-periodic, and proposes constructing a generalized helix with 1 linear component and 4 periodic components (T = [2, 5, 10, 100]), and proposes that the model follows a "clock" algorithm, step by step completing input helix embedding, attention head cross-position transport, intermediate-layer MLP synthesis of the sum helix, and later-layer decoding to logits.
- Main causal experimental evidence: causal activation patching shows that on GPT-J the helix fit reaches a log-odds difference of 7.21 (Table 1), surpassing the PCA baseline (6.13); ablating the helix subspace in the residual stream degrades model performance nearly as much as ablating an entire network layer (Figure 21).
- Component and neuron fine-grained circuits: in GPT-J, only 20 attention heads are needed to recover 83.9% of total attention effect (Figure 25); MLP layers 14–18 are responsible for synthesizing the sum helix, and layers 19–27 dominate direct writing to logits (total direct effect 8.20, Figure 6); only about 1% of key neurons across the network (4587) recover 80% of task accuracy (Figure 31).
- Error mechanisms and design insights: analysis shows that 45.7% of GPT-J's erroneous digit outputs are off by 10 (Figure 37), stemming from an overall internal bias toward smaller values; pure linear addition achieves less than 20% accuracy at the same precision (Figure 36), and the authors infer that the model autonomously evolved a periodic representation resembling a decimal clock to gain stronger fault-tolerance redundancy.