"""Alternate root implementation: source-table regeneration and integer tests. Imports none of the C435-C443 calculation modules. Not an independent agent. """ from pathlib import Path from itertools import product,combinations_with_replacement from collections import Counter import argparse,json,re ROOT=Path(__file__).resolve().parent.parent def main(out): read=lambda n:(ROOT/'sources'/n).read_text() load=lambda n:json.loads(read(n)) checks=[] def ck(n,v): assert v,n checks.append(n) t18,t02=read('File_18.md'),read('File_02.md');base={} mt=t02.split('### 6.2 Regular chronology: localized effect',1)[1].split('### 6.3',1)[0] lx=t18.split('For LXX, retain the independently sourced',1)[1].split('The corrected SP field',1)[0] sp=t18.split('#### 3.2.1 SP Noah/Shem field and named bindings',1)[1].split('####',1)[0] for who in ['Noah','Shem']: c=next(z for z in mt.splitlines() if z.startswith('| '+who+' |')).split('|') base['MT',who+' birth',None]=int(re.findall(r'\d+',c[2])[-1]);base['MT',who+' death',None]=int(re.findall(r'\d+',c[3])[-1]) c=next(z for z in lx.splitlines() if z.startswith('| LXX | '+who+' |')).split('|') base['LXX',who+' birth',None],base['LXX',who+' death',None]=map(int,re.findall(r'\d+',c[4 if who=='Noah' else 3])) for role,c in zip(['Noah birth','Noah death','Shem birth','Shem death'],next(z for z in sp.splitlines() if z.startswith('| G1 |')).split('|')[2:6]): for rail,v in zip(['primary','companion'],map(int,c.strip().split('/'))):base['SP',role,rail]=v flood=t18.split('#### 3.1.4 Ordinary Flood Gears, fixed Arphaxad, and the SP midpoint',1)[1];fb={} for tr,label in [('MT','MT'),('SP','SP'),('LXX','LXX — native Cainan ON')]: row=next(z for z in flood.splitlines() if z.startswith('| '+label+' |'));fb[tr]=int(re.findall(r'(\d+)→(\d+)',row)[-1][0]) gen=set() for tr,g,c,t,f in product(['MT','SP','LXX'],[1,2,3],[0,1],[0,1],[0,1]): shift=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]):gen.add((tr,role,rail,g,c,t,f,base[tr,role,rail]+shift)) for role in ['Flood start','Flood close']:gen.add((tr,role,None,g,c,t,f,fb[tr]-215+shift-int(role=='Flood close'))) reg=load('C286_DATA.json')['target_register'];keys=['tradition','role','rail','gear','Cainan','Terah60','full430','center'] ck('direct source grid equals528 inherited records',gen=={tuple(r.get(k) for k in keys) for r in reg} and len(gen)==528) coords=sorted({r[-1] for r in gen});cs=set(coords);by={x:[i for i,r in enumerate(reg) if r['center']==x] for x in coords} ck('373 distinct coordinates',len(coords)==373) forward=[];families=[] for t,g in product([0,1],[1,2,3]): N=base['SP','Noah birth','primary']+215+2*(g-1)+60*t;p=N-86;q=N-950;h=N-500;c=N-518 mid_count=int_count=end_count=0;paths=[] for x in coords: a=25*x-2*p;b=625*x-50*p-46*q mid_count+=a%23==0 and a//23 in cs int_count+=b%529==0 end_count+=b%529==0 and b//529 in cs if a%23==0 and b%529==0 and a//23 in cs and b//529 in cs:paths.append((x,a//23,b//529));forward.append((h,*paths[-1])) families.append((mid_count,int_count,end_count,len(paths))) ck(f'source weighted midpoint identity {g}/{t}',25*p+23*q==48*h and h-c==18 and p-c==432) d435=load('C435_DATA.json') ck('forward census exact',families==[(r['sourced_intermediates'],r['integer_outputs'],r['sourced_outputs'],r['complete_paths']) for r in d435['families']] and forward==[(3206,2148,2020,1956),(3206,3206,3170,3206)]) ck('source loop36 and24-to1 geometry',100-60-4==36 and (3620+2756)==(3206+3170)==2*3188 and 3620-3188==24*(3206-3188)) ck('same-record loop returns versus Cartesian assignments',len(by[3206])*len(by[3170])*len(by[3620])*len(by[2756])==8 and len(by[3206])**2*len(by[3170])*len(by[3620])*len(by[2756])==16) centers=[c for c in [3188,3190,3192,3248,3250,3252] if c in cs] ck('four sourced centers',centers==[3188,3190,3248,3250]) # Alternate enumeration: scan unordered pairs by their sums, not reflected inputs. orbits={(c,x,y) for x,y in combinations_with_replacement(coords,2) for c in centers if x+y==2*c} d438=load('C438_DATA.json');expected={(z['center'],z['lower'],z['upper']) for z in d438['coordinate_orbits']} ck('all106 reflection orbits from pair sums',orbits==expected and len(orbits)==106) labels={(c,i,j) for c,x,y in orbits for i,j in product(by[x],by[y])} ck('all258 source label pairings',labels=={(z['center'],z['lower_record'],z['upper_record']) for z in d438['labelled_pairs']} and len(labels)==258) for c,domain_size in [(3188,61),(3190,67),(3248,19),(3250,61)]: ck('source reflection domain '+str(c),len({v for cc,x,y in orbits if cc==c for v in [x,y]})==domain_size) A={(c,i,j) for c,i,j in labels if sorted([reg[i]['role'],reg[j]['role']])==['Noah birth','Noah death']} ck('Noah complement class128',len(A)==128) for c,i,j in A: a,b=reg[i],reg[j];t=int(c>3200);g=1+((c-3188-60*t)//2) ck('Noah source complement '+str((c,i,j)),a['Cainan']+b['Cainan']==1 and a['full430']+b['full430']==1 and a['Terah60']==b['Terah60']==t and a['gear']+b['gear']==2*g and int(a.get('rail')=='companion')+int(b.get('rail')=='companion')==1) # Inverse transport from target labels, testing whether tradition is preserved. B={(c,i,j) for c,i,j in labels if 'Shem birth' in [reg[i]['role'],reg[j]['role']] and any(reg[k]['role'].startswith('Flood') for k in [i,j])} inv=0;alias=0 for c,i,j in B: sb=reg[i] if reg[i]['role']=='Shem birth' else reg[j];fl=reg[j] if reg[j]['role'].startswith('Flood') else reg[i] rail=('companion' if fl['role']=='Flood close' else ('primary' if fl['tradition']=='SP' else None)) target_sd=(fl['tradition'],'Shem death',rail,fl['gear'],fl['Cainan'],fl['Terah60'],fl['full430'],fl['center']-500) target_nb=(sb['tradition'],'Noah birth',sb.get('rail'),sb['gear'],sb['Cainan'],sb['Terah60'],sb['full430'],sb['center']+500) ok=target_sd in gen and target_nb in gen inv+=ok;alias+=not ok if not ok:ck('only LXX Flood-close has missing typed inverse '+str((c,i,j)),fl['tradition']=='LXX' and fl['role']=='Flood close' and sb.get('rail')=='companion') ck('inverse opposed500 transport40 plus8 aliases',len(B)==48 and inv==40 and alias==8) roles=Counter(tuple(sorted([reg[i]['role'],reg[j]['role']])) for _,i,j in labels) ck('seven role pairs form six source classes',roles==Counter({('Noah birth','Noah death'):128,('Noah birth','Shem death'):40,('Flood start','Shem birth'):32,('Flood close','Shem birth'):16,('Flood close','Flood start'):32,('Flood close','Noah birth'):4,('Noah birth','Noah birth'):6})) groups={z['id']:{(p['center'],p['lower'],p['upper']) for p in z['pairs']} for z in load('C441_DATA.json')['classes']} ck('six coordinate aliases explain112 versus106',sum(map(len,groups.values()))==112 and set().union(*groups.values())==orbits) rev=[];primitive=[] for c in centers: p,q=c+432,c-432 for x in coords: a=25*x-2*q;b=625*x-50*q-46*p if a%23==b%529==0 and a//23 in cs and b//529 in cs:rev.append((c,x,a//23,b//529)) a=25*x-2*p if a%23==0 and a//23 in cs and 2*c-x in cs and 2*c-a//23 in cs:primitive.append((c,x,a//23)) ck('reversed census only zero-net loop',rev==[(3188,3170,3206,3170)]) ck('only five primitive conjugate pairs',len(primitive)==5 and sum(x==y for _,x,y in primitive)==4) ck('nonzero2K reflected path entirely outside range',[6376-x for x in [2148,2020,1956]]==[4228,4356,4420] and 4228>max(cs)) cum={r['coordinate'] for r in load('C365_DATA.json')['cumulative_register']};slots=[];pairs=[] for a in [-2639,-2635]: for c in centers: for x in {v for cc,x,y in orbits if cc==c for v in [x,y]}: if a-x in cum:slots.append((a,c,x)) for c,x,y in orbits: if a-x in cum and a-y in cum:pairs.append((a,c,x,y)) ck('Mirror partial counts37 slots and5 orbits',len(slots)==37 and len(pairs)==5) ck('sole nonfixed Mirror orbit',[(a,c,x,y) for a,c,x,y in pairs if x!=y]==[(-2639,3248,3246,3250)]) ck('all16 core Mirror images absent',not any(a-x in cum for a in [-2639,-2635] for x in [3620,3206,3188,3170,2756,2148,2020,1956])) result={'step':'C444','status':'passed','check_count':len(checks),'checks':checks,'source_records_generated':len(gen),'regular_coordinates':len(cs),'forward_complete_paths':forward,'reflection_coordinate_orbits':len(orbits),'reflection_labelled_pairs':len(labels),'typed_inverse_500':inv,'additional_aliases':alias,'reverse_complete_paths':rev,'Mirror_sourced_slots':len(slots),'Mirror_complete_orbits':len(pairs),'new_independent_agent_review':False,'method':'Source-table reconstruction, unordered pair sums, integer affine divisibility and inverse label transport; imports no main calculation modules.','C445_executed':False} out.mkdir(parents=True,exist_ok=True);(out/'SECOND_METHOD_RESULTS.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n') print(json.dumps({k:v for k,v in result.items() if k!='checks'})) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--out',type=Path,required=True);main(p.parse_args().out)