Use Strassen’s algorithm to compute the matrix product
$\begin{pmatrix} 1 & 3 \\ 7 & 5 \end{pmatrix}\begin{pmatrix} 6 & 8 \\ 4 & 2 \end{pmatrix}$.
Show your work.
Write pseudocode for Strassen’s algorithm.
def matrix_product_strassen_sub(a, b, r_low, r_high, c_low, c_high):
n = r_high - r_low
if n == 1:
return [[a[r_low][c_low] * b[r_low][c_low]]]
mid = n // 2
r_mid = (r_low + r_high) // 2
c_mid = (c_low + c_high) // 2
s = [[[0 for _ in range(mid)] for _ in range(mid)] for _ in range(10)]
for i in range(mid):
for j in range(mid):
s[0][i][j] = b[r_low + i][c_mid + j] - b[r_mid + i][c_mid + j]
s[1][i][j] = a[r_low + i][c_low + j] + a[r_low + i][c_mid + j]
s[2][i][j] = a[r_mid + i][c_low + j] + a[r_mid + i][c_mid + j]
s[3][i][j] = b[r_mid + i][c_low + j] - b[r_low + i][c_low + j]
s[4][i][j] = a[r_low + i][c_low + j] + a[r_mid + i][c_mid + j]
s[5][i][j] = b[r_low + i][c_low + j] + b[r_mid + i][c_mid + j]
s[6][i][j] = a[r_low + i][c_mid + j] - a[r_mid + i][c_mid + j]
s[7][i][j] = b[r_mid + i][c_low + j] + b[r_mid + i][c_mid + j]
s[8][i][j] = a[r_low + i][c_low + j] - a[r_mid + i][c_low + j]
s[9][i][j] = b[r_low + i][c_low + j] + b[r_low + i][c_mid + j]
p = [[[0 for _ in range(mid)] for _ in range(mid)] for _ in range(7)]
for i in range(mid):
for j in range(mid):
for k in range(mid):
p[0][i][j] += a[r_low + i][c_low + k] * s[0][k][j]
p[1][i][j] += s[1][i][k] * b[r_mid + k][c_mid + j]
p[2][i][j] += s[2][i][k] * b[r_low + k][c_low + j]
p[3][i][j] += a[r_mid + i][c_mid + k] * s[3][k][j]
p[4][i][j] += s[4][i][k] * s[5][k][j]
p[5][i][j] += s[6][i][k] * s[7][k][j]
p[6][i][j] += s[8][i][k] * s[9][k][j]
c = [[0 for _ in range(n)] for _ in range(n)]
for i in range(mid):
for j in range(mid):
c[r_low + i][c_low + j] = p[4][i][j] + p[3][i][j] - p[1][i][j] + p[5][i][j]
c[r_low + i][c_mid + j] = p[0][i][j] + p[1][i][j]
c[r_mid + i][c_low + j] = p[2][i][j] + p[3][i][j]
c[r_mid + i][c_mid + j] = p[4][i][j] + p[0][i][j] - p[2][i][j] - p[6][i][j]
return c
def matrix_product_strassen(a, b):
n = len(a)
return matrix_product_strassen_sub(a, b, 0, n, 0, n)
How would you modify Strassen’s algorithm to multiply
$n \times n$ matrices in which$n$ is not an exact power of$2$ ? Show that the resulting algorithm runs in time$\Theta(n^{\lg 7})$ .
Extend the matrix with zeros.
What is the largest
$k$ such that if you can multiply$3 \times 3$ matrices using k multiplications (not assuming commutativity of multiplication), then you can multiply$n \times n$ matrices in time$\Theta(n^{\lg 7})$ ? What would the running time of this algorithm be?
Running time:
V. Pan has discovered a way of multiplying
$68 \times 68$ matrices using$132,464$ multiplications, a way of multiplying$70 \times 70$ matrices using$143,640$ multiplications, and a way of multiplying$72 \times 72$ matrices using$155,424$ multiplications. Which method yields the best asymptotic matrix-multiplication algorithm? How does it compare to Strassen’s algorithm?
How quickly can you multiply a
$kn \times n$ matrix by an$n \times kn$ matrix, using Strassen’s algorithm as a subroutine? Answer the same question with the order of the input matrices reversed.
Reversed:
Show how to multiply the complex numbers
$a + bi$ and$c + di$ using only three multiplications of real numbers. The algorithm should take$a$ ,$b$ ,$c$ , and$d$ as input and produce the real component$ac - bd$ and the imaginary component$ad + bc$ separately.
Real component:
Image component: