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, field-workflow and contingent-policy calculations, not independent academic acceptance or production migration safety.
"""Original MBA685 synthetic model checks. No network, credentials, files or databases."""
from fractions import Fraction as F
from math import isclose
from itertools import product
import json,copy
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('field total accuracy',F(891+80,1000),.971)
eq('ordinary accuracy',F(891,900),.99);eq('difficult accuracy',F(80,100),.8)
eq('changed field mix',F(8,10)*F(99,100)+F(2,10)*F(8,10),.952)
eq('equal field mix',F(1,2)*F(99,100)+F(1,2)*F(8,10),.895)
eq('new full workflow minutes',1000*(2+3)+100*20,7000)
eq('released workflow hours',F(10000-7000,60),50)
eq('fully captured value',50*40-1200-400,400)
eq('partly captured value',30*40-1200-400,-400)
eq('longer exceptions value',F(10000-8000,60)*40-1600,F(-800,3))
eq('serial independent availability',F(999,1000)*F(95,100)*F(99,100),.9395595)
eq('observed outage union',16+4-2,18)
eq('observed availability',F(720-18,720),.975)
eq('fully overlapping availability',F(720-(16+4-4),720),F(44,45))
eq('nonoverlapping availability',F(720-20,720),F(35,36))
eq('accepted offline completion',80+15,95)
assert 80+15+3+2==100 and 80+18==98
eq('sequential useful recovery',2+3+1,6)
eq('actually parallel useful recovery',max(2,3)+1,4)
eq('sequential requirement gap',6-4,2)
assert 24>4 # Maximum age of the only recoverable state does not meet the stated4-hour objective.
def confusion(n,prevalence,sensitivity,fp):
urgent=n*prevalence;ordinary=n-urgent
return dict(tp=urgent*sensitivity,fn=urgent*(1-sensitivity),fp=ordinary*fp,tn=ordinary*(1-fp))
a=confusion(10000,F(1,100),F(9,10),F(5,100));b=confusion(10000,F(1,100),F(8,10),F(1,100))
assert a==dict(tp=90,fn=10,fp=495,tn=9405)
assert b==dict(tp=80,fn=20,fp=99,tn=9801)
eq('positive predictive value',a['tp']/(a['tp']+a['fp']),F(2,13))
eq('original overall accuracy',(a['tp']+a['tn'])/10000,.9495)
eq('never urgent aggregate',F(9900,10000),.99)
eq('original review hours',(a['tp']+a['fp'])*F(3,60),29.25)
eq('changed review hours',(b['tp']+b['fp'])*F(3,60),8.95)
assert F(585*3,60)>20 and F(179*3,60)<=20
eq('original stipulated consequence',a['fn']*1000+a['fp']*5,12475)
eq('changed stipulated consequence',b['fn']*1000+b['fp']*5,20495)
eq('partner commercial margin',500-200-80-40-100,80)
eq('partner300 net',300*80-20000,4000)
eq('higher partner fee margin',500-200-80-40-180,0)
eq('direct commercial margin',500-200-80-40-50,130)
eq('direct300 net',300*130-45000,-6000)
eq('direct600 net',600*130-45000,33000)
eq('partner600 net',600*80-20000,28000)
eq('direct crossover',F(25000,130-80),500)
eq('higher direct setup crossover',F(40000,50),800)
eq('higher direct setup600',600*130-60000,18000)
prior=F(2,5);sens=F(3,4);fp=F(1,4)
states=[dict(useful=True,positive=True,p=prior*sens),dict(useful=False,positive=True,p=(1-prior)*fp),dict(useful=True,positive=False,p=prior*(1-sens)),dict(useful=False,positive=False,p=(1-prior)*(1-fp))]
assert sum(s['p'] for s in states)==1
actions={'none':dict(cost=0,receipt=(0,0)),'build':dict(cost=50,receipt=(120,0)),'buy':dict(cost=10,receipt=(22,22)),'partner':dict(cost=20,receipt=(50,24))}
def net(action,useful):
d=actions[action];return d['receipt'][0 if useful else 1]-d['cost']
no_values={a:prior*net(a,True)+(1-prior)*net(a,False) for a in actions}
assert max(no_values,key=no_values.get)=='partner'
eq('no-test build',no_values['build'],-2);eq('no-test partner',no_values['partner'],14.4)
eq('perfect information gross',prior*70+(1-prior)*12,35.2)
eq('perfect information net',prior*70+(1-prior)*12-6,29.2)
eq('perfect incremental advantage',F(292,10)-F(144,10),14.8)
pos=sum(s['p'] for s in states if s['positive']);neg=1-pos
eq('positive probability',pos,.45);eq('positive useful posterior',prior*sens/pos,F(2,3))
eq('negative useful posterior',prior*(1-sens)/neg,F(2,11))
eq('positive build conditional',F(2,3)*70+F(1,3)*(-50),30)
eq('positive partner conditional',F(2,3)*30+F(1,3)*4,F(64,3))
eq('negative build conditional',F(2,11)*70+F(9,11)*(-50),F(-310,11))
eq('negative partner conditional',F(2,11)*30+F(9,11)*4,F(96,11))
def policies(opening,fee,reserve=0):
results=[]
for positive,negative in product(actions,repeat=2):
rows=[]
for s in states:
action=positive if s['positive'] else negative;d=actions[action]
before=opening-fee-d['cost']
if before<reserve:break
closing=before+d['receipt'][0 if s['useful'] else 1]
rows.append(dict(**s,action=action,beforeReceipt=before,closing=closing,net=closing-opening))
if len(rows)==4:results.append(dict(positive=positive,negative=negative,value=sum(s['p']*s['net'] for s in rows),states=rows))
return max(results,key=lambda p:p['value'])
p=policies(56,6);assert p['positive']=='build' and p['negative']=='buy'
eq('funded imperfect pilot net',p['value'],14.1)
eq('imperfect gross',p['value']+6,20.1)
eq('imperfect fee threshold',F(201,10)-no_values['partner'],5.7)
p55=policies(55,6);assert p55['positive']=='partner' and p55['negative']=='buy'
eq('unfunded build pilot net',p55['value'],10.2)
pcheap=policies(56,F(11,2));eq('cheaper funded pilot',pcheap['value'],14.6)
p60=policies(60,6,5);assert p60['positive']=='partner';eq('reserve blocks build',p60['value'],10.2)
p61=policies(61,6,5);assert p61['positive']=='build';eq('reserve funded high fee',p61['value'],14.1)
p61cheap=policies(61,F(11,2),5);eq('reserve funded cheaper fee',p61cheap['value'],14.6)
eq('actual extra delay defeats pilot',p61cheap['value']-1,13.6)
checks.append(dict(case='all16 signal-contingent policies independently enumerated',passed=True,funded=p,unfundedBuild=p55,reserveCase=p60))
# Isolated memory-only transaction illustration. It does not connect to any actual service.
record={'version':1,'text':'original synthetic work'};requests={};events=[]
def commit(actor,request_id,expected_version,text):
if actor!='authorized-writer':events.append('denied');return 'denied'
if request_id in requests:
return 'duplicate' if requests[request_id]==(expected_version,text) else 'request-id-conflict'
if expected_version!=record['version']:events.append('stale');return 'stale'
requests[request_id]=(expected_version,text);record.update(version=record['version']+1,text=text);events.append('committed');return 'committed'
initial=copy.deepcopy(record)
assert commit('reader','R003',1,'change')=='denied' and record==initial
assert commit('authorized-writer','R003',1,'accepted synthetic work')=='committed'
assert commit('authorized-writer','R003',1,'accepted synthetic work')=='duplicate' and record['version']==2
assert commit('authorized-writer','R003',1,'different')=='request-id-conflict'
assert commit('authorized-writer','R004',1,'stale work')=='stale' and record['text']=='accepted synthetic work'
checks.append(dict(case='isolated authorization version and retry illustration',passed=True,limits='Single-process teaching model; not durable concurrency, cryptographic identity or production security assurance.'))
# Reconstruct retained native and companion cases without changing them.
eq('retained scanner full saving',200*(8-3)-200*2-100,500)
eq('retained scanner net',F(500,60)*30-250,0)
eq('retained scanner reduced verification',F(700,60)*30-250,100)
eq('retained cloud monthly',100+F(5,100)*10000,600)
eq('retained cloud annual',600*12,7200)
eq('retained local annual',400*12+3000,7800)
eq('retained lower transfer annual',(100+F(5,100)*2000)*12,2400)
eq('retained restore gap days',4-1,3)
eq('retained overall ticket accuracy',F(980,1000),.98)
eq('retained urgent accuracy',F(12,20),.6)
eq('retained improved urgent accuracy',F(19,20),.95)
eq('retained sensor margin',200-80-50-40,30)
eq('retained sensor unrecovered',300*30-12000,-3000)
eq('retained sensor recovery',F(12000,30),400)
eq('retained changed sensor recovery',F(12000,10),1200)
eq('retained information advantage',9000-4000-3000-1000,1000)
eq('retained delayed information advantage',9000-4000-3000-3000,-1000)
eq('retained field net monthly',F(1200-200,60)*30-200,300)
eq('retained field recovery',F(4000,300),F(40,3))
eq('retained doubled failures net',F(1200-400,60)*30-200,200)
eq('retained doubled failures recovery',F(4000,200),20)
eq('retained native direct adoption',F(1,2)*120000+F(1,2)*(-80000),20000)
eq('retained native perfect pilot',F(1,2)*120000-15000,45000)
eq('retained native pilot advantage',45000-20000,25000)
eq('retained native higher-prior adoption',F(9,10)*120000+F(1,10)*(-80000),100000)
eq('retained native higher-prior pilot',F(9,10)*120000-15000,93000)
def clean(v):
if isinstance(v,F):return float(v)
raise TypeError(type(v).__name__)
print(json.dumps(dict(passed=True,checks=checks,limits='Original synthetic calculations and bounded in-memory illustrations only; real input validity, operating security, authority, independent review and observed learner competence remain unestablished.'),default=clean))
Related chapters
- Translate a technical function into reliable and useful field performance
- Design connectivity and recovery around the useful workflow
- Evaluate security and recovery through implemented evidence
- Evaluate AI through consequential errors and a workable review process
- Build a commercial system around the technology rather than its factory margin
- Value a technology pilot against the best feasible alternative
- Cumulative dossier: adopt a field technology only within evidence, authority and funding