from pathlib import Path import re,hashlib ROOT=Path(__file__).resolve().parent.parent def run(load,check): files={name:(ROOT/'sources'/name).read_text() for name in ['File_18.md','File_02.md','File_46.md','File_11.md']};spec=[('MT_NOAH','File_02.md',659,716,'6.2 localized Noah/Shem and position matrix'),('J_GAP','File_02.md',718,731,'6.3 gap conversion and Residue distinction'),('VARIANTS','File_18.md',620,627,'1.3 tradition-specific variant forks'),('LXX_REMOVAL','File_18.md',1140,1147,'1.6.2 theoretical LXX Cainan removal'),('NOAH_BASES','File_18.md',1253,1280,'2.2.1 independent MT/LXX Noah states'),('FLOOD','File_18.md',1540,1552,'3.1.4 Flood start/close and branch frames'),('SP_FIELD','File_18.md',1571,1596,'3.2.1 SP person rails and bindings'),('E_P','File_46.md',97,133,'L2/L3 exact ratio definitions'),('E_SQUARED','File_46.md',363,365,'6A.3 double-expansion licensing'),('GEARS','File_11.md',46,53,'Gear offsets+0/+2/+4, applied here only atNoah/Shem/Flood')];cards=[] for key,name,start,end,section in spec: lines=files[name].splitlines();text='\n'.join(lines[start-1:end]);check('source excerpt available '+key,len(lines)>=end and bool(text)) cards.append({'id':key,'source':name,'section':section,'line_start':start,'line_end':end,'text':text,'excerpt_sha256':hashlib.sha256(text.encode()).hexdigest()}) at={c['id']:c['text'] for c in cards} mt=re.search(r'\| Noah \| (\d+)/(\d+) BC',at['MT_NOAH']);sp=re.search(r'\| G1 \| (\d+)/(\d+) \|',at['SP_FIELD']);lx=re.search(r'\| LXX \| Noah \| (\d+)–(\d+) BC \| (\d+)–(\d+) BC',at['NOAH_BASES']) check('source Noah bases parsed',mt is not None and sp is not None and lx is not None) bases={'MT':int(mt.group(2)),'SP':int(sp.group(1)),'LXX':int(lx.group(3))};companion=int(sp.group(2));check('source Noah baselines',bases=={'MT':2841,'SP':3491,'LXX':3621} and companion==3490) flood={} for tr,marker in [('MT','MT'),('SP','SP'),('LXX','LXX — native Cainan ON')]: line=next(l for l in at['FLOOD'].splitlines() if l.startswith('| '+marker+' |'));pairs=re.findall(r'(\d+)→(\d+)',line);check('three sourced Flood boundaries '+tr,len(pairs)==3 and all(int(a)-int(b)==1 for a,b in pairs));flood[tr]=int(pairs[2][0]) check('source variant and operator statements',all(v in at['VARIANTS'] for v in ['+215','+60','+130']) and '300/299=600' in at['J_GAP'] and 'converts a gap, not a date' in at['J_GAP'] and 'not a Residue Protocol' in at['J_GAP'] and '25/23' in at['E_P'] and '70/69' in at['E_P'] and '23²' in at['E_SQUARED']) check('source Gear offsets available',all(v in at['GEARS'] for v in ['+0','+2','+4'])) def reconstruct(r): tr=r['tradition'];g=r['gear'];c=r['Cainan'];t=r['Terah60'];f=r['full430'];native=1 if tr=='LXX' else 0 if r['role']=='Noah birth':return bases[tr]+130*(c-native)+60*t+215*f+2*(g-1)-(1 if tr=='SP' and r.get('rail')=='companion' else 0) assert r['role'] in ['Flood start','Flood close'] return flood[tr]+130*(c-native)+60*t+215*(f-1)+2*(g-1)-(1 if r['role']=='Flood close' else 0) checksrows=[];slots=0 for i,h in enumerate(load('C396_DATA.json')['hits']): records=list(h['records'].items())+[(f'P_pivot_{j}',r) for j,r in enumerate(h['P_return_source_records'])];derived=[] for name,rr in records: value=reconstruct(rr);check('reconstruct source record '+str((i,name)),value==rr['center']);slots+=1;derived.append({'role_in_loop':name,'source_record':rr,'reconstructed_coordinate':value}) check('explicit contextual displacement '+str(i),h['E_Noah_pivot']-h['E_output']==215-130-60==25) if h['edge_family']['rail']=='companion':check('companion return boundary is independent '+str(i),h['edge_family']['tradition']=='SP' and h['J_Flood_boundary']=='Flood close' and h['records']['J_Flood'].get('rail') is None) checksrows.append({'case':i,'reconstructed_records':derived,'LXX_status':' '.join((['Moving LXX source is native CainanON.'] if h['edge_family']['tradition']=='LXX' else [])+(['Held LXX source is explicitly theoretical CainanOFF.'] if h['held_Noah_family']['tradition']=='LXX' else [])) or None}) check('reconstruction coverage',len(checksrows)==12 and slots==52) status=[{'claim':'Noah/Flood endpoints, Gear offsets and variant shifts','status':'Explicit source data/rules; all52 labelled record slots reconstructed.'},{'claim':'E/P ratios and J598→600 conversion','status':'Explicit source scalar operators. File02 specifically describes a gap conversion, not a date transformation or Residue Protocol.'},{'claim':'Holding these particular E/J/P pivots together across source contexts','status':'Derived source-supported comparison; a prescription for the new circuit is not established in the reviewed passages.'},{'claim':'Three-vertex path normal form and commuting positive circuits','status':'Exact algebra of the constructed comparison graph; distinct source/pivot histories remain distinct.'},{'claim':'Global action, whole-biography transport, original17K or529-lattice preservation','status':'Not established; finite source and arithmetic tests show the stated obstructions.'}] return {'step':'C402','source_excerpt_cards':cards,'source_baselines':{'Noah_G1_minimum_or_native':bases,'SP_companion_Noah_G1':companion,'Flood_G1_full430_native_Cainan':flood},'reconstruction_rows':checksrows,'claim_status_matrix':status,'counts':{'source_excerpt_cards':len(cards),'labelled_source_loop_cases':len(checksrows),'source_record_slots_reconstructed':slots,'new_source_endpoints':0,'new_source_protocol_prescriptions_established':0},'interpretation':'The loop sources reconstruct exactly from current table values and scoped variants. The affine maps encode held-pivot gap comparisons; their graph and algebra are derived research objects, not new canonical instructions to transform dates. The source-family census is not statistical corroboration because its inputs share the same variant rules.'}