from fractions import Fraction as Q def run(load,check): E=Q(25,23);J=Q(300,299);reg=load('C286_DATA.json')['target_register'];rows=[];unavailable=[] def exact(trad,rail,full,g,role): out=[r for r in reg if r['tradition']==trad and r.get('rail')==rail and r['full430']==full and r['gear']==g and r['role']==role and r['Cainan']==0 and r['Terah60']==0] return out[0] if len(out)==1 else None for k,base in enumerate(load('C385_DATA.json')['rows']): A,B,x,y,N=base['original_tuple'];sp=base['source_context_lifts'][0]['Noah_input_record'];g=sp['gear'];full=sp['full430'] for trad,rail in [('SP','primary'),('SP','companion'),('LXX',None)]: noah=exact(trad,rail,full,g,'Noah birth');nextn=exact(trad,rail,full,g+1,'Noah birth');check('admitted Noah context '+str((k,trad,rail)),noah is not None and nextn is not None) for mode,sig in [('500/100',0),('502/98',-1)]: key=(k,trad,rail,mode) if g+sig<1: unavailable.append({'row':k,'tradition':trad,'rail':rail,'mode':mode,'reason':'Would require unrecorded Gear0 Shem; no endpoint generated.'});continue s=exact(trad,rail,full,g+sig,'Shem birth');t=exact(trad,rail,full,g+1+sig,'Shem birth');d=exact(trad,rail,full,g+1+sig,'Shem death') check('admitted Shem mode '+str(key),s is not None and t is not None and d is not None and noah['center']-s['center']==(500 if sig==0 else 502)) check('horizontal Shem J remains valid '+str(key),s['center']-d['center']==598 and t['center']-d['center']==600 and d['center']+J*(s['center']-d['center'])==t['center']) image=noah['center']+E*(x-noah['center']);image2=nextn['center']+E*(y-nextn['center']);res=image-s['center'];want=(Q(25,23) if rail=='companion' else 0)+(2 if sig==-1 else 0) check('exact vertical mode residual '+str(key),res==want and image2-t['center']==want) inverse=noah['center']+(s['center']-noah['center'])/E mt=[r for r in reg if r['center']==inverse and r['tradition']=='MT' and r['role']=='Noah birth' and r['Cainan']==1 and r['Terah60']==1 and r['full430']==full] ok=want==0 check('unique typed MT input membership '+str(key),bool(mt)==ok and (inverse==x)==ok) rows.append({'row':k,'tradition':trad,'rail':rail,'mode':mode,'Noah_record':noah,'next_Noah_record':nextn,'Shem_input_record':s,'Shem_output_record':t,'Shem_death_pivot_record':d,'E_input_image':str(image),'vertical_residual':str(res),'unique_required_MT_input':str(inverse),'typed_MT_input_records':mt,'all_four_source_edges_pass':ok,'Shem_J_edge_passes':True}) check('finite mode inventory',len(rows)==18 and len(unavailable)==6 and sum(r['all_four_source_edges_pass'] for r in rows)==8) check('failed modes retain source validity',sum(r['mode']=='502/98' for r in rows)==6 and all(r['Shem_J_edge_passes'] for r in rows)) return {'step':'C387','mode_trials':rows,'unavailable_trials':unavailable,'counts':{'available_labelled_mode_trials':18,'unavailable_Gear0_trials':6,'complete_E_J_squares':8,'valid_horizontal_Shem_J_edges':18,'vertical_E_failures':10},'residual_formula':'E image minus selected Shem birth = (25/23 if SP companion else0)+(2 if502/98 else0).','interpretation':'The square realizes primary500/100 contexts; it does not invalidate the companion or502/98 source modes. All18 available Shem horizontal J edges remain exact. Vertical E fails in ten alternatives. No MT companion or Gear0 is supplied.'}