FAILURE MAP
← Case archive

FA-96841 / Recipe scaling and nutrition / Open access

Servings scaler: scale factor direction · case 01

Scaling a recipe from 4 to 8 servings halves every ingredient instead of doubling it.

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

ROOT CAUSE

The multiplier is built as base/target, so every row moves in the opposite direction of the requested change.

VERIFIED REPAIR

Build the multiplier as target/base.

Unsuccessful approach: Taking the larger over the smaller servings count only fixes scale-ups; scaling down still enlarges the batch.

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(base, target)
    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: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['pepper', '1/2', 'tsp', 'seasoning'], ['lime', '5', 'each', 'base'],
     ['garlic clove', '2', 'each', 'base']],
    1, 4],
   [['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]],
  ['repair check: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['lime', '4', 'each', 'base']], 5, 2],
   [['milk', '7/8', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['salt', '1/2', 'tsp', 'seasoning'], ['butter', '3/4', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 10],
   [['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]],
  ['generated control 2', [[['butter', '1/4', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 8, 12],
   [['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]],
  ['generated control 3', [[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning']], 3, 8],
   [['egg', '5', 'each'], ['pepper', '1 1/2', '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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 5, 7],
   [['flour', '1/2', 'cup'], ['garlic clove', '4', 'each']]],
  ['repair check: scale factor direction',
   [[['cumin', '3/4', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning'],
     ['garlic clove', '1/2', 'each', 'base'], ['milk', '3/2', 'cup', 'base']],
    7, 1],
   [['cumin', '1/4', 'tsp'], ['salt', '3/4', 'tsp'], ['garlic clove', '1', 'each'], ['milk', '1/4', 'cup']]],
  ['generated control 1', [[['cumin', '2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning']], 2, 4],
   [['cumin', '3 1/2', 'tsp'], ['pepper', '5 1/4', 'tsp']]],
  ['generated control 2',
   [[['egg', '4', 'each', 'base'], ['garlic clove', '3', 'each', 'base'], ['milk', '5/2', 'cup', 'base'],
     ['cumin', '2/3', 'tsp', 'seasoning']],
    8, 10],
   [['egg', '5', 'each'], ['garlic clove', '4', 'each'], ['milk', '3 1/8', 'cup'], ['cumin', '3/4', 'tsp']]],
  ['generated control 3',
   [[['butter', '1/4', 'tbsp', 'base'], ['cumin', '3/4', 'tsp', 'seasoning'],
     ['pepper', '1/2', 'tsp', 'seasoning']],
    7, 6],
   [['butter', '1/4', 'tbsp'], ['cumin', '5/8', 'tsp'], ['pepper', '1/2', 'tsp']]]],
 [['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: scale factor direction',
   [[['milk', '3/2', 'cup', 'base'], ['flour', '1/3', 'cup', 'base'], ['salt', '1/2', 'tsp', 'seasoning'],
     ['cumin', '9/4', 'tsp', 'seasoning']],
    5, 10],
   [['milk', '3', 'cup'], ['flour', '5/8', 'cup'], ['salt', '7/8', 'tsp'], ['cumin', '4', 'tsp']]],
  ['repair check: scale factor direction',
   [[['egg', '1', 'each', 'base'], ['milk', '1', 'cup', 'base'], ['lime', '3', 'each', 'base']], 7, 5],
   [['egg', '1', 'each'], ['milk', '3/4', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['lime', '3', 'each', 'base'], ['salt', '2/3', 'tsp', 'seasoning'],
     ['pepper', '5/2', 'tsp', 'seasoning']],
    7, 11],
   [['lime', '5', 'each'], ['salt', '1', 'tsp'], ['pepper', '3 5/8', 'tsp']]],
  ['generated control 2',
   [[['lime', '1/2', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    2, 4],
   [['lime', '1', 'each'], ['flour', '5/8', 'cup'], ['butter', '3', 'tbsp'], ['garlic clove', '10', 'each']]],
  ['generated control 3',
   [[['salt', '9/4', 'tsp', 'seasoning'], ['pepper', '3/4', 'tsp', 'seasoning']], 7, 10],
   [['salt', '3', 'tsp'], ['pepper', '1', '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: scale factor direction',
   [[['egg', '3', 'each', 'base'], ['butter', '1', 'tbsp', 'base'], ['garlic clove', '2', 'each', 'base'],
     ['cumin', '1/4', 'tsp', 'seasoning'], ['milk', '1', 'cup', 'base']],
    3, 7],
   [['egg', '7', 'each'], ['butter', '2 3/8', 'tbsp'], ['garlic clove', '5', 'each'], ['cumin', '1/2', 'tsp'],
    ['milk', '2 3/8', 'cup']]],
  ['repair check: scale factor direction',
   [[['pepper', '3', 'tsp', 'seasoning'], ['flour', '3/4', 'cup', 'base'], ['butter', '1/3', 'tbsp', 'base'],
     ['milk', '1/4', 'cup', 'base']],
    7, 1],
   [['pepper', '1 1/8', 'tsp'], ['flour', '1/8', 'cup'], ['butter', 'pinch', 'tbsp'],
    ['milk', 'pinch', 'cup']]],
  ['generated control 1',
   [[['butter', '9/4', 'tbsp', 'base'], ['egg', '2', 'each', 'base'], ['pepper', '3/2', 'tsp', 'seasoning'],
     ['salt', '1/3', 'tsp', 'seasoning']],
    4, 8],
   [['butter', '4 1/2', 'tbsp'], ['egg', '4', 'each'], ['pepper', '2 5/8', 'tsp'], ['salt', '5/8', 'tsp']]],
  ['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']], 3, 9],
   [['butter', '7 1/2', 'tbsp'], ['cumin', '6 1/4', 'tsp']]],
  ['generated control 3',
   [[['salt', '3/2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning'],
     ['garlic clove', '4', 'each', 'base'], ['flour', '1/8', 'cup', 'base']],
    4, 5],
   [['salt', '1 3/4', 'tsp'], ['pepper', '3 5/8', 'tsp'], ['garlic clove', '5', 'each'],
    ['flour', '1/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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['lime', '1', 'each', 'base'], ['butter', '1', 'tbsp', 'base']], 4, 3],
   [['flour', '1/4', 'cup'], ['lime', '1', 'each'], ['butter', '3/4', 'tbsp']]],
  ['repair check: scale factor direction',
   [[['flour', '5/2', 'cup', 'base'], ['milk', '2', 'cup', 'base'], ['salt', '1', 'tsp', 'seasoning']], 4, 1],
   [['flour', '5/8', 'cup'], ['milk', '1/2', 'cup'], ['salt', '1/2', 'tsp']]],
  ['generated control 1', [[['butter', '3/2', 'tbsp', 'base'], ['pepper', '2', 'tsp', 'seasoning']], 2, 11],
   [['butter', '8 1/4', 'tbsp'], ['pepper', '8 3/4', 'tsp']]],
  ['generated control 2',
   [[['salt', '1/3', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 9],
   [['salt', '3/8', 'tsp'], ['milk', '3 1/4', 'cup'], ['garlic clove', '6', 'each']]],
  ['generated control 3',
   [[['cumin', '1/3', 'tsp', 'seasoning'], ['garlic clove', '3', 'each', 'base'],
     ['pepper', '3/4', 'tsp', 'seasoning'], ['flour', '2/3', 'cup', 'base']],
    4, 2],
   [['cumin', '1/4', 'tsp'], ['garlic clove', '2', 'each'], ['pepper', '1/2', 'tsp'],
    ['flour', '3/8', 'cup']]]]]
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
identity scaling control[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']][['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]Passed
zero servings rejectederror: servings must be positiveerror: servings must be positivePassed
double batch with seasoning[['salt', '5/8', 'tsp'], ['egg', '2', 'each']][['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]Failed
regression: scale factor direction[['milk', '5/8', 'cup'], ['pepper', '1/4', 'tsp'], ['lime', '1', 'each'], ['garlic clove', '1', 'each']][['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]Failed
repair check: scale factor direction[['milk', '5 5/8', 'cup'], ['lime', '10', 'each']][['milk', '7/8', 'cup'], ['lime', '2', 'each']]Failed
generated control 1[['salt', '3/8', 'tsp'], ['butter', '1/2', 'tbsp'], ['garlic clove', '4', 'each']][['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]Failed
generated control 2[['butter', '1/8', 'tbsp'], ['pepper', '1 1/8', 'tsp']][['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]Failed
generated control 3[['egg', '1', 'each'], ['pepper', '3/8', 'tsp']][['egg', '5', 'each'], ['pepper', '1 1/2', 'tsp']]Failed

SHA-256 / bb29f07a3d6e4914dfdc1b2aa75ae34ec255dde03592184ca8b0e657ca5652ea

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(max(base, target), min(base, target))
    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: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['pepper', '1/2', 'tsp', 'seasoning'], ['lime', '5', 'each', 'base'],
     ['garlic clove', '2', 'each', 'base']],
    1, 4],
   [['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]],
  ['repair check: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['lime', '4', 'each', 'base']], 5, 2],
   [['milk', '7/8', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['salt', '1/2', 'tsp', 'seasoning'], ['butter', '3/4', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 10],
   [['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]],
  ['generated control 2', [[['butter', '1/4', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 8, 12],
   [['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]],
  ['generated control 3', [[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning']], 3, 8],
   [['egg', '5', 'each'], ['pepper', '1 1/2', '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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 5, 7],
   [['flour', '1/2', 'cup'], ['garlic clove', '4', 'each']]],
  ['repair check: scale factor direction',
   [[['cumin', '3/4', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning'],
     ['garlic clove', '1/2', 'each', 'base'], ['milk', '3/2', 'cup', 'base']],
    7, 1],
   [['cumin', '1/4', 'tsp'], ['salt', '3/4', 'tsp'], ['garlic clove', '1', 'each'], ['milk', '1/4', 'cup']]],
  ['generated control 1', [[['cumin', '2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning']], 2, 4],
   [['cumin', '3 1/2', 'tsp'], ['pepper', '5 1/4', 'tsp']]],
  ['generated control 2',
   [[['egg', '4', 'each', 'base'], ['garlic clove', '3', 'each', 'base'], ['milk', '5/2', 'cup', 'base'],
     ['cumin', '2/3', 'tsp', 'seasoning']],
    8, 10],
   [['egg', '5', 'each'], ['garlic clove', '4', 'each'], ['milk', '3 1/8', 'cup'], ['cumin', '3/4', 'tsp']]],
  ['generated control 3',
   [[['butter', '1/4', 'tbsp', 'base'], ['cumin', '3/4', 'tsp', 'seasoning'],
     ['pepper', '1/2', 'tsp', 'seasoning']],
    7, 6],
   [['butter', '1/4', 'tbsp'], ['cumin', '5/8', 'tsp'], ['pepper', '1/2', 'tsp']]]],
 [['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: scale factor direction',
   [[['milk', '3/2', 'cup', 'base'], ['flour', '1/3', 'cup', 'base'], ['salt', '1/2', 'tsp', 'seasoning'],
     ['cumin', '9/4', 'tsp', 'seasoning']],
    5, 10],
   [['milk', '3', 'cup'], ['flour', '5/8', 'cup'], ['salt', '7/8', 'tsp'], ['cumin', '4', 'tsp']]],
  ['repair check: scale factor direction',
   [[['egg', '1', 'each', 'base'], ['milk', '1', 'cup', 'base'], ['lime', '3', 'each', 'base']], 7, 5],
   [['egg', '1', 'each'], ['milk', '3/4', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['lime', '3', 'each', 'base'], ['salt', '2/3', 'tsp', 'seasoning'],
     ['pepper', '5/2', 'tsp', 'seasoning']],
    7, 11],
   [['lime', '5', 'each'], ['salt', '1', 'tsp'], ['pepper', '3 5/8', 'tsp']]],
  ['generated control 2',
   [[['lime', '1/2', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    2, 4],
   [['lime', '1', 'each'], ['flour', '5/8', 'cup'], ['butter', '3', 'tbsp'], ['garlic clove', '10', 'each']]],
  ['generated control 3',
   [[['salt', '9/4', 'tsp', 'seasoning'], ['pepper', '3/4', 'tsp', 'seasoning']], 7, 10],
   [['salt', '3', 'tsp'], ['pepper', '1', '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: scale factor direction',
   [[['egg', '3', 'each', 'base'], ['butter', '1', 'tbsp', 'base'], ['garlic clove', '2', 'each', 'base'],
     ['cumin', '1/4', 'tsp', 'seasoning'], ['milk', '1', 'cup', 'base']],
    3, 7],
   [['egg', '7', 'each'], ['butter', '2 3/8', 'tbsp'], ['garlic clove', '5', 'each'], ['cumin', '1/2', 'tsp'],
    ['milk', '2 3/8', 'cup']]],
  ['repair check: scale factor direction',
   [[['pepper', '3', 'tsp', 'seasoning'], ['flour', '3/4', 'cup', 'base'], ['butter', '1/3', 'tbsp', 'base'],
     ['milk', '1/4', 'cup', 'base']],
    7, 1],
   [['pepper', '1 1/8', 'tsp'], ['flour', '1/8', 'cup'], ['butter', 'pinch', 'tbsp'],
    ['milk', 'pinch', 'cup']]],
  ['generated control 1',
   [[['butter', '9/4', 'tbsp', 'base'], ['egg', '2', 'each', 'base'], ['pepper', '3/2', 'tsp', 'seasoning'],
     ['salt', '1/3', 'tsp', 'seasoning']],
    4, 8],
   [['butter', '4 1/2', 'tbsp'], ['egg', '4', 'each'], ['pepper', '2 5/8', 'tsp'], ['salt', '5/8', 'tsp']]],
  ['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']], 3, 9],
   [['butter', '7 1/2', 'tbsp'], ['cumin', '6 1/4', 'tsp']]],
  ['generated control 3',
   [[['salt', '3/2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning'],
     ['garlic clove', '4', 'each', 'base'], ['flour', '1/8', 'cup', 'base']],
    4, 5],
   [['salt', '1 3/4', 'tsp'], ['pepper', '3 5/8', 'tsp'], ['garlic clove', '5', 'each'],
    ['flour', '1/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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['lime', '1', 'each', 'base'], ['butter', '1', 'tbsp', 'base']], 4, 3],
   [['flour', '1/4', 'cup'], ['lime', '1', 'each'], ['butter', '3/4', 'tbsp']]],
  ['repair check: scale factor direction',
   [[['flour', '5/2', 'cup', 'base'], ['milk', '2', 'cup', 'base'], ['salt', '1', 'tsp', 'seasoning']], 4, 1],
   [['flour', '5/8', 'cup'], ['milk', '1/2', 'cup'], ['salt', '1/2', 'tsp']]],
  ['generated control 1', [[['butter', '3/2', 'tbsp', 'base'], ['pepper', '2', 'tsp', 'seasoning']], 2, 11],
   [['butter', '8 1/4', 'tbsp'], ['pepper', '8 3/4', 'tsp']]],
  ['generated control 2',
   [[['salt', '1/3', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 9],
   [['salt', '3/8', 'tsp'], ['milk', '3 1/4', 'cup'], ['garlic clove', '6', 'each']]],
  ['generated control 3',
   [[['cumin', '1/3', 'tsp', 'seasoning'], ['garlic clove', '3', 'each', 'base'],
     ['pepper', '3/4', 'tsp', 'seasoning'], ['flour', '2/3', 'cup', 'base']],
    4, 2],
   [['cumin', '1/4', 'tsp'], ['garlic clove', '2', 'each'], ['pepper', '1/2', 'tsp'],
    ['flour', '3/8', 'cup']]]]]
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
identity scaling control[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']][['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]Passed
zero servings rejectederror: servings must be positiveerror: servings must be positivePassed
double batch with seasoning[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']][['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]Passed
regression: scale factor direction[['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']][['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]Passed
repair check: scale factor direction[['milk', '5 5/8', 'cup'], ['lime', '10', 'each']][['milk', '7/8', 'cup'], ['lime', '2', 'each']]Failed
generated control 1[['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']][['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]Passed
generated control 2[['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']][['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]Passed
generated control 3[['egg', '5', 'each'], ['pepper', '1 1/2', 'tsp']][['egg', '5', 'each'], ['pepper', '1 1/2', 'tsp']]Passed

SHA-256 / e1b8ef5e1d543a24b7e50aee4e910f79acad52874ea124d9050ecdf214fa5169

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: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['pepper', '1/2', 'tsp', 'seasoning'], ['lime', '5', 'each', 'base'],
     ['garlic clove', '2', 'each', 'base']],
    1, 4],
   [['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]],
  ['repair check: scale factor direction',
   [[['milk', '9/4', 'cup', 'base'], ['lime', '4', 'each', 'base']], 5, 2],
   [['milk', '7/8', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['salt', '1/2', 'tsp', 'seasoning'], ['butter', '3/4', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 10],
   [['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]],
  ['generated control 2', [[['butter', '1/4', 'tbsp', 'base'], ['pepper', '3/2', 'tsp', 'seasoning']], 8, 12],
   [['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]],
  ['generated control 3', [[['egg', '2', 'each', 'base'], ['pepper', '2/3', 'tsp', 'seasoning']], 3, 8],
   [['egg', '5', 'each'], ['pepper', '1 1/2', '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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['garlic clove', '3', 'each', 'base']], 5, 7],
   [['flour', '1/2', 'cup'], ['garlic clove', '4', 'each']]],
  ['repair check: scale factor direction',
   [[['cumin', '3/4', 'tsp', 'seasoning'], ['salt', '2', 'tsp', 'seasoning'],
     ['garlic clove', '1/2', 'each', 'base'], ['milk', '3/2', 'cup', 'base']],
    7, 1],
   [['cumin', '1/4', 'tsp'], ['salt', '3/4', 'tsp'], ['garlic clove', '1', 'each'], ['milk', '1/4', 'cup']]],
  ['generated control 1', [[['cumin', '2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning']], 2, 4],
   [['cumin', '3 1/2', 'tsp'], ['pepper', '5 1/4', 'tsp']]],
  ['generated control 2',
   [[['egg', '4', 'each', 'base'], ['garlic clove', '3', 'each', 'base'], ['milk', '5/2', 'cup', 'base'],
     ['cumin', '2/3', 'tsp', 'seasoning']],
    8, 10],
   [['egg', '5', 'each'], ['garlic clove', '4', 'each'], ['milk', '3 1/8', 'cup'], ['cumin', '3/4', 'tsp']]],
  ['generated control 3',
   [[['butter', '1/4', 'tbsp', 'base'], ['cumin', '3/4', 'tsp', 'seasoning'],
     ['pepper', '1/2', 'tsp', 'seasoning']],
    7, 6],
   [['butter', '1/4', 'tbsp'], ['cumin', '5/8', 'tsp'], ['pepper', '1/2', 'tsp']]]],
 [['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: scale factor direction',
   [[['milk', '3/2', 'cup', 'base'], ['flour', '1/3', 'cup', 'base'], ['salt', '1/2', 'tsp', 'seasoning'],
     ['cumin', '9/4', 'tsp', 'seasoning']],
    5, 10],
   [['milk', '3', 'cup'], ['flour', '5/8', 'cup'], ['salt', '7/8', 'tsp'], ['cumin', '4', 'tsp']]],
  ['repair check: scale factor direction',
   [[['egg', '1', 'each', 'base'], ['milk', '1', 'cup', 'base'], ['lime', '3', 'each', 'base']], 7, 5],
   [['egg', '1', 'each'], ['milk', '3/4', 'cup'], ['lime', '2', 'each']]],
  ['generated control 1',
   [[['lime', '3', 'each', 'base'], ['salt', '2/3', 'tsp', 'seasoning'],
     ['pepper', '5/2', 'tsp', 'seasoning']],
    7, 11],
   [['lime', '5', 'each'], ['salt', '1', 'tsp'], ['pepper', '3 5/8', 'tsp']]],
  ['generated control 2',
   [[['lime', '1/2', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    2, 4],
   [['lime', '1', 'each'], ['flour', '5/8', 'cup'], ['butter', '3', 'tbsp'], ['garlic clove', '10', 'each']]],
  ['generated control 3',
   [[['salt', '9/4', 'tsp', 'seasoning'], ['pepper', '3/4', 'tsp', 'seasoning']], 7, 10],
   [['salt', '3', 'tsp'], ['pepper', '1', '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: scale factor direction',
   [[['egg', '3', 'each', 'base'], ['butter', '1', 'tbsp', 'base'], ['garlic clove', '2', 'each', 'base'],
     ['cumin', '1/4', 'tsp', 'seasoning'], ['milk', '1', 'cup', 'base']],
    3, 7],
   [['egg', '7', 'each'], ['butter', '2 3/8', 'tbsp'], ['garlic clove', '5', 'each'], ['cumin', '1/2', 'tsp'],
    ['milk', '2 3/8', 'cup']]],
  ['repair check: scale factor direction',
   [[['pepper', '3', 'tsp', 'seasoning'], ['flour', '3/4', 'cup', 'base'], ['butter', '1/3', 'tbsp', 'base'],
     ['milk', '1/4', 'cup', 'base']],
    7, 1],
   [['pepper', '1 1/8', 'tsp'], ['flour', '1/8', 'cup'], ['butter', 'pinch', 'tbsp'],
    ['milk', 'pinch', 'cup']]],
  ['generated control 1',
   [[['butter', '9/4', 'tbsp', 'base'], ['egg', '2', 'each', 'base'], ['pepper', '3/2', 'tsp', 'seasoning'],
     ['salt', '1/3', 'tsp', 'seasoning']],
    4, 8],
   [['butter', '4 1/2', 'tbsp'], ['egg', '4', 'each'], ['pepper', '2 5/8', 'tsp'], ['salt', '5/8', 'tsp']]],
  ['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['cumin', '5/2', 'tsp', 'seasoning']], 3, 9],
   [['butter', '7 1/2', 'tbsp'], ['cumin', '6 1/4', 'tsp']]],
  ['generated control 3',
   [[['salt', '3/2', 'tsp', 'seasoning'], ['pepper', '3', 'tsp', 'seasoning'],
     ['garlic clove', '4', 'each', 'base'], ['flour', '1/8', 'cup', 'base']],
    4, 5],
   [['salt', '1 3/4', 'tsp'], ['pepper', '3 5/8', 'tsp'], ['garlic clove', '5', 'each'],
    ['flour', '1/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: scale factor direction',
   [[['flour', '1/3', 'cup', 'base'], ['lime', '1', 'each', 'base'], ['butter', '1', 'tbsp', 'base']], 4, 3],
   [['flour', '1/4', 'cup'], ['lime', '1', 'each'], ['butter', '3/4', 'tbsp']]],
  ['repair check: scale factor direction',
   [[['flour', '5/2', 'cup', 'base'], ['milk', '2', 'cup', 'base'], ['salt', '1', 'tsp', 'seasoning']], 4, 1],
   [['flour', '5/8', 'cup'], ['milk', '1/2', 'cup'], ['salt', '1/2', 'tsp']]],
  ['generated control 1', [[['butter', '3/2', 'tbsp', 'base'], ['pepper', '2', 'tsp', 'seasoning']], 2, 11],
   [['butter', '8 1/4', 'tbsp'], ['pepper', '8 3/4', 'tsp']]],
  ['generated control 2',
   [[['salt', '1/3', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
     ['garlic clove', '5', 'each', 'base']],
    7, 9],
   [['salt', '3/8', 'tsp'], ['milk', '3 1/4', 'cup'], ['garlic clove', '6', 'each']]],
  ['generated control 3',
   [[['cumin', '1/3', 'tsp', 'seasoning'], ['garlic clove', '3', 'each', 'base'],
     ['pepper', '3/4', 'tsp', 'seasoning'], ['flour', '2/3', 'cup', 'base']],
    4, 2],
   [['cumin', '1/4', 'tsp'], ['garlic clove', '2', 'each'], ['pepper', '1/2', 'tsp'],
    ['flour', '3/8', 'cup']]]]]
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
identity scaling control[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']][['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]Passed
zero servings rejectederror: servings must be positiveerror: servings must be positivePassed
double batch with seasoning[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']][['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]Passed
regression: scale factor direction[['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']][['milk', '9', 'cup'], ['pepper', '1 5/8', 'tsp'], ['lime', '20', 'each'], ['garlic clove', '8', 'each']]Passed
repair check: scale factor direction[['milk', '7/8', 'cup'], ['lime', '2', 'each']][['milk', '7/8', 'cup'], ['lime', '2', 'each']]Passed
generated control 1[['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']][['salt', '5/8', 'tsp'], ['butter', '1 1/8', 'tbsp'], ['garlic clove', '7', 'each']]Passed
generated control 2[['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']][['butter', '3/8', 'tbsp'], ['pepper', '2 1/8', 'tsp']]Passed
generated control 3[['egg', '5', 'each'], ['pepper', '1 1/2', 'tsp']][['egg', '5', 'each'], ['pepper', '1 1/2', 'tsp']]Passed

SHA-256 / 829000484a6b7dd63068a65de729bb6d3e869c0242ad68380c4e92f2e648de65

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

Case digest / 85b7d344ef68ae0fe14018d07cc56027cb195da95254f159675b13c402a7d27c