"""Finite SP Gear/binding transport through the fixed C270 maps; exact arithmetic.""" from pathlib import Path from fractions import Fraction as Q from collections import Counter import argparse, csv, hashlib, json ROOT = Path(__file__).resolve().parents[1] parser = argparse.ArgumentParser() parser.add_argument('--output', type=Path, default=ROOT/'evidence') OUT = parser.parse_args().output OUT.mkdir(parents=True, exist_ok=True) checks = [] def check(name, condition): if not condition: raise AssertionError(name) checks.append(name) def read(name): return json.loads((ROOT/'sources'/name).read_text()) def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() def dump(name, value): (OUT/name).write_text(json.dumps(value, indent=2, ensure_ascii=False, default=str)+'\n') def pair(center): return [Q(center)-Q(1,4), Q(center)+Q(1,4)] def apply(mapping, x): return mapping[0]*x+mapping[1] def label(x): x = Q(x) part = x % 1 assert part in (Q(1,4), Q(3,4)) season = 'n' if part == Q(1,4) else 't' year = x+(Q(3,4) if season == 'n' else Q(1,4)) if x > 0 else (Q(1,4) if season == 'n' else Q(3,4))-x assert year.denominator == 1 and year > 0 return f'AD {year}{season}' if x > 0 else f'{year}{season} BC' manifest = json.loads((ROOT/'SOURCE_MANIFEST.json').read_text()) for name, row in manifest.items(): path = ROOT/'sources'/name check('frozen source '+name, sha(path) == row['sha256'] and path.stat().st_size == row['bytes']) previous = read('C270_CERTIFICATE.json') check('previous certificate identity', sha(ROOT/'sources/C270_CERTIFICATE.json') == '73969d5cc289651b69b7894761c84b9771b745fc96cc6f82f5eb86e789335490') for name, field in [('C270_REPORT.md','report_sha256'), ('C270_CHECKPOINT.md','checkpoint_sha256'), ('C270_RESULTS.json','results_sha256')]: check('previous certificate '+name, sha(ROOT/'sources'/name) == previous[field]) for name, expected in [('FILE_18.md','68301ab760bfbe2e874aedc5c8d943ced7a6219d34bc2859332a70713f9630d5'), ('FILE_09.md','45851004c5864229ebf6a896f9099819a08d8926715d3e97e4bc3985c4a3876e')]: check('controlling source '+name, sha(ROOT/'sources'/name) == expected) maps = read('C270_MAPS.json') RN = tuple(map(Q, maps['regular_reflected_Noah_map'])) RF = tuple(map(Q, maps['regular_reflected_Flood_map'])) T = tuple(map(Q, maps['correspondence'])) check('fixed C270 maps', RN == (1,-3703) and RF == (-1,3105) and T == (1,8993)) check('K identity retained', 8993 == 17*529 and 3703 == 7*529 and 5290 == 10*529) all_events = read('C01_RESULTS.json')['events'] events = [e for e in all_events if e['tradition'] == 'SP' and e['role'] in ('Noah birth','Flood start','Flood close')] check('finite register size', len(events) == 12) table = (ROOT/'sources/FILE_18.md').read_text() check('controlling SP Flood row', '| SP | 3110→3109 | 3108→3107 | 3106→3105 | 3106 |' in table) for gear, births in [(1,'3491/3490'),(2,'3493/3492'),(3,'3495/3494')]: check('controlling native Noah G'+str(gear), f'| G{gear} | {births} |' in table) cumulative = [r for r in read('C266_ENDPOINTS.json') if r['profile'] == 'LXX_OFF' and ((r['source_role'] == 'Flood' and not r['reflection_after_translation']) or (r['source_role'] == 'Shem' and r['reflection_after_translation']))] check('held cumulative domain', len(cumulative) == 16 and all(r['regular_Gear'] is None and r['mode'] == 'cumulative' for r in cumulative)) register = [] for event in events: gear, y = event['gear'], event['BC_Nisan'] noah = event['role'] == 'Noah birth' selector = event['rail'] if noah else event['role'].split()[-1] lower = selector in ('companion','close') event_id = f'SP_G{gear}_'+('Noah_'+selector if noah else 'Flood_'+selector) check(event_id+' held coordinate', y == (3704 if noah else 3104)+2*gear-int(lower)) check(event_id+' source class', event['rail'] in ('primary','companion') if noah else event['rail'] is None) mapping = RN if noah else RF role = 'Flood' if noah else 'Shem' q = Q(y)-8993 source_matches = [r for r in cumulative if r['source_role'] == role and -r['source_BC_base'] == q] check(event_id+' unique cumulative ancestry', len(source_matches) == 1) source = source_matches[0] index = source['source_index'] center = apply(mapping,Q(y)) check(event_id+' index formula', index == 2*gear+1-int(lower)) check(event_id+' cumulative local center', center == source['pair_center']) phases = [] for delta in (-Q(1,4),Q(1,4)): regular_phase = Q(y)+delta original = -regular_phase cumulative_phase = regular_phase-8993 local = apply(mapping,regular_phase) via_cumulative = cumulative_phase+5290 if noah else -(cumulative_phase+5888) check(event_id+' phase transport '+str(delta), local == via_cumulative and local in list(map(Q,source['exact_components']))) phases.append({'reflected_coordinate':regular_phase,'reflected_phase':label(regular_phase),'original_BC_coordinate':original,'original_BC_phase':label(original),'cumulative_coordinate':cumulative_phase,'cumulative_phase':label(cumulative_phase),'local_coordinate':local,'local_phase':label(local),'eta':1000*(local-1)}) check(event_id+' complete local phase pair', sorted(p['local_coordinate'] for p in phases) == pair(center)) check(event_id+' actual half-year width', abs(phases[1]['local_coordinate']-phases[0]['local_coordinate']) == Q(1,2)) register.append({'id':event_id,'source_event':event,'branch':'Noah' if noah else 'Flood','selector':selector,'lower_selector':int(lower),'center':center,'cumulative_source':source,'comparison_status':'derived T8993 comparison between admitted endpoint records; no new stored path asserted','phases':phases}) noahs = [r for r in register if r['branch'] == 'Noah'] floods = [r for r in register if r['branch'] == 'Flood'] matrix, matches = [], [] for n in noahs: for f in floods: ne, fe = n['source_event'], f['source_event'] gap = ne['BC_Nisan']-fe['BC_Nisan'] residual = n['center']+f['center']-2 formula = 2*(ne['gear']-fe['gear'])-n['lower_selector']+f['lower_selector'] exact = residual == 0 check(n['id']+'/'+f['id']+' residual', residual == gap-600 == formula) phase_residuals = [np['local_coordinate']+fp['local_coordinate']-2 for np,fp in zip(n['phases'],f['phases'])] check(n['id']+'/'+f['id']+' phase residuals', phase_residuals == [residual,residual]) check(n['id']+'/'+f['id']+' binding criterion', exact == (ne['gear'] == fe['gear'] and n['lower_selector'] == f['lower_selector'])) matrix.append({'Noah':n['id'],'Flood':f['id'],'source_gap':gap,'J1_residual':residual,'local_midpoint':(n['center']+f['center'])/2,'cumulative_index_difference':n['cumulative_source']['source_index']-f['cumulative_source']['source_index'],'exact_J1_pair':exact,'component_residuals':phase_residuals}) if exact: radius = n['center']-1 inner, outer = 1000*radius-250,1000*radius+250 check(n['id']+' matched cumulative indices', n['cumulative_source']['source_index'] == f['cumulative_source']['source_index']) check(n['id']+' bilateral signed phases', sorted(p['eta'] for p in f['phases']) == [-outer,-inner] and sorted(p['eta'] for p in n['phases']) == [inner,outer]) matches.append({'Noah':n['id'],'Flood':f['id'],'gear':ne['gear'],'binding':'companion/close' if n['lower_selector'] else 'primary/start','cumulative_index':n['cumulative_source']['source_index'],'cumulative_Flood_BC_base':n['cumulative_source']['source_BC_base'],'cumulative_Shem_BC_base':f['cumulative_source']['source_BC_base'],'local_centers':[n['center'],f['center']],'radius':radius,'eta_positive_phases':[inner,outer],'outer_inner_ratio':outer/inner,'is_E_25_over_23':outer/inner == Q(25,23)}) check('complete cross-pair classification', len(matrix) == 36 and len(matches) == 6) counts = Counter(int(r['J1_residual']) for r in matrix) check('residual multiplicities', counts == Counter({d:6-abs(d) for d in range(-5,6)})) check('six consecutive radii', sorted(r['radius'] for r in matches) == list(range(1,7))) check('primary even radii', sorted(r['radius'] for r in matches if r['binding']=='primary/start') == [2,4,6]) check('companion odd radii', sorted(r['radius'] for r in matches if r['binding']=='companion/close') == [1,3,5]) check('only radius six retains E', [r['radius'] for r in matches if r['is_E_25_over_23']] == [6]) check('origin phase display without year zero', [label(x) for x in pair(0)] == ['1t BC','AD 1n']) g1close = next(r for r in floods if r['source_event']['gear']==1 and r['selector']=='close') check('G1 close actual origin pair', sorted(p['local_coordinate'] for p in g1close['phases']) == pair(0)) coverage = [] for role, branch, offset in [('Flood','Noah',5290),('Shem','Flood',5890)]: selected = [r for r in register if r['branch']==branch] indices = sorted(r['cumulative_source']['source_index'] for r in selected) check(role+' selected indices', indices == list(range(2,8))) missing = [] for source in cumulative: if source['source_role'] != role or source['source_index'] in indices: continue hypothetical = 8993-source['source_BC_base'] check(role+' missing preimage '+str(source['source_index']), all(r['source_event']['BC_Nisan'] != hypothetical for r in selected)) colocations = [r['id'] for r in register if r['center']==source['pair_center']] missing.append({'cumulative_source':source,'required_reflected_regular_center':hypothetical,'admitted_in_selected_branch':False,'same_local_center_other_source_records':colocations}) coverage.append({'cumulative_role':role,'regular_branch':branch,'covered_indices':indices,'total_source_indices':8,'missing':missing,'regular_Gear_assigned_to_cumulative':False}) check('omitted indices retained', all([r['cumulative_source']['source_index'] for r in c['missing']] == [0,1] for c in coverage)) check('no local junction source in regular register', all(r['center'] != 1 for r in register)) check('index zero co-location does not fill ancestry', all(len(c['missing'][0]['same_local_center_other_source_records']) == 1 for c in coverage)) old = read('C270_COMPONENTS.json') for branch, role in [('Noah','Noah birth'),('Flood','Flood start')]: selected = next(r for r in register if r['source_event']['gear']==3 and r['source_event']['role']==role and (branch=='Flood' or r['selector']=='primary')) prior = [r for r in old if r['regular_source']['role']==role] check('C270 G3 phases retained '+branch, sorted((p['local_coordinate'],p['eta']) for p in selected['phases']) == sorted((Q(p['local_coordinate']),Q(p['eta'])) for p in prior)) dump('REGISTER_IMAGES.json',register) dump('PAIR_MATRIX.json',{'pairs':matrix,'residual_counts':dict(sorted(counts.items())),'exact_pairs':6,'nonmatching_pairs':30,'formula':'residual=N−F−600=2(gN−gF)−cN+cF','residual_zero_axis':'local x=1 only'}) dump('CUMULATIVE_COVERAGE.json',coverage) dump('MATCHED_FAMILIES.json',sorted(matches,key=lambda r:r['radius'])) dump('RESULTS.json',{'step':'C271','status':'passed','check_count':len(checks),'checks':checks,'source_events':12,'seasonal_components':24,'cross_pairs':36,'exact_J1_pairs':6,'nonmatching_pairs':30,'radii':[1,2,3,4,5,6],'covered_cumulative_indices':[2,3,4,5,6,7],'missing_cumulative_indices':[0,1],'maps_changed':False,'source_events_identified_as_same':False,'new_stored_graph_paths_asserted':False,'canonical_sources_modified':False}) with (OUT/'COMPONENTS.csv').open('w',newline='') as handle: writer=csv.writer(handle) fields=['original_BC_phase','reflected_phase','cumulative_phase','local_phase','local_coordinate','eta'] writer.writerow(['event_id','cumulative_role','cumulative_index']+fields) for r in sorted(register,key=lambda r:r['id']): for p in r['phases']: writer.writerow([r['id'],r['cumulative_source']['source_role'],r['cumulative_source']['source_index']]+[p[k] for k in fields]) print(json.dumps({'step':'C271','status':'passed','checks':len(checks),'output_files':6,'exact_pairs':6,'nonmatching_pairs':30}))