from fractions import Fraction as F def rank(a): a=[[F(x) for x in r] for r in a];r=0 for c in range(len(a[0])): k=next((k for k in range(r,len(a)) if a[k][c]),None) if k is None:continue a[r],a[k]=a[k],a[r];v=a[r][c];a[r]=[x/v for x in a[r]] for k in range(len(a)): if k!=r: v=a[k][c];a[k]=[x-v*y for x,y in zip(a[k],a[r])] r+=1 return r def run(load,check): old=load('PREVIOUS_DATA.json');c286=load('C286_DATA.json');anc=load('C271_REGISTER.json');four=load('C287_DATA.json');rows=[] for r in old['rows']: i,j,g,rail=r['i'],r['j'],r['gear'],r['rail'];n,s,f,nd,d=r['biography_BC'];p=-5890+i;q=-5290+i pairs=[z for z in c286['source_pairs'] if z['Shem_Cainan']==z['Flood_Cainan']==0 and z['Shem_index']==z['Flood_index']==i] check(f'i{i} source600 segment',len(pairs)==1 and (pairs[0]['S'],pairs[0]['F'],pairs[0]['first'])==(p,q,600)) widths=[[f-p,n-p],[f-q,n-q]];check(f'i{i} crosswidths',widths==[[8993,9593],[8393,8993]]) phase=[] for e in [F(-1,4),F(1,4)]: for branch,role,source,output in [('Noah','Noah birth',q,n),('Flood',r['selected_Flood_role'],p,f)]: ar=[a for a in anc if a['branch']==branch and a['source_event']['gear']==g and a['source_event']['role']==role and (branch=='Flood' or a['source_event']['rail']==rail)] check(f'i{i} {e} {branch} ancestry',len(ar)==1 and ar[0]['cumulative_source']['source_index']==i and any(F(z['cumulative_coordinate'])==source+e and F(z['reflected_coordinate'])==output+e for z in ar[0]['phases'])) check(f'i{i} {e} rectangle',(q+e)-(p+e)==(n+e)-(f+e)==600 and (f+e)-(p+e)==(n+e)-(q+e)==8993) phase.append({'phase':str(e),'p':str(p+e),'q':str(q+e),'f':str(f+e),'n':str(n+e)}) c=[x for x in four['rows'] if x['i']==i and x['complete']] if c: c=c[0];check(f'i{i} paired458 replacement',p-c['S']==f-c['R']==458 and c['F']==q and c['Noah_required']==n) replacement={'S':c['S'],'R':c['R'],'paired_shift':-458,'new_side':1058,'source_admitted':True} else:replacement={'S_required':p-458,'R_required':f-458,'ON_Shem_index_required':i+2,'source_admitted':False} rows.append({'i':i,'j':j,'gear':g,'rail':rail,'p':p,'q':q,'f':f,'n':n,'cross_widths':widths,'side600':True,'components':phase,'C287_replacement':replacement}) incidence=[[-1,1,0,0],[-1,0,1,0],[0,-1,0,1],[0,0,-1,1],[-1,0,0,1],[0,-1,1,0]] check('six durations rankthree',rank(incidence)==3) check('two translated600 sides dependent',8993+600-600==8993) check('600 sides notK multiple',600%529!=0) return {'step':'C317','rows':rows,'counts':{'source_rectangles':5,'exact_phase_rectangles':10,'C287_paired_replacements':3,'C287_failed_extensions':2},'duration_rank':3,'equations':{'rectangle':'q−p=n−f=600; f−p=n−q=17K','dependency':'(n−q)−(f−p)=(n−f)−(q−p)=0','C287_replacement':'(p,f)→(p−458,f−458); (q,n) retained'},'source_types':['cumulative LXX_OFF Shem','cumulative LXX_OFF Flood','regular SP Flood boundary','regular SP Noah birth'],'new_independent_17K_measurements':False}