How to represent a matrix in index notation when it's a combination of more than two multiplications? Let's say there is an arbitrary matrix $A$. $A$ is $a_{ij}$ in index notation. $A^2$ can be written as $\sum_{ij}a_{ij}a_{ji}$. But I have no idea how to represent $A^3$ or $A^4$. I tried to find a way by computing every element of $A^3$ and $A^4$ but I didn't catch any rule to condense each element in index notation in index notation. Can you give me any insight?
 A: The quantity $\sum_{ij}a_{ij}a_{ji}\ $ is not an entry of $\ A^2\ $, but its trace.  The entry in the $\ i^\text{th}\ $ row and $\ k^\text{th}\ $ column of $\ A^2\ $ is $\ \sum_ja_{ij}a_{jk}\ $.  When you set $\ k=i\ $ you get the entry in the $\ i^\text{th}\ $ row and $\ i^\text{th}\ $ column—that is, the $\ i^\text{th}\ $ entry of the main diagonal.  Summing over $\ i\ $ then gives you the sum of the entries down the main diagonal, which is called the trace.
The entry in the $\ i^\text{th}\ $ row and $\ k^\text{th}\ $ column of $\ A^3\ $ is $\ \sum_{j_1j_2}a_{ij_1}a_{j_1j_2}a_{j_2k}\ $, and that in the $\ i^\text{th}\ $ row and $\ k^\text{th}\ $ column of $\ A^4\ $ is $\ \sum_{j_1j_2j_3}a_{ij_1}a_{j_1j_2}a_{j_2j_3}a_{j_3k}\ $.
A: You can start from what you already know about $A^2$.
Let $A^2=AA=[a_{i,j}^{(2)}]_{n,n}$, where $a_{i,j}^{(2)}=\sum_{k=1}^{n}a_{i,k}a_{k,j}$.
Now, $A^3=[a_{i,j}^{(3)}]_{n,n}=A^2A$, so, to obtain the expression for $a_{i,j}^{(3)}$, you'll have to find the dot product of the $i$th row of $A^2$ and the $j$th column of $A$:
$$
a_{i,j}^{(3)} = \sum_{k=1}^{n}a_{i,k}^{(2)}a_{k,j} = \sum_{k=1}^{n}\left(\sum_{\ell=1}^{n}a_{i,\ell}a_{\ell,k}\right)a_{k,j}=\\\sum_{k=1}^{n}\sum_{\ell=1}^{n}a_{i,\ell}a_{\ell,k}a_{k,j}
$$
The same way you can get the expression for $a_{i,j}^{(4)}$.
In general, for any $r=2,3,\ldots$, the following will hold: $$a_{i,j}^{(r)}=\sum_{k=1}^{n}a_{i,k}^{(r-1)}a_{k,j}$$
If $A$ is a diagonalizable matrix, i.e., it can be written as $A=PDP^{-1}$ where $D$ is a diagonal matrix, the expression becomes simpler because $A^r=PD^rP^{-1}$ , and computing powers of a diagonal matrix is straightforward:
$$D^r=\begin{bmatrix}d_1 & 0 & \ldots & 0 \\0 & d_2 & 0 & \ldots & 0 \\ \vdots & \vdots &\vdots  & \ddots & \vdots \\ 0 & 0 & 0 & \ldots & d_n\end{bmatrix}^r=\begin{bmatrix}d_1^r & 0 & \ldots & 0 \\0 & d_2^r & 0 & \ldots & 0 \\ \vdots & \vdots &\vdots  & \ddots & \vdots \\ 0 & 0 & 0 & \ldots & d_n^r\end{bmatrix}$$
