SlideShare a Scribd company logo
6
Most read
11
Most read
13
Most read
1
Strassen’s Matrix Multiplication
Ahmad Baryal
Saba Institute of Higher Education
Computer Science Faculty
Oct 22, 2024
2 Table of contents
 Overview of matrix
 Matrix multiplication
 Matrix multiplication implementation
 Strassen’s Matrix Multiplication
 Algorithm
 Pseudo code
 Implementation
 Practical Limitations
 Real world applications
3
Matrix
• A matrix is a rectangular array of numbers arranged in rows and columns.
• It is a fundamental mathematical object used in various fields, including
computer science, physics, engineering, and economics.
• Matrices are used to represent and manipulate data, solve systems of linear
equations, perform transformations in geometry, and model various real-
world phenomena
4 Key characteristics of matrix
 Dimensions: A matrix is defined by its number of rows and columns. If a
matrix has rows and columns, it is called an × matrix.
𝑚 𝑛 𝑚 𝑛
 Elements: The individual values or entries in a matrix are called elements,
typically denoted as , where represents the row and the column
𝑎𝑖𝑗 𝑖 𝑗
position.
Figure 1: matrix representation
5 Types of matrix
• Row Matrix: A matrix with only one row (e.g., 1×n).
• Column Matrix: A matrix with only one column (e.g., m×1).
• Square Matrix: A matrix where the number of rows equals the number of columns
(e.g., n×n).
• Diagonal Matrix: A square matrix where all elements outside the main diagonal
are zero.
• Identity Matrix: A diagonal matrix where all diagonal elements are 1.
• Zero Matrix: A matrix where all elements are zero.
• Symmetric Matrix: A square matrix that is equal to its transpose (i.e., A=).
6 Matrix multiplication
 Matrix multiplication is the process of combining two matrices to produce a
third matrix. It requires the number of columns in the first matrix to match the
number of rows in the second.
 Key Points:
• If A is an m×n matrix and B is an n×p matrix, their product C=A×B will be an
m×p matrix.
• Each element in C is the sum of the products of corresponding elements
from a row in A and a column in B.
Figure 2: Matrix multiplication
7 Matrix multiplication Algorithm
Matrix-Multiplication (X, Y, Z)
for i = 1 to p do
for j = 1 to r do
Z[i,j] := 0
for k = 1 to q do
Z[i,j] := Z[i,j] + X[i,k] × Y[k,j]
Explanation:
• Outer loops: The two outer loops iterate over each element of the resulting
matrix Z. The loop variables i and j represent the row and column indices,
respectively.
• Initialization: Each element of Z[i,j] is initialized to 0.
• Inner loop: For each pair of row i in X and column j in Y, the inner loop sums
the product of corresponding elements X[i,k] and Y[k,j] across all values of k.
• This results in each element Z[i,j] being the dot product of the i-th row of X
and the j-th column of Y.
8 Strassen’s Matrix Multiplication
• Strassen’s Matrix Multiplication is the divide and conquer approach to solve
the matrix multiplication problems.
• Strassen's matrix multiplication, developed by Volker Strassen in 1969, is a
significant algorithm in computer science and mathematics.
• It revolutionized the field of matrix multiplication by introducing a more
efficient method for multiplying large matrices.
• The usual matrix multiplication method multiplies each row with each
column to achieve the product matrix. The time complexity taken by this
approach is O(), since it takes two loops to multiply.
9 Significance of Strassen’s Matrix
 Improved Efficiency: Strassen's algorithm reduces matrix multiplication time from O()
to approximately O(), improving performance for large matrices.
 Divide and Conquer: Uses a divide-and-conquer strategy, breaking the problem into
smaller, easier sub-problems.
 Theoretical Advancement: Showed how algorithms can optimize basic mathematical
operations, leading to more efficient methods.
 Practical Applications: Useful in numerical simulations, scientific computing, and
