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
58 lines
1.5 KiB
JSON
58 lines
1.5 KiB
JSON
{
|
|
"name": "KahanSum",
|
|
"summary": "The sum of a list of FLOAT values by compensated summation, whose error does not grow with the length of the list.",
|
|
"tags": [
|
|
"summation",
|
|
"rounding",
|
|
"precision"
|
|
],
|
|
"sources": [
|
|
{
|
|
"title": "Kahan, Further remarks on reducing truncation errors, CACM 8(1), 1965",
|
|
"url": "https://doi.org/10.1145/363707.363723"
|
|
},
|
|
{
|
|
"title": "Higham, Accuracy and Stability of Numerical Algorithms, section 4.3"
|
|
}
|
|
],
|
|
"cases": [
|
|
{
|
|
"call": "KahanSum([1.0, 2.0, 3.0])"
|
|
},
|
|
{
|
|
"call": "KahanSum([1.0, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16])"
|
|
},
|
|
{
|
|
"call": "KahanSum([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])"
|
|
},
|
|
{
|
|
"call": "KahanSum([])"
|
|
}
|
|
],
|
|
"references": [
|
|
{
|
|
"lang": "python",
|
|
"level": "plain",
|
|
"file": "ref/python/plain.py",
|
|
"note": "The same compensated loop."
|
|
},
|
|
{
|
|
"lang": "c",
|
|
"level": "plain",
|
|
"file": "ref/c/plain.c",
|
|
"note": "The same loop in C. It survives -O2; it would not survive -ffast-math, which lets the compiler treat (t - total) - y as 0."
|
|
},
|
|
{
|
|
"lang": "mojo",
|
|
"level": "plain",
|
|
"file": "ref/mojo/plain.mojo",
|
|
"note": "The same loop in Mojo."
|
|
}
|
|
],
|
|
"proof": {
|
|
"lang": "dafny",
|
|
"file": "proof/kahan_sum.dfy",
|
|
"note": "Over real numbers the compensation C stays 0 and the result is exactly the sum: what Kahan summation corrects is rounding, and nothing else."
|
|
}
|
|
}
|