FAILURE MAP
← Case archive

FA-62431 / Tax bracket computation / Open access

A short-term loss reduces ordinary income while long-term gain stays preferential · case 01

A short-term loss saves ordinary-rate tax although it should first absorb long-term gain.

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

ROOT CAUSE

Short- and long-term results are not netted against each other before characterizing the gain.

VERIFIED REPAIR

Net a short-term loss against long-term gain (and vice versa) before splitting ordinary and preferential amounts.

Unsuccessful approach: Netting only up to 3000 of the short-term loss confuses the ordinary-income loss limit with character netting.

Case contract

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (half-up).

Why this case matters

Tax computations hinge on which slice, threshold, ordering and rounding rule applies at each step; a misplaced boundary silently misstates liabilities.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(ordinary, stcg, ltcg, status):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))
    
    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: ordinary, st = ordinary - min(3000, -st), 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cross-netting 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression cross-netting 2', (60000, -2000, 9000, 'single'), 930300),
  ('partial repair guard 2', (550000, -8000, 135896, 'single'), 18845395),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression cross-netting 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression cross-netting 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (9947, -13667, 100000, 'single'), 838295),
  ('partial repair guard 2', (173496, -15585, 20000, 'single'), 3534379),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression cross-netting 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression cross-netting 2', (173496, -15585, 20000, 'single'), 3534379),
  ('partial repair guard 1', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression cross-netting 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('regression cross-netting 2', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 1', (550000, -8000, 100000, 'single'), 18127475),
  ('partial repair guard 2', (0, -13215, 100000, 'mfj'), 0), ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression cross-netting 1', (40000, -6055, 100000, 'mfj'), 1032025),
  ('regression cross-netting 2', (90000, -1500, 259301, 'single'), 5352315),
  ('partial repair guard 1', (200000, -8000, 100000, 'single'), 5548650),
  ('partial repair guard 2', (200000, -18032, 100000, 'mfj'), 4640120),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0)]]
for label, args, expected in cases[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
regression cross-netting 114446001390600Failed
regression cross-netting 2916300930300Failed
partial repair guard 21890039518845395Failed
control: stacked partly in zero band651425651425Passed
control: gain only4462544625Passed
control: net capital loss759300759300Passed
control: high mfj1315620013156200Passed

SHA-256 / 6d28efcd6efad4f86c750936b24e2f2f555ab073b2e6f215ef2036dafed416f9

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(ordinary, stcg, ltcg, status):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))
    
    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt - min(3000, -st), 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cross-netting 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression cross-netting 2', (60000, -2000, 9000, 'single'), 930300),
  ('partial repair guard 2', (550000, -8000, 135896, 'single'), 18845395),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression cross-netting 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression cross-netting 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (9947, -13667, 100000, 'single'), 838295),
  ('partial repair guard 2', (173496, -15585, 20000, 'single'), 3534379),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression cross-netting 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression cross-netting 2', (173496, -15585, 20000, 'single'), 3534379),
  ('partial repair guard 1', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression cross-netting 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('regression cross-netting 2', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 1', (550000, -8000, 100000, 'single'), 18127475),
  ('partial repair guard 2', (0, -13215, 100000, 'mfj'), 0), ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression cross-netting 1', (40000, -6055, 100000, 'mfj'), 1032025),
  ('regression cross-netting 2', (90000, -1500, 259301, 'single'), 5352315),
  ('partial repair guard 1', (200000, -8000, 100000, 'single'), 5548650),
  ('partial repair guard 2', (200000, -18032, 100000, 'mfj'), 4640120),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0)]]
for label, args, expected in cases[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
regression cross-netting 114656001390600Failed
regression cross-netting 2930300930300Passed
partial repair guard 21894539518845395Failed
control: stacked partly in zero band651425651425Passed
control: gain only4462544625Passed
control: net capital loss759300759300Passed
control: high mfj1315620013156200Passed

SHA-256 / 9cc52710d0cb8c04eec09ab0801cc90c975ed975261b0701896cb011bd38ef9e

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(ordinary, stcg, ltcg, status):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))
    
    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cross-netting 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression cross-netting 2', (60000, -2000, 9000, 'single'), 930300),
  ('partial repair guard 2', (550000, -8000, 135896, 'single'), 18845395),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression cross-netting 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression cross-netting 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (9947, -13667, 100000, 'single'), 838295),
  ('partial repair guard 2', (173496, -15585, 20000, 'single'), 3534379),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression cross-netting 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression cross-netting 2', (173496, -15585, 20000, 'single'), 3534379),
  ('partial repair guard 1', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression cross-netting 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('regression cross-netting 2', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 1', (550000, -8000, 100000, 'single'), 18127475),
  ('partial repair guard 2', (0, -13215, 100000, 'mfj'), 0), ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression cross-netting 1', (40000, -6055, 100000, 'mfj'), 1032025),
  ('regression cross-netting 2', (90000, -1500, 259301, 'single'), 5352315),
  ('partial repair guard 1', (200000, -8000, 100000, 'single'), 5548650),
  ('partial repair guard 2', (200000, -18032, 100000, 'mfj'), 4640120),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0)]]
for label, args, expected in cases[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
regression cross-netting 113906001390600Passed
regression cross-netting 2930300930300Passed
partial repair guard 21884539518845395Passed
control: stacked partly in zero band651425651425Passed
control: gain only4462544625Passed
control: net capital loss759300759300Passed
control: high mfj1315620013156200Passed

SHA-256 / 1c35df8b2fa86cf255aa99b22af86c751602ef2d653b9622c7367453281494cd

Verification & scope

A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. 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:47:04.632465+00:00.

Case digest / 59f8d61c5c5a5e64c193103a7b8cf6a7c0e765bd512026bded90626e056a9173