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,actual,expected):
 assert actual==expected,(name,actual,expected);checks.append(dict(name=name,value=str(actual)))
def near(name,actual,expected):
 assert isclose(actual,expected,rel_tol=1e-8,abs_tol=1e-8),(name,actual,expected);checks.append(dict(name=name,value=actual))
def choice(m,px,py):return F(m,2*px),F(m,2*py)
for m,px,py,expected in [(120,4,2,(15,30)),(160,4,2,(20,40)),(120,2,2,(30,30)),(200,5,2,(20,50)),(120,3,2,(20,30)),(120,6,3,(10,20)),(120,12,3,(5,20)),(120,8,2,(F(15,2),30))]:eq('consumer '+str((m,px,py)),choice(m,px,py),expected)
near('old price-cut compensation X',sqrt(450),21.213203435596427)
x=sqrt(450*2/8);y=450/x;expenditure=8*x+2*y
near('new compensated X',x,sqrt(112.5));near('new compensated Y',y,sqrt(1800))
near('compensated expenditure',expenditure,2*sqrt(7200))
near('components add',x-15+7.5-x,-7.5)
eq('perfect substitutes new Y',F(120,2),60)
def market(intercept=40,tax=0,demand=240):
 pb=F(demand+intercept+3*tax,7);ps=pb-tax;q=demand-4*pb
 assert q==-intercept+3*ps
 return pb,ps,q
eq('native market',market(),(40,40,80));eq('native tax7',market(tax=7),(43,36,68));eq('native tax14',market(tax=14),(46,32,56));eq('native demand shift',market(demand=268),(44,44,92))
eq('native tax revenue7',7*68,476);eq('native tax loss7',F(1,2)*7*12,42);eq('native tax loss14',F(1,2)*14*24,168)
eq('native ceiling demand',240-4*30,120);eq('native ceiling supply',-40+3*30,50);eq('native ceiling shortage',120-50,70);eq('native ceiling lost baseline trade',80-50,30)
eq('shifted no tax',market(68),(44,44,64));eq('shifted tax7',market(68,7),(47,40,52));eq('shifted tax14',market(68,14),(50,36,40))
eq('shifted revenue7',7*52,364);eq('shifted revenue14',14*40,560)
before=F(1,2)*(60-44)*64+F(1,2)*(44-F(68,3))*64
after=F(1,2)*(60-47)*52+F(1,2)*(40-F(68,3))*52+364
eq('shifted baseline surplus',before,F(3584,3));eq('shifted taxed surplus',after,F(3458,3));eq('shifted loss',before-after,42)
for t,ps,pb,q,revenue in [(10,55,65,35,350),(20,50,70,30,600)]:
 calc_ps=F(120-t,2);eq('companion tax'+str(t),(calc_ps,calc_ps+t,calc_ps-20,t*(calc_ps-20)),(ps,pb,q,revenue))
eq('companion tax20 loss',F(1,2)*20*10,100)
def input_cost(q,w,r):
 l=q*sqrt(r/w);k=q*sqrt(w/r)
 near('technology output '+str((q,w,r)),sqrt(l*k),q)
 return l,k,w*l+r*k
for q,w,r,l,k,total in [(10,20,5,5,20,200),(20,20,5,10,40,400),(10,45,5,F(10,3),30,300),(10,4,9,15,F(20,3),120)]:
 a,b,v=input_cost(q,w,r);near('labor '+str((q,w,r)),a,float(l));near('capital '+str((q,w,r)),b,float(k));near('input cost '+str((q,w,r)),v,total)
eq('fixedK20 wage45',45*5+5*20,325);eq('companion fixedK4',4*25+9*4,136)
def tc(q):return 200+10*q+q*q
eq('nativeTC10',tc(10),400);eq('native discrete change',tc(11)-tc(10),31);eq('nativeTC20',tc(20),800)
near('native minimum ATC',200/sqrt(200)+10+sqrt(200),10+2*sqrt(200))
def competitive(p,capacity=None,fixed=100,a=4,b=1):
 q=max(F(0),F(p-a,2*b));q=min(q,capacity) if capacity is not None else q
 profit=p*q-fixed-a*q-b*q*q;return q,profit
for p,cap,q,profit in [(24,None,10,0),(20,None,8,-36),(3,None,0,-100),(4,None,0,-100),(24,6,6,-16),(24,8,8,-4),(12,None,4,-84)]:eq('native competitive '+str((p,cap)),competitive(p,cap),(q,profit))
eq('companion competitive',competitive(30,fixed=400,a=10),(10,-300))
def monopoly(a,b,mc,fixed=0,cap=None):
 q=F(a-mc,2*b);q=min(q,cap) if cap is not None else q;p=a-b*q;return q,p,(p-mc)*q-fixed
eq('native monopoly',monopoly(100,2,20,100),(20,60,700));eq('native MC28',monopoly(100,2,28),(18,64,648));eq('native MC40',monopoly(100,2,40),(15,70,450))
eq('native monopoly lost gains',F(1,2)*40*20,400);eq('native markup',F(40,60),-1/F(-3,2))
def vertical(a,b,mc):
 w=F(a+mc,2);q=F(a-w,2*b);p=a-b*q;return w,q,p,(w-mc)*q,(p-w)*q
eq('native vertical',vertical(100,2,20),(60,10,80,400,200));eq('companion vertical',vertical(100,1,20),(60,20,80,800,400));eq('companion MC40',vertical(100,1,40),(70,15,85,450,225))
eq('native w40 total',(40-20)*15+(70-40)*15,750)
eq('companion integrated',monopoly(100,1,20),(40,60,1600));eq('companion cap30',monopoly(100,1,20,cap=30),(30,70,1500));eq('companion setup1600 cap30',monopoly(100,1,20,fixed=1600,cap=30),(30,70,-100))
eq('participation lower fee',400,400);eq('participation upper fee',800-200,600)
eq('no feasible cash300 fee',max(0,min(600,300)-400),0);eq('cash450 interval upper',min(600,450),450)
def repeated(beta,c=8,d=12,p=4):return F(c)/(1-beta),F(d)+p*beta/(1-beta)
eq('native repeated .6',repeated(F(3,5)),(20,18));eq('native repeated .4',repeated(F(2,5)),(F(40,3),F(44,3)))
eq('companion repeated .5',repeated(F(1,2),3,5,1),(6,6));eq('companion repeated .4',repeated(F(2,5),3,5,1),(5,F(17,3)))
eq('expected penalty deters',12-8*F(3,5),F(36,5));eq('low detection fails',12-8*F(2,5),F(44,5))
beta=F(3,5)*F(4,5);eq('discount survival product',beta,F(12,25));eq('new incentive values',repeated(beta),(F(200,13),F(204,13)))
eq('survival threshold',F(1,2)/F(3,5),F(5,6));eq('new survival .9 effective',F(3,5)*F(9,10),F(27,50));assert repeated(F(27,50))[0]>repeated(F(27,50))[1]
eq('rubric total',6*5,30)
print(json.dumps({'passed':True,'checks':checks,'scope':'Original and new synthetic derivation, consistency and arithmetic checks; not observed learning, actual taxes, lawful coordination or contract approval'},indent=2))

Related chapters