Papers
Topics
Authors
Recent
Search
2000 character limit reached

Modular Addition (mod 97)

Updated 5 July 2026
  • Modular addition mod 97 is the operation that reduces a sum to a unique residue in the set {0,…,96}, forming the basis for arithmetic in Z₉₇.
  • It plays a vital role in diverse fields by underpinning neural sequence modeling, reversible circuit synthesis, and quantum arithmetic through precise wrap-around handling.
  • The technique leverages auxiliary-modulus training to minimize wrap frequency and optimize both theoretical insights and empirical performance in modular learning tasks.

Modular addition modulo $97$ is the operation that maps an integer sum to its unique residue in {0,,96}\{0,\dots,96\}. For integers a,ba,b, the quantity a+bmod97a+b \bmod 97 is the unique r{0,,96}r\in\{0,\dots,96\} such that ra+b(mod97)r\equiv a+b \pmod{97}. Although elementary as a definition, modular addition mod $97$ occupies several technically distinct roles in current research: it is a basic operation in the ring Z97\mathbb{Z}_{97}, a nontrivial target function for neural sequence models, and a core arithmetic primitive in reversible and quantum circuit synthesis (Kikuchi et al., 8 May 2026, Oumarou et al., 2021, Oonishi et al., 2020).

1. Algebraic definition and elementary arithmetic

For modulus $97$, each residue class has a unique representative in {0,,96}\{0,\dots,96\}. Accordingly,

{0,,96}\{0,\dots,96\}0

This is the standard modular-addition rule specialized to {0,,96}\{0,\dots,96\}1 (Kikuchi et al., 8 May 2026).

The operation can be read informally as ordinary addition followed by reduction by {0,,96}\{0,\dots,96\}2. If the ordinary sum already lies in {0,,96}\{0,\dots,96\}3, nothing further happens. Thus {0,,96}\{0,\dots,96\}4, so {0,,96}\{0,\dots,96\}5. If the sum exceeds {0,,96}\{0,\dots,96\}6, one subtracts a multiple of {0,,96}\{0,\dots,96\}7 until the result returns to the residue range. Since {0,,96}\{0,\dots,96\}8 and {0,,96}\{0,\dots,96\}9, one obtains a,ba,b0. The same rule applies to longer sums: a,ba,b1, and a,ba,b2, hence

a,ba,b3

In the sequence-based formalism used in recent learning work, modular addition is the function

a,ba,b4

For mod a,ba,b5, this becomes

a,ba,b6

The case a,ba,b7 is the parity function, so parity is a special case of modular addition rather than a distinct problem class (Kikuchi et al., 8 May 2026).

2. Wrap-around, carries, and digit-system structure

A central structural feature of modular addition is wrap-around: the sum crosses a multiple of the modulus and must be reduced back into the residue set. In the learning-theoretic treatment, the number of wraps around modulus a,ba,b8 for input a,ba,b9 is

a+bmod97a+b \bmod 970

For mod a+bmod97a+b \bmod 971, a+bmod97a+b \bmod 972 records how many times the unreduced sum crosses multiples of a+bmod97a+b \bmod 973. The cited work treats wrap frequency as a proxy for task difficulty: more wraps correspond to a more sensitive input-output mapping (Kikuchi et al., 8 May 2026).

A distinct but related perspective comes from additive combinatorics, where one studies carries induced by a digit system. For a base a+bmod97a+b \bmod 974, a digital set a+bmod97a+b \bmod 975 is a complete set of residues modulo a+bmod97a+b \bmod 976. If a+bmod97a+b \bmod 977, a carry occurs when the sum does not remain inside the chosen digit set. In the modular setting of digital sets a+bmod97a+b \bmod 978, the paper formulates carry occurrence through the condition a+bmod97a+b \bmod 979, and studies the frequency

r{0,,96}r\in\{0,\dots,96\}0

Under the paper’s hypotheses, asymptotically every such digital system has carry frequency at least r{0,,96}r\in\{0,\dots,96\}1, and balanced digit sets are extremal or near-extremal (Monopoli, 2015).

