Consider the problem of matrix multiplication. A matrix A
of shape (n, m)
may be multiplied by a matrix B
of shape (m, p)
to produce a new matrix A * B
of shape (n, p)
. The number of scalar multiplications required to perform this operation is n * m * p
.
Now consider the problem of multiplying three or more matrices together. It turns out that matrix multiplication is associative, but the number of scalar multiplications required to perform such operation depends on the association.
For example, consider three matrices of the following shapes:
A: (3, 5)
B: (5, 7)