#!/usr/bin/env python3 """Alternate root verification: output-first source joins and integer affine matrices. No primary CALCULATION.py is imported. This is not an independent-agent review. """ import argparse,json from pathlib import Path from itertools import product from fractions import Fraction def main(src,out): def load(name):return json.loads((src/name).read_text()) checks=[] def ck(name,value): assert value,name assert name not in checks,name checks.append(name) reg=load('C286_DATA.json')['target_register'];cum=load('C365_DATA.json')['cumulative_register'];coords={r['center'] for r in reg};cums={r['coordinate'] for r in cum} keys=['tradition','rail','Cainan','Terah60','full430'] def fam(r):return tuple(r.get(k) for k in keys) def get(f,g,role): rs=[r for r in reg if r['role']==role and r['gear']==g and all(r.get(k)==v for k,v in zip(keys,f) if k!='rail' or not role.startswith('Flood'))] assert len(rs)==1,(f,g,role);return rs[0] def sig(r):return (r['input_Gear'],fam(r['records']['x']),fam(r['records']['N']),r['Flood_boundary']) # Reverse the main census: start at target Shem/Noah and invert E to locate input. found=[];targets=[r for r in reg if r['role']=='Noah birth' and r['gear'] in [1,2]] for nr in targets: tf=fam(nr);g=nr['gear'];N=nr['center'];zr=get(tf,g,'Shem birth');z=zr['center'];num=23*z+2*N if num%25:continue x=num//25 for xr in [r for r in reg if r['role']=='Noah birth' and r['gear']==g and r['center']==x]: sf=fam(xr);yr=get(sf,g+1,'Noah birth');y=yr['center'];nn=get(tf,g+1,'Noah birth')['center'];wr=get(tf,g+1,'Shem birth');w=wr['center'];dr=get(tf,g+1,'Shem death');D=dr['center'] if 25*(y-nn)!=23*(w-nn) or 300*(z-D)!=299*(w-D):continue for boundary in ['Flood start','Flood close']: ar=get(sf,g+1,boundary);A=ar['center'] if 300*(x-A)==299*(y-A):found.append((g,sf,tf,boundary)) recorded=load('C390_DATA.json')['hits'] ck('output-first family census',len(targets)==64 and set(found)=={sig(r) for r in recorded} and len(found)==8) ck('fixed census coverage',load('C390_DATA.json')['counts']['labelled_trials']==32*32*2*2) # Integer homogeneous affine matrices: denominator is lower-right entry. def dil(p,q,a):return [[p,(q-p)*a],[0,q]] def mul(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)] def at(M,x):return Fraction(M[0][0]*x+M[0][1],M[1][1]) phasecount=0;matrices=[] for i,row in enumerate(load('C385_DATA.json')['rows']): A,B,x,y,N=row['original_tuple'];z=int(row['E_image_input']);w=int(row['E_image_output_with_next_Noah']);D=int(row['required_J_pivot']);h=y-x l=mul(dil(25,23,N+h),dil(300,299,A));r=mul(dil(300,299,D),dil(25,23,N)) ck('integer E J square '+str(i),l==r and at(l,x)==w) wrong=mul(dil(300,299,A+h),dil(25,23,N));wrongp=mul(dil(70,69,B+h),dil(25,23,N));lp=mul(dil(25,23,N+h),dil(70,69,B)) ck('direct moving pivot defects '+str(i),l[0][1]-wrong[0][1]==966 and lp[0][1]-wrongp[0][1]==966) ck('source target geometry '+str(i),N-z==500 and w-D==600 and z-D==598 and D==A-40 and (N+h-D)-(N-A)==42) ck('P pivot absent from complete register '+str(i),z-69*h==int(row['required_P_pivot']) and z-69*h not in coords) for lift in row['source_context_lifts']: label=(i,lift['tradition']);nr=lift['Noah_input_record'];nn=lift['Noah_next_record'];sr=lift['Shem_input_record'];ss=lift['Shem_output_record'];df=get(fam(nr),nr['gear']+1,'Shem death') ck('typed source joins '+str(label),all(r0 in reg for r0 in [nr,nn,sr,ss,df]) and df['center']==D and nr['center']==N and nn['center']==N+2 and sr['center']==z and ss['center']==w) good=[] for eps in product([-1,1],repeat=8): n0,n1,a0,x0,y0,z0,w0,d0=[4*v+e for v,e in zip([N,N+h,A,x,y,z,w,D],eps)] if 25*(x0-n0)==23*(z0-n0) and 25*(y0-n1)==23*(w0-n1) and 300*(x0-a0)==299*(y0-a0) and 300*(z0-d0)==299*(w0-d0):good.append(eps) ck('integer quarter-component census '+str(i),good==[(-1,)*8,(1,)*8]);phasecount+=len(good);matrices.append(l) # Static E can carry the original pivot images, but its repaired image is not integral. ck('static E image obstruction '+str(i),(25*y-2*N)%23!=0 and (25*x-2*N)==23*z) ck('derived529 P equivalence '+str(i),N-x==230*h and x-A==299*h and N-A==529*h and B-A==230*h and x-B==69*h and y-B==70*h) ck('all component successes match',phasecount==load('C386_DATA.json')['counts']['source_exact_component_squares']==8) for i,row in enumerate(load('C387_DATA.json')['mode_trials']): N=row['Noah_record']['center'];s=row['Shem_input_record']['center'];n1=row['next_Noah_record']['center'];w=row['Shem_output_record']['center'];D=row['Shem_death_pivot_record']['center'];orig=load('C385_DATA.json')['rows'][row['row']]['original_tuple'];x,y=orig[2:4] ck('mode residual cross multiplication '+str(i),Fraction(25*x-2*N-23*s,23)==Fraction(row['vertical_residual']) and Fraction(25*y-2*n1-23*w,23)==Fraction(row['vertical_residual'])) ck('mode J and inverse membership '+str(i),300*(s-D)==299*(w-D) and Fraction(23*s+2*N,25)==Fraction(row['unique_required_MT_input']) and bool(row['typed_MT_input_records'])==row['all_four_source_edges_pass']) strips=load('C388_DATA.json')['strips'] for i,st in enumerate(strips): x,y,v=st['MT_Noah_vertices'];z,_,w=map(int,st['SP_LXX_Shem_vertices']);N=st['Noah_centers'][0];A0,A1=st['J_Flood_pivots'];D0,D1=map(int,st['J_Shem_death_pivots']);right=mul(mul(dil(300,299,D1),dil(300,299,D0)),dil(25,23,N));left=mul(dil(25,23,N+4),mul(dil(300,299,A1),dil(300,299,A0))) ck('composed integer strip '+str(i),left==right and at(left,x)==w) for word in product('PJ',repeat=2): mats=[] for op,A in zip(word,[A0,A1]):mats.append(dil(300,299,A) if op=='J' else dil(70,69,A+460)) M=mul(dil(25,23,N+4),mul(mats[1],mats[0]));equal=all(M[a][b]*right[1][1]==right[a][b]*M[1][1] for a in range(2) for b in range(2)) ck('word endpoint versus map '+str((i,word)),at(M,x)==w and equal==(word==('J','J'))) for i,row in enumerate(load('C389_DATA.json')['rows']): C=row['existing_corner_sum'];S=row['source_native_Shem'];missing=[] for p in row['reflected_points']: u=int(p['regular_coordinate']);v=C-u;exists=v in cums ck('reflected membership '+str((i,p['regular_point'])),v==int(p['reflected_coordinate']) and exists==p['source_member']) if not exists:missing.append(v) ck('three absent cumulative counterparts '+str(i),set(missing)=={S+500,S+498,S+1098}) phases={4*v+e for v in cums for e in [-1,1]} ck('phase cannot rescue missing counterpart '+str(i),all(4*v+e not in phases for v in missing for e in [-1,1])) # Reverse E graph enumeration: compute each possible predecessor from an existing output. edgescount=0;pathcount=0;units=[] for i,g in enumerate(load('C392_DATA.json')['graphs']): N=g['Noah_pivot'];es=set() for target in coords: num=23*target+2*N if num%25==0 and num//25 in coords and num//25!=target:es.add((num//25,target)) ck('output-first complete E graph '+str(i),es=={(e['input'],e['output']) for e in g['edges']}) edgescount+=len(es);succ=dict(es);incoming={q for _,q in es};paths=[] for p in sorted(set(succ)-incoming): chain=[p] while chain[-1] in succ:chain.append(succ[chain[-1]]) paths.append(chain) ck('finite E graph path decomposition '+str(i),paths==g['maximal_paths'] and max(len(p) for p in paths)==3) pathcount+=len(paths) for p,q in es: if N-p==23 and N-q==25: units.append((N,p,q));heldg=next(r['gear'] for r in g['pivot_contexts'] if r['tradition']=='SP') for tr in ['SP','LXX']: f=(tr,'primary' if tr=='SP' else None,1,1,0);rr=get(f,heldg+1,'Noah birth');ss=get(f,heldg,'Noah birth') ck('unit E exact ancestry '+str((i,tr)),rr['center']==p and ss['center']==q and q==N-215+130+60) ck('observed E totals and unit edges',edgescount==29 and pathcount==25 and sorted(units)==[(3706,3683,3681),(3708,3685,3683)]) result={'status':'passed','method':'Output-first inversion and typed source joins; integer homogeneous affine matrices and quarter-component cross-products; output-first E graph enumeration. No primary calculation code imported.','performed_by':'root agent','new_independent_agent_review':False,'check_count':len(checks),'checks':checks,'complete_labelled_E_J_squares':len(found),'complete_coordinate_E_J_squares':4,'component_phase_successes':phasecount,'reflected_cumulative_squares':0,'held_Noah_E_edges':edgescount,'held_Noah_E_maximal_paths':pathcount,'source23_to25_edges':[list(v) for v in sorted(units)],'C394_executed':False,'canonical_or_graph_edits':False} out.mkdir(parents=True,exist_ok=True);(out/'ROOT_SECOND_METHOD_RESULTS.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'status':'passed','root_secondary_checks':len(checks)})) 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)