#!/usr/bin/env python3 """C322 independent full-biography460 and joint-support diagnostic. --sources contains PREVIOUS_DATA.json(C321),C320_DATA.json,C314_DATA.json, C286_DATA.json,C287_DATA.json. No C323 calculation. """ 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] defaults={'PREVIOUS_DATA.json':root/'C321/evidence/DATA.json','C320_DATA.json':root/'C320/evidence/DATA.json','C314_DATA.json':root/'C314/evidence/DATA.json',**{n:root/'C313/sources'/n for n in ['C286_DATA.json','C287_DATA.json']}} data={};hashes={} 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'];on=data['PREVIOUS_DATA.json'];off=data['C320_DATA.json'];reverse=data['C314_DATA.json'];complete={r['i'] for r in data['C287_DATA.json']['rows'] if r['complete']};roles=['Noah birth','Shem birth','Flood start','Noah death','Shem death'] def record(trad,g,role,c,t): xs=[r for r in reg if r['tradition']==trad and r['gear']==g and r['role']==role and r['Cainan']==c and r['Terah60']==t and r['full430']==1 and r.get('rail') in [None,'primary']] assert len(xs)==1;return xs[0] rows=[] for case in on['rows']: for match in case['matched_context_rectangles']: i=case['i'];g=match['Noah']['gear'];assert match['Noah']['tradition']=='MT' endpoints=[];spchain=[];mtchain=[] for role in roles: sp=record('SP',g,role,0,0);mt=record('MT',g,role,1,1);expected=sp['center']-460;residual=mt['center']-expected assert residual==0 and mt['center']+460==sp['center'] and mt.get('rail') is None aliases=[r for r in reg if r['role']==role and r['tradition']=='MT' and r['Cainan']==1 and r['Terah60']==1 and r['full430']==1 and r['center']==expected and r['gear']!=g] assert aliases==[] ps=[] for e in (F(-1,4),F(1,4)): sc=sp['center']+e;mc=mt['center']+e;assert mc-sc==-460 and mc+460==sc ps.append({'phase':str(e),'SP':str(sc),'MT':str(mc),'MT_restored_plus460':str(mc+460),'residual':'0'}) endpoints.append({'role':role,'SP_record':sp,'MT_record':mt,'predicted_MT':expected,'actual_MT':mt['center'],'restored_SP':mt['center']+460,'transport_residual':residual,'wrongGear_same_context_same_role_aliases':aliases,'phase_components':ps});spchain.append(sp['center']);mtchain.append(mt['center']) spgaps=[spchain[k]-spchain[k+1] for k in range(4)];mtgaps=[mtchain[k]-mtchain[k+1] for k in range(4)];assert spgaps==mtgaps==[500,100,350,150] assert mtchain[0]-mtchain[3]==950 and mtchain[1]-mtchain[4]==600 and mtchain[0]-mtchain[2]==600 assert match['Noah']['center']==mtchain[0] and match['Flood']['center']==mtchain[2] rows.append({'i':i,'gear':g,'roles_in_order':roles,'SP_source_chain':spchain,'MT_source_chain':mtchain,'SP_gaps':spgaps,'MT_gaps':mtgaps,'uniform_displacement':-460,'endpoint_results':endpoints,'source_Noah_life':950,'source_Shem_life':600,'Noah_to_Shem':500,'Noah_to_Flood_start':600}) assert [r['i'] for r in rows]==[3,5,7] off_by={r['i']:r for r in off['rows']};on_by={r['i']:r for r in on['rows']};rev_by={r['i']:r for r in reverse['rows']};support=[] for i in range(8): j=10-i offsp=any(m['Noah']['tradition']=='SP' for m in off_by[i]['matched_context_rectangles']) onmt=any(m['Noah']['tradition']=='MT' for m in on_by[i]['matched_context_rectangles']) rev=i in rev_by and rev_by[i]['j']==j if rev: assert 0<=j<=7 b=rev_by[i]['biography_BC'];assert b[0]-b[1]==500 and b[1]-b[2]==600 flags={'C320_OFF_SP_rectangle':offsp,'C321_ON_MT_rectangle':onmt,'C314_reversed_SP500':rev,'C287_complete_at_i':i in complete,'C287_complete_at_j':j in complete} support.append({'i':i,'required_j':j,'j_in_0_to7':0<=j<=7,**flags,'all_five_supports':all(flags.values())}) intersections={name:[r['i'] for r in support if r[name]] for name in ['C320_OFF_SP_rectangle','C321_ON_MT_rectangle','C314_reversed_SP500','C287_complete_at_i','C287_complete_at_j','all_five_supports']} assert intersections=={'C320_OFF_SP_rectangle':[2,3,4,5,6,7],'C321_ON_MT_rectangle':[3,5,7],'C314_reversed_SP500':[3,4,5,6,7],'C287_complete_at_i':[2,3,4,5],'C287_complete_at_j':[5,6,7],'all_five_supports':[5]} cross_noah=record('MT',2,'Noah birth',1,1);cross_shem=record('MT',1,'Shem birth',1,1) assert cross_noah['center']-cross_shem['center']==502 typed_guard={'initial_hypothesis_corrected':'MTsameGear502 was not supported by the frozen register; all three sameGearharmonic rows give500.', 'sameGear_harmonic_binding':500,'distinct_crossGear_example':{'Noah_Gear':2,'Noah':cross_noah['center'],'Shem_Gear':1,'Shem':cross_shem['center'],'difference':502},'source_interpretation':'File18§1.3.5 distinguishes Noah/Flood-bound harmonic100 from Arphaxad/text-bound100; neither replaces the other.','crossGear_adopted_as_sameGear_repair':False} out={'step':'C322','status':'passed','input_sha256':hashes,'scope':'Three admittedMTON/T60/full430 primarycases, five source roles each, plus existing i0..7 support conditions.','biographies':rows,'binding_guard':typed_guard,'joint_support_table':support,'support_index_sets':intersections,'counts':{'source_biography_pairs':3,'endpoint_role_comparisons':15,'exact_phase_endpoint_comparisons':30,'zero_transport_residuals':15,'wrongGear_same_role_context_aliases':0,'support_annual_indices':8,'all_five_support_intersection':1},'central_joint_case':{'i':5,'j':5,'SP_G2_primary_chain':[3708,3208,3108,2758,2608],'MT_G2_ON_T60_full430_chain':[3248,2748,2648,2298,2148]},'interpretation':'The sameGear−460 correspondence extends to all five selected source roles in each admitted primarybiography, with zero residuals; no wrongGear repair is needed. The joint-support intersectionis i=j5, but a unique intersection of these comparison tests is not a source-prescribed selector or evidence that distinct event identities merge.','suggested_next_bounded_question':'C323 should synthesize C314–C322: distinguish the fully source-qualified460biography correspondence and center overlap from the conditional paired22allK selection; preserve exact ancestry labels, finite failures, and the unresolved source-selection obligation.','C323_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'C322_Independent_Math_Results.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'status':'passed','source_biographies':3,'endpoint_residuals_zero':15,'phase_residuals_zero':30,'joint_support_i':[5]})) if __name__=='__main__':main()