Elamur Research

Modular Arithmetic: Language Models Solve Math Digit by Digit

Paper · 2025 · Tanja Baeumel, Daniil Gurgurov, Yusser al Ghussin et al.

Summary

A correct answer to an addition problem tells us little about how it was produced. A system might recognize familiar patterns, estimate the answer and refine it, or work with the decimal places separately. The authors ask whether language models have internal machinery for the last of these possibilities. They study addition and subtraction with three-digit operands and answers. Their main experiments remove carries and borrowing so that the arithmetic at each place can be examined on its own. They find that groups of neurons spread across several layers can selectively influence the units, tens, or hundreds digit of an answer.

The study combines measurement with a direct test of cause and effect. The authors first group prompts by the pair of operand digits at a particular place. They look for neurons whose responses vary across these groups but stay comparatively stable when the arithmetic at that place is held fixed. Then they run a different problem and replace the activity of those neurons with activity recorded from the first problem. For instance, the base problem has answer 578 and the problem supplying the replacement activity has answer 773. Swapping activity in the units group produces 573 in the paper’s illustration. This answer retains the base problem’s hundreds and tens while taking its units digit from the other problem.

The most complete tests use systems that produce the whole answer as a single token, the unit of text they predict at each generation step. The separation into decimal places is therefore visible inside the computation even when the answer is emitted all at once. In one Llama 3 8B addition experiment, swapping the hundreds group raised the probability of the intended mixed answer from 0.23% to 45.79%. Gemma 2 9B, which emits numbers a digit at a time, shows a different distribution of activity. At the point where it must predict the hundreds digit, that place has the strongest group, and the authors also detect a shorter-lived tens group.

Carry experiments clarify what the separation amounts to. When the authors borrow activity from a problem with a carry, the targeted digit is more readily transferred than the carry’s effect on its neighbor. This suggests that the selected neurons convey digit information while other components may handle the interaction between places. Some individual neurons also respond to familiar patterns such as even answers or a particular range of values. The findings leave room for these local rules within a larger organization by decimal place. The paper establishes causal influence over individual answer digits and leaves the complete arithmetic procedure, including the assembly of the final answer, open.

Deep dive: Modular Arithmetic: Language Models Solve Math Digit by Digit

This study traces how language systems add and subtract by testing whether groups of neurons can change individual digits in an answer. · about 34 minutes to read

The problem and its context

What a correct answer leaves unresolved

Addition and subtraction offer a way to study reasoning because the answer is determinate and the inputs can be varied systematically. The same expression also supports several levels of description. It has whole operands, pairs of digits aligned by place, and a final answer with its own places. A successful prediction says that the relevant output was reached. It gives an investigator little leverage for deciding which of these descriptions corresponds to the internal computation.

The authors focus on a property of positional notation. In a problem without a carry or a borrow, the operation in the units place can be fixed while the tens and hundreds inputs vary. A researcher can therefore compare many problems that share one local task but differ in their operands and complete answers. If a neuron responds similarly across those problems, the local task is a plausible explanation for the similarity. Repeating this comparison at each place makes it possible to look for separate groups of neurons. Changing their activity then tests whether the distinction matters for what is predicted.

There is a further reason that decimal place is an interesting unit of analysis. Through tokenization, a string of digits can be assigned a single vocabulary entry. In the paper’s Llama example, 347 comes in as one unit and a complete three-digit answer can go out as one unit. Neither boundary gives a separate position in the input or output sequence to each of the digits. If the system nonetheless has different internal groups for the hundreds, tens, and units, those groups reveal an organization finer than the visible sequence of tokens.

In a system that predicts single digits, the visible sequence creates a different question. The first answer token already has a particular decimal place, and later places can be generated after it. It is natural to look for activity associated with the next digit at that point. The extra question is how far ahead the computation extends, especially when a carry from a lower place can change the digit that has to be emitted first. The paper’s comparison of number formats thus concerns when computations are useful as well as whether they can be localized by place.

From reading representations to testing their use

Earlier studies gave the authors reason to look for digits inside a whole-number token. In the work by Levy and Geva described in the paper, probes applied to internal states could recover individual decimal digits even though they failed to recover exact numerical values directly. A probe is a separately fitted readout that tries to extract a property from activity recorded during a computation. The work on Successor Heads likewise found evidence for information about numbers modulo 10. In decimal notation, this means information about the remainder on division by 10, which corresponds to the units digit.

These findings concern what a reader of the internal state can extract. A digit might be recoverable because the state reflects the spelling of the input. It might also be recoverable because it is used by a later stage of arithmetic. The probe result alone leaves these possibilities open. The present paper makes use of this distinction by asking whether swapping the activity associated with one place predictably changes that place in the output. It moves from a question about representation to a question about the role a representation plays.

The paper also places digit representations among other accounts of numerical information. It describes work in which numerical values are encoded along linear directions and work that considers a mixture of string-like and numerical properties. A separate line of research proposes that addition uses trigonometric representations arranged in generalized helices and a procedure described as a clock algorithm. These accounts concern the form of number representations or the operations that can be performed with them. A finding about which output digits can be influenced separately still leaves the precise form of the representations open. Linear representations of number values · Trigonometric representations for addition · Progress measures for grokking

Why look for groups of neurons?

The paper describes several explanations of arithmetic behavior at different levels of detail. One, developed in Arithmetic Without Algorithms, identifies individual neurons that respond to conditions on the operands or answer. A neuron might respond to an answer in a particular range or to a class of remainders. An assortment of such responses could help produce an answer. Another account, from the study of Claude-3.5 Haiku discussed by the authors, describes separate pathways for the approximate size of the result and its exact units digit. The first account directs attention to what individual neurons detect. The second suggests that different parts of an answer may receive different kinds of processing.

