from fractions import Fraction as F from itertools import product def run(load,check): reg=load('C286_DATA.json')['target_register'];old=load('C287_DATA.json');rows=[];phase_trials=[] for x in old['rows']: if not x['complete']:continue n=next(n for n in x['Noah_records'] if n['tradition']=='SP');g=n['gear'];rail=n['rail'];i=x['i'];N=n['center'] def pick(tr,role,gear,c,t,rail=None,center=None): found=[r for r in reg if r['tradition']==tr and r['role']==role and r['gear']==gear and r['Cainan']==c and r['Terah60']==t and r['full430']==1 and (rail is None or r.get('rail')==rail) and (center is None or r['center']==center)] check(f'i{i}/{tr}/{role}/unique',len(found)==1);return found[0] d=pick('SP','Noah death',g,0,0,rail);m=pick('MT','Noah birth',g,1,1);r=pick('MT','Flood start' if rail=='primary' else 'Flood close',g+1,1,1,center=x['R']);M,D,R=m['center'],d['center'],r['center'];legs=[N-M,M-D,D-R] check(f'i{i}/allheld',n in reg and N==x['Noah_required'] and N-M>0 and M-D>0 and D-R>0) check(f'i{i}/950+108',N-D==950 and D-R==108 and N-R==2*529) check(f'i{i}/rolequalifiedlegs',legs==([460,490,108] if rail=='primary' else [459,491,108])) hypothetical=[z for z in reg if z['tradition']=='MT' and z['role']=='Noah birth' and z['Cainan']==1 and z['Terah60']==1 and z['full430']==1 and z['center']==N-460] check(f'i{i}/MTsourceboundary',len(hypothetical)==(1 if rail=='primary' else 0)) row={'i':i,'SP_gear':g,'rail':rail,'records':{'N':n,'M':m,'D':d,'R':r},'coordinates':[N,M,D,R],'adjacent_legs':legs,'Noah_life':N-D,'death_to_MT_Flood':D-R,'MT_Noah_to_MT_Flood':M-R,'total_2K':N-R,'N_minus460_required':N-460,'N_minus460_MT_Noah_matches':hypothetical,'C287_S':x['S'],'C287_F':x['F'],'coincident_LXX_Noah_labels':[z for z in x['Noah_records'] if z['tradition']=='LXX']};rows.append(row) check(f'i{i}/inheritedC287',N-x['F']==R-x['S']==17*529 and x['F']-x['S']==2*529) for ph in product([F(-1,4),F(1,4)],repeat=4): vals=[F(v)+e for v,e in zip([N,M,D,R],ph)];ds=[vals[j]-vals[j+1] for j in range(3)];ok=ds==legs phase_trials.append({'i':i,'phases':list(map(str,ph)),'coordinates':list(map(str,vals)),'legs':list(map(str,ds)),'exact':ok}) check('allphasecriterion',all(x['exact']==(len(set(x['phases']))==1) for x in phase_trials)) counts={'complete_SP_paths':len(rows),'primary460_490_paths':sum(x['rail']=='primary' for x in rows),'companion459_491_paths':sum(x['rail']=='companion' for x in rows),'phase_trials':len(phase_trials),'exact_components':sum(x['exact'] for x in phase_trials)} check('counts',counts=={'complete_SP_paths':4,'primary460_490_paths':2,'companion459_491_paths':2,'phase_trials':64,'exact_components':8}) return {'step':'C331','rows':rows,'phase_trials':phase_trials,'counts':counts,'incomplete_C287_rows_retained':[x for x in old['rows'] if not x['complete']],'common_partition':'2K=1058=950+108 for allfour;primary460+490+108,companion459+491+108 with actualMTNoah.','new_source_nodes':False,'new_independent_witnesses':False,'scope':'SP source pathways only; co-located LXX Noah labels preserved without a newly asserted LXX death path.'}