Files
pplus-library/modules/md/lennard-jones/proof/lennard_jones.dfy
T
alexmandClaude df12b2a008 Start pplus-library: 16 verified routines in six modules
Routines written once in pseudo and checked at every level, so programs
can use them by name instead of rewriting and re-verifying them:

- stats: Mean, Variance (two-pass)
- numerics: KahanSum, LinearInterp, Trapezoid
- align: LinearGapPenalty, AffineGapPenalty, MatchScore,
  NeedlemanWunschScore
- md: LennardJones, LennardJonesForce, MinimumImage, PairDistance
- seq: GCContent, HammingDistance
- special: ErfApprox (Abramowitz and Stegun 7.1.26)

Each has contracts, cases, reference implementations in Python, Mojo
and (for the numerical ones) C at more than one level, and nine have a
Dafny proof over exact numbers. status.json and STATUS.md are written by
pplus-core's library-check: every check passes or is open/unverified as
listed there. The Mojo references still need the pinned compiler's
answers (library-verify-mojo, network).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
2026-10-05 11:58:22 +00:00

60 lines
1.1 KiB
Plaintext

function Pow(x: real, n: nat): real
{
if n == 0 then 1.0 else x * Pow(x, n - 1)
}
function LJ(r: real, epsilon: real, sigma: real): real
requires r > 0.0
{
4.0 * epsilon * (Pow(sigma / r, 12) - Pow(sigma / r, 6))
}
lemma PowAdd(x: real, a: nat, b: nat)
ensures Pow(x, a + b) == Pow(x, a) * Pow(x, b)
{
if a > 0 {
PowAdd(x, a - 1, b);
assert Pow(x, a + b) == x * Pow(x, a - 1 + b);
}
}
lemma Pow2(x: real)
ensures Pow(x, 2) == x * x
{
assert Pow(x, 1) == x;
}
lemma Pow6(s: real)
ensures Pow(s, 6) == (s * s) * (s * s) * (s * s)
{
Pow2(s);
PowAdd(s, 2, 2);
PowAdd(s, 4, 2);
}
lemma Pow12(s: real)
ensures Pow(s, 12) == Pow(s, 6) * Pow(s, 6)
{
PowAdd(s, 6, 6);
}
method LennardJones(r: real, epsilon: real, sigma: real) returns (v: real)
requires r > 0.0
ensures v == LJ(r, epsilon, sigma)
{
var s := sigma / r;
var s2 := s * s;
var s6 := s2 * s2 * s2;
Pow6(s);
Pow12(s);
v := 4.0 * epsilon * (s6 * s6 - s6);
}
// The potential crosses zero at R = Sigma.
lemma ZeroAtSigma(epsilon: real, sigma: real)
requires sigma > 0.0
ensures LJ(sigma, epsilon, sigma) == 0.0
{
assert sigma / sigma == 1.0;
}