A range-sensitive neuron makes the connection between these levels concrete. For an answer between 900 and 999, the hundreds digit is 9. A neuron that distinguishes this range can be described in terms of whole-number magnitude or in terms of one decimal place. Its response alone leaves the broader organization unresolved. The authors ask whether such a neuron sits in a group that, when manipulated together, has a selective effect on the hundreds place. That group-level test makes it possible to take individual patterns seriously while asking how they fit into a larger computation.

The study belongs to mechanistic interpretability, which examines internal components to explain how a system produces a behavior. Earlier arithmetic work using causal mediation gave the authors a way to look for the layers involved in producing an answer. Work on factual associations provides another precedent for replacing internal activity and observing the downstream change. Here the intervention is designed around decimal places. The investigators can say in advance which answer should become more probable if the selected group influences one place and other sources of information retain their contribution. Arithmetic reasoning through causal mediation · Locating and editing factual associations

The method, step by step

Prepare problems with separable digit tasks

The authors begin with a dataset of 1000 addition prompts and a dataset of 1000 subtraction prompts. These are used to find candidate neurons. Each prompt uses a one-shot format. A worked example precedes a new expression whose answer is left for the system to generate. The addition demonstration shown in the paper is 157 + 431 = 588. The new problem has two operands drawn from 100 through 999, and the correct answer is also in that range. The examples are constructed to avoid carries in addition and the corresponding exchanges between places in subtraction.

Holding the answer length fixed gives every example a units, tens, and hundreds place. Avoiding exchanges between places gives each local task a well-defined relationship to the answer. For example, the units subtask in 347 + 231 is the ordered pair 7 and 1. Its contribution can be studied alongside other problems with the same pair, even when the numbers differ in the higher places. The authors do this independently for addition and subtraction. An ordered pair labels the digits in the first and second operands, a distinction that matters directly for subtraction and also lets the addition analysis track operand order.

The intervention data are built separately around pairs of prompts. One prompt is the base, the problem whose computation is going to be altered. The other is the source, the problem from which replacement activity is taken. In each pair the operation is the same. The paper constructs one set per operation in which the first operand varies and another in which the second operand varies. Each set contains 200 pairs of unique arithmetic problems. Here too, the main experiment excludes exchanges between places.

The changing operand differs at every digit. In the first-operand setting, the second operand is shared by base and source, and each digit of the first operand changes. In the second-operand setting, the first operand is shared and each digit of the second changes. Under the constraints of these problems, this design gives distinct base and source answer digits at each place. It makes it possible to recognize where a digit came from when a mixed answer appears. Keeping one operand fixed also gives the authors two controlled ways to vary the problem and check whether the result depends on which side was changed.

Work with existing systems and locate the relevant layers

The authors use pretrained base systems without instruction tuning or task-specific fine-tuning. The four systems are LLaMA3-8B, LLaMA3-70B, OLMo 2 7B, and Gemma 2 9B. All use decoder-only transformer and attention architectures. In this setting, a forward pass over the prompt produces probabilities for the next token. Llama and OLMo have a vocabulary entry for each operand and correct answer used in their experiments. Gemma instead predicts an answer digit at a time. The Llama 3 family

Within a transformer, the residual stream is the running state at each token position. Attention can bring information from earlier positions into that state, and a multilayer perceptron, or MLP, can transform the information available at a position. The study uses “neuron” for an individual unit inside an MLP. Its activation is a numerical response measured while processing a prompt. The last position of the unfinished expression is important because it provides the state from which the answer begins. For whole-number output, this is the point from which the complete result token is predicted.

The first localization step asks where the operands become available in that last-position state. The authors run a base and a source problem and replace the output of a module at a chosen layer with the corresponding output from the source. They test whole decoder blocks, attention modules, and MLP blocks in the layer investigation. For these swaps they track the probabilities of the full base and full source answers. A sharp increase in the source answer’s probability after an attention swap points to a layer where attention supplies information that changes what arithmetic is carried forward at the final position.

The authors use that evidence to set the earliest layers for their neuron search. The interpretation is that a group processing digits at the answer position needs access to the operands first. In LLaMA3-8B addition, the attention test points to layer 16 when the first operand changes and layer 15 when the second changes. The main addition interventions use layers 16 through 24 and 15 through 24, respectively. This starting point follows an experiment on information flow. It is different from the threshold that determines which individual neurons are included within those layers.

Finding and testing arithmetic circuits by digit place

The steps in order.

Finding and testing arithmetic circuits by digit placeStep 1: Generate arithmetic prompts without carries1. Generate arithmetic prompts without carriesStep 2: Locate layers that deliver operand information2. Locate layers that deliver operand informationStep 3: Group prompts by ordered digit pair3. Group prompts by ordered digit pairStep 4: Rank neuron activations with Fisher Scores4. Rank neuron activations with Fisher ScoresStep 5: Select candidate groups for each place5. Select candidate groups for each placeStep 6: Replace base activity with source activity6. Replace base activity with source activityStep 7: Compare probabilities of mixed answers7. Compare probabilities of mixed answers

Score each neuron for each decimal place

For a given operation, the authors record MLP activity as the identification prompts run. They then regroup the same prompts according to the position under study. The units grouping places together all prompts having the same ordered pair of units digits. The tens grouping uses the tens digits, and the hundreds grouping uses the hundreds. Each neuron is scored separately under these groupings. The aim is to find responses that track changes in a specified place across problems where the rest of the input can vary.

The paper writes each class label by concatenating the corresponding operand digits. The labels run from 00 through 99 as a naming scheme. For instance, 71 names the units class of 347 + 231. It represents the ordered pair 7 and 1, so its numerical magnitude plays no part in the analysis. In particular, classes close to each other when their labels are read as integers receive no special treatment. The datasets’ restrictions determine which labels have examples. A hundreds pair with a leading zero, for instance, would be incompatible with the three-digit operand requirement.

