"""Separate source-grid and integer-affine verification by the root agent. No research calculation module is imported. Not an independent-agent review. """ from pathlib import Path from itertools import product,combinations from fractions import Fraction as F from collections import Counter,defaultdict import argparse,json,re,hashlib p=argparse.ArgumentParser();p.add_argument('--sources',type=Path,required=True);p.add_argument('--out',type=Path,required=True);a=p.parse_args() def load(name):return json.loads((a.sources/name).read_text()) checks=[] def ck(name,ok): assert ok,name assert name not in checks,name checks.append(name) r=load('C286_DATA.json')['target_register'];ds={n:load(f'C{n}_DATA.json') for n in range(424,433)} # Independently generate the entire record grid from current table baselines. text18=(a.sources/'File_18.md').read_text();text02=(a.sources/'File_02.md').read_text();lines18=text18.splitlines();mt=text02.splitlines()[658:716];lxx=lines18[1252:1282];sp=text18.split('#### 3.2.1 SP Noah/Shem field and named bindings',1)[1].split('####',1)[0];base={} for who in ['Noah','Shem']: cells=next(x for x in mt if x.startswith('| '+who+' |')).split('|');base['MT',who+' birth',None]=int(re.findall(r'\d+',cells[2])[-1]);base['MT',who+' death',None]=int(re.findall(r'\d+',cells[3])[-1]) cells=next(x for x in lxx if x.startswith('| LXX | '+who+' |')).split('|');v=list(map(int,re.findall(r'\d+',cells[4 if who=='Noah' else 3])));base['LXX',who+' birth',None],base['LXX',who+' death',None]=v for role,cell in zip(['Noah birth','Noah death','Shem birth','Shem death'],next(x for x in sp.splitlines() if x.startswith('| G1 |')).split('|')[2:6]): for rail,v in zip(['primary','companion'],map(int,cell.strip().split('/'))):base['SP',role,rail]=v fb={} for tr,label in [('MT','MT'),('SP','SP'),('LXX','LXX — native Cainan ON')]:fb[tr]=int(re.findall(r'(\d+)→(\d+)',next(x for x in lines18[1539:1552] if x.startswith('| '+label+' |')))[-1][0]) def key(x):return tuple(x.get(z) for z in ['tradition','role','rail','gear','Cainan','Terah60','full430','center']) generated=set() for tr,g,c,t,f in product(['MT','SP','LXX'],[1,2,3],[0,1],[0,1],[0,1]): delta=130*(c-int(tr=='LXX'))+60*t+215*f+2*(g-1) for role,rail in product(['Noah birth','Noah death','Shem birth','Shem death'],['primary','companion'] if tr=='SP' else [None]):generated.add((tr,role,rail,g,c,t,f,base[tr,role,rail]+delta)) for role in ['Flood start','Flood close']:generated.add((tr,role,None,g,c,t,f,fb[tr]-215+delta-int(role=='Flood close'))) ck('generated source grid equals528 records',len(generated)==528 and generated=={key(x) for x in r}) for i,x in enumerate(r):ck('generated source identity '+str(i),key(x) in generated) # All ordered record pairs, with no initial2K role or context selection. allpairs=[(i,j) for i,j in product(range(len(r)),repeat=2) if r[i]['center']-r[j]['center']==1058];coordpairs={(r[i]['center'],r[j]['center']) for i,j in allpairs};ck('complete2K pair inventory',len(allpairs)==46 and len(coordpairs)==26) ck('C426 exact record inventory',set(allpairs)=={(x['upper_record_index'],x['lower_record_index']) for x in ds[426]['labelled_pairs']}) fsnd=[(i,j) for i,j in allpairs if r[i]['role']=='Flood start' and r[j]['role']=='Noah death'];ck('C42416 seeds',len(fsnd)==16 and set(fsnd)=={tuple(x['seed_record_indices']) for x in ds[424]['cases']}) ctxkeys=['tradition','gear','Cainan','Terah60','full430'];ctx=lambda x:tuple(x[k] for k in ctxkeys) for i,j in fsnd: ups=[k for k,x in enumerate(r) if ctx(x)==ctx(r[i])];lows=[k for k,x in enumerate(r) if ctx(x)==ctx(r[j]) and (x['role'].startswith('Flood') or x.get('rail')==r[j].get('rail'))];hits={(u,z) for u,z in product(ups,lows) if r[u]['center']-r[z]['center']==1058};ck('isolated within source contexts '+str((i,j)),hits=={(i,j)}) ck('C425 full role menu',sum(x['role']=='Flood start' for x in r)*sum(x['role']=='Noah death' for x in r)==6912) terms=Counter();offsetcoords=defaultdict(set) for i,j in allpairs: u,z=r[i],r[j];v=(650*(int(u['tradition']!='MT')-int(z['tradition']!='MT')),130*(u['Cainan']-z['Cainan']),60*(u['Terah60']-z['Terah60']),215*(u['full430']-z['full430']),2*(u['gear']-z['gear']));terms[v]+=1;offsetcoords[sum(v)].add((u['center'],z['center'])) ck('four exact context templates',terms==Counter({(650,-130,-60,0,-2):20,(650,0,60,0,-2):16,(650,130,60,215,2):4,(650,130,60,215,4):6})) overlap={p for p in coordpairs if sum(p in c for c in offsetcoords.values())>1};ck('sole coordinate template overlap',overlap=={(3298,2240)}) mtnd=[x for x in r if x['tradition']=='MT' and x['role']=='Noah death'];mtfc=[x for x in r if x['tradition']=='MT' and x['role']=='Flood close'];coinc=[(x,z) for x,z in product(mtnd,mtfc) if x['center']==z['center']];ck('MT349 coincidence family',len(coinc)==2 and {x['center'] for x,z in coinc}=={2240,2300} and all((x['Cainan']-z['Cainan'],x['Terah60']-z['Terah60'],x['full430']-z['full430'],x['gear']-z['gear'])==(1,0,1,2) for x,z in coinc)) coords=sorted({x['center'] for x in r});cs=set(coords);by={v:[i for i,x in enumerate(r) if x['center']==v] for v in coords};ck('only2240 participates in2K',3298 in cs and 3358 not in cs) # Complete fixed Mirror comparisons. cum=load('C365_DATA.json')['cumulative_register'];cp={(s['coordinate'],f['coordinate']) for s,f in product(cum,cum) if s['role']=='Shem' and f['role']=='Flood' and f['coordinate']-s['coordinate']==1058};mirrors={(h,x,s,f) for (h,x),(s,f) in product(coordpairs,cp) if x-s==h-f==8993} ck('complete old Mirror geometry',len(cp)==6 and mirrors=={(3705,2647,-6346,-5288),(3706,2648,-6345,-5287),(3707,2649,-6344,-5286),(3708,2650,-6343,-5285)}) ck('C428 exact hits',mirrors=={(*x['regular_pair'],*x['cumulative_coordinates']) for x in ds[428]['hits']}) # Integer affine coefficients; retained record aliases checked on every output. ops={'E':(25,23),'E2':(625,529),'P':(70,69),'J':(300,299)};outrows={};counts=Counter();targets={};fixedpaths=[] for h,x in sorted(coordpairs): for op,(n,q) in ops.items(): y=F(n*x+(q-n)*h,q);outrows[h,x,op]=y;counts[op]+=y in cs if op=='E2' and y in cs: targets[h]=(x,int(y));mid=F(25*x-2*h,23) if mid in cs:fixedpaths.append((h,x,int(mid),int(y))) ck('complete harmonic counts',counts==Counter({'E':13,'E2':13,'P':0,'J':0}) and len(fixedpaths)==4) for row in ds[429]['operator_trials']: y=outrows[row['held_upper'],row['input_lower'],row['operator']];ck('harmonic output '+str((row['held_upper'],row['operator'])),y==F(row['output']['numerator'],row['output']['denominator']) and by.get(y,[])==row['source_record_indices']) floodlifts=[] for i,j in allpairs: h,x=r[i],r[j];y=outrows[h['center'],x['center'],'E'] if h['role']=='Flood start' and y in cs: for k in by[y]:floodlifts.append((i,j,k)) ck('twenty typed Flood-held arrows',len(floodlifts)==20 and set(floodlifts)=={(x['upper_record_index'],x['input_record_index'],x['output_record_index']) for x in ds[430]['record_labelled_arrows']}) ck('three-Gear strip input identity',[(g['held'],g['input'],g['output']) for g in ds[430]['C1_F1_three_Gear_strip']]==[(3296,2238,2146),(3298,2240,2148),(3300,2242,2150)]) ck('no Gear4 Noah source',all(not x['correct_Noah_death_record_indices'] for x in ds[430]['Noah_death_family_boundary_trials'] if x['upper_Gear']==3)) # Independent Cartesian pivot search and integer composition coefficients. pivots=[];complete=[] for p,q in product(coords,repeat=2): effective=25*p+23*q if effective%48 or effective//48 not in targets:continue h=effective//48;x,y=targets[h];mid=F(25*x-2*p,23);pivots.append((h,p,q));ck('Cartesian same-map equality '+str((h,p,q)),F(625*x-50*p-46*q,529)==y) if mid in cs:complete.append((h,p,q,int(mid))) expectedp={(row['target_held'],v['first_pivot'],v['second_pivot']) for row in ds[431]['target_maps'] for v in row['pivot_solutions']};ck('39 pivot pairs andfive paths',set(pivots)==expectedp and len(pivots)==39 and len(complete)==5) new=[v for v in complete if v[1]!=v[2]];ck('sole new path',new==[(3206,3620,2756,2020)]) ck('new same-map integer coefficients',50*3620+46*2756==96*3206 and 625*2148-307776==529*1956) ck('64 and 32 source gaps',[3620-2148,3620-2020,2756-2020,2756-1956]==[23*64,25*64,23*32,25*32]) ck('two source-labelled factorizations',len(by[3620])*len(by[2756])*len(by[2148])*len(by[2020])*len(by[1956])==2) ck('plus2 fails source intermediate',all(x in cs for x in [3622,2758,2150,1958]) and 2022 not in cs) # Same slope requires exactly two E factors: signed prime exponents. def factors(v): d=Counter();p=2 while p*p<=v: while v%p==0:d[p]+=1;v//=p p+=1 if v>1:d[v]+=1 return d powers={} for op,(n,q) in ops.items(): fn,fq=factors(n),factors(q);powers[op]={p:fn[p]-fq[p] for p in set(fn)|set(fq)} ck('positive-word slope restriction',powers['P'].get(7)==1 and all(powers[k].get(7,0)==0 for k in ['E','J','E2']) and powers['J'].get(13)==-1 and all(powers[k].get(13,0)==0 for k in ['E','P','E2']) and powers['E2'][5]==2*powers['E'][5]) # Quarter components using signed integers rather than fractions of chronology coordinates. ck('no fixed quarter-component path',not any(25*ei==23*em and 625*ei==529*eo for ei,em,eo in product([-1,1],repeat=3))) for card in ds[432]['source_excerpt_cards']: text='\n'.join((a.sources/card['source']).read_text().splitlines()[card['line_start']-1:card['line_end']]);ck('source excerpt '+card['id'],text==card['text'] and hashlib.sha256(text.encode()).hexdigest()==card['excerpt_sha256']) result={'status':'passed','check_count':len(checks),'checks':checks,'new_independent_agent_review':False,'method':'Root-agent source-grid generation, complete record/context census, integer affine outputs, Cartesian pivot search and prime/quarter-integer controls; no main calculation imports.','source_records_generated':len(generated),'labelled_2K_pairs':len(allpairs),'coordinate_2K_pairs':len(coordpairs),'context_templates':len(terms),'fixed_17K_rectangles':len(mirrors),'sourced_E_outputs':counts['E'],'sourced_E2_outputs':counts['E2'],'sourced_two_pivot_solutions':len(pivots),'complete_coordinate_paths':len(complete),'new_distinct_pivot_paths':[list(x) for x in new],'C434_executed':False} a.out.mkdir(parents=True,exist_ok=True);(a.out/'ROOT_SECOND_METHOD_RESULTS.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps({k:v for k,v in result.items() if k!='checks'}))