{"abstract":"When the largest line is a credit, the difference is booked to a small debit line instead.","category":"Currency rounding and FX conversion","checks":6,"contract":"solve(lines, rate, exp): lines are source-currency decimal strings (credits negative), rate a decimal string, exp the target exponent. The converted total is round_half_even(sum(lines)*rate) at exp. Each line is converted and rounded half-even individually; the difference between the converted total and the sum of converted lines is posted in full to the line with the largest absolute source amount (earliest on ties). Return the converted lines as plain strings; zero lines are unsigned. An empty invoice returns [].","evaluation_group":"w2-currency_rounding_and_fx_conversion-invoice-line-conversion-plug","failed_approach":"Using absolute source amounts but breaking ties toward the last line still moves the plug on equal lines.","family":"w2-currency_rounding_and_fx_conversion-invoice-line-conversion-plug-plug-line-selection","id":"FA-61951","implementations":{"attempt":{"sha256":"d53de30810b1175404db19a139c70896b555f8a498abf80b8524d21f7c5c6c83","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN\nN = 1\nobservations = []\ndef solve(lines, rate, exp):\n    r = Decimal(rate)\n    qt = Decimal(1).scaleb(-exp)\n    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)\n    src = [Decimal(l) for l in lines]\n    if not src: return []\n    conv = [q(v * r) for v in src]\n    total = q(sum(src, Decimal(0)) * r)\n    diff = total - sum(conv, Decimal(0))\n    i = max(range(len(conv)), key=lambda k: (abs(src[k]), k))\n    conv[i] += diff\n    return [format(abs(c) if c == 0 else c, 'f') for c in conv]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]\nfor label, args, expected in cases[N - 1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"c31bbbc9061d1be0da448f5ef467cfbde2e628850713cd31dd13c01f731a7be7","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN\nN = 1\nobservations = []\ndef solve(lines, rate, exp):\n    r = Decimal(rate)\n    qt = Decimal(1).scaleb(-exp)\n    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)\n    src = [Decimal(l) for l in lines]\n    if not src: return []\n    conv = [q(v * r) for v in src]\n    total = q(sum(src, Decimal(0)) * r)\n    diff = total - sum(conv, Decimal(0))\n    i = max(range(len(conv)), key=lambda k: conv[k])\n    conv[i] += diff\n    return [format(abs(c) if c == 0 else c, 'f') for c in conv]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]\nfor label, args, expected in cases[N - 1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"3db9a4b210d333570648b1aeefecbf798e58b4bfd8a395bf306efec4fa59b1e1","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN\nN = 1\nobservations = []\ndef solve(lines, rate, exp):\n    r = Decimal(rate)\n    qt = Decimal(1).scaleb(-exp)\n    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)\n    src = [Decimal(l) for l in lines]\n    if not src: return []\n    conv = [q(v * r) for v in src]\n    total = q(sum(src, Decimal(0)) * r)\n    diff = total - sum(conv, Decimal(0))\n    i = max(range(len(conv)), key=lambda k: (abs(src[k]), -k))\n    conv[i] += diff\n    return [format(abs(c) if c == 0 else c, 'f') for c in conv]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),\n  ('control: tiny credit', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),\n  ('control: empty invoice', ([], '1.1', 2), []),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150'])],\n [('regression plug-line-selection 1', (['72.78', '-142.93'], '10.9958', 3), ['800.274', '-1571.629']),\n  ('partial repair guard 1', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),\n  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),\n  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),\n  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),\n  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]\nfor label, args, expected in cases[N - 1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-currency_rounding_and_fx_conversion-invoice-line-conversion-plug-plug-line-selection","generated_at":"2026-09-29T14:47:00.037009+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.","repair":"Choose the line with the largest absolute source amount, earliest index on ties.","root_cause":"The plug line is chosen by the signed converted value rather than the absolute source amount.","sha256":"0addd1324cdcff6d01a95cc9bbb448a993738cde040429325caecc38e586dd80","title":"The rounding plug lands on the largest signed converted line · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":46.253,"exit_code":1,"observations":[{"actual":["800.274","-1571.629"],"check":"regression plug-line-selection 1","expected":["800.274","-1571.629"],"passed":true},{"actual":["5.00","5.00","5.02"],"check":"partial repair guard 1","expected":["5.02","5.00","5.00"],"passed":false},{"actual":["-5.00","5.00"],"check":"control: credit and debit","expected":["-5.00","5.00"],"passed":true},{"actual":["30.00","0.00"],"check":"control: tiny credit","expected":["30.00","0.00"],"passed":true},{"actual":[],"check":"control: empty invoice","expected":[],"passed":true},{"actual":["3026","758","150"],"check":"control: yen target","expected":["3026","758","150"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression plug-line-selection 1\", \"actual\": [\"800.274\", \"-1571.629\"], \"expected\": [\"800.274\", \"-1571.629\"], \"passed\": true}, {\"check\": \"partial repair guard 1\", \"actual\": [\"5.00\", \"5.00\", \"5.02\"], \"expected\": [\"5.02\", \"5.00\", \"5.00\"], \"passed\": false}, {\"check\": \"control: credit and debit\", \"actual\": [\"-5.00\", \"5.00\"], \"expected\": [\"-5.00\", \"5.00\"], \"passed\": true}, {\"check\": \"control: tiny credit\", \"actual\": [\"30.00\", \"0.00\"], \"expected\": [\"30.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: empty invoice\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: yen target\", \"actual\": [\"3026\", \"758\", \"150\"], \"expected\": [\"3026\", \"758\", \"150\"], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":41.277,"exit_code":1,"observations":[{"actual":["800.275","-1571.630"],"check":"regression plug-line-selection 1","expected":["800.274","-1571.629"],"passed":false},{"actual":["5.02","5.00","5.00"],"check":"partial repair guard 1","expected":["5.02","5.00","5.00"],"passed":true},{"actual":["-5.00","5.00"],"check":"control: credit and debit","expected":["-5.00","5.00"],"passed":true},{"actual":["30.00","0.00"],"check":"control: tiny credit","expected":["30.00","0.00"],"passed":true},{"actual":[],"check":"control: empty invoice","expected":[],"passed":true},{"actual":["3026","758","150"],"check":"control: yen target","expected":["3026","758","150"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression plug-line-selection 1\", \"actual\": [\"800.275\", \"-1571.630\"], \"expected\": [\"800.274\", \"-1571.629\"], \"passed\": false}, {\"check\": \"partial repair guard 1\", \"actual\": [\"5.02\", \"5.00\", \"5.00\"], \"expected\": [\"5.02\", \"5.00\", \"5.00\"], \"passed\": true}, {\"check\": \"control: credit and debit\", \"actual\": [\"-5.00\", \"5.00\"], \"expected\": [\"-5.00\", \"5.00\"], \"passed\": true}, {\"check\": \"control: tiny credit\", \"actual\": [\"30.00\", \"0.00\"], \"expected\": [\"30.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: empty invoice\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: yen target\", \"actual\": [\"3026\", \"758\", \"150\"], \"expected\": [\"3026\", \"758\", \"150\"], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":43.684,"exit_code":0,"observations":[{"actual":["800.274","-1571.629"],"check":"regression plug-line-selection 1","expected":["800.274","-1571.629"],"passed":true},{"actual":["5.02","5.00","5.00"],"check":"partial repair guard 1","expected":["5.02","5.00","5.00"],"passed":true},{"actual":["-5.00","5.00"],"check":"control: credit and debit","expected":["-5.00","5.00"],"passed":true},{"actual":["30.00","0.00"],"check":"control: tiny credit","expected":["30.00","0.00"],"passed":true},{"actual":[],"check":"control: empty invoice","expected":[],"passed":true},{"actual":["3026","758","150"],"check":"control: yen target","expected":["3026","758","150"],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression plug-line-selection 1\", \"actual\": [\"800.274\", \"-1571.629\"], \"expected\": [\"800.274\", \"-1571.629\"], \"passed\": true}, {\"check\": \"partial repair guard 1\", \"actual\": [\"5.02\", \"5.00\", \"5.00\"], \"expected\": [\"5.02\", \"5.00\", \"5.00\"], \"passed\": true}, {\"check\": \"control: credit and debit\", \"actual\": [\"-5.00\", \"5.00\"], \"expected\": [\"-5.00\", \"5.00\"], \"passed\": true}, {\"check\": \"control: tiny credit\", \"actual\": [\"30.00\", \"0.00\"], \"expected\": [\"30.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: empty invoice\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: yen target\", \"actual\": [\"3026\", \"758\", \"150\"], \"expected\": [\"3026\", \"758\", \"150\"], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}