Arithmetic
Addition and Subtraction
1994. Intel ships the Pentium. The recall costs USD 475 million. The cause: a bug in the partial remainder table - which is multi-digit addition. Every time a CPU adds numbers, it runs the same algorithm taught in schools as column addition. Just in nanoseconds.
- **Neural network quantization**: INT8/INT4 replaces float32 with integer fixed-point additions. Apple Neural Engine in M1 runs this for every transformer layer
- **Karatsuba algorithm**: multiplying large numbers through recursive additions - the basis of Python BigInteger and Java BigDecimal. Faster than naive multiplication for numbers longer than ~70 digits
- **Carry lookahead adder**: hardware acceleration of column addition - parallel carry pre-computation in TPU, Apple Neural Engine, and FPGA for ML inference
Column Algorithm and Carry Propagation
1994. Intel ships the Pentium. The recall costs USD 475 million. The cause: a bug in the partial remainder table - which is multi-digit addition. Every time a CPU adds numbers, it executes exactly what school textbooks call column addition. Just in nanoseconds.
Column addition is not a classroom ritual. It is an algorithm with carry propagation that lives in every ALU on the planet. When Apple Neural Engine adds thousands of INT8 values during neural network quantization, the same carry logic runs - simultaneously across millions of cells.
**Carry lookahead adder** in processors pre-computes all carries in parallel, without waiting for each previous one. That is why adding 64-bit numbers takes ~1 clock cycle, not 64. The school column algorithm is the direct ancestor of this logic.
Neural network quantization (INT8/INT4) replaces float32 operations with integer fixed-point additions. GPT-4 in inference mode performs billions of such additions. The precision of quantization depends on correct carry propagation - that same carry from the column algorithm.
When computing 487 + 356 with column addition, what carry arises in the tens column?
Subtraction via Complement
Subtraction is not a standalone operation. It is addition with a complement. The scheme works identically in decimal and binary - which is why processors have no dedicated subtraction circuit. A subtractor is an adder plus an inverter.
Two's complement is not just transistor savings. It is mathematical elegance: numbers form the ring Z_n, where -k is equivalent to 2^n - k. Addition works automatically; the carry out of range is discarded. Karatsuba's algorithm multiplies large numbers through recursive additions - Python BigInteger and Java BigDecimal use it internally.
**Column subtraction** is the same complement idea in decimal: when a digit is too small, one unit is borrowed from the next higher column. That borrowed unit equals 10. After borrowing, it reduces to ordinary addition with a complemented value.
Why does a processor have no dedicated subtraction circuit?
Mental Math: Splitting, Rounding, Compensation
Mental arithmetic is not about speed. It is about choosing the right decomposition. The same idea drives Karatsuba's algorithm: split a large problem into smaller ones that are cheaper to solve. Karatsuba multiplies 1000-digit numbers using three additions instead of four - recursively, down to the base case.
All four tricks rely on one property: commutativity and associativity of addition. Subtraction lacks these properties - which is why the order matters in the compensation trick. 521 - 198 = 521 - 200 + 2, but not 521 + 200 - 2.
**The golden rule:** turn inconvenient numbers into round ones, then compensate the difference. 99 + 47 = 100 + 47 - 1 = 146. This is not a trick - it is the distributive property in action.
Subtraction is just reverse addition and shares all the same properties
Subtraction loses commutativity and associativity
7 - 3 = 4, but 3 - 7 = -4. (10 - 5) - 2 = 3, but 10 - (5 - 2) = 7. Compilers account for this when reordering arithmetic expressions.
What is the fastest way to compute 998 + 347 mentally?
Key Ideas
- Column addition = digit-by-digit with carry propagation; carry is the atomic operation of an ALU
- Subtraction is implemented via complement: a - b = a + (-b); two's complement in CPUs is the same idea
- Addition is commutative and associative; subtraction is not; this determines which mental tricks are valid
- Mental math tricks - round up, split by place, compensation - all rest on associativity of addition
Related Topics
Addition and subtraction are the foundation for more complex operations:
- Multiplication and Division — Multiplication is repeated addition; Karatsuba uses recursive additions
- Integers and Absolute Value — Signs and magnitude - the basis for operations over Z
- Order of Operations — When +/- apply inside compound expressions
- Binary System — Column addition in base 2 - the language of the processor
- Computer Arithmetic — Overflow, carry lookahead, integer operations in hardware
Вопросы для размышления
- The Pentium FDIV bug was in division, yet its fix required redesigning the entire arithmetic pipeline. Why does an error in one operation affect addition?
- Why is subtraction not commutative while addition is? What would change in algebra if the situation were reversed?
- Karatsuba multiplies via recursive additions. Why is that faster than straightforward multiplication?
Связанные уроки
- ar-02-integers — Integers and sign rules are the foundation for operations
- ar-04-multiplication — Multiplication is repeated addition; column algorithm scales up
- ar-05-order — Order of operations determines when +/- apply
- ar-26-binary — Binary addition is the same column algorithm in base 2
- ar-28-modular — Modular addition - carry wraps around the ring Z_n
- ar-45-computer-arithmetic — Carry lookahead adder - hardware column algorithm in ALU
- calc-01-sequences