image processing, especially with large datasets.
10 Strassen’s Matrix Multiplication Algorithm
• In this context, using Strassen’s Matrix multiplication algorithm, the time consumption
can be improved a little bit.
• Strassen’s Matrix multiplication can be performed only on square matrices where n is
a power of 2. Order of both of the matrices are n × n.
• Divide X, Y and Z into four (n/2)×(n/2) matrices as represented below −
11 Strassen’s Algorithm Computation
Using Strassen’s Algorithm compute the following −
12 Strassen’s Algorithm Computation
Then,
13 Analysis
Using this recurrence relation, we get T(n)=O()
Hence, the complexity of Strassen’s matrix multiplication algorithm is O()
14 Sudo code of Strassen’s Matrix
function strassenMatrixMultiply(A, B, n):
if n <= threshold: # Use standard matrix multiplication for small matrices
return standardMatrixMultiply(A, B)
# Divide matrices A and B into submatrices
A11, A12, A21, A22 = divideMatrix(A)
B11, B12, B21, B22 = divideMatrix(B)
# Calculate 7 recursive products
P1 = strassenMatrixMultiply(A11, subtractMatrices(B12, B22), n/2)
P2 = strassenMatrixMultiply(addMatrices(A11, A12), B22, n/2)
P3 = strassenMatrixMultiply(addMatrices(A21, A22), B11, n/2)
P4 = strassenMatrixMultiply(A22, subtractMatrices(B21, B11), n/2)
P5 = strassenMatrixMultiply(addMatrices(A11, A22), addMatrices(B11, B22), n/2)
P6 = strassenMatrixMultiply(subtractMatrices(A12, A22), addMatrices(B21, B22), n/2)
P7 = strassenMatrixMultiply(subtractMatrices(A11, A21), addMatrices(B11, B12), n/2)
# Calculate resulting submatrices
C11 = subtractMatrices(addMatrices(addMatrices(P5, P4), P6), P2)
C12 = addMatrices(P1, P2)
C21 = addMatrices(P3, P4)
C22 = subtractMatrices(subtractMatrices(addMatrices(P5, P1), P3), P7)
# Combine submatrices to form the result matrix C
C = combineMatrices(C11, C12, C21, C22)
return C
15 Practical limitations of Strassen’s Matrix
• Overhead and Constants: Strassen’s algorithm introduces overhead due to
recursive calls and splitting, making traditional multiplication faster for smaller
matrices.
• Memory Usage: Higher memory demand can slow performance if resources are
limited.
• Practical Constants: The O() improvement is only significant for very large matrices.
• Non-Power-of-Two Sizes: Works best for power-of-two dimensions; padding for
other sizes reduces benefits.
• Complexity: Strassen's algorithm is more complex and prone to coding errors than
traditional methods.
16 Real World applications of Strassen’s Matrix
• Scientific Computing: Used in simulations like fluid dynamics and weather modeling.
• Image Processing: Efficient for high-resolution images in tasks like compression and
filtering.
• Machine Learning: Speeds up matrix-heavy tasks like linear regression and PCA.
• Cryptography: Improves efficiency in matrix-based encryption.
• Numerical Analysis: Enhances numerical methods in physics and engineering.
17 General Matrix Multiplication (Python Code)
import numpy as np
def matrix_multiplication(X, Y):
# Get dimensions
p, q = X.shape
q, r = Y.shape
# Initialize the result matrix Z with zeros
Z = np.zeros((p, r))
# Perform multiplication
for i in range(p):
for j in range(r):
for k in range(q):
Z[i, j] += X[i, k] * Y[k, j]
return Z
# Example usage
X = np.array([[1, 2], [3, 4]])
Y = np.array([[5, 6], [7, 8]])
Z = matrix_multiplication(X, Y)
print("Result of General Matrix Multiplication:n", Z)
Explanation:
• We take two matrices X (size p×q) and Y (size q×r).
• We initialize a result matrix Z of size p×r, filled with zeros.
• For each element in Z[i,j], we compute the sum of the
element-wise products of the corresponding row from X
and the corresponding column from Y.
• This is the triple loop approach: outer loops for the row
(i) and column (j), and an inner loop for computing the
dot product (k).
X = [[1, 2],
[3, 4]]
Y = [[5, 6],
[7, 8]]
Z = [[19 22]
[43 50]]
Input:
Output:
18
Strassen Matrix Multiplication (Python Code)
import numpy as np
def add_matrix(A, B):
return A + B
def subtract_matrix(A, B):
return A - B
def strassen_multiplication(A, B):
# Base case when matrix size is 1x1
if len(A) == 1:
return A * B
# Splitting matrices into quadrants
mid = len(A) // 2
A11, A12, A21, A22 = A[:mid, :mid], A[:mid, mid:], A[mid:, :mid], A[mid:, mid:]
B11, B12, B21, B22 = B[:mid, :mid], B[:mid, mid:], B[mid:, :mid], B[mid:, mid:]
# Strassen's formulas
M1 = strassen_multiplication(add_matrix(A11, A22), add_matrix(B11, B22))
M2 = strassen_multiplication(add_matrix(A21, A22), B11)
M3 = strassen_multiplication(A11, subtract_matrix(B12, B22))
M4 = strassen_multiplication(A22, subtract_matrix(B21, B11))
M5 = strassen_multiplication(add_matrix(A11, A12), B22)
M6 = strassen_multiplication(subtract_matrix(A21, A11), add_matrix(B11, B12))
M7 = strassen_multiplication(subtract_matrix(A12, A22), add_matrix(B21, B22))
# Combining the results into a single matrix
C11 = M1 + M4 - M5 + M7
C12 = M3 + M5
C21 = M2 + M4
C22 = M1 - M2 + M3 + M6
# Stacking the submatrices to form the result matrix
C = np.vstack((np.hstack((C11, C12)), np.hstack((C21, C22))))
return C
# Example usage
A = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]])
B = np.array([[17, 18, 19, 20],
[21, 22, 23, 24],
[25, 26, 27, 28],
[29, 30, 31, 32]])
C = strassen_multiplication(A, B)
print("Result of Strassen Matrix Multiplication:n", C)
19
Any Questions?

