FAILURE MAP
← Case archive

FA-64096 / Medication dosing calculations / Open access

Pharmacokinetic loading and maintenance doses: dosing unit rounding · case 01

A 162.5 mg requirement with 25 mg units is given as 150 mg.

Verified by executionVariant 1 · 6 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Rounding to the unit strength truncates instead of rounding half-up.

VERIFIED REPAIR

Round half-up to the nearest unit multiple.

Unsuccessful approach: round() uses half-to-even and still rounds some half units down.

Case contract

Input {target, current, vd_l_kg, weight_kg, f, cl_ml_min, tau_h, unit_mg}. Toy one-compartment rule: loading = max(0, (target-current)*Vd*weight/F); maintenance = target*CL*tau/F with CL in L/h = cl_ml_min*60/1000. Both are rounded half-up to a multiple of unit_mg. Return {loading_mg, maintenance_mg}.

Why this case matters

Loading and maintenance calculations chain unit conversions and bioavailability; each factor is an independent defect site.

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):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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 fixtureActualExpectedOutcome
drug-naive loading{'loading_mg': 700.0, 'maintenance_mg': 1050.0}{'loading_mg': 750.0, 'maintenance_mg': 1100.0}Failed
partial existing level credited{'loading_mg': 700.0, 'maintenance_mg': 950.0}{'loading_mg': 700.0, 'maintenance_mg': 950.0}Passed
level above target gives no load{'loading_mg': 0.0, 'maintenance_mg': 600.0}{'loading_mg': 0.0, 'maintenance_mg': 650.0}Failed
oral bioavailability maintenance{'loading_mg': 240.0, 'maintenance_mg': 285.0}{'loading_mg': 240.0, 'maintenance_mg': 290.0}Failed
half unit rounds up{'loading_mg': 150.0, 'maintenance_mg': 25.0}{'loading_mg': 175.0, 'maintenance_mg': 50.0}Failed
slow clearance long interval{'loading_mg': 10.0, 'maintenance_mg': 14.0}{'loading_mg': 10.0, 'maintenance_mg': 14.0}Passed

SHA-256 / 33ec7b2ca922d2669b70109ef10d92c14b87a026687cce210029e6499a1996b6

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):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(round(v / u) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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 fixtureActualExpectedOutcome
drug-naive loading{'loading_mg': 750.0, 'maintenance_mg': 1100.0}{'loading_mg': 750.0, 'maintenance_mg': 1100.0}Passed
partial existing level credited{'loading_mg': 700.0, 'maintenance_mg': 950.0}{'loading_mg': 700.0, 'maintenance_mg': 950.0}Passed
level above target gives no load{'loading_mg': 0.0, 'maintenance_mg': 650.0}{'loading_mg': 0.0, 'maintenance_mg': 650.0}Passed
oral bioavailability maintenance{'loading_mg': 240.0, 'maintenance_mg': 290.0}{'loading_mg': 240.0, 'maintenance_mg': 290.0}Passed
half unit rounds up{'loading_mg': 150.0, 'maintenance_mg': 50.0}{'loading_mg': 175.0, 'maintenance_mg': 50.0}Failed
slow clearance long interval{'loading_mg': 10.0, 'maintenance_mg': 14.0}{'loading_mg': 10.0, 'maintenance_mg': 14.0}Passed

SHA-256 / 4090d8af96faa9a8e1a81f497dc0f341767f358b8164355114ce8fee326c4c0a

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):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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 fixtureActualExpectedOutcome
drug-naive loading{'loading_mg': 750.0, 'maintenance_mg': 1100.0}{'loading_mg': 750.0, 'maintenance_mg': 1100.0}Passed
partial existing level credited{'loading_mg': 700.0, 'maintenance_mg': 950.0}{'loading_mg': 700.0, 'maintenance_mg': 950.0}Passed
level above target gives no load{'loading_mg': 0.0, 'maintenance_mg': 650.0}{'loading_mg': 0.0, 'maintenance_mg': 650.0}Passed
oral bioavailability maintenance{'loading_mg': 240.0, 'maintenance_mg': 290.0}{'loading_mg': 240.0, 'maintenance_mg': 290.0}Passed
half unit rounds up{'loading_mg': 175.0, 'maintenance_mg': 50.0}{'loading_mg': 175.0, 'maintenance_mg': 50.0}Passed
slow clearance long interval{'loading_mg': 10.0, 'maintenance_mg': 14.0}{'loading_mg': 10.0, 'maintenance_mg': 14.0}Passed

SHA-256 / 4a5c087edd33bbaa8185795ebebbce007304e402cb18f237577b6034e6b14f75

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.158131+00:00.

Case digest / 9d287ccc5fd626089215314fcae7083a9228137addab550ef633640788e6cb6d