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 synthetic operating, dated-cash and enterprise-valuation calculations, not independent academic acceptance or production migration safety.
"""Original synthetic capstone verification. No network, credentials or learner records."""
from fractions import Fraction as F
from itertools import product
from math import isclose
import json
checks=[]
def eq(name,x,y):
assert isclose(float(x),float(y),rel_tol=1e-9,abs_tol=1e-5),(name,x,y)
checks.append(dict(case=name,value=float(x),expected=float(y)))
d=F(10,11);a2=d+d*d;a3=a2+d**3;a4=a3+d**4
eq('retained contribution',70*(200-120)-4000,1600)
eq('unrecovered return cost',1600-10*50,1100)
orders={'X':(200,120),'Y':(200,120)};events=['X','X','Y']
eq('naive duplicated contribution',sum(orders[x][0]-orders[x][1] for x in events),240)
eq('correct order grain less actual support',sum(p-c for p,c in orders.values())-10*len(events),130)
projects=[(12,5),(8,4),(7,3)]
portfolios=[(sum(t*v for t,(_,v) in zip(bits,projects)),bits) for bits in product([0,1],repeat=3) if sum(t*c for t,(c,_) in zip(bits,projects))<=15]
assert max(portfolios)==(7,(0,1,1))
assert max(x for x in portfolios if not(x[1][1] and x[1][2]))==(5,(1,0,0))
def narrow(action,p,concession=0):
return {'A':(6+16*p)*a3-40+concession,'B':(8+2*p)*a3-20,'wait':F(0)}[action]
eq('A high state',narrow('A',1),14.71074380165);eq('A low state',narrow('A',0),-25.07888805409)
eq('B high state',narrow('B',1),4.86851990984);eq('B low state',narrow('B',0),-.105184072126)
eq('narrow probability crossover',(20/a3+2)/14,.717306862322)
eq('complete WC crossover',(20+3*(1-d**3)+2*a3)/(14*a3),.738735433751)
for p,expected in [(F(3,5),(-1.205108940646,2.879038317055)),(F(4,5),(6.752817430503,3.873779113449))]:
for action,value in zip(['A','B'],expected):eq('expected '+action+' at '+str(p),narrow(action,p),value)
# Independent dense rational parameter grid checks endpoint extrema and all feasible rivals.
grid=[F(500+i,1000) for i in range(401)]
def criteria(concession):
values={action:[narrow(action,p,concession) for p in grid] for action in ['A','B','wait']}
worst={action:min(v) for action,v in values.items()}
regrets={action:max(max(values[r][i] for r in values)-v for i,v in enumerate(vs)) for action,vs in values.items()}
return worst,regrets
w,r=criteria(0);assert max(w,key=w.get)=='B' and min(r,key=r.get)=='B'
eq('A worst parameter regret',r['A'],7.565740045079);eq('B worst parameter regret',r['B'],6.360631104433)
w,r=criteria(2);assert max(w,key=w.get)=='B' and min(r,key=r.get)=='A'
eq('A price concession regret',r['A'],5.565740045079);eq('B rival concession regret',r['B'],8.360631104433)
eq('separate teams schedule',2+2+max(3,3)+1,8);eq('shared expert schedule',2+2+3+3+1,11)
eq('real acceleration net',3*3000-3000,6000);eq('acceleration tie',3*1000-3000,0)
eq('retained ramp six-month net',2*500+4*3000-4000,9000)
eq('retained changed ramp',4*500+2*3000-4000,4000)
def cashpath(opening,flows):
out=[]
for flow in flows:opening+=flow;out.append(opening)
return out
assert cashpath(12000,[-5000,-6000,-3000])==[7000,1000,-2000]
assert cashpath(12000,[-5000,-2000,-3000,-4000])==[7000,5000,2000,-2000]
assert cashpath(12000,[-5000,-2000,-3000,3000-4000])[-1]==1000<2000
eq('retained correction recovery',4000-2000-1000+1000*d*d,1826.446280992)
eq('retained correction no recovery',4000-2000-1000,1000)
eq('native acquisition baseline',160000*a4-500000,7178.471415887)
eq('native acquisition downside',110000*a4-500000,-151314.800901579)
eq('native price-protected downside',110000*a4-400000,-51314.800901579)
eq('retained A allocation',6000*a2-10000,413.223140496)
eq('retained B allocation',8500*a2-15000,-247.933884298)
eq('retained B price concession',8500*a2-14000,752.066115702)
eq('retained cumulative original',5000*a3-12000,434.259954921)
eq('retained cumulative corrected',5000*a3+1000*d**3-15000,-1814.425244177)
timing=-8/(1.1**(1/12))+8/1.1
eq('first-year monthly timing correction',timing,-.663984274849)
def complete(action,p,integration=0,concession=0,timed=False,recover=True):
if action=='wait':return 0
if action=='A':return (6+16*p)*a3+(5*d**3 if recover else 0)-45-integration+concession+(timing if timed else 0)
return (8+2*p)*a3+2*d**3-22
p=F(4,5);A=complete('A',p);B=complete('B',p)
eq('clinic original A',A,5.509391435011);eq('clinic complete B',B,3.376408715252)
eq('clinic integration corrected A',complete('A',p,4),1.509391435011)
eq('clinic concession A',complete('A',p,4,3),4.509391435011)
eq('clinic timed A',complete('A',p,4,3,True),3.845407160163)
eq('clinic timed lead',complete('A',p,4,3,True)-B,.468998444911)
eq('clinic changed probability A',complete('A',F(3,4),4,3,True),1.855925567375)
eq('clinic changed probability B',complete('B',F(3,4)),3.127723516153)
eq('clinic no A recovery',complete('A',p,4,3,True,False),.088833155655)
# Independently build actual statewise dated cash streams rather than reuse annual formulas.
def flows(action,state,stage):
if action=='wait':return []
annual={'A':{'H':22,'L':6},'B':{'H':10,'L':8}}[action][state]
if action=='B':return [(0,-22),(1,annual),(2,annual),(3,annual+2)]
uses={'original':45,'integration':49,'concession':46,'timed':46}[stage]
out=[(0,-uses)]
if stage=='timed':out.extend([(F(1,12),-8),(1,annual+8)])
else:out.append((1,annual))
return out+[(2,annual),(3,annual+5)]
def statepv(stream):return sum(float(cash)/(1.1**float(t)) for t,cash in stream)
def independent_value(action,p,stage):return float(p)*statepv(flows(action,'H',stage))+(1-float(p))*statepv(flows(action,'L',stage))
for stage,kwargs in [('original',{}),('integration',dict(integration=4)),('concession',dict(integration=4,concession=3)),('timed',dict(integration=4,concession=3,timed=True))]:
for action in ['A','B','wait']:eq('state stream '+stage+' '+action,independent_value(action,p,stage),complete(action,p,**kwargs))
def feasible(action,opening,stage,reserve=15,stress=0):
if action=='wait':return opening>=reserve
for state in ['H','L']:
path=flows(action,state,stage)
if stress and action=='A' and state=='L':path=path+[(F(1,12),-stress)]
# Combine simultaneous entries before checking a date; no fictional intermediate receipt order.
dates=sorted(set(t for t,_ in path));cash=opening
for t in dates:
cash+=sum(v for dt,v in path if dt==t)
if cash<reserve:return False
return True
def best(opening,stage):
candidates=[(independent_value(a,p,stage),a) for a in ['A','B','wait'] if feasible(a,opening,stage)]
return max(candidates)[1]
assert best(60,'original')=='A' and best(60,'integration')=='B' and best(60,'concession')=='B'
assert best(61,'timed')=='B' and best(69,'timed')=='A'
assert min(x for x in range(46,90) if feasible('A',x,'timed'))==69
assert not feasible('A',69,'timed',stress=12) and feasible('A',81,'timed',stress=12)
assert cashpath(69,[-46,-8,30,22,27])==[23,15,45,67,94]
assert cashpath(69,[-46,-8,14,6,11])==[23,15,29,35,46]
print(json.dumps(dict(passed=True,checks=checks,independentChecks=['all eight indivisible portfolios','401 rational probability points with every rival and distinct maximin/regret criteria','statewise monthly/annual cash reconstructed independently','complete alternatives enumerated after every correction','cash reserve checked at every actual date in both states','retained native and companion calculations reproduced'],boundary='Synthetic arithmetic and conditional decision verification only; no actual evidence, permission, finance, production records or learner performance verified.'),indent=2))
Related chapters
- Design a capstone that can change a consequential decision
- Build an auditable evidence-to-cash model
- Compare complete alternatives under scarce resources and uncertainty
- Make the implementation mechanism part of the recommendation
- Stress survival and responsibility without disguising an obligation
- Defend a recommendation by making it possible to overturn
- Mariner capstone: correct the winning model, then test the commitment