Four-Digit Addition Analysis
- Four-digit addition (FDA) is a structured operation on 4-digit vectors where standard addition computes sums with carry using base-dependent digit interpretation.
- Its algebraic formulation allows various group laws, ranging from full carry to carry-free operations, by partitioning digit vectors into contiguous blocks.
- Transformer studies of FDA reveal digit-wise subroutines and carry propagation mechanisms achieving over 95% accuracy, highlighting both computational strengths and edge-case challenges.
Four-digit addition (FDA) denotes the addition of two 4-digit quantities, most commonly in base 10, but it also admits a more general formalization as an abelian-group law on the digit-vector space . In algebraic treatments, FDA distinguishes full integer addition with carry from coordinatewise modular addition and mixed blockwise operations; in mechanistic interpretability, it serves as a clear probe of whether Transformers encode carries, digit structure, and output selection algorithmically rather than through superficial pattern matching (Hellekalek, 2012, Quirke et al., 2023, Yan, 9 Jun 2025).
1. Formal definition and representational conventions
Let be an integer base and let
The set of length-4 digit vectors is
An element is written as
with the least significant digit first. The corresponding integer interpretation is given by
and denotes the inverse map from residues modulo back to 4-digit vectors. Standard FDA is then
which is addition with carry across all four positions. The contrasting operation is coordinatewise addition without carry,
For prime base 0, these are the two basic types of digit-vector addition: addition with carry and addition without carry, also called XOR-addition in the binary case (Hellekalek, 2012).
2. Algebraic classification of four-digit additions
The algebraic theory of FDA is not limited to the usual schoolbook operation. For prime base 1, every abelian group of order 2 is isomorphic to a product
3
To realize such a group law on 4, one chooses a composition of 5, cuts the digit vector into contiguous blocks of those lengths, and performs integer addition with carry inside each block. A block of length 6 is simply addition without carry. The eight compositions of 7 are
8
Because the number of compositions of 9 is 0, there are at least
1
different additions on 2 arising from compositions alone. Standard FDA corresponds to the single-block composition 3, hence to 4; fully carry-free FDA corresponds to 5, hence to 6. The intermediate compositions, such as 7, permit carries within blocks but block them across boundaries. The same paper further shows that, for prime base 8, compositions together with automorphisms of the residue groups generate
9
different additions on 0 (Hellekalek, 2012).
3. FDA as an algorithm in one-layer Transformers
Mechanistic work on a one-layer Transformer trained for 1-digit integer addition characterizes addition as a composition of local subtasks rather than as a monolithic operation. The paper explicitly trains and analyzes 5-, 10-, and 15-digit models, and states that for a 4-digit addition task the same algorithm would apply. In the 4-digit specialization, the model receives
2
and predicts a 5-digit answer
3
The discovered subroutines are BaseAdd, MakeCarry1, UseSum9, UseCarry1, and UseSum9Cascade. In summarized form, the current answer digit is computed as
4
where the effective carry depends on whether the previous column produced a carry and, in rare cases, whether a carry must propagate through a column whose digit pair sums to 5. With three heads, the roles separate cleanly: one head attends to the current digit pair and computes BaseAdd, one attends to the previous digit pair and computes MakeCarry1 and UseSum9, and one attends to the previous-previous digit pair and computes an additional carry signal used in cascade logic. The MLP then combines these features as a 6 key space, yielding a 60-way key-value mechanism for digit prediction (Quirke et al., 2023).
4. Carry propagation, parallel digit streams, and edge cases
The one-layer Transformer does not implement a human-style sequential right-to-left routine with a persistent carry register. Instead, it uses parallel digit-specific streams: each answer digit is computed in a dedicated row after the full question has been revealed, and the necessary information is re-read from the input by attention. This gives a time-dense circuit in which current, previous, and previous-previous digit pairs suffice for most cases. The boundary digits are treated differently: the units digit requires only BaseAdd, while the most significant answer digit is learned fastest because, in 7-digit plus 8-digit addition, it is constrained to be 9 or 0 (Quirke et al., 2023).
The principal failure mode is cascading UseSum9. Simple sum-to-9 cases are handled correctly, but cases in which a carry must propagate through multiple consecutive 9-columns remain weak and error-prone. Examples include 1 and, in the four-digit regime, extreme patterns such as 2. The paper attributes this to the fixed-depth, left-to-right, one-layer architecture: the model can look back two digit positions reliably, but longer carry chains are structurally difficult. For FDA, this implies that typical inputs are tractable, while the hardest cases are those in which carries traverse several adjacent columns whose local sums equal 3 (Quirke et al., 2023).
5. Layer-wise FDA trajectories in LLaMA-3-8B-Instruct
A separate line of work probes LLaMA-3-8B-Instruct on multi-digit addition using the prompt format "Calculate: num1 + num2 = ", always reading the hidden state of the trailing space before the first answer token is generated. The model has 32 transformer layers, achieves overall arithmetic accuracy of 97.29%, and attains 95.51% accuracy on four-digit addition. The central result is a four-stage trajectory in the forward pass. First, formula-structure representations become linearly decodable: probes trained only on 2-digit operands decode the expression type of 4-digit additions with nearly 100% accuracy by about layer 14, even though 4-digit problems are out of distribution for probe training. Second, core computational features emerge: in three-digit settings, carry detection begins a reliable upward trend around layer 14 and is near 100% by layer 19, while exact sum-class prediction rises sharply around layer 16 and is approximately 100% by layer 19 and above. Third, numerical abstractions of the result become clearer: for three-digit sums, hundreds, tens, and units digits become increasingly decodable from about layers 19–25, and by layer 28 and beyond all three positions are decoded with high, stable accuracies, near perfect in practice. Fourth, final content organization and token selection occur near the output: in logit-lens analysis of 3-digit43-digit53-digit problems, the earliest layer at which the correct first result token becomes top-1 always lies between layers 23 and 31, with a peak at layer 30 where about 45.4% of examples first become correct (Yan, 9 Jun 2025).
For FDA specifically, two quantitative observations are explicit: four-digit answer accuracy is 95.51%, and formula-type decodability for 4-digit expressions is nearly perfect by layer 14. The paper does not train separate probes for a 4-digit result’s thousands place. This suggests, rather than directly proves, that the digit-wise abstraction observed for three-digit outputs extends to thousands, hundreds, tens, and ones in four-digit sums. The same caution applies to carry structure beyond the hundreds place: the three-digit carry probes show coherent positional carry signals, and a plausible implication is that four-digit carries are represented by the same mechanism repeated over one additional position (Yan, 9 Jun 2025).
6. Generalization, limitations, and scientific significance
FDA occupies an unusual position: it is simultaneously elementary arithmetic, a finite-group classification problem, and a mechanistic benchmark for sequence models. In LLaMA-3-8B-Instruct, accuracy remains above 93% for 1- to 6-digit addition except for a slight drop at 5 digits, and the structural probes trained on 2-digit data generalize almost perfectly to 4-digit expressions. In the same study, a hundreds-digit probe trained on addition generalizes to multiplication with peak accuracy above 6 and to subtraction with peak accuracy around 7–8, indicating partially operation-general digit representations. These observations support the paper’s interpretation of a hierarchical process that favors internal computation over rote memorization, while also underscoring that probe and logit-lens evidence is correlational rather than causal (Yan, 9 Jun 2025).
The limitations are equally clear. The LLaMA study restricts itself to the single prompt format "Calculate: a+b = " and does not test alternative phrasings, vertical layouts, or spacing variations. Its explicit carry and digit probes are conducted on three-digit outputs, not four-digit outputs. The one-layer Transformer study does not explicitly train a 4-digit model, although it states that the same algorithm would apply, and its failure on cascading UseSum9 cases shows that correct local behavior does not guarantee exact handling of all edge cases. The algebraic classification, for its part, clarifies that “four-digit addition” is not uniquely defined once one abstracts away from standard integer interpretation: only the single-block composition 9 yields ordinary integer addition modulo 0; all other group laws on 1 alter carry propagation by construction (Hellekalek, 2012, Quirke et al., 2023, Yan, 9 Jun 2025).
Taken together, these results position FDA as a compact but technically rich object of study. In algebra, it exemplifies how carry structure determines the group law on digit vectors. In mechanistic interpretability, it exposes whether a model has learned structure recognition, carry computation, digit-wise abstraction, and late-stage token commitment. In both settings, the central issue is the same: whether the apparent simplicity of four-digit sums conceals a genuinely structured computation.