"""Separate root-agent checks using direct pair enumeration and integer affine coefficients. No main calculation module is imported. Counts describe verification, not witnesses. """ from pathlib import Path from fractions import Fraction as F from itertools import combinations,product from collections import Counter import argparse,json,re,hashlib p=argparse.ArgumentParser();p.add_argument('--sources',type=Path,required=True);p.add_argument('--out',type=Path,required=True);args=p.parse_args() def load(name):return json.loads((args.sources/name).read_text()) checks=[] def ck(name,yes): assert yes,name assert name not in checks,name checks.append(name) def frac(x):return F(x['numerator'],x['denominator']) r=load('C286_DATA.json')['target_register'];coords=sorted({x['center'] for x in r});by={v:[i for i,x in enumerate(r) if x['center']==v] for v in coords};d={n:load(f'C{n}_DATA.json') for n in range(414,423)} # Rebuild source coordinates directly from source table cells, then derive all comparisons. mt=(args.sources/'File_02.md').read_text().splitlines()[658:716] sptext=(args.sources/'File_18.md').read_text().split('#### 3.2.1 SP Noah/Shem field and named bindings',1)[1].split('####',1)[0] lxx=(args.sources/'File_18.md').read_text().splitlines()[1252:1282] base={} for who in ['Noah','Shem']: line=next(z for z in mt if z.startswith('| '+who+' |'));cells=line.split('|');nums=[list(map(int,re.findall(r'\d+',z))) for z in cells[2:4]] base['MT',who+' birth',None]=nums[0][-1];base['MT',who+' death',None]=nums[1][-1] line=next(z for z in lxx if z.startswith('| LXX | '+who+' |'));cells=line.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 cells=next(z for z in sptext.splitlines() if z.startswith('| G1 |')).split('|')[2:6] for role,cell in zip(['Noah birth','Noah death','Shem birth','Shem death'],cells): a,b=map(int,cell.strip().split('/'));base['SP',role,'primary']=a;base['SP',role,'companion']=b floodtext=(args.sources/'File_18.md').read_text().splitlines()[1539:1552];fb={} for tr,label in [('MT','MT'),('SP','SP'),('LXX','LXX — native Cainan ON')]: line=next(z for z in floodtext if z.startswith('| '+label+' |'));pairs=re.findall(r'(\d+)→(\d+)',line);fb[tr]=int(pairs[-1][0]) for i,x in enumerate(r): shift=sum([130*x['Cainan'],60*x['Terah60'],215*x['full430'],2*x['gear']])-2-130*(x['tradition']=='LXX') b=(fb[x['tradition']]-215-(x['role']=='Flood close')) if x['role'].startswith('Flood') else base[x['tradition'],x['role'],x.get('rail')] ck('direct table polynomial '+str(i),b+shift==x['center']) # C414: enumerate unordered coordinate pairs instead of subtractive lookups. pairs={(a,b) for b,a in combinations(coords,2) if a-b==1058};survive={(a,b) for a,b in pairs if (a-500,b-500) in pairs};twice={(a,b) for a,b in survive if (a-500,b-500) in survive} ck('C414 full pair set',pairs=={(x['upper'],x['lower']) for x in d[414]['source_pairs']}) ck('C414 translation domain',len(pairs)==26 and len(survive)==6 and not twice) ck('C414 record pair inventory',sum(len(by[a])*len(by[b]) for a,b in pairs)==46) # C415: construct only the Noah/Flood-to-Shem role rules actually used here. identity=['tradition','gear','Cainan','Terah60','full430'] def edge(i,j): a,b=r[i],r[j] if a['center']-b['center']!=500 or any(a[k]!=b[k] for k in identity):return False if (a['role'],b['role'])==('Noah birth','Shem birth'):return a.get('rail')==b.get('rail') if (a['role'],b['role'])==('Flood start','Shem death'):return b.get('rail')==('primary' if a['tradition']=='SP' else None) if (a['role'],b['role'])==('Flood close','Shem death'):return a['tradition']=='SP' and b.get('rail')=='companion' return False lifts=set();raw=0 for a,b in survive: for i,j,k,l in product(by[a],by[b],by[a-500],by[b-500]): raw+=1 if edge(i,k) and edge(j,l):lifts.add((i,j,k,l)) recorded={tuple(z['record_indices']) for row in d[415]['pair_transports'] for z in row['typed_lifts']} ck('C415 derived typed lift identities',lifts==recorded and len(lifts)==10 and raw==19) ck('bridge cannot touch pair endpoints',all(3395 not in p for p in survive)) # C416-417: independent context vectors and all pairwise difference vectors. keys=['tradition','rail','gear','Cainan','Terah60','full430'];roles=['Noah birth','Shem birth','Noah death','Shem death'];groups={} for x in r: if x['role'] in roles:groups.setdefault(tuple(x.get(k) for k in keys),{})[x['role']]=x['center'] ck('96 complete four-station contexts',len(groups)==96 and all(set(v)==set(roles) for v in groups.values())) hits=[];hist=Counter() for (ka,a),(kb,b) in combinations(groups.items(),2): offsets=tuple(a[t]-b[t] for t in roles);assert len(set(offsets))==1 hist[abs(offsets[0])]+=1 if set(offsets)=={1058}:hits.append((ka,kb)) if set(offsets)=={-1058}:hits.append((kb,ka)) expected=(('SP','companion',3,1,1,1),('MT',None,1,0,0,0)) ck('unique complete2K profile',hits==[expected]) ck('full offset histogram',hist==Counter({x['offset']:x['context_pairs'] for x in d[417]['offset_distribution']}) and sum(hist.values())==4560) u,z=[groups[k] for k in expected] for a,b in combinations(roles,2):ck('profile interval '+a+' / '+b,u[a]-u[b]==z[a]-z[b]) ck('950 and600 biographies',[u['Noah birth']-u['Noah death'],u['Shem birth']-u['Shem death']]==[950,600]) # C418: same-boundary parity and fixed-source five-station columns. five=[(3899,2841),(3399,2341),(3299,2241),(2949,1891),(2799,1741)] ck('five-station source membership',all(a in by and b in by and a-b==1058 for a,b in five)) ck('five-station partition',[(five[i][0]-five[i+1][0],five[i][1]-five[i+1][1]) for i in range(4)]==[(500,500),(100,100),(350,350),(150,150)]) for gu,gl in product([1,2,3],repeat=2):ck('same-boundary odd offset '+str((gu,gl)),(1055+2*(gu-gl))%2==1) ck('C418 boundary matrix',[x['difference'] for x in d[418]['fixed_Gear_boundary_matrix']]==[1059,1060,1058,1059]) # C419: solve required cumulative source coordinates directly. cum=load('C365_DATA.json')['cumulative_register'];cc={x['coordinate'] for x in cum};shems={x['coordinate'] for x in cum if x['role']=='Shem'};floods={x['coordinate'] for x in cum if x['role']=='Flood'} ck('no17K source join',all(not (b-8993 in shems and a-8993 in floods) for a,b in five)) ck('no existing corner-exchange image',all(C-x not in cc for C,(a,b) in product([-2639,-2635],five) for x in [a,b])) ck('six cumulative2K pairs',len([(s,f) for s,f in product(shems,floods) if f-s==1058])==6) # C420: integer numerator form, no floating point and no main affine helper. slopes={'E':(25,23),'E2':(625,529),'P':(70,69),'J':(300,299)};endpoint_hits=[] for row in d[420]['harmonic_trials']: n,q=slopes[row['operator']];out=F(n*row['input_lower']+(q-n)*row['held_upper'],q) ck('integer affine endpoint '+row['station']+' '+row['operator'],out==frac(row['output']) and by.get(out,[])==row['source_record_indices']) if out in by:endpoint_hits.append((row['held_upper'],row['input_lower'],row['operator'],int(out))) ck('only one sourced harmonic endpoint',endpoint_hits==[(3899,2841,'E2',2649)]) # C421: full finite Cartesian search, plus nonnegative exponent certificate. pivot_pairs=[(p,q) for p,q in product(coords,repeat=2) if 25*p+23*q==48*3899] ck('only repeated3899 pivot pair',pivot_pairs==[(3899,3899)] and 2749 not in coords) def factor(v): out=Counter();p=2 while p*p<=v: while v%p==0:out[p]+=1;v//=p p+=1 if v>1:out[v]+=1 return out def primepowers(n,q): a,b=factor(n),factor(q);return {p:a[p]-b[p] for p in set(a)|set(b)} powers={k:primepowers(*v) for k,v in slopes.items()} ck('unique positive operator counts from7,13,5',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]) # C422: quarter-integer comparisons; each signed unit denotes a quarter year. phase=[] for a,b in five: for eu,el in product([-1,1],repeat=2):phase.append(4*a+eu-4*1058==4*b+el) ck('translation components',sum(phase)==10 and len(phase)==20) errors=[F(625*ei-529*eo,4*529) for ei,eo in product([-1,1],repeat=2)] ck('fixed E2 component defects',errors==[F(-24,529),F(-577,1058),F(577,1058),F(24,529)]) for card in d[422]['source_excerpt_cards']: text='\n'.join((args.sources/card['source']).read_text().splitlines()[card['line_start']-1:card['line_end']]);ck('excerpt byte identity '+card['id'],text==card['text'] and hashlib.sha256(text.encode()).hexdigest()==card['excerpt_sha256']) result={'status':'passed','scope':'Separate root-agent direct source-table reconstruction, coordinate/context pair enumeration, integer affine coefficients, all-pivot Cartesian search, prime-factor proof and quarter-integer controls. Main calculation modules were not imported.','check_count':len(checks),'checks':checks,'new_independent_agent_review':False,'source_records_reconstructed':len(r),'coordinate_2K_pairs':len(pairs),'paired500_transports':len(survive),'typed_pair_lifts':len(lifts),'same_role_2K_profiles':len(hits),'sourced_harmonic_endpoint_trials':len(endpoint_hits),'complete_same_map_E2_source_paths':0,'C424_executed':False} args.out.mkdir(parents=True,exist_ok=True);(args.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'}))