Building a Hamiltonian matrix

  1. Initialize \( H(\alpha,\beta)=0.0 \)
  2. Set up an outer loop over \( \beta \)
  3. Loop over \( \alpha = 1, NSD \)
  4. For each \( \alpha \), loop over \( a=1,ntbme \) and fetch \( V(a) \) and the single-particle indices \( p,q,r,s \)
  5. If \( V(a) = 0 \) skip. Otherwise, apply \( \hat{a}^\dagger_p\hat{a}^\dagger_q \hat{a}_s \hat{a}_r \) to the Slater determinant labeled by \( \alpha \).
  6. Find, if any, the label \( \beta \) of the resulting Slater determinant and the phase (which is 0, +1, -1).
  7. If phase \( \neq 0 \), then update \( H(\alpha,\beta) \) as \( H(\alpha,\beta) + phase*V(a) \). The sum is important because multiple operators might contribute to the same matrix element.
  8. Continue loop over \( a \)
  9. Continue loop over \( \alpha \).
  10. End the outer loop over \( \beta \).
You should force the resulting matrix \( H \) to be symmetric. To do this, when updating \( H(\alpha,\beta) \), if \( \alpha \neq \beta \), also update \( H(\beta,\alpha) \).