# TRG sample code provided on the hompage produces errors during compilation

+1 vote

I tried to run the sample code for TRG provided on the ITensor homepage (https://itensor.org/docs.cgi?page=book/trg&vers=cppv3) to familiarize myself with ITensor. I followed the instructions, cloned the latest version of ITensor with git, successfully installed it and tried to compile the code. However, I received the following error message:
trg.cc: In function ‘int main()’:
trg.cc:47:12: error: 3 names provided while ‘std::tuple<itensor::ITensor, itensor::ITensor>’ decomposes into 2 elements
auto [Fl,Fr,lnew] = factor(A,{r,d},{l,u},{"MaxDim=",maxdim,
^~~~~~~~~~~~~
trg.cc:52:12: error: 3 names provided while ‘std::tuple<itensor::ITensor, itensor::ITensor>’ decomposes into 2 elements
auto [Fu,Fd,u
new] = factor(A,{l,d},{u,r},{"MaxDim=",maxdim,

Looking into the documentation, factor should behave as

factor(ITensor T, IndexSet Ais[, IndexSet Bis],
Args args = Args::global()) -> std::tuple<ITensor,ITensor>


Indeed, if I replace the the call to factor with

auto [Fl,Fr] = factor(A,{r,d},{l,u},{"MaxDim=",maxdim,
"Tags=","left,scale="+str(scale),
"ShowEigs=",true});
auto l_new = commonIndex(Fl,Fr);


and correspondingly the second call for factoring A in Fu, Fd , everything seems to work fine.

I was just wondering if I overlooked something, or if the calls to factor in the example provided should be replaced as shown above?

commented by (37.3k points)
Thanks for catching this & for the bug report. Just updated the website as Matt suggested to make this change.
commented by (170 points)
Thanks Matt, thanks Miles.
Just one more thing I stumbled across on the website: isn't there a @@ -2\beta @@ too much in the formula for @@ \ln(Z)/N_s @@? Since @@ \ln(Z)/N_s @@ should be   @@ -\beta F @@ with  @@ F @@ the free energy density, this should go as shown here: https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Exact_solution
Indeed, if I remove the @@ -2\beta @@ from the formula and compare the output of ITensor for various temperatures, it matches nicely.
commented by (37.3k points)
Thanks for noticing this. I don't recall why I added that term to the solution, but I checked and you're right that the TRG code agrees only when it's removed. So I just made that change to the website!

+1 vote