logo

Strassen Algorithm Proof 📂Matrix Algebra

Strassen Algorithm Proof

Algorithm

Let’s say for kNk \in \mathbb{N} there is n=2kn=2^{k}. For A,BRn×nA, B \in \mathbb{R}^{n \times n}, using the Jordan block matrix representation, let’s consider the following 8 matrices n2×n2{{n} \over {2}} \times {{n} \over {2}}, AiA_{i}, and BiB_{i}. AB=[A1A2A3A4][B1B2B3B4]=[C1C2C3C4]=C AB= \begin{bmatrix} A_{1} & A_{2} \\ A_{3} & A_{4} \end{bmatrix} \begin{bmatrix} B_{1} & B_{2} \\ B_{3} & B_{4} \end{bmatrix} = \begin{bmatrix} C_{1} & C_{2} \\ C_{3} & C_{4} \end{bmatrix} = C To calculate C=ABC = AB, compute the following. P1=A1(B2B4)P2=(A1+A2)B4P3=(A3+A4)B1P4=A4(B3B1)P5=(A1+A4)(B1+B4)P6=(A2A4)(B3+B4)P7=(A3A1)(B1+B2) P_{1} = A_{1} ( B_{2} - B_{4} ) \\ P_{2} = ( A_{1} + A_{2} ) B_{4} \\ P_{3} = ( A_{3} + A_{4} ) B_{1} \\ P_{4} = A_{4} ( B_{3} - B_{1} ) \\ P_{5} = (A_{1} + A_{4}) ( B_{1} + B_{4} ) \\ P_{6} = (A_{2} - A_{4}) ( B_{3} + B_{4} ) \\ P_{7} = (A_{3} - A_{1}) ( B_{1} + B_{2} )

C1=P2+P4+P5+P6C2=P1+P2C3=P3+P4C4=P1P3+P5+P7 C_{1} = -P_{2} + P_{4}+ P_{5} + P_{6} \\ C_{2} = P_{1} + P_{2} \\ C_{3} = P_{3} + P_{4} \\ C_{4} = P_{1} - P_{3} + P_{5} + P_{7} When calculating AiBjA_{i} B_{j}, repeat the same method, and the time complexity is Θ(n2.807)\Theta ( n^{2.807} ).


  • Of course, it is not that you cannot use n2kn \ne 2^{k}, and you can apply it as is by adjusting the size.

Explanation

The multiplications of matrices that are straightforward and immediately come to mind are C1=A1B1+A2B3C2=A1B2+A2B4C3=A3B1+A4B3C4=A3B2+A4B4 C_{1} = A_{1}B_{1} + A_{2} B_{3} \\ C_{2} = A_{1}B_{2} + A_{2} B_{4} \\ C_{3} = A_{3}B_{1} + A_{4} B_{3} \\ C_{4} = A_{3}B_{2} + A_{4} B_{4} Just keep repeating this calculation, and there was no doubt that the time it took was known as Θ(n3)\Theta ( n^3 ) until Strassen was born.

This algorithm is very revolutionary because originally, it is definitely necessary to perform two matrix multiplications to calculate one CiC_{i}. Combining them requires calculation 8 times each time, but Strassen reduced this to 7 times. The consideration from the very beginning, whether there could be another method, is an extraordinary sense, and what was truly found can even be said to be a wonder. With the development of this algorithm, a significant amount of resources, if not a little, that would have been used for matrix calculations can be saved.

Proof

Part 1. Computability

There’s no choice but to calculate directly.

Part 1-1. C1=A1B1+A2B3C_{1} = A_{1}B_{1} + A_{2} B_{3}

C1=P2+P4+P5+P6=(A1B4A2B4)+P4+(A1B1+A1B4+A4B1+A4B4)+P6=A2B4+(A4B3A4B1)+A1B1+A4B1+A4B4+P6=A2B4+A4B3+A1B1+A4B4+(A2B3+A2A4A4B3A4B4)=A1B1+A2B3 \begin{align*} C_{1} =& -P_{2} + P_{4} + P_{5} + P_{6} \\ =& ( {\color{red}- A_{1} B_{4}} - A_{2} B_{4} ) + P_{4} + ( A_{1}B_{1} + {\color{red} A_{1}B_{4} } + A_{4} B_{1} + A_{4}B_{4} ) + P_{6} \\ =& - A_{2} B_{4} + (A_{4} B_{3} {\color{red}- A_{4} B_{1} }) + A_{1}B_{1} + {\color{red} A_{4} B_{1} } + A_{4}B_{4} + P_{6} \\ =& {\color{red} - A_{2} B_{4} } + \color{blue}{A_{4} B_{3} } + A_{1}B_{1} + \color{green}{A_{4}B_{4}} + ( A_{2} B_{3} + {\color{red} A_{2} A_{4} } \color{blue}{ - A_{4} B_{3} }- \color{green}{A_{4} B_{4}}) \\ =& A_{1}B_{1} + A_{2} B_{3} \end{align*}

