Strassens Matrix Multiplication
Strassens Matrix Multiplication
Strassens Matrix Multiplication
Bheekya D
Basic or brute force Matrix Multiplication
T(n) = O(n3)
= 82 T(n/4)+ c22n2 +
c 2 n2
= log n
8 2 c1 + c n2
.
8
=nlog2 c1 + c n2 = n3 c1+ cn2 = O(n3 )
Strassen’s Matrix Multiplication
• Matrix multiplications are more expensive than matrix additions
or subtractions
• Time complexity of matrix multiplication: O(n3)
• Time complexity of matrix addition: O(n2).
C11=M1 + M4 - M5 + M7
C12= M3 + M5
C21= M2 + M4
C22=M1 + M3 - M2 + M6
Formulas for Strassen’s matrix multiplication
Algorithm
C11 C12 A11 A12 B11 B12
= *
C21 C22 A21 A22 B21 B22
M1 + M 4 - M 5 + M 7 M3 + M 5
=
M2 + M 4 M 1 + M3 - M 2 + M6
T(n)= c1 n<=2
1 2 3 5 = 1*3+2*1=5 1*5+2*4=13
3 4 1 4 3*3+4*1=13 3*5+4*4=31
m1 = (a00+a11)*(b00+b11) = 35
m2 = (a10+a11)*b00 =21 35-8-12-10=5 1+12=13
m3 = a00*(b01-b11) = 1
21-8=13 35+1-21+16=31
m4 = a11*(b10-b00) = -8
m5 = (a00+a01)*b11 = 12
m6 = (a10-a00)*(b00+b01) = 16 7 mults
18 adds/subs
m7 = (a01-a11)*(b10+b11) = -10
STRESSEN’S MATRIX MULTIPLICATION
1 2 3 4 1 0 0 0 1 2 3 4
5 6 7 8 0 1 0 0 5 6 7 8
9 10 11 12
9 10 11 12 x 0 0 1 0
=
13 14 15 16 0 0 0 1 13 14 15 16
1 2 3 4 9 10 11 12
A11 A12 A21 A22
= 5 6 = 7 8 = 13 14 = 15 16
1 0 0 0 0 0 1 0
B11= B12 B21 B22
0 1 0 0 = 0 0 = 0 1
=
P1 = (A11+ A22)(B11+B22)
C11 = P1 + P4 - P5 + P7
P2 = (A21 + A22) * B11
C12 = P3 + P5
P3 = A11 * (B12 - B22)
C21 = P2 + P4
P4 = A22 * (B21 - B11)
C22 = P1 + P3 - P2 + P6
P5 = (A11 + A12) * B22
P6 = (A21 - A11) * (B11 + B12)
P7 = (A12 - A22) * (B21 + B22)
STRESSEN’S MATRIX MULTIPLICATION
C11 = A11+B11
C12 = A12+B12
C21 = A21+B21
C22 = A22+B22
Div. & Conq. : Strassen’s Matrix Multiplication