from fractions import Fraction from collections import defaultdict from itertools import product import hashlib def run(load,read,check): for n in [429,472]:check(str(n)+'_data_certificate',hashlib.sha256(read('C'+str(n)+'_DATA.json').encode()).hexdigest()==load('C'+str(n)+'_CERTIFICATE.json')['data_sha256']) r=load('C286_DATA.json')['target_register'];ix=defaultdict(list) for i,z in enumerate(r):ix[z['center']].append(i) def matches(tr,role,gear,C,T,F,rail=None):return [i for i,z in enumerate(r) if z['tradition']==tr and z['role']==role and z['gear']==gear and z['Cainan']==C and z['Terah60']==T and z['full430']==F and z.get('rail')==rail] def E(h,x):return Fraction(25*x-2*h,23) rows=[] for gear,C,T,F in product(range(1,4),range(2),range(2),range(2)): delta=2*(gear-1)+130*C+60*T+215*F;N=3491+delta expected_input=(gear<=2 and C==T==0) ctx={'gear':gear,'Cainan':C,'Terah60':T,'full430':F} for rail,offset in [('primary',0),('companion',-1)]: h=N+offset;x=h-1058;mid=h-1150;y=h-1250 label=str((gear,C,T,F,rail)) check(label+'_Noah_source',bool(matches('SP','Noah birth',gear,C,T,F,rail)) and r[matches('SP','Noah birth',gear,C,T,F,rail)[0]]['center']==h) check(label+'_E_arithmetic',E(h,x)==mid and E(h,mid)==y) extra_alias=(rail=='companion' and (gear,C,T,F)==(3,1,1,1)) check(label+'_input_gate',bool(ix.get(x))==(expected_input or extra_alias)) if extra_alias:check('extra_companion_input_is_MT_Noah2841',x==2841 and ix[x]==matches('MT','Noah birth',1,0,0,0)) input_role='Flood start' if rail=='primary' else 'Flood close' typed_input=matches('MT',input_role,gear+1,C+1,T+1,F) typed_final=matches('MT',input_role,gear,C,T,F) check(label+'_input_source_state',bool(typed_input)==expected_input and all(r[i]['center']==x for i in typed_input)) check(label+'_final_source_state',bool(typed_final) and all(r[i]['center']==y for i in typed_final)) check(label+'_middle_gate',bool(ix.get(mid))==(rail=='primary')) typed_mid=matches('MT','Shem birth',gear,C,T,F) if rail=='primary' else [] check(label+'_middle_source_state',all(r[i]['center']==mid for i in typed_mid) and (bool(typed_mid)==(rail=='primary'))) rows.append({'context':ctx,'rail':rail,'upper':h,'lower_path':[x,mid,y],'record_indices':{'upper':ix.get(h,[]),'input':ix.get(x,[]),'middle':ix.get(mid,[]),'final':ix.get(y,[])},'typed_indices':{'upper':matches('SP','Noah birth',gear,C,T,F,rail),'input':typed_input,'middle':typed_mid,'final':typed_final},'extra_input_alias':extra_alias,'endpoint_pair_complete':bool(ix.get(x)) and bool(ix.get(y)),'two_sourced_E_steps':all(ix.get(v) for v in [h,x,mid,y])}) prior=load('C429_DATA.json')['complete_fixed_pivot_E2_ladders'] check('four_primary_match_C429',sorted(z['upper'] for z in rows if z['two_sourced_E_steps'])==sorted(z['held_upper'] for z in prior)) old_endpoint={z['held_upper'] for z in load('C429_DATA.json')['sourced_output_trials'] if z['operator']=='E2' and not z['two_sourced_E_steps']} comp_complete=[z for z in rows if z['rail']=='companion' and z['endpoint_pair_complete']] check('companion_endpoint_cases_already_recorded',len(comp_complete)==5 and all(z['upper'] in old_endpoint for z in comp_complete)) summary={rail:{'contexts':sum(z['rail']==rail for z in rows),'sourced_inputs':sum(z['rail']==rail and bool(z['record_indices']['input']) for z in rows),'sourced_middles':sum(z['rail']==rail and bool(z['record_indices']['middle']) for z in rows),'sourced_finals':sum(z['rail']==rail and bool(z['record_indices']['final']) for z in rows),'complete_paths':sum(z['rail']==rail and z['two_sourced_E_steps'] for z in rows)} for rail in ['primary','companion']} return {'step':'C476','context_formula':'N=3491+2(g-1)+130C+60T+215F; companion N-1','rows':rows,'summary':summary,'conditions':{'matched_Flood_input':'C=0,T=0,g in {1,2}; F either0 or1','additional_companion_input':'N_companion3899 atG3C1T1F1 has input2841=MTNoahbirthG1C0T0F0; a role/context alias, not the shifted matched Flood input','primary_middle':'MT Shem birth at same context','primary_final':'MT Flood start at same context','companion_middle':'one less than matched MT Shem birth; no coordinate in declared register','companion_final':'MT Flood close at same context'},'source_records':r,'limits':'The companion shift acts on the SP person rail and the matched MT Flood boundary at the endpoints. No MT person companion is licensed at the middle; no new operator or coordinate is admitted.'}