# Swapping indices of an MPS for Hubbard

Hello,

I have written a code that creates MPS's as a product of valence bonds for Hubbard. The code works fine for the cases where the valence bonds have adjacent sites., ie. for 6 sites: 1-2 3-4 5-6, 1-2 5-6 3-4, etc. My guess is that I am doing something wrong when I swap the indices and there must be a difference for Hubbard and Heisenberg, because for Heisenberg the same swapping part of the code works. Below is the code I have written:

            ITensor wf, S,V,U;
for (int i=swaps_.size()-1; i>=0; i--){
// swaps_ has all the swaps that are necessary so that I get the pattern that I want.
// swaps_ is calculated somewhere else, but I do not think it matters for the code below.
// Below is some code that gets the indices, again, not super important I think.
ar1 = swaps_[i].first;
ar2 = swaps_[i].second;
s1.clear(); s1.push_back(siteIndex(psi,ar1));
s2.clear(); s2.push_back(siteIndex(psi,ar2));
auto is1 = IndexSet(s1);
auto is2 = IndexSet(s2);
// And below comes the swapping part that works for Heisenberg.
psi.position(ar1);
wf = psi.A(ar1)*psi.A(ar2);
wf.swapInds(is1,is2);
wf.noPrime();
U = psi.A(ar1);
svd(wf,U,S,V,{"Cutoff=",1E-8});
psi.setA(ar1,U);
psi.setA(ar2,S*V);
}


Does anyone have any input maybe? Am I missing a sign for the fermionic wavefunction somehow that disturbs the final result? Could the error be somewhere else? The Hubbard that I am using preserves all quantum numbers.

Thank you,
Thanos

commented by (8.5k points)
Probably you need to add a "fermionic swap" during your swap operation, i.e. an operator that acts as identity for even parity sectors of the site indices but has a minus sign for odd parity sectors of the site indices.

-Matt
commented by (310 points)
But how does the parity sector translate into the site ordering? Do you maybe have an example?

ie. 1,2,3,4 -> 1,4,2,3, does this need a sign correction?
commented by (8.5k points)
edited
You should think about it as implementing a site reordering in terms of a series of pairwise swaps, i.e.:

s1,s2,s3,s4 -> s1,s2,s4,s3 -> s1,s4,s2,s3

Then, there would be a fermionic swap gate that implements (s3,s4) -> (s4,s3), and then one that implements (s2,s4) -> (s4,s2). The same fermionic swap gate implements the general operation (si,sj) -> (sj,si). For spinless fermions, for example, the fermionic swap gate would be something like:

1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 -1

where there is a -1 in the doubly-occupied subspace (so for the basis |00>, |01>, |10>, |11>).
commented by (310 points)
Great, I think I understood now and I also think the code works. Thank you so much!