from fractions import Fraction as Q def run(load,check): reg=load('C286_DATA.json')['target_register'];rows=[] for r in load('C319_DATA.json')['rows']: tag=str((r['a'],r['b'],r['i'])) nn=[z for z in reg if z['tradition']=='SP' and z['role']=='Noah birth' and z['Cainan']==0 and z['Terah60']==0 and z['full430']==1 and z['center']==r['n']] check('one source Noah '+tag,len(nn)==1);N=nn[0];g=N['gear'];rail=N['rail'];e=int(rail=='companion') def one(t,role,c,terah,rr=None): p=[z for z in reg if z['tradition']==t and z['gear']==g and z['role']==role and z['Cainan']==c and z['Terah60']==terah and z['full430']==1 and z.get('rail')==rr];assert len(p)==1;return p[0] M=one('MT','Noah birth',1,1);S=one('SP','Shem birth',0,0,rail);T=one('SP','Shem death',0,0,rail) upper=r['n']-M['center'];lower=M['center']-r['R'];s=Q(r['n'])-Q(25,23)*upper;t=s-Q(300,299)*lower check('input normal form '+tag,upper==460-e and lower==600+e-r['b']) serror=s-S['center'];terror=t-T['center'] check('exact residual formula '+tag,serror==Q(25,23)*e and terror==Q(300*r['b']+25*e-600,299)) endpoint_exact=s==S['center'] and t==T['center'];valid=endpoint_exact and r['joint_admitted'] check('exact iff primary b2 '+tag,endpoint_exact==(e==0 and r['b']==2)) rows.append({'a':r['a'],'b':r['b'],'i':r['i'],'SP_Noah':N,'MT_Noah':M,'R':r['R'],'Shem_birth':S,'Shem_death':T,'input_gaps':[upper,lower],'calculated_birth':str(s),'calculated_death':str(t),'birth_error':str(serror),'death_error':str(terror),'algebraic_endpoint_exact':endpoint_exact,'joint_source_admitted':r['joint_admitted'],'admitted_exact':valid,'two17K':r['two17K'],'allK':r['allK']}) hits=[r for r in rows if r['admitted_exact']];sig=lambda rr:sorted(f"{r['a']}{r['b']}:i{r['i']}" for r in rr) check('four admitted exact controls',sig(hits)==['02:i3','02:i5','22:i3','22:i5']) check('algebraic source distinction',sum(r['algebraic_endpoint_exact'] for r in rows)==6 and len(hits)==4) check('17K subset unchanged',sig([r for r in hits if r['two17K']])==['22:i3','22:i5']) return {'step':'C360','rows':rows,'counts':{'tested':20,'algebraic_exact':6,'admitted_exact':4,'with17K':2},'survivors':sig(hits),'birth_error_formula':'(25/23)e','death_error_formula':'(300b+25e-600)/299','total_span_error_formula':'(600-300b-25e)/299','interpretation':'The source mapping selects primaryb2, equivalent to the regular2K side within this menu. It leavesa0 and2. Near cancellation on companionb2 leaves25/299 death error and25/23 birth error; no rounding is licensed.'}