FA-97361 / Knitting and sewing pattern grading / Open access
Gauge-based cast-on calculator: actual width basis · case 01
The reported finished width includes selvedge stitches that disappear into seams.
ROOT CAUSE
Actual width is computed from the cast-on including selvedges.
VERIFIED REPAIR
Compute actual width from body stitches only.
Unsuccessful approach: Removing one selvedge still counts the other side.
Case contract
Target width = width + ease (ease may be negative). Raw stitches = target * gauge / 10 (gauge per 10 cm). Body stitches = nearest multiple of repeat, half-up in repeat units, at least one repeat. Cast on = body + 2*edge (selvedge each side). Actual body width = body*10/gauge, half-up to 0.1 cm. Non-positive target, gauge or repeat returns an error string.
Why this case matters
Knitting patterns and calculators convert a finished measurement and gauge into a stitch count that fits the stitch pattern repeat.
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(width_cm, sts_per_10cm, repeat, edge, ease_cm):
w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
g = Fraction(str(sts_per_10cm))
if w <= 0 or g <= 0 or repeat < 1:
return 'error: bad measurements'
raw = w * g / 10
body = repeat * math.floor(raw / repeat + Fraction(1, 2))
body = max(repeat, body)
total = body + 2 * edge
actual = total * 10 / g
return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['regression: actual width basis', [45, '22', 8, 1, 0], [98, 43.6]],
['repair check: actual width basis', [50, '20', 1, 3, 5], [116, 55.0]],
['generated control 1', [52.5, '27.5', 2, 2, 10], [176, 62.5]],
['generated control 2', [50, '24', 8, 1, -5], [114, 46.7]],
['generated control 3', [30, '16', 8, 3, -5], [46, 25.0]]],
[['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['regression: actual width basis', [3, '18', 6, 1, 7.5], [20, 10.0]],
['repair check: actual width basis', [10, '22', 2, 1, -5], [14, 5.5]],
['generated control 1', [45, '18', 1, 1, -5], [74, 40.0]],
['generated control 2', [8, '24', 8, 0, 7.5], [40, 16.7]],
['generated control 3', [8, '27.5', 6, 2, -5], [10, 2.2]]],
[['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['regression: actual width basis', [3, '18', 2, 2, 0], [10, 3.3]],
['repair check: actual width basis', [45, '22', 6, 2, -5], [94, 40.9]],
['generated control 1', [30, '16', 4, 0, 5], [56, 35.0]],
['generated control 2', [50, '24', 8, 0, 0], [120, 50.0]],
['generated control 3', [30, '20', 2, 1, -2], [58, 28.0]]],
[['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['regression: actual width basis', [3, '22', 1, 2, 5], [22, 8.2]],
['repair check: actual width basis', [50, '20', 2, 3, -2], [102, 48.0]],
['generated control 1', [45, '16', 12, 2, -5], [64, 37.5]],
['generated control 2', [10, '27.5', 6, 0, -5], [12, 4.4]],
['generated control 3', [30, '22', 6, 1, -5], [56, 24.5]]],
[['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['regression: actual width basis', [40, '22', 2, 1, 10], [112, 50.0]],
['repair check: actual width basis', [50, '16', 8, 3, 0], [86, 50.0]],
['generated control 1', [52.5, '27.5', 2, 0, 0], [144, 52.4]],
['generated control 2', [40, '24', 6, 0, -2], [90, 37.5]],
['generated control 3', [40, '18', 8, 1, -5], [66, 35.6]]]]
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 |
|---|---|---|---|
| plain stockinette | [100, 50.0] | [100, 50.0] | Passed |
| rib with selvedges | [114, 51.8] | [114, 50.9] | Failed |
| narrow strap one repeat | [12, 7.5] | [12, 5.0] | Failed |
| regression: actual width basis | [98, 44.5] | [98, 43.6] | Failed |
| repair check: actual width basis | [116, 58.0] | [116, 55.0] | Failed |
| generated control 1 | [176, 64.0] | [176, 62.5] | Failed |
| generated control 2 | [114, 47.5] | [114, 46.7] | Failed |
| generated control 3 | [46, 28.8] | [46, 25.0] | Failed |
SHA-256 / 03307b43e1a58248ee850a5d6ab38cbc9b8a9128fc0509350f332bab37c70a2b
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(width_cm, sts_per_10cm, repeat, edge, ease_cm):
w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
g = Fraction(str(sts_per_10cm))
if w <= 0 or g <= 0 or repeat < 1:
return 'error: bad measurements'
raw = w * g / 10
body = repeat * math.floor(raw / repeat + Fraction(1, 2))
body = max(repeat, body)
total = body + 2 * edge
actual = (total - edge) * 10 / g
return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['regression: actual width basis', [45, '22', 8, 1, 0], [98, 43.6]],
['repair check: actual width basis', [50, '20', 1, 3, 5], [116, 55.0]],
['generated control 1', [52.5, '27.5', 2, 2, 10], [176, 62.5]],
['generated control 2', [50, '24', 8, 1, -5], [114, 46.7]],
['generated control 3', [30, '16', 8, 3, -5], [46, 25.0]]],
[['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['regression: actual width basis', [3, '18', 6, 1, 7.5], [20, 10.0]],
['repair check: actual width basis', [10, '22', 2, 1, -5], [14, 5.5]],
['generated control 1', [45, '18', 1, 1, -5], [74, 40.0]],
['generated control 2', [8, '24', 8, 0, 7.5], [40, 16.7]],
['generated control 3', [8, '27.5', 6, 2, -5], [10, 2.2]]],
[['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['regression: actual width basis', [3, '18', 2, 2, 0], [10, 3.3]],
['repair check: actual width basis', [45, '22', 6, 2, -5], [94, 40.9]],
['generated control 1', [30, '16', 4, 0, 5], [56, 35.0]],
['generated control 2', [50, '24', 8, 0, 0], [120, 50.0]],
['generated control 3', [30, '20', 2, 1, -2], [58, 28.0]]],
[['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['regression: actual width basis', [3, '22', 1, 2, 5], [22, 8.2]],
['repair check: actual width basis', [50, '20', 2, 3, -2], [102, 48.0]],
['generated control 1', [45, '16', 12, 2, -5], [64, 37.5]],
['generated control 2', [10, '27.5', 6, 0, -5], [12, 4.4]],
['generated control 3', [30, '22', 6, 1, -5], [56, 24.5]]],
[['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['regression: actual width basis', [40, '22', 2, 1, 10], [112, 50.0]],
['repair check: actual width basis', [50, '16', 8, 3, 0], [86, 50.0]],
['generated control 1', [52.5, '27.5', 2, 0, 0], [144, 52.4]],
['generated control 2', [40, '24', 6, 0, -2], [90, 37.5]],
['generated control 3', [40, '18', 8, 1, -5], [66, 35.6]]]]
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 |
|---|---|---|---|
| plain stockinette | [100, 50.0] | [100, 50.0] | Passed |
| rib with selvedges | [114, 51.4] | [114, 50.9] | Failed |
| narrow strap one repeat | [12, 6.3] | [12, 5.0] | Failed |
| regression: actual width basis | [98, 44.1] | [98, 43.6] | Failed |
| repair check: actual width basis | [116, 56.5] | [116, 55.0] | Failed |
| generated control 1 | [176, 63.3] | [176, 62.5] | Failed |
| generated control 2 | [114, 47.1] | [114, 46.7] | Failed |
| generated control 3 | [46, 26.9] | [46, 25.0] | Failed |
SHA-256 / 253f0f8438f833ae244177ab664bffc95a5571f1be280b5b7096d1b7eebcdde3
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(width_cm, sts_per_10cm, repeat, edge, ease_cm):
w = Fraction(str(width_cm)) + Fraction(str(ease_cm))
g = Fraction(str(sts_per_10cm))
if w <= 0 or g <= 0 or repeat < 1:
return 'error: bad measurements'
raw = w * g / 10
body = repeat * math.floor(raw / repeat + Fraction(1, 2))
body = max(repeat, body)
total = body + 2 * edge
actual = body * 10 / g
return [total, math.floor(actual * 10 + Fraction(1, 2)) / 10]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['regression: actual width basis', [45, '22', 8, 1, 0], [98, 43.6]],
['repair check: actual width basis', [50, '20', 1, 3, 5], [116, 55.0]],
['generated control 1', [52.5, '27.5', 2, 2, 10], [176, 62.5]],
['generated control 2', [50, '24', 8, 1, -5], [114, 46.7]],
['generated control 3', [30, '16', 8, 3, -5], [46, 25.0]]],
[['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['regression: actual width basis', [3, '18', 6, 1, 7.5], [20, 10.0]],
['repair check: actual width basis', [10, '22', 2, 1, -5], [14, 5.5]],
['generated control 1', [45, '18', 1, 1, -5], [74, 40.0]],
['generated control 2', [8, '24', 8, 0, 7.5], [40, 16.7]],
['generated control 3', [8, '27.5', 6, 2, -5], [10, 2.2]]],
[['narrow strap one repeat', [3, '16', 8, 2, 0], [12, 5.0]],
['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['regression: actual width basis', [3, '18', 2, 2, 0], [10, 3.3]],
['repair check: actual width basis', [45, '22', 6, 2, -5], [94, 40.9]],
['generated control 1', [30, '16', 4, 0, 5], [56, 35.0]],
['generated control 2', [50, '24', 8, 0, 0], [120, 50.0]],
['generated control 3', [30, '20', 2, 1, -2], [58, 28.0]]],
[['negative ease', [40, '24', 2, 1, -5], [86, 35.0]],
['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['regression: actual width basis', [3, '22', 1, 2, 5], [22, 8.2]],
['repair check: actual width basis', [50, '20', 2, 3, -2], [102, 48.0]],
['generated control 1', [45, '16', 12, 2, -5], [64, 37.5]],
['generated control 2', [10, '27.5', 6, 0, -5], [12, 4.4]],
['generated control 3', [30, '22', 6, 1, -5], [56, 24.5]]],
[['invalid width', [3, '20', 2, 0, -5], 'error: bad measurements'],
['plain stockinette', [50, '20', 1, 0, 0], [100, 50.0]],
['rib with selvedges', [45, '22', 4, 1, 5], [114, 50.9]],
['regression: actual width basis', [40, '22', 2, 1, 10], [112, 50.0]],
['repair check: actual width basis', [50, '16', 8, 3, 0], [86, 50.0]],
['generated control 1', [52.5, '27.5', 2, 0, 0], [144, 52.4]],
['generated control 2', [40, '24', 6, 0, -2], [90, 37.5]],
['generated control 3', [40, '18', 8, 1, -5], [66, 35.6]]]]
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 |
|---|---|---|---|
| plain stockinette | [100, 50.0] | [100, 50.0] | Passed |
| rib with selvedges | [114, 50.9] | [114, 50.9] | Passed |
| narrow strap one repeat | [12, 5.0] | [12, 5.0] | Passed |
| regression: actual width basis | [98, 43.6] | [98, 43.6] | Passed |
| repair check: actual width basis | [116, 55.0] | [116, 55.0] | Passed |
| generated control 1 | [176, 62.5] | [176, 62.5] | Passed |
| generated control 2 | [114, 46.7] | [114, 46.7] | Passed |
| generated control 3 | [46, 25.0] | [46, 25.0] | Passed |
SHA-256 / c487def22183aed6a3ef25f59361dc409bba1e1140c00d7e5871884c127c12c3
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:31.469169+00:00.
Case digest / a07bbd27fbefd57e4d1034f8e6485150c31f4d94841570a63e1af84317bb04f4