FAILURE MAP
← Case archive

FA-62911 / Insurance premium rating / Open access

Deductible credit interpolation: Negative credits round toward zero · case 01

Surcharge amounts are off by a cent in the insured's favour.

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

ROOT CAUSE

int() truncates toward zero, so half-up on negative credits moves the wrong way.

VERIFIED REPAIR

Use floor(v+1/2) for both signs.

Unsuccessful approach: Banker's rounding still differs on exact half-cent surcharges.

Case contract

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

Why this case matters

Premium rating engines apply ordered tabular rules where one misplaced boundary or step silently misprices policies.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tab=x['table']; d=x['deductible']; prem=x['premium']
    if d<0 or not tab: return 'invalid'
    if d<=tab[0][0]: c=Fraction(tab[0][1])
    elif d>=tab[-1][0]: c=Fraction(tab[-1][1])
    else:
        i=0
        while tab[i+1][0]<d: i+=1
        d0,c0=tab[i]; d1,c1=tab[i+1]
        c=c0+Fraction(c1-c0)*(d-d0)/(d1-d0)
    credit=int(prem*c/1000+Fraction(1,2))
    return [credit, prem-credit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['base deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 50000, 'premium': 261724}, [0, 261724]], ['interpolated low segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 78500, 'premium': 331983}, [11543, 320440]], ['interpolated upper segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 481000, 'premium': 116345}, [23939, 92406]], ['beyond largest tabulated deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 751000, 'premium': 322204}, [67985, 254219]], ['exact largest deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 500000, 'premium': 393848}, [83102, 310746]], ['zero deductible uses lowest row', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 0, 'premium': 210458}, [-631, 211089]], ['deductible below table surcharged', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 10000, 'premium': 199242}, [-598, 199840]], ['negative deductible rejected', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': -100, 'premium': 226782}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 25000, 'premium': 22500}, [-67, 22567]], ['interior knot', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 250000, 'premium': 94197}, [13376, 80821]]], [['base deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 50000, 'premium': 199101}, [0, 199101]], ['interpolated low segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 86000, 'premium': 159529}, [7121, 152408]], ['interpolated upper segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 369000, 'premium': 114198}, [20141, 94057]], ['beyond largest tabulated deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 752000, 'premium': 110216}, [23366, 86850]], ['exact largest deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 500000, 'premium': 313269}, [66413, 246856]], ['zero deductible uses lowest row', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 0, 'premium': 174100}, [-870, 174970]], ['deductible below table surcharged', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 10000, 'premium': 243190}, [-1216, 244406]], ['negative deductible rejected', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': -100, 'premium': 214814}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 25000, 'premium': 23500}, [-117, 23617]], ['interior knot', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 250000, 'premium': 349563}, [50337, 299226]]], [['base deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 50000, 'premium': 263025}, [0, 263025]], ['interpolated low segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 55000, 'premium': 117616}, [741, 116875]], ['interpolated upper segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 315000, 'premium': 209271}, [34199, 175072]], ['beyond largest tabulated deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 753000, 'premium': 115225}, [24543, 90682]], ['exact largest deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 500000, 'premium': 322765}, [68749, 254016]], ['zero deductible uses lowest row', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 0, 'premium': 297017}, [-2079, 299096]], ['deductible below table surcharged', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 10000, 'premium': 263626}, [-1845, 265471]], ['negative deductible rejected', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': -100, 'premium': 120680}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 25000, 'premium': 24500}, [-171, 24671]], ['interior knot', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 250000, 'premium': 301911}, [44079, 257832]]], [['base deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 50000, 'premium': 340242}, [0, 340242]], ['interpolated low segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 96500, 'premium': 240169}, [14295, 225874]], ['interpolated upper segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 339000, 'premium': 148801}, [25519, 123282]], ['beyond largest tabulated deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 754000, 'premium': 216687}, [46371, 170316]], ['exact largest deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 500000, 'premium': 388433}, [83125, 305308]], ['zero deductible uses lowest row', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 0, 'premium': 394112}, [-3547, 397659]], ['deductible below table surcharged', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 10000, 'premium': 145337}, [-1308, 146645]], ['negative deductible rejected', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': -100, 'premium': 335212}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 25000, 'premium': 25500}, [-229, 25729]], ['interior knot', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 250000, 'premium': 128496}, [19017, 109479]]], [['base deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 50000, 'premium': 113213}, [0, 113213]], ['interpolated low segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 56500, 'premium': 364381}, [3079, 361302]], ['interpolated upper segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 374000, 'premium': 322937}, [58852, 264085]], ['beyond largest tabulated deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 755000, 'premium': 161418}, [34705, 126713]], ['exact largest deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 500000, 'premium': 386131}, [83018, 303113]], ['zero deductible uses lowest row', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 0, 'premium': 264667}, [-2911, 267578]], ['deductible below table surcharged', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 10000, 'premium': 141161}, [-1553, 142714]], ['negative deductible rejected', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': -100, 'premium': 190310}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 25000, 'premium': 26500}, [-291, 26791]], ['interior knot', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 250000, 'premium': 86734}, [13010, 73724]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
