This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/two-integral-families

Two methods compute water's 6-31G integrals

McMurchie-Davidson and Head-Gordon-Pople compute the same 4186 electron repulsion integrals for water in the 6-31G basis by different recurrences. They agree to rounding, each matches PySCF, and each one alone gives PySCF's Hartree-Fock energy. With a third implementation in the comparison, the cross-check names the implementation that disagrees and the integral where it does.

The electron repulsion integrals are most of the cost of a Hartree-Fock calculation and the easiest place for a bug that does not announce itself. lib/hf computes them more than one way and compares the answers. This post takes the two methods the library cross-checks by default and runs each one alone on water in 6-31G: 13 basis functions and 4186 integrals after the eightfold permutation symmetry.

McMurchie-Davidson writes each product of two Gaussians as a sum of Hermite Gaussians. The integral becomes two matrix products over those expansions and the Hermite Coulomb integrals at the distance between the two product centers.

Head-Gordon-Pople starts from Obara and Saika's vertical recurrence, which builds up the angular momentum on one center of each pair, primitive by primitive. A horizontal recurrence then moves it onto the other center once per contracted shell quartet.

They share no recurrence. Both take the Boys function from lib/hf/boys, which is checked on its own against mpmath values (tools/boys_reference.py).

About 60 percent of the integrals come out as the same double from both methods, bit for bit: 2483 of the 4186. The exact count depends on the last bit of exp, so a different math library would change it. Every Viv engine, native or in the browser, uses the same one, so the count is the same in all of them, and a test checks it. The figure sorts the integrals that differ by how far apart they are, measured as , the measure the library's cross-check uses. None is as far as . For the integrals larger than 0.01 the gap is at most 5.75 times the double-precision epsilon relative to the integral itself. The screened McMurchie-Davidson code skips any shell quartet whose Schwarz bound is under , so a few integrals no larger than are exactly zero in its set.

Each method is also checked against PySCF's stored integrals within , and each one alone, fed to the self-consistent field with the default implementation of every other step, gives PySCF's energy within .

Finding which implementation is wrong. The cross-check takes the median of the implementations' answers, entry by entry, and blames the implementation farthest from it, at a named integral. For an even count the program takes the upper of the two middle values as the median. With two implementations that is the larger value, so a disagreement is detected but the blame falls on whichever one gave the lower value. With three, the median is a correct value. The last part of the program adds a third implementation that returns the Head-Gordon-Pople integrals with integral 2000, which is , multiplied by . That makes it larger, so with only two implementations the median is the wrong value and the correct one takes the blame. With three, the check names the altered implementation and integral 2000.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 61–239