(AB)C = A(BC) for matrix. Why can I move the sum? I am having trouble understanding why the proof of (AB)C = A(BC) works for matrix multiplication.
Let's say our matrices are :
A of size m x n, B of n x p and C of p x q
I understand that I simply need to do the following :
$\sum_{k=0}^{p-1} (AB)_{ik} C_{kj} = \sum_{k=0}^{p-1}[(\sum_{l=0}^{m-1} A_{il}B_{lk}) C_{kj}]$
Here I was stuck, but when I looked at the answer I was also confused (probably a lack of knowledge somewhere or a big misunderstanding)
Because apparently the next step is to move the second sum to the left of the equation :
$\sum_{l=0}^{m-1}[A_{il}\sum_{k=0}^{p-1} B_{lk} C_{kj}]$
From there the rest speaks for itself.
Why can I do that ? I am basically adding multiplications why should I be able to change the multiplications ? $1 * 2 + 2 * 3 \neq 1*3 + 2*2$
I am clearly missing something basic and very logic, can please someone guide me ?
 A: To keep the notation compact and focused on the essence, it is maybe good to write
$$
(AB)_{ik} =\sum_j A_{ij}B_{jk}\ .
$$
(The sum is finite, the intermediate index $j$ runs in a finite index set, the index set of the columns of $A$, respectively rows of $B$, which must match.)
Then which is the $il$ entry in $(AB)C$, and respectively $A(BC)$? Let us use $j,k$ to intermediate, and to correspond:
$$
\begin{aligned}
(\ (AB)C\ )_{il} &=\sum_k (AB)_{ik}C_{kl}=\sum_k \sum_j (A_{ij}B_{jk})C_{kl}\ ,\\
(\ A(BC)\ )_{il} &=\sum_j A_{ij}(BC)_{jl}=\sum_j \sum_k A_{ij}(B_{jk}C_{kl})\ .
\end{aligned}
$$
Now use $\displaystyle\sum_{j,k}$ instead of the double sums above, the addition is commutative, and the associativity in the ring of the entries of the matrices,
$$
(A_{ij}B_{jk})C_{kl} =
 A_{ij}(B_{jk}C_{kl})\ .
$$
A: You might find the following visual to be helpful. The sum $\sum_{k=0}^{p-1}[(\sum_{l=0}^{m-1} A_{il}B_{lk}) C_{kj}]$ can be written as $\sum_{k=0}^{p-1}[(\sum_{l=0}^{m-1} A_{il}B_{lk}C_{kj})]$, which, when expanded with ...'s, can be written as
$$
\matrix{&(A_{i0}B_{00}C_{0j}&+&A_{i1}B_{10}C_{0j}& + & \cdots & + & A_{i,m-1}B_{m-1,0} C_{0j})\\
+&(A_{i0}B_{01}C_{1j}&+&A_{i1}B_{11}C_{1j}& + & \cdots & + & A_{i,m-1}B_{m-1,1} C_{1j})\\
&&&&&\vdots\\
+&(A_{i0}B_{0,p-1}C_{p-1,j}&+&A_{i1}B_{1,p-1}C_{p-1,j}& + & \cdots & + & A_{i,m-1}B_{m-1,p-1} C_{p-1,j}).}
$$
The inner sum is a sum across each of the rows, and the outer sum is the sum of these "row" results.
If we take a sum along the "columns" in the above arrangement, then the sum of each column is $\sum_{k=0}^{p-1} A_{il} B_{lk} C_{kj}$ for some value of $k = 0,1,\dots,p-1$, and the sum of these "column" results is $\sum_{l=0}^{m-1}[\sum_{k=0}^{p-1} A_{il} B_{lk} C_{kj}]$. From here, we can factor $A_{il}$ out of the inner sum to get the desired result.
