from pathlib import Path from fractions import Fraction as Q from itertools import product import re,hashlib ROOT=Path(__file__).resolve().parent.parent def rat(x):return {'numerator':x.numerator,'denominator':x.denominator} def run(load,check): reg=load('C286_DATA.json')['target_register'];by={} for i,r in enumerate(reg):by.setdefault(r['center'],[]).append(i) target=next(r for r in load('PREVIOUS_DATA.json')['target_maps'] if r['target_held']==3206);sol=next(r for r in target['pivot_solutions'] if r['complete_source_path']);p,q=sol['first_pivot'],sol['second_pivot'];x,z,y=2148,2020,1956;lam=Q(25,23);check('C431 factorization retained',(p,q)==(3620,2756)) selected=set() for v in [x,z,y,p,q,3206,x+2,y+2,p+2,q+2,3208]:selected.update(by.get(v,[])) biographies=[];keys=['tradition','rail','gear','Cainan','Terah60','full430'] for i in by[p]+by[q]: seed=reg[i];own={} for role in ['Noah birth','Noah death']: ids=[j for j,r in enumerate(reg) if r['role']==role and all(r.get(k)==seed.get(k) for k in keys)];check('own biography source '+str((i,role)),len(ids)==1);selected.update(ids);own[role]=ids[0] check('own950 '+str(i),reg[own['Noah birth']]['center']-reg[own['Noah death']]['center']==950);biographies.append({'pivot_record_index':i,'birth_record_index':own['Noah birth'],'death_record_index':own['Noah death'],'birth':reg[own['Noah birth']]['center'],'death':reg[own['Noah death']]['center']}) spec=[('MT_PERSONS','File_02.md',659,716),('PERSON_BASES','File_18.md',1253,1282),('SP_FIELD','File_18.md',1571,1596),('VARIANTS','File_18.md',620,627),('SP_LOCALITY','File_18.md',433,435),('LXX_REMOVAL','File_18.md',1140,1147),('E_RULE','File_46.md',97,113),('DUAL100','File_18.md',755,771),('MIRROR_COMPONENTS','File_09.md',2028,2065)];cards=[] for key,name,a,b in spec: lines=(ROOT/'sources'/name).read_text().splitlines();text='\n'.join(lines[a-1:b]);check('source excerpt '+key,len(lines)>=b and bool(text));cards.append({'id':key,'source':name,'line_start':a,'line_end':b,'text':text,'excerpt_sha256':hashlib.sha256(text.encode()).hexdigest()}) at={r['id']:r['text'] for r in cards};bases={} for who in ['Noah','Shem']: m=re.search(r'\| '+who+r' \| (\d+)/(\d+) BC \| (\d+)/(\d+) BC',at['MT_PERSONS']);assert m;bases['MT',who+' birth',None]=int(m.group(2));bases['MT',who+' death',None]=int(m.group(4)) m=re.search(r'\| LXX \| '+who+r' \| (\d+)–(\d+) BC \| (\d+)–(\d+) BC',at['PERSON_BASES']);assert m;a,b=(3,4) if who=='Noah' else (1,2);bases['LXX',who+' birth',None]=int(m.group(a));bases['LXX',who+' death',None]=int(m.group(b)) cells=next(l for l in at['SP_FIELD'].splitlines() if l.startswith('| G1 |')).split('|')[2:6] for role,cell in zip(['Noah birth','Noah death','Shem birth','Shem death'],cells): for rail,v in zip(['primary','companion'],map(int,cell.strip().split('/'))):bases['SP',role,rail]=v rebuilt=[] for i in sorted(selected): r=reg[i];v=bases[r['tradition'],r['role'],r.get('rail')]+130*(r['Cainan']-int(r['tradition']=='LXX'))+60*r['Terah60']+215*r['full430']+2*(r['gear']-1);check('direct source reconstruction '+str(i),v==r['center']);rebuilt.append({'record_index':i,'record':r,'reconstructed_coordinate':v}) check('SP source qualifiers retained','inclusive/harmonic' in at['SP_FIELD'] and 'do not transfer it to MT/LXX' in at['SP_LOCALITY']) b1=(1-lam)*p;b2=(1-lam)*q;intercept=lam*b1+b2;check('same complete affine map',intercept==(1-lam*lam)*3206 and lam*x+b1==z and lam*z+b2==y) gaps=[{'pivot':p,'input':x,'output':z,'input_gap':p-x,'output_gap':p-z,'input_multiple_of23':(p-x)//23,'output_multiple_of25':(p-z)//25,'gain':x-z},{'pivot':q,'input':z,'output':y,'input_gap':q-z,'output_gap':q-y,'input_multiple_of23':(q-z)//23,'output_multiple_of25':(q-y)//25,'gain':z-y}] check('64 and32 expansion legs',[(g['input_multiple_of23'],g['output_multiple_of25'],g['gain']) for g in gaps]==[(64,64,128),(32,32,64)]) check('cross-context pivot gap is not Noah lifespan',p-q==864 and p-q!=950) shifted={'held_effective':3208,'pivots':[p+2,q+2],'input':x+2,'required_intermediate':z+2,'output':y+2,'pivot_source_record_indices':[by[p+2],by[q+2]],'intermediate_source_record_indices':by.get(z+2,[]),'required_MT_Shem_death_Gear':4} check('+2 arithmetic but absent source',Q(p+2)+lam*(x+2-(p+2))==z+2 and Q(q+2)+lam*(z+2-(q+2))==y+2 and not by.get(z+2)) eps=[-Q(1,4),Q(1,4)];phase=[] for ei,em,eo in product(eps,repeat=3): first=Q(p)+lam*(x+ei-p);second=Q(q)+lam*(first-q);ok=first==z+em and second==y+eo;phase.append({'input_offset':str(ei),'intermediate_offset':str(em),'output_offset':str(eo),'first_error':str(first-(z+em)),'whole_map_error':str(second-(y+eo)),'both_steps_preserved':ok}) joint=[] for e in eps: first=Q(p)+e+lam*(x+e-(p+e));second=Q(q)+e+lam*(first-(q+e));check('joint component shift '+str(e),first==z+e and second==y+e);joint.append({'common_offset':str(e),'intermediate':str(first),'output':str(second),'same_fixed_pivots':False}) return {'step':'C432','path':{'input':x,'intermediate':z,'output':y,'pivots':[p,q],'effective_pivot':3206,'record_indices':{'input':by[x],'intermediate':by[z],'output':by[y],'first_pivot':by[p],'second_pivot':by[q],'effective_pivot':by[3206]}},'source_excerpt_cards':cards,'reconstructed_records':rebuilt,'separate_Noah_biographies':biographies,'gap_expansions':gaps,'whole_map':{'slope':rat(lam*lam),'intercept':rat(intercept)},'plus2_control':shifted,'fixed_pivot_component_trials':phase,'jointly_shifted_component_comparisons':joint,'counts':{'source_excerpt_cards':len(cards),'direct_source_records_reconstructed':len(rebuilt),'first_pivot_source_labels':len(by[p]),'second_pivot_source_labels':len(by[q]),'complete_record_labelled_paths':len(by[p])*len(by[q])*len(by[x])*len(by[z])*len(by[y]),'separate_Noah_biographies':len(biographies),'plus2_intermediate_sources':len(by.get(z+2,[])),'fixed_pivot_component_assignments':len(phase),'preserved_fixed_pivot_assignments':sum(r['both_steps_preserved'] for r in phase),'joint_shifted_comparisons':len(joint),'new_protocol_prescriptions_established':0},'interpretation':'The two actual pivots are SP companion Noah birth3620 and SP primary/LXX-OFF Noah death2756, in different contexts. The three path stations are different MT Shem-death source states, G2→G3→G1 with explicit Cainan/Terah changes. Each selected Noah biography remains950; pivot separation864 is cross-context. This is a sourced exact affine factorization, not a reviewed prescription for combined chronology or a single fixed-pivot seasonal action. The+2 partner lacks2022 and requires unavailable Gear4 for the analogous MT Shem-death state.'}