#!/usr/bin/env python3 """C321 independent nativeLXX_ON equalT8993 source coherence census. --sources contains C286_DATA.json and C320_DATA.json. Eight existing nativeON rows, all528regular records, no new companions. """ import argparse from fractions import Fraction as F from pathlib import Path import hashlib,json def main(): ap=argparse.ArgumentParser();ap.add_argument('--sources',type=Path);ap.add_argument('--out',type=Path,default=Path(__file__).parent);a=ap.parse_args();root=Path(__file__).resolve().parents[1];data={};hashes={} defaults={'C286_DATA.json':root/'C313/sources/C286_DATA.json','C320_DATA.json':root/'C320/evidence/DATA.json'} for name,p in defaults.items(): raw=(a.sources/name if a.sources else p).read_bytes();data[name]=json.loads(raw);hashes[name]=hashlib.sha256(raw).hexdigest() reg=data['C286_DATA.json']['target_register'];pairs=data['C286_DATA.json']['source_pairs'];prior=data['C320_DATA.json'];ctx=['tradition','gear','Cainan','Terah60','full430'];rows=[];matches=[] assert len(reg)==528 def lookup(role,center,trad=None,gear=None,cain=None,terah=None,full=None): return [r for r in reg if r['role']==role and r['center']==center and (trad is None or r['tradition']==trad) and (gear is None or r['gear']==gear) and (cain is None or r['Cainan']==cain) and (terah is None or r['Terah60']==terah) and (full is None or r['full430']==full)] for i in range(8): p=-6350+i;q=-5750+i;f=p+8993;n=q+8993 assert any(r['Shem_Cainan']==r['Flood_Cainan']==1 and r['Shem_index']==r['Flood_index']==i and r['S']==p and r['F']==q for r in pairs) ns=lookup('Noah birth',n);fs=lookup('Flood start',f)+lookup('Flood close',f);ms=[] for nr in ns: for fr in fs: if not all(nr[k]==fr[k] for k in ctx):continue role='Flood close' if nr['tradition']=='SP' and nr.get('rail')=='companion' else 'Flood start' if fr['role']!=role:continue assert n-f==600 and nr.get('rail') is None and fr.get('rail') is None offn=lookup('Noah birth',n+460,'SP',nr['gear'],0,0,1);offf=lookup(fr['role'],f+460,'SP',nr['gear'],0,0,1) assert len(offn)==len(offf)==1 and offn[0]['rail']=='primary' prow=next(x for x in prior['rows'] if x['i']==i) assert [prow['p'],prow['q'],prow['f_required'],prow['n_required']]==[p+460,q+460,f+460,n+460] assert any(x['Noah']==offn[0] and x['Flood']==offf[0] for x in prow['matched_context_rectangles']) paths=[] for role,base,target in [('Noah birth',n+460,n),(fr['role'],f+460,f)]: st=[(base,'SP',0,0),(base-650,'MT',0,0),(base-520,'MT',1,0),(base-460,'MT',1,1)];records=[] for center,trad,c,t in st: hits=lookup(role,center,trad,nr['gear'],c,t,1);assert len(hits)==1;records.append(hits[0]) assert records[-1]['center']==target paths.append({'role':role,'coordinates':[x[0] for x in st],'source_records':records}) components=[] for e in [F(-1,4),F(1,4)]: assert f+e-(p+e)==n+e-(q+e)==8993 assert q+e-(p+e)==n+e-(f+e)==600 assert (f+460+e)-(p+460+e)==8993 components.append({'phase':str(e),'p_ON_Shem':str(p+e),'q_ON_Flood':str(q+e),'f_MT_Flood':str(f+e),'n_MT_Noah':str(n+e),'OFF_comparison_coordinates':[str(x+460+e) for x in [p,q,f,n]],'all_coordinate_displacements_from_OFF':'-460','both_translations':'8993','both_sides':'600'}) m={'i':i,'Noah_record':nr,'Flood_record':fr,'context':{k:nr[k] for k in ctx},'OFF_SP_Noah':offn[0],'OFF_SP_Flood':offf[0],'sameGear_regular_conversion_paths':paths,'phase_rectangles':components};ms.append(m);matches.append(m) rows.append({'i':i,'p_native_ON_Shem':p,'q_native_ON_Flood':q,'expected_f':f,'expected_n':n,'Noah_point_matches':ns,'Flood_point_matches':fs,'matched_context_pairs':ms,'point_only':bool(ns or fs) and not ms,'empty':not ns and not fs}) assert [m['i'] for m in matches]==[3,5,7] and len(matches)==3 assert all(m['context']['tradition']=='MT' and m['context']['Cainan']==1 and m['context']['Terah60']==1 and m['context']['full430']==1 for m in matches) assert sum(len(r['Noah_point_matches']) for r in rows)==3 and sum(len(r['Flood_point_matches']) for r in rows)==6 assert [r['i'] for r in rows if r['point_only']]==[2,4,6] assert [r['i'] for r in rows if r['empty']]==[0,1] # At the three rejected companion indices, SPregular partners exist but MTNoah does not. companion_controls=[] for i in [2,4,6]: n=3703+i;f=3103+i;spn=lookup('Noah birth',n,'SP',cain=0,terah=0,full=1);assert len(spn)==1 and spn[0]['rail']=='companion';g=spn[0]['gear'] assert len(lookup('Flood close',f-460,'MT',g,1,1,1))==1 assert not lookup('Noah birth',n-460,'MT',g,1,1,1) companion_controls.append({'i':i,'SP_gear':g,'SP_Noah_companion':n,'MT_Noah_requirement':n-460,'MT_Noah_admitted':False,'MT_Flood_close':f-460,'MT_Flood_admitted':True,'companion_not_imported':True}) out={'step':'C321','status':'passed','input_sha256':hashes,'scope':'NativeONLXXShem/Flood at all8existingindices; full528regularregister searched without context preselection.','rows':rows,'companion_controls':companion_controls,'counts':{'annual_rows':8,'regular_register_records':528,'Noah_point_labels':3,'Noah_coordinates':3,'Flood_point_labels':6,'Flood_coordinates':6,'matched_context_pairs':3,'matched_coordinate_rectangles':3,'exact_phase_rectangles':6,'point_only_rows':3,'empty_rows':2,'matched_MT_labels':3,'matched_SP_labels':0,'matched_LXX_labels':0,'sameGear_OFF_SP_conversion_pairs':3},'crosswidth_matrix':[[8993,9593],[8393,8993]],'nativeON_matches':'MT regular CainanON/Terah+60/full430 at primary G1/G2/G3; this context emerges from the census.','comparison_to_OFF':'The three SPprimaryOFF/T0/full430 rectangles at i3,5,7 translate by−460 in all four comparison coordinates. On the regular side the typed conversion is−650+130+60=−460 at the same Gear; no Gear change or companion import.','interpretation':'NativeON source rectangles are compatible with three regularMTsource contexts. The460 correspondence preserves their existing17K bridges and600 sides, so it is a source-coherence relation rather than a new independent17K measurement or a source-prescribed global chronology.','suggested_next_bounded_question':'Consolidate the minimal dependency and selector conditions for the nativeON/MT and derivedOFF/SP rectangles and the cross-state2K rectangle, making explicit which 529 features follow from shared17K and which require the paired annual/Gear selection.','later_step_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'C321_Independent_Math_Results.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'status':'passed','matched_MT_pairs':3,'phase_rectangles':6,'point_only':3,'empty':2})) if __name__=='__main__':main()