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 ceil,log,isclose
import json
checks=[]
def ck(name,actual,expected):
 assert actual==expected,(name,actual,expected)
 checks.append(dict(case=name,actual=str(actual),expected=str(expected)))
ck('Original defect rate',F(12,300),F(1,25))
ck('Changed defect rate',F(15,500),F(3,100))
ck('Rate percentage-point change',100*(F(15,500)-F(12,300)),F(-1))
ck('Relative defect rate change',F(15,500)/F(12,300)-1,F(-1,4))
ck('Successive price factors',200*F(5,4)*F(3,4),F(375,2))
ck('Reverse price increase with new denominator',F(250-200,250),F(1,5))
ck('Markup price',450*F(13,10),F(585))
target=F(450)*F(10,7);discount=target*F(9,10)
ck('Target margin price',target,F(4500,7))
ck('Discounted realized margin',(discount-450)/discount,F(2,9))
ck('Residual loss from ten-percent discount',(target-discount)/(target-450),F(1,3))
ck('Changed cost realized margin',(target-500)/target,F(2,9))
ck('Changed cost target price',F(500)*F(10,7),F(5000,7))
ck('Separate linear break-even',ceil(F(4700,90)),53)
ck('Separate linear target volume',ceil(F(5700,90)),64)
ck('Profit at capacity in separate case',60*90-4700,700)
ck('Required price at sixty',F(5700,60)+150,F(245))
r=F(106,100);fv=4000*r**3+1000*r**2
ck('Dated initial and end-year-one deposit future value',fv,F('5887.664'))
ck('Fee at end-year-two accumulated one year',100*r,F(106))
ck('Future value after dated fee',fv-100*r,F('5781.664'))
duration=log(2)/log(1.06)
assert isclose(4000*1.06**duration,8000,rel_tol=1e-12)
checks.append(dict(case='Log duration substituted into no-flow model',passed=True))
ck('Recorded production equality units',12+12,24)
ck('Recorded production equality hours',3*12+2*12,60)
ck('Invalid negative solution still satisfies algebra',3*(-8)+2*32,40)
assert -8<0 and 24*2>40
checks.append(dict(case='Forty-hour production equalities infeasible under nonnegativity',passed=True))
p=F(45,100)
ck('Original project expected value',p*9000-(1-p)*6000,F(750))
ck('Expected advantage over safe alternative',p*9000-(1-p)*6000-500,F(250))
ck('Project break-even probability',F(6000,15000),F(2,5))
ck('Project equality to safe alternative',F(6500,15000),F(13,30))
ck('Higher-loss expected value',p*9000-(1-p)*10000,F(-1450))
ck('Higher-loss equality to safe alternative',F(10500,19000),F(21,38))
ck('Cumulative target price',F(720)*F(5,3),F(1200))
ck('Cumulative whole-job break-even',ceil(F(6000,480)),13)
ck('Next lower whole quantity loses',12*480-6000,-240)
ck('First whole quantity covers',13*480-6000,240)
ck('Cumulative original profit',18*480-6000,2640)
ck('Cumulative original operating cash',18*1200*F(1,2)-18*720-6000,F(-8160))
ck('Original current receivable balance',18*1200*F(1,2),F(10800))
ck('Original collection threshold',F(18*720+6000,18*1200),F(79,90))
ck('Higher-cost margin',F(1200-840,1200),F(3,10))
ck('Higher-cost whole-job break-even',ceil(F(6000,360)),17)
ck('Higher-cost profit at eighteen',18*360-6000,480)
ck('Higher-cost margin-restoring quote',F(840)*F(5,3),F(1400))
receipts=18*1200*F(3,4);ar=18*1200-receipts
ck('New transfer receipts',receipts,F(16200))
ck('New transfer receivables',ar,F(5400))
ck('New transfer cash',receipts-18*840-6000,F(-4920))
ck('New transfer profit-to-cash bridge',F(480)-ar,F(-4920))
ck('Higher-cost collection threshold',F(18*840+6000,18*1200),F(44,45))
ck('Full collection matches stated profit',18*1200-18*840-6000,480)
print(json.dumps(dict(passed=True,scope='Synthetic mathematical mechanisms, not observed learners or real business forecasts',checks=checks)))

Related chapters