# How to calculate four point correlation function in ITensor v3 C++ version

Dear ITensor team,
Thanks for your reply and thanks for the wonderful library about TensorNetwork. Recently, I want to calculate spin four point correlation function e.g. <S^{x}{I}S^{y}{I+1}S^{x}{j}S^{y}{j+1}>.

I am using the latest version of ITensor c++ and i find some documents about how to calculate 2-pt correlation function

I try to coding (just show in the below), but the result is wrong.

op_i = op(sites,“Sx”,i);
auto op_i1 = op(sites,“Sy”,i+1);
op_j = op(sites,“Sx”,j);
auto op_j1 = op(sites,“Sy”,j+1);

//ground state

psi_gs = psi;

psi_gs.position(i);

psi_gsdag = dag(psi_gs);

auto Cg = prime(psi_gs(i),li_1)*op_i;

Cg *= prime(psi_gsdag(i),“Site”);

Cg *= psi_gs(i+1)*op_i1;

Cg *= prime(psi_gsdag(i+1),“Site”);

for(int k=i+2; k<j;++k)
{
Cg *= psi_gs(k);
Cg *= psi_gsdag(k);
}

Cg *= psi_gs(j)*op_j;
Cg *= prime(psi_gsdag(j),“Site”);

Cg *= prime(psi_gs(j+1),lj)*op_j1;
Cg *= prime(psi_gsdag(j+1),“Site”);

auto resultg = eltC(Cg);

Thanks a lot in advance !
Best regards,
Sugar

Hi, when you say the result is wrong, what happens? Do you mean you get a wrong number? Or that you get an error message?

Most likely the code is not actually doing what you think. I would suggest printing out the tensor Cg after each step of your code for a small system size and looking at its indices to see if it always has the indices you expect. One thing you can do to slow down the printing of the code is to put the line `PAUSE;` and then it will pause the execution of the code until you hit “Enter” to go to the next part of the code.

(Not exactly an answer to the question but I’ll point out that we are developing a package for computing arbitrary n-point correlators in Julia: GitHub - ITensor/ITensorCorrelators.jl).