FA-64076 / Medication dosing calculations / Open access
Pharmacokinetic loading and maintenance doses: existing level credit · case 01
Patients already partly loaded receive a full loading dose.
ROOT CAUSE
The loading dose uses the target concentration and ignores the current level.
THE FAILURE
The loading dose uses the target concentration and ignores the current level.
Unsuccessful approach: abs() turns a level above target into a positive loading dose.
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 + Fraction(1, 2)) * u)
load = max(Fraction(0), tgt * 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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': 1000.0, 'maintenance_mg': 950.0} | {'loading_mg': 700.0, 'maintenance_mg': 950.0} | Failed |
| level above target gives no load | {'loading_mg': 400.0, 'maintenance_mg': 650.0} | {'loading_mg': 0.0, 'maintenance_mg': 650.0} | Failed |
| 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 / e50c58be94247b73c345984a03355c5ad5c763f390a27c5a6e139a7cf0f25eb1
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(math.floor(v / u + Fraction(1, 2)) * u)
load = max(Fraction(0), abs(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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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': 150.0, 'maintenance_mg': 650.0} | {'loading_mg': 0.0, 'maintenance_mg': 650.0} | Failed |
| 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 / 7299f2c952f47a322d79edf8f1a9daeec7a0fa126dd0288baf29d3e2fb0517b0
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 6 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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 / da8ea47ab09b57477323684705db1c3b0a8e3045e08377becf2307c906da5afe