from fractions import Fraction as Q from collections import Counter def run(load,check): reg=load('C286_DATA.json')['target_register'];keys=['tradition','rail','Cainan','Terah60','full430'];families=sorted({tuple(r.get(k) for k in keys) for r in reg if r['role']=='Noah birth'});trials=[];hits=[];counter=Counter() def one(f,g,role): rs=[r for r in reg if r['gear']==g and r['role']==role and all(r.get(k)==v for k,v in zip(keys,f) if k!='rail' or not role.startswith('Flood'))];assert len(rs)==1;return rs[0] for g in [1,2]: for ei,edgef in enumerate(families): yr=one(edgef,g,'Noah birth');xr=one(edgef,g+1,'Noah birth');y=yr['center'];x=xr['center'] check('coherent moving Noah pair '+str((g,ei)),x-y==2) for ni,nf in enumerate(families): nr=one(nf,g,'Noah birth');N=nr['center'];epass=25*(x-N)==23*(y-N) for boundary in ['Flood start','Flood close']: ar=one(edgef,g+1,boundary);A=ar['center'];jpass=300*(y-A)==299*(x-A);mask=('1' if epass else '0')+('1' if jpass else '0');counter[mask]+=1 trials.append({'lower_Gear':g,'edge_family':ei,'held_Noah_family':ni,'Flood_boundary':boundary,'E_pass':epass,'J_pass':jpass,'loop':epass and jpass}) if epass and jpass: B=y-69*(x-y);pivots=[q for q in reg if q['center']==B] hits.append({'lower_Gear':g,'edge_family':dict(zip(keys,edgef)),'held_Noah_family':dict(zip(keys,nf)),'records':{'higher_Noah':xr,'lower_Noah':yr,'held_Noah':nr,'J_Flood':ar},'E_Noah_pivot':N,'E_input':x,'E_output':y,'J_return_pivot':A,'J_Flood_boundary':boundary,'unique_P_return_pivot':B,'P_return_source_records':pivots}) coords={tuple(h[k] for k in ['E_Noah_pivot','E_input','E_output','J_return_pivot']) for h in hits};phits=[h for h in hits if h['P_return_source_records']] common=next(f for f in load('C378_DATA.json')['fields'] if f['field']=='regular')['hits'] for k,h in enumerate(hits): check('derived primitive distances '+str(k),h['E_Noah_pivot']-h['E_input']==23 and h['E_Noah_pivot']-h['E_output']==25 and h['E_Noah_pivot']-h['J_return_pivot']==623) check('25-year source context displacement '+str(k),h['held_Noah_family']['Cainan']==h['held_Noah_family']['Terah60']==0 and h['held_Noah_family']['full430']==1 and h['edge_family']['Cainan']==h['edge_family']['Terah60']==1 and h['edge_family']['full430']==0) if h['P_return_source_records']: check('existing common P J return '+str(k),any(t['J_pivot']==h['J_return_pivot'] and t['P_pivot']==h['unique_P_return_pivot'] and t['input']==h['E_output'] and t['output']==h['E_input'] for t in common)) check('typed P Flood sources '+str(k),len(h['P_return_source_records'])==2 and all(t['role']=='Flood start' and t['tradition'] in ['SP','LXX'] and t['gear']==h['lower_Gear']+1 and t['Cainan']==t['Terah60']==0 and t['full430']==0 for t in h['P_return_source_records'])) check('census domain',len(families)==32 and len(trials)==4096) check('observed loop inventory',len(hits)==12 and len(coords)==6 and len(phits)==2 and sum(h['J_Flood_boundary']=='Flood close' for h in hits)==2) return {'step':'C396','families':[dict(zip(keys,f)) for f in families],'trials':trials,'hits':hits,'coordinate_loops':[list(t) for t in sorted(coords)],'outcome_masks_E_J':dict(sorted(counter.items())),'counts':{'families':32,'labelled_trials':4096,'source_labelled_E_J_loops':len(hits),'coordinate_E_J_loops':len(coords),'labelled_Flood_close_loops':2,'coordinate_E_P_J_loops':len(phits),'coordinate_J_only_loops':len(coords)-len(phits)},'interpretation':'The complete coherent-family motif has six coordinate E/J loops: two MT, two SP-primary/LXX coordinate families with distinct aliases, and two SP companion loops using Flood close. Only the two MT loops have a sourced P return; their reverse edges are the existing lower-full430 common P/J repairs. No529 filter was applied.'}