Fast Matrix Multiplication

Report 19 Downloads 175 Views
Fast Matrix Multiplication Strassen’s algorithm: Straightforward block partitioned 2 x 2 matrix multiplication C = A B can be written  C11 C12   A11 C   21 C22   A21

A12   B11 A22   B21

B12  B22 

where  C11  A11 B11  A12 B21 C  A B  A B  12 11 12 12 22  C  A B  A 21 21 11 22 B21  C22  A21 B12  A22 B22

In the scheme discovered by Strassen (1969), the computations are rearranged into  P1  ( A11  A22 )( B11  B22 ) P  ( A  A )B 11 22 11  2  P3  A11  A22 ) B11   P4  A22 ( B21  B11 )  P  ( A  A )B 11 12 22  5  P6  ( A21  A11 )( B11  B12 )  P  ( A  A )( B  B )  7 12 22 21 22  C11  P1  P4  P5  P7 C  P  P  12 3 5  C  P  P 2 4  21 C22  P1  P2  P3  P6

Easy to check: i.

The Strassen scheme gives the same result as direct multiplication (in particular, we never assumed that matrix multiplication is commutative).

ii.

If one starts with two n x n matrices where n = 2m and use the algorithm repeatedly until all matrices have become of size 1 x 1, the total operation count (use induction!) becomes

7  7m  6  4m operations, which we can write as O(nlog2 7 )  O(n2.81) log2 7m

(since 7m  2

 2mlog2 7  nlog2 7 ) - significantly faster for n large than O(nlog2 8 )  O(n3 ) .

Currently fastest know algorithms: -

Original Coopersmith-Winograd algorithm: Optimized versions

O(n2.376) O(n2.373)

Open conjecture: -

It is possible to multiply two general full n x n matrices in O(n2 log n) operations.

Matlab code for Strassen’s algorithm:

function c = strass(a,b) nmin = 16; [n,n] = size(a); if n