FA-97266 / Recipe scaling and nutrition / Open access
Macronutrient target splitter: split validation · case 01
A 30/40/31 split is accepted and silently renormalized.
ROOT CAUSE
Only splits above 100% are rejected, so splits summing under 100 pass.
VERIFIED REPAIR
Reject any split not summing to exactly 100.
Unsuccessful approach: A one-point tolerance still accepts a 101% split.
Case contract
split = [protein%, carb%, fat%] must sum to 100 else "error: split". protein_g = max(half-up kcal*p/400, ceiling(1.6*weight_kg)). Remaining kcal = kcal - 4*protein_g is divided between carb and fat in the ratio c:f; fat_g = half-up(rem*f/(c+f)/9); carb_g = half-up((rem - 9*fat_g)/4). Return [protein_g, carb_g, fat_g].
Why this case matters
Meal-plan generators turn calorie targets into gram targets with a protein floor by body weight.
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(kcal, weight_kg, split):
p, c, f = split
if p + c + f > 100:
return 'error: split'
def r(x):
return math.floor(x + Fraction(1, 2))
protein_g = max(r(Fraction(kcal * p, 400)), math.ceil(Fraction(16, 10) * weight_kg))
rem = kcal - 4 * protein_g
fat_g = r(Fraction(rem * f, c + f) / 9)
carb_g = r(Fraction(rem - 9 * fat_g, 4))
return [protein_g, carb_g, fat_g]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['regression: split validation', [3000, 100, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 91, [30, 40, 31]], 'error: split'],
['generated control 1', [2500, 72, [20, 50, 30]], [125, 313, 83]],
['generated control 2', [2000, 120, [15, 55, 30]], [192, 200, 48]],
['generated control 3', [3000, 100, [15, 55, 30]], [160, 381, 93]]],
[['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['regression: split validation', [1800, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [2500, 60, [30, 40, 29]], 'error: split'],
['generated control 1', [2200, 60, [30, 40, 30]], [165, 221, 73]],
['generated control 2', [1800, 118, [15, 55, 30]], [189, 169, 41]],
['generated control 3', [2000, 120, [25, 45, 30]], [192, 184, 55]]],
[['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['regression: split validation', [3000, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [1500, 91, [30, 40, 29]], 'error: split'],
['generated control 1', [1500, 72, [30, 40, 30]], [116, 149, 49]],
['generated control 2', [2000, 72, [15, 55, 30]], [116, 249, 60]],
['generated control 3', [1500, 50, [20, 50, 30]], [80, 185, 49]]],
[['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['regression: split validation', [1500, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 72, [30, 40, 29]], 'error: split'],
['generated control 1', [2000, 60, [30, 40, 30]], [150, 199, 67]],
['generated control 2', [1800, 83, [20, 50, 30]], [133, 198, 53]],
['generated control 3', [2500, 50, [30, 40, 30]], [188, 250, 83]]],
[['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['regression: split validation', [2000, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [2000, 60, [30, 40, 31]], 'error: split'],
['generated control 1', [3000, 118, [25, 45, 30]], [189, 336, 100]],
['generated control 2', [2200, 72, [30, 40, 29]], 'error: split'],
['generated control 3', [2500, 50, [30, 40, 31]], 'error: split']]]
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 |
|---|---|---|---|
| balanced | [150, 199, 67] | [150, 199, 67] | Passed |
| protein floor binds | [192, 118, 29] | [192, 118, 29] | Passed |
| bad split | error: split | error: split | Passed |
| regression: split validation | [225, 305, 98] | error: split | Failed |
| repair check: split validation | error: split | error: split | Passed |
| generated control 1 | [125, 313, 83] | [125, 313, 83] | Passed |
| generated control 2 | [192, 200, 48] | [192, 200, 48] | Passed |
| generated control 3 | [160, 381, 93] | [160, 381, 93] | Passed |
SHA-256 / b2ea3b9ed8a5b6c62600ccdfbce02799ea4079bec93f23b8ea7e9c8979f8a0f3
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(kcal, weight_kg, split):
p, c, f = split
if abs(p + c + f - 100) > 1:
return 'error: split'
def r(x):
return math.floor(x + Fraction(1, 2))
protein_g = max(r(Fraction(kcal * p, 400)), math.ceil(Fraction(16, 10) * weight_kg))
rem = kcal - 4 * protein_g
fat_g = r(Fraction(rem * f, c + f) / 9)
carb_g = r(Fraction(rem - 9 * fat_g, 4))
return [protein_g, carb_g, fat_g]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['regression: split validation', [3000, 100, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 91, [30, 40, 31]], 'error: split'],
['generated control 1', [2500, 72, [20, 50, 30]], [125, 313, 83]],
['generated control 2', [2000, 120, [15, 55, 30]], [192, 200, 48]],
['generated control 3', [3000, 100, [15, 55, 30]], [160, 381, 93]]],
[['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['regression: split validation', [1800, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [2500, 60, [30, 40, 29]], 'error: split'],
['generated control 1', [2200, 60, [30, 40, 30]], [165, 221, 73]],
['generated control 2', [1800, 118, [15, 55, 30]], [189, 169, 41]],
['generated control 3', [2000, 120, [25, 45, 30]], [192, 184, 55]]],
[['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['regression: split validation', [3000, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [1500, 91, [30, 40, 29]], 'error: split'],
['generated control 1', [1500, 72, [30, 40, 30]], [116, 149, 49]],
['generated control 2', [2000, 72, [15, 55, 30]], [116, 249, 60]],
['generated control 3', [1500, 50, [20, 50, 30]], [80, 185, 49]]],
[['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['regression: split validation', [1500, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 72, [30, 40, 29]], 'error: split'],
['generated control 1', [2000, 60, [30, 40, 30]], [150, 199, 67]],
['generated control 2', [1800, 83, [20, 50, 30]], [133, 198, 53]],
['generated control 3', [2500, 50, [30, 40, 30]], [188, 250, 83]]],
[['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['regression: split validation', [2000, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [2000, 60, [30, 40, 31]], 'error: split'],
['generated control 1', [3000, 118, [25, 45, 30]], [189, 336, 100]],
['generated control 2', [2200, 72, [30, 40, 29]], 'error: split'],
['generated control 3', [2500, 50, [30, 40, 31]], 'error: split']]]
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 |
|---|---|---|---|
| balanced | [150, 199, 67] | [150, 199, 67] | Passed |
| protein floor binds | [192, 118, 29] | [192, 118, 29] | Passed |
| bad split | [150, 197, 68] | error: split | Failed |
| regression: split validation | [225, 305, 98] | error: split | Failed |
| repair check: split validation | [225, 296, 102] | error: split | Failed |
| generated control 1 | [125, 313, 83] | [125, 313, 83] | Passed |
| generated control 2 | [192, 200, 48] | [192, 200, 48] | Passed |
| generated control 3 | [160, 381, 93] | [160, 381, 93] | Passed |
SHA-256 / d4def7757f69bfa5f29741871a65e031d847abc09c8644fd572b49d78b5b184a
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(kcal, weight_kg, split):
p, c, f = split
if p + c + f != 100:
return 'error: split'
def r(x):
return math.floor(x + Fraction(1, 2))
protein_g = max(r(Fraction(kcal * p, 400)), math.ceil(Fraction(16, 10) * weight_kg))
rem = kcal - 4 * protein_g
fat_g = r(Fraction(rem * f, c + f) / 9)
carb_g = r(Fraction(rem - 9 * fat_g, 4))
return [protein_g, carb_g, fat_g]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['regression: split validation', [3000, 100, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 91, [30, 40, 31]], 'error: split'],
['generated control 1', [2500, 72, [20, 50, 30]], [125, 313, 83]],
['generated control 2', [2000, 120, [15, 55, 30]], [192, 200, 48]],
['generated control 3', [3000, 100, [15, 55, 30]], [160, 381, 93]]],
[['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['regression: split validation', [1800, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [2500, 60, [30, 40, 29]], 'error: split'],
['generated control 1', [2200, 60, [30, 40, 30]], [165, 221, 73]],
['generated control 2', [1800, 118, [15, 55, 30]], [189, 169, 41]],
['generated control 3', [2000, 120, [25, 45, 30]], [192, 184, 55]]],
[['bad split', [2000, 70, [30, 40, 31]], 'error: split'],
['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['regression: split validation', [3000, 50, [20, 50, 25]], 'error: split'],
['repair check: split validation', [1500, 91, [30, 40, 29]], 'error: split'],
['generated control 1', [1500, 72, [30, 40, 30]], [116, 149, 49]],
['generated control 2', [2000, 72, [15, 55, 30]], [116, 249, 60]],
['generated control 3', [1500, 50, [20, 50, 30]], [80, 185, 49]]],
[['split under 100', [2000, 70, [30, 40, 20]], 'error: split'],
['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['regression: split validation', [1500, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [3000, 72, [30, 40, 29]], 'error: split'],
['generated control 1', [2000, 60, [30, 40, 30]], [150, 199, 67]],
['generated control 2', [1800, 83, [20, 50, 30]], [133, 198, 53]],
['generated control 3', [2500, 50, [30, 40, 30]], [188, 250, 83]]],
[['fractional floor', [1200, 83, [20, 50, 30]], [133, 104, 28]],
['balanced', [2000, 70, [30, 40, 30]], [150, 199, 67]],
['protein floor binds', [1500, 120, [15, 55, 30]], [192, 118, 29]],
['regression: split validation', [2000, 72, [30, 40, 29]], 'error: split'],
['repair check: split validation', [2000, 60, [30, 40, 31]], 'error: split'],
['generated control 1', [3000, 118, [25, 45, 30]], [189, 336, 100]],
['generated control 2', [2200, 72, [30, 40, 29]], 'error: split'],
['generated control 3', [2500, 50, [30, 40, 31]], 'error: split']]]
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 |
|---|---|---|---|
| balanced | [150, 199, 67] | [150, 199, 67] | Passed |
| protein floor binds | [192, 118, 29] | [192, 118, 29] | Passed |
| bad split | error: split | error: split | Passed |
| regression: split validation | error: split | error: split | Passed |
| repair check: split validation | error: split | error: split | Passed |
| generated control 1 | [125, 313, 83] | [125, 313, 83] | Passed |
| generated control 2 | [192, 200, 48] | [192, 200, 48] | Passed |
| generated control 3 | [160, 381, 93] | [160, 381, 93] | Passed |
SHA-256 / eda74b5ed7d9de162b91e73d6caced73c2c7ee02a6d53ea78eb9df487e8707da
Verification & scope
A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. 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:52:30.485930+00:00.
Case digest / 14fae6529746b5f758cce59efacb8d539d0baa9083b97f42b378d88ad5daad75