Winograd's inner product algorithm computes the matrix product full
This proof shows: correctness, termination.
Let R be a commutative ring, A∈Rn×m, B∈Rm×p with n,m,p≥0, and h=⌊m/2⌋.
Claim. WINOGRAD-PRODUCT(A,B) stops and returns C=AB.
Lemma. For all x1,x2,y1,y2∈R, (x1+y2)(x2+y1)=x1y1+x2y2+x1x2+y1y2.
Proof. By distributivity, (x1+y2)(x2+y1)=x1x2+x1y1+y2x2+y2y1. By commutativity, y2x2=x2y2 and y2y1=y1y2. □
Proof of the claim. Lines L2 and L3 set ξi=∑t<hA[i][2t]A[i][2t+1] and ηj=∑t<hB[2t][j]B[2t+1][j] (empty sums are 0).
Fix 0≤i<n and 0≤j<p. After line L5, s=−ξi−ηj. By induction on the loop of line L6, after the iteration with index t,
s=−ξi−ηj+u≤t∑(A[i][2u]+B[2u+1][j])(A[i][2u+1]+B[2u][j]). The base case before the first iteration is the empty sum, and each iteration adds the next term. After the loop, applying the lemma with x1=A[i][2u], x2=A[i][2u+1], y1=B[2u][j], y2=B[2u+1][j] to each term,
s=−ξi−ηj+u<h∑(A[i][2u]B[2u][j]+A[i][2u+1]B[2u+1][j])+u<h∑A[i][2u]A[i][2u+1]+u<h∑B[2u][j]B[2u+1][j]. The last two sums are ξi and ηj, so s=∑k<2hA[i][k]B[k][j]. If m is even, 2h=m and this is C[i][j]. If m is odd, 2h=m−1, and line L7 adds A[i][m−1]B[m−1][j], so again s=∑k<mA[i][k]B[k][j]=C[i][j]. Line L8 stores this value. The value of s for one entry does not depend on any other entry, so every entry of C is correct.
Termination. Every loop runs over a finite range fixed before it starts (n, p and h iterations), and each iteration does a bounded number of ring operations. ■
Where commutativity is needed. Without it, the lemma fails: for 2×2 matrices x2=(0010), y2=(0100) and x1=y1=0, the left side is y2x2=(0001) while the right side is x2y2=(1000).