FAILURE MAP
← Case archive

FA-97136 / Recipe scaling and nutrition / Open access

Shopping list aggregator: pantry subtraction floor · case 01

Having six eggs for a two-egg recipe lists "-4" eggs to buy.

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

ROOT CAUSE

Pantry subtraction is not clamped at zero.

THE FAILURE

Pantry subtraction is not clamped at zero.

Unsuccessful approach: abs() turns a surplus of four eggs into four eggs to buy.

Case contract

Rows [name, qty, unit]. Names normalize: trim, lower, "-oes" -> drop "es", "-ies" -> "y", other trailing "s" dropped unless "ss". Volume (tsp=1, tbsp=3, cup=48 tsp), mass (g, kg=1000 g) and other units aggregate separately per name. Pantry {name: [qty, unit]} subtracts from the same name and dimension, never below 0. Output sorted by (name, dimension) as [name, str(qty), unit], skipping zero totals; volume shows cup if >=12 tsp, else tbsp if >=3 tsp, else tsp; mass shows kg if >=1000 g.

Why this case matters

Meal planners merge ingredient lists across recipes and subtract what is already in the pantry.

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = tot[pk] - v
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry subtraction floor',
   [[[['peas', '1/4', 'each'], ['eggs', '1', 'kg'], ['grape', '3/4', 'tsp']]], {'peas': ['2', 'each']}],
   [['egg', '1', 'kg'], ['grape', '3/4', 'tsp']]],
  ['repair check: pantry subtraction floor',
   [[[['watercress', '3/4', 'cup'], ['peas', '2', 'each'], ['grapes', '1/2', 'g'], ['flour', '1', 'kg']],
     [['peas', '1/2', 'tbsp'], ['tomatoes', '1/2', 'kg'], ['watercress', '3/4', 'tsp'],
      ['peas', '4', 'each']],
     [['tomatoes', '1/2', 'cup'], ['potatoes', '1/4', 'tsp'], ['egg', '1/3', 'cup'], ['flour', '4', 'tsp']]],
    {'berries': ['1/3', 'each'], 'tomatoes': ['3', 'cup']}],
   [['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'],
    ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'],
    ['watercress', '49/64', 'cup']]],
  ['generated control 1',
   [[[['egg', '1/4', 'g'], ['grape', '4', 'tsp']],
     [['egg', '4', 'tsp'], ['watercress', '4', 'g'], ['egg', '1', 'kg'], ['berry', '4', 'kg']],
     [['grapes', '1/4', 'cup'], ['watercress', '1/2', 'tsp'], ['sugar ', '3/4', 'g']]],
    {'egg': ['1/2', 'tsp']}],
   [['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'],
    ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']]],
  ['generated control 2',
   [[[['potatoes', '1/4', 'g'], ['tomatoes', '4', 'tsp']],
     [['potatoes', '2', 'kg'], ['berry', '3/4', 'cup']]],
    {'grapes': ['2', 'kg']}],
   [['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']]],
  ['generated control 3',
   [[[['peas', '1/3', 'g'], ['flour', '1', 'tsp']]], {'eggs': ['1', 'tbsp'], 'tomatoes': ['2', 'each']}],
   [['flour', '1', 'tsp'], ['pea', '1/3', 'g']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: pantry subtraction floor',
   [[[['berries', '1/4', 'tbsp'], ['berries', '1/2', 'kg'], ['watercress', '1', 'cup'],
      ['watercress', '3', 'tbsp']],
     [['flour', '1', 'kg'], ['grape', '1/2', 'tsp'], ['sugar ', '3/4', 'tsp']]],
    {'eggs': ['2', 'tbsp'], 'grapes': ['1', 'cup']}],
   [['berry', '500', 'g'], ['berry', '3/4', 'tsp'], ['flour', '1', 'kg'], ['sugar', '3/4', 'tsp'],
    ['watercress', '19/16', 'cup']]],
  ['repair check: pantry subtraction floor',
   [[[['peas', '2', 'kg'], ['grapes', '3/4', 'cup'], ['berry', '3/4', 'each'], ['flour', '3', 'g']],
     [['egg', '2', 'tbsp'], ['Tomato', '3/4', 'each']]],
    {'eggs': ['1/4', 'cup'], 'grape': ['1/2', 'cup']}],
   [['berry', '3/4', 'each'], ['flour', '3', 'g'], ['grape', '1/4', 'cup'], ['pea', '2', 'kg'],
    ['tomato', '3/4', 'each']]],
  ['generated control 1',
   [[[['egg', '2', 'tsp'], ['egg', '2', 'cup']], [['Tomato', '1/2', 'cup'], ['berries', '1/3', 'each']],
     [['grapes', '1/2', 'each'], ['berry', '2', 'cup'], ['eggs', '3/4', 'tbsp'], ['flour', '1/3', 'g']]],
    {'grape': ['3', 'tbsp']}],
   [['berry', '1/3', 'each'], ['berry', '2', 'cup'], ['egg', '401/192', 'cup'], ['flour', '1/3', 'g'],
    ['grape', '1/2', 'each'], ['tomato', '1/2', 'cup']]],
  ['generated control 2',
   [[[['egg', '3', 'cup']], [['watercress', '2', 'tbsp'], ['peas', '3', 'each']]], {'sugar ': ['1', 'g']}],
   [['egg', '3', 'cup'], ['pea', '3', 'each'], ['watercress', '2', 'tbsp']]],
  ['generated control 3',
   [[[['berries', '1/3', 'tbsp'], ['Tomato', '1/3', 'tsp'], ['peas', '1/3', 'tbsp']]], {}],
   [['berry', '1', 'tsp'], ['pea', '1', 'tsp'], ['tomato', '1/3', 'tsp']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: pantry subtraction floor',
   [[[['tomatoes', '1/4', 'kg'], ['tomatoes', '1', 'tbsp'], ['potatoes', '1', 'kg'], ['peas', '1', 'each']],
     [['berry', '1/2', 'each']], [['eggs', '1/2', 'kg'], ['grapes', '1', 'kg']]],
    {'berries': ['3/4', 'each'], 'watercress': ['1/2', 'kg']}],
   [['egg', '500', 'g'], ['grape', '1', 'kg'], ['pea', '1', 'each'], ['potato', '1', 'kg'],
    ['tomato', '250', 'g'], ['tomato', '1', 'tbsp']]],
  ['repair check: pantry subtraction floor',
   [[[['flour', '3', 'each'], ['sugar ', '1/3', 'tbsp']], [['grape', '3/4', 'kg'], ['berry', '2', 'each']],
     [['berry', '1', 'cup']]],
    {'flour': ['2', 'cup'], 'sugar ': ['3', 'tbsp']}],
   [['berry', '2', 'each'], ['berry', '1', 'cup'], ['flour', '3', 'each'], ['grape', '750', 'g']]],
  ['generated control 1',
   [[[['flour', '1/2', 'each'], ['eggs', '1/2', 'kg']], [['flour', '2', 'cup']],
     [['berry', '3', 'cup'], ['peas', '3', 'tbsp']]],
    {'berry': ['4', 'tsp'], 'egg': ['1/3', 'each']}],
   [['berry', '35/12', 'cup'], ['egg', '500', 'g'], ['flour', '1/2', 'each'], ['flour', '2', 'cup'],
    ['pea', '3', 'tbsp']]],
  ['generated control 2',
   [[[['grape', '3', 'kg'], ['grape', '3/4', 'kg']],
     [['sugar ', '1', 'kg'], ['tomatoes', '1/2', 'tbsp'], ['potatoes', '2', 'cup'],
      ['watercress', '1/3', 'kg']]],
    {}],
   [['grape', '15/4', 'kg'], ['potato', '2', 'cup'], ['sugar', '1', 'kg'], ['tomato', '3/2', 'tsp'],
    ['watercress', '1000/3', 'g']]],
  ['generated control 3',
   [[[['grapes', '3', 'each'], ['potatoes', '1', 'tbsp'], ['sugar ', '1/2', 'g']]], {}],
   [['grape', '3', 'each'], ['potato', '1', 'tbsp'], ['sugar', '1/2', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: pantry subtraction floor',
   [[[['Tomato', '1/2', 'tbsp'], ['sugar ', '1', 'each'], ['watercress', '1', 'cup'],
      ['flour', '1/2', 'each']],
     [['grape', '4', 'kg']]],
    {'Tomato': ['4', 'cup'], 'grapes': ['3', 'each']}],
   [['flour', '1/2', 'each'], ['grape', '4', 'kg'], ['sugar', '1', 'each'], ['watercress', '1', 'cup']]],
  ['repair check: pantry subtraction floor',
   [[[['berry', '2', 'g'], ['tomatoes', '1', 'tbsp'], ['peas', '3', 'kg'], ['Tomato', '3', 'tbsp']],
     [['watercress', '4', 'tsp']], [['eggs', '3/4', 'tsp'], ['flour', '1/2', 'g']]],
    {'grapes': ['3/4', 'tbsp'], 'watercress': ['4', 'tbsp']}],
   [['berry', '2', 'g'], ['egg', '3/4', 'tsp'], ['flour', '1/2', 'g'], ['pea', '3', 'kg'],
    ['tomato', '1/4', 'cup']]],
  ['generated control 1',
   [[[['sugar ', '2', 'each'], ['watercress', '3/4', 'tsp'], ['sugar ', '1', 'kg'], ['tomatoes', '2', 'kg']]],
    {}],
   [['sugar', '2', 'each'], ['sugar', '1', 'kg'], ['tomato', '2', 'kg'], ['watercress', '3/4', 'tsp']]],
  ['generated control 2',
   [[[['tomatoes', '1/2', 'kg'], ['potatoes', '3/4', 'g'], ['sugar ', '3/4', 'g'], ['Tomato', '4', 'tsp']],
     [['berries', '2', 'tbsp']]],
    {}],
   [['berry', '2', 'tbsp'], ['potato', '3/4', 'g'], ['sugar', '3/4', 'g'], ['tomato', '500', 'g'],
    ['tomato', '4/3', 'tbsp']]],
  ['generated control 3',
   [[[['peas', '3', 'kg'], ['potatoes', '3', 'cup']]], {'Tomato': ['1/4', 'tbsp'], 'peas': ['1', 'cup']}],
   [['pea', '3', 'kg'], ['potato', '3', 'cup']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry subtraction floor',
   [[[['berries', '3/4', 'tbsp'], ['potatoes', '1/2', 'g']],
     [['flour', '2', 'g'], ['grapes', '1/3', 'g'], ['grape', '1/3', 'each']],
     [['sugar ', '2', 'tsp'], ['eggs', '2', 'each'], ['peas', '1', 'cup'], ['watercress', '4', 'tsp']]],
    {'sugar ': ['3', 'tsp']}],
   [['berry', '9/4', 'tsp'], ['egg', '2', 'each'], ['flour', '2', 'g'], ['grape', '1/3', 'each'],
    ['grape', '1/3', 'g'], ['pea', '1', 'cup'], ['potato', '1/2', 'g'], ['watercress', '4/3', 'tbsp']]],
  ['repair check: pantry subtraction floor',
   [[[['tomatoes', '2', 'g'], ['grape', '3', 'tsp'], ['egg', '2', 'g']],
     [['watercress', '1/3', 'g'], ['grapes', '4', 'kg'], ['grape', '2', 'kg'], ['watercress', '1/2', 'tsp']]],
    {'Tomato': ['4', 'g'], 'eggs': ['1/4', 'each']}],
   [['egg', '2', 'g'], ['grape', '6', 'kg'], ['grape', '1', 'tbsp'], ['watercress', '1/3', 'g'],
    ['watercress', '1/2', 'tsp']]],
  ['generated control 1',
   [[[['grape', '1/4', 'each'], ['peas', '4', 'g'], ['sugar ', '2', 'tbsp'], ['tomatoes', '1/2', 'each']],
     [['potatoes', '1/3', 'g'], ['potatoes', '1/2', 'each'], ['Tomato', '1/2', 'tsp'],
      ['watercress', '3', 'tsp']],
     [['grapes', '3/4', 'tsp']]],
    {'berries': ['4', 'tsp'], 'egg': ['2', 'tbsp']}],
   [['grape', '1/4', 'each'], ['grape', '3/4', 'tsp'], ['pea', '4', 'g'], ['potato', '1/2', 'each'],
    ['potato', '1/3', 'g'], ['sugar', '2', 'tbsp'], ['tomato', '1/2', 'each'], ['tomato', '1/2', 'tsp'],
    ['watercress', '1', 'tbsp']]],
  ['generated control 2',
   [[[['grapes', '4', 'tbsp'], ['eggs', '1/3', 'tbsp'], ['egg', '3/4', 'kg']], [['sugar ', '3', 'kg']]], {}],
   [['egg', '750', 'g'], ['egg', '1', 'tsp'], ['grape', '1/4', 'cup'], ['sugar', '3', 'kg']]],
  ['generated control 3',
   [[[['peas', '1/4', 'each'], ['sugar ', '4', 'each'], ['peas', '4', 'kg'], ['potatoes', '1/3', 'kg']],
     [['grape', '1/3', 'cup']]],
    {'grape': ['3/4', 'tsp']}],
   [['grape', '61/192', 'cup'], ['pea', '1/4', 'each'], ['pea', '4', 'kg'], ['potato', '1000/3', 'g'],
    ['sugar', '4', 'each']]]]]
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 recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[['egg', '-4', 'each']][]Failed
regression: pantry subtraction floor[['egg', '1', 'kg'], ['grape', '3/4', 'tsp'], ['pea', '-7/4', 'each']][['egg', '1', 'kg'], ['grape', '3/4', 'tsp']]Failed
repair check: pantry subtraction floor[['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'], ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'], ['tomato', '-120', 'tsp'], ['watercress', '49/64', 'cup']][['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'], ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'], ['watercress', '49/64', 'cup']]Failed
generated control 1[['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'], ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']][['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'], ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']]Passed
generated control 2[['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']][['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']]Passed
generated control 3[['flour', '1', 'tsp'], ['pea', '1/3', 'g']][['flour', '1', 'tsp'], ['pea', '1/3', 'g']]Passed

SHA-256 / 5e7bb521aa6c29a7c106c7e1a506dc42060556ebccfb4ffd11226acfdf17bb06

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = abs(tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry subtraction floor',
   [[[['peas', '1/4', 'each'], ['eggs', '1', 'kg'], ['grape', '3/4', 'tsp']]], {'peas': ['2', 'each']}],
   [['egg', '1', 'kg'], ['grape', '3/4', 'tsp']]],
  ['repair check: pantry subtraction floor',
   [[[['watercress', '3/4', 'cup'], ['peas', '2', 'each'], ['grapes', '1/2', 'g'], ['flour', '1', 'kg']],
     [['peas', '1/2', 'tbsp'], ['tomatoes', '1/2', 'kg'], ['watercress', '3/4', 'tsp'],
      ['peas', '4', 'each']],
     [['tomatoes', '1/2', 'cup'], ['potatoes', '1/4', 'tsp'], ['egg', '1/3', 'cup'], ['flour', '4', 'tsp']]],
    {'berries': ['1/3', 'each'], 'tomatoes': ['3', 'cup']}],
   [['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'],
    ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'],
    ['watercress', '49/64', 'cup']]],
  ['generated control 1',
   [[[['egg', '1/4', 'g'], ['grape', '4', 'tsp']],
     [['egg', '4', 'tsp'], ['watercress', '4', 'g'], ['egg', '1', 'kg'], ['berry', '4', 'kg']],
     [['grapes', '1/4', 'cup'], ['watercress', '1/2', 'tsp'], ['sugar ', '3/4', 'g']]],
    {'egg': ['1/2', 'tsp']}],
   [['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'],
    ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']]],
  ['generated control 2',
   [[[['potatoes', '1/4', 'g'], ['tomatoes', '4', 'tsp']],
     [['potatoes', '2', 'kg'], ['berry', '3/4', 'cup']]],
    {'grapes': ['2', 'kg']}],
   [['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']]],
  ['generated control 3',
   [[[['peas', '1/3', 'g'], ['flour', '1', 'tsp']]], {'eggs': ['1', 'tbsp'], 'tomatoes': ['2', 'each']}],
   [['flour', '1', 'tsp'], ['pea', '1/3', 'g']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: pantry subtraction floor',
   [[[['berries', '1/4', 'tbsp'], ['berries', '1/2', 'kg'], ['watercress', '1', 'cup'],
      ['watercress', '3', 'tbsp']],
     [['flour', '1', 'kg'], ['grape', '1/2', 'tsp'], ['sugar ', '3/4', 'tsp']]],
    {'eggs': ['2', 'tbsp'], 'grapes': ['1', 'cup']}],
   [['berry', '500', 'g'], ['berry', '3/4', 'tsp'], ['flour', '1', 'kg'], ['sugar', '3/4', 'tsp'],
    ['watercress', '19/16', 'cup']]],
  ['repair check: pantry subtraction floor',
   [[[['peas', '2', 'kg'], ['grapes', '3/4', 'cup'], ['berry', '3/4', 'each'], ['flour', '3', 'g']],
     [['egg', '2', 'tbsp'], ['Tomato', '3/4', 'each']]],
    {'eggs': ['1/4', 'cup'], 'grape': ['1/2', 'cup']}],
   [['berry', '3/4', 'each'], ['flour', '3', 'g'], ['grape', '1/4', 'cup'], ['pea', '2', 'kg'],
    ['tomato', '3/4', 'each']]],
  ['generated control 1',
   [[[['egg', '2', 'tsp'], ['egg', '2', 'cup']], [['Tomato', '1/2', 'cup'], ['berries', '1/3', 'each']],
     [['grapes', '1/2', 'each'], ['berry', '2', 'cup'], ['eggs', '3/4', 'tbsp'], ['flour', '1/3', 'g']]],
    {'grape': ['3', 'tbsp']}],
   [['berry', '1/3', 'each'], ['berry', '2', 'cup'], ['egg', '401/192', 'cup'], ['flour', '1/3', 'g'],
    ['grape', '1/2', 'each'], ['tomato', '1/2', 'cup']]],
  ['generated control 2',
   [[[['egg', '3', 'cup']], [['watercress', '2', 'tbsp'], ['peas', '3', 'each']]], {'sugar ': ['1', 'g']}],
   [['egg', '3', 'cup'], ['pea', '3', 'each'], ['watercress', '2', 'tbsp']]],
  ['generated control 3',
   [[[['berries', '1/3', 'tbsp'], ['Tomato', '1/3', 'tsp'], ['peas', '1/3', 'tbsp']]], {}],
   [['berry', '1', 'tsp'], ['pea', '1', 'tsp'], ['tomato', '1/3', 'tsp']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: pantry subtraction floor',
   [[[['tomatoes', '1/4', 'kg'], ['tomatoes', '1', 'tbsp'], ['potatoes', '1', 'kg'], ['peas', '1', 'each']],
     [['berry', '1/2', 'each']], [['eggs', '1/2', 'kg'], ['grapes', '1', 'kg']]],
    {'berries': ['3/4', 'each'], 'watercress': ['1/2', 'kg']}],
   [['egg', '500', 'g'], ['grape', '1', 'kg'], ['pea', '1', 'each'], ['potato', '1', 'kg'],
    ['tomato', '250', 'g'], ['tomato', '1', 'tbsp']]],
  ['repair check: pantry subtraction floor',
   [[[['flour', '3', 'each'], ['sugar ', '1/3', 'tbsp']], [['grape', '3/4', 'kg'], ['berry', '2', 'each']],
     [['berry', '1', 'cup']]],
    {'flour': ['2', 'cup'], 'sugar ': ['3', 'tbsp']}],
   [['berry', '2', 'each'], ['berry', '1', 'cup'], ['flour', '3', 'each'], ['grape', '750', 'g']]],
  ['generated control 1',
   [[[['flour', '1/2', 'each'], ['eggs', '1/2', 'kg']], [['flour', '2', 'cup']],
     [['berry', '3', 'cup'], ['peas', '3', 'tbsp']]],
    {'berry': ['4', 'tsp'], 'egg': ['1/3', 'each']}],
   [['berry', '35/12', 'cup'], ['egg', '500', 'g'], ['flour', '1/2', 'each'], ['flour', '2', 'cup'],
    ['pea', '3', 'tbsp']]],
  ['generated control 2',
   [[[['grape', '3', 'kg'], ['grape', '3/4', 'kg']],
     [['sugar ', '1', 'kg'], ['tomatoes', '1/2', 'tbsp'], ['potatoes', '2', 'cup'],
      ['watercress', '1/3', 'kg']]],
    {}],
   [['grape', '15/4', 'kg'], ['potato', '2', 'cup'], ['sugar', '1', 'kg'], ['tomato', '3/2', 'tsp'],
    ['watercress', '1000/3', 'g']]],
  ['generated control 3',
   [[[['grapes', '3', 'each'], ['potatoes', '1', 'tbsp'], ['sugar ', '1/2', 'g']]], {}],
   [['grape', '3', 'each'], ['potato', '1', 'tbsp'], ['sugar', '1/2', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: pantry subtraction floor',
   [[[['Tomato', '1/2', 'tbsp'], ['sugar ', '1', 'each'], ['watercress', '1', 'cup'],
      ['flour', '1/2', 'each']],
     [['grape', '4', 'kg']]],
    {'Tomato': ['4', 'cup'], 'grapes': ['3', 'each']}],
   [['flour', '1/2', 'each'], ['grape', '4', 'kg'], ['sugar', '1', 'each'], ['watercress', '1', 'cup']]],
  ['repair check: pantry subtraction floor',
   [[[['berry', '2', 'g'], ['tomatoes', '1', 'tbsp'], ['peas', '3', 'kg'], ['Tomato', '3', 'tbsp']],
     [['watercress', '4', 'tsp']], [['eggs', '3/4', 'tsp'], ['flour', '1/2', 'g']]],
    {'grapes': ['3/4', 'tbsp'], 'watercress': ['4', 'tbsp']}],
   [['berry', '2', 'g'], ['egg', '3/4', 'tsp'], ['flour', '1/2', 'g'], ['pea', '3', 'kg'],
    ['tomato', '1/4', 'cup']]],
  ['generated control 1',
   [[[['sugar ', '2', 'each'], ['watercress', '3/4', 'tsp'], ['sugar ', '1', 'kg'], ['tomatoes', '2', 'kg']]],
    {}],
   [['sugar', '2', 'each'], ['sugar', '1', 'kg'], ['tomato', '2', 'kg'], ['watercress', '3/4', 'tsp']]],
  ['generated control 2',
   [[[['tomatoes', '1/2', 'kg'], ['potatoes', '3/4', 'g'], ['sugar ', '3/4', 'g'], ['Tomato', '4', 'tsp']],
     [['berries', '2', 'tbsp']]],
    {}],
   [['berry', '2', 'tbsp'], ['potato', '3/4', 'g'], ['sugar', '3/4', 'g'], ['tomato', '500', 'g'],
    ['tomato', '4/3', 'tbsp']]],
  ['generated control 3',
   [[[['peas', '3', 'kg'], ['potatoes', '3', 'cup']]], {'Tomato': ['1/4', 'tbsp'], 'peas': ['1', 'cup']}],
   [['pea', '3', 'kg'], ['potato', '3', 'cup']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry subtraction floor',
   [[[['berries', '3/4', 'tbsp'], ['potatoes', '1/2', 'g']],
     [['flour', '2', 'g'], ['grapes', '1/3', 'g'], ['grape', '1/3', 'each']],
     [['sugar ', '2', 'tsp'], ['eggs', '2', 'each'], ['peas', '1', 'cup'], ['watercress', '4', 'tsp']]],
    {'sugar ': ['3', 'tsp']}],
   [['berry', '9/4', 'tsp'], ['egg', '2', 'each'], ['flour', '2', 'g'], ['grape', '1/3', 'each'],
    ['grape', '1/3', 'g'], ['pea', '1', 'cup'], ['potato', '1/2', 'g'], ['watercress', '4/3', 'tbsp']]],
  ['repair check: pantry subtraction floor',
   [[[['tomatoes', '2', 'g'], ['grape', '3', 'tsp'], ['egg', '2', 'g']],
     [['watercress', '1/3', 'g'], ['grapes', '4', 'kg'], ['grape', '2', 'kg'], ['watercress', '1/2', 'tsp']]],
    {'Tomato': ['4', 'g'], 'eggs': ['1/4', 'each']}],
   [['egg', '2', 'g'], ['grape', '6', 'kg'], ['grape', '1', 'tbsp'], ['watercress', '1/3', 'g'],
    ['watercress', '1/2', 'tsp']]],
  ['generated control 1',
   [[[['grape', '1/4', 'each'], ['peas', '4', 'g'], ['sugar ', '2', 'tbsp'], ['tomatoes', '1/2', 'each']],
     [['potatoes', '1/3', 'g'], ['potatoes', '1/2', 'each'], ['Tomato', '1/2', 'tsp'],
      ['watercress', '3', 'tsp']],
     [['grapes', '3/4', 'tsp']]],
    {'berries': ['4', 'tsp'], 'egg': ['2', 'tbsp']}],
   [['grape', '1/4', 'each'], ['grape', '3/4', 'tsp'], ['pea', '4', 'g'], ['potato', '1/2', 'each'],
    ['potato', '1/3', 'g'], ['sugar', '2', 'tbsp'], ['tomato', '1/2', 'each'], ['tomato', '1/2', 'tsp'],
    ['watercress', '1', 'tbsp']]],
  ['generated control 2',
   [[[['grapes', '4', 'tbsp'], ['eggs', '1/3', 'tbsp'], ['egg', '3/4', 'kg']], [['sugar ', '3', 'kg']]], {}],
   [['egg', '750', 'g'], ['egg', '1', 'tsp'], ['grape', '1/4', 'cup'], ['sugar', '3', 'kg']]],
  ['generated control 3',
   [[[['peas', '1/4', 'each'], ['sugar ', '4', 'each'], ['peas', '4', 'kg'], ['potatoes', '1/3', 'kg']],
     [['grape', '1/3', 'cup']]],
    {'grape': ['3/4', 'tsp']}],
   [['grape', '61/192', 'cup'], ['pea', '1/4', 'each'], ['pea', '4', 'kg'], ['potato', '1000/3', 'g'],
    ['sugar', '4', 'each']]]]]
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 recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[['egg', '4', 'each']][]Failed
regression: pantry subtraction floor[['egg', '1', 'kg'], ['grape', '3/4', 'tsp'], ['pea', '7/4', 'each']][['egg', '1', 'kg'], ['grape', '3/4', 'tsp']]Failed
repair check: pantry subtraction floor[['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'], ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'], ['tomato', '5/2', 'cup'], ['watercress', '49/64', 'cup']][['egg', '1/3', 'cup'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '1/2', 'g'], ['pea', '6', 'each'], ['pea', '3/2', 'tsp'], ['potato', '1/4', 'tsp'], ['tomato', '500', 'g'], ['watercress', '49/64', 'cup']]Failed
generated control 1[['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'], ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']][['berry', '4', 'kg'], ['egg', '4001/4000', 'kg'], ['egg', '7/6', 'tbsp'], ['grape', '1/3', 'cup'], ['sugar', '3/4', 'g'], ['watercress', '4', 'g'], ['watercress', '1/2', 'tsp']]Passed
generated control 2[['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']][['berry', '3/4', 'cup'], ['potato', '8001/4000', 'kg'], ['tomato', '4/3', 'tbsp']]Passed
generated control 3[['flour', '1', 'tsp'], ['pea', '1/3', 'g']][['flour', '1', 'tsp'], ['pea', '1/3', 'g']]Passed

SHA-256 / bfbaa8b0c68d006b43db1df9e4ba91cc378511c26b79d3ba4db8eef1c7686131

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

Case digest / 68e9e3b6e55d10b35a94cbd9085f1df7d43949cd60efd95a27f82e1a118500ce