# Generalization of the correlation function

**URL:** <https://itensor.discourse.group/t/generalization-of-the-correlation-function/497>\
**Category:** ITensor C++ Questions\
**Created:** [November 4, 2022, 4:35pm UTC](https://itensor.discourse.group/t/generalization-of-the-correlation-function/497 "2022-11-04T16:35:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fra](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@fra](https://itensor.discourse.group/u/fra)\
**Post date:** [November 4, 2022, 4:35pm UTC](https://itensor.discourse.group/t/generalization-of-the-correlation-function/497/1 "2022-11-04T16:35:53Z")

</div>

Hi everyone,  
I am trying to compute the expectation value of a correlation function made up by a string of operators, something like :  
C\_z=\langle\sigma^1\_z\otimes\sigma^2\_z\otimes\sigma^3\_z\otimes\sigma^4\_z\otimes\sigma^5\_z\otimes\sigma^6\_z\rangle

If you are including code in your question or comment, please put it in a code block as follows:

```auto
        int m=1;
        int n=6;
        for(int l = m; l <= n; ++l)
        {
            auto Sz = op(sites,"Sz",l);
            auto C = psi0(l)*Sz;
            auto ir = commonIndex(psi0(l),psi0(l+1),"Link");
            auto D = dag(prime(prime(psi0(l),"Site"),ir));
            if(l==n)
            {   
                auto E=C*D;
                E *= dag(prime(prime(psi0(l),"Site"),"Link"));
                println("E = ",E);
                elt(E);
            }

        } 

```

- 

I am trying to generalize the following tutorial ([ITensor](https://itensor.org/docs.cgi?page=tutorials/correlations)), but I am making some mistake, because E is not a scalar. Any idea on how to fix this ?  
Thank you for your time,  
Francesco

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [November 4, 2022, 5:42pm UTC](https://itensor.discourse.group/t/generalization-of-the-correlation-function/497/2 "2022-11-04T17:42:24Z")

</div>

Hi Francesco,

You’re not carrying a (contracted) tensor along for each site, like the `C*=...` in the tutorial. Ignoring the ends there should be something like

```auto
\\set up C tensor here
for(int l = m; l < n; ++l){
  C*= psi0(l)*op(sites,"Sz",l);
  C*= dag(prime(psi0(l));
}

```

within the loop

---

<div class="post-metadata">

**Author:** ![fra](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@fra](https://itensor.discourse.group/u/fra)\
**Post date:** [November 7, 2022, 11:57am UTC](https://itensor.discourse.group/t/generalization-of-the-correlation-function/497/3 "2022-11-07T11:57:02Z")

</div>

Thank you for your answer, now I figured it out and it is working properly !
