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.

"""Synthetic marketing arithmetic and finite packages only. No network or records.
These checks do not establish true incrementality, causal effects, actual qualified
capacity, legal permission, independent review or observed learner competence.
"""
from fractions import Fraction as F
from itertools import product
import json,math
out={}
def eq(name,v,target,tol=0.000002):
 assert abs(float(v)-target)<tol,(name,float(v),target)
 out[name]=float(v)
assert 9000*F(12,100)==1080
assert 1080*105-1000*100==13400
assert -10000+18000+5400==13400
assert 1080*(105-82)-1000*(100-70)==-5160
assert 80*30+1080*(23-30)==-5160
assert 1080*35==37800
assert F(11,10)*F(92,100)-1==F(12,1000)
assert 92*(220-120)==9200 and 92*(220-140)==7360
assert F(80,1000)==F(8,100)
assert F(160,400)==F(2,5) and F(80,160)==F(1,2)
assert 80*75-5000==1000
assert (110-80)*75-1500==750
assert 1500/F(75)==20 and 10*75-1500==-750
assert 30*50-1500==0
def allocations(hours=60,borders=50,aorders=80,budget=6000,extra=0):
 options={'A':(4000,60,aorders*100-4000),'B':(3000,30,borders*120-3000),'C':(2000,25,40*100-2000)}
 feasible=[]
 for flags in product((0,1),repeat=3):
  names=[n for n,b in zip(options,flags) if b];cash=sum(options[n][0] for n in names);staff=sum(options[n][1] for n in names)
  buy=500 if staff>hours and extra and staff<=hours+extra else 0
  if cash+buy>budget or staff>hours+(extra if buy else 0):continue
  feasible.append(dict(choice=''.join(names) or 'none',cash=cash+buy,hours=staff,net=sum(options[n][2] for n in names)-buy))
 return sorted(feasible,key=lambda x:x['net'],reverse=True)
initial=allocations();assert initial[0]['choice']=='BC' and initial[0]['net']==5000
assert {x['choice'] for x in initial}=={'none','A','B','C','BC'}
assert allocations(hours=50)[0]['choice']=='B'
assert allocations(borders=30)[0]['choice']=='A'
assert allocations(hours=50,borders=30)[0]['choice']=='C'
assert allocations(hours=50,borders=30,extra=10)[0]['net']==3500
assert allocations(borders=30,aorders=60)[0]['choice']=='BC'
assert math.ceil(F(5000,120))==42
assert 1000*(200-120)==80000
eq('discount_break_even_units',F(80000,60),1333.333333333)
assert math.ceil(F(80000,60))==1334 and 1200*60==72000
eq('lower_cost_break_even_units',F(80000,70),1142.857142857)
assert 1200*70==84000 and 1100*70==77000
assert 1000*(220-130)-10000==80000
assert 1000*(210-130)-10000==70000
assert 200*60-150*80==0
harvest=F(17)/F(11,10)+F(10)/F(11,10)**2
eq('harvest_value_thousand',harvest,23.719008)
eq('higher_support_harvest',harvest-F(15)/F(11,10)-F(15)/F(11,10)**2,-2.314050)
eq('replacement_transition12',-12+F(8)/F(11,10)**2,-5.388430)
eq('replacement_transition5',-5+F(8)/F(11,10)**2,1.611570)
assert 120*80-4000==5600 and 100*90-4500==4500
assert -1600+1000-500==-1100
assert 100*85-4500==4000 and -1600+500-500==-1600
assert 110*85-4500==4850 and -800+550-500==-750
assert 3000/F(75)==40 and 45*75-3000==375
assert 35*75-3000==-375 and 38*75-3000==-150
# Independently reconstruct all numerical retained companion/native cases.
assert F(990,9000)==F(11,100) and 990*110==108900
assert 990*(110-85)==24750
assert 40*(100-40)-3000==-600
assert 60*60-3500==100
assert 30*100-2000==1000 and 20*120-1500==900
assert 2000+1500>3000 and 60+20>60
assert 110*(180-120)==6600 and 100*(215-130)==8500
assert 8500-1000-8000==-500
assert -20000+8000+5000==-7000 and -20000+8000+15000==3000
assert 100*80-5000==3000 and 80*100-5500==2500
assert -1600+1600-500==-500
assert 30-20==15+25-20-10==10
assert 15+25-12-10==18
assert 100*100-250*50-3000==-5500
assert 100*100-250*20-3000==2000
print(json.dumps(dict(passed=True,scope='Synthetic reconciliations and finite feasibility, not causal or academic validation',results=out,initialFeasibleCampaigns=initial,combinedChangedFacts=allocations(hours=50,borders=30)),indent=2))

Related chapters