Lawfare Group → Knowledge Institute → Lawfare Academy

Reproduce the worked examples

Copy the complete code below into a UTF-8 file named verify.py and run python verify.py with Python 3. It uses only the standard library and performs exact or rational synthetic calculations. It does not access a network or learner records. Assertions fail if the expected synthetic results change.

These checks verify the stated arithmetic and query behavior, not independent academic acceptance or production migration safety.

"""Cypress synthetic risk/control laboratory; no actual records or assurance."""
from fractions import Fraction as F
import json
checks={}
def check(n,a,b):
 assert a==b,(n,a,b)
 checks[n]=str(a)
check('base expected annual loss',F(5,100)*100000,5000)
check('residual expected annual loss',F(2,100)*100000,2000)
check('control and residual expected total',1500+2000,3500)
check('modeled expected advantage',5000-3500,1500)
check('changed control effectiveness',1500+F(4,100)*100000,5500)
check('independent joint barrier failure',F(1,10)*F(1,5),F(1,50))
assert F(1,10)>F(1,50)
def toy_payment(loss,deductible,limit):return min(max(loss-deductible,0),limit)
check('toy covered payment',toy_payment(15000,1000,10000),10000)
check('toy retained adverse loss',15000-10000,5000)
check('single adverse period with premium',5000+800,5800)
check('toy small loss payment',toy_payment(600,1000,10000),0)
check('single small loss period with premium',600+800,1400)
check('observed sample exception fraction',F(0,60),0)
population=10000;issues=50;nonissues=population-issues
tp=issues*F(4,5);fn=issues-tp;fp=nonissues*F(1,50);tn=nonissues-fp
check('true issue flags',tp,40);check('missed issues',fn,10)
check('false issue flags',fp,199);check('true nonissue cases',tn,9751)
check('screening population reconciliation',tp+fn+fp+tn,population)
check('all flags',tp+fp,239)
check('issue fraction among flags',tp/(tp+fp),F(40,239))
changed_tp=500*F(4,5);changed_fp=9500*F(1,50)
check('changed prevalence true flags',changed_tp,400)
check('changed prevalence false flags',changed_fp,190)
check('changed prevalence flagged fraction',changed_tp/(changed_tp+changed_fp),F(40,59))
check('elapsed interruption hours',20-13,7)
check('recovery point gap hours',13-10,3)
check('incorrect engineer-only duration',20-14,6)
assert 7<=8 and 3<=4
check('daily net cash',2000-3000,-1000)
check('cash after15days',30000+15*(2000-3000),15000)
check('cash at20day floor',30000+20*(2000-3000),10000)
check('cash above floor',30000-10000,20000)
check('no-receipts continuous floor horizon',F(20000,3000),F(20,3))
check('no-receipts exhaustion horizon',F(30000,3000),10)
print(json.dumps(dict(passed=True,checks=checks,limits='Synthetic assumptions only. Calculations establish no empirical risk, control effectiveness, actual policy coverage, fraud or intent, population zero-deviation rate, legal liability, independent assurance or real recovery capability. Independent subject review and observed learner testing remain pending.'),indent=2))

Related chapters