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.

"""Original AI course checkpoints; synthetic standard-library-only calculations.
No model service, network, actual identity, production data or learner records.
Independent units use different supplied subcases; do not combine denominators.
"""
from fractions import Fraction as F
from math import ceil,log,isclose
import json
checks={}
def check(k,v):assert v,k;checks[k]=True
def handling(rate):return 2+3+rate*5
def value(rate):return (8-handling(rate))*F(1000,60)*30-800
check('workflow_original',handling(F(1,5))==6 and value(F(1,5))==200)
check('payback_conditional',F(3000,200)==15)
check('changed_correction',handling(F(1,2))==F(15,2) and value(F(1,2))==-550)
check('template_alternative',(8-7)*F(1000,60)*30-100==400)
check('separate_inquiry_case',400+1000*(F(2,60)*30+F(1,10))==1500)
check('inquiry_correction',400+1000*(1+F(1,10)+F(1,5)*3)==2100)
check('partial_eligibility',500*3+400+500*F(11,10)==2450)
check('inquiry_break_even',ceil(F(400)/F(19,10))==211 and ceil(F(400)/F(13,10))==308 and ceil(F(2400)/F(13,10))==1847)
check('advanced_policy_costs',20*50+90*2==1180 and 10*50+180*2==860)
check('loss_reversal',20*50+90*10==1900 and 10*50+180*10==2300)
check('alert_capacity',80+90==170<=200 and 90+180==270>200)
check('classification_denominators',F(80,170)==F(8,17) and F(80,100)==F(4,5) and F(80+810,1000)==F(89,100))
documents=[dict(id='A1',account='A',start=0,end=11),dict(id='A2',account='A',start=11,end=20),dict(id='B1',account='B',start=0,end=20)]
def context(scope,account,t):
 if account not in scope:raise PermissionError('Outside scope')
 return [d['id'] for d in documents if d['account']==account and d['start']<=t<d['end']]
check('current_temporal_context',context({'A'},'A',12)==['A2'])
check('separate_historical_scope',context({'A'},'A',10)==['A1'])
try:context({'A'},'B',12)
except PermissionError:pass
else:raise AssertionError('cross-account context allowed')
check('review_original',60*F(3,10)*F(4,60)==F(6,5))
check('review_changed',60*F(1,2)*F(5,60)==F(5,2) and F(5,2)/2==F(5,4)>1)
check('conditional_detection',F(1,10)*(1-F(4,5))==F(1,50))
upper=lambda n:1-.05**(1/n)
check('zero_failure_bounds',.0487<upper(60)<.0488 and .0099<upper(300)<.0100)
n=ceil(log(.05)/log(.99))
check('minimum_integer_sample',n==299 and upper(n)<=.01<upper(n-1))
check('twelve_month_undiscounted',12*700-4000==4400)
check('coverage_and_error',F(900,1000)==F(9,10) and F(9,900)==F(1,100) and F(450,1000)==F(9,20)<F(4,5) and F(3,450)==F(1,150))
check('abstention_review_cohort',550*4==2200 and F(2200,60)==F(110,3))
print(json.dumps(dict(passed=True,checks=checks,scope='Synthetic arithmetic and stipulated serial boundary examples only; not production identity, execution, model performance or learner testing.'),indent=2))

Related chapters