I have a $B$ matrix: $B = B_{ij}$
I need to find closed matrix formulation of:
$$\sum_i \sum_j \sum_m \sum_n B_{ij} B_{jm} B_{mn} B_{ni}$$
But I am so confused!
Edit by Henrik:
Originally, it was asked to express
$$\sum_i \sum_j \sum_m \sum_n B_{mi} B_{mj} B_{ni} B_{nj}$$
in terms of matrices.
actually, there is also a condition: i is not equal to j.
If this is indeed a Mathematica question, then first note that:
$$\sum _j B_{i,j} B_{j,k}\equiv (B.B)_{i,j}$$
and
$$\sum _i B_{i,i}\equiv \operatorname{Tr}[B]$$
So, the Mathematica equivalent of:
$$\sum _i \sum _j \sum _m \sum _n B_{i,j} B_{j,m} B_{m,n} B_{n,i} $$
is:
or:
For the original form of the question, note that:
$$ B_{i,j}\equiv B^T{}_{j,i} $$
So, the Mathematica equivalent of:
$$\sum _i \sum _j \sum _m \sum _n B_{m,i} B_{m,j} B_{n,i} B_{n,j}$$
is:
Addendum
The OP added the requirement that terms where $i=j$ should not be included. Without explaining why, you can use the following to compute this version:
$$\sum _i \sum _j \sum _m \sum _n B_{m,i} B_{n,i} B_{m,j} B_{n,j} \ \left(1-\delta _{i,j}\right)\equiv \operatorname{Tr}\left[B^T.B.B^T.B\right]-\ \operatorname{Tr}\left[\left(B^T.B\right)^2\right]$$
For your example, $B=\left( \begin{array}{cc} 1 & 2 \\ 3 & 4 \\ \end{array} \right)$, we have: