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
27 lines
593 B
Plaintext
27 lines
593 B
Plaintext
function Sum(x: seq<real>): real
|
|
{
|
|
if |x| == 0 then 0.0 else Sum(x[..|x| - 1]) + x[|x| - 1]
|
|
}
|
|
|
|
// In exact arithmetic Kahan summation is the plain sum, and its compensation is always 0.
|
|
method KahanSum(x: seq<real>) returns (total: real)
|
|
ensures total == Sum(x)
|
|
{
|
|
total := 0.0;
|
|
var c := 0.0;
|
|
var i := 0;
|
|
while i < |x|
|
|
invariant 0 <= i <= |x|
|
|
invariant total == Sum(x[..i])
|
|
invariant c == 0.0
|
|
{
|
|
assert x[..i + 1][..i] == x[..i];
|
|
var y := x[i] - c;
|
|
var t := total + y;
|
|
c := (t - total) - y;
|
|
total := t;
|
|
i := i + 1;
|
|
}
|
|
assert x[..|x|] == x;
|
|
}
|