Matrix Multiplication

Similar documents
! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution.

Copyright 2000, Kevin Wayne 1

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

DIVIDE AND CONQUER II

Matrix Multiplication. Data Structures and Algorithms Andrei Bulatov

The Divide-and-Conquer Design Paradigm

Introduction to Algorithms 6.046J/18.401J/SMA5503

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1

Chapter 5. Divide and Conquer. CS 350 Winter 2018

Copyright 2000, Kevin Wayne 1

CS 580: Algorithm Design and Analysis

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d)

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d)

Complexity of Matrix Multiplication and Bilinear Problems

Divide-and-conquer algorithm

Chapter 4 Divide-and-Conquer

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

DIVIDE AND CONQUER II

CS 4424 Matrix multiplication

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

Fast Matrix Multiplication Over GF3

Matrices: 2.1 Operations with Matrices

CPS 616 DIVIDE-AND-CONQUER 6-1

Fast Matrix Product Algorithms: From Theory To Practice

Chapter 2. Divide-and-conquer. 2.1 Strassen s algorithm

Group-theoretic approach to Fast Matrix Multiplication

Ma/CS 6b Class 12: Graphs and Matrices

DIVIDE AND CONQUER II

Chapter 1: Systems of linear equations and matrices. Section 1.1: Introduction to systems of linear equations

Kartsuba s Algorithm and Linear Time Selection

Divide and Conquer. Chapter Overview. 1.2 Divide and Conquer

Numerical Linear Algebra

An introduction to parallel algorithms

How to find good starting tensors for matrix multiplication

Divide-and-Conquer. a technique for designing algorithms

Computational complexity and some Graph Theory

Design and Analysis of Algorithms

Fast reversion of formal power series

William Stallings Copyright 2010

MATRICES. a m,1 a m,n A =

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

Matrix Arithmetic. j=1

Lesson 12.7: Sequences and Series

Lecture 9: Submatrices and Some Special Matrices

IEEE TRANSACTIONS ON EVOLUTIONARY COMPUTATION 1

CSE 421 Algorithms: Divide and Conquer

Divide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1

CS475: Linear Equations Gaussian Elimination LU Decomposition Wim Bohm Colorado State University

Divide and Conquer algorithms

Phys 201. Matrices and Determinants

Fast reversion of power series

Fast Matrix Multiplication*

Powers of Tensors and Fast Matrix Multiplication

Introduction to Matrices

A Review of Matrix Analysis

Fast Convolution; Strassen s Method

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 1 x 2. x n 8 (4) 3 4 2

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 13

Algorithms Design & Analysis. Dynamic Programming

The System of Linear Equations. Direct Methods. Xiaozhou Li.

feb abhi shelat Matrix, FFT

Solving Recurrences. Lecture 23 CS2110 Fall 2011

10.34: Numerical Methods Applied to Chemical Engineering. Lecture 2: More basics of linear algebra Matrix norms, Condition number

Divide-and-conquer: Order Statistics. Curs: Fall 2017

RECAP How to find a maximum matching?

A Divide-and-Conquer Algorithm for Functions of Triangular Matrices

Vectors and matrices: matrices (Version 2) This is a very brief summary of my lecture notes.

LU Factorization. Marco Chiarandini. DM559 Linear and Integer Programming. Department of Mathematics & Computer Science University of Southern Denmark

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014

Fractions. Review R.7. Dr. Doug Ensley. January 7, Dr. Doug Ensley Review R.7

DO NOT USE WITHOUT PERMISSION

ENGR-1100 Introduction to Engineering Analysis. Lecture 21. Lecture outline

Strassen-like algorithms for symmetric tensor contractions

ENGR-1100 Introduction to Engineering Analysis. Lecture 21

THE COMPLEXITY OF THE QUATERNION PROD- UCT*

I. Approaches to bounding the exponent of matrix multiplication

On the Exponent of the All Pairs Shortest Path Problem

Elementary maths for GMT

Asymptotic Analysis and Recurrences

Sequences. 1. Number sequences. 2. Arithmetic sequences. Consider the illustrated pattern of circles:

Divide and Conquer Algorithms

10. Linear Systems of ODEs, Matrix multiplication, superposition principle (parts of sections )

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Linear Algebra Tutorial for Math3315/CSE3365 Daniel R. Reynolds

I&C 6N. Computational Linear Algebra

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

Dynamic Programming: Matrix chain multiplication (CLRS 15.2)

Topic 17. Analysis of Algorithms