The Fisher Score uses differences between classes and variation inside each class. To compute it, the authors first average a neuron's activity within each observed class at the chosen place.

μᵢ,꜀,ᵈ = (1 / |𝒳꜀,ᵈ|) × ∑ₓ∈𝒳꜀,ᵈ aᵢ(x)

Here μᵢ,꜀,ᵈ is the average activation of neuron i for class c at decimal place d. The index i identifies a neuron within the layer being examined. The symbol c designates the ordered digit pair and d identifies units, tens, or hundreds. The set 𝒳꜀,ᵈ contains the prompts in that class for that place. The vertical bars give the number of prompts in the set. The symbol x denotes a prompt, and aᵢ(x) is the activation of neuron i on it. The sum runs over the prompts belonging to the class, as indicated by ∈. Multiplication by the reciprocal of the class size converts the sum to a mean.

The authors next measure how far the individual activations spread around their class mean. This step matters because a high average for one digit pair tells little about selectivity if prompts with that same pair cause very different responses.

σ²ᵢ,꜀,ᵈ = (1 / |𝒳꜀,ᵈ|) × ∑ₓ∈𝒳꜀,ᵈ (aᵢ(x) − μᵢ,꜀,ᵈ)²

The quantity σ²ᵢ,꜀,ᵈ is the variance for neuron i in class c at place d. For each prompt x in 𝒳꜀,ᵈ, the expression inside parentheses subtracts the class mean μᵢ,꜀,ᵈ from the observed activation aᵢ(x). The superscript ² squares that deviation. The sum collects the squared deviations and division by |𝒳꜀,ᵈ| takes their average.

They also need a reference level for the neuron across all the prompts for that position. They get it by weighting each class mean by the size of the class. This way, a digit pair represented by few prompts has proportionately less influence than a pair represented by many.

μᵢ,ᵈ = (1 / ∑꜀ |𝒳꜀,ᵈ|) × ∑꜀ |𝒳꜀,ᵈ| μᵢ,꜀,ᵈ

The symbol μᵢ,ᵈ stands for the overall activation mean of neuron i across the classes at place d. Each ∑꜀ sums over the digit-pair classes. In the second sum, the class size |𝒳꜀,ᵈ| weights the class mean μᵢ,꜀,ᵈ. The first sum gives the total number of prompts across those classes. Its reciprocal normalizes the weighted sum.

Finally, the Fisher Score compares the separation of the class means with the spread of the observations inside the classes.

Fᵢ,ᵈ = [∑꜀ |𝒳꜀,ᵈ| (μᵢ,꜀,ᵈ − μᵢ,ᵈ)²] / [∑꜀ |𝒳꜀,ᵈ| σ²ᵢ,꜀,ᵈ]

Here Fᵢ,ᵈ is the Fisher Score for neuron i at place d. In the numerator, μᵢ,꜀,ᵈ is the mean for class c and μᵢ,ᵈ is the overall mean. Their squared difference measures how far that class mean lies from the overall level. The denominator uses σ²ᵢ,꜀,ᵈ, the activation variance within each class. Both sums weight each class by |𝒳꜀,ᵈ|, the count of its prompts. The brackets group the between-class and within-class quantities on either side of the division.

A high score can arise when many prompts from a digit-pair class elicit a fairly consistent response and the response differs substantially across classes. Imagine a unit that behaves similarly whenever the units subtask is 7 + 1, across variation in the tens and hundreds. That response would contribute to discrimination under the units grouping. A neuron can also respond to a simpler property shared by several classes. The score will still reward the separation if the mean responses across classes differ enough. In this sense, selection is sensitive to place-specific structure without assuming what computation an individual neuron performs.

The authors rank neurons and apply a threshold to their scores. For each system, operation, decimal place, and threshold, membership consists of the neurons above the threshold in the eligible layers. The thresholds tested are 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, and 1.0. The paper treats this cutoff as a setting to be varied experimentally. Its scale is relative. Scores close to 0 convey little separation, the authors regard 0.1 through 1.0 as weak to moderate discrimination, and they interpret values above 1.0 as strong discrimination. There is no requirement at this step that a neuron qualify for only one place. Overlap between the sets is measured afterwards.

Intervene on a group and watch where the change lands

For the decisive test, the authors run the paired prompts and intervene during the base forward pass. At the last prompt token and in the selected layers, they replace the activations of neurons in the candidate group with the values from the same neurons on the source run. The rest of the computation continues on the base prompt. This is an interchange intervention, also called activation patching. It uses activity elicited by an actual arithmetic problem, so the donor values carry a concrete experimental meaning. Using a genuine source still creates a hybrid computation, since those values are now combined with activity from a different problem.

The paper illustrates this procedure with 347 + 231 as the base and 261 + 512 as the source. Their answers are 578 and 773. If the units group governs the units place, swapping its activity should make 573 more plausible. This is a stronger prediction than a generic change in the output. It also differs from a tendency to reproduce the source answer as a whole. By choosing the target in advance, the authors can test whether an intervention acts where the Fisher grouping said it should. The illustration uses two different operands in the two prompts. In the controlled datasets, one operand is held fixed.

To record all the designated alternatives in a whole-number-token experiment, the authors use a three-letter code read from hundreds through units. The letter b takes a digit from the base answer and s takes it from the source answer. The 8 variants include bbb for the unmodified base answer and sss for the complete source answer. The target is bbs for a units intervention, bsb for tens, and sbb for hundreds. Variants such as bss, sbs, and ssb are informative about effects that extend to more than one place. The authors compare the probability of each variant before and after the replacement.

