Strassen's seven products give the matrix product full
This proof shows: correctness, termination.
Let R be a ring (an additive abelian group with an associative multiplication that distributes over addition). Commutativity of the multiplication is not used. For matrices over R of matching shapes, the matrix ring laws hold: X(Y+Z)=XY+XZ, (X+Y)Z=XZ+YZ, X(−Y)=−(XY)=(−X)Y, and block multiplication: if A and B are split into 2×2 blocks with matching inner splits, then (AB)rs=Ar1B1s+Ar2B2s.
Lemma (the four identities). For any blocks of matching shapes, with M1,…,M7 defined as in lines L4 to L10 but with exact products,
M1+M4−M5+M7M2+M4=A11B11+A12B21,=A21B11+A22B21,M3+M5M1−M2+M3+M6=A11B12+A12B22,=A21B12+A22B22. Proof. Expand each product by distributivity, with the A factor kept on the left:
- M1=A11B11+A11B22+A22B11+A22B22
- M2=A21B11+A22B11
- M3=A11B12−A11B22
- M4=A22B21−A22B11
- M5=A11B22+A12B22
- M6=A21B11+A21B12−A11B11−A11B12
- M7=A12B21+A12B22−A22B21−A22B22
First identity. In M1+M4−M5+M7, the term A11B22 appears in M1 and in −M5 and cancels. A22B11 appears in M1 and with a minus sign in M4. A22B22 appears in M1 and with a minus sign in M7. A22B21 appears in M4 and with a minus sign in M7. A12B22 appears in −M5 with a minus sign and in M7 with a plus sign. What is left is A11B11+A12B21.
Second identity. M3+M5=A11B12−A11B22+A11B22+A12B22=A11B12+A12B22.
Third identity. M2+M4=A21B11+A22B11+A22B21−A22B11=A21B11+A22B21.
Fourth identity. In M1−M2+M3+M6: A11B11 cancels between M1 and M6; A11B22 cancels between M1 and M3; A22B11 cancels between M1 and −M2; A21B11 cancels between −M2 and M6; A11B12 cancels between M3 and M6. What is left is A22B22+A21B12. Addition is commutative, so this is the claimed right side. □
Lemma (padding). Let A′ be A with zero rows added at the bottom and zero columns added at the right, and B′ be B with zero rows added at the bottom (as many as the zero columns of A′) and zero columns at the right. Then the top left n×p block of A′B′ is AB.
Proof. For i<n and j<p, (A′B′)[i][j]=∑k<mA[i][k]B[k][j]+∑k≥mA′[i][k]B′[k][j], and each term of the second sum has A′[i][k]=0. □
Theorem. For every n0≥1 and all A∈Rn×m, B∈Rm×p, STRASSEN(A,B) stops and returns AB.
Proof. Let μ=max(n,m,p). We use strong induction on μ, and inside one value of μ, we first treat the calls of line L3 (all sides even) and then the calls of line L2.
Line L1. If min(n,m,p)≤n0, the result is the classical product, which is correct by the triple loop proof. This covers every μ≤n0 and every input with a side 0.
All sides even, min(n,m,p)>n0≥1. Then all sides are at least 2. Line L3 splits each side d into two halves of length d/2<d. Each of the seven calls of lines L4 to L10 has the shape (n/2)×(m/2) times (m/2)×(p/2), with max<μ, so by the hypothesis it returns the exact product of its two operands. By the first lemma, lines L11 to L14 compute the four blocks (AB)rs, and by block multiplication the matrix of line L15 is AB.
Some side odd, min(n,m,p)>n0. Line L2 pads each odd side by one, so the padded sides are even and at most μ+1. The call on the padded matrices passes line L1 (its sides are at least the old ones) and goes to line L3 with all sides even. Its seven calls have sides at most ⌈μ/2⌉, which is less than μ since μ≥2, so by the hypothesis and the case above, the padded call returns A′B′. By the padding lemma, removing the padding gives AB.
Termination. Each call either returns at line L1, or calls itself on sides at most ⌈μ/2⌉<μ after at most one padding step. So μ drops along each path of the recursion, and the depth is O(logμ). ■