1 Multiply Eq. E i by λ 0: (λe i ) (E i ) 2 Multiply Eq. E j by λ and add to Eq. E i : (E i + λe j ) (E i )

Algebra 2 Matrices. Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Find.

Kevin James. MTHSC 3110 Section 2.1 Matrix Operations

Matrices. Chapter Definitions and Notations

Transcription:

Matrix Multiplication

Matrix Multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. n c ij = a ik b kj k=1 c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn = a 11 a 12 a 1n a 21 a 22 a 2n a n1 a n2 a nn b 11 b 12 b 1n b 21 b 22 b 2n b n1 b n2 b nn Brute force. Θ(n 3 ) arithmetic operations. Fundamental question. Can we improve upon brute force? 2

Matrix Multiplication: Warmup Divide-and-conquer. Divide: partition A and B into ½n-by-½n blocks. Conquer: multiply 8 ½n-by-½n recursively. Combine: add appropriate products using 4 matrix additions. C 11 C 12 = A 11 A 12 B 11 B 12 C 21 C 22 A 21 A 22 B 21 B 22 ( ) + ( A 12 B 21 ) ( ) + ( A 12 B 22 ) ( ) + ( A 22 B 21 ) ( ) + ( A 22 B 22 ) C 11 = A 11 B 11 C 12 = A 11 B 12 C 21 = A 21 B 11 C 22 = A 21 B 12 ( ) T(n) = 8T n/2 + Θ(n2 ) recursive calls add, form submatrices T(n) = Θ(n 3 ) 3

Matrix Multiplication: Key Idea Key idea. multiply 2-by-2 block matrices with only multiplications. C 11 C 12 = C 21 C 22 A 11 A 12 B 11 B 12 A 21 A 22 B 21 B 22 P 1 = A 11 (B 12 B 22 ) P 2 = ( A 11 + A 12 ) B 22 C 11 = P 5 + P 4 P 2 + P 6 C 12 = P 1 + P 2 C 21 = P 3 + P 4 C 22 = P 5 + P 1 P 3 P P 3 = ( A 21 + A 22 ) B 11 P 4 = A 22 (B 21 B 11 ) P 5 = ( A 11 + A 22 ) (B 11 + B 22 ) P 6 = ( A 12 A 22 ) (B 21 + B 22 ) P = ( A 11 A 21 ) (B 11 + B 12 ) multiplications. 18 = 10 + 8 additions (or subtractions). 4

Fast Matrix Multiplication Fast matrix multiplication. (Strassen, 1969) Divide: partition A and B into ½n-by-½n blocks. Compute: 14 ½n-by-½n matrices via 10 matrix additions. Conquer: multiply ½n-by-½n matrices recursively. Combine: products into 4 terms using 8 matrix additions. Analysis. Assume n is a power of 2. T(n) = # arithmetic operations. ( ) T(n) = T n /2 + Θ(n2 ) recursive calls add, subtract T(n) = Θ(n log 2 ) = O(n 2.81 ) 5

Fast Matrix Multiplication in Practice Implementation issues. Sparsity. Caching effects. Numerical stability. Odd matrix dimensions. Crossover to classical algorithm around n = 128. Common misperception: "Strassen is only a theoretical curiosity." Advanced Computation Group at Apple Computer reports 8x speedup on G4 Velocity Engine when n ~ 2,500. Range of instances where it's useful is a subject of controversy. Remark. Can "Strassenize" Ax=b, determinant, eigenvalues, and other matrix ops. 6

Θ(n log 2 ) = O(n 2.81 ) Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log 3 21 ) = O(n 2. ) Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log 3 21 ) = O(n 2. ) Decimal wars. Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log 3 21 ) = O(n 2. ) Decimal wars. December, 199: O(n 2.521813 ). Θ(n log 0 143640 ) = O(n 2.80 )

Q. Multiply two 2-by-2 matrices with only scalar multiplications? Θ(n log 2 ) = O(n 2.81 ) A. Impossible. [Hopcroft and Kerr, 191] Q. Two 3-by-3 matrices with only 21 scalar multiplications? A. Also impossible. Q. Two 0-by-0 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log 3 21 ) = O(n 2. ) Decimal wars. December, 199: O(n 2.521813 ). January, 1980: O(n 2.521801 ). Θ(n log 0 143640 ) = O(n 2.80 )

Best known. O(n 2.36 ) [Coppersmith-Winograd, 198.] Conjecture. O(n 2+ε ) for any ε > 0. Caveat. Theoretical improvements to Strassen are progressively less practical. 8