- Initialize \( H(\alpha,\beta)=0.0 \)
- Set up an outer loop over \( \beta \)
- Loop over \( \alpha = 1, NSD \)
- For each \( \alpha \), loop over \( a=1,ntbme \) and fetch \( V(a) \) and the single-particle indices \( p,q,r,s \)
- 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 \).
- Find, if any, the label \( \beta \) of the resulting Slater determinant and the phase (which is 0, +1, -1).
- 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.
- Continue loop over \( a \)
- Continue loop over \( \alpha \).
- 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) \).