FA-64286 / Medication dosing calculations / Open access
INR-guided weekly dose adjustment and daily plan: weekly total rounding · case 01
A 22.75 mg weekly requirement rounds down to 22.5 mg.
ROOT CAUSE
The half-milligram rounding truncates.
VERIFIED REPAIR
Round the weekly total half-up to 0.5 mg.
Unsuccessful approach: round() half-to-even still rounds some quarter values down.
Case contract
Input {inr, weekly_mg, low, high}. Toy table: inr >= 5 HOLD and weekly x0.85; high < inr < 5 x0.90; low <= inr <= high CONTINUE unchanged; low-0.5 <= inr < low x1.05; lower x1.10 (ADJUST otherwise). New weekly total rounds half-up to 0.5 mg; the plan spreads it over 7 days in 0.5 mg units as evenly as possible with the larger doses on the first days. Return {action, weekly_mg, plan}.
Why this case matters
Weekly anticoagulant adjustment combines threshold bands with a dispensing plan; band edges and the distribution rule are independent defects.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
inr = Fraction(str(x['inr']))
lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
w = Fraction(str(x['weekly_mg']))
action = 'ADJUST'
if inr >= 5:
action, w = 'HOLD', w * Fraction(85, 100)
elif inr > hi:
w = w * Fraction(90, 100)
elif inr >= lo:
action = 'CONTINUE'
elif inr >= lo - Fraction(1, 2):
w = w * Fraction(105, 100)
else:
w = w * Fraction(110, 100)
units = math.floor(w * 2)
base, extra = divmod(units, 7)
plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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 |
|---|---|---|---|
| INR exactly 5 holds | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 3.5, 3.5, 3.5, 3.5], 'weekly_mg': 26.0} | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Failed |
| high target range above 3 | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.5} | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0], 'weekly_mg': 30.0} | Failed |
| INR at upper target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | Passed |
| INR at lower target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | Passed |
| INR exactly half below target | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | Passed |
| INR well below target | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | Passed |
| weekly rounding half-up | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 3.5, 3.5, 3.5, 3.5], 'weekly_mg': 26.0} | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Failed |
| uneven weekly split | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | Passed |
SHA-256 / 818c641d19ce799ac9df831fd2bda2ab98da350b655b14d4f126ee6743471f0c
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
inr = Fraction(str(x['inr']))
lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
w = Fraction(str(x['weekly_mg']))
action = 'ADJUST'
if inr >= 5:
action, w = 'HOLD', w * Fraction(85, 100)
elif inr > hi:
w = w * Fraction(90, 100)
elif inr >= lo:
action = 'CONTINUE'
elif inr >= lo - Fraction(1, 2):
w = w * Fraction(105, 100)
else:
w = w * Fraction(110, 100)
units = round(w * 2)
base, extra = divmod(units, 7)
plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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 |
|---|---|---|---|
| INR exactly 5 holds | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Passed |
| high target range above 3 | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0], 'weekly_mg': 30.0} | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0], 'weekly_mg': 30.0} | Passed |
| INR at upper target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | Passed |
| INR at lower target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | Passed |
| INR exactly half below target | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | Passed |
| INR well below target | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | Passed |
| weekly rounding half-up | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 3.5, 3.5, 3.5, 3.5], 'weekly_mg': 26.0} | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Failed |
| uneven weekly split | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | Passed |
SHA-256 / 664074fd30f6916811d81db4823c601f345a51833a0075686b53803eede96de7
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
inr = Fraction(str(x['inr']))
lo, hi = Fraction(str(x['low'])), Fraction(str(x['high']))
w = Fraction(str(x['weekly_mg']))
action = 'ADJUST'
if inr >= 5:
action, w = 'HOLD', w * Fraction(85, 100)
elif inr > hi:
w = w * Fraction(90, 100)
elif inr >= lo:
action = 'CONTINUE'
elif inr >= lo - Fraction(1, 2):
w = w * Fraction(105, 100)
else:
w = w * Fraction(110, 100)
units = math.floor(w * 2 + Fraction(1, 2))
base, extra = divmod(units, 7)
plan = [(base + 1) / 2] * extra + [base / 2] * (7 - extra)
return {'action': action, 'weekly_mg': units / 2, 'plan': plan}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 29, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 31, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 22, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 23.0, 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 28.5, 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 25, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 26.5, 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '32.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.5, 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 27.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 3.5, 3.5]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 30, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 32, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 24, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 25.0, 'plan': [4.0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 27, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 45, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 47.5, 'plan': [7.0, 7.0, 7.0, 7.0, 6.5, 6.5, 6.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '27.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 28.0, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 31, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 33, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 26, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 27.5, 'plan': [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 65, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 68.5, 'plan': [10.0, 10.0, 10.0, 10.0, 9.5, 9.5, 9.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '31', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 31.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 29.0, 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 32, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 34, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 34.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 4.5, 4.5]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 28, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 29.5, 'plan': [4.5, 4.5, 4.5, 4.0, 4.0, 4.0, 4.0]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 29, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 32.0, 'plan': [5.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 85, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 89.5, 'plan': [13.0, 13.0, 13.0, 13.0, 12.5, 12.5, 12.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '22.5', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 22.5, 'plan': [3.5, 3.5, 3.5, 3.0, 3.0, 3.0, 3.0]})],
[('INR exactly 5 holds',
{'inr': '5.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('high target range above 3',
{'inr': '5.2', 'weekly_mg': 35, 'low': '2.5', 'high': '3.5'},
{'action': 'HOLD', 'weekly_mg': 30.0, 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0]}),
('INR at upper target continues',
{'inr': '3.5', 'weekly_mg': 33, 'low': '2.5', 'high': '3.5'},
{'action': 'CONTINUE', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('INR at lower target continues',
{'inr': '2.0', 'weekly_mg': 35, 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 35.0, 'plan': [5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0]}),
('INR exactly half below target',
{'inr': '1.5', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 31.5, 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]}),
('INR well below target',
{'inr': '1.2', 'weekly_mg': 30, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 33.0, 'plan': [5.0, 5.0, 5.0, 4.5, 4.5, 4.5, 4.5]}),
('weekly rounding half-up',
{'inr': '1.8', 'weekly_mg': 105, 'low': 2, 'high': 3},
{'action': 'ADJUST', 'weekly_mg': 110.5, 'plan': [16.0, 16.0, 16.0, 16.0, 15.5, 15.5, 15.5]}),
('uneven weekly split',
{'inr': '2.5', 'weekly_mg': '38', 'low': 2, 'high': 3},
{'action': 'CONTINUE', 'weekly_mg': 38.0, 'plan': [5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.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 |
|---|---|---|---|
| INR exactly 5 holds | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | {'action': 'HOLD', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Passed |
| high target range above 3 | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0], 'weekly_mg': 30.0} | {'action': 'HOLD', 'plan': [4.5, 4.5, 4.5, 4.5, 4.0, 4.0, 4.0], 'weekly_mg': 30.0} | Passed |
| INR at upper target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 29.0} | Passed |
| INR at lower target continues | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | {'action': 'CONTINUE', 'plan': [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.0], 'weekly_mg': 31.0} | Passed |
| INR exactly half below target | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | {'action': 'ADJUST', 'plan': [3.5, 3.5, 3.5, 3.5, 3.0, 3.0, 3.0], 'weekly_mg': 23.0} | Passed |
| INR well below target | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | {'action': 'ADJUST', 'plan': [4.5, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], 'weekly_mg': 28.5} | Passed |
| weekly rounding half-up | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | {'action': 'ADJUST', 'plan': [4.0, 4.0, 4.0, 4.0, 3.5, 3.5, 3.5], 'weekly_mg': 26.5} | Passed |
| uneven weekly split | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | {'action': 'CONTINUE', 'plan': [5.0, 5.0, 4.5, 4.5, 4.5, 4.5, 4.5], 'weekly_mg': 32.5} | Passed |
SHA-256 / 7b53215b83f2fd582e76cd4b1019cef1a37ebde067950d817be1da8bd4fabd2a
Verification & scope
A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. 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:23.013003+00:00.
Case digest / ac3be39c54b95df0620c4ea2b0f551caae2f00a70425a701ea832b3a17ef649f