More Related Content

PPTX
Basic MATLAB-Presentation.pptx
PPTX
Linear Algebra Presentation including basic of linear Algebra
PPTX
Introduction to MATLAB Programming for Engineers
PPTX
DimensionalityReduction.pptx
PPTX
Linear Algebra in python programming....
PDF
pca.pdf polymer nanoparticles and sensors
PPT
Introduction to Matlab - Basic Functions
PDF
Aaa ped-17-Unsupervised Learning: Dimensionality reduction
Basic MATLAB-Presentation.pptx
Linear Algebra Presentation including basic of linear Algebra
Introduction to MATLAB Programming for Engineers
DimensionalityReduction.pptx
Linear Algebra in python programming....
pca.pdf polymer nanoparticles and sensors
Introduction to Matlab - Basic Functions
Aaa ped-17-Unsupervised Learning: Dimensionality reduction

Similar to Strassen's Matrix Multiplication divide and conquere algorithm (20)

PPTX
Introduction to Matlab and application.pptx
PPT
Matrix Algebra : Mathematics for Business
PDF
Basics of matlab
PPT
Matrix Multiplication(An example of concurrent programming)
PPTX
5. Matrix Analysis12424214124124124.pptx
PPTX
1. Introduction to Computing - MATLAB.pptx
PPTX
MATLAB - Arrays and Matrices
PPTX
Basics of Digital Images
PDF
5 DimensionalityReduction.pdf
DOCX
Application of matrices in real life
PPTX
MATLABgraphPlotting.pptx
DOCX
M Jamee Raza (BSE-23S-056)LA project.docx
PPT
Matlab introduction
PPTX
Unit-1 Basic Concept of Algorithm.pptx
PPTX
Introduction to matlab lecture 2 of 4
PPTX
Computer Graphics Unit 1
PPT
Introduction to MATLAB
PPTX
Dimension Reduction Introduction & PCA.pptx
PPTX
matrix mathmatics information technology .pptx
PDF
Engineering Numerical Analysis-Introduction.pdf
Introduction to Matlab and application.pptx
Matrix Algebra : Mathematics for Business
Basics of matlab
Matrix Multiplication(An example of concurrent programming)
5. Matrix Analysis12424214124124124.pptx
1. Introduction to Computing - MATLAB.pptx
MATLAB - Arrays and Matrices
Basics of Digital Images
5 DimensionalityReduction.pdf
Application of matrices in real life
MATLABgraphPlotting.pptx
M Jamee Raza (BSE-23S-056)LA project.docx
Matlab introduction
Unit-1 Basic Concept of Algorithm.pptx
Introduction to matlab lecture 2 of 4
Computer Graphics Unit 1
Introduction to MATLAB
Dimension Reduction Introduction & PCA.pptx
matrix mathmatics information technology .pptx
Engineering Numerical Analysis-Introduction.pdf
Ad

