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.

"""Alder operations laboratory. Exact synthetic models, not empirical validation."""
from fractions import Fraction as F
from math import isqrt
import json
checks={}
def check(n,a,b):
 assert a==b,(n,a,b)
 checks[n]=str(a)
capacities=[F(60,6),F(60,10),F(60,8)]
check('serial capacity',min(capacities),6)
check('parallel assembly line capacity',min(capacities[0],2*capacities[1],capacities[2]),F(15,2))
check('available assembly hours',8*F(3,4),6)
check('available day output',6*6,36)
check('scrap-only accepted flow',6*F(9,10),F(27,5))
check('matched flow time days',F(24,6),4)
jobs=[(F(0),F(2)),(F(1),F(4)),(F(2),F(3))]
times=sorted({t for job in jobs for t in job});area=F(0)
for a,b in zip(times,times[1:]):
 n=sum(entry<=a<exit for entry,exit in jobs)
 area+=n*(b-a)
check('finite inventory area',area,6)
horizon=times[-1]-times[0];avg_inventory=area/horizon
mean_time=sum(exit-entry for entry,exit in jobs)/len(jobs)
check('trace average inventory',avg_inventory,F(3,2))
check('trace mean time',mean_time,2)
check('trace Little reconciliation',F(len(jobs))/horizon*mean_time,avg_inventory)
check('changed policy conditional flow time',F(18,4),F(9,2))
def mm1(arrival,service):
 if arrival<0 or service<=0 or arrival>=service:raise ValueError('Finite stable M/M/1 requires0<=arrival<service.')
 rho=arrival/service;W=1/(service-arrival);Wq=W-1/service
 return dict(rho=rho,L=arrival*W,W=W,Wq=Wq,Lq=arrival*Wq)
base=mm1(F(4),F(5));high=mm1(F(9,2),F(5))
for k,v in dict(rho=F(4,5),L=4,W=1,Wq=F(4,5),Lq=F(16,5)).items():check('base queue '+k,base[k],v)
for k,v in dict(rho=F(9,10),L=9,W=2,Wq=F(9,5),Lq=F(81,10)).items():check('higher queue '+k,high[k],v)
check('arrival relative increase',(F(9,2)-4)/4,F(1,8))
for lam in [F(5),F(6)]:
 try:mm1(lam,F(5))
 except ValueError:checks['overload rejected '+str(lam)]='True'
 else:raise AssertionError('Overload accepted')
def waits(arrivals,service_minutes):
 finish=F(0);out=[]
 for arrival in arrivals:
  start=max(arrival,finish);out.append(start-arrival);finish=start+service_minutes
 return out
check('spaced deterministic waits',waits([F(0),F(15),F(30)],F(12)),[0,0,0])
check('burst deterministic waits',waits([F(0),F(0),F(0)],F(12)),[0,12,24])
D=1200;S=50;H=3;rad=F(2*D*S,H);Q=isqrt(rad.numerator)
assert Q*Q==rad
check('EOQ',Q,200)
def relevant_cost(q,s=50):return F(D,q)*s+F(q,2)*H
check('EOQ relevant annual cost',relevant_cost(200),600)
check('quantity100 relevant cost',relevant_cost(100),750)
check('quantity400 relevant cost',relevant_cost(400),750)
check('reorder point',6*5+10,40)
check('inventory position',35+20-5,50)
check('supplierA total',1200*20+600+400+200,25200)
check('supplierB total',1200*F(39,2)+1000+600+300,25300)
check('supplierB changed total',25300-200,25100)
check('independent joint failure',F(1,10)**2,F(1,100))
check('baseline defective rate',F(20,200),F(1,10))
check('new defective rate',F(15,300),F(1,20))
check('absolute rate drop',F(1,10)-F(1,20),F(1,20))
check('relative rate reduction',(F(1,10)-F(1,20))/F(1,10),F(1,2))
check('defective count reduction',F(20-15,20),F(1,4))
check('subgroup4 lower limit',100-3*F(2,2),97)
check('subgroup4 upper limit',100+3*F(2,2),103)
check('subgroup16 lower limit',100-3*F(2,4),F(197,2))
check('subgroup16 upper limit',100+3*F(2,4),F(203,2))
check('illustrativeCp',F(105-95,6*2),F(5,6))
check('illustrativeCpk',min(F(105-101,3*2),F(101-95,3*2)),F(2,3))
print(json.dumps(dict(passed=True,checks=checks,limits='Synthetic arithmetic and finite traces do not establish empirical distributions, stable capability, service probability, causal improvement, safety, current trade rules or actual resource availability. Independent subject review and learner testing remain pending.'),indent=2))

Related chapters