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 ceil
from itertools import product
import json
def near(a,b,tol=.015):assert abs(float(a)-float(b))<tol,(a,b)
def total(q,external=F(1)):
benefit=100*q-F(q*q,2);private=benefit-20*q;harm=external*q*q/2
return benefit,private,harm,private-harm
assert total(80)==(4800,3200,3200,0)
assert total(40)==(3200,2400,800,1600)
assert total(0)[3]==0 and total(100)[3]==-2000
assert total(40)[1]-40*40==800 and 800+1600-800==1600
assert 1600-200==1400
q=F(160,3);assert 100-q==20+F(1,2)*q
assert F(80)-F(3,2)*q==0;near(total(q,F(1,2))[3],F(6400,3))
assert 1400000-500000==900000
assert 1400000-180000-120000==1100000
assert 100000-180000==-80000
def lifecycle(n,wash=F(1,100)):
objects=ceil(F(1000,n));climate=F(3,2)*objects+1000*wash;water=3*objects+200
return dict(objects=objects,climate=climate,water=water)
assert F(3,2)/38+F(1,100)<F(5,100)
assert F(3,2)/37+F(1,100)>F(5,100)
assert lifecycle(38)==dict(objects=27,climate=F(101,2),water=281)
assert lifecycle(39)==dict(objects=26,climate=49,water=278)
assert lifecycle(40)['climate']==F(95,2)
assert lifecycle(20)==dict(objects=50,climate=85,water=350)
assert min(n for n in range(1,1001) if lifecycle(n)['climate']<50)==39
assert min(n for n in range(1,1001) if lifecycle(n,F(25,1000))['climate']<50)==63
assert lifecycle(61,F(25,1000))['climate']==F(101,2)
assert lifecycle(63,F(25,1000))['climate']==49
assert F(49,50)-1==F(-2,100) and F(278,100)-1==F(178,100)
assert F(85,50)-1==F(7,10)
assert 90*5==450 and 100*7==700
assert F(30,100)/F(60,100)==F(1,2)
assert F(50,100)/F(55,100)==F(10,11)
old=[100,200,700];new=[90,150,810]
assert sum(old)==1000 and sum(new)==1050
assert F(sum(new[:2]),sum(old[:2]))-1==F(-2,10)
assert F(sum(new),sum(old))-1==F(5,100)
assert F(sum(new),1200)==F(875,1000)
assert F(875,1000)-1==F(-125,1000)
assert 1050-100==950
assert 90+150+700==940;near(F(940,1200)-1,-.21666667,.00000001)
ann=sum(F(10,11)**t for t in range(1,4));energy=-30000+15000*ann;waste=-20000+9000*ann
near(energy,7302.7798648);near(waste,2381.6679189)
near(-20000+7000*ann,-2592.0360631)
def candidates(budget,hours):
out=[]
for required,e,w in product([0,1],repeat=3):
cost=15000*required+30000*e+20000*w;used=40*required+80*e+50*w
if required and cost<=budget and used<=hours:out.append(dict(required=required,energy=e,waste=w,cost=cost,hours=used,optionalNPV=float(e*energy+w*waste)))
return out
normal=candidates(45000,100);more=candidates(45000,120)
assert len(normal)==2 and max(normal,key=lambda x:x['optionalNPV'])['waste']==1
assert max(more,key=lambda x:x['optionalNPV'])['energy']==1
assert 15000+30000+5000==50000 and 40+80==120
assert 15000+20000==35000 and 40+50==90
assert 15000+30000+20000==65000 and 40+80+50==170
# Reconstruct the complete retained native and companion examples.
assert 40000-55000==-15000
assert (40000-15000)-(55000-45000)==15000
assert (40000-15000)-(55000-20000)==-10000
assert 15000-(-15000)==30000 and -10000-(-15000)==5000
assert F(9,12)-1==F(-1,4) and 12*2000==24000 and 9*3000==27000
assert F(27000,24000)-1==F(125,1000)
assert 27000-6000==21000
assert F(85,100)*F(140,100)==F(119,100)
assert 10*1000==10000 and 8*2000==16000 and F(16000,10000)-1==F(6,10)
assert F(8000,10000)-1==F(-2,10)
print(json.dumps(dict(passed=True,scope='Synthetic marginal,inventory,lifecycle and resource-feasibility arithmetic;not an ethical optimizer,empirical assessment,permit or technical assurance.',privateChoice=list(map(float,total(80))),socialChoice=list(map(float,total(40))),finiteLifecycleThreshold=39,changedWashThreshold=63,lifecycle39={k:float(v) for k,v in lifecycle(39).items()},energyNPV=float(energy),wasteNPV=float(waste),originalFeasible=normal,changedStaffFeasible=more,retainedCasesPassed=True,networkAccess=False,learnerAccess=False),indent=2))
Related chapters
- Translate corporate purpose into contested and accountable choices
- Derive marginal externality choices and keep incidence visible
- Compare lifecycle service with finite horizons and multiple impact measures
- Test practical access, job relevance and meaningful participation
- Reconcile emissions boundaries, intensity and credible environmental claims
- Build a responsibility portfolio within budget, capacity and evidence gates
- Cumulative clinic: boundaries, distribution and a feasible responsibility portfolio