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.

"""Fictional workshop procurement laboratory; independent subcases."""
from fractions import Fraction as F
import math,json
checks={}
def check(n,a,b):
 assert a==b,(n,a,b)
 checks[n]=str(a)
def close(n,a,b):
 assert math.isclose(a,b,rel_tol=1e-8,abs_tol=1e-8),(n,a,b)
 checks[n]=a
def ceil(f):return -(-f.numerator//f.denominator)
check('original A expected usable',1000*F(95,100),950)
check('original A purchase',1000*8,8000)
bq=ceil(F(900)/F(99,100));check('original B order',bq,910)
check('original B purchase',bq*F(83,10),7553)
check('original B expected usable',bq*F(99,100),F(9009,10))
check('original B with freight',7553+600,8153)
aq=ceil(F(1100)/F(95,100)/1000)*1000
check('changed A minimum lots',aq,2000);check('changed A purchase',aq*8,16000)
bq2=ceil(F(1100)/F(96,100));check('changed B order',bq2,1146)
check('changed B purchase',bq2*F(83,10),F(47559,5))
check('changed B expected usable',bq2*F(96,100),F(27504,25))
a_total=8000+200+150+50*4+F(1,10)*2000
b_total=7553+600+100+20+F(91,10)*4+F(3,100)*2000
check('A modeled specified total',a_total,8750)
check('B modeled specified total',b_total,F(41847,5))
check('base modeled advantage',a_total-b_total,F(1903,5))
check('B freight crossover',600+a_total-b_total,F(4903,5))
check('changed freight total',b_total+500,F(44347,5))
check('changed freight disadvantage',b_total+500-a_total,F(597,5))
check('changed disruption total',b_total-60+500,F(44047,5))
check('changed disruption disadvantage',b_total-60+500-a_total,F(297,5))
d=12000;k=75;h=3;qstar=math.sqrt(2*d*k/h)
close('restricted EOQ',qstar,774.5966692414834)
cost=lambda q:d/q*k+q/2*h
close('annual cost at775',cost(775),2323.7903225806454)
close('annual ordering cost at775',d/775*k,1161.2903225806451)
check('annual cost at1000',F(d,1000)*k+F(1000,2)*h,2400)
close('modeled annual difference',cost(1000)-cost(775),76.20967741935465)
assert cost(qstar)<=cost(775) and cost(qstar)<=cost(1000)
check('base lead time demand',40*8,320);check('normal-model reorder point',320+2*30,380)
close('normal-model nonexceedance',F(1,2)*(1+math.erf(2/math.sqrt(2))),0.9772498680518208)
check('changed lead time demand',40*10,400)
check('shipment on time rate',F(18,20),F(9,10));check('shipment acceptance rate',F(16,20),F(4,5))
check('observed joint shipment rate',F(14,20),F(7,10));check('unsupported independent product',F(18,20)*F(16,20),F(18,25))
check('separate component sample fraction',F(5,100),F(1,20))
check('discounted invoice',10000*F(98,100),9800)
check('simple funding cost12pct',9800*F(12,100)*F(30,360),98)
check('narrow net discount saving',200-98,102)
close('simple annualized trade credit comparison',float(F(200,9800)*F(360,30)),0.24489795918367346)
check('funding cost18pct',9800*F(18,100)*F(30,360),147)
check('changed net discount saving',200-147,53)
common=F(5,100);specific=F(1,10)
check('single supplier marginal failure',common+(1-common)*specific,F(29,200))
check('common-cause joint failure',common+(1-common)*specific*specific,F(119,2000))
check('wrong marginal product',(common+(1-common)*specific)**2,F(841,40000))
check('separate-route independent joint',specific*specific,F(1,100))
check('changed common-cause joint',F(1,10)+F(9,10)*specific*specific,F(109,1000))
check('shortfall after one300-unit supply fails',600-300,300)
check('zero observed sample fraction',F(0,60),0)
upper=1-math.pow(0.05,F(1,60));close('zero-in60 binomial upper bound',upper,0.04870291331009751)
close('upper bound equation',(1-upper)**60,0.05)
check('rule of three approximation',F(3,60),F(1,20))
check('price reduction minus additional attributable cost',500-650,-150)
print(json.dumps(dict(passed=True,checks=checks,limits='Independent fictional subcases, not actual supplier measurements or one transaction. Expected yield is not a guarantee; EOQ and normal service interpretation require their assumptions; cycle probability is not fill rate; observed fractions are not causal findings; sample bounds require the stated binomial model. No legal entitlement, financial transaction, supplier assurance, independent subject review or learner completion is established.'),indent=2))

Related chapters