#!/usr/bin/env python3 """Alternate root verification: endpoint-first joins and integer affine matrices.""" import argparse,json from pathlib import Path from fractions import Fraction as Q from itertools import product from collections import defaultdict def main(src,out): def load(n):return json.loads((src/n).read_text()) checks=[] def ck(n,v): assert v,n assert n not in checks,n checks.append(n) reg=load('C286_DATA.json')['target_register'];cum=load('C365_DATA.json')['cumulative_register'];menus={'regular':reg,'cumulative':cum};found={};coords={};pivots={} d378=load('C378_DATA.json') # Enumerate endpoint pairs first, the reverse of the main pivot-first census. for field,records in menus.items(): at=defaultdict(list);fl=set() for r in records: v=r['center'] if field=='regular' else r['coordinate'];at[v].append(r) if r['role'].startswith('Flood'):fl.add(v) coords[field]=at;pivots[field]=fl;hits=set() for x in at: for y in at: if x==y:continue gain=y-x;A=x-299*gain;B=x-69*gain if A in fl and B in fl:hits.add((A,B,x,y)) recorded=next(f for f in d378['fields'] if f['field']==field) expected={(r['J_pivot'],r['P_pivot'],r['input'],r['output']) for r in recorded['hits']} ck('endpoint-first exhaustive census '+field,hits==expected) intpairs=[(A,B) for A in fl for B in fl if A!=B and (B-A)%230==0] ck('integral pivot pair census '+field,len(intpairs)==len(recorded['integer_candidates']) and len(fl)*(len(fl)-1)==recorded['counts']['ordered_distinct_pivot_pairs']) ck('unit gain excluded by pivot membership '+field,not any(abs(B-A)==230 for A in fl for B in fl)) found[field]=sorted(hits) ck('six cumulative four regular hits',len(found['cumulative'])==6 and len(found['regular'])==4) # Output-first reconstruction of every nontrivial fixed-pivot edge. for row in load('C376_DATA.json')['rows']: field=row['field'];i=row['i'];at=coords[field];edges=set() for op,num,den,a in [('J',300,299,row['J_pivot']),('P',70,69,row['P_pivot'])]: for y in at: numerator=num*a+den*(y-a) if numerator%num:continue x=numerator//num if x in at and x!=y:edges.add((op,x,y)) expected={(e['operator'],e['from_coordinate'],e['to_coordinate']) for e in row['edges']} ck('output-first fixed pivot graph '+str((field,i)),edges==expected) ck('no forward continuation at fixed pivots '+str((field,i)),not any(x==row['candidate_output'] for _,x,y in edges)) # Source ancestry, role qualification and local950 obstruction. for row in load('C377_DATA.json')['rows']: i=row['i'];s=row['source_death'];t=row['target_death'];bs=row['source_birth'];bt=row['target_birth'];a=row['MT_Flood_pivot'] ck('unit edge source ancestry '+str(i),all(p in reg and p['tradition']=='SP' and p['Cainan']==p['Terah60']==p['full430']==1 for p in [s,t,bs,bt])) ck('unit edge biography cross products '+str(i),t['center']-s['center']==bt['center']-bs['center']==1 and bs['center']-s['center']==bt['center']-t['center']==950 and 300*(bs['center']-a)-299*(bt['center']-a)==950) # Four complete source-corner rows, including typed companion failures. for r in load('C375_DATA.json')['rows']: i=r['i'];C=r['corner_sum_diagnostic'];A,AR=r['paired_pivots']['cumulative_OFF_to_MT'];B,BR=r['paired_pivots']['cumulative_ON_to_SP'];u,v=r['cumulative_input_output'];M,Y=r['actual_MT_input_output'];e=int(r['rail']=='companion') ck('both source pivot exchanges '+str(i),C-A==AR and C-B==BR) ck('typed middle exchange '+str(i),C-u==M-e and C-v==Y-e and (e==0)==r['actual_source_input_output_carried']) for n,d,p,q in [(300,299,A,AR),(70,69,B,BR)]: ck('integer conjugacy coefficients '+str((i,n)),d*C-(d-n)*p==n*C+(d-n)*q) for off in [-1,1]:ck('exchange phase sign '+str((i,off)),4*C-(4*u+off)==4*(C-u)-off and 4*C-(4*u+off)!=4*(C-u)+off) # Qualify all regular source hits and pair them with cumulative source edges. states=[] for A,B,x,y in found['regular']: xr=next(r for r in reg if r['center']==x and r['role']=='Noah birth' and r['tradition']=='MT' and r['Cainan']==r['Terah60']==1) full=xr['full430'];g=xr['gear'];N=x+460 ar=[r for r in reg if r['center']==A and r['tradition']=='MT' and r['role']=='Flood start' and r['Cainan']==r['Terah60']==1 and r['full430']==full and r['gear']==g+1] yr=[r for r in reg if r['center']==y and r['tradition']=='MT' and r['role']=='Noah birth' and r['Cainan']==r['Terah60']==1 and r['full430']==full and r['gear']==g+1] ck('regular exact context join '+str(A),bool(ar and yr) and B-A==N-x==460 and N-A==1058) for tr in ['SP','LXX']: bp=[r for r in reg if r['center']==B and r['tradition']==tr and r['role']=='Flood start' and r['gear']==g+1 and r['Cainan']==r['Terah60']==0 and r['full430']==full] np=[r for r in reg if r['center']==N and r['tradition']==tr and r['role']=='Noah birth' and r['gear']==g and r['Cainan']==r['Terah60']==0 and r['full430']==full and r.get('rail')==('primary' if tr=='SP' else None)] ck('counterpart typed source join '+str((A,tr)),bool(bp and np)) for q,f,u,v in found['cumulative']: S=u-460;sr=[r for r in cum if r['coordinate']==S and r['role']=='Shem' and r['Cainan']==1];assert len(sr)==1 i=next(r['annual_index'] for r in cum if r['coordinate']==q and r['role']=='Flood' and r['Cainan']==0) state={'key':f'{full}:{g}:{i}','in':(u,x),'out':(v,y),'corners':(S,q,A,N),'delta':A-S-17*529,'C':S+N} ck('pair corners and2K source sides '+state['key'],q-S==N-A==1058 and A-S==N-q and S+N==q+A==u+x==v+y) states.append(state) good=[s for s in states if s['delta']==0];ck('original full Mirror pairings',sorted(s['key'] for s in good)==['1:1:3','1:2:5']) for s in good: S,q,R,N=s['corners'];u,m=s['in'];v,n=s['out'];old=[[b-a for b in [R,m,N]] for a in [S,u,q]];new=[[b-a for b in [R,n,N]] for a in [S,v,q]] ck('full span matrix displacement '+s['key'],[[new[i][j]-old[i][j] for j in range(3)] for i in range(3)]==[[0,2,0],[2,4,2],[0,2,0]] and m-u==17*529+138 and n-v==17*529+142) at={s['in']:s for s in states};links=[] for s in states: if s['out'] in at: t=at[s['out']];links.append((s['key'],t['key'])) ck('paired path separation and corner sum '+s['key'],t['delta']==s['delta']+4 and t['C']==s['C'] and [b-a for a,b in zip(s['corners'],t['corners'])]==[-2,-2,2,2]) ck('paired path cannot retain17K '+s['key'],not(s['delta']==t['delta']==0)) ck('eight paired source paths replay',sorted(links)==sorted((r['from_key'],r['to_key']) for r in load('C381_DATA.json')['two_step_paths']) and len(links)==8) # Rebuild maximal coordinate paths without importing a main path builder. groups=defaultdict(dict) for field,hits in found.items(): for A,B,x,y in hits: full=None if field=='cumulative' else next(r['full430'] for r in reg if r['center']==x and r['tradition']=='MT' and r['role']=='Noah birth' and r['Cainan']==r['Terah60']==1) groups[field,full][x]=(A,B,y) pathrows=[] for (field,full),edge in groups.items(): ends={v[2] for v in edge.values()} for start in sorted(set(edge)-ends): vals=[start];x=start while x in edge:x=edge[x][2];vals.append(x) pathrows.append((field,full,vals)) expected=[(p['field'],p['full430'],p['source_vertices']) for p in load('C380_DATA.json')['paths']] ck('complete maximal source paths',sorted(pathrows,key=str)==sorted(expected,key=str)) # Integer2x2 affine matrices: denominator is their lower-right entry. def mat(n,d,a):return [[n,(d-n)*a],[0,d]] def mm(a,b):return [[sum(a[i][k]*b[k][j] for k in range(2)) for j in range(2)] for i in range(2)] squares=load('C380_DATA.json')['consecutive_edge_pairs'] for k,s in enumerate(squares): a=s['first_edge'];b=s['second_edge'];A=a['J_pivot'];B=a['P_pivot'];h=s['common_gain'];D=B-A left=mm(mat(70,69,B+h),mat(300,299,A));right=mm(mat(300,299,A+h),mat(70,69,B)) staticL=mm(mat(70,69,B),mat(300,299,A));staticR=mm(mat(300,299,A),mat(70,69,B)) ck('integer moving-square matrix equality '+str(k),left==right and left[0][0]*a['input']+left[0][1]==left[1][1]*b['output']) ck('integer fixed-pivot defect '+str(k),staticL[0][1]-staticR[0][1]==D and staticL[1][1]==20631 and D==230*h) words=0 for k,path in enumerate(load('C380_DATA.json')['paths']): x0=path['source_vertices'][0];xn=path['source_vertices'][-1];h=path['signed_step'];es=path['edges'];classes={} for t,e in enumerate(es): for name,n,d,a in [('P',70,69,e['P_pivot']),('J',300,299,e['J_pivot'])]: ck('integer translated-frame center '+str((k,t,name)),(d-n)*a+n*t*h-d*(t+1)*h==(d-n)*x0) for word in product('PJ',repeat=len(es)): m=[[1,0],[0,1]] for name,e in zip(word,es):m=mm(mat(70,69,e['P_pivot']) if name=='P' else mat(300,299,e['J_pivot']),m) p=word.count('P');words+=1 ck('integer finite word endpoint '+str((k,word)),m[0][0]*x0+m[0][1]==m[1][1]*xn and m[0][0]==70**p*300**(len(es)-p) and m[1][1]==69**p*299**(len(es)-p)) coeff=(Q(m[0][0],m[1][1]),Q(m[0][1],m[1][1])) if p in classes:ck('same-count integer matrix comparison '+str((k,word)),classes[p]==coeff) else:classes[p]=coeff ck('six squares24words',len(squares)==6 and words==24) result={'status':'passed','method':'Root-authored alternate endpoint-first exhaustive joins, output-first fixed-pivot edges and integer2x2 affine matrices. No main calculation imported; shared frozen sources and same analyst.','new_independent_agent_review':False,'check_count':len(checks),'checks':checks,'common_source_hits':{k:[list(v) for v in vs] for k,vs in found.items()},'original_Mirror_states':sorted(s['key'] for s in good),'paired_two_step_paths':len(links),'paired_two_step_paths_preserving17K':0,'source_mixed_squares':len(squares),'finite_word_routes':words,'C384_executed':False} out.mkdir(parents=True,exist_ok=True);(out/'ROOT_SECOND_METHOD_RESULTS.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps({'status':'passed','checks':len(checks),'common_source_hits':{k:len(v) for k,v in found.items()},'mixed_squares':len(squares)})) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--sources',type=Path,required=True);p.add_argument('--out',type=Path,required=True);a=p.parse_args();main(a.sources,a.out)