#!/usr/bin/env python3 """Alternate root verification: forced pivots, integer maps, output-first domain, residue-class chains, backward record-path enumeration and direct table parsing. No primary CALCULATION.py is imported. No independent-agent review is claimed. """ import argparse,json,hashlib from pathlib import Path from fractions import Fraction as Q from math import gcd from itertools import product from collections import Counter,defaultdict def main(src,out): def load(n):return json.loads((src/n).read_text()) checks=[] def ck(name,ok): assert ok,name assert name not in checks,name checks.append(name) reg=load('C286_DATA.json')['target_register'];coords={r['center'] for r in reg} def norm(a,b,d): g=gcd(gcd(abs(a),abs(b)),abs(d));return(a//g,b//g,d//g) def dil(p,q,c): c=Q(c);return norm(p*c.denominator,(q-p)*c.numerator,q*c.denominator) def comp(a,b):return norm(a[0]*b[0],a[0]*b[1]+a[1]*b[2],a[2]*b[2]) def coeff(t):return[str(Q(t[0],t[2])),str(Q(t[1],t[2]))] def same(a,b,keys):return all(a.get(k)==b.get(k) for k in keys) ratios={'E':(25,23),'P':(70,69),'J':(300,299)} strip=load('C388_DATA.json')['strips'][0];charts=dict(zip(strip['MT_Noah_vertices'],strip['Noah_centers']));supported=[] for i,e in enumerate(load('C400_DATA.json')['edges']): p,q=ratios[e['operator']];u,v=e['input'],e['output'];z,w=u-40,v-40;V=Q(p*z-q*w,p-q) left=comp(dil(25,23,charts[v]),dil(p,q,e['pivot']));right=comp(dil(p,q,V),dil(25,23,charts[u])) row=load('C404_DATA.json')['edge_transport'][i] ck('integer moving-chart square '+str(i),left==right and str(V)==row['required_Shem_pivot'] and (V in coords)==bool(row['source_pivot_records'])) supported.append(V in coords) admitted=sum(all(supported[i] for i in p['edge_indices']) for p in load('C400_DATA.json')['path_trials']) ck('only sourced J paths survive E charts',supported==[False,False,True,False,False,True] and admitted==6) for i,p in enumerate(load('C400_DATA.json')['path_trials']): u,v=p['start'],p['end'];e,jp,j=[p['counts'][x] for x in ['E','P','J']];m=Q(25,23)**e*Q(70,69)**jp*Q(300,299)**j ck('translated path endpoint normal form '+str(i),load('C405_DATA.json')['translated_paths'][i]['affine_coefficients']==[str(m),str(Q(v-500)-m*(u-500))]) # Target-first source census: each adjacent pair forces both pivots. keys=['tradition','rail','Cainan','Terah60','full430'] def fam(r):return tuple(r.get(k) for k in keys) bs=[r for r in reg if r['role']=='Shem birth'];ds=[r for r in reg if r['role']=='Shem death'];forced=[] for lo in bs: if lo['gear']==3:continue hi=next(r for r in bs if fam(r)==fam(lo) and r['gear']==lo['gear']+1);y,x=lo['center'],hi['center'];V=(25*x-23*y)//2;A=y-299*(x-y) for held in bs: if held['gear']!=lo['gear'] or held['center']!=V:continue deaths=[r for r in ds if fam(r)==fam(lo) and r['gear']==hi['gear'] and r['center']==A] for d in deaths:forced.append((lo,hi,held,d)) def sig(rs):return tuple(tuple(sorted(r.items())) for r in rs) expected={sig(tuple(h['records'][k] for k in ['lower_Shem','higher_Shem','held_Shem','J_Shem_death'])) for h in load('C406_DATA.json')['hits']} ck('forced-pivot Shem census',len(forced)==12 and {sig(r) for r in forced}==expected) ck('complete P closure',sum(r[0]['center']-138 in coords for r in forced)==2) for i,h in enumerate(load('C405_DATA.json')['loop_translations']): for key,s in h['Shem_records'].items(): n=h['Noah_records'][key] ck('source500 slot '+str((i,key)),s in reg and n in reg and n['center']-s['center']==500 and same(n,s,['tradition','gear','Cainan','Terah60','full430'])) for i,row in enumerate(load('C407_DATA.json')['binding_trials']): ok=all(s['matching_records'] for s in row['slots']) ck('mode boundary '+str(i),ok==row['all_required_records_sourced']==(row['shift']==500 or row['original_lower_Gear']==2) and all(s['matching_records'] or s['required_Gear']==0 for s in row['slots'])) # Two-E maps compared by the weighted fixed-point formula, not map composition. ees=sorted({(hi['center'],lo['center'],held['center']) for lo,hi,held,d in forced});pairs=[(a,b) for a in ees for b in ees if a[1]==b[0]] ck('three slope-compatible EE paths',len(pairs)==3) errors=[];phasehits=0 for i,(a,b) in enumerate(pairs): V=Q(25*a[2]+23*b[2],48) for target in load('C361_DATA.json')['rows']: pivot=target['squared_E']['pivot']['center'];err=(1-Q(625,529))*(V-pivot);errors.append(err) ck('weighted-pivot whole-map obstruction '+str((i,target['i'])),err!=0) for e1,e2,et in product([-Q(1,4),Q(1,4)],repeat=3): phasehits+=Q(25*(a[2]+e1)+23*(b[2]+e2),48)==pivot+et ck('nearest map discrepancy and phase exclusion',min(map(abs,errors))==Q(4,529) and phasehits==0) # Frozen original corners, without using a fitted exchange. cum={r['coordinate'] for r in load('C365_DATA.json')['cumulative_register']};refslots=0 for row in load('C287_DATA.json')['rows']: if row['i'] not in [3,5]:continue N,R,S,F=row['Noah_required'],row['R'],row['S'],row['F'];C=N+S ck('fixed rectangle translation '+str(row['i']),N-R==F-S==1058 and N-500-F==R-500-S==8493 and C-(N-500) not in cum and C-(R-500) not in cum) for h in load('C405_DATA.json')['loop_translations']: for r in list(h['Shem_records'].values())+h['P_Shem_death_records']: assert C-r['center'] not in cum;refslots+=1 ck('all new reflected source slots absent',refslots==104) # Output-first domain enumeration and residue-class runs replace forward paths. arrows={(v+500,v) for v in coords if v+500 in coords};primary={(e['input'],e['output']) for e in load('C410_DATA.json')['source_edges']} ck('output-first500 domain',arrows==primary and len(arrows)==169) groups=defaultdict(list) for x in coords:groups[x%500].append(x) chains=[] for group in groups.values(): run=[] for x in sorted(group): if run and x-run[-1]!=500: if len(run)>1:chains.append(tuple(reversed(run))) run=[] run.append(x) if len(run)>1:chains.append(tuple(reversed(run))) ck('residue-class chain census',{tuple(p['vertices']) for p in load('C410_DATA.json')['maximal_paths']}==set(chains) and len(chains)==141 and max(map(len,chains))==5) labels={(i,j) for i,a in enumerate(reg) for j,z in enumerate(reg) if a['center']-z['center']==500} ck('all raw source label pairs',len(labels)==392) rolelinks=set();bridge=set() for i,j in labels: a,z=reg[i],reg[j];common=same(a,z,['tradition','gear','Cainan','Terah60','full430']);ctx=same(a,z,['gear','Cainan','Terah60','full430']) nb=a['role']=='Noah birth' and z['role']=='Shem birth' and common and a.get('rail')==z.get('rail') fs=a['role']=='Flood start' and z['role']=='Shem death' and common and z.get('rail')==('primary' if a['tradition']=='SP' else None) fc=a['role']=='Flood close' and z['role']=='Shem death' and common and a['tradition']=='SP' and z.get('rail')=='companion' sn=a['role']=='Shem death' and z['role']=='Noah death' and a['tradition'] in ['SP','LXX'] and z['tradition']=='MT' and ctx and a.get('rail') in [None,'primary'] if nb or fs or fc or sn:rolelinks.add((i,j)) if a['role']=='Shem birth' and z['role']=='Flood start':bridge.add((i,j)) ck('role-defined and bridge label counts',len(rolelinks)==240 and len(bridge)==2 and {(reg[i]['center'],reg[j]['center']) for i,j in bridge}=={(3395,2895)}) def backward_paths(links): preds=defaultdict(list);starts=set();ends=set() for a,b in sorted(links):preds[b].append(a);starts.add(a);ends.add(b) paths=[] def back(p): if p[0] not in preds:paths.append(tuple(p));return for a in preds[p[0]]:back([a]+p) for end in sorted(ends-starts):back([end]) return paths pre=backward_paths(rolelinks);post=backward_paths(rolelinks|bridge) ck('backward record-path census',len(pre)==192 and max(map(len,pre))==3 and len(post)==191 and Counter(map(len,post))==Counter({2:143,3:46,5:2})) ck('record path identities match primary',set(post)=={tuple(p) for p in load('C411_DATA.json')['continuous_paths_with_bridge']}) modes=[(c,t,f,g,h,r) for c,t,f in product([-1,0,1],repeat=3) for g,h in product([1,2,3],repeat=2) for r in [0,1] if 100+130*c+60*t+215*f+2*(g-h)-r==500] ck('unique bridge source mode',modes==[(1,1,1,1,3,1)]) # Parse source tables separately, using table cells rather than primary regexes. d412=load('C412_DATA.json');cards={c['id']:c for c in d412['source_excerpt_cards']} for key,c in cards.items(): text='\n'.join((src/c['source']).read_text().splitlines()[c['line_start']-1:c['line_end']]) ck('source card identity '+key,text==c['text'] and hashlib.sha256(text.encode()).hexdigest()==c['excerpt_sha256']) bases={} for who in ['Noah','Shem']: row=next(l for l in cards['MT_PERSONS']['text'].splitlines() if l.startswith('| '+who+' |')).split('|') for role,cell in [('birth',row[2]),('death',row[3])]:bases['MT',who+' '+role,None]=int(cell.strip().split('/')[1].split()[0]) row=next(l for l in cards['PERSON_BASES']['text'].splitlines() if l.startswith('| LXX | '+who+' |')).split('|') cell=row[4] if who=='Noah' else row[3];birth,death=cell.strip().split()[0].split('–') bases['LXX',who+' birth',None]=int(birth);bases['LXX',who+' death',None]=int(death) sp=next(l for l in cards['SP_FIELD']['text'].splitlines() if l.startswith('| G1 |')).split('|')[2:6] for role,cell in zip(['Noah birth','Noah death','Shem birth','Shem death'],sp): a,z=map(int,cell.strip().split('/'));bases['SP',role,'primary']=a;bases['SP',role,'companion']=z floods={} for tr,label in [('MT','MT'),('SP','SP'),('LXX','LXX — native Cainan ON')]:floods[tr]=int(next(l for l in cards['FLOOD']['text'].splitlines() if l.startswith('| '+label+' |')).split('|')[4].strip().split('→')[0]) for i,r in enumerate(reg): tr=r['tradition'];offset=130*r['Cainan']-130*int(tr=='LXX')+60*r['Terah60']+2*r['gear']-2 if r['role'].startswith('Flood'):x=floods[tr]+offset+215*r['full430']-215-int(r['role']=='Flood close') else:x=bases[tr,r['role'],r.get('rail')]+offset+215*r['full430'] ck('direct table record '+str(i),x==r['center']) result={'status':'passed','performed_by':'root agent','new_independent_agent_review':False,'method':'Integer affine cross-products; endpoint-forced Shem pivots; weighted fixed-point obstruction; fixed-corner reflection; output-first500 domain; residue-class chains; backward record paths; independent table-cell reconstruction. No primary calculation imported.','check_count':len(checks),'checks':checks,'source_Shem_labelled_loops':12,'source_Shem_coordinate_loops':6,'complete_Shem_E_P_J_graphs':2,'surviving_E_chart_paths':admitted,'squared_E_replacement_matches':0,'reflected_Shem_source_slots':refslots,'reflected_source_hits':0,'translation_coordinate_arrows':len(arrows),'maximal_coordinate_chains':len(chains),'continuous_four_step_record_paths':2,'source_records_reconstructed':len(reg),'C414_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)