# Negative indices for lattice sites

+1 vote

For the exthubbard.cc code, when we take N sites, we define the Hamiltonian using for-loops where the index goes from 1 to N.
Can we make the index go from -N/2 to N/2?

+1 vote

This isn't supported, since the numbering of the operators is meant to match the possible inputs to the site set object.

Let's say you define a site set object as:

auto sites = SpinHalf(N);


Then sites(1) accesses the first index of the lattice, sites(2) the second, etc.

The AutoMPO class uses the site set to know how to construct the various operators defined for each site when making an MPO. So the numbering of the AutoMPO input needs to match that of the site set.

commented by (220 points)
Thanks for the answer. So now if I consider an impurity at N/2 (I wanted the impurity at origin so I wanted -N/2 to N/2, which is not applicable), I need to put the index for correlation functions of the type i= (N/2 - x)*scale, j= (N/2 - xp)*scale and so on. But when I do so I get the following error.

In the program  itensor/itensor/itensor_interface.ih

Wrong number of IndexVals passed to real/cplx (expected 4, got 0)

If I put i=x*scale and j=xp*scale, it works fine. Can you please tell me why this happens?
commented by (28.2k points)
I'm not sure exactly why you're getting that error based on the information you gave, but generally that error comes from a function or a piece of code that's supposed to result in a scalar. Some piece of code is calling the .real() method on a tensor to retrieve its value, assuming it is a scalar, but instead it is not a scalar due to mismatched indices.
commented by (220 points)
edited by
Thanks for the clarification. But I got it now. What happened was that for calculating the correlation functions, the indices i and j goes from 1 to N and i+1 to N respectively. Hence j > i always. When I did the shift (N/2-x, etc. )as told above, it was getting values such that i > j. But when I chose those values where i<j, it worked out fine.