0% found this document useful (0 votes)
87 views11 pages

Strassen's Matrix Multiplication

Strassen's algorithm improves on the basic matrix multiplication algorithm by reducing the number of multiplication operations needed to multiply two n x n matrices from 8n^3 to 7n^3. It achieves this reduction using a divide-and-conquer approach that divides the matrices into sub-matrices and recursively multiplies the sub-matrices using combinations of additions and subtractions in place of some multiplications. The algorithm runs in O(n^log7) time, providing an asymptotic improvement over the O(n^3) time of basic matrix multiplication.

Uploaded by

dogege3595
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)
87 views11 pages

Strassen's Matrix Multiplication

Strassen's algorithm improves on the basic matrix multiplication algorithm by reducing the number of multiplication operations needed to multiply two n x n matrices from 8n^3 to 7n^3. It achieves this reduction using a divide-and-conquer approach that divides the matrices into sub-matrices and recursively multiplies the sub-matrices using combinations of additions and subtractions in place of some multiplications. The algorithm runs in O(n^log7) time, providing an asymptotic improvement over the O(n^3) time of basic matrix multiplication.

Uploaded by

dogege3595
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/ 11

Strassen's Matrix

Multiplication
Basic Matrix Multiplication

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
Strassens’s Matrix Multiplication

Strassen showed that 2x2 matrix multiplication


can be accomplished in 7 multiplication and 18
additions or subtractions.

This reduce can be done by Divide and Conquer


Approach.
Divide-and-Conquer
Divide-and conquer is a general algorithm design
paradigm:
 Divide: divide the input data S in two or more disjoint
subsets S1, S2, …
 Recur: solve the subproblems recursively
 Conquer: combine the solutions for S1, S2, …, into a
solution for S
The base case for the recursion are subproblems of
constant size
Analysis can be done using recurrence equations
Divide and Conquer Matrix Multiply
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
Divide and Conquer Matrix Multiply
A  B = R

a0  b0 = a 0  b0

• Terminate recursion with a simple base case


Strassens’s Matrix Multiplication

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)
Comparison

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
Strassen Algorithm
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
Time Analysis
2 3 5 2
3 4 1 4

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