More from Ahmad177077 (12)

PPTX
Pointers in C++ object oriented programming
PPTX
Array In C++ programming object oriented programming
PPTX
6. Functions in C ++ programming object oriented programming
PPTX
Operators in c++ programming types of variables
PPTX
2. Variables and Data Types in C++ proramming.pptx
PPTX
Introduction to c++ programming language
PPTX
Selection Sort & Insertion Sorts Algorithms
PPTX
Recursive Algorithms with their types and implementation
PPTX
Graph Theory in Theoretical computer science
PPTX
Propositional Logics in Theoretical computer science
PPTX
Proof Techniques in Theoretical computer Science
PPTX
1. Introduction to C++ and brief history
Pointers in C++ object oriented programming
Array In C++ programming object oriented programming
6. Functions in C ++ programming object oriented programming
Operators in c++ programming types of variables
2. Variables and Data Types in C++ proramming.pptx
Introduction to c++ programming language
Selection Sort & Insertion Sorts Algorithms
Recursive Algorithms with their types and implementation
Graph Theory in Theoretical computer science
Propositional Logics in Theoretical computer science
Proof Techniques in Theoretical computer Science
1. Introduction to C++ and brief history
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Strassen's Matrix Multiplication divide and conquere algorithm

  • 1. 1 Strassen’s Matrix Multiplication Ahmad Baryal Saba Institute of Higher Education Computer Science Faculty Oct 22, 2024
  • 2. 2 Table of contents  Overview of matrix  Matrix multiplication  Matrix multiplication implementation  Strassen’s Matrix Multiplication  Algorithm  Pseudo code  Implementation  Practical Limitations  Real world applications
  • 3. 3 Matrix • A matrix is a rectangular array of numbers arranged in rows and columns. • It is a fundamental mathematical object used in various fields, including computer science, physics, engineering, and economics. • Matrices are used to represent and manipulate data, solve systems of linear equations, perform transformations in geometry, and model various real- world phenomena
  • 4. 4 Key characteristics of matrix  Dimensions: A matrix is defined by its number of rows and columns. If a matrix has rows and columns, it is called an × matrix. 𝑚 𝑛 𝑚 𝑛  Elements: The individual values or entries in a matrix are called elements, typically denoted as , where represents the row and the column 𝑎𝑖𝑗 𝑖 𝑗 position. Figure 1: matrix representation
  • 5. 5 Types of matrix • Row Matrix: A matrix with only one row (e.g., 1×n). • Column Matrix: A matrix with only one column (e.g., m×1). • Square Matrix: A matrix where the number of rows equals the number of columns (e.g., n×n). • Diagonal Matrix: A square matrix where all elements outside the main diagonal are zero. • Identity Matrix: A diagonal matrix where all diagonal elements are 1. • Zero Matrix: A matrix where all elements are zero. • Symmetric Matrix: A square matrix that is equal to its transpose (i.e., A=).
  • 6. 6 Matrix multiplication  Matrix multiplication is the process of combining two matrices to produce a third matrix. It requires the number of columns in the first matrix to match the number of rows in the second.  Key Points: • If A is an m×n matrix and B is an n×p matrix, their product C=A×B will be an m×p matrix. • Each element in C is the sum of the products of corresponding elements from a row in A and a column in B. Figure 2: Matrix multiplication
  • 7. 7 Matrix multiplication Algorithm Matrix-Multiplication (X, Y, Z) for i = 1 to p do for j = 1 to r do Z[i,j] := 0 for k = 1 to q do Z[i,j] := Z[i,j] + X[i,k] × Y[k,j] Explanation: • Outer loops: The two outer loops iterate over each element of the resulting matrix Z. The loop variables i and j represent the row and column indices, respectively. • Initialization: Each element of Z[i,j] is initialized to 0. • Inner loop: For each pair of row i in X and column j in Y, the inner loop sums the product of corresponding elements X[i,k] and Y[k,j] across all values of k. • This results in each element Z[i,j] being the dot product of the i-th row of X and the j-th column of Y.
  • 8. 8 Strassen’s Matrix Multiplication • Strassen’s Matrix Multiplication is the divide and conquer approach to solve the matrix multiplication problems. • Strassen's matrix multiplication, developed by Volker Strassen in 1969, is a significant algorithm in computer science and mathematics. • It revolutionized the field of matrix multiplication by introducing a more efficient method for multiplying large matrices. • The usual matrix multiplication method multiplies each row with each column to achieve the product matrix. The time complexity taken by this approach is O(), since it takes two loops to multiply.
  • 9. 9 Significance of Strassen’s Matrix  Improved Efficiency: Strassen's algorithm reduces matrix multiplication time from O() to approximately O(), improving performance for large matrices.  Divide and Conquer: Uses a divide-and-conquer strategy, breaking the problem into smaller, easier sub-problems.  Theoretical Advancement: Showed how algorithms can optimize basic mathematical operations, leading to more efficient methods.  Practical Applications: Useful in numerical simulations, scientific computing, and image processing, especially with large datasets.
  • 10. 10 Strassen’s Matrix Multiplication Algorithm • In this context, using Strassen’s Matrix multiplication algorithm, the time consumption can be improved a little bit. • Strassen’s Matrix multiplication can be performed only on square matrices where n is a power of 2. Order of both of the matrices are n × n. • Divide X, Y and Z into four (n/2)×(n/2) matrices as represented below −
  • 11. 11 Strassen’s Algorithm Computation Using Strassen’s Algorithm compute the following −
  • 12. 12 Strassen’s Algorithm Computation Then,
  • 13. 13 Analysis Using this recurrence relation, we get T(n)=O() Hence, the complexity of Strassen’s matrix multiplication algorithm is O()
  • 14. 14 Sudo code of Strassen’s Matrix function strassenMatrixMultiply(A, B, n): if n <= threshold: # Use standard matrix multiplication for small matrices return standardMatrixMultiply(A, B) # Divide matrices A and B into submatrices A11, A12, A21, A22 = divideMatrix(A) B11, B12, B21, B22 = divideMatrix(B) # Calculate 7 recursive products P1 = strassenMatrixMultiply(A11, subtractMatrices(B12, B22), n/2) P2 = strassenMatrixMultiply(addMatrices(A11, A12), B22, n/2) P3 = strassenMatrixMultiply(addMatrices(A21, A22), B11, n/2) P4 = strassenMatrixMultiply(A22, subtractMatrices(B21, B11), n/2) P5 = strassenMatrixMultiply(addMatrices(A11, A22), addMatrices(B11, B22), n/2) P6 = strassenMatrixMultiply(subtractMatrices(A12, A22), addMatrices(B21, B22), n/2) P7 = strassenMatrixMultiply(subtractMatrices(A11, A21), addMatrices(B11, B12), n/2) # Calculate resulting submatrices C11 = subtractMatrices(addMatrices(addMatrices(P5, P4), P6), P2) C12 = addMatrices(P1, P2) C21 = addMatrices(P3, P4) C22 = subtractMatrices(subtractMatrices(addMatrices(P5, P1), P3), P7) # Combine submatrices to form the result matrix C C = combineMatrices(C11, C12, C21, C22) return C
  • 15. 15 Practical limitations of Strassen’s Matrix • Overhead and Constants: Strassen’s algorithm introduces overhead due to recursive calls and splitting, making traditional multiplication faster for smaller matrices. • Memory Usage: Higher memory demand can slow performance if resources are limited. • Practical Constants: The O() improvement is only significant for very large matrices. • Non-Power-of-Two Sizes: Works best for power-of-two dimensions; padding for other sizes reduces benefits. • Complexity: Strassen's algorithm is more complex and prone to coding errors than traditional methods.
  • 16. 16 Real World applications of Strassen’s Matrix • Scientific Computing: Used in simulations like fluid dynamics and weather modeling. • Image Processing: Efficient for high-resolution images in tasks like compression and filtering. • Machine Learning: Speeds up matrix-heavy tasks like linear regression and PCA. • Cryptography: Improves efficiency in matrix-based encryption. • Numerical Analysis: Enhances numerical methods in physics and engineering.
  • 17. 17 General Matrix Multiplication (Python Code) import numpy as np def matrix_multiplication(X, Y): # Get dimensions p, q = X.shape q, r = Y.shape # Initialize the result matrix Z with zeros Z = np.zeros((p, r)) # Perform multiplication for i in range(p): for j in range(r): for k in range(q): Z[i, j] += X[i, k] * Y[k, j] return Z # Example usage X = np.array([[1, 2], [3, 4]]) Y = np.array([[5, 6], [7, 8]]) Z = matrix_multiplication(X, Y) print("Result of General Matrix Multiplication:n", Z) Explanation: • We take two matrices X (size p×q) and Y (size q×r). • We initialize a result matrix Z of size p×r, filled with zeros. • For each element in Z[i,j], we compute the sum of the element-wise products of the corresponding row from X and the corresponding column from Y. • This is the triple loop approach: outer loops for the row (i) and column (j), and an inner loop for computing the dot product (k). X = [[1, 2], [3, 4]] Y = [[5, 6], [7, 8]] Z = [[19 22] [43 50]] Input: Output:
  • 18. 18 Strassen Matrix Multiplication (Python Code) import numpy as np def add_matrix(A, B): return A + B def subtract_matrix(A, B): return A - B def strassen_multiplication(A, B): # Base case when matrix size is 1x1 if len(A) == 1: return A * B # Splitting matrices into quadrants mid = len(A) // 2 A11, A12, A21, A22 = A[:mid, :mid], A[:mid, mid:], A[mid:, :mid], A[mid:, mid:] B11, B12, B21, B22 = B[:mid, :mid], B[:mid, mid:], B[mid:, :mid], B[mid:, mid:] # Strassen's formulas M1 = strassen_multiplication(add_matrix(A11, A22), add_matrix(B11, B22)) M2 = strassen_multiplication(add_matrix(A21, A22), B11) M3 = strassen_multiplication(A11, subtract_matrix(B12, B22)) M4 = strassen_multiplication(A22, subtract_matrix(B21, B11)) M5 = strassen_multiplication(add_matrix(A11, A12), B22) M6 = strassen_multiplication(subtract_matrix(A21, A11), add_matrix(B11, B12)) M7 = strassen_multiplication(subtract_matrix(A12, A22), add_matrix(B21, B22)) # Combining the results into a single matrix C11 = M1 + M4 - M5 + M7 C12 = M3 + M5 C21 = M2 + M4 C22 = M1 - M2 + M3 + M6 # Stacking the submatrices to form the result matrix C = np.vstack((np.hstack((C11, C12)), np.hstack((C21, C22)))) return C # Example usage A = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) B = np.array([[17, 18, 19, 20], [21, 22, 23, 24], [25, 26, 27, 28], [29, 30, 31, 32]]) C = strassen_multiplication(A, B) print("Result of Strassen Matrix Multiplication:n", C)

Editor's Notes

  • #13: 7 multiplications