# eltC function generates wrong answer when calculating inner product

**URL:** <https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176>\
**Category:** ITensor C++ Questions\
**Tags:** cpp, mps\
**Created:** [December 17, 2024, 2:47pm UTC](https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176 "2024-12-17T14:47:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StrongCC](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/strongcc/32/679_2.png) [@StrongCC](https://itensor.discourse.group/u/StrongCC)\
**Post date:** [December 17, 2024, 2:47pm UTC](https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176/1 "2024-12-17T14:47:55Z")

</div>

Hello,  
I wonder why the eltC function and the innerC function generate the different results of the norm of the wave function.

```c++
      tJ sitesold;
      readFromFile("sites_file",sitesold);
      MPS psi(sitesold);
      readFromFile("psi_file",psi);
      psi.position(1);
      auto newdagpsi = dag(psi);
      auto Ctest = psi(1)*newdagpsi(1);
      for (int k=2 ;k<=Nx*Ny;k++)
      {
          Ctest *= psi(k);
          Ctest *= newdagpsi(k);
      }
      std::cout<<"testphi0"<<eltC(Ctest)<<std::endl;//result:testphi0(1.73505e+83,-8.44144e+65)
      std::cout<<"testphi0"<<innerC(psi,psi)<<std::endl; //result:testphi0(1,-1.484e-17)

```

The result generated by the eltC function is exponentially large, I do not know the reason. If you know why, please tell me, thank you very much!

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [December 18, 2024, 10:46pm UTC](https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176/2 "2024-12-18T22:46:44Z")

</div>

It looks like you need to prime the link indices of either `psi` or `newdagpsi` to make sure the link indices in the bra and ket don’t contract with each other.

---

<div class="post-metadata">

**Author:** ![StrongCC](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/strongcc/32/679_2.png) [@StrongCC](https://itensor.discourse.group/u/StrongCC)\
**Post date:** [December 19, 2024, 7:43am UTC](https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176/3 "2024-12-19T07:43:17Z")

</div>

Hi mtfishman,  
Thanks a lot! I have fixed the problem.  
This code was adapted from the code sample in “Operator Matrix Elements Involving Two MPS” in the code formulas, where the link indices of `dag(phi)` are not primed since we are measuring the correlation function between two different state |\phi\rangle and |\psi\rangle. In this example, prime the link indices of either `psi` or `newdagpsi` are important since they are the same state.  
Best regards,  
StrongCC

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [December 29, 2024, 7:43am UTC](https://itensor.discourse.group/t/eltc-function-generates-wrong-answer-when-calculating-inner-product/2176/4 "2024-12-29T07:43:32Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
