I am working on the single particle entanglement entropy and in the process I have something like
Table[
Sum[
states[[eindex, spaceindex]] * states[[eindex, spaceindex2]],
{eindex,1, Na/2}(*trace over lower-half filling*)
],
{spaceindex, 1, Nb},
{spaceindex2, 1, Nb}(*some subsystem*)
]
where states
is a Na
by Na
square matrix, from diagonalizing some other matrix. 1<Nb
<Na
is some sub-system. The matrix I am trying to construct is essentially $C_{i,j}=Tr[states[k,i]*states[k,j]]$ traced over the first index.
The above code gets the job done but I wonder if there are more efficient ways.
Also, I keep getting myself into this situation where I need to generate a matrix efficiently via similar constructions, for example, projection matrices. I would also like to know some general ways to directly translate the equations into efficient code.
Transpose[a].b
$\endgroup$