#!/usr/bin/env python3 """C320 independent complete fixed-fieldT8993 coverage census. --sources contains C286_DATA.json,C271_REGISTER.json,C287_DATA.json. Searches all528 frozen regular records for eight declared cumulative rows. """ 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={} for name in ['C286_DATA.json','C271_REGISTER.json','C287_DATA.json']: p=a.sources/name if a.sources else root/'C313/sources'/name;raw=p.read_bytes();data[name]=json.loads(raw);hashes[name]=hashlib.sha256(raw).hexdigest() reg=data['C286_DATA.json']['target_register'];anc=data['C271_REGISTER.json'];four={r['i'] for r in data['C287_DATA.json']['rows'] if r['complete']};source_pairs=data['C286_DATA.json']['source_pairs'];ctx=['tradition','gear','Cainan','Terah60','full430'] assert len(reg)==528 and four=={2,3,4,5} rows=[];allmatches=[] for i in range(8): p=-5890+i;q=-5290+i;f=p+8993;n=q+8993 assert any(x['Shem_Cainan']==x['Flood_Cainan']==0 and x['Shem_index']==x['Flood_index']==i and x['S']==p and x['F']==q for x in source_pairs) ns=[x for x in reg if x['role']=='Noah birth' and x['center']==n] fs=[x for x in reg if x['role'] in ['Flood start','Flood close'] and x['center']==f] matches=[] for nr in ns: for fr in fs: if not all(nr[k]==fr[k] for k in ctx):continue expected_role='Flood close' if nr['tradition']=='SP' and nr.get('rail')=='companion' else 'Flood start' if fr['role']!=expected_role:continue assert n-f==600 and fr.get('rail') is None if nr['tradition']!='SP':assert nr.get('rail') is None phases=[] for e in (F(-1,4),F(1,4)): assert (p+e)+8993==f+e and (q+e)+8993==n+e and (n+e)-(f+e)==600 phases.append({'phase':str(e),'cumulative_Shem':str(p+e),'cumulative_Flood':str(q+e),'regular_Flood':str(f+e),'regular_Noah':str(n+e)}) m={'i':i,'Noah_record':nr,'Flood_record':fr,'context':{k:nr[k] for k in ctx},'rail':nr.get('rail'),'phase_rectangles':phases} if nr['tradition']=='SP': an=[x for x in anc if x['branch']=='Noah' and x['source_event']['gear']==nr['gear'] and x['source_event']['rail']==nr['rail']] af=[x for x in anc if x['branch']=='Flood' and x['source_event']['gear']==fr['gear'] and x['source_event']['role']==fr['role']] assert len(an)==len(af)==1;an,af=an[0],af[0] assert an['cumulative_source']['source_index']==af['cumulative_source']['source_index']==i assert an['cumulative_source']['source_role']=='Flood' and af['cumulative_source']['source_role']=='Shem' for phase in phases: assert any(x['cumulative_coordinate']==phase['cumulative_Flood'] and x['reflected_coordinate']==phase['regular_Noah'] for x in an['phases']) assert any(x['cumulative_coordinate']==phase['cumulative_Shem'] and x['reflected_coordinate']==phase['regular_Flood'] for x in af['phases']) sb=n-500;sd=sb-600;j=10-i births=[x for x in reg if x['role']=='Shem birth' and x['center']==sb and x.get('rail')==nr['rail'] and all(x[k]==nr[k] for k in ctx)] deaths=[x for x in reg if x['role']=='Shem death' and x['center']==sd and x.get('rail')==nr['rail'] and all(x[k]==nr[k] for k in ctx)] assert len(births)==len(deaths)==1 assert sb==3213-j m['SP_additional_checks']={'C271_two_actual_source_bindings':True,'source_Shem_birth':births[0],'source_Shem_death':deaths[0],'source_Noah_to_Shem':500,'source_Shem_life':600,'C314_reversed_Shem_j_required':j,'C314_j_within_existing_0_to7':0<=j<=7,'C314_required_cumulative_Flood_source':-5290+j,'C287_complete_at_i':i in four} matches.append(m);allmatches.append(m) unmatched_flood=[fr for fr in fs if not any(m['Flood_record']==fr for m in matches)] rows.append({'i':i,'p_OFF_Shem':p,'q_OFF_Flood':q,'expected_f':f,'expected_n':n,'Noah_point_matches':ns,'Flood_point_matches':fs,'matched_context_pairs':matches,'unpaired_Flood_point_matches':unmatched_flood}) sp=[x for x in allmatches if x['context']['tradition']=='SP'];lx=[x for x in allmatches if x['context']['tradition']=='LXX'] assert len(allmatches)==9 and len(sp)==6 and len(lx)==3 assert [x['i'] for x in sp]==[2,3,4,5,6,7] assert [x['i'] for x in lx]==[3,5,7] assert all(x['context']['Cainan']==0 and x['context']['Terah60']==0 and x['context']['full430']==1 for x in allmatches) assert sum(len(r['Noah_point_matches']) for r in rows)==9 assert sum(len(r['Flood_point_matches']) for r in rows)==12 assert sum(len(r['unpaired_Flood_point_matches']) for r in rows)==3 out={'step':'C320','status':'passed','scope':'All eight pre-existing cumulativeOFFShem/Flood annual rows; entire528-record regular register, with no context preselection.','input_sha256':hashes,'rows':rows,'counts':{'cumulative_rows':8,'regular_register_records':528,'Noah_point_labels':9,'Noah_point_coordinates':6,'Flood_point_labels':12,'Flood_point_coordinates':6,'matched_context_pair_labels':9,'matched_coordinate_pairs':6,'SP_pair_labels':6,'LXX_pair_labels':3,'MT_pair_labels':0,'unpaired_Flood_labels':3,'empty_annual_rows':2,'exact_phase_pair_labels':18,'exact_phase_coordinate_pairs':12,'SP_C271_binding_pairs':6,'SP_source_500_partners':6,'SP_C314_reversed_j_in_field':5,'SP_C287_complete_i':4,'SP_both_C314_j_and_C287_i':3},'newly_exposed_boundary_case':{'i':2,'context':'SP G1 companion OFF/Terah0/full430','Noah':3705,'Flood_close':3105,'Shem_birth':3205,'Shem_death':2605,'C314_j_required':8,'C314_j_admitted':False,'C287_i2_complete':True},'interpretation':'Six coordinate rectangles exhaust the fixed field, carrying nine compatible source-pair labels. Three LXXprimary aliases add labels but no coordinates. Three LXXFlood-close point aliases lack a matchingNoah endpoint in the same context and must not borrow theSPcompanion. The previously omittedSPG1companion case is a valid17K/600 rectangle and source500+600 biography, but its C314 reversed ancestry needsj8 outside the retained field.','suggested_next_bounded_question':'Construct the minimal typed dependence and coverage summary for all six SP rectangles, distinguishing the five admitted reversed-Shem cases, four C287 cases, three overlaps, and coordinate aliases from independent constraints.','later_step_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'C320_Independent_Math_Results.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'status':'passed','pair_labels':9,'coordinate_pairs':6,'SP':6,'LXX':3,'MT':0,'reversed_Shem_admitted':5})) if __name__=='__main__':main()