FA-96991 / Recipe scaling and nutrition / Open access
Atwater energy calculator: fiber energy factor · case 01
Fiber contributes nothing to energy.
ROOT CAUSE
The 2 kcal per gram fermentable fiber factor is dropped.
VERIFIED REPAIR
Add 2 kcal per gram of fiber.
Unsuccessful approach: Using 4 kcal per gram treats fiber as available carbohydrate.
Case contract
Gram amounts as strings. Total carbohydrate includes fiber and polyols; available carb = max(0, carb - fiber - polyol). kcal = 4*protein + 9*fat + 4*available + 2*fiber + 7*alcohol + 2.4*polyol. Return [kcal, kJ, fat_energy_pct]: kcal half-up integer of the exact energy, kJ half-up integer of exact kcal * 4.184, fat pct = half-up of 9*fat/exact kcal*100 (0 if energy is 0).
Why this case matters
Recipe energy totals use factor systems where fiber and sugar alcohols are not full carbohydrate.
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(protein, fat, carb, fiber, alcohol, polyol):
p, fat, carb, fib, alc, poly = (Fraction(v) for v in (protein, fat, carb, fiber, alcohol, polyol))
avail = carb - fib - poly
avail = max(avail, Fraction(0))
exact = 4 * p + 9 * fat + 4 * avail + 0 * fib + 7 * alc + Fraction(12, 5) * poly
def r(x):
return math.floor(x + Fraction(1, 2))
kj = r(exact * Fraction(4184, 1000))
pct_fat = r(9 * fat * 100 / exact) if exact else 0
return [r(exact), kj, pct_fat]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['regression: fiber energy factor', ['17', '21', '21', '5', '0', '0'], [331, 1385, 57]],
['repair check: fiber energy factor', ['19', '0', '27', '5', '5', '0'], [209, 874, 0]],
['generated control 1', ['6', '15', '18', '1', '14', '4'], [321, 1341, 42]],
['generated control 2', ['7', '6', '58', '3', '5', '4'], [337, 1408, 16]],
['generated control 3', ['15', '51/2', '46', '0', '0', '4'], [467, 1954, 49]]],
[['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['regression: fiber energy factor', ['17', '4', '0', '8', '0', '0'], [120, 502, 30]],
['repair check: fiber energy factor', ['16', '3/4', '37', '39', '5', '0'], [184, 769, 4]],
['generated control 1', ['36', '7/4', '0', '0', '0', '4'], [169, 709, 9]],
['generated control 2', ['33', '1/4', '59', '0', '0', '4'], [364, 1522, 1]],
['generated control 3', ['34', '22', '13', '0', '0', '10'], [370, 1548, 54]]],
[['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['regression: fiber energy factor', ['40', '5', '46', '5', '0', '4'], [373, 1559, 12]],
['repair check: fiber energy factor', ['19', '7/2', '45', '2', '0', '4'], [277, 1159, 11]],
['generated control 1', ['21', '51/4', '3', '0', '5', '10'], [258, 1078, 45]],
['generated control 2', ['26', '26', '45', '5', '14', '0'], [606, 2536, 39]],
['generated control 3', ['39', '0', '52', '0', '0', '10'], [348, 1456, 0]]],
[['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['regression: fiber energy factor', ['6', '14', '27', '5', '14', '10'], [330, 1381, 38]],
['repair check: fiber energy factor', ['6', '13/4', '38', '2', '14', '0'], [299, 1252, 10]],
['generated control 1', ['8', '21', '33', '35', '0', '0'], [291, 1218, 65]],
['generated control 2', ['15', '11', '32', '8', '0', '0'], [271, 1134, 37]],
['generated control 3', ['38', '59/4', '30', '2', '14', '10'], [483, 2020, 27]]],
[['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['regression: fiber energy factor', ['2', '27/2', '5', '5', '0', '4'], [149, 624, 81]],
['repair check: fiber energy factor', ['30', '67/4', '9', '1', '5', '10'], [332, 1388, 45]],
['generated control 1', ['23', '25', '24', '8', '0', '10'], [381, 1594, 59]],
['generated control 2', ['32', '39/2', '10', '0', '0', '10'], [328, 1370, 54]],
['generated control 3', ['28', '23', '33', '5', '0', '4'], [435, 1818, 48]]]]
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 |
|---|---|---|---|
| all zero | [0, 0, 0] | [0, 0, 0] | Passed |
| fat only | [90, 377, 100] | [90, 377, 100] | Passed |
| fiber heavier than carb | [29, 121, 31] | [41, 172, 22] | Failed |
| regression: fiber energy factor | [321, 1343, 59] | [331, 1385, 57] | Failed |
| repair check: fiber energy factor | [199, 833, 0] | [209, 874, 0] | Failed |
| generated control 1 | [319, 1333, 42] | [321, 1341, 42] | Failed |
| generated control 2 | [331, 1383, 16] | [337, 1408, 16] | Failed |
| generated control 3 | [467, 1954, 49] | [467, 1954, 49] | Passed |
SHA-256 / cb170e084db351f0c455439e2665d71a27e8c53d34d37e2fb32b009f5225d57b
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(protein, fat, carb, fiber, alcohol, polyol):
p, fat, carb, fib, alc, poly = (Fraction(v) for v in (protein, fat, carb, fiber, alcohol, polyol))
avail = carb - fib - poly
avail = max(avail, Fraction(0))
exact = 4 * p + 9 * fat + 4 * avail + 4 * fib + 7 * alc + Fraction(12, 5) * poly
def r(x):
return math.floor(x + Fraction(1, 2))
kj = r(exact * Fraction(4184, 1000))
pct_fat = r(9 * fat * 100 / exact) if exact else 0
return [r(exact), kj, pct_fat]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['regression: fiber energy factor', ['17', '21', '21', '5', '0', '0'], [331, 1385, 57]],
['repair check: fiber energy factor', ['19', '0', '27', '5', '5', '0'], [209, 874, 0]],
['generated control 1', ['6', '15', '18', '1', '14', '4'], [321, 1341, 42]],
['generated control 2', ['7', '6', '58', '3', '5', '4'], [337, 1408, 16]],
['generated control 3', ['15', '51/2', '46', '0', '0', '4'], [467, 1954, 49]]],
[['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['regression: fiber energy factor', ['17', '4', '0', '8', '0', '0'], [120, 502, 30]],
['repair check: fiber energy factor', ['16', '3/4', '37', '39', '5', '0'], [184, 769, 4]],
['generated control 1', ['36', '7/4', '0', '0', '0', '4'], [169, 709, 9]],
['generated control 2', ['33', '1/4', '59', '0', '0', '4'], [364, 1522, 1]],
['generated control 3', ['34', '22', '13', '0', '0', '10'], [370, 1548, 54]]],
[['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['regression: fiber energy factor', ['40', '5', '46', '5', '0', '4'], [373, 1559, 12]],
['repair check: fiber energy factor', ['19', '7/2', '45', '2', '0', '4'], [277, 1159, 11]],
['generated control 1', ['21', '51/4', '3', '0', '5', '10'], [258, 1078, 45]],
['generated control 2', ['26', '26', '45', '5', '14', '0'], [606, 2536, 39]],
['generated control 3', ['39', '0', '52', '0', '0', '10'], [348, 1456, 0]]],
[['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['regression: fiber energy factor', ['6', '14', '27', '5', '14', '10'], [330, 1381, 38]],
['repair check: fiber energy factor', ['6', '13/4', '38', '2', '14', '0'], [299, 1252, 10]],
['generated control 1', ['8', '21', '33', '35', '0', '0'], [291, 1218, 65]],
['generated control 2', ['15', '11', '32', '8', '0', '0'], [271, 1134, 37]],
['generated control 3', ['38', '59/4', '30', '2', '14', '10'], [483, 2020, 27]]],
[['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['regression: fiber energy factor', ['2', '27/2', '5', '5', '0', '4'], [149, 624, 81]],
['repair check: fiber energy factor', ['30', '67/4', '9', '1', '5', '10'], [332, 1388, 45]],
['generated control 1', ['23', '25', '24', '8', '0', '10'], [381, 1594, 59]],
['generated control 2', ['32', '39/2', '10', '0', '0', '10'], [328, 1370, 54]],
['generated control 3', ['28', '23', '33', '5', '0', '4'], [435, 1818, 48]]]]
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 |
|---|---|---|---|
| all zero | [0, 0, 0] | [0, 0, 0] | Passed |
| fat only | [90, 377, 100] | [90, 377, 100] | Passed |
| fiber heavier than carb | [53, 222, 17] | [41, 172, 22] | Failed |
| regression: fiber energy factor | [341, 1427, 55] | [331, 1385, 57] | Failed |
| repair check: fiber energy factor | [219, 916, 0] | [209, 874, 0] | Failed |
| generated control 1 | [323, 1350, 42] | [321, 1341, 42] | Failed |
| generated control 2 | [343, 1433, 16] | [337, 1408, 16] | Failed |
| generated control 3 | [467, 1954, 49] | [467, 1954, 49] | Passed |
SHA-256 / 8c416c75c13af586784c8861479bc8f7ebfce45e4b6ae6c3296c1ee1670dd0f5
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(protein, fat, carb, fiber, alcohol, polyol):
p, fat, carb, fib, alc, poly = (Fraction(v) for v in (protein, fat, carb, fiber, alcohol, polyol))
avail = carb - fib - poly
avail = max(avail, Fraction(0))
exact = 4 * p + 9 * fat + 4 * avail + 2 * fib + 7 * alc + Fraction(12, 5) * poly
def r(x):
return math.floor(x + Fraction(1, 2))
kj = r(exact * Fraction(4184, 1000))
pct_fat = r(9 * fat * 100 / exact) if exact else 0
return [r(exact), kj, pct_fat]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['regression: fiber energy factor', ['17', '21', '21', '5', '0', '0'], [331, 1385, 57]],
['repair check: fiber energy factor', ['19', '0', '27', '5', '5', '0'], [209, 874, 0]],
['generated control 1', ['6', '15', '18', '1', '14', '4'], [321, 1341, 42]],
['generated control 2', ['7', '6', '58', '3', '5', '4'], [337, 1408, 16]],
['generated control 3', ['15', '51/2', '46', '0', '0', '4'], [467, 1954, 49]]],
[['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['regression: fiber energy factor', ['17', '4', '0', '8', '0', '0'], [120, 502, 30]],
['repair check: fiber energy factor', ['16', '3/4', '37', '39', '5', '0'], [184, 769, 4]],
['generated control 1', ['36', '7/4', '0', '0', '0', '4'], [169, 709, 9]],
['generated control 2', ['33', '1/4', '59', '0', '0', '4'], [364, 1522, 1]],
['generated control 3', ['34', '22', '13', '0', '0', '10'], [370, 1548, 54]]],
[['fiber heavier than carb', ['5', '1', '3', '6', '0', '0'], [41, 172, 22]],
['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['regression: fiber energy factor', ['40', '5', '46', '5', '0', '4'], [373, 1559, 12]],
['repair check: fiber energy factor', ['19', '7/2', '45', '2', '0', '4'], [277, 1159, 11]],
['generated control 1', ['21', '51/4', '3', '0', '5', '10'], [258, 1078, 45]],
['generated control 2', ['26', '26', '45', '5', '14', '0'], [606, 2536, 39]],
['generated control 3', ['39', '0', '52', '0', '0', '10'], [348, 1456, 0]]],
[['sugar-free candy', ['0', '5', '30', '1', '0', '20'], [131, 548, 34]],
['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['regression: fiber energy factor', ['6', '14', '27', '5', '14', '10'], [330, 1381, 38]],
['repair check: fiber energy factor', ['6', '13/4', '38', '2', '14', '0'], [299, 1252, 10]],
['generated control 1', ['8', '21', '33', '35', '0', '0'], [291, 1218, 65]],
['generated control 2', ['15', '11', '32', '8', '0', '0'], [271, 1134, 37]],
['generated control 3', ['38', '59/4', '30', '2', '14', '10'], [483, 2020, 27]]],
[['cocktail', ['0', '0', '12', '0', '14', '0'], [146, 611, 0]],
['all zero', ['0', '0', '0', '0', '0', '0'], [0, 0, 0]],
['fat only', ['0', '10', '0', '0', '0', '0'], [90, 377, 100]],
['regression: fiber energy factor', ['2', '27/2', '5', '5', '0', '4'], [149, 624, 81]],
['repair check: fiber energy factor', ['30', '67/4', '9', '1', '5', '10'], [332, 1388, 45]],
['generated control 1', ['23', '25', '24', '8', '0', '10'], [381, 1594, 59]],
['generated control 2', ['32', '39/2', '10', '0', '0', '10'], [328, 1370, 54]],
['generated control 3', ['28', '23', '33', '5', '0', '4'], [435, 1818, 48]]]]
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 |
|---|---|---|---|
| all zero | [0, 0, 0] | [0, 0, 0] | Passed |
| fat only | [90, 377, 100] | [90, 377, 100] | Passed |
| fiber heavier than carb | [41, 172, 22] | [41, 172, 22] | Passed |
| regression: fiber energy factor | [331, 1385, 57] | [331, 1385, 57] | Passed |
| repair check: fiber energy factor | [209, 874, 0] | [209, 874, 0] | Passed |
| generated control 1 | [321, 1341, 42] | [321, 1341, 42] | Passed |
| generated control 2 | [337, 1408, 16] | [337, 1408, 16] | Passed |
| generated control 3 | [467, 1954, 49] | [467, 1954, 49] | Passed |
SHA-256 / 8a616de99083d165e253192009c2119621d16dac29df2760ab7734e4c0410644
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:27.780969+00:00.
Case digest / 9001f89a8b8f89a4b4232e1d07cf713cfefb91cf497f1f2f4e762b556653204e