FAILURE MAP
← Case archive

FA-79851 / Typography line breaking / Open access

Glue-set badness rating: cubic badness curve · case 01

Moderately loose lines look far better than they are.

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

ROOT CAUSE

Badness squares the adjustment ratio instead of cubing it.

VERIFIED REPAIR

Rate badness as 100 times the cube of the ratio magnitude.

Unsuccessful approach: Multiplying square by ratio but dropping the half-unit rounding still yields off-by-one ratings.

Case contract

Input [natural, stretch, shrink, width, tolerance] (ints). shortfall=width-natural. Positive shortfall with zero stretch is underfull 10000 very_loose; shrinking past total shrink is overfull 1000000 tight. r=shortfall/stretch (or /shrink when negative); badness=min(10000, floor(100*|r|^3+1/2)); fitness tight r<-1/2, decent r<=1/2, loose r<=1, else very_loose; status ok iff badness<=tolerance. Return [status, badness, fitness].

Why this case matters

Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.

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(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 2 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('regression: cubic badness curve', [111, 10, 12, 125, 1000], ['ok', 274, 'very_loose']), ('regression: cubic badness curve', [76, 8, 4, 74, 500], ['ok', 13, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('control layout', [97, 1, 3, 91, 500], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [86, 10, 8, 106, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [119, 3, 8, 117, 500], ['ok', 2, 'decent']), ('regression: cubic badness curve', [99, 8, 9, 96, 100], ['ok', 4, 'decent']), ('regression: cubic badness curve', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [75, 3, 3, 78, 500], ['ok', 100, 'loose']), ('control layout', [101, 8, 2, 91, 1000], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [114, 2, 7, 113, 200], ['ok', 0, 'decent']), ('regression: cubic badness curve', [81, 1, 3, 83, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [73, 10, 1, 79, 150], ['ok', 22, 'loose']), ('regression: cubic badness curve', [109, 16, 4, 117, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [82, 1, 9, 82, 500], ['ok', 0, 'decent'])], [('regression: cubic badness curve', [82, 6, 9, 86, 1000], ['ok', 30, 'loose']), ('regression: cubic badness curve', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('regression: cubic badness curve', [80, 4, 2, 97, 500], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('control layout', [111, 1, 1, 134, 500], ['underfull', 10000, 'very_loose'])], [('regression: cubic badness curve', [79, 12, 5, 78, 1000], ['ok', 1, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('regression: cubic badness curve', [75, 20, 6, 71, 1000], ['ok', 30, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [71, 8, 8, 71, 150], ['ok', 0, 'decent']), ('control layout', [118, 0, 2, 133, 200], ['underfull', 10000, 'very_loose'])]]
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
half stretch ratio rounds 12.5 up['ok', 25, 'decent']['ok', 13, 'decent']Failed
regression: cubic badness curve['ok', 196, 'very_loose']['ok', 274, 'very_loose']Failed
regression: cubic badness curve['ok', 25, 'decent']['ok', 13, 'decent']Failed
regression: cubic badness curve['underfull', 1806, 'very_loose']['underfull', 7677, 'very_loose']Failed
full shrink is still acceptable['ok', 100, 'tight']['ok', 100, 'tight']Passed
one unit past total shrink['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed
control layout['ok', 100, 'tight']['ok', 100, 'tight']Passed
control layout['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed

SHA-256 / 3a978be0f7ba7d0538211dd65b3355cc6baad99c3610e11a33c3b08175d28419

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(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 2 * abs(r)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('regression: cubic badness curve', [111, 10, 12, 125, 1000], ['ok', 274, 'very_loose']), ('regression: cubic badness curve', [76, 8, 4, 74, 500], ['ok', 13, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('control layout', [97, 1, 3, 91, 500], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [86, 10, 8, 106, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [119, 3, 8, 117, 500], ['ok', 2, 'decent']), ('regression: cubic badness curve', [99, 8, 9, 96, 100], ['ok', 4, 'decent']), ('regression: cubic badness curve', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [75, 3, 3, 78, 500], ['ok', 100, 'loose']), ('control layout', [101, 8, 2, 91, 1000], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [114, 2, 7, 113, 200], ['ok', 0, 'decent']), ('regression: cubic badness curve', [81, 1, 3, 83, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [73, 10, 1, 79, 150], ['ok', 22, 'loose']), ('regression: cubic badness curve', [109, 16, 4, 117, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [82, 1, 9, 82, 500], ['ok', 0, 'decent'])], [('regression: cubic badness curve', [82, 6, 9, 86, 1000], ['ok', 30, 'loose']), ('regression: cubic badness curve', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('regression: cubic badness curve', [80, 4, 2, 97, 500], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('control layout', [111, 1, 1, 134, 500], ['underfull', 10000, 'very_loose'])], [('regression: cubic badness curve', [79, 12, 5, 78, 1000], ['ok', 1, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('regression: cubic badness curve', [75, 20, 6, 71, 1000], ['ok', 30, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [71, 8, 8, 71, 150], ['ok', 0, 'decent']), ('control layout', [118, 0, 2, 133, 200], ['underfull', 10000, 'very_loose'])]]
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
half stretch ratio rounds 12.5 up['ok', 12, 'decent']['ok', 13, 'decent']Failed
regression: cubic badness curve['ok', 274, 'very_loose']['ok', 274, 'very_loose']Passed
regression: cubic badness curve['ok', 12, 'decent']['ok', 13, 'decent']Failed
regression: cubic badness curve['underfull', 7676, 'very_loose']['underfull', 7677, 'very_loose']Failed
full shrink is still acceptable['ok', 100, 'tight']['ok', 100, 'tight']Passed
one unit past total shrink['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed
control layout['ok', 100, 'tight']['ok', 100, 'tight']Passed
control layout['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed

SHA-256 / 3877101dc4c587c6eca52efbc80294c3871abf2e8e4e1afe160fe1b3a5f9dfec

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(x):
    natural, stretch, shrink, width, tolerance = x
    shortfall = width - natural
    if shortfall > 0:
        if stretch == 0:
            return ['underfull', 10000, 'very_loose']
        r = Fraction(shortfall, stretch)
    elif shortfall < 0:
        if -shortfall > shrink:
            return ['overfull', 1000000, 'tight']
        r = Fraction(shortfall, shrink)
    else:
        r = Fraction(0)
    badness = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
    if r < Fraction(-1, 2):
        fitness = 'tight'
    elif r <= Fraction(1, 2):
        fitness = 'decent'
    elif r <= 1:
        fitness = 'loose'
    else:
        fitness = 'very_loose'
    status = 'ok' if badness <= tolerance else 'underfull'
    return [status, badness, fitness]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('half stretch ratio rounds 12.5 up', [100, 10, 5, 105, 200], ['ok', 13, 'decent']), ('regression: cubic badness curve', [111, 10, 12, 125, 1000], ['ok', 274, 'very_loose']), ('regression: cubic badness curve', [76, 8, 4, 74, 500], ['ok', 13, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('control layout', [62, 4, 4, 58, 200], ['ok', 100, 'tight']), ('control layout', [97, 1, 3, 91, 500], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [86, 10, 8, 106, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [119, 3, 8, 117, 500], ['ok', 2, 'decent']), ('regression: cubic badness curve', [99, 8, 9, 96, 100], ['ok', 4, 'decent']), ('regression: cubic badness curve', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [75, 3, 3, 78, 500], ['ok', 100, 'loose']), ('control layout', [101, 8, 2, 91, 1000], ['overfull', 1000000, 'tight'])], [('regression: cubic badness curve', [114, 2, 7, 113, 200], ['ok', 0, 'decent']), ('regression: cubic badness curve', [81, 1, 3, 83, 100], ['underfull', 800, 'very_loose']), ('regression: cubic badness curve', [73, 10, 1, 79, 150], ['ok', 22, 'loose']), ('regression: cubic badness curve', [109, 16, 4, 117, 200], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [91, 16, 1, 85, 150], ['overfull', 1000000, 'tight']), ('control layout', [82, 1, 9, 82, 500], ['ok', 0, 'decent'])], [('regression: cubic badness curve', [82, 6, 9, 86, 1000], ['ok', 30, 'loose']), ('regression: cubic badness curve', [99, 16, 2, 111, 1000], ['ok', 42, 'loose']), ('regression: cubic badness curve', [80, 4, 2, 97, 500], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('negative half ratio is decent', [100, 10, 6, 97, 200], ['ok', 13, 'decent']), ('control layout', [105, 1, 1, 120, 500], ['underfull', 10000, 'very_loose']), ('control layout', [111, 1, 1, 134, 500], ['underfull', 10000, 'very_loose'])], [('regression: cubic badness curve', [79, 12, 5, 78, 1000], ['ok', 1, 'decent']), ('regression: cubic badness curve', [88, 4, 3, 105, 1000], ['underfull', 7677, 'very_loose']), ('regression: cubic badness curve', [108, 0, 6, 105, 1000], ['ok', 13, 'decent']), ('regression: cubic badness curve', [75, 20, 6, 71, 1000], ['ok', 30, 'tight']), ('rigid line with slack', [100, 0, 5, 110, 200], ['underfull', 10000, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [71, 8, 8, 71, 150], ['ok', 0, 'decent']), ('control layout', [118, 0, 2, 133, 200], ['underfull', 10000, 'very_loose'])]]
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
half stretch ratio rounds 12.5 up['ok', 13, 'decent']['ok', 13, 'decent']Passed
regression: cubic badness curve['ok', 274, 'very_loose']['ok', 274, 'very_loose']Passed
regression: cubic badness curve['ok', 13, 'decent']['ok', 13, 'decent']Passed
regression: cubic badness curve['underfull', 7677, 'very_loose']['underfull', 7677, 'very_loose']Passed
full shrink is still acceptable['ok', 100, 'tight']['ok', 100, 'tight']Passed
one unit past total shrink['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed
control layout['ok', 100, 'tight']['ok', 100, 'tight']Passed
control layout['overfull', 1000000, 'tight']['overfull', 1000000, 'tight']Passed

SHA-256 / 49c018cf2b70d2ea1c1fe8b6c415a639831951f9c8f75be1cfa1e9365d1f81b8

Verification & scope

A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. 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:49:48.261772+00:00.

Case digest / ed32952ef64e3ee57638ece6a4905260ccbcfe1fa8e53e2efeacc428ae8af221