For modulus r{0,,96}r\in\{0,\dots,96\}2, the digital-set framework has a subtle specialization. Since r{0,,96}r\in\{0,\dots,96\}3 is prime, the only nontrivial divisor choice in the strict r{0,,96}r\in\{0,\dots,96\}4 setup is r{0,,96}r\in\{0,\dots,96\}5, and then a digital set of size r{0,,96}r\in\{0,\dots,96\}6 inside r{0,,96}r\in\{0,\dots,96\}7 must be all of r{0,,96}r\in\{0,\dots,96\}8, making carries trivial. Nontrivial carry-minimization phenomena relevant to mod r{0,,96}r\in\{0,\dots,96\}9 therefore arise either in ordinary base-ra+b(mod97)r\equiv a+b \pmod{97}0 representations whose total sums are later reduced mod ra+b(mod97)r\equiv a+b \pmod{97}1, or in higher-lifted settings such as base-ra+b(mod97)r\equiv a+b \pmod{97}2 digits inside ra+b(mod97)r\equiv a+b \pmod{97}3 (Monopoli, 2015). A common misconception is that carry-minimization results “for mod ra+b(mod97)r\equiv a+b \pmod{97}4” directly concern arithmetic internal to ra+b(mod97)r\equiv a+b \pmod{97}5; in the strict digital-set model, they do not.

3. Modular addition mod 97 as a learning problem

Recent work studies modular addition as a supervised learning task for Transformers and related architectures. In that setting the model receives ra+b(mod97)r\equiv a+b \pmod{97}6 and must predict ra+b(mod97)r\equiv a+b \pmod{97}7. The cited paper emphasizes that such tasks are hard despite their algorithmic simplicity, and that difficulty increases with the number of summands ra+b(mod97)r\equiv a+b \pmod{97}8, the modulus size ra+b(mod97)r\equiv a+b \pmod{97}9, and especially the amount of wrap-around (Kikuchi et al., 8 May 2026).

The paper’s main proposal is an auxiliary-modulus training scheme. Instead of always training on the target $97$0, one mixes labels from modulus $97$1 and modulus $97$2, where $97$3: $97$4 For mod $97$5, one may take $97$6 and, for example, $97$7, so that the auxiliary target is mod $97$8. The inputs remain $97$9; only the training label changes (Kikuchi et al., 8 May 2026).

The theoretical motivation is that enlarging the modulus reduces wrap frequency. If Z97\mathbb{Z}_{97}0 are i.i.d. uniform on Z97\mathbb{Z}_{97}1, the paper shows that the expected wrap proxy under auxiliary-modulus mixing is scaled by

Z97\mathbb{Z}_{97}2

Thus the method reduces effective difficulty while leaving the input distribution unchanged. This is its key contrast with the earlier sparse method, which makes training inputs contain more zeros, thereby reducing the effective number of summands but introducing a covariate shift between training and test data (Kikuchi et al., 8 May 2026).

For mod Z97\mathbb{Z}_{97}3, the paper reports successful hyperparameter choices including Z97\mathbb{Z}_{97}4 for Z97\mathbb{Z}_{97}5 with angular embedding, Z97\mathbb{Z}_{97}6 for Z97\mathbb{Z}_{97}7, and Z97\mathbb{Z}_{97}8 for Z97\mathbb{Z}_{97}9. This suggests that modest $97$0 and moderate $97$1 are already effective in the small-prime-modulus regime, not only at very large moduli. A second misconception is therefore that a modulus as small as $97$2 makes the problem trivial for generic neural architectures; the reported experiments do not support that view.

4. Empirical behavior at $97$3

The paper evaluates models using two metrics. Match accuracy is exact correctness on the residue class. For large moduli and continuous angular outputs, it also uses relaxed $97$4-accuracy, where a prediction is counted as correct if its circular distance from the true label is at most $97$5. For $97$6 and $97$7, the tolerance is approximately $97$8, so predictions within about $97$9 to {0,,96}\{0,\dots,96\}0 positions on the residue circle are accepted (Kikuchi et al., 8 May 2026).

For token embedding at {0,,96}\{0,\dots,96\}1 with {0,,96}\{0,\dots,96\}2M samples, the auxiliary-modulus method substantially outperforms the sparse baseline across sequence lengths:

{0,,96}\{0,\dots,96\}3 Auxiliary modulus method Sparse method
8 90.1% match accuracy 74.9% match accuracy
16 81.9% match accuracy 1.1% match accuracy
32 62.2% match accuracy 1.0% match accuracy

The same study states that angular embeddings perform even better for periodic tasks, with match accuracies near {0,,96}\{0,\dots,96\}4 for moderate {0,,96}\{0,\dots,96\}5 at {0,,96}\{0,\dots,96\}6 (Kikuchi et al., 8 May 2026). The empirical pattern is consistent with the paper’s theoretical emphasis on wrap reduction and with the representation advantage of circular outputs for periodic labels.

