broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
        if c < raw: c += 1
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c < raw: c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression yen-ending 1', ('1239', '1', 'JPY'), '1248'),
  ('regression yen-ending 2', ('1234.5', '1', 'JPY'), '1238'),
  ('partial repair guard 2', ('1408.999', '1', 'JPY'), '1418'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')],
 [('regression yen-ending 1', ('1238', '1', 'JPY'), '1238'),
  ('regression yen-ending 2', ('9.99', '151.37', 'JPY'), '1518'),
  ('partial repair guard 1', ('128.999', '1', 'JPY'), '138'), ('partial repair guard 2', ('538.99', '1', 'JPY'), '548'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99')],
 [('regression yen-ending 1', ('1408.999', '1', 'JPY'), '1418'),
  ('regression yen-ending 2', ('73.04', '172.2043', 'JPY'), '12578'),
  ('partial repair guard 1', ('82.26', '4.0106', 'JPY'), '338'),
  ('partial repair guard 2', ('291.37', '7.8591', 'JPY'), '2298'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99'),
  ('control: sub-cent above', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518')],
 [('regression yen-ending 1', ('114', '1', 'JPY'), '118'),
  ('regression yen-ending 2', ('42.57', '41.3869', 'JPY'), '1768'),
  ('partial repair guard 1', ('63.46', '153.7785', 'JPY'), '9768'),
  ('partial repair guard 2', ('2209.9996', '1', 'JPY'), '2218'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression yen-ending 1', ('225.53', '87.4879', 'JPY'), '19738'),
  ('regression yen-ending 2', ('128.999', '1', 'JPY'), '138'),
  ('partial repair guard 1', ('124.55', '167.3895', 'JPY'), '20858'),
  ('partial repair guard 2', ('119', '1', 'JPY'), '128'), ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(price, rate, ccy):
    raw = Decimal(price) * Decimal(rate)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c < raw: c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression yen-ending 1', ('1239', '1', 'JPY'), '1248'),
  ('regression yen-ending 2', ('1234.5', '1', 'JPY'), '1238'),
  ('partial repair guard 2', ('1408.999', '1', 'JPY'), '1418'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')],
 [('regression yen-ending 1', ('1238', '1', 'JPY'), '1238'),
  ('regression yen-ending 2', ('9.99', '151.37', 'JPY'), '1518'),
  ('partial repair guard 1', ('128.999', '1', 'JPY'), '138'), ('partial repair guard 2', ('538.99', '1', 'JPY'), '548'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99')],
 [('regression yen-ending 1', ('1408.999', '1', 'JPY'), '1418'),
  ('regression yen-ending 2', ('73.04', '172.2043', 'JPY'), '12578'),
  ('partial repair guard 1', ('82.26', '4.0106', 'JPY'), '338'),
  ('partial repair guard 2', ('291.37', '7.8591', 'JPY'), '2298'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: just above charm', ('11.994', '1', 'USD'), '12.99'),
  ('control: sub-cent above', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518')],
 [('regression yen-ending 1', ('114', '1', 'JPY'), '118'),
  ('regression yen-ending 2', ('42.57', '41.3869', 'JPY'), '1768'),
  ('partial repair guard 1', ('63.46', '153.7785', 'JPY'), '9768'),
  ('partial repair guard 2', ('2209.9996', '1', 'JPY'), '2218'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression yen-ending 1', ('225.53', '87.4879', 'JPY'), '19738'),
  ('regression yen-ending 2', ('128.999', '1', 'JPY'), '138'),
  ('partial repair guard 1', ('124.55', '167.3895', 'JPY'), '20858'),
  ('partial repair guard 2', ('119', '1', 'JPY'), '128'), ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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)

prompt:
Yen shelf prices appear as 1234.99.

solve(price, rate, ccy): a price list converted at rate is re-priced to the smallest charm price not below the exact converted value raw = price*rate. For JPY, charm prices end in 8 (…8 yen, i.e. 10k-2). For other currencies, charm prices end in .99. Return the charm price as a plain string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(price, rate, ccy):
    raw = (Decimal(price) * Decimal(rate)).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c < raw: c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(price, rate, ccy):
    raw = (Decimal(price) * Decimal(rate)).quantize(Decimal('0.0001'), rounding=ROUND_HALF_EVEN)
    if ccy == 'JPY':
        c = (raw / 10).to_integral_value(rounding=ROUND_CEILING) * 10 - 2
        if c < raw: c += 10
        return format(c, 'f')
    c = raw.to_integral_value(rounding=ROUND_FLOOR) + Decimal('0.99')
    if c < raw: c += 1
    return format(c, 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: converted euro', ('10.00', '0.92', 'EUR'), '9.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'),
  ('control: already charm', ('11.99', '1', 'EUR'), '11.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: yen converted', ('9.99', '151.37', 'JPY'), '1518'),
  ('control: whole number', ('12.00', '1', 'EUR'), '12.99'), ('control: already charm', ('11.99', '1', 'EUR'), '11.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99')],
 [('regression pre-rounded-raw 1', ('11.994', '1', 'USD'), '12.99'),
  ('regression pre-rounded-raw 2', ('11.99004', '1', 'GBP'), '12.99'),
  ('control: above charm', ('12.995', '1', 'EUR'), '13.99'), ('control: yen round up', ('1234.5', '1', 'JPY'), '1238'),
  ('control: yen above ending', ('1239', '1', 'JPY'), '1248'),
  ('control: yen exact ending', ('1238', '1', 'JPY'), '1238')]]
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)

prompt:
A converted value of 11.994 is listed at 11.99, below the converted amount.

solve(price, rate, ccy): a price list converted at rate is re-priced to the smallest charm price not below the exact converted value raw = price*rate. For JPY, charm prices end in 8 (…8 yen, i.e. 10k-2). For other currencies, charm prices end in .99. Return the charm price as a plain string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rq * days / 360) / (1 + rb * days / 360)
    pe = 2 if quote == 'JPY' else 4
    pts = ((F - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression money-market-basis 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression money-market-basis 2', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression money-market-basis 1', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('regression money-market-basis 2', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression money-market-basis 1', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('regression money-market-basis 2', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression money-market-basis 1', ('AUDJPY', '5.9212', '0.74', '1.63', 182), ['5.948', '2.68']),
  ('regression money-market-basis 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression money-market-basis 1', ('GBPJPY', '5.4304', '2.54', '5.76', 365), ['5.605', '17.48']),
  ('regression money-market-basis 2', ('USDCAD', '90.4307', '5.79', '0.97', 365), ['86.24494', '-41857.60']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rq * days / basis[base]) / (1 + rb * days / basis[base])
    pe = 2 if quote == 'JPY' else 4
    pts = ((F - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression money-market-basis 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression money-market-basis 2', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression money-market-basis 1', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('regression money-market-basis 2', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression money-market-basis 1', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('regression money-market-basis 2', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression money-market-basis 1', ('AUDJPY', '5.9212', '0.74', '1.63', 182), ['5.948', '2.68']),
  ('regression money-market-basis 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression money-market-basis 1', ('GBPJPY', '5.4304', '2.54', '5.76', 365), ['5.605', '17.48']),
  ('regression money-market-basis 2', ('USDCAD', '90.4307', '5.79', '0.97', 365), ['86.24494', '-41857.60']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

prompt:
Sterling and Canadian-dollar forwards are mispriced by the basis difference.

solve(pair, spot, base_pct, quote_pct, days): covered-interest-parity outright F = S*(1 + rq*days/Bq)/(1 + rb*days/Bb) with money-market bases GBP, AUD, CAD 365 and USD, EUR, JPY, CHF 360; rates are given in percent. The pip exponent is 2 for JPY-quoted pairs, else 4. Return [F rounded half-even to pip exponent + 1 decimals, forward points = (F - S)*10**pip_exp rounded half-even to 2 decimals] as strings, both computed from the exact F.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rb * days / basis[base]) / (1 + rq * days / basis[quote])
    pe = 2 if quote == 'JPY' else 4
    pts = ((F - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parity-orientation 1', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('regression parity-orientation 2', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression parity-orientation 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression parity-orientation 2', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression parity-orientation 1', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('regression parity-orientation 2', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('partial repair guard 2', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression parity-orientation 1', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('regression parity-orientation 2', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('partial repair guard 2', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression parity-orientation 1', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('regression parity-orientation 2', ('AUDJPY', '5.9212', '0.74', '1.63', 182), ['5.948', '2.68']),
  ('partial repair guard 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + (rq - rb) * days / basis[quote])
    pe = 2 if quote == 'JPY' else 4
    pts = ((F - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parity-orientation 1', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('regression parity-orientation 2', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression parity-orientation 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression parity-orientation 2', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression parity-orientation 1', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('regression parity-orientation 2', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('partial repair guard 2', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression parity-orientation 1', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('regression parity-orientation 2', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('partial repair guard 2', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression parity-orientation 1', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('regression parity-orientation 2', ('AUDJPY', '5.9212', '0.74', '1.63', 182), ['5.948', '2.68']),
  ('partial repair guard 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

prompt:
A higher-yielding quote currency produces forward discount points instead of premium points.

solve(pair, spot, base_pct, quote_pct, days): covered-interest-parity outright F = S*(1 + rq*days/Bq)/(1 + rb*days/Bb) with money-market bases GBP, AUD, CAD 365 and USD, EUR, JPY, CHF 360; rates are given in percent. The pip exponent is 2 for JPY-quoted pairs, else 4. Return [F rounded half-even to pip exponent + 1 decimals, forward points = (F - S)*10**pip_exp rounded half-even to 2 decimals] as strings, both computed from the exact F.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rq * days / basis[quote]) / (1 + rb * days / basis[base])
    pe = 2 if quote == 'JPY' else 4
    pts = ((F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN) - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression points-from-rounded-forward 1', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('regression points-from-rounded-forward 2', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression points-from-rounded-forward 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression points-from-rounded-forward 2', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression points-from-rounded-forward 1', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('regression points-from-rounded-forward 2', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression points-from-rounded-forward 1', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('regression points-from-rounded-forward 2', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression points-from-rounded-forward 1', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('regression points-from-rounded-forward 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rq * days / basis[quote]) / (1 + rb * days / basis[base])
    pe = 2 if quote == 'JPY' else 4
    pts = ((F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_UP) - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression points-from-rounded-forward 1', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('regression points-from-rounded-forward 2', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression points-from-rounded-forward 1', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('regression points-from-rounded-forward 2', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85'])],
 [('regression points-from-rounded-forward 1', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('regression points-from-rounded-forward 2', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression points-from-rounded-forward 1', ('USDCAD', '128.6366', '0.30', '6.36', 365), ['136.40300', '77663.95']),
  ('regression points-from-rounded-forward 2', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression points-from-rounded-forward 1', ('GBPUSD', '17.5535', '4.72', '0.07', 182), ['17.15594', '-3975.59']),
  ('regression points-from-rounded-forward 2', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

prompt:
Points disagree in the second decimal with points computed from the exact forward.

solve(pair, spot, base_pct, quote_pct, days): covered-interest-parity outright F = S*(1 + rq*days/Bq)/(1 + rb*days/Bb) with money-market bases GBP, AUD, CAD 365 and USD, EUR, JPY, CHF 360; rates are given in percent. The pip exponent is 2 for JPY-quoted pairs, else 4. Return [F rounded half-even to pip exponent + 1 decimals, forward points = (F - S)*10**pip_exp rounded half-even to 2 decimals] as strings, both computed from the exact F.

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(pair, spot, base_pct, quote_pct, days):
    basis = {'USD': 360, 'EUR': 360, 'JPY': 360, 'CHF': 360, 'GBP': 365, 'AUD': 365, 'CAD': 365}
    base, quote = pair[:3], pair[3:]
    S = Decimal(spot)
    rb, rq = Decimal(base_pct) / 100, Decimal(quote_pct) / 100
    F = S * (1 + rq * days / basis[quote]) / (1 + rb * days / basis[base])
    pe = 2 if base == 'JPY' else 4
    pts = ((F - S) * Decimal(10) ** pe).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
    return [format(F.quantize(Decimal(1).scaleb(-(pe + 1)), rounding=ROUND_HALF_EVEN), 'f'), format(pts, 'f')]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression jpy-pip-exponent 1', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('regression jpy-pip-exponent 2', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16'])],
 [('regression jpy-pip-exponent 1', ('AUDJPY', '54.4548', '0.49', '4.06', 91), ['54.947', '49.17']),
  ('regression jpy-pip-exponent 2', ('AUDJPY', '5.9212', '0.74', '1.63', 182), ['5.948', '2.68']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression jpy-pip-exponent 1', ('GBPJPY', '137.7426', '3.56', '5.48', 1), ['137.750', '0.75']),
  ('regression jpy-pip-exponent 2', ('GBPJPY', '5.4304', '2.54', '5.76', 365), ['5.605', '17.48']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])],
 [('regression jpy-pip-exponent 1', ('USDJPY', '99.9582', '4.97', '2.67', 91), ['99.384', '-57.39']),
  ('regression jpy-pip-exponent 2', ('GBPJPY', '63.7106', '6.59', '7.11', 91), ['63.807', '9.67']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37']),
  ('control: dollar cad', ('USDCAD', '1.3577', '5.30', '4.75', 182), ['1.35359', '-41.12']),
  ('control: euro franc', ('EURCHF', '0.9512', '3.75', '1.50', 7), ['0.95078', '-4.16']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64'])],
 [('regression jpy-pip-exponent 1', ('AUDJPY', '25.5690', '7.90', '3.42', 182), ['25.025', '-54.37']),
  ('regression jpy-pip-exponent 2', ('GBPJPY', '111.1109', '0.75', '7.67', 30), ['111.752', '64.13']),
  ('control: euro dollar year', ('EURUSD', '1.0800', '3.60', '5.40', 360), ['1.09876', '187.64']),
  ('control: dollar yen half year', ('USDJPY', '150.00', '5.00', '0.00', 180), ['146.341', '-365.85']),
  ('control: sterling dollar', ('GBPUSD', '1.2650', '5.25', '5.30', 91), ['1.26538', '3.85']),
  ('control: aussie yen', ('AUDJPY', '98.765', '4.35', '0.10', 30), ['98.421', '-34.37'])]]
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)

prompt:
USDJPY forward points are a hundred times too large.

solve(pair, spot, base_pct, quote_pct, days): covered-interest-parity outright F = S*(1 + rq*days/Bq)/(1 + rb*days/Bb) with money-market bases GBP, AUD, CAD 365 and USD, EUR, JPY, CHF 360; rates are given in percent. The pip exponent is 2 for JPY-quoted pairs, else 4. Return [F rounded half-even to pip exponent + 1 decimals, forward points = (F - S)*10**pip_exp rounded half-even to 2 decimals] as strings, both computed from the exact F.

split: open-access


prompt:
Crossing a threshold by one dollar raises tax on every dollar of income.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


prompt:
Tax in the second bracket also re-taxes the first bracket's income.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


prompt:
Totals differ by a cent from the exact schedule when several slices carry half-cents.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        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 int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression threshold-validation 1', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (500, [[0, '10'], [None, '30']]), 'ERR:brackets'),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression threshold-validation 1', (1, [[44000, '15'], [44000, '22'], [None, '40.5']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[60000, '22'], [60000, '15'], [188000, '33.3'], [None, '37']]),
   'ERR:brackets'),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression threshold-validation 1', (999, [[24000, '33.3'], [24000, '22'], [150000, '10'], [None, '37']]),
   'ERR:brackets'),
  ('regression threshold-validation 2',
   (40000, [[83000, '5'], [83000, '10'], [156000, '10'], [192000, '10'], [None, '37']]), 'ERR:brackets'),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression threshold-validation 1', (10000, [[178000, '24'], [178000, '33.3'], [None, '45']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[44000, '5'], [44000, '15'], [None, '37']]), 'ERR:brackets'),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression threshold-validation 1', (999, [[105000, '15'], [105000, '24'], [None, '30']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[138000, '15'], [138000, '33.3'], [None, '45']]), 'ERR:brackets'),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip(uppers[1:], uppers[2:])): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        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 int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression threshold-validation 1', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (500, [[0, '10'], [None, '30']]), 'ERR:brackets'),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression threshold-validation 1', (1, [[44000, '15'], [44000, '22'], [None, '40.5']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[60000, '22'], [60000, '15'], [188000, '33.3'], [None, '37']]),
   'ERR:brackets'),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression threshold-validation 1', (999, [[24000, '33.3'], [24000, '22'], [150000, '10'], [None, '37']]),
   'ERR:brackets'),
  ('regression threshold-validation 2',
   (40000, [[83000, '5'], [83000, '10'], [156000, '10'], [192000, '10'], [None, '37']]), 'ERR:brackets'),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression threshold-validation 1', (10000, [[178000, '24'], [178000, '33.3'], [None, '45']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[44000, '5'], [44000, '15'], [None, '37']]), 'ERR:brackets'),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression threshold-validation 1', (999, [[105000, '15'], [105000, '24'], [None, '30']]), 'ERR:brackets'),
  ('regression threshold-validation 2', (10000, [[138000, '15'], [138000, '33.3'], [None, '45']]), 'ERR:brackets'),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

prompt:
A mis-keyed bracket table silently produces a tax figure.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets[:-1]:
        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 int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression open-top-bracket 1',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('regression open-top-bracket 2', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022)],
 [('regression open-top-bracket 1', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('regression open-top-bracket 2', (777, [[None, '12.5']]), 9713),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets')],
 [('regression open-top-bracket 1',
   (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]), 4039200),
  ('regression open-top-bracket 2', (40000, [[None, '45']]), 1800000),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression open-top-bracket 1', (139460, [[None, '40.5']]), 5648130),
  ('regression open-top-bracket 2',
   (236107, [[31000, '10'], [159000, '10'], [172000, '24'], [193000, '22'], [None, '45']]), 4303815),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression open-top-bracket 1',
   (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]), 5673643),
  ('regression open-top-bracket 2', (172773, [[None, '30']]), 5183190),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets[:-1]:
        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
    if len(brackets) > 1 and x > brackets[-2][0]: tax += (x - brackets[-2][0]) * Fraction(brackets[-2][1]) / 100
    return int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression open-top-bracket 1',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('regression open-top-bracket 2', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022)],
 [('regression open-top-bracket 1', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('regression open-top-bracket 2', (777, [[None, '12.5']]), 9713),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets')],
 [('regression open-top-bracket 1',
   (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]), 4039200),
  ('regression open-top-bracket 2', (40000, [[None, '45']]), 1800000),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression open-top-bracket 1', (139460, [[None, '40.5']]), 5648130),
  ('regression open-top-bracket 2',
   (236107, [[31000, '10'], [159000, '10'], [172000, '24'], [193000, '22'], [None, '45']]), 4303815),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression open-top-bracket 1',
   (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]), 5673643),
  ('regression open-top-bracket 2', (172773, [[None, '30']]), 5183190),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

prompt:
High earners pay the same tax as someone exactly at the final threshold.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        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 int(round(float(tax), 2) * 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression final-cent-rounding 1', (46, [[None, '10']]), 460),
  ('regression final-cent-rounding 2', (41, [[None, '12.5']]), 513),
  ('partial repair guard 2', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression final-cent-rounding 1',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('regression final-cent-rounding 2', (777, [[None, '12.5']]), 9713),
  ('partial repair guard 2', (999, [[24000, '33.3'], [134000, '15'], [190000, '15'], [None, '40.5']]), 33267),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression final-cent-rounding 1', (10001, [[18000, '12.5'], [80000, '22'], [None, '30']]), 125013),
  ('regression final-cent-rounding 2', (10001, [[60000, '12.5'], [92000, '22'], [None, '45']]), 125013),
  ('partial repair guard 2', (999, [[166000, '33.3'], [178000, '10'], [None, '40.5']]), 33267),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression final-cent-rounding 1', (1, [[68000, '12.5'], [81000, '10'], [167000, '33.3'], [None, '45']]), 13),
  ('regression final-cent-rounding 2',
   (64068, [[32000, '22'], [105000, '10'], [170000, '24'], [193000, '10'], [None, '37']]), 1024680),
  ('partial repair guard 1', (10001, [[60000, '12.5'], [92000, '22'], [None, '45']]), 125013),
  ('partial repair guard 2', (999, [[17000, '33.3'], [None, '40.5']]), 33267),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression final-cent-rounding 1', (1, [[94000, '12.5'], [191000, '24'], [None, '45']]), 13),
  ('regression final-cent-rounding 2', (1, [[1000, '12.5'], [59000, '24'], [None, '40.5']]), 13),
  ('partial repair guard 1', (1, [[68000, '12.5'], [81000, '10'], [167000, '33.3'], [None, '45']]), 13),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        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 int(tax * 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression final-cent-rounding 1', (46, [[None, '10']]), 460),
  ('regression final-cent-rounding 2', (41, [[None, '12.5']]), 513),
  ('partial repair guard 2', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression final-cent-rounding 1',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('regression final-cent-rounding 2', (777, [[None, '12.5']]), 9713),
  ('partial repair guard 2', (999, [[24000, '33.3'], [134000, '15'], [190000, '15'], [None, '40.5']]), 33267),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression final-cent-rounding 1', (10001, [[18000, '12.5'], [80000, '22'], [None, '30']]), 125013),
  ('regression final-cent-rounding 2', (10001, [[60000, '12.5'], [92000, '22'], [None, '45']]), 125013),
  ('partial repair guard 2', (999, [[166000, '33.3'], [178000, '10'], [None, '40.5']]), 33267),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression final-cent-rounding 1', (1, [[68000, '12.5'], [81000, '10'], [167000, '33.3'], [None, '45']]), 13),
  ('regression final-cent-rounding 2',
   (64068, [[32000, '22'], [105000, '10'], [170000, '24'], [193000, '10'], [None, '37']]), 1024680),
  ('partial repair guard 1', (10001, [[60000, '12.5'], [92000, '22'], [None, '45']]), 125013),
  ('partial repair guard 2', (999, [[17000, '33.3'], [None, '40.5']]), 33267),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression final-cent-rounding 1', (1, [[94000, '12.5'], [191000, '24'], [None, '45']]), 13),
  ('regression final-cent-rounding 2', (1, [[1000, '12.5'], [59000, '24'], [None, '40.5']]), 13),
  ('partial repair guard 1', (1, [[68000, '12.5'], [81000, '10'], [167000, '33.3'], [None, '45']]), 13),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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)

prompt:
A liability of 4.60 is reported as 459 cents.

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = min(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression larger-deduction 1', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('regression larger-deduction 2', ('single', 50000, 50000, 3000, 0, False, False), [14600, 35400]),
  ('partial repair guard 2', ('mfj', 70625, 900, 25000, 1, False, False), [30750, 39875]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression larger-deduction 1', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('regression larger-deduction 2', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('partial repair guard 1', ('hoh', 102225, 22645, 15000, 0, False, True), [21900, 80325]),
  ('partial repair guard 2', ('mfj', 828, 2000, 15000, 0, False, True), [29200, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression larger-deduction 1', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('regression larger-deduction 2', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('partial repair guard 1', ('mfs', 54568, 20000, 3000, 0, True, False), [14600, 39968]),
  ('partial repair guard 2', ('mfj', 140586, 20000, 3000, 0, True, False), [20450, 120136]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression larger-deduction 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('regression larger-deduction 2', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('partial repair guard 1', ('single', 45837, 500, 15000, 1, False, False), [16550, 29287]),
  ('partial repair guard 2', ('single', 111058, 500, 3000, 1, False, False), [16550, 94508]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression larger-deduction 1', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('regression larger-deduction 2', ('mfs', 15301, 1366, 3000, 0, True, False), [3000, 12301]),
  ('partial repair guard 1', ('mfj', 82202, 19334, 3000, 2, False, False), [32300, 49902]),
  ('partial repair guard 2', ('hoh', 26068, 20000, 3000, 0, False, True), [21900, 4168]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = itemized if itemized else s
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression larger-deduction 1', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('regression larger-deduction 2', ('single', 50000, 50000, 3000, 0, False, False), [14600, 35400]),
  ('partial repair guard 2', ('mfj', 70625, 900, 25000, 1, False, False), [30750, 39875]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression larger-deduction 1', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('regression larger-deduction 2', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('partial repair guard 1', ('hoh', 102225, 22645, 15000, 0, False, True), [21900, 80325]),
  ('partial repair guard 2', ('mfj', 828, 2000, 15000, 0, False, True), [29200, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression larger-deduction 1', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('regression larger-deduction 2', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('partial repair guard 1', ('mfs', 54568, 20000, 3000, 0, True, False), [14600, 39968]),
  ('partial repair guard 2', ('mfj', 140586, 20000, 3000, 0, True, False), [20450, 120136]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression larger-deduction 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('regression larger-deduction 2', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('partial repair guard 1', ('single', 45837, 500, 15000, 1, False, False), [16550, 29287]),
  ('partial repair guard 2', ('single', 111058, 500, 3000, 1, False, False), [16550, 94508]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression larger-deduction 1', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('regression larger-deduction 2', ('mfs', 15301, 1366, 3000, 0, True, False), [3000, 12301]),
  ('partial repair guard 1', ('mfj', 82202, 19334, 3000, 2, False, False), [32300, 49902]),
  ('partial repair guard 2', ('hoh', 26068, 20000, 3000, 0, False, True), [21900, 4168]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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)

prompt:
A taxpayer with no itemized deductions deducts nothing.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, gross - d]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taxable-floor 1', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('regression taxable-floor 2', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression taxable-floor 1', ('mfj', 828, 2000, 15000, 0, False, True), [29200, 0]),
  ('regression taxable-floor 2', ('hoh', 8066, 20000, 0, 0, False, False), [21900, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression taxable-floor 1', ('mfj', 19816, 500, 25000, 0, False, False), [29200, 0]),
  ('regression taxable-floor 2', ('mfj', 22895, 900, 3000, 0, False, True), [29200, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression taxable-floor 1', ('mfs', 10207, 2000, 15000, 0, False, True), [15000, 0]),
  ('regression taxable-floor 2', ('single', 8621, 12617, 40000, 0, True, False), [40000, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression taxable-floor 1', ('hoh', 3413, 17479, 25000, 0, False, True), [25000, 0]),
  ('regression taxable-floor 2', ('single', 7394, 900, 40000, 0, False, False), [40000, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross) - d]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taxable-floor 1', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('regression taxable-floor 2', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression taxable-floor 1', ('mfj', 828, 2000, 15000, 0, False, True), [29200, 0]),
  ('regression taxable-floor 2', ('hoh', 8066, 20000, 0, 0, False, False), [21900, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression taxable-floor 1', ('mfj', 19816, 500, 25000, 0, False, False), [29200, 0]),
  ('regression taxable-floor 2', ('mfj', 22895, 900, 3000, 0, False, True), [29200, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression taxable-floor 1', ('mfs', 10207, 2000, 15000, 0, False, True), [15000, 0]),
  ('regression taxable-floor 2', ('single', 8621, 12617, 40000, 0, True, False), [40000, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression taxable-floor 1', ('hoh', 3413, 17479, 25000, 0, False, True), [25000, 0]),
  ('regression taxable-floor 2', ('single', 7394, 900, 40000, 0, False, False), [40000, 0]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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)

prompt:
A low-income return shows negative taxable income that offsets other lines.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access