NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Neural Arithmetic Units

Andreas Madsen, Alexander Rosenberg Johansen

Introduction

While standard neural networks are powerful universal function approximators, they are notoriously poor at basic, exact arithmetic. If you train a standard Multi-Layer Perceptron (MLP) to add numbers between 1 and 100, it will likely fail miserably when asked to compute 1,000 + 1,000. This failure stems from a lack of inductive bias for arithmetic; standard networks perform curve-fitting within their training distribution rather than learning the underlying, generalizable logic of mathematical operations.

Previous attempts to solve this, such as the Neural Arithmetic Logic Unit (NALU), proved fragile. They struggled with optimization, failed when scaled to large hidden layers, and were prone to exploding gradients. A major culprit was the inclusion of division, which creates mathematical singularities when dividing by near-zero values.

To address these shortcomings, researchers have developed two new, theoretically grounded neural network components: the Neural Addition Unit (NAU) and the Neural Multiplication Unit (NMU). These units possess the necessary inductive biases to learn exact arithmetic operations and extrapolate to numbers far outside their training distribution.

A Back-to-Basics Approach: NAU and NMU

The authors propose splitting arithmetic into two specialized units, avoiding the pitfalls of previous all-in-one approaches.

1. Neural Addition Unit (NAU) The NAU learns to select elements from an input vector and either add or subtract them. It utilizes a weight matrix clamped between -1 and 1. Crucially, it incorporates a sparsity regularizer that forces weights toward exactly -1, 0, or 1. This effectively "programs" the network to cleanly pick specific inputs for addition or subtraction, treating the operation as discrete logic rather than a continuous approximation.

2. Neural Multiplication Unit (NMU) Designed to multiply subsets of a vector, the NMU abandons the logarithmic transformations used in previous models (which fail with negative numbers). Instead, it uses a linear gating mechanism defined by the equation $z = \prod (W x + 1 - W)$. If a weight $W$ is 1, the input is multiplied; if it is 0, the input is effectively ignored (multiplied by 1).

Diagram of the Neural Multiplication Unit (NMU) architecture, illustrating the gating mechanism where inputs are either multiplied or bypassed based on the learned weights.

3. Theoretical Initialization and No Division The authors performed a detailed variance analysis to determine the optimal weight initialization, ensuring gradients do not vanish or explode in deep architectures. Furthermore, by design, the NMU does not support division. The researchers argue that the search for a differentiable division operator often breaks the optimization of the much more common multiplication operator due to the "Division Singularity"—a phenomenon where near-zero denominators create incredibly spiky and unstable loss landscapes.

Key Insights and Performance

The models were evaluated on synthetic benchmark datasets (learning functions like $t = (x_1 + x_2) \cdot (x_3 + x_4)$) and Sequential MNIST, where the model must output the cumulative product or sum of a sequence of digit images.

The results demonstrate a massive leap in reliability and performance over prior methods:

  • Unprecedented Success Rates: On a 10-parameter multiplication task, the NMU achieved a 94% success rate, completely eclipsing the 13% success rate of the previous NAC unit and 26% for the NALU.
  • Perfect Extrapolation: While standard networks and NALU saw errors skyrocket when tested on numbers outside their training range, the NAU and NMU maintained near-zero error. This proves they learned the actual "rule" of the math, not just a local approximation.
  • Stability and Interpretability: The NAU and NMU converged much faster and more consistently across different random seeds. Because of the sparsity constraints, the final weight matrices are often human-readable, showing exactly which input indices the model decided to add or multiply.
Performance comparison charts showing the NMU (purple triangles) consistently achieving higher success rates and lower sparsity errors across different hidden sizes and interpolation ranges compared to NALU and NAC variants.

Limitations and Future Work

Despite these successes, challenges remain. The authors note that "soft gating"—using a learned mechanism to automatically choose between an addition unit and a multiplication unit—is often the weakest link in a combined architecture. The gate frequently converges to a random choice early in training, preventing the model from learning the correct operation. Solving this "sparse gating" problem is a major area for future research.

Additionally, while removing division dramatically improved stability, it inherently limits these units from solving problems involving fractions or ratios. Finally, while the units handle overparameterization better than NALU, they still perform optimally when the network architecture closely matches the complexity of the underlying mathematical problem.

Summary updated

BibTeX
@inproceedings{madsen2020neural,
  author = {Andreas Madsen and Alexander Rosenberg Johansen},
  title = {{Neural Arithmetic Units}},
  booktitle = {International Conference on Learning Representations},
  year = {2020},
}
Figure