Matrix Multiplication
Matrix multiplication
Let A and B be n × n n\times n n × n matrices, where n = 2 k n=2^k n = 2 k . Each of C's n 2 n^2 n 2 entries requires n multiplications, giving W ( n ) = O ( n 3 ) W(n)=O(n^3) W ( n ) = O ( n 3 ) .
A simple divide-and-conquer strategy partitions the matrices into blocks.
( A 11 A 12 A 21 A 22 ) ( B 11 B 12 B 21 B 22 ) = ( C 11 C 12 C 21 C 22 ) \begin{pmatrix}A_{11}&A_{12}\\A_{21}&A_{22}\end{pmatrix}
\begin{pmatrix}B_{11}&B_{12}\\B_{21}&B_{22}\end{pmatrix}
=
\begin{pmatrix}C_{11}&C_{12}\\C_{21}&C_{22}\end{pmatrix} ( A 11 A 21 A 12 A 22 ) ( B 11 B 21 B 12 B 22 ) = ( C 11 C 21 C 12 C 22 )
Here:
C 11 = A 11 B 11 + A 12 B 21 C 12 = A 11 B 12 + A 12 B 22 C 21 = A 21 B 11 + A 22 B 21 C 22 = A 21 B 12 + A 22 B 22 \begin{aligned}
C_{11}&=A_{11}B_{11}+A_{12}B_{21}\\
C_{12}&=A_{11}B_{12}+A_{12}B_{22}\\
C_{21}&=A_{21}B_{11}+A_{22}B_{21}\\
C_{22}&=A_{21}B_{12}+A_{22}B_{22}
\end{aligned} C 11 C 12 C 21 C 22 = A 11 B 11 + A 12 B 21 = A 11 B 12 + A 12 B 22 = A 21 B 11 + A 22 B 21 = A 21 B 12 + A 22 B 22
The original problem becomes eight subproblems, with recurrence:
W ( n ) = { 1 n = 1 8 W ( n / 2 ) + c n 2 n > 1 W(n)=\begin{cases}1&n=1\\8W(n/2)+cn^2&n>1\end{cases} W ( n ) = { 1 8 W ( n /2 ) + c n 2 n = 1 n > 1
Solving gives:
W ( n ) = O ( n 3 ) W(n)=O(n^3) W ( n ) = O ( n 3 )
Simple division does not lower the order, but reducing the number of subproblems can improve matrix multiplication.
QUESTION Which expression gives block C₁₂?
A A₁₁B₁₂ + A₁₂B₂₂ B A₁₂B₁₂ + A₁₂B₂₂ C A₁₁B₂₁ + A₁₂B₂₂ D B₁₂A₁₁ + B₂₂A₁₂
Strassen matrix multiplication
Let M 1 , M 2 , … , M 7 M_1,M_2,\ldots,M_7 M 1 , M 2 , … , M 7 be seven matrix-product subproblems:
M 1 = A 11 ( B 12 − B 22 ) M 2 = ( A 11 + A 12 ) B 22 M 3 = ( A 21 + A 22 ) B 11 M 4 = A 22 ( B 21 − B 11 ) M 5 = ( A 11 + A 22 ) ( B 11 + B 22 ) M 6 = ( A 12 − A 22 ) ( B 21 + B 22 ) M 7 = ( A 11 − A 21 ) ( B 11 + B 12 ) \begin{aligned}
M_1&=A_{11}(B_{12}-B_{22})\\
M_2&=(A_{11}+A_{12})B_{22}\\
M_3&=(A_{21}+A_{22})B_{11}\\
M_4&=A_{22}(B_{21}-B_{11})\\
M_5&=(A_{11}+A_{22})(B_{11}+B_{22})\\
M_6&=(A_{12}-A_{22})(B_{21}+B_{22})\\
M_7&=(A_{11}-A_{21})(B_{11}+B_{12})
\end{aligned} M 1 M 2 M 3 M 4 M 5 M 6 M 7 = A 11 ( B 12 − B 22 ) = ( A 11 + A 12 ) B 22 = ( A 21 + A 22 ) B 11 = A 22 ( B 21 − B 11 ) = ( A 11 + A 22 ) ( B 11 + B 22 ) = ( A 12 − A 22 ) ( B 21 + B 22 ) = ( A 11 − A 21 ) ( B 11 + B 12 )
Combine these intermediate matrices to obtain the result:
C 11 = M 5 + M 4 − M 2 + M 6 C 12 = M 1 + M 2 C 21 = M 3 + M 4 C 22 = M 5 + M 1 − M 3 − M 7 \begin{aligned}
C_{11}&=M_5+M_4-M_2+M_6\\
C_{12}&=M_1+M_2\\
C_{21}&=M_3+M_4\\
C_{22}&=M_5+M_1-M_3-M_7
\end{aligned} C 11 C 12 C 21 C 22 = M 5 + M 4 − M 2 + M 6 = M 1 + M 2 = M 3 + M 4 = M 5 + M 1 − M 3 − M 7
Seven subproblems and eighteen matrix additions or subtractions give:
W ( n ) = { 1 n = 1 7 W ( n / 2 ) + 18 ( n / 2 ) 2 n > 1 W(n)=\begin{cases}1&n=1\\7W(n/2)+18(n/2)^2&n>1\end{cases} W ( n ) = { 1 7 W ( n /2 ) + 18 ( n /2 ) 2 n = 1 n > 1
Solving gives:
W ( n ) = O ( n log 2 7 ) ≈ O ( n 2.8075 ) W(n)=O(n^{\log_2 7})\approx O(n^{2.8075}) W ( n ) = O ( n l o g 2 7 ) ≈ O ( n 2.8075 )
The Coppersmith–Winograd algorithm improved the matrix-multiplication upper bound to O ( n 2.376 ) O(n^{2.376}) O ( n 2.376 ) ; subsequent research has improved this bound further. Matrix multiplication is used in scientific computing, graphics, and data mining. Regression, clustering, principal component analysis, and decision trees frequently involve large matrix operations.
Historical result and subsequent improvement: the Coppersmith–Winograd paper and later matrix multiplication research .
PRO EXCLUSIVE Go further with Pro Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Unlock Pro access
QUESTION Why does Strassen improve the asymptotic order?
A Eliminate all matrix additions B Make the partitions less balanced C Reduce eight recursive products to seven per level D Make every product constant time
QUESTION May M₁=A₁₁(B₁₂−B₂₂) always be reordered to (B₁₂−B₂₂)A₁₁?
A Yes: the blocks have equal sizes B No: matrix multiplication is generally noncommutative C Yes: they are square matrices D No: matrices cannot be subtracted
Given A=[[2,1],[3,4]] and B=[[5,2],[1,3]], use the lesson’s Strassen formulas to compute AB on paper, preserving multiplication order.
Compute M₁ through M₇. Combine C₁₁, C₁₂, C₂₁, C₂₂ from the intermediate results. Check with ordinary multiplication and compare product counts.