Gemma’s first answer token calls for a different measurement. An intervention at the end of the prompt can be assessed on the probabilities of the base and source hundreds digits, which are competing candidates for the very next token. The whole-number comparison also checks whether the untargeted places stay fixed in the same prediction. The Gemma experiment, by construction, assesses the immediate digit instead of the full set of places in a single step. The authors use the pyvene library for the replacements and release the study’s code and data in the transformer-digit-arithmetic repository.

Experiments and results

Establishing the normal answer and measuring a change

The study first checks ordinary addition and subtraction accuracy on the neuron-identification datasets. The authors report performance above 95% on these simple tasks for the evaluated systems. This result establishes a starting behavior to investigate. The systems generally solve the problems as posed, so the intervention experiments can examine how an existing correct answer responds to changes in internal activity. The accuracy statement concerns the restricted arithmetic datasets and the one-shot prompt format.

The baseline for the main intervention is the same base prompt run without a swap. Comparing probabilities within that prompt controls for the wording, operands, and operation. Comparing result variants within an intervention tests the location of the effect. The base answer tracks whether the original behavior lost support. The intended hybrid tracks whether the selected place picked up the source digit. Other hybrids and the complete source answer test whether activity associated with additional places was transferred as well. These comparisons give more detail than reporting what fraction of intervened problems were still answered correctly, since a successful swap is designed to make an arithmetically different answer more likely.

The paired datasets also supply a comparison across operand roles. A group selected for units from the identification data can be tested when the units change on the first operand and when they change on the second. Analogous tests apply for the higher places. The paper presents the second-operand sets in its main results and includes the first-operand sets in the appendix. The datasets for the two operations keep the same basic design, making it possible to check whether the direction of the intervention holds across the addition and subtraction conditions.

The results distinguish changes in probability from changes in the most likely answer. Effect size is the change in a variant’s prediction probability, expressed in percentage points. Flip rate counts changes from the original base prediction to the specific intended hybrid. A variant can gain probability without becoming the most likely answer. Conversely, when the top prediction does flip from the base answer to the target, the new answer can be inspected directly for which digits it retained. The authors report both measures at the best threshold for each circuit.

Whole-number predictions change at the targeted place

The key pattern across the whole-number-token experiments is that the expected hybrid gains support for each of the three digit interventions. Replacing the units group favors bbs. Replacing the tens group favors bsb, and replacing the hundreds group favors sbb. The authors report the same direction of effect in the addition and subtraction pairs and under either choice of varying operand. The original base answer generally loses probability. Variants with multiple source digits show much smaller changes, an important observation because those variants offer a way to detect a broader transfer from the source.

A numerical example comes from Llama 3 8B on the second-operand addition set. The hundreds group is selected with a Fisher threshold of 0.9. Before patching, the answer that combines the source hundreds with the base tens and units has probability 0.23%. After patching that group, its probability is 45.79%. The paper reports the gain as 45.56 percentage points. The comparison is for the probability of the targeted hybrid on that dataset. It measures neither ordinary answer accuracy nor the frequency of flips.

Probability of the targeted hybrid on second-operand addition pairs in Llama 3 8B

Swapping the hundreds group raises support for the source hundreds digit combined with the base tens and units.

Probability of the targeted hybrid on second-operand addition pairs in Llama 3 8BBase run: 0.23Base run0.23Hundreds-group intervention (this paper): 45.79Hundreds-group intervention (this paper)45.79
The numbers
System or settingprediction probability %
Base run0.23
Hundreds-group intervention (this paper)45.79

The target remains a single whole-number token in this experiment, even though the intervention is defined through a digit. Consider the authors’ pairing of the base answer 579 with the source answer 685. A swap affecting only the hundreds place should favor the variant that begins with the source hundreds digit and ends with the last two digits from the base. A swap that carries general information about the source answer could instead favor the full source result or hybrids containing several source digits. Evaluating all the designated variants is what allows the authors to distinguish these effects. A high probability for an arbitrary changed answer would be much less informative.

The reported probabilities also give the observed selectivity its proper scale. The hundreds example shows a large shift toward an answer the base run rarely favors. A 45.79% probability can still leave substantial probability elsewhere. The flip results therefore address a separate question. The authors report that the intended hybrid often replaces the base answer as the prediction, with similar behavior in the first- and second-operand sets. The probabilistic result is evidence of directed influence even on examples where the change falls short of a flip.

The operating thresholds vary by place. The paper gives 0.5 for units, 0.6 for tens, and 0.9 for hundreds in its Llama 3 8B addition circuit statistics. At these settings, it reports that neurons associated with the digit groups account for an average of 60.3% of MLP neurons per layer in the relevant part of the addition computation. This describes the groups collectively at the chosen settings. The circuits can be differentiated by place while spanning a substantial portion of the available units. Broad interventions can therefore provide evidence about the function of a population even when its internal division of labor is still unknown.

Comparing systems and the timing of number generation

The other whole-number-token systems support the same qualitative finding while using different intervention layers. In OLMo 2 7B, the attention tests find operand delivery for both addition pair sets starting at layer 17, with the corresponding MLP interventions extending through layer 30. For subtraction, the reported start is layer 19 for first-operand variation and layer 17 for second-operand variation. In LLaMA3-70B, layer 39 is the reported start for both kinds of pairs in both operations. Its interventions run through layer 56 for addition and layer 58 for subtraction. These ranges are settings for the intervention analyses. Their variation illustrates how the authors localize circuits within each system rather than assuming the same layer numbers recur everywhere.

The comparison across systems matters because there are several possible sources of specificity. An effect could reflect idiosyncratic features of one layer range or one choice of base and source prompts. Finding the same sort of hybrid in systems with different layer ranges, and with either operand allowed to vary, supports a shared organization at the level of decimal place. It leaves open how the individual neurons and layers implement that organization. In particular, the study compares roles of selected groups and the effects of swapping them. It does not align individual neurons across systems.

