from fractions import Fraction as Q def run(load,check): reg=load('C286_DATA.json')['target_register'];cases=load('C396_DATA.json')['hits'];rows=[];good={500:[],502:[]} def find(r,role,rail,shift): gear=r['gear']-(shift-500)//2 return [s for s in reg if s['role']==role and s['gear']==gear and s.get('rail')==rail and s['center']==r['center']-shift and all(s.get(k)==r.get(k) for k in ['tradition','Cainan','Terah60','full430'])] for shift in [500,502]: for i,h in enumerate(cases): slots=[] for name,r in h['records'].items(): role='Shem death' if name=='J_Flood' else 'Shem birth';rail=h['records']['higher_Noah'].get('rail') if name=='J_Flood' else r.get('rail');hits=find(r,role,rail,shift) slots.append({'role_in_loop':name,'source':r,'required_role':role,'required_Gear':r['gear']-(shift-500)//2,'required_coordinate':r['center']-shift,'matching_records':hits}) for k,r in enumerate(h['P_return_source_records']): hits=find(r,'Shem death','primary' if r['tradition']=='SP' else None,shift);slots.append({'role_in_loop':'P_pivot_'+str(k),'source':r,'required_role':'Shem death','required_Gear':r['gear']-(shift-500)//2,'required_coordinate':r['center']-shift,'matching_records':hits}) passed=all(len(s['matching_records'])==1 for s in slots) check('binding boundary '+str((shift,i)),passed==(shift==500 or h['lower_Gear']==2)) if not passed:check('only unavailable Gear0 slots '+str((shift,i)),all(s['required_Gear']==0 for s in slots if not s['matching_records'])) loop=[h[k]-shift for k in ['E_Noah_pivot','E_input','E_output','J_return_pivot']] if passed: good[shift].append(loop);V,x,y,A=loop;check('admitted loop arithmetic '+str((shift,i)),Q(25,23)*(x-V)==y-V and Q(300,299)*(y-A)==x-A) rows.append({'shift':shift,'mode':'500/100' if shift==500 else '502/98','case':i,'original_lower_Gear':h['lower_Gear'],'slots':slots,'all_required_records_sourced':passed,'coordinate_loop':loop if passed else None}) a={tuple(r) for r in good[500]};c={tuple(r) for r in good[502]} check('502 outputs are a subset of500 source configurations',len(a)==6 and len(c)==3 and c