Key idea of this section
Adding n-digit numbers costs Θ(n). Schoolbook multiplication costs Θ(n²). Karatsuba (1960): (aB + b)(cB + d) = acB² + [(a + b)(c + d) − ac − bd]B + bd, cost O(n1.585). FFT methods: Schönhage–Strassen (1971) O(n log n log log n); Harvey–van der Hoeven (2019) O(n log n). Division costs a constant times multiplication.
Kolmogorov's conjecture and its refutation
Write M(n) for the number of bit operations needed to multiply two n-bit integers. Schoolbook multiplication shows M(n) = O(n²), and for millennia no one suspected that one could do better. In a seminar at Moscow State University in 1960, Andrey Kolmogorov conjectured that Θ(n²) is optimal. Within a week a 23-year-old student in the seminar, Anatoly Karatsuba, found a faster method, and Kolmogorov closed the seminar; the result was published in 1962 under the names of Karatsuba and Ofman.
Karatsuba's algorithm
Split n-digit numbers in base B as x = aBᵐ + b and y = cBᵐ + d with m = ⌈n/2⌉. Then
xy = ac B²ᵐ + (ad + bc) Bᵐ + bd, ad + bc = (a + b)(c + d) − ac − bd
so three multiplications of half-size numbers (ac, bd and (a + b)(c + d)) and a linear number of additions suffice, instead of four. Applied recursively this gives the recurrence T(n) = 3T(n/2) + O(n).
Theorem 12.1 (Master theorem, simple form). If T(n) = aT(n/b) + Θ(n) with a > b ≥ 2, then T(n) = Θ(nlogb a).
Proof sketch. The recursion tree has logb n levels; level j has aʲ subproblems of size n/bʲ, costing Θ(n (a/b)ʲ) in total. This geometric series is dominated by its last term, Θ(n (a/b)logb n) = Θ(alogb n) = Θ(nlogb a). ∎
Thus Karatsuba multiplication costs Θ(nlog₂ 3) = Θ(n1.58496…). For n = 2ᵏ single digits the recursion performs exactly 3ᵏ single-digit multiplications against 4ᵏ for the schoolbook method: 2187 against 16384 at k = 7.
Worked Example 12.2 — 1234 × 5678 with one level of Karatsuba. Here a = 12, b = 34, c = 56, d = 78 with B = 10 and m = 2, so Bᵐ = 100:
ac = 12 · 56 = 672, bd = 34 · 78 = 2652, (a + b)(c + d) = 46 · 134 = 6164 ad + bc = 6164 − 672 − 2652 = 2840 xy = 672 · 10⁴ + 2840 · 10² + 2652 = 6720000 + 284000 + 2652 = 7006652
Toom–Cook
Karatsuba's trick is polynomial interpolation in disguise: x and y are values at B of linear polynomials, their product is a quadratic polynomial, and a quadratic is determined by three values (at 0, 1 and ∞ in Karatsuba's version). Toom (1963) and Cook (1966) generalised this by splitting into k pieces: the product of two polynomials of degree k − 1 has degree 2k − 2 and is determined by 2k − 1 values, giving T(n) = (2k − 1)T(n/k) + O(n) and cost Θ(nlogk(2k − 1)). Toom-3 has exponent log₃ 5 ≈ 1.465. Since logk(2k − 1) → 1 as k → ∞, for every ε > 0 there is an O(n1+ε) algorithm, though the constants grow rapidly with k.
The fast Fourier transform
Taking the evaluation points to be N-th roots of unity, with N a power of 2 at least the length of the product, turns evaluation and interpolation into the discrete Fourier transform, which the fast Fourier transform computes in O(N log N) ring operations. The FFT was published by Cooley and Tukey in 1965, but Gauss had used the method around 1805 for interpolating asteroid orbits. To multiply integers: write them as digit sequences, i.e. polynomials evaluated at the base, compute the cyclic convolution of the digit sequences by FFT, pointwise multiplication and inverse FFT, and finally propagate carries.
The ring in which the FFT runs is a design choice. Over ℂ with floating-point arithmetic one needs an error analysis to be sure that rounding to the nearest integer recovers the exact convolution. Alternatively, the number-theoretic transform works in ℤ/pℤ for a prime p = c · 2ᵏ + 1, which contains primitive 2ᵏ-th roots of unity because (ℤ/pℤ)× is cyclic of order p − 1; a popular choice is p = 998244353 = 119 · 2²³ + 1. Schönhage and Strassen (1971) worked in ℤ/(2K + 1)ℤ, where 2 is a root of unity of order 2K so that multiplications by roots of unity are mere shifts, and obtained M(n) = O(n log n log log n). Schönhage and Strassen conjectured that Θ(n log n) is the true complexity. Fürer (2007) improved the bound to n log n · 2O(log* n), and in 2019 David Harvey and Joris van der Hoeven gave an algorithm with M(n) = O(n log n) (Annals of Mathematics, 2021), so the upper bound now matches the conjecture. No matching lower bound is known for general models of computation; Ω(n log n) has been proved only for restricted models or conditionally on conjectures in network coding.
The hierarchy of practical algorithms is visible in libraries such as GMP, which switch from schoolbook to Karatsuba to several Toom variants and finally to FFT multiplication as operand sizes grow past tuned thresholds. Record computations of π to trillions of digits rest entirely on FFT multiplication.
Division and other operations
Theorem 12.3. Division of n-bit numbers can be performed in O(M(n)) bit operations.
Proof sketch. To compute 1/d, use Newton's method on g(x) = 1/x − d, which gives the iteration
xₖ₊₁ = xₖ(2 − d xₖ), with error eₖ = 1 − d xₖ satisfying eₖ₊₁ = eₖ²
since 1 − d xₖ(2 − d xₖ) = (1 − d xₖ)². The number of correct bits doubles at each step, so step k need only be carried out with about 2ᵏ bits of precision. The total cost is O(M(n) + M(n/2) + M(n/4) + ⋯) = O(M(n)), assuming M(n)/n is nondecreasing; then a/d = a · (1/d) costs one more multiplication, and a final correction fixes the last bit of the quotient. ∎
Similar Newton iterations give square roots in O(M(n)). Conversion between binary and decimal, and the gcd by the Knuth–Schönhage half-gcd algorithm, cost O(M(n) log n), compared with O(n²) for the naive methods. Modular exponentiation aᵉ mod m with n-bit numbers costs O(n) modular multiplications by the square-and-multiply method of Lesson 7, hence O(n M(n)) bit operations, which is what makes RSA practical. The analogous question for matrices remains open: Strassen (1969) showed that n × n matrices can be multiplied in O(nlog₂ 7) = O(n2.807) operations, and the best known exponent ω is now below 2.372, but whether ω = 2 is unknown.
Exercise
- (a)Apply Newton's iteration for 1/7 from x₀ = 0.1 three times, and verify that the error eₖ = 1 − 7xₖ squares at each step.
- (b)Compute 47 × 83 by one level of Karatsuba with B = 10.
- (c)How many single-digit multiplications does fully recursive Karatsuba use for two 64-digit numbers, compared with the schoolbook method?
Show solution
Answers: (a) x₁ = 0.1(2 − 0.7) = 0.13, x₂ = 0.13(2 − 0.91) = 0.1417, x₃ = 0.1417(2 − 0.9919) = 0.14284777. The errors are e₀ = 0.3, e₁ = 0.09, e₂ = 0.0081, e₃ = 0.00006561, each the square of the one before; 1/7 = 0.142857142…. (b) a = 4, b = 7, c = 8, d = 3: ac = 32, bd = 21, (a + b)(c + d) = 11 · 11 = 121, so ad + bc = 121 − 32 − 21 = 68 and the product is 3200 + 680 + 21 = 3901. (c) 64 = 2⁶, so Karatsuba uses 3⁶ = 729 single-digit multiplications against 64² = 4096.