The paper also places the {0,,96}\{0,\dots,96\}7 results inside a broader scalability narrative. At {0,,96}\{0,\dots,96\}8 and {0,,96}\{0,\dots,96\}9, training on {0,,96}\{0,\dots,96\}00K samples yields {0,,96}\{0,\dots,96\}01 {0,,96}\{0,\dots,96\}02-accuracy at {0,,96}\{0,\dots,96\}03 for the auxiliary-modulus method, whereas the sparse method achieves {0,,96}\{0,\dots,96\}04 on the same data size and {0,,96}\{0,\dots,96\}05 even when extended to {0,,96}\{0,\dots,96\}06M samples (Kikuchi et al., 8 May 2026). Although these figures are not specific to mod {0,,96}\{0,\dots,96\}07, they indicate that the same training principle remains effective as both sequence length and modulus grow.

5. Reversible and quantum realizations for modulus {0,,96}\{0,\dots,96\}08

In reversible and quantum arithmetic, modular addition typically appears as a map of the form

{0,,96}\{0,\dots,96\}09

where {0,,96}\{0,\dots,96\}10 is quantum, while {0,,96}\{0,\dots,96\}11 and {0,,96}\{0,\dots,96\}12 are classical constants. For modulus {0,,96}\{0,\dots,96\}13, one has

{0,,96}\{0,\dots,96\}14

so {0,,96}\{0,\dots,96\}15 fits in {0,,96}\{0,\dots,96\}16 bits. The width-optimized Toffoli-based construction therefore takes {0,,96}\{0,\dots,96\}17, uses an {0,,96}\{0,\dots,96\}18-qubit data register to hold intermediate carries, and requires a total of {0,,96}\{0,\dots,96\}19 qubits: {0,,96}\{0,\dots,96\}20 data qubits, one garbage qubit, and one flag qubit (Oumarou et al., 2021).

The construction combines a recursive constant adder with the Vedral–Barenco–Ekert modular-addition scheme. Operationally, it adds the classical constant {0,,96}\{0,\dots,96\}21, subtracts {0,,96}\{0,\dots,96\}22, tests the sign of the result through the most significant bit, conditionally re-adds {0,,96}\{0,\dots,96\}23 if the subtraction went negative, and then performs a cleanup sequence that restores all ancillas to {0,,96}\{0,\dots,96\}24. The paper emphasizes that this realizes modular reduction without a separate comparator and uses only Toffoli, CNOT, and NOT gates before Clifford+{0,,96}\{0,\dots,96\}25 decomposition (Oumarou et al., 2021).

For modulus {0,,96}\{0,\dots,96\}26, the paper works through the example {0,,96}\{0,\dots,96\}27 with {0,,96}\{0,\dots,96\}28. Since {0,,96}\{0,\dots,96\}29 and {0,,96}\{0,\dots,96\}30, the desired output is {0,,96}\{0,\dots,96\}31. In the circuit logic, the register first reaches the binary encoding of {0,,96}\{0,\dots,96\}32, then the encoding of {0,,96}\{0,\dots,96\}33 after subtraction of {0,,96}\{0,\dots,96\}34, the sign flag remains zero because the subtraction is nonnegative, and the cleanup sequence restores the ancillas while leaving the main register in state {0,,96}\{0,\dots,96\}35 (Oumarou et al., 2021).

The same paper contrasts its approach with Fourier-basis adders. Its stated advantage is that it does not require small-angle rotations and their Clifford+{0,,96}\{0,\dots,96\}36 decomposition. For mod {0,,96}\{0,\dots,96\}37, this yields an exact Toffoli-based constant modular adder with {0,,96}\{0,\dots,96\}38 logical qubits and linear depth in {0,,96}\{0,\dots,96\}39 (Oumarou et al., 2021).

6. Controlled modular addition, carry-lookahead synthesis, and resource trade-offs

A second quantum-circuit line of work studies the controlled modular adder

{0,,96}\{0,\dots,96\}40

where {0,,96}\{0,\dots,96\}41 is a control qubit and {0,,96}\{0,\dots,96\}42 are classical constants. This is the primitive needed in modular multiplication and modular exponentiation. For {0,,96}\{0,\dots,96\}43, one again sets {0,,96}\{0,\dots,96\}44, since {0,,96}\{0,\dots,96\}45, and encodes all residues on {0,,96}\{0,\dots,96\}46 bits (Oonishi et al., 2020).

