"""Reproducible model checks, not physical experiments or a formal proof assistant. Run: python3 code/verify_models.py All results are generated mathematical values; no human or experimental data. """ from pathlib import Path from fractions import Fraction as F import csv import json import math ROOT=Path(__file__).resolve().parents[1] RESULTS=ROOT/'results' def write_csv(name,rows): with (RESULTS/name).open('w',newline='') as f: w=csv.DictWriter(f,fieldnames=list(rows[0]));w.writeheader();w.writerows(rows) def rk4_constant(y,u,tau,dt): def f(v):return (u-v)/tau a=f(y);b=f(y+dt*a/2);c=f(y+dt*b/2);d=f(y+dt*c) return y+dt*(a+2*b+2*c+d)/6 def check_buffer(): rows=[] for tau in [0.2,1.0,3.0]: amplitude=0.7;duration=0.8 for steps in [100,200]: dt=duration/steps;y=0.;error=0. for i in range(steps): y=rk4_constant(y,amplitude,tau,dt) exact=amplitude*(1-math.exp(-(i+1)*dt/tau)) error=max(error,abs(y-exact)) peak=amplitude*(1-math.exp(-duration/tau)) rows.append(dict(data_origin='numerical ODE verification only',tau=tau,input_amplitude=amplitude,pulse_duration=duration,rise_steps=steps,analytic_peak=peak,numerical_end_of_rise=y,max_absolute_rise_error=error,units='consistent arbitrary model units')) assert peak1 matched_work_peak=math.exp(.5)-math.exp(-.5) assert matched_work_peak>1 write_csv('H0836_ODE_checks.csv',rows) write_csv('H0836_convex_release_checks.csv',closure) return dict(max_ODE_error=max(r['max_absolute_rise_error'] for r in rows),threshold_counterexample_buffer_duration=binary_duration,threshold_counterexample_rigid_duration=1.0,matched_work_buffer_peak=matched_work_peak,matched_work_rigid_peak=1.0,matched_work_volume_is_also_matched=False) def check_skin(): rows=[] for b in [F(1,10**6),F(1,1000),F(1,100),F(1),F(100)]: for skin in [F(1,1000),F(1,100),F(1,10),F(1)]: for ratio in [F(1),F(2),F(10),F(100)]: hole=skin*ratio;delta=hole-skin for phi in [F(1,1000),F(1,100),F(1,10),F(1,2)]: g=skin+phi*delta t0=1/b+1/skin;t1=1/b+1/g reduction=1-t1/t0 algebra=b*phi*delta/(g*(b+skin)) assert reduction==algebra condition=delta*(b-phi*(b+skin))>skin*(b+skin) assert (reduction>phi)==condition assert t1<=t0 rows.append(dict(data_origin='exact rational model calculation',bulk_conductance=str(b),skin_conductance=str(skin),hole_conductance=str(hole),open_fraction=str(phi),half_time_ratio=str(t1/t0),relative_delay_reduction=str(reduction),reduction_exceeds_open_fraction=condition,units='consistent arbitrary model units')) b=F(1);skin=F(1,100);hole=F(1);phi=F(1,100) g=skin+phi*(hole-skin) D=b*phi*(hole-skin)/(g*(b+skin)) assert D==F(9900,20099) # Explicit bulk-limited counterexample. bslow=F(1,10**6) Dslow=bslow*phi*(hole-skin)/(g*(bslow+skin)) assert Dslow