In Gemma 2 9B, the appendix finds a different allocation at the moment the first digit is predicted. The attention analysis points to layer 28 as the place to look for operand information, with a minimal effect in the first-operand subtraction condition. For both operations, the authors find a large hundreds group that remains present through the final layer. They describe it as spanning 70-90% of the MLP neurons per layer on average. A sizable tens group appears from layers 28 to 31 and then diminishes sharply. No units group meets the selection criterion at this stage. These findings describe the activations available at the prompt’s end, before lower answer digits have been emitted.

Intervening on the Gemma hundreds group effectively shifts the immediate prediction from the base digit toward the source digit on the second-operand addition and subtraction sets. The authors note that this is an invasive swap because the group spans most of the MLP units in the relevant layers. The tens group is of interest for a different reason. Its presence before the first output suggests some processing of a digit beyond the one about to be printed, and the authors propose a possible connection to carry handling. The hundreds swap directly tests the role of the group for the next digit. The shorter-lived tens activity supplies evidence about which information is present at that point.

Taken together, the two output formats reveal why a comparison of next-token probabilities has to respect the unit being predicted. In Llama and OLMo, a selective shift toward a hybrid shows that the system can change one digit inside a token while preserving its other digits. In Gemma, a shift towards the source hundreds digit shows control of the immediate next token. The accompanying localization of tens activity provides a second observation about decimal place, but the causal comparison is narrower. The paper’s cross-format finding is that activity can be organized by decimal place in either format. The strongest evidence for simultaneous selective control of several places comes from the systems that output the entire result together.

What the ablations show

Changing the layer range or the score cutoff

The layer-depth ablation for Llama 3 8B addition starts from the same relevant region and extends the intervention farther into the network. The appendix explicitly compares layers 15 through 24 with layers 15 through 28 on the second-operand addition set. The authors report no significant difference from using the deeper range. The shallower range was chosen using the size of the groups and tests of whether their activity was sufficient to identify the local subtask. Extending the range probes whether swapping more late-layer activity materially changes the effect.

This comparison supports the sufficiency of the shorter patch for producing the measured shift. It addresses the marginal value of intervening on additional layers after the earlier groups have already been swapped. It leaves room for later layers to process the consequences of the swap or to participate in turning the modified state into an output. The experiment would answer a different question if the authors patched only the extra late layers or traced the downstream effect of each earlier layer individually. The result here is specifically about the added effect of extending an intervention.

Varying the Fisher threshold changes which neurons are exchanged. A lower cutoff admits responses with weaker evidence of class separation. A higher cutoff gives a smaller group of the most selective responses. This matters because a score is assigned one neuron at a time, whereas the intervention outcome depends on the group working together. Removing some neurons can affect how much digit information is transferred. Adding others can bring in responses associated with a broader set of properties. The threshold curves therefore test the group selected at several cutoffs. The best-threshold measurements describe the particular groups used in the main effect summaries.

The membership analysis gives another view of what thresholding changes. For Llama 3 8B, the authors report that when the cutoff is at least 0.7, overlap between the digit groups is generally below 2%. The low overlap speaks to whether the same units repeatedly qualify for different decimal places. The finding belongs to the higher cutoffs, while the collective size reported for the best addition settings includes places with lower cutoffs. Each number describes its own selection condition. Even where membership is mostly distinct, the groups can contribute to a common state that is read out as one answer.

Checking whether the selected neurons carry the digit-pair information

The authors also compare two classifiers built with linear discriminant analysis, or LDA. This procedure learns to identify a class using measured features. For each layer and decimal place, one classifier sees the full MLP activation vector. The other sees only the activity of neurons that pass the relevant Fisher cutoff. Each predicts which ordered pair of operand digits appeared at the specified place. The full vector provides the reference for how much label information a linear classifier can recover before feature selection.

The reduced classifier retains high accuracy especially in middle layers 15–24 in the Llama 3 8B analysis. The units and hundreds groups are particularly effective at supporting the readout. The tens group also supports it at lower cutoffs, where more neurons are available. Accuracy falls in later layers. The authors suggest that units and hundreds information may have a more redundant or compact representation and that tens information may require more neurons. Those possibilities concern how readily the chosen features support linear decoding. The experiment leaves the detailed code for each digit unresolved.

This test gives “sufficiency” a specific meaning. The selected neurons provide enough information for a fitted classifier to recover the input digit pair with high accuracy in the relevant layers. The target is the pair of digits in the operands. The learned classifier is an instrument for reading them, and the system’s own answer probabilities are measured separately. The output intervention adds causal evidence because changing those neurons alters the answer in a way related to the same place. Conversely, a high classification score on its own would be compatible with information that simply remains readable in the state.

An additional comparison looks at the activation vectors directly. The authors compute cosine similarity between the selected neurons’ responses to prompts that share a subtask. Cosine similarity measures how closely two vectors point in the same direction. The paper’s example pairs 154 + 635 with 137 + 611 because their hundreds subtask is 1 + 6. As a reference for ordinary similarity in the same neurons, the authors also evaluate 5000 random sample pairs. In layer 15, addition pairs sharing the units computation have an average similarity of 0.84 in the units group. Across places, the paper reports high similarities within the matched groups.

This analysis adds a geometric view of the same activations. The Fisher ranking evaluates individual neurons relative to the labeled classes. Cosine similarity checks whether their joint response recurs when the designated local problem recurs. The random pairs help show how much similarity is typical without that matching rule. Because the subtask labels guide the original neuron selection too, the result is best read as a characterization of the selected groups. The independent reason to think that this similarity matters to the answer comes from exchanging those groups between problems.

Comparing addition with subtraction

