FAILURE MAP
← Case archive

FA-97276 / Recipe scaling and nutrition / Open access

Macronutrient target splitter: remaining energy · case 01

When the protein floor binds, total energy exceeds the target.

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

ROOT CAUSE

Remaining energy subtracts the nominal protein share, not the actual protein grams.

THE FAILURE

Remaining energy subtracts the nominal protein share, not the actual protein grams.

Unsuccessful approach: Using 9 kcal per gram of protein removes too much energy.

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 - Fraction(kcal * p, 100)
    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: remaining energy', [2200, 72, [10, 60, 30]], [116, 290, 64]],
  ['repair check: remaining energy', [2000, 72, [40, 30, 30]], [200, 149, 67]],
  ['generated control 1', [1800, 118, [40, 30, 30]], [189, 131, 58]],
  ['generated control 2', [2200, 60, [40, 30, 30]], [220, 166, 73]],
  ['generated control 3', [2200, 83, [20, 50, 30]], [133, 260, 70]]],
 [['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: remaining energy', [2000, 91, [15, 55, 30]], [146, 228, 56]],
  ['repair check: remaining energy', [3000, 91, [40, 30, 30]], [300, 225, 100]],
  ['generated control 1', [1500, 72, [20, 50, 25]], 'error: split'],
  ['generated control 2', [2000, 60, [10, 60, 30]], [96, 269, 60]],
  ['generated control 3', [2200, 100, [30, 40, 30]], [165, 221, 73]]],
 [['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: remaining energy', [1800, 91, [10, 60, 30]], [146, 203, 45]],
  ['repair check: remaining energy', [1800, 60, [15, 55, 30]], [96, 228, 56]],
  ['generated control 1', [2500, 83, [15, 55, 30]], [133, 319, 77]],
  ['generated control 2', [2200, 50, [15, 55, 30]], [83, 303, 73]],
  ['generated control 3', [1500, 91, [40, 30, 30]], [150, 113, 50]]],
 [['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: remaining energy', [1500, 118, [20, 50, 30]], [189, 116, 31]],
  ['repair check: remaining energy', [1800, 50, [40, 30, 30]], [180, 135, 60]],
  ['generated control 1', [2000, 72, [30, 40, 29]], 'error: split'],
  ['generated control 2', [2500, 83, [30, 40, 30]], [188, 250, 83]],
  ['generated control 3', [2500, 100, [10, 60, 30]], [160, 310, 69]]],
 [['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: remaining energy', [2500, 118, [30, 40, 30]], [189, 249, 83]],
  ['repair check: remaining energy', [1800, 72, [10, 60, 30]], [116, 224, 49]],
  ['generated control 1', [2200, 91, [20, 50, 30]], [146, 253, 67]],
  ['generated control 2', [1500, 60, [30, 40, 31]], 'error: split'],
  ['generated control 3', [1500, 91, [30, 40, 29]], '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 fixtureActualExpectedOutcome
balanced[150, 199, 67][150, 199, 67]Passed
protein floor binds[192, 206, 50][192, 118, 29]Failed
bad spliterror: spliterror: splitPassed
regression: remaining energy[116, 331, 73][116, 290, 64]Failed
repair check: remaining energy[200, 149, 67][200, 149, 67]Passed
generated control 1[189, 135, 60][189, 131, 58]Failed
generated control 2[220, 166, 73][220, 166, 73]Passed
generated control 3[133, 276, 73][133, 260, 70]Failed

SHA-256 / a09cb2bdd74ec5ff1c5786c6249bc44c67fb9f35d8ea46e1cca06143c343a0fb

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 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 - 9 * 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: remaining energy', [2200, 72, [10, 60, 30]], [116, 290, 64]],
  ['repair check: remaining energy', [2000, 72, [40, 30, 30]], [200, 149, 67]],
  ['generated control 1', [1800, 118, [40, 30, 30]], [189, 131, 58]],
  ['generated control 2', [2200, 60, [40, 30, 30]], [220, 166, 73]],
  ['generated control 3', [2200, 83, [20, 50, 30]], [133, 260, 70]]],
 [['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: remaining energy', [2000, 91, [15, 55, 30]], [146, 228, 56]],
  ['repair check: remaining energy', [3000, 91, [40, 30, 30]], [300, 225, 100]],
  ['generated control 1', [1500, 72, [20, 50, 25]], 'error: split'],
  ['generated control 2', [2000, 60, [10, 60, 30]], [96, 269, 60]],
  ['generated control 3', [2200, 100, [30, 40, 30]], [165, 221, 73]]],
 [['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: remaining energy', [1800, 91, [10, 60, 30]], [146, 203, 45]],
  ['repair check: remaining energy', [1800, 60, [15, 55, 30]], [96, 228, 56]],
  ['generated control 1', [2500, 83, [15, 55, 30]], [133, 319, 77]],
  ['generated control 2', [2200, 50, [15, 55, 30]], [83, 303, 73]],
  ['generated control 3', [1500, 91, [40, 30, 30]], [150, 113, 50]]],
 [['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: remaining energy', [1500, 118, [20, 50, 30]], [189, 116, 31]],
  ['repair check: remaining energy', [1800, 50, [40, 30, 30]], [180, 135, 60]],
  ['generated control 1', [2000, 72, [30, 40, 29]], 'error: split'],
  ['generated control 2', [2500, 83, [30, 40, 30]], [188, 250, 83]],
  ['generated control 3', [2500, 100, [10, 60, 30]], [160, 310, 69]]],
 [['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: remaining energy', [2500, 118, [30, 40, 30]], [189, 249, 83]],
  ['repair check: remaining energy', [1800, 72, [10, 60, 30]], [116, 224, 49]],
  ['generated control 1', [2200, 91, [20, 50, 30]], [146, 253, 67]],
  ['generated control 2', [1500, 60, [30, 40, 31]], 'error: split'],
  ['generated control 3', [1500, 91, [30, 40, 29]], '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 fixtureActualExpectedOutcome
balanced[150, 93, 31][150, 199, 67]Failed
protein floor binds[192, -37, -9][192, 118, 29]Failed
bad spliterror: spliterror: splitPassed
regression: remaining energy[116, 192, 43][116, 290, 64]Failed
repair check: remaining energy[200, 25, 11][200, 149, 67]Failed
generated control 1[189, 11, 6][189, 131, 58]Failed
generated control 2[220, 28, 12][220, 166, 73]Failed
generated control 3[133, 156, 42][133, 260, 70]Failed

SHA-256 / 5049e34e90e59964f949debef12c475ff8ee9db6bbf5a002b2adb7255031fd82

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 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 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.585655+00:00.

Case digest / da860b8730efe28f629d537ff20b35ac6004afb73d564a61f38881d610bbe805