Part 1-2. C2=A1B2+A2B4C_{2} = A_{1}B_{2} + A_{2} B_{4}

C2=P1+P2=(A1B2A1B4)+(A1B4+A2B4)=A1B2+A2B4 \begin{align*} C_{2} =& P_{1} + P_{2} \\ =& (A_{1}B_{2} {\color{red}- A_{1} B_{4}}) + ( {\color{red}A_{1} B_{4}} + A_{2} B_{4}) \\ =& A_{1}B_{2} + A_{2} B_{4} \end{align*}

Part 1-3. C3=A3B1+A4B3C_{3} = A_{3}B_{1} + A_{4} B_{3}

C3=P3+P4=(A3B1+A4B1)+(A4B3A4B1)=A3B1+A4B3 \begin{align*} C_{3} =& P_{3} + P_{4} \\ =& (A_{3}B_{1} + {\color{red} A_{4}B_{1}}) + (A_{4}B_{3} {\color{red}- A_{4}B_{1}}) \\ =& A_{3}B_{1} + A_{4} B_{3} \end{align*}

Part 1-4. C4=A3B2+A4B4C_{4} = A_{3}B_{2} + A_{4} B_{4}

C4=P1P3+P5+P7=(A1B2A1B4)P3+(A1B1+A1B4+A4B1+A4B4)+P7=A1B2+(A3B1A4B1)+A1B1+A4B1+A4B4+P7=A1B2A3B1+A1B1+A4B4+(A3B1+A3B2A1B1A1B2)=A3B2+A4B4 \begin{align*} C_{4} =& P_{1} - P_{3} + P_{5} + P_{7} \\ =& (A_{1}B_{2} {\color{red} - A_{1} B_{4} } ) - P_{3} + ( A_{1}B_{1} + {\color{red} A_{1}B_{4} } + A_{4}B_{1} + A_{4}B_{4}) + P_{7} \\ =& A_{1}B_{2} + (- A_{3}B_{1} - {\color{red}A_{4}B_{1}}) + A_{1}B_{1} + {\color{red}A_{4}B_{1}} + A_{4}B_{4} + P_{7} \\ =& {\color{red} A_{1}B_{2}} - \color{blue}{A_{3}B_{1}} + \color{green}{A_{1}B_{1}}+ A_{4}B_{4} + ( \color{blue}{A_{3}B_{1}} + A_{3}B_{2} - \color{green}{A_{1}B_{1}} {\color{red}- A_{1}B_{2}}) \\ =& A_{3}B_{2} + A_{4} B_{4} \end{align*}


Part 2. Time Complexity

Essentially, it is the same as the method that proved that the original calculation method was known as Θ(n3)\Theta ( n^3 ). If the time taken for one calculation is T(n)T(n) and the time taken outside of repetitions is cc, then because it is T(n)=7T(n2)+c\displaystyle T(n) = 7 T \left( {{n} \over {2}} \right) + c,

T(n)=7T(n2)+c=7[7T(n4)+c]+c=7[49T(n8)+7c+c]+c=73T(n8)+(1+7+72)c=73T(n8)+73171c7log2n(T(1)+c)=nlog27(T(1)+c)=n2.807(T(1)+c)=Θ(n2.807) \begin{align*} T(n) =& 7 T \left( {{n} \over {2}} \right) + c \\ =& 7 \left[ 7 T \left( {{n} \over {4}} \right) + c \right] + c \\ =& 7 \left[ 49 T \left( {{n} \over {8}} \right) + 7 c + c \right] + c \\ =& 7^3 T \left( {{n} \over {8}} \right) + (1+7+7^2)c \\ =& 7^3 T \left( {{n} \over {8}} \right) + {{7^3 - 1} \over {7 - 1}}c \\ & \vdots & \\ \approx& 7^{\log_{2} n} ( T(1) + c ) \\ =& n^{\log_{2} 7} ( T(1) + c ) \\ =& n^{2.807} ( T(1) + c ) \\ =& \Theta \left( n^{2.807} \right) \end{align*}