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 sqrt,isclose
import json
checks=[]
def eq(name,x,y):
assert x==y,(name,x,y);checks.append(dict(name=name,value=str(x)))
def near(name,x,y):
assert isclose(x,y,rel_tol=1e-8,abs_tol=1e-8),(name,x,y);checks.append(dict(name=name,value=x))
def cournot(a,c1,c2):
q1=F(a-2*c1+c2,3);q2=F(a-2*c2+c1,3);p=a-q1-q2
assert q1==F(a-c1-q2,2) and q2==F(a-c2-q1,2)
return q1,q2,p,(p-c1)*q1,(p-c2)*q2
eq('native cournot',cournot(120,30,30),(30,30,60,900,900))
eq('companion asymmetric120',cournot(120,40,30),(F(70,3),F(100,3),F(190,3),F(4900,9),F(10000,9)))
eq('companion cournot100',cournot(100,20,20),(F(80,3),F(80,3),F(140,3),F(6400,9),F(6400,9)))
eq('companion asymmetric100',cournot(100,30,20),(20,30,50,400,900))
eq('native unilateral deviation',(120-35-30-30)*35,875)
eq('native leader',(F(45),F(45,2),120-45-F(45,2)),(45,F(45,2),F(105,2)))
eq('native leader payoff',(F(105,2)-30)*45,F(2025,2))
eq('native follower payoff',(F(105,2)-30)*F(45,2),F(2025,4))
eq('companion leader100',(40,20,40,(40-20)*40,(40-20)*20),(40,20,40,800,400))
eq('differentiated native price',F(35)/(1-F(1,4)),F(140,3))
eq('differentiated native profit',(F(140,3)-20)*F(160,3),F(12800,9))
eq('differentiated conditional response',35+F(60,4),50)
eq('one cap best response2',F(90-20,2),35);eq('one cap best response1',min(20,F(90-35,2)),20)
eq('one cap outcome',(120-20-35,(120-20-35-30)*20,(120-20-35-30)*35),(65,700,1225))
eq('two cap value',(120-40-30)*20,1000)
def vl(q):return 8*q-q*q/2
def vh(q):return 12*q-q*q/2
def menu(q,alpha=F(1,2)):
tl=vl(q);th=70-4*q;ul=vl(q)-tl;uh=vh(10)-th
assert ul>=0 and uh>=0 and ul>=vl(10)-th and uh>=vh(q)-tl
return tl,th,alpha*(tl-2*q)+(1-alpha)*(th-20)
eq('fullinfo margins average',F(18+50,2),34)
eq('fullinfo high deviation',vh(6)-30,24)
for q,tl,th,profit in [(F(2),14,62,26),(F(4),24,54,25)]:eq('native menu'+str(q),menu(q),(tl,th,profit))
eq('changed alpha .8',menu(F(5),F(4,5)),(F(55,2),50,20))
eq('changed alpha .3',menu(F(0),F(3,10)),(0,70,35))
eq('menu complexity original',26-F(3,2),F(49,2));eq('menu complexity changed',20-F(3,2),F(37,2))
eq('companion premium ceiling',120-(60-40),100)
eq('companion intended contribution',(40-20)+(100-45),75)
eq('companion premium105 switches',(40-20)*2,40)
eq('companion cumulative premium ceiling',100-(40-35),95)
def both_tariff(p):
fee=F(1,2)*(8-p)**2;ql=8-p;qh=12-p;return fee,ql,qh,2*fee+(p-2)*(ql+qh)
for p,expected in [(F(2),(18,6,10,36)),(F(4),(8,4,8,40)),(F(6),(2,2,6,36))]:eq('native common tariff'+str(p),both_tariff(p),expected)
eq('native homogeneous price4',F(1,2)*8**2+2*8,48);eq('native high only fee',F(1,2)*10**2,50)
eq('companion high access fee',F(1,2)*16**2,128);eq('companion low access fee',F(1,2)*8**2,32)
eq('native separate bundle examples',(18,2*11,18),(18,22,18))
eq('companion bundle contribution',2*119-4*10,198);eq('companion changed bundle',119-2*10,99);eq('companion changed separate',80-10,70)
def ce(values,probs):return sum(p*sqrt(v) for v,p in zip(values,probs))**2
near('native certainty equivalent',ce([144,64],[.5,.5]),100)
near('native risk premium',104-ce([144,64],[.5,.5]),4)
near('native second certainty equivalent',ce([81,121],[.5,.5]),100)
near('companion lottery CE',ce([100,400],[.5,.5]),225)
wealth_ce=ce([1000,1300],[.5,.5]);near('background CE',wealth_ce,1145.087712549569)
near('background premium',1150-wealth_ce,4.912287450431)
assert 225<240 and wealth_ce>1140
near('insurance CE',ce([100,36],[.75,.25]),81);eq('full insurance maxpremium',100-81,19)
assert .75*sqrt(88)+.25*sqrt(68)>sqrt(82)
eq('project EVPI',F(2,5)*80-(F(2,5)*80-F(3,5)*40),24)
eq('changed project EVPI',F(1,5)*80-max(0,F(1,5)*80-F(4,5)*40),16)
eq('posterior10pct',F(9,100)/(F(9,100)+F(9,100)),F(1,2))
eq('posterior50pct',F(45,100)/(F(45,100)+F(5,100)),F(9,10))
eq('selection native margin',50-80,-30);eq('selection companion margin',70-100,-30);eq('selection intervention margin',70-60,10)
for effort,gain,threshold in [(6,F(1,5),30),(8,F(1,5),40),(6,F(1,10),60)]:eq('retained exposure'+str((effort,gain)),F(effort)/gain,threshold)
eq('native hidden action total',7+6+F(1,10)*30,16)
def bonus(ph,pl,cost):
b=F(cost)/(ph-pl);uh=ph*b-cost;ul=pl*b
assert uh==ul and uh>=0;return b,ph*b,100*ph-ph*b,uh
eq('native bonus',bonus(F(4,5),F(2,5),10),(25,20,60,10))
eq('native changed bonus',bonus(F(7,10),F(2,5),12),(40,28,42,16))
ph=F(9,10)*F(4,5)+F(1,10)*F(1,5);pl=F(9,10)*F(2,5)+F(1,10)*F(3,5)
eq('reported probabilities',(ph,pl),(F(37,50),F(21,50)))
b=F(10)/(ph-pl);pay=ph*b
eq('noisy bonus',b,F(125,4));eq('noisy expected payment',pay,F(185,8));eq('noisy principal true output',80-pay,F(455,8));eq('noisy agent tie',ph*b-10,pl*b)
eq('noisy principal after10cost',80-pay-10,F(375,8));eq('uninformative rate gap',F(1,2)-F(1,2),0)
def agent(share):
e=5*share;y=100+10*e;w=20+share*y;return e,y,w,w-e*e,y-w
eq('companion linear .4',agent(F(2,5)),(2,120,68,64,52));eq('companion linear .6',agent(F(3,5)),(3,130,98,89,32))
eq('companion principal share .5',50*F(1,2)*(1-F(1,2)),F(25,2))
def firstprice(v,b,u=100,n=2,k=F(1,2)):
probability=min(F(1),(F(b)/(k*u))**(n-1));return probability,(v-b)*probability
for v,b,expected in [(80,40,(F(4,5),32)),(80,30,(F(3,5),30)),(80,50,(1,30)),(60,30,(F(3,5),18))]:eq('native first price'+str((v,b)),firstprice(v,b),expected)
eq('native revenue equivalence',F(200,3)*F(1,2),F(100,3))
eq('new three bidder',firstprice(90,60,120,3,F(2,3)),(F(9,16),F(135,8)))
eq('new budget limit',firstprice(90,30,120,3,F(2,3)),(F(9,64),F(135,16)))
grid=[(firstprice(90,F(i,4),120,3,F(2,3))[1],F(i,4)) for i in range(321)]
eq('new finite bid check',max(grid),(F(135,8),60));eq('new constrained bid check',max(grid[:121]),(F(135,16),30))
eq('rubric total',6*5,30)
print(json.dumps({'passed':True,'checks':checks,'scope':'Retained and new synthetic arithmetic, incentive inequalities, best responses and finite feasibility checks; not actual market behavior, lawful conduct or observed learner testing'},indent=2))