How Does Strassen’s Recursive Matrix Multiplication Work?
At a glance
- 1. Split the matrices
Partition each matrix into four equally sized blocks, then treat those blocks as entries in a 2-by-2 matrix.
- 2. Compute seven products
Form seven carefully chosen recursive products instead of the eight products used by ordinary block multiplication.
- 3. Combine the results
Use additions and subtractions of the seven products to construct the four blocks of the answer.
- 4. Recurse to a cutoff
Repeat on smaller blocks until reaching a size where ordinary multiplication is more efficient.
Strassen’s algorithm is a divide-and-conquer method for multiplying square matrices. Its key idea is to reduce the number of recursive block multiplications from eight to seven, at the cost of doing more additions and subtractions.
For sufficiently large matrices, that tradeoff can reduce the number of arithmetic operations. Here is the block formula, a worked example, and the complexity analysis.
Split each matrix into four blocks
Write two matrices, with a power of 2 (or after padding to such a size), as
Each block is an matrix. Ordinary block multiplication uses eight block multiplications to calculate the four blocks of . Strassen’s method replaces those eight products with seven:
The products are matrix products of half-size blocks. They can be calculated by applying Strassen’s method recursively, until the blocks are small enough for ordinary multiplication.
Combine the seven products
Construct the four blocks of the result from the values:
These identities produce the same result as ordinary matrix multiplication. Matrix multiplication is not generally commutative, so keep the factor order in each exactly as written.
Worked example
Take
For matrices, each block is a single number. Substituting the entries into the seven formulas gives
Now combine them:
Thus
As a check, the top-left entry from ordinary multiplication is , and the other entries agree as well.
Why the algorithm is faster asymptotically
At each recursive level, Strassen makes seven multiplications on matrices of size . The additions and subtractions of blocks take operations, so the recurrence, for power-of-two sizes, is
By the Master Theorem,
This grows more slowly than the arithmetic complexity of the standard algorithm. The bound describes asymptotic operation counts, not a guarantee that Strassen is faster for every matrix size or computer. For small blocks, the extra additions and implementation overhead can outweigh the saved multiplications, so practical implementations switch to ordinary multiplication below a chosen cutoff.
Implementation details and common mistakes
- Stopping condition: Use ordinary matrix multiplication at a base-case size rather than recursing indefinitely. The best cutoff depends on the implementation and hardware.
- Uneven dimensions: The simplest recursive version assumes a power-of-two matrix size. For arbitrary sizes, pad matrices with zero rows and columns to a power-of-two size, then remove the padding from the result, or use a variant that handles uneven blocks.
- More additions: Strassen reduces multiplications but performs extra additions and subtractions. Its practical speed depends on matrix size, memory use, data type, and implementation.
- Floating-point accuracy: With floating-point entries, different operation orders can produce different rounding errors. Strassen can be less numerically stable than conventional multiplication in some settings, so consider the required accuracy and use an appropriate implementation.
- Wrong signs or factor order: A sign error in one combination formula changes the result. Also, do not reverse factors in a block product: in general, .
For integer, real, or complex matrices, the same block identities apply; the entries must support the additions, subtractions, and multiplications used by the algorithm.
References
- Introduction to Algorithms, 4th edition — Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein
- Gaussian Elimination Is Not Optimal — Volker Strassen
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.