Table of Contents
Fetching ...

Language Models Use Trigonometry to Do Addition

Subhash Kantamneni, Max Tegmark

TL;DR

The paper reveals that mid-sized LLMs internally represent numbers as generalized helices and perform addition by Clock-like manipulation of these helices, with $a$ and $b$ embedded as helix components and the final $a+b$ helix read to produce logits. Through activation and path patching, it causal supports a two-stage circuit: MLPs (reading $a,b$ to build $a+b$) followed by MLPs (reading $a+b$ to output the answer), with a sparse set of attention heads moving helices to the last token. The work provides a representation-level account for mathematical capabilities in LLMs and demonstrates that a clock-based, trigonometric decomposition yields robust predictive power and insights into model reliability and error modes. While compelling, it also notes model- and task-dependent variations, suggesting multiple algorithms may coexist and that further study across architectures and numeral representations is needed. This mechanistic perspective offers concrete avenues for improving interpretability and safety in reasoning tasks.

Abstract

Mathematical reasoning is an increasingly important indicator of large language model (LLM) capabilities, yet we lack understanding of how LLMs process even simple mathematical tasks. To address this, we reverse engineer how three mid-sized LLMs compute addition. We first discover that numbers are represented in these LLMs as a generalized helix, which is strongly causally implicated for the tasks of addition and subtraction, and is also causally relevant for integer division, multiplication, and modular arithmetic. We then propose that LLMs compute addition by manipulating this generalized helix using the "Clock" algorithm: to solve $a+b$, the helices for $a$ and $b$ are manipulated to produce the $a+b$ answer helix which is then read out to model logits. We model influential MLP outputs, attention head outputs, and even individual neuron preactivations with these helices and verify our understanding with causal interventions. By demonstrating that LLMs represent numbers on a helix and manipulate this helix to perform addition, we present the first representation-level explanation of an LLM's mathematical capability.

Language Models Use Trigonometry to Do Addition

TL;DR

The paper reveals that mid-sized LLMs internally represent numbers as generalized helices and perform addition by Clock-like manipulation of these helices, with and embedded as helix components and the final helix read to produce logits. Through activation and path patching, it causal supports a two-stage circuit: MLPs (reading to build ) followed by MLPs (reading to output the answer), with a sparse set of attention heads moving helices to the last token. The work provides a representation-level account for mathematical capabilities in LLMs and demonstrates that a clock-based, trigonometric decomposition yields robust predictive power and insights into model reliability and error modes. While compelling, it also notes model- and task-dependent variations, suggesting multiple algorithms may coexist and that further study across architectures and numeral representations is needed. This mechanistic perspective offers concrete avenues for improving interpretability and safety in reasoning tasks.

Abstract

Mathematical reasoning is an increasingly important indicator of large language model (LLM) capabilities, yet we lack understanding of how LLMs process even simple mathematical tasks. To address this, we reverse engineer how three mid-sized LLMs compute addition. We first discover that numbers are represented in these LLMs as a generalized helix, which is strongly causally implicated for the tasks of addition and subtraction, and is also causally relevant for integer division, multiplication, and modular arithmetic. We then propose that LLMs compute addition by manipulating this generalized helix using the "Clock" algorithm: to solve , the helices for and are manipulated to produce the answer helix which is then read out to model logits. We model influential MLP outputs, attention head outputs, and even individual neuron preactivations with these helices and verify our understanding with causal interventions. By demonstrating that LLMs represent numbers on a helix and manipulate this helix to perform addition, we present the first representation-level explanation of an LLM's mathematical capability.

Paper Structure

This paper contains 29 sections, 3 equations, 42 figures, 3 tables.

Figures (42)

  • Figure 1: Illustrating the Clock algorithm. We find that LLMs represent numbers on a helix. When computing the addition problem $a+b$, LLMs rotate the $a$ and $b$ helices, as if on a clock, to create the $a+b$ helix and read out the final answer.
  • Figure 2: Number representations are both periodic and linear.Top The residual stream after layer 0 in GPT-J is sparse in the Fourier domain when batching the hidden states for $a\in[0,360]$ together. We average the magnitude of the Fourier transform of the batched matrix $h_{360}^0$ across the model dimension. Bottom In addition to this periodicity, the first PCA component is roughly linear in $a$ for $a \in [0,99]$.
  • Figure 3: Helix subspace visualized. For GPT-J's layer 0 output, we project each of the numbers $a \in [0,99]$ onto our fitted $T = [2,5,10,100]$ helix subspace, and visualize it. In the top row, we plot $\sin({\frac{2\pi}{T_i}a})$ vs $\cos({\frac{2\pi}{T_i}a})$ for each $T_i \in T$ and plot all $a$ congruent under $a\mod T$ in the same color and annotate their mean. The bottom row contains the linear component subplot.
  • Figure 4: Helix causal intervention results. We use activation patching to causally determine if our fits preserve the information the model uses to compute $a+b$. We find that our helical and circular fits are strongly causally implicated, often outperforming the PCA baseline.
  • Figure 5: Last token hidden states are well-modeled by $\mathrm{helix}(a+b)$. We use activation patching to show that $h_=^l$ for GPT-J is well modeled by helices, in particular $\mathrm{helix}(a+b)$.
  • ...and 37 more figures