The architecture in the cited paper is built from two comparators and one controlled-controlled adder on top of a Draper–Kutin–Rains–Svore carry-lookahead adder. Its total logical width is {0,,96}\{0,\dots,96\}47, so specialization to modulus {0,,96}\{0,\dots,96\}48 gives {0,,96}\{0,\dots,96\}49 qubits: one control qubit, a {0,,96}\{0,\dots,96\}50-qubit data register {0,,96}\{0,\dots,96\}51, a {0,,96}\{0,\dots,96\}52-qubit ancilla data register {0,,96}\{0,\dots,96\}53, one comparator flag, and {0,,96}\{0,\dots,96\}54 carry/propagate ancillas (Oonishi et al., 2020).

The paper optimizes with respect to {0,,96}\{0,\dots,96\}55, defined as the product of qubit count and circuit depth. In the fault-tolerant setting it focuses on {0,,96}\{0,\dots,96\}56, and in the NISQ setting on {0,,96}\{0,\dots,96\}57. Using relative-phase Toffoli gates, it reports a control modular adder that uses only {0,,96}\{0,\dots,96\}58 of the number of {0,,96}\{0,\dots,96\}59 gates of the original and only {0,,96}\{0,\dots,96\}60 of the number of CNOT gates of the original; it further states that {0,,96}\{0,\dots,96\}61 is {0,,96}\{0,\dots,96\}62 of the original (Oonishi et al., 2020).

At the asymptotic resource level, the same paper gives {0,,96}\{0,\dots,96\}63 {0,,96}\{0,\dots,96\}64 gates for its {0,,96}\{0,\dots,96\}65-optimal control modular adder, {0,,96}\{0,\dots,96\}66 CNOT gates for the NISQ-oriented construction, CNOT depth {0,,96}\{0,\dots,96\}67, and {0,,96}\{0,\dots,96\}68 (Oonishi et al., 2020). For {0,,96}\{0,\dots,96\}69, the paper’s specialization yields rough figures of {0,,96}\{0,\dots,96\}70 {0,,96}\{0,\dots,96\}71 gates, approximately {0,,96}\{0,\dots,96\}72 CNOTs, CNOT depth approximately {0,,96}\{0,\dots,96\}73, and {0,,96}\{0,\dots,96\}74. These numbers are substantially larger than the {0,,96}\{0,\dots,96\}75-qubit constant-adder construction because the objectives differ: one design minimizes width for constant modular addition, while the other optimizes controlled modular addition under carry-lookahead and relative-phase-Toffoli cost models. This suggests complementarity rather than contradiction between the two circuit families.

7. Conceptual synthesis for modulus {0,,96}\{0,\dots,96\}76

Across algebra, machine learning, additive combinatorics, and quantum computing, modular addition mod {0,,96}\{0,\dots,96\}77 is the same formal map but not the same technical object. In bare arithmetic it is reduction of a sum to the residue set {0,,96}\{0,\dots,96\}78. In sequence learning it is the target function

{0,,96}\{0,\dots,96\}79

whose difficulty is governed in part by wrap frequency and whose learnability can be improved by auxiliary-modulus training without inducing input-side covariate shift (Kikuchi et al., 8 May 2026). In additive combinatorics it is connected to carry phenomena through digit systems, although the strict digital-set model is degenerate at {0,,96}\{0,\dots,96\}80 itself and becomes nontrivial only in lifted or external-base representations (Monopoli, 2015). In reversible and quantum circuit design it appears both as a width-sensitive constant-adder problem with {0,,96}\{0,\dots,96\}81 qubits for modulus {0,,96}\{0,\dots,96\}82 and as a control-sensitive carry-lookahead problem with {0,,96}\{0,\dots,96\}83 qubits and explicit {0,,96}\{0,\dots,96\}84-count/CNOT-depth trade-offs (Oumarou et al., 2021, Oonishi et al., 2020).

Taken together, these results make clear that “modular addition mod {0,,96}\{0,\dots,96\}85” is not merely a textbook residue calculation. It is also a benchmark for sensitivity in learned arithmetic, a vehicle for carry-minimization theorems, and a standard primitive for exact fault-tolerant arithmetic synthesis.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Modular Addition (mod 97).