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.

"""Original synthetic enterprise cases. No network, production data or learner records.
Financial checks and exhaustive small portfolios do not establish organizational
effectiveness, legal permission, actual capability or independent academic review.
"""
from fractions import Fraction as F
from itertools import product
import json
a=sum(F(10,11)**t for t in range(1,4));results={}
def expect(name,value,target,tolerance=0.000002):
 assert abs(float(value)-target)<tolerance,(name,float(value),target)
 results[name]=float(value)
assert 120-50+25-30==65
expect('annuity_three_years',a,2.486851991)
expect('acquisition',65*a-130,31.645379)
expect('contract',30*a-20,54.605560)
expect('ownership_premium_matches_contract',65*a-90-(30*a-20),17.039820)
expect('delayed_acquisition',sum(65*F(10,11)**t for t in (2,3))-130,-27.445530)
expect('contract_extra_setup',30*a-35,39.605560)
assert 12-4-10*F(6,10)==2
assert 12-4-10*F(9,10)==-1
assert 8-3<7 and 10+10>16
assert 7+8-F(1,2)==F(29,2)
lostmonths=3*F(1,2)+3*F(1,5)
assert lostmonths==F(21,10)
assert 80+15+lostmonths*10==116
assert 80+15+lostmonths*15==F(253,2)
expect('replacement_break_even_contribution',25/lostmonths,11.904762)
assert 80+15+lostmonths*15/2==F(443,4)
assert 30+60+8+F(4,10)*10+2==104
assert 30-18-20==-8 and 18-5-4==9
assert (82-70)-(83-75)==4
assert (82-70)-(73-75)==14
expect('owned_global',55*a-100,36.776860)
expect('contract_global',45*a-30,81.908340)
expect('owned_global_lower_support',70*a-100,74.079639)
expect('owned_global_lower_setup',70*a-90,84.079639)
for spot,expected in [(F(11,10),F(55)),(F(9,10),F(45))]:
 assert (200-150)*spot==expected
 assert (200-150)*spot+(F(105,100)-spot)*50==F(105,2)
for spot,expected in [(F(11,10),F(-27,2)),(F(9,10),F(-3,2))]:
 assert (140-150)*spot+(F(105,100)-spot)*50==expected
assert 100-70-60==-30 and 100-70-20==10 and 100-40-20==40
assert 35-50==-15 and -5>-15 and 32-20==12
assert 35+20-50==5 and 32-20-25==-13
def portfolios(budget=150,hours=100,renewal=18,maintenance=0):
 candidates=[]
 for A,C,R,T in product((0,1),repeat=4):
  if A+C>1 or R>T:continue
  cash=130*A+20*C+25*R+15*T
  staff=80*A+30*C+40*R+30*T
  if cash>budget or staff>hours:continue
  value=A*(65*a-130)+C*((30-maintenance)*a-20)+R*(renewal*a-25)-15*T
  candidates.append(dict(choice=''.join(n for n,b in zip('ACRT',(A,C,R,T)) if b) or 'none',upfront=cash,hours=staff,value=value))
 return sorted(candidates,key=lambda x:x['value'],reverse=True)
p=portfolios();assert p[0]['choice']=='CRT'
expect('best_initial_portfolio',p[0]['value'],59.368896)
assert {x['choice'] for x in p}=={'CRT','C','CT','A','RT','none','T'}
assert portfolios(hours=90)[0]['choice']=='C'
assert portfolios(budget=200)[0]['choice']=='CRT'
assert portfolios(renewal=15)[0]['choice']=='C'
expect('renewal_changed_value',15*a-40,-2.697220)
expect('paid_extra_hours_incremental',18*a-40-6,-1.236664)
expect('maintenance_changed_best',portfolios(maintenance=8)[0]['value'],39.474080)
assert portfolios(maintenance=8)[0]['choice']=='CRT'
# Independently reconstruct every quantitative retained companion/native example.
assert 80-50-20==10 and 80-50-20+60==70
assert 25-35==-10 and F(25,2)-0==F(25,2)
expect('retained_acquisition_cumulative',-180+60/F(11,10)+60/F(11,10)**2+100/F(11,10)**3,-0.736289)
expect('retained_lower_savings',-180+40/F(11,10)+40/F(11,10)**2+80/F(11,10)**3,-50.473328)
expect('retained_savings_reduction',20*a,49.737040)
print(json.dumps(dict(passed=True,scope='Synthetic financial and finite-feasibility checks, not actual capability or academic acceptance',results=results,feasiblePortfolios=[{**x,'value':float(x['value'])} for x in p]),indent=2))

Related chapters