Strassen's matrix multiplication

hip-hop, educational · 2:53

Listen on 93

Lyrics

[Verse 1]
Standard matrix multiplication got you feeling slow
N cubed complexity making algorithms crawl below
Volker Strassen had a vision back in sixty-nine
Seven multiplies instead of eight to cross the line
Breaking down the matrices into blocks of four
Each quadrant gets a name from A eleven to two four
Same thing for matrix B and result matrix C
Now we're ready for the magic, follow closely with me

[Chorus]
Seven products, not eight, that's the Strassen way
M one through M seven, remember what they say
Divide and conquer matrices, recursive all day
From N cubed down to N log two point eight one way
Seven products, not eight, complexity goes down
Strassen's algorithm wears the efficiency crown

[Verse 2]
M one equals A eleven plus A twenty-two times
B eleven plus B twenty-two, that's our first design
M two takes A twenty-one plus A twenty-two and then
Multiply by B eleven, second product in the pen
M three grabs A eleven times B twelve minus B twenty-two
M four uses A twenty-two times B twenty-one minus B eleven too
Each multiplication strategically placed with care
Seven products total, that's the genius we share

[Chorus]
Seven products, not eight, that's the Strassen way
M one through M seven, remember what they say
Divide and conquer matrices, recursive all day
From N cubed down to N log two point eight one way
Seven products, not eight, complexity goes down
Strassen's algorithm wears the efficiency crown

[Bridge]
When N gets large enough to make it worth the switch
Overhead of recursion won't put you in a ditch
Base case still classic when the size gets small
Hybrid implementation gives you best of all
Memory access patterns, cache efficiency
Strassen shows us how to beat the N cubed spree

[Verse 3]
M five combines A eleven plus A twelve with B twenty-two
M six takes A twenty-one minus A eleven times B eleven plus B twelve too
M seven uses A twelve minus A twenty-two times B twenty-one plus B twenty-two
Now combine these seven to get C in our view
C eleven gets M one plus M four minus M five plus M seven
C twelve equals M three plus M five, that's matrix heaven
C twenty-one takes M two plus M four
C twenty-two gets M one minus M two plus M three plus M six, nothing more

[Outro]
Seven multiplications broke the cubic bound
Divide and conquer principles where efficiency is found
Strassen's legacy lives on in algorithms today
When matrices get massive, this is how we play

← Bloom filters | Karatsuba multiplication →