To see whether the same neurons support corresponding places in both operations, the authors compare their high-scoring sets in Llama 3 8B. For the top 100 neurons under the Fisher ranking, the reported average overlap is 19% for units, 9.2% for tens, and 19.8% for hundreds. The comparison is made for the same place across operations, with membership examined by layer. It addresses a different kind of overlap from the comparison of units, tens, and hundreds groups within addition.

The low overlaps show that the most selective neurons for an operand pair in one operation frequently differ from the most selective neurons for that same place in the other. The result matters because the two tasks use decimal digits in the same positions. If place alone determined the strongest activity patterns, a greater reuse of the highest-ranked units would be plausible. The observed memberships are compatible with operation-specific processing within a shared organization by place. A ranked-list comparison leaves shared components outside the selected sets, and it gives no direct test of what would happen if an addition group were patched into a subtraction run.

Introducing carries from the source problem

The main datasets make local tasks separable by excluding carries and borrowing. The supplementary addition experiments ask what happens when the source problem requires a carry and the base does not. The authors test two directions of carry, with 200 samples in each. In each case, there is a candidate answer that borrows just the source digit and a second candidate that also adjusts the neighboring base digit. This comparison asks whether a group can transfer both a local result and the local result’s influence on the next place.

In the units-to-tens condition, 347 + 231 gives the base answer 578. The source, 347 + 415, gives 762 and has a carry out of the units. The authors swap the units group. If only the source units digit is transferred, the corresponding answer is 572. If the carry also transfers and raises the base tens digit, the corresponding answer is 582. The latter prediction requires an effect that extends beyond the place selected by the intervention, so the two alternatives distinguish a local output contribution from the transfer of its carry.

The second experiment moves the question up one place. The same base expression has answer 578, and the source 347 + 482 has answer 829 with a carry from tens to hundreds. Swapping the tens group favors a test of 528, the hybrid with the source tens and the original neighboring digits. The carry-adjusted candidate is 628. The comparison holds the type of intervention fixed and asks whether probability follows the replacement digit alone or also moves toward an answer with its effect on the higher place.

In both scenarios, the variant with just the targeted source digit shows the strongest increase in probability. The effect on its carry-adjusted counterpart is considerably smaller. The behavior suggests that the selected units and tens groups can convey information about their own answer digits without reliably conveying the associated change to the higher place. The authors infer that other mechanisms may determine or process the carry. The experiment detects a separation in what the patch transfers. It does not locate the other components or trace the normal path of a carry in an unmodified problem.

There is an asymmetry in this design that matters for interpretation. The carry is present in the source computation, but the surrounding parts of the patched run still come from a no-carry base. The experiment tests whether donor activity can bring along a downstream consequence under those conditions. A carry could depend on signals or interactions outside the group selected on the no-carry data. The outcome therefore narrows what can be attributed to the swapped neurons. It also explains why the authors use the carry comparison to qualify independence, since arithmetic with carries still involves a dependency between positions.

Inspecting the patterns in individual neurons

The qualitative analysis asks what the selected groups contain. For LLaMA 3 8B, the authors examine the 20 highest-scoring neurons per digit group per layer across layers 15–24. For each place, they plot the mean activity as a function of the digit in the first operand and the digit in the second. This organizes the responses by local inputs. It can reveal whether a neuron responds to a particular operand digit, a property of the local answer, or a pattern spanning several digit pairs.

One units neuron responds to even answers. Parity can be determined from the units place, so the response fits its membership in the units group. A hundreds neuron responds to results in the range 900–999, which can be described as sensitivity to a hundreds digit of 9. The paper gives examples of other responses, including units activity associated with a 2 in the second operand’s units place, a tens response associated with a 0 in the first operand’s tens place, and units activity associated with a result digit of 6. These patterns show that a high Fisher Score can capture a recognizable property shared across several classes.

The analysis helps reconcile two scales of description. A single neuron can respond to a simple condition and a group containing it can selectively affect one digit. The group intervention demonstrates the latter, while the response plots characterize the former. A neuron that tracks a result range can therefore be interpreted in the context of its group’s place-specific role. The authors treat this finding as preliminary. The plots document examples among highly ranked units and provide no census of how common each pattern is or how the responses are combined to produce the answer. Arithmetic Without Algorithms

Limitations

Limits the authors identify

The authors restrict their conclusions to addition and subtraction. They do not investigate multiplication or division and leave open how the framework would apply there. Even for the operations tested, they separate the causal contribution of the digit groups from the final assembly of the answer. In a system that predicts a whole three-digit token, information corresponding to different places must ultimately influence one vocabulary decision. The experiments show that this decision can respond selectively to a swap. The authors leave the circuits responsible for combining the digit information to future work.

The main analysis concentrates on MLP neurons. The attention interventions offer evidence about when operand information arrives where the answer will be predicted. They do not resolve the contribution of individual attention heads or of other components of the residual stream to the arithmetic itself. This gap matters especially for dependencies such as carry propagation. The carry tests tell us what the selected MLP groups are unlikely to transfer by themselves, and the paper leaves the mechanism handling that dependency open.

The authors also emphasize that Fisher scoring is a straightforward way to find candidate groups. It can identify units that separate classes across the studied systems, but the measured circuits are broad. They suggest that other approaches, such as attribution based on gradients, may identify more precise sets. The causal results support the groups as intervention targets. How much of each group is essential, and which units could be removed while maintaining the same selectivity, remain distinct questions.

Limits that follow from the experimental design

The main result concerns a carefully restricted family of prompts. Operands and answers have three digits, prompts use a worked example, and the primary datasets exclude arithmetic exchanges across places. That restriction is part of the experiment’s logic because it makes a targeted hybrid easy to interpret. Generalization to different prompt formats, wider numbers, or chains of dependencies across places would require evidence under those conditions. The supplementary carry work increases the range of cases studied, but it tests transfers from particular carry-producing examples into no-carry base runs. The paper does not trace how the system solves an unrestricted distribution of carry problems or borrowing problems.

