Proofs: Divide-and-conquer matrix multiplication
These are the human proofs of Divide-and-conquer matrix multiplication, at full length.
The eight block products add up to the matrix product full
This proof shows: correctness, termination.
Let be a ring, or a semiring (commutativity of the multiplication is not used). A view is a block of an array given by a row range and a column range. For a call DC-MULTIPLY-ADD with of shape , of shape and of shape , write for at the start of the call. Let be its set of index triples.
Claim. The call stops. When it returns, for all , where the products are added one at a time in increasing order of . No entry of the arrays outside the view changes, and and do not change. Line L3 runs exactly times.
Termination. Let . If the call reaches line L5, then it did not return at line L1 or L4, so and at least one side is at least 2. A side splits into and . A side splits into and . So each of the eight calls of lines L8 and L9 has its three sides at most the old ones, and the side that was at least 2 is strictly smaller. So drops by at least 1 in each call, and , so the recursion is finite.
Proof of the claim. By strong induction on .
Base cases. If or , there are no entries of and line L1 returns, so the claim holds. If , each sum is empty and line L1 returns with . If , line L3 adds to , which is the claim with one term, and .
Step. Let with one side at least 2, and assume the claim for all calls with a smaller . Line L5 splits the row range into and with , the inner range into and , and the column range into and . The view has rows and columns , the view has rows and columns , and the view has rows and columns . The views are disjoint and cover .
Fix and an entry with , . Only the two calls with this change , because each call changes only its own view of by the hypothesis. The call of line L8 has a smaller , so by the hypothesis it adds , in increasing order of . Then the call of line L9 adds , in increasing order of . Every element of is less than every element of , and . So after both calls,
with the terms added in increasing order of . The calls for other pairs do not touch . This holds for each entry, so the claim holds for . The calls read and and never write them.
Count. The eight sets for are disjoint and their union is . By the hypothesis, the call for runs line L3 exactly times. The sum over the eight calls is .
Corollary. DC-MULTIPLY-ADD gives , with each entry computed by the same sequence of additions as the triple loop with starting at .