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 limited synthetic outcome, allocation and review-capacity calculations, not independent academic acceptance or production migration safety.

"""Original synthetic ethical-model checks, not a moral decision procedure."""
from fractions import Fraction as F
from itertools import product
import json
checks=[]
def eq(name,value,expected):
 assert value==expected,(name,value,expected);checks.append(dict(case=name,value=str(value),expected=str(expected)))
eq('retained identifiable expected net',F(4,5)*30-10,14)
eq('retained less intrusive net',20-1,19)
eq('new identified p.7',F(7,10)*40-12,16)
eq('new identified p.95',F(19,20)*40-12,26)
eq('new less intrusive before risk',25-2,23)
eq('conditional crossover',F(23+12,40),F(7,8))
eq('new low exposure risk',25-2-F(3,10)*15,F(37,2))
eq('new high exposure risk',25-2-F(3,5)*15,14)
assert 18>14 and F(37,2)>18
confirmed=set(range(18));independent=set(range(18,22));eq('disjoint known informed',len(confirmed|independent),22)
overlap=set(range(4));eq('overlapping known informed',len(confirmed|overlap),18)
eq('unconfirmed after overlap correction',24-len(confirmed|overlap),6)
old_needs=(2,4,6);assert sum(old_needs)==12 and (4,4,4)[2]<old_needs[2]
assert not [x for x in product(range(11),repeat=3) if sum(x)<=10 and all(v>=n for v,n in zip(x,old_needs))]
eq('retained equal-share third shortfall',old_needs[2]-4,2)
needs=(2,3,5);budget=9
allocations=[x for x in product(range(budget+1),repeat=3) if sum(x)<=budget]
enabled=lambda x:sum(v>=n for v,n in zip(x,needs))
min_fraction=lambda x:min(F(v,n) for v,n in zip(x,needs))
eq('maximum enabled whole workshops',max(map(enabled,allocations)),2)
assert enabled((2,3,4))==enabled((0,4,5))==2
eq('integer maximin fraction',max(map(min_fraction,allocations)),F(4,5))
assert min_fraction((2,3,4))==F(4,5)
ratio=F(budget,sum(needs));continuous=tuple(n*ratio for n in needs)
assert sum(continuous)==budget and min_fraction(continuous)==F(9,10) and enabled(continuous)==0
checks.append(dict(case='continuous proportional bound',allocation=[str(x) for x in continuous],proof='Any minimum fraction r requires at least10r hours;9 hours bounds r at0.9; the given allocation attains it. Different ethical criteria remain distinct.'))
assert sum((2,3,4))==9 and all(v>=n for v,n in zip((2,3,4),(2,3,4)))
eq('retained selected error fraction',F(8,100),F(2,25))
eq('retained error concentration, not group rate',F(6,8),F(3,4))
eq('new weak-subject rate',F(6,20),F(3,10));eq('new other rate',F(4,80),F(1,20));eq('new total error',F(10,100),F(1,10));eq('new error concentration',F(6,10),F(3,5))
assert 80+10+10==100
eq('100 outputs at2minutes',100*2,200);eq('80 outputs at2minutes',80*2,160)
assert max(n for n in range(101) if n*2<=120)==60
assert max(n for n in range(101) if n*3<=120)==40
# Enumerate complete supplied alternatives under an EXPLICIT assumed refusal constraint.
def available(exposure,assume_refusal_constraint):
 alternatives=[('identified',F(19,20)*40-12),('less-intrusive',25-2-exposure*15),('private',F(18)),('wait',F(0))]
 return [(name,value) for name,value in alternatives if not(assume_refusal_constraint and name=='identified')]
assert max(available(F(3,5),False),key=lambda x:x[1])[0]=='identified'
assert max(available(F(3,5),True),key=lambda x:x[1])[0]=='private'
assert max(available(F(3,10),True),key=lambda x:x[1])[0]=='less-intrusive'
checks.append(dict(case='constraint and outcome distinction',result='The conditional ranking changes when an openly assumed ethical constraint or exposure fact changes. Code does not prove the constraint, consent, probability or moral scale.'))
print(json.dumps(dict(passed=True,checks=checks,independentChecks=['all whole allocations under nine hours enumerated','continuous proportional bound derived and attained','whole review capacity searched under changed workload','sets deduplicated independently of displayed counts','all supplied alternatives compared under explicit hypothetical constraint'],boundary='Limited stipulated arithmetic and feasibility only; no moral theory, real consent/eligibility decision, current legal compliance, professional approval, independent subject review or observed learner competence established.',learnerRecordsAccessed=False),indent=2))

Related chapters