Dear All
I am trying to implement a product singlet state and measure the Sz of it. I tried tutorial/finiteT/ancilla.cc code as a start. My code is as follows:
#include "./itensor/all.h"
#include "./itensor/util/print_macro.h"
using namespace itensor;
int main()
{
int N = 2; //number of sites
auto sites = tJ(N,{"ConserveQNs=",true});
auto psi = MPS(sites);
for(int n = 1; n < N; n += 2)
    {
    auto s1 = sites(n);
    auto s2 = sites(n+1);
    auto wf = ITensor(s1,s2);
    wf.set(s1(1),s2(2), ISqrt2);
    wf.set(s1(2),s2(1), -ISqrt2);
    ITensor D;
    psi.ref(n) = ITensor(s1);
    psi.ref(n+1) = ITensor(s2);
    svd(wf,psi.ref(n),D,psi.ref(n+1));
    psi.ref(n) *= D;
    }
for (auto i : range1(N-1))
    {
    psi.position(i);
    auto bondket = psi(i)*psi(i+1);
    auto bondbra = dag(prime(bondket,"Site"));
    auto zzop = op(sites,"Sz",i)*op(sites,"Sz",i+1);
    auto zz = eltC(bondbra*zzop*bondket).real();
    printfln("%d Sz*Sz: %.12f",i,zz);
    }
for(auto j : range1(N))
        {
        psi.position(j);
        auto ket = psi(j);
        auto bra = dag(prime(ket,"Site"));
        auto Nupjop = op(sites,"Nup",j);
        auto Nupj = eltC(bra*Nupjop*ket).real();
        auto Ndnjop = op(sites,"Ndn",j);
        auto Ndnj = eltC(bra*Ndnjop*ket).real();
        auto szjop = op(sites,"Sz",j);
        auto szj = eltC(bra*szjop*ket).real();
        printfln("%d up:%.12f,dn:%.12f,tot:%.12f,sz:%.12f",j,Nupj,Ndnj,Nupj+Ndnj,szj);
        }
return 0;
}
So above I produced the product of singlet states (|up dn>-|dn up>)/sqrt2. I measured the Szi*Szj, Nupi, Ndni, Sz_i for this state. The result is :
1 S*S: 0.000000000000 Sz*Sz: 0.000000000000
1 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
2 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
This is wrong but I don't know why. 
I changed the number of sites to 4 and the result is:
1 S*S: 0.000000000000 Sz*Sz: 0.000000000000
2 S*S: 0.062500000000 Sz*Sz: 0.062500000000
3 S*S: 0.000000000000 Sz*Sz: 0.000000000000
1 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
2 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
3 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
4 up:0.500000000000,dn:0.000000000000,tot:0.500000000000,sz:0.250000000000
Can you pls tell me what is the problem of it? Thanks!
Eric