base deductible[0, 261724][0, 261724]Passed
interpolated low segment[11543, 320440][11543, 320440]Passed
interpolated upper segment[23939, 92406][23939, 92406]Passed
beyond largest tabulated deductible[67985, 254219][67985, 254219]Passed
exact largest deductible[83102, 310746][83102, 310746]Passed
zero deductible uses lowest row[-630, 211088][-631, 211089]Failed
deductible below table surcharged[-597, 199839][-598, 199840]Failed
negative deductible rejectedinvalidinvalidPassed
surcharge tie rounds toward positive[-67, 22567][-67, 22567]Passed
interior knot[13376, 80821][13376, 80821]Passed

SHA-256 / e7d3f044be64d28dec348272a8cde8a8e1fd5f6e7bf790e90a64fb208fe9fe5d

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tab=x['table']; d=x['deductible']; prem=x['premium']
    if d<0 or not tab: return 'invalid'
    if d<=tab[0][0]: c=Fraction(tab[0][1])
    elif d>=tab[-1][0]: c=Fraction(tab[-1][1])
    else:
        i=0
        while tab[i+1][0]<d: i+=1
        d0,c0=tab[i]; d1,c1=tab[i+1]
        c=c0+Fraction(c1-c0)*(d-d0)/(d1-d0)
    credit=round(prem*c/1000)
    return [credit, prem-credit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['base deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 50000, 'premium': 261724}, [0, 261724]], ['interpolated low segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 78500, 'premium': 331983}, [11543, 320440]], ['interpolated upper segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 481000, 'premium': 116345}, [23939, 92406]], ['beyond largest tabulated deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 751000, 'premium': 322204}, [67985, 254219]], ['exact largest deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 500000, 'premium': 393848}, [83102, 310746]], ['zero deductible uses lowest row', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 0, 'premium': 210458}, [-631, 211089]], ['deductible below table surcharged', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 10000, 'premium': 199242}, [-598, 199840]], ['negative deductible rejected', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': -100, 'premium': 226782}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 25000, 'premium': 22500}, [-67, 22567]], ['interior knot', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 250000, 'premium': 94197}, [13376, 80821]]], [['base deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 50000, 'premium': 199101}, [0, 199101]], ['interpolated low segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 86000, 'premium': 159529}, [7121, 152408]], ['interpolated upper segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 369000, 'premium': 114198}, [20141, 94057]], ['beyond largest tabulated deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 752000, 'premium': 110216}, [23366, 86850]], ['exact largest deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 500000, 'premium': 313269}, [66413, 246856]], ['zero deductible uses lowest row', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 0, 'premium': 174100}, [-870, 174970]], ['deductible below table surcharged', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 10000, 'premium': 243190}, [-1216, 244406]], ['negative deductible rejected', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': -100, 'premium': 214814}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 25000, 'premium': 23500}, [-117, 23617]], ['interior knot', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 250000, 'premium': 349563}, [50337, 299226]]], [['base deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 50000, 'premium': 263025}, [0, 263025]], ['interpolated low segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 55000, 'premium': 117616}, [741, 116875]], ['interpolated upper segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 315000, 'premium': 209271}, [34199, 175072]], ['beyond largest tabulated deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 753000, 'premium': 115225}, [24543, 90682]], ['exact largest deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 500000, 'premium': 322765}, [68749, 254016]], ['zero deductible uses lowest row', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 0, 'premium': 297017}, [-2079, 299096]], ['deductible below table surcharged', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 10000, 'premium': 263626}, [-1845, 265471]], ['negative deductible rejected', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': -100, 'premium': 120680}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 25000, 'premium': 24500}, [-171, 24671]], ['interior knot', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 250000, 'premium': 301911}, [44079, 257832]]], [['base deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 50000, 'premium': 340242}, [0, 340242]], ['interpolated low segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 96500, 'premium': 240169}, [14295, 225874]], ['interpolated upper segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 339000, 'premium': 148801}, [25519, 123282]], ['beyond largest tabulated deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 754000, 'premium': 216687}, [46371, 170316]], ['exact largest deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 500000, 'premium': 388433}, [83125, 305308]], ['zero deductible uses lowest row', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 0, 'premium': 394112}, [-3547, 397659]], ['deductible below table surcharged', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 10000, 'premium': 145337}, [-1308, 146645]], ['negative deductible rejected', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': -100, 'premium': 335212}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 25000, 'premium': 25500}, [-229, 25729]], ['interior knot', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 250000, 'premium': 128496}, [19017, 109479]]], [['base deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 50000, 'premium': 113213}, [0, 113213]], ['interpolated low segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 56500, 'premium': 364381}, [3079, 361302]], ['interpolated upper segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 374000, 'premium': 322937}, [58852, 264085]], ['beyond largest tabulated deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 755000, 'premium': 161418}, [34705, 126713]], ['exact largest deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 500000, 'premium': 386131}, [83018, 303113]], ['zero deductible uses lowest row', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 0, 'premium': 264667}, [-2911, 267578]], ['deductible below table surcharged', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 10000, 'premium': 141161}, [-1553, 142714]], ['negative deductible rejected', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': -100, 'premium': 190310}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 25000, 'premium': 26500}, [-291, 26791]], ['interior knot', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 250000, 'premium': 86734}, [13010, 73724]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