An interchange intervention establishes what changes when one set of activations is exchanged in a specific context. It does not establish that every swapped neuron is required in an ordinary run or that the selected sets are the only pathways carrying the relevant information. The size of the groups makes this distinction practically important. A large set can have a clear aggregate effect while containing units that make redundant, indirect, or small contributions. Similarly, membership is defined by a class-discrimination score, so neurons that matter only through interactions may rank poorly on their own. The depth comparisons and classifier analysis narrow the account of the groups, but their functions are still described mostly at population level.

The before-and-after comparison is strongest for the pre-defined variants. A small shift in the probability of multi-source variants argues against simply transferring the entire source answer. The measured variants still represent a selected set of possibilities within the broader output distribution. Other answers can use digits from neither of the original results. The reported flip measure adds information about the most likely outcome. Together these metrics support selective influence, while leaving open a fuller accounting of where probability goes after an intervention.

The threshold analyses also distinguish discovery from evaluation. Candidate neurons are ranked using the identification datasets, and the paper summarizes the patching results at the best threshold for each group. This demonstrates which of the tested settings produce strong effects in the study. It leaves a further question about how a fixed cutoff chosen in advance would perform on fresh prompts or on a different arithmetic distribution. The different best thresholds across places show why “digit-specific circuit” refers to a set identified under a defined scoring and intervention procedure, with membership sensitive to the cutoff.

Finally, the cross-tokenization comparison changes the point at which each result is available for measurement. For a whole-number answer, one intervention can be evaluated against mixtures of all three output digits. In Gemma, the paper observes the first prediction and looks for information about other places in the state leading to it. A units group absent at that point could become relevant when later tokens are generated. The analysis supports a dominant role for the hundreds group at the first step and a more limited tens representation alongside it. The timing and causal organization of later answer steps would require testing those steps directly.

These limits also set the scope of the paper’s claim about arithmetic strategies. A selective edit reveals that a group participates in generating a particular answer place. The heatmaps show that some members track patterns that can be expressed as local rules. Taken together, those findings specify an organization and several of its components. They leave room for more than one detailed account of how the system arrives at the individual digit, handles dependencies, and selects the token that expresses the result.

What came after

The Lookahead Limitation addresses why addition with multiple operands is difficult. The present paper also cites it in discussing how far ahead a system may compute when it emits numbers digit by digit. The result attributed to that work is that a system internally prepares one digit beyond the digit currently needed for generation, which can account for a carry, and does not prepare further digits at that step. The connection is about the timing of place-specific computation. A system about to emit a higher digit can benefit from information about the lower place that might change it.

That result gives the authors a way to interpret the Gemma findings. Before the first answer token, they observe a dominant hundreds group, a shorter-lived tens group, and no units group under their selection procedure. The hundreds group is relevant to the digit being emitted. The tens group is positioned to supply information about the next lower place, which could affect the hundreds through a carry. The selective hundreds intervention confirms control of the immediate prediction. The possible carry role of the tens group remains an interpretation informed by the lookahead result.

The documented relationship between the studies thus turns on how much of a number must be available at a particular generation step. The digit-circuit experiments test whether parts of an answer can be influenced separately, including when they are emitted together in one token. The lookahead work asks how much additional computation accompanies an immediate digit prediction and connects that question to difficulty with multiple operands. Its specific contribution discussed in the digit-circuit paper is the limited span of advance digit computation. The account establishes this conceptual connection without specifying a reuse of the Fisher selection procedure or the interchange interventions.

Cite

Cite as Tanja Baeumel, Daniil Gurgurov, Yusser al Ghussin, Josef van Genabith and Simon Ostermann. 2025. Modular Arithmetic: Language Models Solve Math Digit by Digit. arXiv:2508.02513.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.48550/arxiv.2508.02513 · arXiv 2508.02513

@misc{baeumel2025modular,
  title = {{Modular Arithmetic: Language Models Solve Math Digit by Digit}},
  author = {Tanja Baeumel, Daniil Gurgurov, Yusser {al Ghussin}, Josef {van Genabith} and Simon Ostermann},
  year = {2025},
  doi = {10.48550/arxiv.2508.02513},
  eprint = {2508.02513},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.48550/arxiv.2508.02513}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/baeumel-2025-modular-arithmetic-language-models-solve/

References

