FA-65051 / Epidemic compartment models / Open access
Final epidemic size by bisection: case count rounding · case 01
Expected case counts are one lower than the nearest integer.
ROOT CAUSE
The expected count is truncated rather than rounded.
VERIFIED REPAIR
Restore the case count rounding rule: `round(z * pop)`.
Unsuccessful approach: Ceiling rounds every fractional count upward.
Case contract
Attack fraction z is the positive root of z = 1-exp(-R0*z) found by bisection on (1e-9, 1] until the bracket is narrower than tol; for R0<=1 return [0.0, 0, 0.0]; return [z rounded 6, round(z*pop), overshoot z-(1-1/R0) rounded 6].
Why this case matters
Compartmental epidemic calculations drive outbreak forecasts, vaccine targets and hospital planning; a single wrong flow, rate conversion or boundary silently changes every downstream number.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(r0, pop, tol):
if r0 <= 1:
return [0.0, 0, 0.0]
lo, hi = 1e-9, 1.0
for _ in range(200):
mid = (lo + hi) / 2
if mid - (1 - math.exp(-r0 * mid)) < 0:
lo = mid
else:
hi = mid
if hi - lo < tol:
break
z = (lo + hi) / 2
return [round(z, 6), int(z * pop), round(z - (1 - 1 / r0), 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: flu-like R0 1.5 | [0.582812, 5828, 0.249478] | [0.582812, 5828, 0.249478] | Passed |
| regression: measles-like R0 12 | [0.999994, 999, 0.083327] | [0.999994, 1000, 0.083327] | Failed |
| regression: R0 2 | [0.796812, 3984, 0.296812] | [0.796812, 3984, 0.296812] | Passed |
| control: boundary R0 exactly 1 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| control: subcritical 0.8 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| regression: coarse tolerance | [0.89267, 892, 0.29267] | [0.89267, 893, 0.29267] | Failed |
| control: subcritical 0.5 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
SHA-256 / 07b880b2364251d1ad3c8db3cc1211c82b84fa0167be28931eeb4b2c41fe6748
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(r0, pop, tol):
if r0 <= 1:
return [0.0, 0, 0.0]
lo, hi = 1e-9, 1.0
for _ in range(200):
mid = (lo + hi) / 2
if mid - (1 - math.exp(-r0 * mid)) < 0:
lo = mid
else:
hi = mid
if hi - lo < tol:
break
z = (lo + hi) / 2
return [round(z, 6), math.ceil(z * pop), round(z - (1 - 1 / r0), 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: flu-like R0 1.5 | [0.582812, 5829, 0.249478] | [0.582812, 5828, 0.249478] | Failed |
| regression: measles-like R0 12 | [0.999994, 1000, 0.083327] | [0.999994, 1000, 0.083327] | Passed |
| regression: R0 2 | [0.796812, 3985, 0.296812] | [0.796812, 3984, 0.296812] | Failed |
| control: boundary R0 exactly 1 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| control: subcritical 0.8 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| regression: coarse tolerance | [0.89267, 893, 0.29267] | [0.89267, 893, 0.29267] | Passed |
| control: subcritical 0.5 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
SHA-256 / 5bfa87e29adc85985bc07180cb425d2cfacf7e5948453bd3565b42df033b2c51
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(r0, pop, tol):
if r0 <= 1:
return [0.0, 0, 0.0]
lo, hi = 1e-9, 1.0
for _ in range(200):
mid = (lo + hi) / 2
if mid - (1 - math.exp(-r0 * mid)) < 0:
lo = mid
else:
hi = mid
if hi - lo < tol:
break
z = (lo + hi) / 2
return [round(z, 6), round(z * pop), round(z - (1 - 1 / r0), 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('regression: R0 1.2 mid city', (1.2, 250000, 1e-10), [0.313698, 78425, 0.147032]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: flu-like R0 1.5', (1.5, 10000, 1e-12), [0.582812, 5828, 0.249478]),
('regression: measles-like R0 12', (12.0, 1000, 1e-12), [0.999994, 1000, 0.083327]),
('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])],
[('regression: R0 2', (2.0, 5000, 1e-12), [0.796812, 3984, 0.296812]),
('regression: near threshold 1.05', (1.05, 100000, 1e-12), [0.093702, 9370, 0.046083]),
('control: boundary R0 exactly 1', (1.0, 1000, 1e-12), [0.0, 0, 0.0]),
('control: subcritical 0.8', (0.8, 1000, 1e-12), [0.0, 0, 0.0]),
('regression: coarse tolerance', (2.5, 1000, 0.0001), [0.89267, 893, 0.29267]),
('regression: R0 3 small town', (3.0, 777, 1e-12), [0.94048, 731, 0.273813]),
('control: subcritical 0.5', (0.5, 100, 1e-12), [0.0, 0, 0.0])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: flu-like R0 1.5 | [0.582812, 5828, 0.249478] | [0.582812, 5828, 0.249478] | Passed |
| regression: measles-like R0 12 | [0.999994, 1000, 0.083327] | [0.999994, 1000, 0.083327] | Passed |
| regression: R0 2 | [0.796812, 3984, 0.296812] | [0.796812, 3984, 0.296812] | Passed |
| control: boundary R0 exactly 1 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| control: subcritical 0.8 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
| regression: coarse tolerance | [0.89267, 893, 0.29267] | [0.89267, 893, 0.29267] | Passed |
| control: subcritical 0.5 | [0.0, 0, 0.0] | [0.0, 0, 0.0] | Passed |
SHA-256 / 1c5cc59c3b415f3b80ecb14c8008771a873717b5b8e8df546badf0253691b4af
Verification & scope
Deterministic bounded teaching model with a stipulated contract; not a validated scientific or public-health modelling library. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:30.223599+00:00.
Case digest / c37ff0151e5c8d1d9220fb288937a838ef0c5c328b03fe824b28d96662fff6a7