"""Reproduce the finite C268 comparison from frozen inputs, using exact rationals.""" from pathlib import Path from fractions import Fraction as F import argparse, hashlib, json, csv ROOT=Path(__file__).resolve().parents[1] p=argparse.ArgumentParser();p.add_argument('--output',type=Path,default=ROOT/'evidence') OUT=p.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 sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() def read(name):return json.loads((ROOT/'sources'/name).read_text()) def dump(name,obj):(OUT/name).write_text(json.dumps(obj,indent=2,ensure_ascii=False,default=str)+'\n') def pair(x):return [F(x)-F(1,4),F(x)+F(1,4)] def affine(m,x):return m[0]*x+m[1] def compose(u,v):return (u[0]*v[0],u[0]*v[1]+u[1]) E=F(25,23);g=(E,1-E);J=(-1,F(2));M=(-1,F(0)) manifest=json.loads((ROOT/'SOURCE_MANIFEST.json').read_text()) for name,row in manifest.items(): src=ROOT/'sources'/name check('frozen '+name,sha(src)==row['sha256'] and src.stat().st_size==row['bytes']) prev=read('C267_CERTIFICATE.json') for file,key in [('C267_REPORT.md','report_sha256'),('C267_CHECKPOINT.md','checkpoint_sha256'),('C267_RESULTS.json','results_sha256')]: check('C267 certificate '+file,sha(ROOT/'sources'/file)==prev[key]) for file,expected in [('FILE_18.md','68301ab760bfbe2e874aedc5c8d943ced7a6219d34bc2859332a70713f9630d5'),('FILE_09.md','45851004c5864229ebf6a896f9099819a08d8926715d3e97e4bc3985c4a3876e'),('C01_REPORT.md','7bbf912ef6729b12691b259f11d77d79b6c9584a072565cb943c1660af0460b4'),('C01_RESULTS.json','191f28fb5f22ddec24790f3b17ec3962f2507b9095370a4712d5cbe25103ce1b')]: check('prior controlling hash '+file,sha(ROOT/'sources'/file)==expected) old=read('C01_RESULTS.json');chains=old['complete_three_stage_chains'];events=old['events'] c206=read('C206_CERTIFICATE.json')['evidence']['chains'] check('two retained source chains',len(chains)==2 and [r['offset'] for r in chains]==[2,4]) check('held regular event register',len(events)==48) check('prior status and scope',old['status']=='PASS' and old['scope']['active_regular_Gears_only']==['Noah','Shem','Flood']) records=read('C266_ENDPOINTS.json') local=[] for role,reflection,center,base in [('Flood',False,7,5283),('Shem',True,-5,5883)]: rs=[r for r in records if r['profile']=='LXX_OFF' and r['source_role']==role and r['source_index']==7 and r['reflection_after_translation']==reflection] check('unique closing LXX '+role,len(rs)==1) r=rs[0];check('local closing identity '+role,r['pair_center']==center and r['source_BC_base']==base) check('local closing phases '+role,list(map(F,r['exact_components']))==pair(center));local.append(r) z=[F(27,4),F(7),F(29,4)];radii=[x-1 for x in z] check('fixed local triple',radii==[F(23,4),F(6),F(25,4)]) check('LXX local J symmetry',sorted(affine(J,x) for x in z)==[F(-21,4),F(-5),F(-19,4)]) check('same Key ratio',radii[2]/radii[0]==E) scales=[F(6877)/radii[0],F(7475)/radii[0]] check('uniquely determined scales',scales==[1196,1300]) check('outer points fit independently',scales[0]*radii[2]==7475 and scales[1]*radii[2]==8125) check('scales have Key ratio',scales[1]/scales[0]==E) check('quarter scales are midpoint gains',[s/4 for s in scales]==[299,325]) check('half year scales are endpoint gains',[s/2 for s in scales]==[598,650]) rows=[];phase_rows=[];reflection_rows=[];limits=[] for idx,(src,prior) in enumerate(zip(chains,c206)): label=('N02','N04')[idx];a=-src['Creation_BC_Nisan'] f=src['Flood']['BC_Nisan'];m=src['midpoint']['BC_Nisan'];n=src['MT_Noah']['BC_Nisan'];v=src['SP_Noah']['BC_Nisan'];h=F(n+v,2) P=(E,(1-E)*a);Ja=(-1,F(2*a)) check(label+' prior C206 chain',[a,f,n,v]==[prior['a'],prior['f'],prior['n'],prior['x']]) check(label+' fixed Creation member',src['Creation_pair']==f'{-a+1}t/{-a}n BC') expected=[('MT','Flood start',idx+2,None),('SP','Noah death',idx+2,'companion'),('MT','Noah birth',idx+1,None),('SP','Noah birth',idx+1,'primary')] for role,exp in zip(['Flood','midpoint','MT_Noah','SP_Noah'],expected): e=src[role] check(label+' source role '+role,tuple(e[k] for k in ['tradition','role','gear','rail'])==exp and e in events) check(label+' widths',[f-a,n-a,v-a]==[6877,7475,8125]) check(label+' two endpoint gains',[n-f,v-n]==[598,650]) check(label+' old sourced midpoint',F(f+n,2)==m) check(label+' second midpoint generated in held register',not any(e['BC_Nisan']==h for e in events)) check(label+' first midpoint image',affine(P,m)==h) maps=[] for stage,s in enumerate(scales): A=(s,a-s);maps.append(A);ys=[affine(A,x) for x in z] desired=[f,m,n] if stage==0 else [n,h,v] check(label+' stage '+str(stage)+' all images',ys==desired) check(label+' stage '+str(stage)+' fixed anchor',affine(A,1)==a) check(label+' stage '+str(stage)+' unique slope from endpoints',F(desired[2]-desired[0],z[2]-z[0])==s) check(label+' stage '+str(stage)+' local conjugacy coefficients',compose(A,g)==compose(P,A)) check(label+' stage '+str(stage)+' reflection about Creation',compose(A,J)==compose(Ja,A)) check(label+' stage '+str(stage)+' global reflection differs',compose(A,J)!=compose(M,A)) B=(s,-a-s) check(label+' stage '+str(stage)+' reflected-anchor chart',compose(B,J)==compose(M,A)) reflection_rows.append({'chain':label,'scale':s,'fixed_Creation_anchor':a,'local_negative_points':[affine(J,x) for x in z],'same_chart_images':[affine(A,affine(J,x)) for x in z],'reflection_center':a,'global_negative_images_with_opposite_anchor':[affine(B,affine(J,x)) for x in z],'opposite_chart_anchor':-a,'status':'same-chart negative images are generated; opposite-anchor images are ordinary Mirror reversals of the retained targets, not new witnesses'}) roles=[src['Flood'],src['midpoint'],src['MT_Noah']] if stage==0 else [src['MT_Noah'],None,src['SP_Noah']] for x,y,e in zip(z,ys,roles): rows.append({'chain':label,'anchor':a,'stage':stage,'scale':s,'local_x':x,'local_radius':x-1,'local_role':'pair center' if x==7 else 'seasonal component','target_center':y,'width_from_Creation':y-a,'target_pair_components':pair(y),'target_source':e,'target_status':'source-qualified' if e else 'generated midpoint; absent from held48-event register'}) check(label+' stage '+str(stage)+' local half year changes role',ys[2]-ys[0]==s/2 and ys[2]-ys[0]!=F(1,2)) check(label+' adjacent-scale composition coefficients',maps[1]==compose(P,maps[0])==compose(maps[0],g)) # C206/C224 use paired-center expansion followed by standard display restoration. for start,end in [(f,n),(n,v)]: raw=[affine(P,x) for x in pair(start)];restored=pair(end) check(label+' center step '+str(start),affine(P,start)==end) check(label+' raw phase width '+str(start),raw[1]-raw[0]==F(25,46)) check(label+' restoration error '+str(start),[x-y for x,y in zip(raw,restored)]==[F(-1,46),F(1,46)]) check(label+' restored same-season width '+str(end),[q-p for p,q in zip(pair(a),restored)]==[end-a,end-a]) b=-a;check(label+' no-year-zero civil span '+str(end),[(b+1)+end-1,b+(end+1)-1]==[end-a,end-a]) phase_rows.append({'chain':label,'input_target_center':start,'output_target_center':end,'raw_component_images':raw,'restored_pair':restored,'raw_minus_restored':[F(-1,46),F(1,46)],'status':'center expansion with phase restoration; not raw phase transport'}) xfirst=1+F(6877,1300);xthird=1+F(8125,1196) check(label+' missing local first or third component',[xfirst,xthird]==[F(629,100),F(717,92)]) check(label+' both generated preimages nonphase',all(x%1 not in (F(1,4),F(3,4)) for x in [xfirst,xthird])) check(label+' generated preimages adjacent E orbit',affine(g,xfirst)==z[0] and affine(g,z[2])==xthird) check(label+' natural 10fold-to13fold lift',[affine(maps[1],1+F(w,1000)) for w in [5290,5750,6250]]==[f,n,v]) limits.append({'chain':label,'at_scale1196_third_target_local_preimage':xthird,'at_scale1300_first_target_local_preimage':xfirst,'local_status':'generated non-quarter-year points','full_ladder_at_scale1300':'13/10 of the C267 macro comparison values, with the same Creation anchor'}) check('two source anchors stay distinct',c206[1]['a']-c206[0]['a']==2) for s in scales: A=(s,c206[0]['a']-s);B=(s,c206[1]['a']-s) check('target chart translation '+str(s),B==compose((F(1),F(2)),A)) check('midpoint source status differs by stage',sum(r['target_source'] is None for r in rows)==2) dump('LOCAL_PROVENANCE.json',{'local_records':local,'positive_triple':z,'negative_triple':[affine(J,x) for x in z],'radii':radii}) dump('CORRESPONDENCE.json',rows) dump('PHASE_AND_REFLECTION.json',{'phase_restoration':phase_rows,'reflection':reflection_rows}) dump('LIMITS.json',{'full_ladder_preimages':limits,'scales':scales,'scale_ratio':E,'source_claim':'exact finite source-qualified coordinate correspondence; no common event identity or source-preserving chronology action established'}) dump('RESULTS.json',{'step':'C268','status':'passed','check_count':len(checks),'checks':checks,'main_result':'LXX half-year bracket maps by1196 to the sourced299+299 segment and by1300 to the325+325 segment; the two maps intertwine25/23 while preserving distinct source roles','canonical_sources_modified':False,'prior_graph_modified':False}) with (OUT/'CORRESPONDENCE.csv').open('w',newline='') as f: w=csv.writer(f);w.writerow(['chain','anchor','scale','local_x','local_role','target_center','width_from_Creation','target_status','target_role']) for r in rows:w.writerow([r[k] for k in ['chain','anchor','scale','local_x','local_role','target_center','width_from_Creation','target_status']]+[r['target_source']['role'] if r['target_source'] else 'generated midpoint']) print(json.dumps({'step':'C268','status':'passed','checks':len(checks),'output_files':6}))