FA-96866 / Recipe scaling and nutrition / Open access
Servings scaler: kitchen fraction reduction · case 01
Half a cup prints as "4/8" and one and a quarter as "1 2/8".
ROOT CAUSE
The remainder in eighths is printed without dividing out the common factor.
VERIFIED REPAIR
Reduce rem/8 by gcd(rem, 8).
Unsuccessful approach: Dividing only by 2 turns 4/8 into 2/4 instead of 1/2.
Case contract
Scale [name, qty, unit, kind] rows from base to target servings. Factor f=target/base (both must be positive, else an error string). Seasoning rows scale by 1+(f-1)*3/4 (damped); other rows by f. Unit "each" rounds half-up to an integer with a floor of 1. Other units round half-up to the nearest 1/8 and print as reduced kitchen fractions ("1 1/2", "3/4", "2"); a zero result prints "pinch".
Why this case matters
Home and commercial recipe scalers must keep countable items whole and print measurable fractions cooks can actually portion.
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(items, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = 1
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(max(1, n)), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: kitchen fraction reduction',
[[['pepper', '5/2', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning']], 8, 1],
[['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['milk', '3/4', 'cup', 'base'], ['garlic clove', '3', 'each', 'base'], ['lime', '2', 'each', 'base'],
['egg', '4', 'each', 'base']],
3, 6],
[['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']]],
['generated control 1',
[[['milk', '1', 'cup', 'base'], ['butter', '5/2', 'tbsp', 'base'], ['pepper', '1/4', 'tsp', 'seasoning'],
['cumin', '1/4', 'tsp', 'seasoning']],
3, 12],
[['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']]],
['generated control 2', [[['salt', '3/4', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 7, 8],
[['salt', '7/8', 'tsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['pepper', '1', 'tsp', 'seasoning'], ['garlic clove', '5', 'each', 'base'], ['egg', '4', 'each', 'base'],
['salt', '3/4', 'tsp', 'seasoning']],
2, 3],
[['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: kitchen fraction reduction',
[[['salt', '1/2', 'tsp', 'seasoning'], ['garlic clove', '1/2', 'each', 'base']], 2, 11],
[['salt', '2 1/4', 'tsp'], ['garlic clove', '3', 'each']]],
['repair check: kitchen fraction reduction',
[[['cumin', '3/2', 'tsp', 'seasoning'], ['salt', '5/2', 'tsp', 'seasoning'],
['flour', '3/4', 'cup', 'base'], ['garlic clove', '4', 'each', 'base'],
['butter', '3/2', 'tbsp', 'base']],
2, 10],
[['cumin', '6', 'tsp'], ['salt', '10', 'tsp'], ['flour', '3 3/4', 'cup'], ['garlic clove', '20', 'each'],
['butter', '7 1/2', 'tbsp']]],
['generated control 1',
[[['butter', '2', 'tbsp', 'base'], ['pepper', '5/2', 'tsp', 'seasoning'], ['milk', '1/2', 'cup', 'base']],
5, 8],
[['butter', '3 1/4', 'tbsp'], ['pepper', '3 5/8', 'tsp'], ['milk', '3/4', 'cup']]],
['generated control 2',
[[['pepper', '1/4', 'tsp', 'seasoning'], ['cumin', '3', 'tsp', 'seasoning'],
['butter', '9/4', 'tbsp', 'base'], ['lime', '4', 'each', 'base']],
5, 2],
[['pepper', '1/8', 'tsp'], ['cumin', '1 5/8', 'tsp'], ['butter', '7/8', 'tbsp'], ['lime', '2', 'each']]],
['generated control 3',
[[['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '2/3', 'tbsp', 'base'], ['egg', '4', 'each', 'base'],
['milk', '1/3', 'cup', 'base']],
6, 1],
[['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['egg', '1', 'each'], ['milk', 'pinch', 'cup']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: kitchen fraction reduction',
[[['pepper', '2/3', 'tsp', 'seasoning'], ['salt', '3/4', 'tsp', 'seasoning']], 6, 11],
[['pepper', '1 1/8', 'tsp'], ['salt', '1 1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '5/2', 'cup', 'base'], ['milk', '3/4', 'cup', 'base'], ['lime', '2', 'each', 'base'],
['cumin', '3/2', 'tsp', 'seasoning']],
5, 3],
[['flour', '1 1/2', 'cup'], ['milk', '1/2', 'cup'], ['lime', '1', 'each'], ['cumin', '1', 'tsp']]],
['generated control 1', [[['butter', '2', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 1, 4],
[['butter', '8', 'tbsp'], ['pepper', '4 7/8', 'tsp']]],
['generated control 2',
[[['pepper', '3/4', 'tsp', 'seasoning'], ['milk', '3/2', 'cup', 'base'], ['egg', '1', 'each', 'base']], 1,
8],
[['pepper', '4 3/4', 'tsp'], ['milk', '12', 'cup'], ['egg', '8', 'each']]],
['generated control 3',
[[['egg', '1', 'each', 'base'], ['flour', '1/8', 'cup', 'base'], ['pepper', '3/4', 'tsp', 'seasoning'],
['salt', '1', 'tsp', 'seasoning']],
6, 12],
[['egg', '2', 'each'], ['flour', '1/4', 'cup'], ['pepper', '1 3/8', 'tsp'], ['salt', '1 3/4', 'tsp']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: kitchen fraction reduction',
[[['butter', '2/3', 'tbsp', 'base'], ['flour', '2/3', 'cup', 'base'],
['pepper', '3/2', 'tsp', 'seasoning'], ['salt', '1/4', 'tsp', 'seasoning'],
['lime', '4', 'each', 'base']],
7, 3],
[['butter', '1/4', 'tbsp'], ['flour', '1/4', 'cup'], ['pepper', '7/8', 'tsp'], ['salt', '1/8', 'tsp'],
['lime', '2', 'each']]],
['repair check: kitchen fraction reduction',
[[['egg', '2', 'each', 'base'], ['garlic clove', '2', 'each', 'base'], ['butter', '3/4', 'tbsp', 'base'],
['lime', '4', 'each', 'base'], ['cumin', '1/8', 'tsp', 'seasoning']],
2, 12],
[['egg', '12', 'each'], ['garlic clove', '12', 'each'], ['butter', '4 1/2', 'tbsp'],
['lime', '24', 'each'], ['cumin', '5/8', 'tsp']]],
['generated control 1', [[['flour', '2/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 3, 8],
[['flour', '1 3/4', 'cup'], ['garlic clove', '8', 'each']]],
['generated control 2',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '3', 'each', 'base'],
['cumin', '1/4', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base'], ['butter', '1', 'tbsp', 'base']],
5, 1],
[['egg', '1', 'each'], ['garlic clove', '1', 'each'], ['cumin', '1/8', 'tsp'], ['lime', '1', 'each'],
['butter', '1/4', 'tbsp']]],
['generated control 3',
[[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning'], ['milk', '9/4', 'cup', 'base'],
['flour', '9/4', 'cup', 'base']],
6, 7],
[['egg', '2', 'each'], ['pepper', '3/4', 'tsp'], ['milk', '2 5/8', 'cup'], ['flour', '2 5/8', 'cup']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: kitchen fraction reduction',
[[['egg', '1', 'each', 'base'], ['pepper', '1/4', 'tsp', 'seasoning']], 7, 8],
[['egg', '1', 'each'], ['pepper', '1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '2/3', 'cup', 'base'], ['pepper', '1', 'tsp', 'seasoning'],
['garlic clove', '4', 'each', 'base'], ['salt', '2', 'tsp', 'seasoning']],
3, 11],
[['flour', '2 1/2', 'cup'], ['pepper', '3', 'tsp'], ['garlic clove', '15', 'each'], ['salt', '6', 'tsp']]],
['generated control 1', [[['garlic clove', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 1, 4],
[['garlic clove', '2', 'each'], ['flour', '6', 'cup']]],
['generated control 2',
[[['flour', '1', 'cup', 'base'], ['butter', '1/8', 'tbsp', 'base'], ['egg', '3', 'each', 'base']], 7, 7],
[['flour', '1', 'cup'], ['butter', '1/8', 'tbsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '2', 'each', 'base'], ['milk', '1/2', 'cup', 'base'],
['egg', '2', 'each', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']],
4, 4],
[['salt', '5/8', 'tsp'], ['lime', '2', 'each'], ['milk', '1/2', 'cup'], ['egg', '2', 'each'],
['cumin', '2 1/2', 'tsp']]]]]
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 |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 4/8', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Failed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 6/8', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Failed |
| regression: kitchen fraction reduction | [['pepper', '7/8', 'tsp'], ['salt', '6/8', 'tsp']] | [['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']] | Failed |
| repair check: kitchen fraction reduction | [['milk', '1 4/8', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | [['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | Failed |
| generated control 1 | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | Passed |
| generated control 2 | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | Passed |
| generated control 3 | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | Passed |
SHA-256 / 652f9cb6a5fa9d1f5289f3e2fa1f49fe2706c2f77263bb6d712be49aa9ea12f3
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(items, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = 2 if rem % 2 == 0 else 1
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(max(1, n)), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: kitchen fraction reduction',
[[['pepper', '5/2', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning']], 8, 1],
[['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['milk', '3/4', 'cup', 'base'], ['garlic clove', '3', 'each', 'base'], ['lime', '2', 'each', 'base'],
['egg', '4', 'each', 'base']],
3, 6],
[['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']]],
['generated control 1',
[[['milk', '1', 'cup', 'base'], ['butter', '5/2', 'tbsp', 'base'], ['pepper', '1/4', 'tsp', 'seasoning'],
['cumin', '1/4', 'tsp', 'seasoning']],
3, 12],
[['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']]],
['generated control 2', [[['salt', '3/4', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 7, 8],
[['salt', '7/8', 'tsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['pepper', '1', 'tsp', 'seasoning'], ['garlic clove', '5', 'each', 'base'], ['egg', '4', 'each', 'base'],
['salt', '3/4', 'tsp', 'seasoning']],
2, 3],
[['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: kitchen fraction reduction',
[[['salt', '1/2', 'tsp', 'seasoning'], ['garlic clove', '1/2', 'each', 'base']], 2, 11],
[['salt', '2 1/4', 'tsp'], ['garlic clove', '3', 'each']]],
['repair check: kitchen fraction reduction',
[[['cumin', '3/2', 'tsp', 'seasoning'], ['salt', '5/2', 'tsp', 'seasoning'],
['flour', '3/4', 'cup', 'base'], ['garlic clove', '4', 'each', 'base'],
['butter', '3/2', 'tbsp', 'base']],
2, 10],
[['cumin', '6', 'tsp'], ['salt', '10', 'tsp'], ['flour', '3 3/4', 'cup'], ['garlic clove', '20', 'each'],
['butter', '7 1/2', 'tbsp']]],
['generated control 1',
[[['butter', '2', 'tbsp', 'base'], ['pepper', '5/2', 'tsp', 'seasoning'], ['milk', '1/2', 'cup', 'base']],
5, 8],
[['butter', '3 1/4', 'tbsp'], ['pepper', '3 5/8', 'tsp'], ['milk', '3/4', 'cup']]],
['generated control 2',
[[['pepper', '1/4', 'tsp', 'seasoning'], ['cumin', '3', 'tsp', 'seasoning'],
['butter', '9/4', 'tbsp', 'base'], ['lime', '4', 'each', 'base']],
5, 2],
[['pepper', '1/8', 'tsp'], ['cumin', '1 5/8', 'tsp'], ['butter', '7/8', 'tbsp'], ['lime', '2', 'each']]],
['generated control 3',
[[['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '2/3', 'tbsp', 'base'], ['egg', '4', 'each', 'base'],
['milk', '1/3', 'cup', 'base']],
6, 1],
[['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['egg', '1', 'each'], ['milk', 'pinch', 'cup']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: kitchen fraction reduction',
[[['pepper', '2/3', 'tsp', 'seasoning'], ['salt', '3/4', 'tsp', 'seasoning']], 6, 11],
[['pepper', '1 1/8', 'tsp'], ['salt', '1 1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '5/2', 'cup', 'base'], ['milk', '3/4', 'cup', 'base'], ['lime', '2', 'each', 'base'],
['cumin', '3/2', 'tsp', 'seasoning']],
5, 3],
[['flour', '1 1/2', 'cup'], ['milk', '1/2', 'cup'], ['lime', '1', 'each'], ['cumin', '1', 'tsp']]],
['generated control 1', [[['butter', '2', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 1, 4],
[['butter', '8', 'tbsp'], ['pepper', '4 7/8', 'tsp']]],
['generated control 2',
[[['pepper', '3/4', 'tsp', 'seasoning'], ['milk', '3/2', 'cup', 'base'], ['egg', '1', 'each', 'base']], 1,
8],
[['pepper', '4 3/4', 'tsp'], ['milk', '12', 'cup'], ['egg', '8', 'each']]],
['generated control 3',
[[['egg', '1', 'each', 'base'], ['flour', '1/8', 'cup', 'base'], ['pepper', '3/4', 'tsp', 'seasoning'],
['salt', '1', 'tsp', 'seasoning']],
6, 12],
[['egg', '2', 'each'], ['flour', '1/4', 'cup'], ['pepper', '1 3/8', 'tsp'], ['salt', '1 3/4', 'tsp']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: kitchen fraction reduction',
[[['butter', '2/3', 'tbsp', 'base'], ['flour', '2/3', 'cup', 'base'],
['pepper', '3/2', 'tsp', 'seasoning'], ['salt', '1/4', 'tsp', 'seasoning'],
['lime', '4', 'each', 'base']],
7, 3],
[['butter', '1/4', 'tbsp'], ['flour', '1/4', 'cup'], ['pepper', '7/8', 'tsp'], ['salt', '1/8', 'tsp'],
['lime', '2', 'each']]],
['repair check: kitchen fraction reduction',
[[['egg', '2', 'each', 'base'], ['garlic clove', '2', 'each', 'base'], ['butter', '3/4', 'tbsp', 'base'],
['lime', '4', 'each', 'base'], ['cumin', '1/8', 'tsp', 'seasoning']],
2, 12],
[['egg', '12', 'each'], ['garlic clove', '12', 'each'], ['butter', '4 1/2', 'tbsp'],
['lime', '24', 'each'], ['cumin', '5/8', 'tsp']]],
['generated control 1', [[['flour', '2/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 3, 8],
[['flour', '1 3/4', 'cup'], ['garlic clove', '8', 'each']]],
['generated control 2',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '3', 'each', 'base'],
['cumin', '1/4', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base'], ['butter', '1', 'tbsp', 'base']],
5, 1],
[['egg', '1', 'each'], ['garlic clove', '1', 'each'], ['cumin', '1/8', 'tsp'], ['lime', '1', 'each'],
['butter', '1/4', 'tbsp']]],
['generated control 3',
[[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning'], ['milk', '9/4', 'cup', 'base'],
['flour', '9/4', 'cup', 'base']],
6, 7],
[['egg', '2', 'each'], ['pepper', '3/4', 'tsp'], ['milk', '2 5/8', 'cup'], ['flour', '2 5/8', 'cup']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: kitchen fraction reduction',
[[['egg', '1', 'each', 'base'], ['pepper', '1/4', 'tsp', 'seasoning']], 7, 8],
[['egg', '1', 'each'], ['pepper', '1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '2/3', 'cup', 'base'], ['pepper', '1', 'tsp', 'seasoning'],
['garlic clove', '4', 'each', 'base'], ['salt', '2', 'tsp', 'seasoning']],
3, 11],
[['flour', '2 1/2', 'cup'], ['pepper', '3', 'tsp'], ['garlic clove', '15', 'each'], ['salt', '6', 'tsp']]],
['generated control 1', [[['garlic clove', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 1, 4],
[['garlic clove', '2', 'each'], ['flour', '6', 'cup']]],
['generated control 2',
[[['flour', '1', 'cup', 'base'], ['butter', '1/8', 'tbsp', 'base'], ['egg', '3', 'each', 'base']], 7, 7],
[['flour', '1', 'cup'], ['butter', '1/8', 'tbsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '2', 'each', 'base'], ['milk', '1/2', 'cup', 'base'],
['egg', '2', 'each', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']],
4, 4],
[['salt', '5/8', 'tsp'], ['lime', '2', 'each'], ['milk', '1/2', 'cup'], ['egg', '2', 'each'],
['cumin', '2 1/2', 'tsp']]]]]
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 |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 2/4', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Failed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Passed |
| regression: kitchen fraction reduction | [['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']] | [['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']] | Passed |
| repair check: kitchen fraction reduction | [['milk', '1 2/4', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | [['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | Failed |
| generated control 1 | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | Passed |
| generated control 2 | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | Passed |
| generated control 3 | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | Passed |
SHA-256 / 3687cf07513fcee948516d4e9c49391c86a25762f803a0e42dea9b32dedc9a56
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(items, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = math.gcd(rem, 8)
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(max(1, n)), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: kitchen fraction reduction',
[[['pepper', '5/2', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning']], 8, 1],
[['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['milk', '3/4', 'cup', 'base'], ['garlic clove', '3', 'each', 'base'], ['lime', '2', 'each', 'base'],
['egg', '4', 'each', 'base']],
3, 6],
[['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']]],
['generated control 1',
[[['milk', '1', 'cup', 'base'], ['butter', '5/2', 'tbsp', 'base'], ['pepper', '1/4', 'tsp', 'seasoning'],
['cumin', '1/4', 'tsp', 'seasoning']],
3, 12],
[['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']]],
['generated control 2', [[['salt', '3/4', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 7, 8],
[['salt', '7/8', 'tsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['pepper', '1', 'tsp', 'seasoning'], ['garlic clove', '5', 'each', 'base'], ['egg', '4', 'each', 'base'],
['salt', '3/4', 'tsp', 'seasoning']],
2, 3],
[['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: kitchen fraction reduction',
[[['salt', '1/2', 'tsp', 'seasoning'], ['garlic clove', '1/2', 'each', 'base']], 2, 11],
[['salt', '2 1/4', 'tsp'], ['garlic clove', '3', 'each']]],
['repair check: kitchen fraction reduction',
[[['cumin', '3/2', 'tsp', 'seasoning'], ['salt', '5/2', 'tsp', 'seasoning'],
['flour', '3/4', 'cup', 'base'], ['garlic clove', '4', 'each', 'base'],
['butter', '3/2', 'tbsp', 'base']],
2, 10],
[['cumin', '6', 'tsp'], ['salt', '10', 'tsp'], ['flour', '3 3/4', 'cup'], ['garlic clove', '20', 'each'],
['butter', '7 1/2', 'tbsp']]],
['generated control 1',
[[['butter', '2', 'tbsp', 'base'], ['pepper', '5/2', 'tsp', 'seasoning'], ['milk', '1/2', 'cup', 'base']],
5, 8],
[['butter', '3 1/4', 'tbsp'], ['pepper', '3 5/8', 'tsp'], ['milk', '3/4', 'cup']]],
['generated control 2',
[[['pepper', '1/4', 'tsp', 'seasoning'], ['cumin', '3', 'tsp', 'seasoning'],
['butter', '9/4', 'tbsp', 'base'], ['lime', '4', 'each', 'base']],
5, 2],
[['pepper', '1/8', 'tsp'], ['cumin', '1 5/8', 'tsp'], ['butter', '7/8', 'tbsp'], ['lime', '2', 'each']]],
['generated control 3',
[[['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '2/3', 'tbsp', 'base'], ['egg', '4', 'each', 'base'],
['milk', '1/3', 'cup', 'base']],
6, 1],
[['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['egg', '1', 'each'], ['milk', 'pinch', 'cup']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: kitchen fraction reduction',
[[['pepper', '2/3', 'tsp', 'seasoning'], ['salt', '3/4', 'tsp', 'seasoning']], 6, 11],
[['pepper', '1 1/8', 'tsp'], ['salt', '1 1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '5/2', 'cup', 'base'], ['milk', '3/4', 'cup', 'base'], ['lime', '2', 'each', 'base'],
['cumin', '3/2', 'tsp', 'seasoning']],
5, 3],
[['flour', '1 1/2', 'cup'], ['milk', '1/2', 'cup'], ['lime', '1', 'each'], ['cumin', '1', 'tsp']]],
['generated control 1', [[['butter', '2', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 1, 4],
[['butter', '8', 'tbsp'], ['pepper', '4 7/8', 'tsp']]],
['generated control 2',
[[['pepper', '3/4', 'tsp', 'seasoning'], ['milk', '3/2', 'cup', 'base'], ['egg', '1', 'each', 'base']], 1,
8],
[['pepper', '4 3/4', 'tsp'], ['milk', '12', 'cup'], ['egg', '8', 'each']]],
['generated control 3',
[[['egg', '1', 'each', 'base'], ['flour', '1/8', 'cup', 'base'], ['pepper', '3/4', 'tsp', 'seasoning'],
['salt', '1', 'tsp', 'seasoning']],
6, 12],
[['egg', '2', 'each'], ['flour', '1/4', 'cup'], ['pepper', '1 3/8', 'tsp'], ['salt', '1 3/4', 'tsp']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: kitchen fraction reduction',
[[['butter', '2/3', 'tbsp', 'base'], ['flour', '2/3', 'cup', 'base'],
['pepper', '3/2', 'tsp', 'seasoning'], ['salt', '1/4', 'tsp', 'seasoning'],
['lime', '4', 'each', 'base']],
7, 3],
[['butter', '1/4', 'tbsp'], ['flour', '1/4', 'cup'], ['pepper', '7/8', 'tsp'], ['salt', '1/8', 'tsp'],
['lime', '2', 'each']]],
['repair check: kitchen fraction reduction',
[[['egg', '2', 'each', 'base'], ['garlic clove', '2', 'each', 'base'], ['butter', '3/4', 'tbsp', 'base'],
['lime', '4', 'each', 'base'], ['cumin', '1/8', 'tsp', 'seasoning']],
2, 12],
[['egg', '12', 'each'], ['garlic clove', '12', 'each'], ['butter', '4 1/2', 'tbsp'],
['lime', '24', 'each'], ['cumin', '5/8', 'tsp']]],
['generated control 1', [[['flour', '2/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 3, 8],
[['flour', '1 3/4', 'cup'], ['garlic clove', '8', 'each']]],
['generated control 2',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '3', 'each', 'base'],
['cumin', '1/4', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base'], ['butter', '1', 'tbsp', 'base']],
5, 1],
[['egg', '1', 'each'], ['garlic clove', '1', 'each'], ['cumin', '1/8', 'tsp'], ['lime', '1', 'each'],
['butter', '1/4', 'tbsp']]],
['generated control 3',
[[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning'], ['milk', '9/4', 'cup', 'base'],
['flour', '9/4', 'cup', 'base']],
6, 7],
[['egg', '2', 'each'], ['pepper', '3/4', 'tsp'], ['milk', '2 5/8', 'cup'], ['flour', '2 5/8', 'cup']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: kitchen fraction reduction',
[[['egg', '1', 'each', 'base'], ['pepper', '1/4', 'tsp', 'seasoning']], 7, 8],
[['egg', '1', 'each'], ['pepper', '1/4', 'tsp']]],
['repair check: kitchen fraction reduction',
[[['flour', '2/3', 'cup', 'base'], ['pepper', '1', 'tsp', 'seasoning'],
['garlic clove', '4', 'each', 'base'], ['salt', '2', 'tsp', 'seasoning']],
3, 11],
[['flour', '2 1/2', 'cup'], ['pepper', '3', 'tsp'], ['garlic clove', '15', 'each'], ['salt', '6', 'tsp']]],
['generated control 1', [[['garlic clove', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 1, 4],
[['garlic clove', '2', 'each'], ['flour', '6', 'cup']]],
['generated control 2',
[[['flour', '1', 'cup', 'base'], ['butter', '1/8', 'tbsp', 'base'], ['egg', '3', 'each', 'base']], 7, 7],
[['flour', '1', 'cup'], ['butter', '1/8', 'tbsp'], ['egg', '3', 'each']]],
['generated control 3',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '2', 'each', 'base'], ['milk', '1/2', 'cup', 'base'],
['egg', '2', 'each', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']],
4, 4],
[['salt', '5/8', 'tsp'], ['lime', '2', 'each'], ['milk', '1/2', 'cup'], ['egg', '2', 'each'],
['cumin', '2 1/2', 'tsp']]]]]
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 |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Passed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Passed |
| regression: kitchen fraction reduction | [['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']] | [['pepper', '7/8', 'tsp'], ['salt', '3/4', 'tsp']] | Passed |
| repair check: kitchen fraction reduction | [['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | [['milk', '1 1/2', 'cup'], ['garlic clove', '6', 'each'], ['lime', '4', 'each'], ['egg', '8', 'each']] | Passed |
| generated control 1 | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | [['milk', '4', 'cup'], ['butter', '10', 'tbsp'], ['pepper', '7/8', 'tsp'], ['cumin', '7/8', 'tsp']] | Passed |
| generated control 2 | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | [['salt', '7/8', 'tsp'], ['egg', '3', 'each']] | Passed |
| generated control 3 | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | [['pepper', '1 3/8', 'tsp'], ['garlic clove', '8', 'each'], ['egg', '6', 'each'], ['salt', '1', 'tsp']] | Passed |
SHA-256 / 510e58a5def619b96c87c9c3ca6749674efbae9bcfa209f9880f012e06a201b6
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:26.621365+00:00.
Case digest / 382e5876be1a4f8d640c5e0f199d7a697ba9dfe58a9f0b2955aad40e240eec38