from pathlib import Path import argparse,json,itertools 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(n):return json.loads((a.sources/n).read_text()) checks=[] def check(name,v): assert v,name checks.append(name) reg=load('C286_DATA.json')['target_register'];pairs=load('C286_DATA.json')['source_pairs'];source_rows=load('C331_DATA.json')['rows'];phase_count=phase_hits=0 for x in source_rows: m,r=x['records']['M']['center'],x['records']['R']['center'];primary=x['rail']=='primary' for held in ['Flood','Noah']: role='Noah birth' if held=='Flood' else x['records']['R']['role'];g=x['records']['R']['gear'] if held=='Flood' else x['records']['M']['gear'];z=[z for z in reg if z['tradition']=='MT' and z['role']==role and z['gear']==g and z['Cainan']==z['Terah60']==z['full430']==1];check(f'i{x["i"]}/{held} target source',len(z)==1);t=z[0]['center'] exact=(299*(t-r)==300*(m-r)) if held=='Flood' else (299*(m-t)==300*(m-r));check(f'i{x["i"]}/{held} integer ratio',exact==primary) for em,er,et in itertools.product([-1,1],repeat=3): mq,rq,tq=4*m+em,4*r+er,4*t+et;phase_count+=1 ok=299*(tq-rq)==300*(mq-rq) if held=='Flood' else 299*(mq-tq)==300*(mq-rq) phase_hits+=ok check('phase controls by integer arithmetic',(phase_count,phase_hits)==(64,8)) check('companion residual numerator',300*599-299*601==1) # Every relation is recomputed by integer affine coefficients, including inverses. for field in load('C349_DATA.json')['fields']: i=field['i'];vals={k:x['center'] for k,x in field['records'].items()} check(f'i{i} every node in source register',all(x in reg for x in field['records'].values())) coeff={'E_N':(25,-2*vals['N'],23),'J_R':(300,-vals['R'],299),'J_M':(300,-vals['M'],299)} derived={} for label,(u,v,w) in list(coeff.items()): for inv in [False,True]: name=label+('_inverse' if inv else '');A,B,D=(w,-v,u) if inv else(u,v,w);hits={} for k,x in vals.items(): targets=[t for t,y in vals.items() if D*y==A*x+B] if targets:check(f'i{i}/{name}/{k} unique',len(targets)==1);hits[k]=targets[0] check(f'i{i}/{name} exact relation agreement',hits==field['maps'][name]);derived[name]=hits for f,g in itertools.combinations(coeff,2): A,B,D=coeff[f];U,V,W=coeff[g];numerator=A*V+B*W-U*B-V*D;expected={('E_N','J_R'):92,('E_N','J_M'):40,('J_R','J_M'):-2}[f,g] check(f'i{i}/{f}/{g} integer commutator',299*numerator==expected*D*W) check(f'i{i}/{f}/{g} bounded source composition',not any(derived[f].get(derived[g].get(k)) is not None and derived[g].get(derived[f].get(k)) is not None for k in vals)) check(f'i{i}600 tradeoff algebra',1058-600==458 and 950-458==492 and 460+600==1060) # Cumulative source-member replacements, without an affine implementation. ss={z['S'] for z in pairs if z['Shem_Cainan']==0};ff={z['F'] for z in pairs if z['Flood_Cainan']==0} for x in load('C287_DATA.json')['rows']: if not x['complete']:continue s,q=x['S'],x['F'];p=s+460;check(f'i{x["i"]} originalOFFinterior',p in ss and q-p==598) check(f'i{x["i"]} two cumulative repairs',q-600 in ss and p+600 in ff and q-600-s==458 and p+600-s==1060) # Selector counted by direct source gaps and endpoint membership. selected=[];outputs=[] for x in load('C319_DATA.json')['rows']: if not x['joint_admitted']:continue ns=[z for z in reg if z['tradition']=='SP' and z['role']=='Noah birth' and z['Cainan']==z['Terah60']==0 and z['full430']==1 and z['center']==x['n']];assert len(ns)==1;n=ns[0] ms=[z for z in reg if z['tradition']=='MT' and z['role']=='Noah birth' and z['gear']==n['gear'] and z['Cainan']==z['Terah60']==z['full430']==1];assert len(ms)==1 if x['q']-(x['S']+460)==ms[0]['center']-x['R']==598:selected.append({k:x[k] for k in ['a','b','i']}) if n['rail']=='primary' and x['q']-600 in ss and any(z['tradition']=='MT' and z['role']=='Noah birth' and z['Cainan']==z['Terah60']==z['full430']==1 and z['center']==x['R']+600 for z in reg):outputs.append({k:x[k] for k in ['a','b','i']}) check('paired input selector',selected==load('C352_DATA.json')['paired598_survivors']) check('nine600 output controls',outputs==load('C352_DATA.json')['both600_output_survivors'] and len(outputs)==9) result={'status':'passed','author':'root agent; separate integer cross-multiplication, affine-coefficient and direct record-join implementation','new_independent_agent_review':False,'check_count':len(checks),'checks':checks,'phase_controls':phase_count,'phase_successes':phase_hits,'paired598_survivors':selected,'both600_output_survivors':outputs} 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({'status':'passed','checks':len(checks)}))