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 synthetic arithmetic, experimental-method and contingent-policy calculations, not independent academic acceptance or production migration safety.
"""Original MBA683 synthetic calculations. Standard library; no network or records."""
from fractions import Fraction as F
from math import sqrt,erfc,isclose,floor,comb
from itertools import combinations,product
import json
checks=[]
def eq(name,x,y):
assert isclose(float(x),float(y),rel_tol=1e-10,abs_tol=1e-8),(name,x,y)
checks.append(dict(case=name,value=float(x),expected=float(y)))
eq('old aggregate',F(60,200),.30);eq('new aggregate',F(125,400),.3125)
eq('raw difference points',(F(125,400)-F(60,200))*100,1.25)
eq('equal mix new',(F(120,300)+F(5,100))/2,.225)
eq('equal mix change points',(.225-.30)*100,-7.5)
eq('new mix old',F(3,4)*F(1,2)+F(1,4)*F(1,10),.40)
eq('new mix change points',(.3125-.4)*100,-8.75)
eq('paid funnel overall',F(10,1000),.01);eq('paid funnel conditional',F(10,30),F(1,3))
eq('cohort first net',10*(150-90)-600,0)
eq('cohort second net',6*(150-90),360)
eq('renewal',F(6,10),.6);eq('per paid acquisition',600/10,60);eq('per retained acquisition',600/6,100)
eq('costly renewal',6*(150-160),-60)
projects={'A':(4000,8000,10),'B':(3000,6000,6),'C':(2000,5000,6)}
def portfolios(budget,hours):
result=[]
for k in range(4):
for selected in combinations(projects,k):
cost=sum(projects[p][0] for p in selected);value=sum(projects[p][1]-projects[p][0] for p in selected);h=sum(projects[p][2] for p in selected)
if cost<=budget and h<=hours:result.append(dict(selected=selected,cost=cost,hours=h,net=value))
return sorted(result,key=lambda x:x['net'])
assert portfolios(5000,10)[-1]['selected']==('A',)
assert portfolios(5000,12)[-1]['selected']==('B','C')
eq('two hours at1000 incremental gain',6000-1000-4000,1000)
eq('two hours at2500 net',6000-2500,3500)
assert 3000+2000+1000>5000
checks.append(dict(case='all resource-feasible subsets',passed=True,initial=portfolios(5000,10),expanded=portfolios(5000,12)))
pc=F(56,400);diff=F(36,200)-F(20,200);se=sqrt(pc*(1-pc)*(F(1,200)+F(1,200)));z=float(diff)/se
eq('pooled null standard error',se,.03469870314579494)
eq('original two-proportion z',z,2.30556167081694)
eq('approximate two-sided p',erfc(z/sqrt(2)),.02113513706757147)
eq('additional point completions',200*diff,16)
eq('rollout atcost600',200*diff*30-600,-120)
eq('rollout atcost300',200*diff*30-300,180)
eq('ten independent null tests',1-F(95,100)**10,.4012630607616213)
# Independent conditional null enumeration: all possible allocations of56 successes.
# This exact randomization benchmark differs from the published normal approximation.
den=comb(400,200);weights=[]
for x in range(57):
if 0<=200-x<=344:
weights.append((x,F(comb(56,x)*comb(344,200-x),den)))
assert sum(p for _,p in weights)==1
exact=sum(p for x,p in weights if abs(2*x-56)>=16)
assert 0<float(exact)<.05
checks.append(dict(case='independent exact null allocation benchmark',conditionalTwoSided=float(exact),normalApproximation=erfc(z/sqrt(2)),passed=True,limits='Conditional fixed-margin benchmark under exchangeability, not a remedy for clustering or biased recruitment.'))
finite=lambda m,r,n:sum(F(m)*F(r)**j for j in range(n))
eq('three opportunity contribution',finite(25,F(7,10),3),54.75)
eq('three opportunity net',finite(25,F(7,10),3)-90,-35.25)
eq('six opportunity contribution',finite(25,F(7,10),6),73.52925)
eq('six opportunity net',finite(25,F(7,10),6)-90,-16.47075)
eq('infinite net',F(25)/(1-F(7,10))-90,F(-20,3))
eq('higher service infinite net',F(15)/(1-F(7,10))-90,-40)
eq('fifty before receipts',5000-1200-50*90,-700)
eq('fifty after net contribution',5000-1200-50*90+50*25,550)
eq('whole cohort cash limit',floor(F(5000-1200-500,90)),36)
assert 5000-1200-36*90>=500 and 5000-1200-37*90<500
prior=F(2,5);sens=F(4,5);fp=F(1,5)
states=[dict(success=True,positive=True,p=prior*sens),dict(success=False,positive=True,p=(1-prior)*fp),dict(success=True,positive=False,p=prior*(1-sens)),dict(success=False,positive=False,p=(1-prior)*(1-fp))]
assert sum(s['p'] for s in states)==1
pos=sum(s['p'] for s in states if s['positive']);neg=1-pos
eq('positive probability',pos,.44);eq('positive posterior',prior*sens/pos,F(8,11));eq('negative posterior',prior*(1-sens)/neg,F(1,7))
eq('no information launch',prior*100+(1-prior)*(-100),-20)
eq('perfect information',prior*100,40);eq('perfect fee45',prior*100-45,-5)
def policy(opening,fee,reserve):
# Enumerate all four deterministic signal-dependent action rules; enforce every dated reserve.
out=[]
for launch_pos,launch_neg in product([False,True],repeat=2):
rows=[]
if opening-fee<reserve:continue
for s in states:
launch=launch_pos if s['positive'] else launch_neg
before_receipt=opening-fee-(100 if launch else 0)
if before_receipt<reserve:break
closing=before_receipt+(200 if launch and s['success'] else 0)
rows.append(dict(**s,launch=launch,beforeReceipt=before_receipt,closing=closing))
if len(rows)==4:out.append(dict(positive=launch_pos,negative=launch_neg,value=sum(s['p']*(s['closing']-opening) for s in rows),states=rows))
return max(out,key=lambda x:x['value']) if out else None
p=policy(105,5,0);assert p['positive'] and not p['negative'];eq('funded test net',p['value'],15)
assert [s['closing'] for s in p['states']]==[200,0,100,100]
eq('expected funded closing',sum(s['p']*s['closing'] for s in p['states']),120)
eq('unfunded test actual',policy(100,5,0)['value'],-5)
eq('reserve blocks favorable launch',policy(105,5,10)['value'],-5)
p2=policy(115,5,10);eq('reserve funded test net',p2['value'],15)
assert [s['closing'] for s in p2['states']]==[210,10,110,110]
eq('costly imperfect test',policy(125,25,0)['value'],-5)
checks.append(dict(case='independent enumeration of all contingent policies',passed=True,fundedActions=dict(positive=p['positive'],negative=p['negative']),cashUnit='thousands'))
# Retained native and full companion calculations are reconstructed without changing them.
eq('retained interviews counted',4+3+2+1,10)
eq('retained paid pilots revenue',3*200,600);eq('retained paid contribution',3*(200-80),360)
eq('retained first acquisition net',360-900,-540);eq('retained renewal net',720-900,-180)
eq('retained prototype completion',F(8,10),.8)
eq('retained manual margin',20-25,-5)
eq('retained expected remediation',F(1,5)*30,6);eq('retained automated margin',20-8-6,6)
eq('retained three paid months',3*(40-15)-90,-15)
eq('retained recovery',F(90,25),3.6);eq('retained six months',6*25-90,60)
eq('retained changed cost recovery',F(90,15),6);eq('retained changed three months',3*15-90,-45)
eq('retained test A net',7000-4000,3000);eq('retained test B net',5000-3000,2000)
assert 4000+3000>5000
eq('retained cumulative future test',8000-5000,3000)
eq('retained perfect pilot net',F(4,10)*100000-10000,30000)
eq('retained perfect pilot expensive',F(4,10)*100000-45000,-5000)
def clean(v):
if isinstance(v,F):return float(v)
raise TypeError(type(v).__name__)
print(json.dumps(dict(passed=True,checks=checks,limits='Synthetic model/code verification only; no empirical validation, independent subject review, observed learner testing or operating approval.'),default=clean))
Related chapters
- Define a problem that survives changes in the denominator
- Discover an opportunity through paid behavior and a traceable funnel
- Select alternatives with real constraints before applying scores
- Design an experiment whose result supports the claim being made
- Connect paid demand to retained contribution and affordable delivery
- Fund experiments only when learning can change a feasible later action
- Cumulative dossier: choose an informative experiment whose result can still be funded