0% found this document useful (0 votes)
24 views14 pages

Strassen Matrix DAA

The document discusses efficient algorithms for multiplying complex numbers and matrices, highlighting the reduction of multiplications from 4 to 3 for complex numbers and introducing Strassen's algorithm for matrix multiplication, which reduces the complexity from Θ(n³) to Θ(n².807). It explains the divide-and-conquer approach used in these algorithms, where inputs are split into smaller parts, solved recursively, and then combined. The document also lists various inventors and their contributions to improving matrix multiplication complexity over the years.

Uploaded by

Clock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views14 pages

Strassen Matrix DAA

The document discusses efficient algorithms for multiplying complex numbers and matrices, highlighting the reduction of multiplications from 4 to 3 for complex numbers and introducing Strassen's algorithm for matrix multiplication, which reduces the complexity from Θ(n³) to Θ(n².807). It explains the divide-and-conquer approach used in these algorithms, where inputs are split into smaller parts, solved recursively, and then combined. The document also lists various inventors and their contributions to improving matrix multiplication complexity over the years.

Uploaded by

Clock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

 The mathematician Carl Friedrich Guass (1777-1855) once

noticed that although the product of two complex numbers


◦ (a + bi) (c + di) = ac – bd + (bc + ad)I
◦ Seems to involve 4 real number multiplications, it can infact be done
with just 3: ac, bd and (a+b)(c+d), since
 Bc + ad= (a+b)(c+d) –ac – bd
In our big-O of thinking, reducing the number of multiplications
from 4 to 3 seems wasted. But this improvement becomes
very significant when applied recursively.
Suppose x & y are two n-bit integers, and assume that n is a
power of 2. then split each of them into their Left & Right
halves, which are n/2 bits long:
X = xL xR = 2 n/2 xL + xR
Y = yL yR = 2 n/2 yL + yR
For instance, if x=(10110110) 2 & y=(01100011 )2
 xL = (1011)2 xR= (0110)2 , and
 X = (1011)2 * 2ᶺ4 + ( 0110)2, then product
of xy= (2ᶺn/2 xL + xR)(2ᶺn/2 yL + yR)
 = 2ᶺn xL yL +2 ᶺn/2 (xLyR + xRyL) + xRyR
 These can be handle by 4 recursive calls.
 Thus our method for multiplying n-bit
numbers start by making recursive calls to
multiply these 4 pair of n/2-bit numbers,
then
 T(n) = 4T (n/2) = O(n)
 Since xLyR+ xRyL= (xL+xR)(yL+yR)- xLyL –
xRyR,
 Thus T(n) = 3 T(n/2) + O(n)
 It yields O (n ᶺ1.59) of time bound.
 function multiply(x,y)
 Input: positive integers x & y in binary
 Output: their product
 N= max( size of x, size of y)
 If n=1 : return xy
 xL , xR = leftmost[n/2], rightmost[n/2] bits of x
 yL , yR= leftmost[n/2], rightmost[n/2] bits of y
 P1= multiply(xL, yL)
 P2= multiply (xR, yR)
 P3= multiply( xL + xR, yL +yR)
 Return P1 * 2ᶺn + (P3-P1-P2) * 2 ᶺn/2 + P2
Suppose we want to multiply two matrices of size N
x N: for example A x B = C.

C11 = a11b11 + a12b21

C12 = a11b12 + a12b22

C21 = a21b11 + a22b21 2x2 matrix multiplication can be


accomplished in 8 multiplication.(2log28 =23)
C22 = a21b12 + a22b22
void matrix_mult (){
for (i = 1; i <= N; i++) { algorithm

for (j = 1; j <= N; j++) {


compute Ci,j;
}
N
}}
Ci , j  ai ,k bk , j
Time k 1
N N N
analysis Thus T ( N )    c cN 3 O( N 3 )
i 1 j 1 k 1
 Strassen showed that 2x2 matrix multiplication can
be accomplished in 7 multiplication and 18 additions
or subtractions. .(2log27 =22.807)

 This reduce can be done by Divide and Conquer


Approach.
 Divide-and conquer is a general algorithm design
paradigm:
◦ Divide: divide the input data A in two or more disjoint
subsets A1, A2, …
◦ Recur: solve the subproblems recursively i.e., all the P-
i’s . ( P1 – P7) for Pi= AiBi where i= 1,2,…
◦ Conquer: combine the solutions for A1, A2, …, into a
solution for A
 The base case for the recursion are subproblems of
constant size
 Analysis can be done using recurrence equations
A  B = R
A0 A1 B0 B1 A0B0+A1B2 A0B1+A1B3
 =
A2 A3 B2 B3 A2B0+A3B2 A2B1+A3B3

•Divide matrices into sub-matrices: A0 , A1, A2 etc


•Use blocked matrix multiply equations
•Recursively multiply sub-matrices
A  B = R

a0  b0 = a0  b 0

• Terminate recursion with a simple base case


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)
C11 = P1 + P4 - P5 + P7
= (A11+ A22)(B11+B22) + A22 * (B21 - B11) - (A11 + A12) * B22+
(A12 - A22) * (B21 + B22)
= A11 B11 + A11 B22 + A22 B11 + A22 B22 + A22 B21 – A22 B11 -

A11 B22 -A12 B22 + A12 B21 + A12 B22 – A22 B21 – A22 B22
= A11 B11 + A12 B21
void matmul(int *A, int *B, int *R, int n) {
if (n == 1) {
(*R) += (*A) * (*B);
} else {
matmul(A, B, R, n/4);
matmul(A, B+(n/4), R+(n/4), n/4);
matmul(A+2*(n/4), B, R+2*(n/4), n/4);
matmul(A+2*(n/4), B+(n/4), R+3*(n/4), n/4);
matmul(A+(n/4), B+2*(n/4), R, n/4);
matmul(A+(n/4), B+3*(n/4), R+(n/4), n/4);
matmul(A+3*(n/4), B+2*(n/4), R+2*(n/4), n/4);
matmul(A+3*(n/4), B+3*(n/4), R+3*(n/4), n/4);
}
Divide matrices in
sub-matrices and
recursively multiply
sub-matrices
Inventor Year Complexity
Classical ― Θ (nᶺ3)
Volker Strassen 1968 Θ (nᶺ2.807)
Victor Pan
( multiply two 70 × 70 matrices using
143,640 multiplications )
1978 Θ (nᶺ2.795)
Don Coppersmith & ShmuelWinograd
( arithmetic progressions )
1990 Θ (nᶺ2.3737)
Andrew Stothers 2010 Θ (nᶺ2.3736)
Virginia Williams 2011 Θ (nᶺ2.3727)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy