from fractions import Fraction as F def run(load,check): data=load('C286_DATA.json');reg=data['target_register'];anc=load('C271_REGISTER.json');four={r['i'] for r in load('C287_DATA.json')['rows'] if r['complete']};rows=[];context_keys=['tradition','gear','Cainan','Terah60','full430'];comparisons=0 for i in range(8): p,q,f,n=-5890+i,-5290+i,3103+i,3703+i ps=[z for z in data['source_pairs'] if z['Shem_Cainan']==z['Flood_Cainan']==0 and z['Shem_index']==z['Flood_index']==i] check(f'i{i} frozen sourcepair',len(ps)==1 and ps[0]['S']==p and ps[0]['F']==q) nh=[];fh=[] for t in reg: comparisons+=2 if t['role']=='Noah birth' and t['center']==n:nh.append(t) if t['role'] in ['Flood start','Flood close'] and t['center']==f:fh.append(t) pairs=[] for N in nh: for B in fh: if any(N[k]!=B[k] for k in context_keys):continue check(f'i{i} {N["tradition"]} matched duration',N['center']-B['center']==600) if N['tradition']=='SP':check(f'i{i} SP rail boundary',B['role']==('Flood start' if N['rail']=='primary' else 'Flood close')) else:check(f'i{i} {N["tradition"]} no invented companion',N.get('rail') is None and B['role']=='Flood start') components=[] for e in [F(-1,4),F(1,4)]: vals=[F(z)+e for z in [p,q,f,n]];check(f'i{i} {N["tradition"]} {e} exactrectangle',vals[2]-vals[0]==vals[3]-vals[1]==8993 and vals[1]-vals[0]==vals[3]-vals[2]==600) if N['tradition']=='SP': for role,source,out in [('Noah',p+600+e,n+e),('Flood',p+e,f+e)]: ar=[z for z in anc if z['branch']==role and z['source_event']['gear']==N['gear'] and (z['source_event']['rail']==N['rail'] if role=='Noah' else z['source_event']['role']==B['role'])] check(f'i{i} {e} C271 {role}',len(ar)==1 and any(F(z['cumulative_coordinate'])==source and F(z['reflected_coordinate'])==out for z in ar[0]['phases'])) components.append([str(z) for z in vals]) pairs.append({'Noah':N,'Flood':B,'components':components}) j=10-i;sp=[z for z in pairs if z['Noah']['tradition']=='SP'];shem=[] if sp: N=sp[0]['Noah'];shem=[z for z in reg if z['tradition']=='SP' and z['gear']==N['gear'] and z.get('rail')==N['rail'] and z['role']=='Shem birth' and z['Cainan']==N['Cainan'] and z['Terah60']==N['Terah60'] and z['full430']==N['full430'] and z['center']==n-500] check(f'i{i} source matched Shem',len(shem)==1 and shem[0]['center']==3213-j) rows.append({'i':i,'p':p,'q':q,'f_required':f,'n_required':n,'Noah_point_records':nh,'Flood_point_records':fh,'matched_context_rectangles':pairs,'C287_complete':i in four,'C314_required_j':j,'C314_j_in_field':j in range(8),'matched_SP_Shem':shem}) counts={'point_record_comparisons':comparisons,'Noah_point_records':sum(len(r['Noah_point_records']) for r in rows),'Flood_point_records':sum(len(r['Flood_point_records']) for r in rows),'context_rectangles':sum(len(r['matched_context_rectangles']) for r in rows),'coordinate_rectangles':sum(bool(r['matched_context_rectangles']) for r in rows),'SP_rectangles':sum(z['Noah']['tradition']=='SP' for r in rows for z in r['matched_context_rectangles']),'LXX_rectangles':sum(z['Noah']['tradition']=='LXX' for r in rows for z in r['matched_context_rectangles'])} check('entire existing register searched',len(reg)==528 and comparisons==8448) check('complete finite census',counts['SP_rectangles']==6 and counts['LXX_rectangles']==3 and counts['context_rectangles']==9 and counts['coordinate_rectangles']==6) check('only i2 through7 admitted',[r['i'] for r in rows if r['matched_context_rectangles']]==list(range(2,8))) return {'step':'C320','rows':rows,'counts':counts,'omitted_G1_companion':{'i':2,'Noah':3705,'Flood_close':3105,'Shem':3205,'required_j':8,'source_biography_valid':True,'C314_cumulative_j_absent':True,'C287_complete':True},'limits':'Source-controlled aliases, not independent historical witnesses. All source inputs/contexts fixed.'}