{"abstract":"The paragraph ending is rated like a justified line and good breaks become infeasible.","category":"Typography line breaking","checks":8,"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\"].","contract_signature":"x","evaluation_group":"w2-typography-line-breaking-total-fit-demerits","failed_approach":"Exempting the last line even when overfull lets impossible endings through.","family":"w2-typography-line-breaking-total-fit-demerits-last-line-exemption","id":"FA-79876","implementations":{"attempt":{"sha256":"b577bf7453985b1dec6d9173d11fd6db19d3eb93978655b1fcba8aa5dd116532","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * gaps\n        short = width - nat\n        if j == n:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if abs(fit - pfit) > 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('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]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"11ed2df0119935012554aff0b39a0baec6ab82a337c6f5b202a0c546f6e9a8f1","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * gaps\n        short = width - nat\n        if j == n - 1 and short >= 0:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if abs(fit - pfit) > 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('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]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-typography-line-breaking-total-fit-demerits-last-line-exemption","generated_at":"2026-09-29T14:49:48.536518+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.","root_cause":"The zero-badness exemption is applied to lines ending one word before the paragraph end.","sha256":"3e77423773664ac5e0cf3159bb6fded8cc529ee6629dccb479c0a1de51bfb413","title":"Total-fit paragraph demerits: last-line exemption · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":42.888,"exit_code":1,"observations":[{"actual":[100,[4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":false},{"actual":[1,[5]],"check":"regression: last-line exemption","expected":[197,[4,5]],"passed":false},{"actual":[1,[7]],"check":"regression: last-line exemption","expected":[3,[2,5,7]],"passed":false},{"actual":[2500,[8]],"check":"regression: last-line exemption","expected":[753500,[2,5,8]],"passed":false},{"actual":[1,[7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":false},{"actual":[100,[1]],"check":"single word paragraph","expected":[100,[1]],"passed":true},{"actual":[100,[5]],"check":"control layout","expected":[100,[5]],"passed":true},{"actual":[1,[4]],"check":"control layout","expected":[1,[4]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [100, [4]], \"expected\": [12200, [3, 4]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [1, [5]], \"expected\": [197, [4, 5]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [1, [7]], \"expected\": [3, [2, 5, 7]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [2500, [8]], \"expected\": [753500, [2, 5, 8]], \"passed\": false}, {\"check\": \"tight then loose lines\", \"actual\": [1, [7]], \"expected\": [20403, [3, 6, 7]], \"passed\": false}, {\"check\": \"single word paragraph\", \"actual\": [100, [1]], \"expected\": [100, [1]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [100, [5]], \"expected\": [100, [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [1, [4]], \"expected\": [1, [4]], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":43.583,"exit_code":1,"observations":[{"actual":[245208,[2,4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":false},{"actual":["infeasible"],"check":"regression: last-line exemption","expected":[197,[4,5]],"passed":false},{"actual":[644603,[2,5,7]],"check":"regression: last-line exemption","expected":[3,[2,5,7]],"passed":false},{"actual":[754969,[2,5,8]],"check":"regression: last-line exemption","expected":[753500,[2,5,8]],"passed":false},{"actual":[243043,[3,5,7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":false},{"actual":["infeasible"],"check":"single word paragraph","expected":[100,[1]],"passed":false},{"actual":[100,[5]],"check":"control layout","expected":[100,[5]],"passed":true},{"actual":[1,[4]],"check":"control layout","expected":[1,[4]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [245208, [2, 4]], \"expected\": [12200, [3, 4]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [\"infeasible\"], \"expected\": [197, [4, 5]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [644603, [2, 5, 7]], \"expected\": [3, [2, 5, 7]], \"passed\": false}, {\"check\": \"regression: last-line exemption\", \"actual\": [754969, [2, 5, 8]], \"expected\": [753500, [2, 5, 8]], \"passed\": false}, {\"check\": \"tight then loose lines\", \"actual\": [243043, [3, 5, 7]], \"expected\": [20403, [3, 6, 7]], \"passed\": false}, {\"check\": \"single word paragraph\", \"actual\": [\"infeasible\"], \"expected\": [100, [1]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [100, [5]], \"expected\": [100, [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [1, [4]], \"expected\": [1, [4]], \"passed\": true}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}