25 references, from the paper's own bibliography.

  1. Tanja Baeumel, Josef van Genabith, and Simon Ostermann. 2025. The lookahead limitation: Why multi-operand addition is hard for llms (https://api.semanticscholar.org/CorpusID:276647483). ArXiv, abs/2502.19981. OpenAlex ↗ · Scholar ↗
  2. Chunyuan Deng, Zhiqi Li, Roy Xie, Ruidi Chang, and Hanjie Chen. 2024. Language models are symbolic learners in arithmetic. arXiv preprint arXiv:2410.15580. OpenAlex ↗ · Scholar ↗
  3. P. E. H. R. O. Duda and D. G. Stork. 2001. Pattern classification. Wiley-Interscience Publication. OpenAlex ↗ · Scholar ↗
  4. Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, et al. 2021. A mathematical framework for transformer circuits. Transformer Circuits Thread. Https://transformer-circuits.pub/2021/framework/index.html. OpenAlex ↗ · Scholar ↗
  5. Rhys Gould, Euan Ong, George Ogden, and Arthur Conmy. 2023. Successor heads: Recurring, interpretable attention heads in the wild. arXiv preprint arXiv:2312.09230. our card
  6. Aaron Grattafiori, Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, et al. 2024. The llama 3 herd of models (https://arxiv.org/abs/2407.21783). Preprint, arXiv:2407.21783. our card
  7. Quanquan Gu, Zhenhui Li, and Jiawei Han. 2012. Generalized fisher score for feature selection (https://arxiv.org/abs/1202.3725). Preprint, arXiv:1202.3725. OpenAlex ↗ · Scholar ↗
  8. Subhash Kantamneni and Max Tegmark. 2025. Language models use trigonometry to do addition (https://arxiv.org/abs/2502.00873). Preprint, arXiv:2502.00873. our card
  9. Amit Arnold Levy and Mor Geva. 2024. Language models encode numbers using digit representations in base 10. arXiv preprint arXiv:2410.11781. OpenAlex ↗ · Scholar ↗
  10. Jack Lindsey, Wes Gurnee, Emmanuel Ameisen, Brian Chen, Adam Pearce, et al. 2025. On the biology of a large language model (https://transformer-circuits.pub/2025/attribution-graphs/biology.html). Transformer Circuits Thread. OpenAlex ↗ · Scholar ↗
  11. Raja Marjieh, Veniamin Veselovsky, Thomas L Griffiths, and Ilia Sucholutsky. 2025. What is a number, that a large language model may know it? arXiv preprint arXiv:2502.01540. OpenAlex ↗ · Scholar ↗
  12. Kevin Meng, David Bau, Alex Andonian, and Yonatan Belinkov. 2023. Locating and Editing Factual Associations in GPT (https://doi.org/10.48550/arXiv.2202.05262). arXiv preprint. ArXiv:2202.05262 [cs]. our card
  13. Neel Nanda, Lawrence Chan, Tom Lieberum, Jess Smith, and Jacob Steinhardt. 2023. Progress measures for grokking via mechanistic interpretability (https://doi.org/10.48550/arXiv.2301.05217). arXiv preprint. ArXiv:2301.05217 [cs]. our card
  14. Yaniv Nikankin, Anja Reusch, Aaron Mueller, and Yonatan Belinkov. 2024. Arithmetic without algorithms: Language models solve math with a bag of heuristics (https://arxiv.org/abs/2410.21272). Preprint, arXiv:2410.21272. our card
  15. Chris Olah, Nick Cammarata, Ludwig Schubert, Gabriel Goh, Michael Petrov, and Shan Carter. 2020. Zoom in: An introduction to circuits. Distill, 5(3):e00024–001. OpenAlex ↗ · Scholar ↗
  16. Team OLMo, Pete Walsh, Luca Soldaini, Dirk Groeneveld, Kyle Lo, et al. 2024. 2 olmo 2 furious (https://arxiv.org/abs/2501.00656). Preprint, arXiv:2501.00656. OpenAlex ↗ · Scholar ↗
  17. Alessandro Stolfo, Yonatan Belinkov, and Mrinmaya Sachan. 2023. A Mechanistic Interpretation of Arithmetic Reasoning in Language Models using Causal Mediation Analysis (http://arxiv.org/abs/2305.15054). arXiv preprint. ArXiv:2305.15054 [cs]. our card
  18. Lin Sun, Tianxiang Wang, Weiping Ding, Jiucheng Xu, and Yaojin Lin. 2021. Feature selection using fisher score and multilabel neighborhood rough sets for multilabel classification (https://doi.org/10.1016/j.ins.2021.08.032). Information Sciences, 578:887–912. OpenAlex ↗ · Scholar ↗
  19. Gemma Team. 2024. Gemma (https://doi.org/10.34740/KAGGLE/M/3301). OpenAlex ↗ · Scholar ↗
  20. B Venkatesh and J Anuradha. 2019. A review of feature selection and its methods. Cybern. Inf. Technol, 19(1):3–26. OpenAlex ↗ · Scholar ↗
  21. Jesse Vig, Sebastian Gehrmann, Yonatan Belinkov, Sharon Qian, Daniel Nevo, Yaron Singer, and Stuart Shieber. 2020. Investigating Gender Bias in Language Models Using Causal Mediation Analysis (https://proceedings.neurips.cc/paper/2020/hash/92650b2e92217715fe312e6fa7b90d82-Abstract.html). In Advances in Neural Information Processing Systems, volume 33, pages 12388–12401. Curran Associates, Inc. OpenAlex ↗ · Scholar ↗
  22. Zhengxuan Wu, Atticus Geiger, Aryaman Arora, Jing Huang, Zheng Wang, Noah Goodman, Christopher Manning, and Christopher Potts. 2024. pyvene: A library for understanding and improving PyTorch models via interventions (https://doi.org/10.18653/v1/2024.naacl-demo.16). In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 3: System Demonstrations), pages 158–165, Mexico City, Mexico. Association for Computational Linguistics. OpenAlex ↗ · Scholar ↗
  23. Wei Zhang, Chaoqun Wan, Yonggang Zhang, Yiu ming Cheung, Xinmei Tian, Xu Shen, and Jieping Ye. 2024. Interpreting and improving large language models in arithmetic calculation (https://arxiv.org/abs/2409.01659). Preprint, arXiv:2409.01659. OpenAlex ↗ · Scholar ↗
  24. Yongchao Zhou, Uri Alon, Xinyun Chen, Xuezhi Wang, Rishabh Agarwal, and Denny Zhou. 2024. Transformers can achieve length generalization but not robustly (https://arxiv.org/abs/2402.09371). Preprint, arXiv:2402.09371. our card
  25. Fangwei Zhu, Damai Dai, and Zhifang Sui. 2025. Language models encode the value of numbers linearly (https://aclanthology.org/2025.coling-main.47/). In Proceedings of the 31st International Conference on Computational Linguistics, pages 693–709, Abu Dhabi, UAE. Association for Computational Linguistics. our card