FA-96921 / Recipe scaling and nutrition / Open access
Volume-to-mass ingredient converter: small-mass decimal threshold · case 01
7.5 g of flour prints "8 g" and exactly 10 g prints "10.0 g" under the attempted fix.
ROOT CAUSE
The one-decimal display is reserved for amounts under 1 g instead of under 10 g.
VERIFIED REPAIR
Print one decimal for results strictly below 10 g.
Unsuccessful approach: Using <= 10 prints an exact 10 g as "10.0 g" instead of whole grams.
Case contract
Convert amount (fraction string) of cup/tbsp/tsp/ml to grams. 1 cup = 16 tbsp = 48 tsp = 236.5 ml. Grams per cup: flour 120, sugar 200, brown sugar 145 (213 when prefixed "packed "), butter 227, honey 340, water 236. Names are trimmed and case-insensitive; a ", sifted" suffix multiplies density by 9/10. Results below 10 g print one decimal ("%.1f g"), otherwise whole grams, both half-up. Unknown ingredient or unit returns an error string.
Why this case matters
Recipe apps convert American volume measures to weights for scaling and nutrition lookup.
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(amount, unit, ingredient):
DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
name = ingredient.strip().lower()
packed = name.startswith('packed ')
if packed:
name = name[len('packed '):]
sifted = name.endswith(', sifted')
if sifted:
name = name[:-len(', sifted')]
if name not in DENS:
return 'error: unknown ingredient'
if unit == 'ml':
cups = Fraction(amount) / Fraction(2365, 10)
elif unit in PER_CUP:
cups = Fraction(amount) / PER_CUP[unit]
else:
return 'error: unknown unit'
d = Fraction(DENS[name])
if packed and name == 'brown sugar':
d = Fraction(213)
if sifted:
d = d * Fraction(9, 10)
g = cups * d
if g < 1:
return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['regression: small-mass decimal threshold', ['2', 'ml', ' Flour '], '1.0 g'],
['generated control 1', ['4', 'cup', 'saffron'], 'error: unknown ingredient'],
['generated control 2', ['3', 'tbsp', ' Water, Sifted '], '40 g'],
['generated control 3', ['4', 'tbsp', 'saffron'], 'error: unknown ingredient'],
['generated control 4', ['3', 'ml', ' Brown Sugar '], '1.8 g']],
[['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['regression: small-mass decimal threshold', ['1/4', 'tbsp', ' Packed Water '], '3.7 g'],
['generated control 1', ['1/3', 'ml', 'honey'], '0.5 g'],
['generated control 2', ['3/4', 'ml', 'butter, sifted'], '0.6 g'],
['generated control 3', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 4', ['3/4', 'ml', 'sugar'], '0.6 g']],
[['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['regression: small-mass decimal threshold', ['1/3', 'tsp', 'packed sugar'], '1.4 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['1', 'ml', 'SUGAR'], '0.8 g'],
['generated control 2', ['5', 'tsp', 'water'], '25 g'],
['generated control 3', ['250', 'pinch', 'butter'], 'error: unknown unit']],
[['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['regression: small-mass decimal threshold', ['1/2', 'tbsp', 'flour'], '3.8 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['250', 'cup', 'butter'], '56750 g'],
['generated control 2', ['1/3', 'ml', 'BUTTER'], '0.3 g'],
['generated control 3', ['1/3', 'tsp', ' Brown Sugar, Sifted '], '0.9 g']],
[['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['one cup flour', ['1', 'cup', 'flour'], '120 g'],
['regression: small-mass decimal threshold', ['1', 'tsp', 'honey'], '7.1 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', ' Packed Flour '], '10 g'],
['generated control 1', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 2', ['6', 'cup', 'packed sugar'], '1200 g'],
['generated control 3', ['1', 'ml', 'water'], '1.0 g']]]
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 |
|---|---|---|---|
| one cup flour | 120 g | 120 g | Passed |
| exactly ten grams | 10 g | 10 g | Passed |
| packed brown sugar | 213 g | 213 g | Passed |
| regression: small-mass decimal threshold | 1 g | 1.0 g | Failed |
| generated control 1 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 2 | 40 g | 40 g | Passed |
| generated control 3 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 4 | 2 g | 1.8 g | Failed |
SHA-256 / bc8c23b1c04da7721d83b8d31dc8062d37f1e011947c52c6f041fcd3d83d5896
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(amount, unit, ingredient):
DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
name = ingredient.strip().lower()
packed = name.startswith('packed ')
if packed:
name = name[len('packed '):]
sifted = name.endswith(', sifted')
if sifted:
name = name[:-len(', sifted')]
if name not in DENS:
return 'error: unknown ingredient'
if unit == 'ml':
cups = Fraction(amount) / Fraction(2365, 10)
elif unit in PER_CUP:
cups = Fraction(amount) / PER_CUP[unit]
else:
return 'error: unknown unit'
d = Fraction(DENS[name])
if packed and name == 'brown sugar':
d = Fraction(213)
if sifted:
d = d * Fraction(9, 10)
g = cups * d
if g <= 10:
return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['regression: small-mass decimal threshold', ['2', 'ml', ' Flour '], '1.0 g'],
['generated control 1', ['4', 'cup', 'saffron'], 'error: unknown ingredient'],
['generated control 2', ['3', 'tbsp', ' Water, Sifted '], '40 g'],
['generated control 3', ['4', 'tbsp', 'saffron'], 'error: unknown ingredient'],
['generated control 4', ['3', 'ml', ' Brown Sugar '], '1.8 g']],
[['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['regression: small-mass decimal threshold', ['1/4', 'tbsp', ' Packed Water '], '3.7 g'],
['generated control 1', ['1/3', 'ml', 'honey'], '0.5 g'],
['generated control 2', ['3/4', 'ml', 'butter, sifted'], '0.6 g'],
['generated control 3', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 4', ['3/4', 'ml', 'sugar'], '0.6 g']],
[['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['regression: small-mass decimal threshold', ['1/3', 'tsp', 'packed sugar'], '1.4 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['1', 'ml', 'SUGAR'], '0.8 g'],
['generated control 2', ['5', 'tsp', 'water'], '25 g'],
['generated control 3', ['250', 'pinch', 'butter'], 'error: unknown unit']],
[['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['regression: small-mass decimal threshold', ['1/2', 'tbsp', 'flour'], '3.8 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['250', 'cup', 'butter'], '56750 g'],
['generated control 2', ['1/3', 'ml', 'BUTTER'], '0.3 g'],
['generated control 3', ['1/3', 'tsp', ' Brown Sugar, Sifted '], '0.9 g']],
[['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['one cup flour', ['1', 'cup', 'flour'], '120 g'],
['regression: small-mass decimal threshold', ['1', 'tsp', 'honey'], '7.1 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', ' Packed Flour '], '10 g'],
['generated control 1', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 2', ['6', 'cup', 'packed sugar'], '1200 g'],
['generated control 3', ['1', 'ml', 'water'], '1.0 g']]]
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 |
|---|---|---|---|
| one cup flour | 120 g | 120 g | Passed |
| exactly ten grams | 10.0 g | 10 g | Failed |
| packed brown sugar | 213 g | 213 g | Passed |
| regression: small-mass decimal threshold | 1.0 g | 1.0 g | Passed |
| generated control 1 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 2 | 40 g | 40 g | Passed |
| generated control 3 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 4 | 1.8 g | 1.8 g | Passed |
SHA-256 / 19dfd3a19979e6b8618b9628ec50d8fb0bbcba9864de06b1713f13ca0c03e14c
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(amount, unit, ingredient):
DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
name = ingredient.strip().lower()
packed = name.startswith('packed ')
if packed:
name = name[len('packed '):]
sifted = name.endswith(', sifted')
if sifted:
name = name[:-len(', sifted')]
if name not in DENS:
return 'error: unknown ingredient'
if unit == 'ml':
cups = Fraction(amount) / Fraction(2365, 10)
elif unit in PER_CUP:
cups = Fraction(amount) / PER_CUP[unit]
else:
return 'error: unknown unit'
d = Fraction(DENS[name])
if packed and name == 'brown sugar':
d = Fraction(213)
if sifted:
d = d * Fraction(9, 10)
g = cups * d
if g < 10:
return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['regression: small-mass decimal threshold', ['2', 'ml', ' Flour '], '1.0 g'],
['generated control 1', ['4', 'cup', 'saffron'], 'error: unknown ingredient'],
['generated control 2', ['3', 'tbsp', ' Water, Sifted '], '40 g'],
['generated control 3', ['4', 'tbsp', 'saffron'], 'error: unknown ingredient'],
['generated control 4', ['3', 'ml', ' Brown Sugar '], '1.8 g']],
[['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['regression: small-mass decimal threshold', ['1/4', 'tbsp', ' Packed Water '], '3.7 g'],
['generated control 1', ['1/3', 'ml', 'honey'], '0.5 g'],
['generated control 2', ['3/4', 'ml', 'butter, sifted'], '0.6 g'],
['generated control 3', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 4', ['3/4', 'ml', 'sugar'], '0.6 g']],
[['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['regression: small-mass decimal threshold', ['1/3', 'tsp', 'packed sugar'], '1.4 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['1', 'ml', 'SUGAR'], '0.8 g'],
['generated control 2', ['5', 'tsp', 'water'], '25 g'],
['generated control 3', ['250', 'pinch', 'butter'], 'error: unknown unit']],
[['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['regression: small-mass decimal threshold', ['1/2', 'tbsp', 'flour'], '3.8 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', 'flour'], '10 g'],
['generated control 1', ['250', 'cup', 'butter'], '56750 g'],
['generated control 2', ['1/3', 'ml', 'BUTTER'], '0.3 g'],
['generated control 3', ['1/3', 'tsp', ' Brown Sugar, Sifted '], '0.9 g']],
[['metric cup of water', ['250', 'ml', 'water'], '249 g'],
['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
['one cup flour', ['1', 'cup', 'flour'], '120 g'],
['regression: small-mass decimal threshold', ['1', 'tsp', 'honey'], '7.1 g'],
['repair check: small-mass decimal threshold', ['4', 'tsp', ' Packed Flour '], '10 g'],
['generated control 1', ['1/3', 'cup', ' Flour, Sifted '], '36 g'],
['generated control 2', ['6', 'cup', 'packed sugar'], '1200 g'],
['generated control 3', ['1', 'ml', 'water'], '1.0 g']]]
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 |
|---|---|---|---|
| one cup flour | 120 g | 120 g | Passed |
| exactly ten grams | 10 g | 10 g | Passed |
| packed brown sugar | 213 g | 213 g | Passed |
| regression: small-mass decimal threshold | 1.0 g | 1.0 g | Passed |
| generated control 1 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 2 | 40 g | 40 g | Passed |
| generated control 3 | error: unknown ingredient | error: unknown ingredient | Passed |
| generated control 4 | 1.8 g | 1.8 g | Passed |
SHA-256 / 97359ee216f358b7336bbd37c73f3e857c096c048c9550d59b6957c30391e135
Verification & scope
A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:52:27.131682+00:00.
Case digest / 1e0a1ccadea8f84ab9a756490f6915a7fbac5ef8db6826765f83c9765ace9a7d