FAILURE MAP
← Case archive

FA-97221 / Recipe scaling and nutrition / Open access

Meal glycemic load: available carbohydrate · case 01

Lentils and oats show inflated glycemic load.

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

ROOT CAUSE

Fiber is not subtracted from carbohydrate before weighting.

THE FAILURE

Fiber is not subtracted from carbohydrate before weighting.

Unsuccessful approach: Subtracting half the fiber still overstates available carbohydrate.

Case contract

Rows [name, gi, carbs, fiber, grams_eaten, per_grams] where carbs and fiber are per per_grams. Available carb = (carbs-fiber)*eaten/per. Meal GI = sum(gi*avail)/sum(avail) half-up integer (None if no available carb). GL = sum(gi*avail)/100 half-up to 0.1. Class from the exact GL: <=10 low, <20 medium, else high.

Why this case matters

Diabetes-friendly meal planners estimate combined glycemic load from mixed foods.

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(foods):
    tot = Fraction(0)
    w = Fraction(0)
    for name, gi, carbs, fiber, eaten, per in foods:
        avail = Fraction(str(carbs)) * Fraction(eaten, per)
        tot += avail
        w += gi * avail
    gi_meal = math.floor(w / tot + Fraction(1, 2)) if tot else None
    gl = w / 100
    cls = 'low' if gl <= 10 else 'medium' if gl < 20 else 'high'
    return {'gi': gi_meal, 'gl': math.floor(gl * 10 + Fraction(1, 2)) / 10, 'class': cls}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['regression: available carbohydrate',
   [[['bread', 75, 49, 2.7, 200, 100], ['apple', 36, 14, 2.4, 120, 50], ['banana', 51, 23, 2.6, 200, 100],
     ['rice', 73, 28, 0.4, 200, 100]]],
   {'class': 'high', 'gi': 65, 'gl': 140.6}],
  ['repair check: available carbohydrate',
   [[['bread', 75, 49, 2.7, 150, 100], ['oats', 55, 60, 10, 80, 100]]],
   {'class': 'high', 'gi': 68, 'gl': 74.1}],
  ['generated control 1', [[['bread', 75, 49, 2.7, 150, 100]]], {'class': 'high', 'gi': 75, 'gl': 52.1}],
  ['generated control 2',
   [[['oats', 55, 60, 10, 50, 100], ['banana', 51, 23, 2.6, 120, 100], ['apple', 36, 14, 2.4, 50, 100],
     ['juice', 50, 10, 0, 200, 50]]],
   {'class': 'high', 'gi': 51, 'gl': 48.3}],
  ['generated control 3',
   [[['apple', 36, 14, 2.4, 80, 50], ['lentils', 32, 20, 8, 30, 50], ['juice', 50, 10, 0, 80, 50],
     ['banana', 51, 23, 2.6, 50, 100]]],
   {'class': 'high', 'gi': 43, 'gl': 22.2}]],
 [['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['regression: available carbohydrate',
   [[['apple', 36, 14, 2.4, 80, 100], ['bread', 75, 49, 2.7, 50, 100], ['juice', 50, 10, 0, 80, 50]]],
   {'class': 'high', 'gi': 59, 'gl': 28.7}],
  ['repair check: available carbohydrate',
   [[['juice', 50, 10, 0, 120, 100], ['lentils', 32, 20, 8, 120, 100], ['banana', 51, 23, 2.6, 200, 100],
     ['apple', 36, 14, 2.4, 150, 100]]],
   {'class': 'high', 'gi': 45, 'gl': 37.7}],
  ['generated control 1', [[['juice', 50, 10, 0, 80, 50]]], {'class': 'low', 'gi': 50, 'gl': 8.0}],
  ['generated control 2',
   [[['rice', 73, 28, 0.4, 80, 50], ['banana', 51, 23, 2.6, 200, 100], ['oats', 55, 60, 10, 200, 100]]],
   {'class': 'high', 'gi': 58, 'gl': 108.0}],
  ['generated control 3',
   [[['bread', 75, 49, 2.7, 150, 100], ['apple', 36, 14, 2.4, 120, 100], ['rice', 73, 28, 0.4, 150, 50],
     ['juice', 50, 10, 0, 120, 100]]],
   {'class': 'high', 'gi': 69, 'gl': 123.5}]],
 [['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['regression: available carbohydrate', [[['rice', 73, 28, 0.4, 50, 100], ['apple', 36, 14, 2.4, 200, 50]]],
   {'class': 'high', 'gi': 44, 'gl': 26.8}],
  ['repair check: available carbohydrate',
   [[['banana', 51, 23, 2.6, 200, 100], ['apple', 36, 14, 2.4, 120, 100], ['rice', 73, 28, 0.4, 30, 50]]],
   {'class': 'high', 'gi': 53, 'gl': 37.9}],
  ['generated control 1', [[['banana', 51, 23, 2.6, 120, 100], ['lentils', 32, 20, 8, 80, 100]]],
   {'class': 'medium', 'gi': 46, 'gl': 15.6}],
  ['generated control 2', [[['lentils', 32, 20, 8, 150, 100], ['oats', 55, 60, 10, 150, 100]]],
   {'class': 'high', 'gi': 51, 'gl': 47.0}],
  ['generated control 3',
   [[['lentils', 32, 20, 8, 150, 50], ['banana', 51, 23, 2.6, 150, 50], ['oats', 55, 60, 10, 30, 50]]],
   {'class': 'high', 'gi': 47, 'gl': 59.2}]],
 [['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['regression: available carbohydrate',
   [[['banana', 51, 23, 2.6, 150, 100], ['rice', 73, 28, 0.4, 50, 50], ['bread', 75, 49, 2.7, 80, 100],
     ['oats', 55, 60, 10, 200, 100]]],
   {'class': 'high', 'gi': 61, 'gl': 118.5}],
  ['repair check: available carbohydrate',
   [[['rice', 73, 28, 0.4, 30, 100], ['lentils', 32, 20, 8, 150, 50], ['oats', 55, 60, 10, 50, 100]]],
   {'class': 'high', 'gi': 45, 'gl': 31.3}],
  ['generated control 1', [[['bread', 75, 49, 2.7, 30, 100], ['juice', 50, 10, 0, 120, 100]]],
   {'class': 'medium', 'gi': 63, 'gl': 16.4}],
  ['generated control 2',
   [[['banana', 51, 23, 2.6, 150, 50], ['bread', 75, 49, 2.7, 30, 50], ['rice', 73, 28, 0.4, 150, 100]]],
   {'class': 'high', 'gi': 63, 'gl': 82.3}],
  ['generated control 3', [[['banana', 51, 23, 2.6, 80, 100], ['oats', 55, 60, 10, 30, 50]]],
   {'class': 'high', 'gi': 54, 'gl': 24.8}]],
 [['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['regression: available carbohydrate',
   [[['banana', 51, 23, 2.6, 150, 100], ['juice', 50, 10, 0, 50, 100], ['oats', 55, 60, 10, 150, 100]]],
   {'class': 'high', 'gi': 54, 'gl': 59.4}],
  ['repair check: available carbohydrate', [[['bread', 75, 49, 2.7, 120, 100]]],
   {'class': 'high', 'gi': 75, 'gl': 41.7}],
  ['generated control 1', [[['oats', 55, 60, 10, 80, 100]]], {'class': 'high', 'gi': 55, 'gl': 22.0}],
  ['generated control 2',
   [[['oats', 55, 60, 10, 50, 100], ['bread', 75, 49, 2.7, 30, 50], ['rice', 73, 28, 0.4, 80, 50],
     ['lentils', 32, 20, 8, 200, 100]]],
   {'class': 'high', 'gi': 62, 'gl': 74.5}],
  ['generated control 3', [[['bread', 75, 49, 2.7, 150, 100], ['lentils', 32, 20, 8, 30, 100]]],
   {'class': 'high', 'gi': 73, 'gl': 53.2}]]]
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
single food{'class': 'high', 'gi': 73, 'gl': 30.7}{'class': 'high', 'gi': 73, 'gl': 30.2}Failed
load exactly ten{'class': 'low', 'gi': 50, 'gl': 10.0}{'class': 'low', 'gi': 50, 'gl': 10.0}Passed
no carbs{'class': 'low', 'gi': None, 'gl': 0.0}{'class': 'low', 'gi': None, 'gl': 0.0}Passed
regression: available carbohydrate{'class': 'high', 'gi': 64, 'gl': 149.9}{'class': 'high', 'gi': 65, 'gl': 140.6}Failed
repair check: available carbohydrate{'class': 'high', 'gi': 67, 'gl': 81.5}{'class': 'high', 'gi': 68, 'gl': 74.1}Failed
generated control 1{'class': 'high', 'gi': 75, 'gl': 55.1}{'class': 'high', 'gi': 75, 'gl': 52.1}Failed
generated control 2{'class': 'high', 'gi': 51, 'gl': 53.1}{'class': 'high', 'gi': 51, 'gl': 48.3}Failed
generated control 3{'class': 'high', 'gi': 42, 'gl': 25.8}{'class': 'high', 'gi': 43, 'gl': 22.2}Failed

