# Eigenvalues of partially transposed tensor

Hi,
I'm trying to calculate the negativity (see section VI of this paper) for 1D systems. To this end I need to find the eigenvalues of the partial transpose of a tensor. In simple words, if my tensor has 4 indexes (i,j,i',j'), then I need to find the eigenvalues of the matrix whose indexes are (i, j') and (i',j) (instead of (i,j) and (i',j')).
Now in order to use the method diagHermitian I have to change the prime level of the indexes, so what I've done is this:

//The indexes of the tensor E12 to be swapped:
auto icl = commonIndex(E12 , psi.A(rlim1+1));
//I guess I could've done: auto iclp=prime(icl); as well.
//Now I have the indexes, and I want to swap the prime level:
E12.prime(icl,4);
icl.prime(4);//This is necessary for icl being related to the corresponding index in E12.
E12.prime(iclp,-1);
iclp.prime(-1);
E12.prime(icl,-3);
icl.prime(-3);
//Now the left index of E12 is swapped:
//the prime level (0,1) --> (1,0).
//The index named iclp is not primed, and icl is primed.
IQTensor U,D;
diagHermitian(E12,U,D);


Now this looks quite cumbersome to me. So my (least important) questions are:
1. Is there a better way to swap the indexes? swapPrime wouldn't help, because I have another index (of the same type, namely j,j') which must stay untouched.
2. Is there a simple way to force diagHermitian to group the indexes as I wish instead of the usual way? This will make the swapping unnecessary, of course.

Now my more pressing question is about a case where the tensor to be partially transposed is a product of two diagonal matrices (the S matrix of a svd). The product is supposed to be such that the result will have 4 indexes, because only that way the partial transpose is defined. So my question is:
3. Is there a simple way to convert a diag matrix to a dense one? Alternately, is there a way to do diag*diag --> dense (with 4 indexes) ?

Thanks a lot for all the wonderful work!
I'm really enjoying this library, although I have no former experience in c++!
Yishai

related to an answer for: Contraction of two sparse tensors