#!/usr/bin/env python3 """C316 independent finite ancestry-shift and source-role audit. --sources has PREVIOUS_DATA.json(C315), C286_DATA.json, C287_DATA.json, C271_REGISTER.json. --out controls output. No further-step computation. """ import argparse from fractions import Fraction as F from pathlib import Path import hashlib,json def main(): p=argparse.ArgumentParser();p.add_argument('--sources',type=Path);p.add_argument('--out',type=Path,default=Path(__file__).parent);a=p.parse_args();root=Path(__file__).resolve().parents[1] paths={'PREVIOUS_DATA.json':root/'C315/evidence/DATA.json',**{n:root/'C313/sources'/n for n in ['C286_DATA.json','C287_DATA.json','C271_REGISTER.json']}} data={};hashes={} for name,path in paths.items(): raw=(a.sources/name if a.sources else path).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=data['C287_DATA.json'];before=data['PREVIOUS_DATA.json'];complete={x['i'] for x in four['rows'] if x['complete']} assert complete=={2,3,4,5} assert [x['j'] for x in before['rows']]==[3,4,5,6,7] phases=(F(-1,4),F(1,4));rows=[] for r in before['rows']: i,j,g,rail=r['i'],r['j'],r['gear'],r['rail'];n,s,f,nd,d=r['biography_BC'];h=i-2 assert i+j==10 and h+j==8 center_candidates=[k for k in range(8) if -5290+k+8395==f] assert center_candidates==[h] qi=-5290+i;qh=-5290+h assert qi-qh==2 and n-(qh+8395)==600 ar=[x for x in anc if x['branch']=='Flood' and x['source_event']['tradition']=='SP' and x['source_event']['gear']==g and x['source_event']['role']==r['selected_Flood_role']] assert len(ar)==1;ar=ar[0];src=ar['cumulative_source'];ks=src['source_index'];sx=-src['source_BC_base'] assert ks==i and src['source_role']=='Shem' and src['profile']=='LXX_OFF' assert sx==-5890+i and sx+8993==f assert qh-sx==598 and qi-sx==600 aliases=r['same_role_aliases'];gear_descent=[] for old in aliases: assert old['gear']==g+1 and old['center']-f==2 assert r['source_Flood']['role']==old['role'] candidates=[x for x in reg if x['tradition']=='SP' and x['role']==old['role'] and x['gear']==old['gear']-1 and x['Cainan']==0 and x['Terah60']==0 and x['full430']==1 and x['center']==f] assert len(candidates)==1 and candidates[0]==r['source_Flood'] gear_descent.append({'from_gear':old['gear'],'to_gear':g,'role_preserved':old['role'],'source_BC_difference':2}) cp=[] for c in r['components']: en=F(c['Noah_ancestry_phase']);target=F(c['selected_Flood']) matches=[(k,e) for k in range(8) for e in phases if F(-5290+k)+e+8395==target] assert matches==[(h,en)] asc=[x for x in ar['phases'] if F(x['reflected_coordinate'])==target] assert len(asc)==1;asc=asc[0] assert F(asc['cumulative_coordinate'])==sx+en assert F(asc['cumulative_coordinate'])+8993==target assert qh+en-F(asc['cumulative_coordinate'])==598 assert F(c['Noah'])-target==600 assert F(c['Shem'])-target==100 cp.append({'Noah_ancestry_i':i,'Noah_ancestry_epsilon':str(en),'new_Flood_ancestry_h':h,'new_Flood_ancestry_epsilon':str(en),'normalized_Shem_ancestry_j':j,'normalized_Shem_ancestry_epsilon':str(-en),'Noah_cumulative_Flood_coordinate':str(qi+en),'new_Flood_cumulative_Flood_coordinate':str(qh+en),'actual_C271_cumulative_Shem_index':ks,'actual_C271_cumulative_Shem_coordinate':asc['cumulative_coordinate'],'actual_C271_cumulative_phase':asc['cumulative_phase'],'Flood_output':str(target),'Flood_output_phase':asc['reflected_phase'],'T8395_and_T8993_route_difference':'0','new_cumulative_Flood_minus_C271_cumulative_Shem':'598','Noah_minus_selected_Flood':'600','unique_8395_match':[h,str(en)]}) support={'i':i in complete,'j':j in complete,'h':h in complete} rows.append({'j':j,'i':i,'h':h,'gear':g,'rail':rail,'source_Flood':r['source_Flood'],'unique_annual_h':h,'Noah_cumulative_Flood_index':i,'8395_cumulative_Flood_index':h,'C271_Flood_cumulative_role':'Shem','C271_Flood_cumulative_index':ks,'C271_role_and_index_distinct_from8395_ancestry':True,'source_bridge_factorization':{'C271_Shem_to_shifted_cumulative_Flood':598,'shifted_cumulative_Flood_to_regular_Flood':8395,'sum':8993},'regular_Gear_descent_available':bool(gear_descent),'regular_Gear_descent':gear_descent,'C287_support':support,'C287_all_three':all(support.values()),'phase_cases':cp}) assert [x['h'] for x in rows]==[5,4,3,2,1] assert [x['j'] for x in rows if x['C287_all_three']]==[5] assert [x['j'] for x in rows if x['regular_Gear_descent_available']]==[5,6,7] out={'step':'C316','status':'passed','input_sha256':hashes,'scope':'Fixed five C315 states; h0..7 and two retained phases only.','rows':rows,'counts':{'annual_matches':5,'phase_matches':10,'annual_candidate_checks':40,'phase_candidate_checks':160,'actual_C271_Flood_source_matches':5,'regular_Gear_descent_matches':3,'regular_Gear_descent_unavailable':2,'C287_at_i':sum(x['C287_support']['i'] for x in rows),'C287_at_j':sum(x['C287_support']['j'] for x in rows),'C287_at_h':sum(x['C287_support']['h'] for x in rows),'C287_at_all_three':sum(x['C287_all_three'] for x in rows)},'conclusions':['h=i−2 is unique in the fixed annual/phase domain; epsilon_h=epsilon_i=−epsilon_j.','All five actual Flood endpoints can retain8395 if its cumulative Flood ancestry changes by−2. This is not a same-ancestry repair.','Actual C271 Flood provenance is cumulative LXX_OFF Shem at indexi, not cumulative Flood at indexh.','The two routes agree because (cumulative Flood at h)−(cumulative Shem at i)=598 and598+8395=8993.','Three existing wrong-Gear endpoint aliases permit a regular same-role Gear descent; two formal endpoints have no admitted upper-Gear source.','Cumulative annual reindexing is not a cumulative Gear operation.','Only j5,i5,h3 supports the C287 complete four-node form at all three index values.'],'suggested_next_bounded_question':'Test whether the resolved three-ancestry correspondence adds an independent529 constraint or factors through the already retained598+8395=8993 relation, with C287 event roles kept explicit.','later_step_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'C316_Independent_Math_Results.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'status':'passed','annual_matches':5,'phase_matches':10,'regular_Gear_descent_matches':3,'all_three_C287':1})) if __name__=='__main__':main()