I want to compute ${\rm Tr}(ABAB)$ where $A$ and $B$ are both symmetric, and $B$ is diagonal. Is there a "simple" way to do this?
For example, I know that when $B$ is diagonal, ${\rm Tr}(AB) = \sum_{i} A_{ii} B_{ii}$: is there something similar for this more complicated expression?
Let $A=(a_{ij})_{1 \leq i,j \leq n}$ and $B=(b_{ii})_{1 \leq i,j \leq n}$. Then
\begin{align*} \mathrm{Tr}(ABAB)&=\sum_{i=1}^n (ABAB)_{ii} \\ & = \sum_{i=1}^n \sum_{k=1}^n \sum_{l=1}^n \sum_{p=1}^n a_{ik} b_{kl}a_{lp}b_{pi} \\ & = \sum_{i=1}^n \sum_{k=1}^n a_{ik} b_{kk}a_{ki}b_{ii} \quad \textit{(because $B$ is diagonal)}\\ & = \sum_{i=1}^n \sum_{k=1}^n a_{ik}^2 b_{kk}b_{ii} \quad \textit{(because $A$ is symmetric)} \end{align*}