FA-64161 / Medication dosing calculations / Open access
Percentage taper schedule rounded to tablets: tablet multiple rounding · case 01
A reduction to 42.5 mg with 5 mg tablets is given as 40 mg.
ROOT CAUSE
The reduced dose is truncated to a tablet multiple instead of rounded half-up.
VERIFIED REPAIR
Round half-up to the nearest tablet multiple.
Unsuccessful approach: round() half-to-even still rounds 42.5 mg (8.5 tablets) down to 40 mg.
Case contract
Input {start_mg, step_pct, every_days, min_mg, tablet_mg, days}. Day 0 uses start_mg. On each day d > 0 with d % every_days == 0 (while the dose is non-zero), the dose becomes current*(100-step_pct)/100 rounded half-up to a tablet_mg multiple; if that does not lower the dose, it is lowered by one tablet_mg instead; a result below min_mg stops the taper (0). Return the list of daily doses for days days.
Why this case matters
Tapers compound percentage reductions with dispensing granularity; stepping day, rounding and stop rules are distinct decisions.
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):
dose = Fraction(str(x['start_mg']))
t = Fraction(str(x['tablet_mg']))
out = []
for day in range(x['days']):
if day > 0 and day % x['every_days'] == 0 and dose > 0:
new = dose * (100 - x['step_pct']) / 100
new = math.floor(new / t) * t
if new >= dose:
new = dose - t
dose = new if new >= Fraction(str(x['min_mg'])) else Fraction(0)
out.append(float(dose))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 11},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 4},
[50.0, 50.0, 45.0, 45.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 6},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 8},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 12},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[50.0, 50.0, 45.0, 45.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 7},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 9},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 13},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 6},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 8},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 10},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 14},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 7},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 9},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 11},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 15},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 8},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 10},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 12},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0, 6.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 |
|---|---|---|---|
| weekly 25 percent taper | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 30.0, 30.0, 30.0, 20.0, 20.0] | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0] | Failed |
| half-tablet boundary rounds up | [50.0, 50.0, 40.0, 40.0] | [50.0, 50.0, 45.0, 45.0] | Failed |
| rounding stall forces one tablet step | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | Passed |
| stops below minimum | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | Passed |
| dose equal to minimum continues | [40.0, 20.0, 10.0, 0.0, 0.0] | [40.0, 20.0, 10.0, 0.0, 0.0] | Passed |
| fractional tablet percentages | [30.0, 30.0, 21.0, 21.0, 14.0, 14.0, 9.0, 9.0] | [30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0] | Failed |
SHA-256 / 8559674067336522957e810a37faed1df5bcffa7744875594ef8f5c2103916fd
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):
dose = Fraction(str(x['start_mg']))
t = Fraction(str(x['tablet_mg']))
out = []
for day in range(x['days']):
if day > 0 and day % x['every_days'] == 0 and dose > 0:
new = dose * (100 - x['step_pct']) / 100
new = round(new / t) * t
if new >= dose:
new = dose - t
dose = new if new >= Fraction(str(x['min_mg'])) else Fraction(0)
out.append(float(dose))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 11},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 4},
[50.0, 50.0, 45.0, 45.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 6},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 8},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 12},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[50.0, 50.0, 45.0, 45.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 7},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 9},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 13},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 6},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 8},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 10},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 14},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 7},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 9},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 11},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 15},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 8},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 10},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 12},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0, 6.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 |
|---|---|---|---|
| weekly 25 percent taper | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0] | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0] | Passed |
| half-tablet boundary rounds up | [50.0, 50.0, 40.0, 40.0] | [50.0, 50.0, 45.0, 45.0] | Failed |
| rounding stall forces one tablet step | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | Passed |
| stops below minimum | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | Passed |
| dose equal to minimum continues | [40.0, 20.0, 10.0, 0.0, 0.0] | [40.0, 20.0, 10.0, 0.0, 0.0] | Passed |
| fractional tablet percentages | [30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 10.0, 10.0] | [30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0] | Failed |
SHA-256 / 09346a0d3349c800a78824367923d32a4462bc1b0e4c67a4b62bff4fbe28314b
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):
dose = Fraction(str(x['start_mg']))
t = Fraction(str(x['tablet_mg']))
out = []
for day in range(x['days']):
if day > 0 and day % x['every_days'] == 0 and dose > 0:
new = dose * (100 - x['step_pct']) / 100
new = math.floor(new / t + Fraction(1, 2)) * t
if new >= dose:
new = dose - t
dose = new if new >= Fraction(str(x['min_mg'])) else Fraction(0)
out.append(float(dose))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 11},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 4},
[50.0, 50.0, 45.0, 45.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 6},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 8},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 12},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[50.0, 50.0, 45.0, 45.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 7},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 9},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 13},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 6},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 8},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 10},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 14},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 7},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 1, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 7.5, 5.0, 2.5, 0.0, 0.0, 0.0, 0.0]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 9},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 5, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 5.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 11},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0])],
[('weekly 25 percent taper',
{'start_mg': 60, 'step_pct': 25, 'every_days': 3, 'min_mg': 5, 'tablet_mg': 5, 'days': 15},
[60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0, 25.0, 20.0, 20.0, 20.0]),
('half-tablet boundary rounds up',
{'start_mg': 50, 'step_pct': 15, 'every_days': 2, 'min_mg': 5, 'tablet_mg': 5, 'days': 8},
[50.0, 50.0, 45.0, 45.0, 40.0, 40.0, 35.0, 35.0]),
('rounding stall forces one tablet step',
{'start_mg': 10, 'step_pct': 10, 'every_days': 2, 'min_mg': '2.5', 'tablet_mg': '2.5', 'days': 8},
[10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5]),
('stops below minimum',
{'start_mg': 20, 'step_pct': 50, 'every_days': 2, 'min_mg': 10, 'tablet_mg': 5, 'days': 10},
[20.0, 20.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
('dose equal to minimum continues',
{'start_mg': 40, 'step_pct': 50, 'every_days': 1, 'min_mg': 10, 'tablet_mg': 5, 'days': 5},
[40.0, 20.0, 10.0, 0.0, 0.0]),
('fractional tablet percentages',
{'start_mg': 30, 'step_pct': 30, 'every_days': 2, 'min_mg': 1, 'tablet_mg': 1, 'days': 12},
[30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0, 8.0, 8.0, 6.0, 6.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 |
|---|---|---|---|
| weekly 25 percent taper | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0] | [60.0, 60.0, 60.0, 45.0, 45.0, 45.0, 35.0, 35.0, 35.0, 25.0, 25.0] | Passed |
| half-tablet boundary rounds up | [50.0, 50.0, 45.0, 45.0] | [50.0, 50.0, 45.0, 45.0] | Passed |
| rounding stall forces one tablet step | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | [10.0, 10.0, 7.5, 7.5, 5.0, 5.0, 2.5, 2.5] | Passed |
| stops below minimum | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | [20.0, 20.0, 10.0, 10.0, 0.0, 0.0] | Passed |
| dose equal to minimum continues | [40.0, 20.0, 10.0, 0.0, 0.0] | [40.0, 20.0, 10.0, 0.0, 0.0] | Passed |
| fractional tablet percentages | [30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0] | [30.0, 30.0, 21.0, 21.0, 15.0, 15.0, 11.0, 11.0] | Passed |
SHA-256 / 0255bd4022b2d660efaf1d803e7a2f28240979cf27268e4975ea59ee413fd554
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:21.841325+00:00.
Case digest / 408fa465767ee021b108e7f2b9c523bface34c9abbb8c9aff106ce9b4df45f66