现在的位置: 首页 > 综合 > 正文

Strassen’s Subcubic Matrix Multiplication Algorithm

2018年04月04日 ⁄ 综合 ⁄ 共 831字 ⁄ 字号 评论关闭

Consider multiplying two 2x2 matrices, as follows:

A B * E F = AE+BG AF+BH
C D   G H   CE+DG CF+DH

The obvious way to compute the right side is just to do the 8 multiplies and 4 additions. But imagine multiplies are a lot more expensive than additions, so we want to reduce the number of multiplications if at all possible. Strassen uses a trick to compute
the right hand side with one less multiply and a lot more additions (and some subtractions).

Here are the 7 multiplies:

M1 = (A + D) * (E + H) = AE + AH + DE + DH
M2 = (A + B) * H = AH + BH
M3 = (C + D) * E = CE + DE
M4 = A * (F - H) = AF - AH
M5 = D * (G - E) = DG - DE
M6 = (C - A) * (E + F) = CE + CF - AE - AF
M7 = (B - D) * (G + H) = BG + BH - DG - DH

So to compute AE+BG, start with M1+M7 (which gets us the AE and BG terms), then add/subtract some of the other Ms until AE+BG is all we are left with. Miraculously, the M's are chosen so that M1+M7-M2+M5 works. Same with the other 3 results required.

Now just realize this works not just for 2x2 matrices, but for any (even) sized matrices where the A..H are submatrices.

抱歉!评论已关闭.