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 descriptive rates, standardization, overlap and logical-bound calculations, not independent academic acceptance or production migration safety.

"""Original synthetic sociological records: descriptive checks, not causal proof."""
from fractions import Fraction as F
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)))
# Construct person-level attendance records independently of the weighted formulas.
def cohort(stable,variable,stable_attend,variable_attend):
 return [('stable',i<stable_attend) for i in range(stable)]+[('variable',i<variable_attend) for i in range(variable)]
before=cohort(60,30,48,12);after=cohort(45,45,36,27)
eq('original attendance ledger',sum(x[1] for x in before),60)
eq('later attendance ledger',sum(x[1] for x in after),63)
rates={kind:F(sum(attend for k,attend in after if k==kind),sum(k==kind for k,_ in after)) for kind in ['stable','variable']}
eq('later stable rate',rates['stable'],F(4,5));eq('later variable rate',rates['variable'],F(3,5))
standard=sum(rates[k] for k,_ in before)/len(before)
eq('common mix later attendance',standard,F(11,15))
eq('common mix change',standard-F(60,90),F(1,15))
eq('composition contribution',F(63,90)-standard,F(-1,30))
eq('actual attendance change',F(63-60,90),F(1,30))
completer_records=list(range(36))+list(range(6))
eq('recorded later completions',len(completer_records),42)
eq('deduplicated completions',len(set(completer_records)),36)
eq('corrected all-enrollee completion',F(len(set(completer_records)),90),F(2,5))
eq('corrected attendee completion',F(36,63),F(4,7))
eq('partially resolved duplicates all-enrollee',F(39,90),F(13,30))
# Build the seven disjoint Venn regions, then measure sets and intersections.
regions={1:75,2:70,4:80,3:15,5:5,6:10,7:5}
audiences=[set(),set(),set()];serial=0
for mask,count in regions.items():
 for _ in range(count):
  for bit in range(3):
   if mask&(1<<bit):audiences[bit].add(serial)
  serial+=1
a,b,c=audiences
eq('three actual audience sizes',tuple(map(len,audiences)),(100,100,100))
eq('pair intersections',tuple(map(len,[a&b,a&c,b&c])),(20,10,15))
eq('triple intersection',len(a&b&c),5)
eq('enumerated unique reach',len(a|b|c),260)
eq('inclusion exclusion matches independent sets',300-20-10-15+5,len(a|b|c))
# Explicitly enumerate all possible missing favorable counts rather than choose a midpoint.
possible={F(30+n,120) for n in range(81)}
eq('missing-response lower bound',min(possible),F(1,4));eq('missing-response upper',max(possible),F(11,12))
revised={F(30+n,120) for n in range(61)}
eq('follow-up lower bound',min(revised),F(1,4));eq('follow-up upper',max(revised),F(3,4))
# Stage-specific populations and an independent encounter ledger.
eq('A applicant offers',F(60,100),F(3,5));eq('B applicant offers',F(30,50),F(3,5))
eq('eligible offer gap',F(60,200)-F(30,200),F(3,20))
eq('revised B eligible offers',F(48,200),F(6,25))
old=[True]*90+[False]*10+[True]*50+[False]*50
new=[True]*162+[False]*18+[True]*10+[False]*10
eq('old service ledger',F(sum(old),len(old)),F(7,10));eq('new service ledger',F(sum(new),len(new)),F(43,50))
eq('common service mix',F(90+50,200),F(7,10))
eq('changed complex common mix',F(90+60,200),F(3,4));eq('changed complex actual mix',F(162+12,200),F(87,100))
eq('error rates decline',F(12,200)-F(20,200),F(-1,25))
eq('old error capture',F(5,20),F(1,4));eq('new error capture',F(9,12),F(3,4))
eq('household A wealth',90000-70000,20000);eq('household B wealth',15000-25000,-10000)
events_A=[True]*8+[False]*792+[True]*20+[False]*180
events_B=[True]*4+[False]*396+[True]*60+[False]*540
eq('A crude event rate',F(sum(events_A),len(events_A)),F(7,250))
eq('B crude event rate',F(sum(events_B),len(events_B)),F(8,125))
eq('common age mix',F(1,2)*F(8,800)+F(1,2)*F(20,200),F(11,200))
eq('changed B standardized',F(1,2)*F(4,400)+F(1,2)*F(54,600),F(1,20))
population=list(range(10000));population=population[90:]+list(range(10000,10120))+list(range(20000,20400));population=population[250:]
eq('independent population ledger',len(population),10180)
eq('corrected missing departures',len(population)-80,10100)
print(json.dumps(dict(passed=True,checks=checks,scope='Synthetic descriptive counts, conditional rates, standardization and logical bounds only. No causal effect, legal permission, actual research approval or learner competence established.',learnerRecordsAccessed=False),indent=2))

Related chapters