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.
from fractions import Fraction as F
from math import sqrt,erfc,isclose,ceil
import json
checks=[]
def ck(name,actual,expected):
assert actual==expected,(name,actual,expected)
checks.append(dict(case=name,actual=str(actual),expected=str(expected)))
ck('Trial extra observed purchases',30-20,10)
ck('Trial cost all one hundred',100*20,2000)
ck('Trial net all prospects incur cost',10*150-2000,-500)
ck('Trial net only thirty buyers incur cost',10*150-30*20,900)
ck('Large-buyer contribution per selling hour',F(1000,10),F(100))
ck('Office contribution per selling hour',F(300,2),F(150))
ck('Twenty-hour all-office contribution',10*300,3000)
ck('Twenty-hour all-large-buyer contribution',2*1000,2000)
ck('Office cap mixed feasible contribution',4*300+1000,2200)
ck('Office cap mixed hours',4*2+10,18)
ck('Survey respondent satisfaction only',F(80,100),F(4,5))
ck('Survey response relative to original list only',F(100,1000),F(1,10))
ck('Follow-up respondents, not whole-frame rate',F(25,50),F(1,2))
ck('Separate experiment control conversion',F(50,500),F(1,10))
ck('Separate experiment treatment conversion',F(65,500),F(13,100))
ck('Separate experiment rate difference',F(65,500)-F(50,500),F(3,100))
ck('Separate experiment relative uplift',F(65,50)-1,F(3,10))
ck('Separate experiment net at forty contribution',15*40-800,-200)
ck('Separate experiment net at seventy contribution',15*70-800,250)
ck('Original cohort customer retention',F(150,200),F(3,4))
ck('New arrivals restore active count without changing cohort',150+50,200)
ck('Original cohort revenue retention',F(18000,20000),F(9,10))
ck('Expansion case revenue retention',F(22000,20000),F(11,10))
a=F(40,200);b=F(50,200);difference=b-a
ck('Cumulative control rate',a,F(1,5))
ck('Cumulative treatment rate',b,F(1,4))
ck('Cumulative difference',difference,F(1,20))
ck('Cumulative relative uplift',difference/a,F(1,4))
ck('Observed incremental contribution',10*80-600,200)
ck('Observed incremental contribution after returns',10*80-600-300,-100)
ck('Whole purchases for positive contribution before returns',int(F(600,80))+1,8)
ck('Whole purchases for positive contribution after returns',int(F(900,80))+1,12)
variance=a*(1-a)/200+b*(1-b)/200
ck('Unpooled approximate variance',variance,F(139,80000))
se=sqrt(float(variance));lo=float(difference)-1.96*se;hi=float(difference)+1.96*se
assert isclose(se,.0416833300013333,rel_tol=1e-10) and -.0318<lo<-.0316 and .1316<hi<.1318
pooled=F(90,400);nullse=sqrt(float(pooled*(1-pooled)*(F(1,200)+F(1,200))))
z=float(difference)/nullse;pvalue=erfc(abs(z)/sqrt(2))
assert 1.19<z<1.20 and .23<pvalue<.24
checks.append(dict(case='Limited independent-Bernoulli approximate inference; not design validation',unpooledSE=se,roughWald95=[lo,hi],pooledNullZ=z,twoSidedNormalP=pvalue))
print(json.dumps(dict(passed=True,scope='Synthetic numerical mechanisms and explicitly approximate independent-proportion diagnostic; not evidence of real study validity or learner competence',checks=checks)))