SHA-256 / 52dbc528e4a7949c6957eea420da49f6ffe342c2a41df465cea56e3b72076f84

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(foods):
    tot = Fraction(0)
    w = Fraction(0)
    for name, gi, carbs, fiber, eaten, per in foods:
        avail = (Fraction(str(carbs)) - Fraction(str(fiber)) / 2) * Fraction(eaten, per)
        tot += avail
        w += gi * avail
    gi_meal = math.floor(w / tot + Fraction(1, 2)) if tot else None
    gl = w / 100
    cls = 'low' if gl <= 10 else 'medium' if gl < 20 else 'high'
    return {'gi': gi_meal, 'gl': math.floor(gl * 10 + Fraction(1, 2)) / 10, 'class': cls}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['regression: available carbohydrate',
   [[['bread', 75, 49, 2.7, 200, 100], ['apple', 36, 14, 2.4, 120, 50], ['banana', 51, 23, 2.6, 200, 100],
     ['rice', 73, 28, 0.4, 200, 100]]],
   {'class': 'high', 'gi': 65, 'gl': 140.6}],
  ['repair check: available carbohydrate',
   [[['bread', 75, 49, 2.7, 150, 100], ['oats', 55, 60, 10, 80, 100]]],
   {'class': 'high', 'gi': 68, 'gl': 74.1}],
  ['generated control 1', [[['bread', 75, 49, 2.7, 150, 100]]], {'class': 'high', 'gi': 75, 'gl': 52.1}],
  ['generated control 2',
   [[['oats', 55, 60, 10, 50, 100], ['banana', 51, 23, 2.6, 120, 100], ['apple', 36, 14, 2.4, 50, 100],
     ['juice', 50, 10, 0, 200, 50]]],
   {'class': 'high', 'gi': 51, 'gl': 48.3}],
  ['generated control 3',
   [[['apple', 36, 14, 2.4, 80, 50], ['lentils', 32, 20, 8, 30, 50], ['juice', 50, 10, 0, 80, 50],
     ['banana', 51, 23, 2.6, 50, 100]]],
   {'class': 'high', 'gi': 43, 'gl': 22.2}]],
 [['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['regression: available carbohydrate',
   [[['apple', 36, 14, 2.4, 80, 100], ['bread', 75, 49, 2.7, 50, 100], ['juice', 50, 10, 0, 80, 50]]],
   {'class': 'high', 'gi': 59, 'gl': 28.7}],
  ['repair check: available carbohydrate',
   [[['juice', 50, 10, 0, 120, 100], ['lentils', 32, 20, 8, 120, 100], ['banana', 51, 23, 2.6, 200, 100],
     ['apple', 36, 14, 2.4, 150, 100]]],
   {'class': 'high', 'gi': 45, 'gl': 37.7}],
  ['generated control 1', [[['juice', 50, 10, 0, 80, 50]]], {'class': 'low', 'gi': 50, 'gl': 8.0}],
  ['generated control 2',
   [[['rice', 73, 28, 0.4, 80, 50], ['banana', 51, 23, 2.6, 200, 100], ['oats', 55, 60, 10, 200, 100]]],
   {'class': 'high', 'gi': 58, 'gl': 108.0}],
  ['generated control 3',
   [[['bread', 75, 49, 2.7, 150, 100], ['apple', 36, 14, 2.4, 120, 100], ['rice', 73, 28, 0.4, 150, 50],
     ['juice', 50, 10, 0, 120, 100]]],
   {'class': 'high', 'gi': 69, 'gl': 123.5}]],
 [['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['regression: available carbohydrate', [[['rice', 73, 28, 0.4, 50, 100], ['apple', 36, 14, 2.4, 200, 50]]],
   {'class': 'high', 'gi': 44, 'gl': 26.8}],
  ['repair check: available carbohydrate',
   [[['banana', 51, 23, 2.6, 200, 100], ['apple', 36, 14, 2.4, 120, 100], ['rice', 73, 28, 0.4, 30, 50]]],
   {'class': 'high', 'gi': 53, 'gl': 37.9}],
  ['generated control 1', [[['banana', 51, 23, 2.6, 120, 100], ['lentils', 32, 20, 8, 80, 100]]],
   {'class': 'medium', 'gi': 46, 'gl': 15.6}],
  ['generated control 2', [[['lentils', 32, 20, 8, 150, 100], ['oats', 55, 60, 10, 150, 100]]],
   {'class': 'high', 'gi': 51, 'gl': 47.0}],
  ['generated control 3',
   [[['lentils', 32, 20, 8, 150, 50], ['banana', 51, 23, 2.6, 150, 50], ['oats', 55, 60, 10, 30, 50]]],
   {'class': 'high', 'gi': 47, 'gl': 59.2}]],
 [['mixed meal', [[['lentils', 32, 20, 8, 200, 100], ['bread', 75, 49, 2.7, 50, 100]]],
   {'class': 'high', 'gi': 53, 'gl': 25.0}],
  ['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['regression: available carbohydrate',
   [[['banana', 51, 23, 2.6, 150, 100], ['rice', 73, 28, 0.4, 50, 50], ['bread', 75, 49, 2.7, 80, 100],
     ['oats', 55, 60, 10, 200, 100]]],
   {'class': 'high', 'gi': 61, 'gl': 118.5}],
  ['repair check: available carbohydrate',
   [[['rice', 73, 28, 0.4, 30, 100], ['lentils', 32, 20, 8, 150, 50], ['oats', 55, 60, 10, 50, 100]]],
   {'class': 'high', 'gi': 45, 'gl': 31.3}],
  ['generated control 1', [[['bread', 75, 49, 2.7, 30, 100], ['juice', 50, 10, 0, 120, 100]]],
   {'class': 'medium', 'gi': 63, 'gl': 16.4}],
  ['generated control 2',
   [[['banana', 51, 23, 2.6, 150, 50], ['bread', 75, 49, 2.7, 30, 50], ['rice', 73, 28, 0.4, 150, 100]]],
   {'class': 'high', 'gi': 63, 'gl': 82.3}],
  ['generated control 3', [[['banana', 51, 23, 2.6, 80, 100], ['oats', 55, 60, 10, 30, 50]]],
   {'class': 'high', 'gi': 54, 'gl': 24.8}]],
 [['single food', [[['rice', 73, 28, 0.4, 150, 100]]], {'class': 'high', 'gi': 73, 'gl': 30.2}],
  ['load exactly ten', [[['juice', 50, 10, 0, 200, 100]]], {'class': 'low', 'gi': 50, 'gl': 10.0}],
  ['no carbs', [[['egg', 0, 0, 0, 50, 100]]], {'class': 'low', 'gi': None, 'gl': 0.0}],
  ['regression: available carbohydrate',
   [[['banana', 51, 23, 2.6, 150, 100], ['juice', 50, 10, 0, 50, 100], ['oats', 55, 60, 10, 150, 100]]],
   {'class': 'high', 'gi': 54, 'gl': 59.4}],
  ['repair check: available carbohydrate', [[['bread', 75, 49, 2.7, 120, 100]]],
   {'class': 'high', 'gi': 75, 'gl': 41.7}],
  ['generated control 1', [[['oats', 55, 60, 10, 80, 100]]], {'class': 'high', 'gi': 55, 'gl': 22.0}],
  ['generated control 2',
   [[['oats', 55, 60, 10, 50, 100], ['bread', 75, 49, 2.7, 30, 50], ['rice', 73, 28, 0.4, 80, 50],
     ['lentils', 32, 20, 8, 200, 100]]],
   {'class': 'high', 'gi': 62, 'gl': 74.5}],
  ['generated control 3', [[['bread', 75, 49, 2.7, 150, 100], ['lentils', 32, 20, 8, 30, 100]]],
   {'class': 'high', 'gi': 73, 'gl': 53.2}]]]
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
single food{'class': 'high', 'gi': 73, 'gl': 30.4}{'class': 'high', 'gi': 73, 'gl': 30.2}Failed
load exactly ten{'class': 'low', 'gi': 50, 'gl': 10.0}{'class': 'low', 'gi': 50, 'gl': 10.0}Passed
no carbs{'class': 'low', 'gi': None, 'gl': 0.0}{'class': 'low', 'gi': None, 'gl': 0.0}Passed
regression: available carbohydrate{'class': 'high', 'gi': 65, 'gl': 145.3}{'class': 'high', 'gi': 65, 'gl': 140.6}Failed
repair check: available carbohydrate{'class': 'high', 'gi': 67, 'gl': 77.8}{'class': 'high', 'gi': 68, 'gl': 74.1}Failed
generated control 1{'class': 'high', 'gi': 75, 'gl': 53.6}{'class': 'high', 'gi': 75, 'gl': 52.1}Failed
generated control 2{'class': 'high', 'gi': 51, 'gl': 50.7}{'class': 'high', 'gi': 51, 'gl': 48.3}Failed
generated control 3{'class': 'high', 'gi': 42, 'gl': 24.0}{'class': 'high', 'gi': 43, 'gl': 22.2}Failed

SHA-256 / ab3c3700e6723f6609f2573273d9282012847f23e5fb18af519b83eb7a1fe5e9

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

Case digest / f8b215b2a897a787dc421974192a14934642b02f5c1d8263ba00d4de5d7993c7