Well, I asked this question on Math SE, and didn't get any responses, so I'm trying it here.
Given an $M*N*P$ tensor $T$, is there a fast way of computing the following "eighth-power trace"? $$ f(T) = \sum_{m,n,p} T_{m_{00},n_{00},p_{00}} T_{m_{01},n_{01},p_{00}} T_{m_{10},n_{00},p_{01}} T_{m_{11},n_{01},p_{01}} T_{m_{00},n_{10},p_{10}} T_{m_{01},n_{11},p_{10}} T_{m_{10},n_{10},p_{11}} T_{m_{11},n_{11},p_{11}} $$ That is, imagine 8 copies of the tensor lying at the vertices of a cube and contract along all the edges. The 2-dimensional analog for an $M*N$ matrix $T$ would be $Tr( (T^t T)^2 )$. Is there any faster or less memory-intensive way than just contracting along $M$ to get a $N^2*P^2$ matrix $T' \approx T^2$ and then computing $Tr((T'^t T')^2)$?