#!/usr/bin/env python3 """C318 independent paired458 typed source-path audit. --sources has PREVIOUS_DATA.json(C317), C286_DATA.json, C287_DATA.json. No later step. Exact phases use the inherited quarter-year representation. """ import argparse from fractions import Fraction as F from pathlib import Path import hashlib,json def main(): a=argparse.ArgumentParser();a.add_argument('--sources',type=Path);a.add_argument('--out',type=Path,default=Path(__file__).parent);a=a.parse_args();root=Path(__file__).resolve().parents[1] defaults={'PREVIOUS_DATA.json':root/'C317/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'];pairs=data['C286_DATA.json']['source_pairs'];before=data['PREVIOUS_DATA.json'];oldby={x['i']:x for x in data['C287_DATA.json']['rows']} cum={(x['Shem_Cainan'],x['Shem_index'],x['S']) for x in pairs} assert len(cum)==16 assert 650-130-60==460 and 600+(460-2)==2*529 def record(t,g,role,c,t60,center): return [x for x in reg if x['tradition']==t and x['gear']==g and x['role']==role and x['Cainan']==c and x['Terah60']==t60 and x['full430']==1 and x['center']==center] rows=[] for r in sorted(before['rows'],key=lambda x:x['i']): i,j,g,rail,p,f=r['i'],r['j'],r['gear'],r['rail'],r['p'],r['f'];role='Flood start' if rail=='primary' else 'Flood close' c0=(0,i,p);c1=(1,i,p-460);c2=(1,i+2,p-458) assert c0 in cum and c1 in cum ca=c2 in cum;assert ca==(i<=5) params=[('SP',g,role,0,0,f),('MT',g,role,0,0,f-650),('MT',g,role,1,0,f-520),('MT',g,role,1,1,f-460),('MT',g+1,role,1,1,f-458)] stages=[] for stage,args in enumerate(params): hits=record(*args) assert len(hits)==(1 if stage<4 or g<3 else 0) assert all(x.get('rail') is None for x in hits) stages.append({'stage':stage,'tradition':args[0],'gear':args[1],'role':role,'Cainan':args[3],'Terah60':args[4],'full430':1,'coordinate':args[5],'source_admitted':bool(hits),'source_record':hits[0] if hits else None}) ra=stages[-1]['source_admitted'];assert ra==ca prev=oldby.get(i) assert bool(prev and prev['complete'])==ca if ca: assert prev['S']==c2[2] and prev['R']==stages[-1]['coordinate'] and prev['F']==r['q'] and prev['Noah_required']==r['n'] cps=[] for c in r['components']: e=F(c['phase']);pp=F(c['p']);ff=F(c['f']);cp1=pp-460;cp2=cp1+2;rp1=ff-650;rp2=rp1+130;rp3=rp2+60;rp4=rp3+2 assert cp2==pp-458 and rp4==ff-458 assert ff-pp==rp4-cp2==8993 assert F(c['q'])-cp2==F(c['n'])-rp4==1058 # Same paired shift, applied before/afterT8993, commutes as arithmetic. assert (pp+8993)-458==(pp-458)+8993==rp4 cps.append({'phase':str(e),'cumulative_path':[str(pp),str(cp1),str(cp2)],'regular_path':[str(ff),str(rp1),str(rp2),str(rp3),str(rp4)],'T8993_commutation_residual':'0','two_resulting_sides':'1058','terminal_paths_source_admitted':ca}) rows.append({'i':i,'j':j,'SP_gear':g,'SP_birth_rail':rail,'selected_Flood_boundary':role,'cumulative_path':[{'Cainan':z[0],'annual_index':z[1],'coordinate':z[2],'source_admitted':z in cum} for z in [c0,c1,c2]],'regular_path':stages,'joint_source_admission':ca,'C287_endpoint_match':ca,'formal_paired_displacement':-458,'exact_phase_paths':cps,'failure_reasons':[] if ca else ['Cumulative ON-Shem annual index'+str(i+2)+' is outside retained0..7','Regular MT Gear4 source endpoint is absent; not created']}) assert [r['i'] for r in rows if r['joint_source_admission']]==[3,4,5] out={'step':'C318','status':'passed','input_sha256':hashes,'scope':'Typed decomposition of existing paired458 change on five fixed states.','rows':rows,'counts':{'cases':5,'cumulative_preterminal_admitted_paths':5,'regular_preterminal_admitted_paths':5,'joint_admitted_terminal_paths':3,'joint_failed_terminal_paths':2,'formal_exact_phase_commutations':10,'source_admitted_exact_phase_commutations':6},'identities':{'aggregate_regular_variant_difference':'650−130−60=460','common_displacement':'−460+2=−458','retained_2K_width':'600+(460−2)=1058=2×529'},'critical_distinctions':['Cumulative Cainan insertion460 and regular Cainan insertion130 are different typed operations.','Cumulative+2 changes the annual source index; regular+2 changes the Gear within the admitted Noah/Shem/Flood domain.','Only regular Flood start/close records are used; no SP companion is imported into MT.','Cumulative ON-Shem indices8/9 and regular Gear4 remain unadmitted.','The commuting equalities are conditional algebra on fixed source states, not extra independent529 witnesses or a global458 operator.'],'suggested_next_bounded_question':'Assemble the minimal typed dependency system for the C314–C318 equalities and determine which constraints remain independent after fixed source constants and the common8993 translations are imposed.','later_step_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'C318_Independent_Math_Results.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'status':'passed','admitted_terminal_paths':3,'failed_boundaries':2,'admitted_phase_commutations':6})) if __name__=='__main__':main()