base deductible[0, 261724][0, 261724]Passed
interpolated low segment[11543, 320440][11543, 320440]Passed
interpolated upper segment[23939, 92406][23939, 92406]Passed
beyond largest tabulated deductible[67985, 254219][67985, 254219]Passed
exact largest deductible[83102, 310746][83102, 310746]Passed
zero deductible uses lowest row[-631, 211089][-631, 211089]Passed
deductible below table surcharged[-598, 199840][-598, 199840]Passed
negative deductible rejectedinvalidinvalidPassed
surcharge tie rounds toward positive[-68, 22568][-67, 22567]Failed
interior knot[13376, 80821][13376, 80821]Passed

SHA-256 / d56b96fa65f128d13bcbd0c3eeb67c7edef2a9a313ca0d44669c90e53eef2594

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tab=x['table']; d=x['deductible']; prem=x['premium']
    if d<0 or not tab: return 'invalid'
    if d<=tab[0][0]: c=Fraction(tab[0][1])
    elif d>=tab[-1][0]: c=Fraction(tab[-1][1])
    else:
        i=0
        while tab[i+1][0]<d: i+=1
        d0,c0=tab[i]; d1,c1=tab[i+1]
        c=c0+Fraction(c1-c0)*(d-d0)/(d1-d0)
    credit=math.floor(prem*c/1000+Fraction(1,2))
    return [credit, prem-credit]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['base deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 50000, 'premium': 261724}, [0, 261724]], ['interpolated low segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 78500, 'premium': 331983}, [11543, 320440]], ['interpolated upper segment', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 481000, 'premium': 116345}, [23939, 92406]], ['beyond largest tabulated deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 751000, 'premium': 322204}, [67985, 254219]], ['exact largest deductible', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 500000, 'premium': 393848}, [83102, 310746]], ['zero deductible uses lowest row', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 0, 'premium': 210458}, [-631, 211089]], ['deductible below table surcharged', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 10000, 'premium': 199242}, [-598, 199840]], ['negative deductible rejected', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': -100, 'premium': 226782}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 25000, 'premium': 22500}, [-67, 22567]], ['interior knot', {'table': [[25000, -3], [50000, 0], [100000, 61], [250000, 142], [500000, 211]], 'deductible': 250000, 'premium': 94197}, [13376, 80821]]], [['base deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 50000, 'premium': 199101}, [0, 199101]], ['interpolated low segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 86000, 'premium': 159529}, [7121, 152408]], ['interpolated upper segment', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 369000, 'premium': 114198}, [20141, 94057]], ['beyond largest tabulated deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 752000, 'premium': 110216}, [23366, 86850]], ['exact largest deductible', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 500000, 'premium': 313269}, [66413, 246856]], ['zero deductible uses lowest row', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 0, 'premium': 174100}, [-870, 174970]], ['deductible below table surcharged', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 10000, 'premium': 243190}, [-1216, 244406]], ['negative deductible rejected', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': -100, 'premium': 214814}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 25000, 'premium': 23500}, [-117, 23617]], ['interior knot', {'table': [[25000, -5], [50000, 0], [100000, 62], [250000, 144], [500000, 212]], 'deductible': 250000, 'premium': 349563}, [50337, 299226]]], [['base deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 50000, 'premium': 263025}, [0, 263025]], ['interpolated low segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 55000, 'premium': 117616}, [741, 116875]], ['interpolated upper segment', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 315000, 'premium': 209271}, [34199, 175072]], ['beyond largest tabulated deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 753000, 'premium': 115225}, [24543, 90682]], ['exact largest deductible', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 500000, 'premium': 322765}, [68749, 254016]], ['zero deductible uses lowest row', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 0, 'premium': 297017}, [-2079, 299096]], ['deductible below table surcharged', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 10000, 'premium': 263626}, [-1845, 265471]], ['negative deductible rejected', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': -100, 'premium': 120680}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 25000, 'premium': 24500}, [-171, 24671]], ['interior knot', {'table': [[25000, -7], [50000, 0], [100000, 63], [250000, 146], [500000, 213]], 'deductible': 250000, 'premium': 301911}, [44079, 257832]]], [['base deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 50000, 'premium': 340242}, [0, 340242]], ['interpolated low segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 96500, 'premium': 240169}, [14295, 225874]], ['interpolated upper segment', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 339000, 'premium': 148801}, [25519, 123282]], ['beyond largest tabulated deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 754000, 'premium': 216687}, [46371, 170316]], ['exact largest deductible', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 500000, 'premium': 388433}, [83125, 305308]], ['zero deductible uses lowest row', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 0, 'premium': 394112}, [-3547, 397659]], ['deductible below table surcharged', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 10000, 'premium': 145337}, [-1308, 146645]], ['negative deductible rejected', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': -100, 'premium': 335212}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 25000, 'premium': 25500}, [-229, 25729]], ['interior knot', {'table': [[25000, -9], [50000, 0], [100000, 64], [250000, 148], [500000, 214]], 'deductible': 250000, 'premium': 128496}, [19017, 109479]]], [['base deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 50000, 'premium': 113213}, [0, 113213]], ['interpolated low segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 56500, 'premium': 364381}, [3079, 361302]], ['interpolated upper segment', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 374000, 'premium': 322937}, [58852, 264085]], ['beyond largest tabulated deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 755000, 'premium': 161418}, [34705, 126713]], ['exact largest deductible', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 500000, 'premium': 386131}, [83018, 303113]], ['zero deductible uses lowest row', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 0, 'premium': 264667}, [-2911, 267578]], ['deductible below table surcharged', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 10000, 'premium': 141161}, [-1553, 142714]], ['negative deductible rejected', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': -100, 'premium': 190310}, 'invalid'], ['surcharge tie rounds toward positive', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 25000, 'premium': 26500}, [-291, 26791]], ['interior knot', {'table': [[25000, -11], [50000, 0], [100000, 65], [250000, 150], [500000, 215]], 'deductible': 250000, 'premium': 86734}, [13010, 73724]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
base deductible[0, 261724][0, 261724]Passed
interpolated low segment[11543, 320440][11543, 320440]Passed
interpolated upper segment[23939, 92406][23939, 92406]Passed
beyond largest tabulated deductible[67985, 254219][67985, 254219]Passed
exact largest deductible[83102, 310746][83102, 310746]Passed
zero deductible uses lowest row[-631, 211089][-631, 211089]Passed
deductible below table surcharged[-598, 199840][-598, 199840]Passed
negative deductible rejectedinvalidinvalidPassed
surcharge tie rounds toward positive[-67, 22567][-67, 22567]Passed
interior knot[13376, 80821][13376, 80821]Passed

SHA-256 / d8143b057c5f753e8c81b5267b7a28222a7c5667173b46f4a298c6600336effb

Verification & scope

A deterministic bounded teaching model of a stipulated toy rating contract. Amounts are integer cents and factors exact rationals; it makes no claim of conformance with any filed rating plan, bureau manual or jurisdiction. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:47:09.318142+00:00.

Case digest / e7b774e0c7f585d5ee4204f813d84f470359c7cc47b335ed2732c11bff22cda6