FA-79876 / Typography line breaking / Open access
Total-fit paragraph demerits: last-line exemption · case 01
The paragraph ending is rated like a justified line and good breaks become infeasible.
ROOT CAUSE
The zero-badness exemption is applied to lines ending one word before the paragraph end.
THE FAILURE
The zero-badness exemption is applied to lines ending one word before the paragraph end.
Unsuccessful approach: Exempting the last line even when overfull lets impossible endings through.
Case contract
Input [word widths, [space, stretch, shrink] per gap, line width, line penalty]. A line i..j has gaps=j-i-1. The last line has zero badness when not overfull. Other lines use ratio shortfall/(stretch*gaps) or /(shrink*gaps); zero stretch with slack or compression past shrink is infeasible; badness=min(10000, floor(100|r|^3+1/2)) and must be <=1000. Fitness 0 tight (r<-1/2), 1 decent (r<=1/2), 2 loose (r<=1), 3 very loose; last line decent. Demerits (lp+b)^2 plus 3000 when adjacent fitness classes differ by more than 1, starting from decent. Return [min total demerits, break list] (ties: first found) or ["infeasible"].
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):
words, glue, width, lp = x
sp, st, sh = glue
n = len(words)
def rate(i, j):
gaps = j - i - 1
nat = sum(words[i:j]) + sp * gaps
short = width - nat
if j == n - 1 and short >= 0:
return 0, 1
if short > 0:
if st * gaps == 0:
return None
r = Fraction(short, st * gaps)
elif short < 0:
if -short > sh * gaps:
return None
r = Fraction(short, sh * gaps)
else:
r = Fraction(0)
b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
if b > 1000:
return None
fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3
return b, fit
best = {(0, 1): (0, [])}
for j in range(1, n + 1):
for i in range(j):
rated = rate(i, j)
if rated is None:
continue
b, fit = rated
for (pos, pfit), (dem, brk) in sorted(best.items()):
if pos != i:
continue
d = dem + (lp + b) ** 2
if abs(fit - pfit) > 1:
d += 3000
key = (j, fit)
if key not in best or d < best[key][0]:
best[key] = (d, brk + [j])
finals = [v for (pos, f), v in best.items() if pos == n]
if not finals:
return ['infeasible']
d, brk = min(finals)
return [d, brk]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: last-line exemption', [[1, 3, 6, 5, 7], [3, 1, 2], 21, 1], [197, [4, 5]]), ('regression: last-line exemption', [[7, 2, 1, 4, 1, 6, 1], [3, 1, 0], 12, 1], [3, [2, 5, 7]]), ('regression: last-line exemption', [[7, 2, 7, 1, 5, 1, 5, 3], [2, 2, 1], 15, 50], [753500, [2, 5, 8]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[3, 6, 2, 3, 1], [2, 1, 0], 23, 10], [100, [5]]), ('control layout', [[5, 5, 3, 6], [1, 1, 1], 22, 1], [1, [4]])], [('regression: last-line exemption', [[4, 5, 7, 1], [3, 2, 1], 15, 10], [127204, [2, 4]]), ('regression: last-line exemption', [[6, 5, 1], [2, 2, 1], 12, 10], [12200, [2, 3]]), ('partial-repair probe', [[1, 2, 6], [3, 3, 2], 13, 10], [529, [3]]), ('regression: last-line exemption', [[6, 6, 5, 3, 2, 4, 1, 5], [1, 1, 2], 14, 50], [28969, [2, 6, 8]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[1, 3, 2, 5, 1, 5, 1], [1, 3, 2], 23, 10], [100, [7]]), ('control layout', [[2, 3, 2], [1, 3, 2], 9, 10], [100, [3]])], [('regression: last-line exemption', [[6, 5, 1], [2, 2, 1], 12, 10], [12200, [2, 3]]), ('regression: last-line exemption', [[3, 3, 2, 3, 4, 7], [2, 3, 1], 12, 50], [27500, [3, 5, 6]]), ('partial-repair probe', [[2, 7, 6, 1, 7, 4, 6, 2], [2, 3, 0], 17, 10], ['infeasible']), ('partial-repair probe', [[2, 5, 3, 6, 5], [2, 1, 1], 12, 50], [45000, [3, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[2, 7, 7, 2], [1, 3, 1], 21, 10], [100, [4]]), ('control layout', [[2, 3, 2], [1, 3, 2], 9, 10], [100, [3]])], [('regression: last-line exemption', [[6, 7, 6, 7, 4], [3, 2, 2], 22, 10], [2804, [3, 5]]), ('regression: last-line exemption', [[2, 7, 2, 6, 7], [2, 1, 1], 16, 10], [629, [3, 5]]), ('partial-repair probe', [[5, 7, 4, 4], [3, 2, 1], 13, 10], ['infeasible']), ('regression: last-line exemption', [[4, 3, 3, 4, 2], [1, 3, 0], 17, 1], [2, [4, 5]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[4, 5, 3], [1, 1, 2], 14, 1], [1, [3]]), ('control layout', [[3, 6, 2, 3, 1], [2, 1, 0], 23, 10], [100, [5]])], [('regression: last-line exemption', [[6, 1, 7, 7, 2, 1, 5, 5], [2, 2, 1], 17, 10], [3333, [3, 6, 8]]), ('regression: last-line exemption', [[5, 3, 1, 4, 2, 7, 3, 6], [2, 2, 1], 15, 50], [28969, [3, 6, 8]]), ('regression: last-line exemption', [[2, 2, 7, 7], [3, 3, 0], 19, 1], [26, [3, 4]]), ('regression: last-line exemption', [[5, 7, 5, 6, 5, 6, 4], [1, 2, 1], 17, 1], [20403, [3, 6, 7]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[5, 2, 1, 7], [1, 2, 0], 19, 1], [1, [4]]), ('control layout', [[4, 2, 3], [1, 3, 0], 12, 50], [2500, [3]])]]
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 |
|---|---|---|---|
| two-line paragraph with loose first line | [245208, [2, 4]] | [12200, [3, 4]] | Failed |
| regression: last-line exemption | ['infeasible'] | [197, [4, 5]] | Failed |
| regression: last-line exemption | [644603, [2, 5, 7]] | [3, [2, 5, 7]] | Failed |
| regression: last-line exemption | [754969, [2, 5, 8]] | [753500, [2, 5, 8]] | Failed |
| tight then loose lines | [243043, [3, 5, 7]] | [20403, [3, 6, 7]] | Failed |
| single word paragraph | ['infeasible'] | [100, [1]] | Failed |
| control layout | [100, [5]] | [100, [5]] | Passed |
| control layout | [1, [4]] | [1, [4]] | Passed |
SHA-256 / 11ed2df0119935012554aff0b39a0baec6ab82a337c6f5b202a0c546f6e9a8f1
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):
words, glue, width, lp = x
sp, st, sh = glue
n = len(words)
def rate(i, j):
gaps = j - i - 1
nat = sum(words[i:j]) + sp * gaps
short = width - nat
if j == n:
return 0, 1
if short > 0:
if st * gaps == 0:
return None
r = Fraction(short, st * gaps)
elif short < 0:
if -short > sh * gaps:
return None
r = Fraction(short, sh * gaps)
else:
r = Fraction(0)
b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))
if b > 1000:
return None
fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3
return b, fit
best = {(0, 1): (0, [])}
for j in range(1, n + 1):
for i in range(j):
rated = rate(i, j)
if rated is None:
continue
b, fit = rated
for (pos, pfit), (dem, brk) in sorted(best.items()):
if pos != i:
continue
d = dem + (lp + b) ** 2
if abs(fit - pfit) > 1:
d += 3000
key = (j, fit)
if key not in best or d < best[key][0]:
best[key] = (d, brk + [j])
finals = [v for (pos, f), v in best.items() if pos == n]
if not finals:
return ['infeasible']
d, brk = min(finals)
return [d, brk]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: last-line exemption', [[1, 3, 6, 5, 7], [3, 1, 2], 21, 1], [197, [4, 5]]), ('regression: last-line exemption', [[7, 2, 1, 4, 1, 6, 1], [3, 1, 0], 12, 1], [3, [2, 5, 7]]), ('regression: last-line exemption', [[7, 2, 7, 1, 5, 1, 5, 3], [2, 2, 1], 15, 50], [753500, [2, 5, 8]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[3, 6, 2, 3, 1], [2, 1, 0], 23, 10], [100, [5]]), ('control layout', [[5, 5, 3, 6], [1, 1, 1], 22, 1], [1, [4]])], [('regression: last-line exemption', [[4, 5, 7, 1], [3, 2, 1], 15, 10], [127204, [2, 4]]), ('regression: last-line exemption', [[6, 5, 1], [2, 2, 1], 12, 10], [12200, [2, 3]]), ('partial-repair probe', [[1, 2, 6], [3, 3, 2], 13, 10], [529, [3]]), ('regression: last-line exemption', [[6, 6, 5, 3, 2, 4, 1, 5], [1, 1, 2], 14, 50], [28969, [2, 6, 8]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[1, 3, 2, 5, 1, 5, 1], [1, 3, 2], 23, 10], [100, [7]]), ('control layout', [[2, 3, 2], [1, 3, 2], 9, 10], [100, [3]])], [('regression: last-line exemption', [[6, 5, 1], [2, 2, 1], 12, 10], [12200, [2, 3]]), ('regression: last-line exemption', [[3, 3, 2, 3, 4, 7], [2, 3, 1], 12, 50], [27500, [3, 5, 6]]), ('partial-repair probe', [[2, 7, 6, 1, 7, 4, 6, 2], [2, 3, 0], 17, 10], ['infeasible']), ('partial-repair probe', [[2, 5, 3, 6, 5], [2, 1, 1], 12, 50], [45000, [3, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[2, 7, 7, 2], [1, 3, 1], 21, 10], [100, [4]]), ('control layout', [[2, 3, 2], [1, 3, 2], 9, 10], [100, [3]])], [('regression: last-line exemption', [[6, 7, 6, 7, 4], [3, 2, 2], 22, 10], [2804, [3, 5]]), ('regression: last-line exemption', [[2, 7, 2, 6, 7], [2, 1, 1], 16, 10], [629, [3, 5]]), ('partial-repair probe', [[5, 7, 4, 4], [3, 2, 1], 13, 10], ['infeasible']), ('regression: last-line exemption', [[4, 3, 3, 4, 2], [1, 3, 0], 17, 1], [2, [4, 5]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[4, 5, 3], [1, 1, 2], 14, 1], [1, [3]]), ('control layout', [[3, 6, 2, 3, 1], [2, 1, 0], 23, 10], [100, [5]])], [('regression: last-line exemption', [[6, 1, 7, 7, 2, 1, 5, 5], [2, 2, 1], 17, 10], [3333, [3, 6, 8]]), ('regression: last-line exemption', [[5, 3, 1, 4, 2, 7, 3, 6], [2, 2, 1], 15, 50], [28969, [3, 6, 8]]), ('regression: last-line exemption', [[2, 2, 7, 7], [3, 3, 0], 19, 1], [26, [3, 4]]), ('regression: last-line exemption', [[5, 7, 5, 6, 5, 6, 4], [1, 2, 1], 17, 1], [20403, [3, 6, 7]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[5, 2, 1, 7], [1, 2, 0], 19, 1], [1, [4]]), ('control layout', [[4, 2, 3], [1, 3, 0], 12, 50], [2500, [3]])]]
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 |
|---|---|---|---|
| two-line paragraph with loose first line | [100, [4]] | [12200, [3, 4]] | Failed |
| regression: last-line exemption | [1, [5]] | [197, [4, 5]] | Failed |
| regression: last-line exemption | [1, [7]] | [3, [2, 5, 7]] | Failed |
| regression: last-line exemption | [2500, [8]] | [753500, [2, 5, 8]] | Failed |
| tight then loose lines | [1, [7]] | [20403, [3, 6, 7]] | Failed |
| single word paragraph | [100, [1]] | [100, [1]] | Passed |
| control layout | [100, [5]] | [100, [5]] | Passed |
| control layout | [1, [4]] | [1, [4]] | Passed |
SHA-256 / b577bf7453985b1dec6d9173d11fd6db19d3eb93978655b1fcba8aa5dd116532
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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.536518+00:00.
Case digest / 3e77423773664ac5e0cf3159bb6fded8cc529ee6629dccb479c0a1de51bfb413