TITLE: Complexity of computing $ABx$ depends on the order of multiplication
QUESTION [20 upvotes]: To calculate $y = ABx$ where $A$ and $B$ are two $N\times N$ matrices and $x$ is an vector in $N$-dimensional space. there are two methods. One is to first calculate $z=Bx$, and then $y = Az$. This way takes roughly $2N^2$ multiplications. The other is to first calculate $C = AB$, and then $y=Cx$. This way, however, takes $N^3+N^2$ multiplications!
Am I correct on this? I do not understand why change of the order of the calculation introduces so much difference in the computation complexity.

REPLY [4 votes]: Yes you are correct, this is used a lot in engineering. Two popular cases:

Knowing $AB$ and trying to find $A$ and $B$ which individually contain larger percent 0s than $AB$ multiplied together does. Usually called factoring or "fast transforms". If we lose enough non-zero numbers we can save calculations in this way.
Precomputing $AB$ if we have individual $A$ and $B$ and want to calculate $ABv$ for lots of $v$:s. This should be done if $AB$ is simpler than $A$, $B$ separately.