FAILURE MAP
← Case archive

FA-79846 / Typography line breaking / Open access

Glue-set badness rating: shrink ratio denominator · case 01

Tight lines get badness and fitness computed from the wrong glue total.

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

ROOT CAUSE

The adjustment ratio for a compressed line divides by the stretch total instead of the shrink total.

VERIFIED REPAIR

Divide a negative shortfall by the shrink total.

Unsuccessful approach: Dividing by shrink plus stretch dilutes the ratio and still misrates compressed lines.

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, stretch)
    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 = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('regression: shrink ratio denominator', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [116, 20, 6, 127, 1000], ['ok', 17, 'loose']), ('control layout', [69, 10, 7, 69, 100], ['ok', 0, 'decent'])], [('regression: shrink ratio denominator', [96, 4, 10, 87, 1000], ['ok', 73, 'tight']), ('regression: shrink ratio denominator', [67, 1, 8, 64, 1000], ['ok', 5, 'decent']), ('regression: shrink ratio denominator', [85, 1, 11, 80, 200], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [104, 16, 8, 96, 150], ['ok', 100, 'tight']), ('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', [103, 8, 4, 116, 500], ['ok', 429, 'very_loose']), ('control layout', [92, 10, 3, 102, 1000], ['ok', 100, 'loose'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [100, 0, 9, 105, 100], ['underfull', 10000, 'very_loose']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink ratio denominator', [76, 10, 6, 74, 500], ['ok', 4, 'decent']), ('regression: shrink ratio denominator', [82, 3, 7, 76, 200], ['ok', 63, 'tight']), ('regression: shrink ratio denominator', [112, 16, 9, 104, 150], ['ok', 70, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [113, 8, 3, 103, 150], ['overfull', 1000000, 'tight']), ('control layout', [105, 12, 8, 111, 100], ['ok', 13, 'decent'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [105, 12, 5, 103, 1000], ['ok', 6, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [114, 0, 0, 136, 500], ['underfull', 10000, 'very_loose']), ('control layout', [95, 20, 10, 113, 500], ['ok', 73, '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
full shrink is still acceptable['ok', 13, 'decent']['ok', 100, 'tight']Failed
regression: shrink ratio denominator['ok', 7, 'decent']['ok', 58, 'tight']Failed
regression: shrink ratio denominator['underfull', 463, 'tight']['ok', 13, 'decent']Failed
regression: shrink ratio denominator['ok', 0, 'decent']['ok', 100, 'tight']Failed
exact natural width['ok', 0, 'decent']['ok', 0, 'decent']Passed
badness cap at 10000['underfull', 10000, 'very_loose']['underfull', 10000, 'very_loose']Passed
control layout['ok', 17, 'loose']['ok', 17, 'loose']Passed
control layout['ok', 0, 'decent']['ok', 0, 'decent']Passed

SHA-256 / d99f0e7ea36cbb896db48a83fc1fb14e2644e4d084c623c8eb4336fbc1d6c00e

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 + stretch)
    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 = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('regression: shrink ratio denominator', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [116, 20, 6, 127, 1000], ['ok', 17, 'loose']), ('control layout', [69, 10, 7, 69, 100], ['ok', 0, 'decent'])], [('regression: shrink ratio denominator', [96, 4, 10, 87, 1000], ['ok', 73, 'tight']), ('regression: shrink ratio denominator', [67, 1, 8, 64, 1000], ['ok', 5, 'decent']), ('regression: shrink ratio denominator', [85, 1, 11, 80, 200], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [104, 16, 8, 96, 150], ['ok', 100, 'tight']), ('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', [103, 8, 4, 116, 500], ['ok', 429, 'very_loose']), ('control layout', [92, 10, 3, 102, 1000], ['ok', 100, 'loose'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [100, 0, 9, 105, 100], ['underfull', 10000, 'very_loose']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink ratio denominator', [76, 10, 6, 74, 500], ['ok', 4, 'decent']), ('regression: shrink ratio denominator', [82, 3, 7, 76, 200], ['ok', 63, 'tight']), ('regression: shrink ratio denominator', [112, 16, 9, 104, 150], ['ok', 70, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [113, 8, 3, 103, 150], ['overfull', 1000000, 'tight']), ('control layout', [105, 12, 8, 111, 100], ['ok', 13, 'decent'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [105, 12, 5, 103, 1000], ['ok', 6, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [114, 0, 0, 136, 500], ['underfull', 10000, 'very_loose']), ('control layout', [95, 20, 10, 113, 500], ['ok', 73, '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
full shrink is still acceptable['ok', 4, 'decent']['ok', 100, 'tight']Failed
regression: shrink ratio denominator['ok', 2, 'decent']['ok', 58, 'tight']Failed
regression: shrink ratio denominator['ok', 6, 'decent']['ok', 13, 'decent']Failed
regression: shrink ratio denominator['ok', 0, 'decent']['ok', 100, 'tight']Failed
exact natural width['ok', 0, 'decent']['ok', 0, 'decent']Passed
badness cap at 10000['underfull', 10000, 'very_loose']['underfull', 10000, 'very_loose']Passed
control layout['ok', 17, 'loose']['ok', 17, 'loose']Passed
control layout['ok', 0, 'decent']['ok', 0, 'decent']Passed

SHA-256 / 199c09faffdf6463343114025fd380f3f13f337dafe0dc323d03a738ab752a07

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 = [[('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [105, 12, 6, 100, 1000], ['ok', 58, 'tight']), ('regression: shrink ratio denominator', [82, 3, 10, 77, 100], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [90, 12, 2, 88, 150], ['ok', 100, 'tight']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [116, 20, 6, 127, 1000], ['ok', 17, 'loose']), ('control layout', [69, 10, 7, 69, 100], ['ok', 0, 'decent'])], [('regression: shrink ratio denominator', [96, 4, 10, 87, 1000], ['ok', 73, 'tight']), ('regression: shrink ratio denominator', [67, 1, 8, 64, 1000], ['ok', 5, 'decent']), ('regression: shrink ratio denominator', [85, 1, 11, 80, 200], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [104, 16, 8, 96, 150], ['ok', 100, 'tight']), ('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', [103, 8, 4, 116, 500], ['ok', 429, 'very_loose']), ('control layout', [92, 10, 3, 102, 1000], ['ok', 100, 'loose'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [85, 3, 7, 78, 150], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('partial-repair probe', [88, 8, 8, 84, 150], ['ok', 13, 'decent']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('badness cap at 10000', [100, 2, 0, 150, 200], ['underfull', 10000, 'very_loose']), ('control layout', [100, 0, 9, 105, 100], ['underfull', 10000, 'very_loose']), ('control layout', [76, 20, 1, 72, 200], ['overfull', 1000000, 'tight'])], [('regression: shrink ratio denominator', [76, 10, 6, 74, 500], ['ok', 4, 'decent']), ('regression: shrink ratio denominator', [82, 3, 7, 76, 200], ['ok', 63, 'tight']), ('regression: shrink ratio denominator', [112, 16, 9, 104, 150], ['ok', 70, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('very loose over tolerance', [100, 4, 0, 110, 200], ['underfull', 1563, 'very_loose']), ('exact natural width', [100, 10, 5, 100, 200], ['ok', 0, 'decent']), ('control layout', [113, 8, 3, 103, 150], ['overfull', 1000000, 'tight']), ('control layout', [105, 12, 8, 111, 100], ['ok', 13, 'decent'])], [('regression: shrink ratio denominator', [107, 20, 11, 102, 100], ['ok', 9, 'decent']), ('regression: shrink ratio denominator', [92, 6, 12, 80, 100], ['ok', 100, 'tight']), ('regression: shrink ratio denominator', [96, 12, 2, 95, 200], ['ok', 13, 'decent']), ('regression: shrink ratio denominator', [105, 12, 5, 103, 1000], ['ok', 6, 'decent']), ('one unit past total shrink', [100, 10, 5, 94, 200], ['overfull', 1000000, 'tight']), ('full shrink is still acceptable', [100, 10, 5, 95, 200], ['ok', 100, 'tight']), ('control layout', [114, 0, 0, 136, 500], ['underfull', 10000, 'very_loose']), ('control layout', [95, 20, 10, 113, 500], ['ok', 73, '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
full shrink is still acceptable['ok', 100, 'tight']['ok', 100, 'tight']Passed
regression: shrink ratio denominator['ok', 58, 'tight']['ok', 58, 'tight']Passed
regression: shrink ratio denominator['ok', 13, 'decent']['ok', 13, 'decent']Passed
regression: shrink ratio denominator['ok', 100, 'tight']['ok', 100, 'tight']Passed
exact natural width['ok', 0, 'decent']['ok', 0, 'decent']Passed
badness cap at 10000['underfull', 10000, 'very_loose']['underfull', 10000, 'very_loose']Passed
control layout['ok', 17, 'loose']['ok', 17, 'loose']Passed
control layout['ok', 0, 'decent']['ok', 0, 'decent']Passed

SHA-256 / 1402086afa70c8c9cc18111ea1293e7e8ffed38ab4cb32ccbcfb143e1e0b3c7e

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

Case digest / 63004b812c04d091e04a91ff28d4391f5f98c48854badb1d221314c6820fb015