Speed up

To further speed up these computations, we see that these sums can be written in terms of matrix-matrix multiplications. It is not obvious how to write all of these sums in such a way, but it is useful to first recall that the expression for the multiplication of two matrices \( \hat{C} =\hat{A}\times \hat{B} \) can be written as $$ \begin{equation} C_{ij} = \sum_{k} A_{ik} \times B_{kj}. \tag{20} \end{equation} $$ We observe then that equation (17) can be written as \[ \langle K| \chi |I\rangle = \langle K|v|I\rangle + \frac{1}{2} \sum_{C} \langle K|v|C\rangle \langle C|t|I\rangle \] by mapping the two index pairs \( kl \to K, ij \to I, cd \to C \). The sum looks now like a matrix-matrix multiplication. This is useful because there are packages like BLAS (Basic Linear Algebra Subprograms) which have extremely fast implementations of matrix-matrix multiplication.