from fractions import Fraction as F def run(load,check): old=load('PREVIOUS_DATA.json');reg=load('C286_DATA.json')['target_register'];pairs=load('C286_DATA.json')['source_pairs'];rows=[] for r in old['rows']: i,g=r['i'],r['gear'];role='Flood start' if r['rail']=='primary' else 'Flood close';p=r['p'];f=r['f'] def matches(center,gear,C,T):return [z for z in reg if z['tradition']=='MT' and z['role']==role and z['center']==center and z['gear']==gear and z['Cainan']==C and z['Terah60']==T and z['full430']==1] stages=[(f-650,g,0,0),(f-520,g,1,0),(f-460,g,1,1),(f-458,g+1,1,1)] m=[] for k,args in enumerate(stages): hit=matches(*args);check(f'i{i} regular stage{k} admission',len(hit)==(1 if k<3 or g<3 else 0));m.append({'required_center':args[0],'gear':args[1],'Cainan':args[2],'Terah60':args[3],'records':hit}) on_same=[z for z in pairs if z['Shem_Cainan']==1 and z['Shem_index']==i];on_next=[z for z in pairs if z['Shem_Cainan']==1 and z['Shem_index']==i+2] check(f'i{i} cumulative sameindex ON',len(on_same)>0 and {z['S'] for z in on_same}=={p-460}) check(f'i{i} cumulative nextindex ON',bool(on_next)==(i<=5) and (not on_next or {z['S'] for z in on_next}=={p-458})) admitted=bool(m[-1]['records']) and bool(on_next) check(f'i{i} paired domain',admitted==r['C287_replacement']['source_admitted']) comps=[] for e in [F(-1,4),F(1,4)]: # All here are explicitly signed cumulative or reflected regular coordinates. S=F(p)-460+2+e;R=F(f)-650+130+60+2+e check(f'i{i} {e} ordered operations agree',S==F(p)-458+e and R==F(f)-458+e and R-S==8993) check(f'i{i} {e} allK sublegs',F(r['q'])+e-S==1058 and R-(F(r['q'])+e)==7935) comps.append({'phase':str(e),'required_S':str(S),'required_R':str(R),'source_admitted':admitted}) rows.append({'i':i,'j':r['j'],'SP_gear':g,'role':role,'cumulative_source_OFF':p,'cumulative_ON_same_index':p-460,'cumulative_ON_required_index':i+2,'cumulative_ON_required_center':p-458,'cumulative_final_admitted':bool(on_next),'regular_stages':m,'regular_final_admitted':bool(m[-1]['records']),'paired_admitted':admitted,'components':comps}) check('restored comparison has460 offset',650-130-60==460) check('two decompositions of2K',600+460-2==598+460==2*529) return {'step':'C318','rows':rows,'counts':{'first_regular_stages_admitted':15,'paired_final_admitted':3,'paired_final_failed':2,'exact_admitted_components':6},'cumulative_operations':[-460,2],'regular_operations':[-650,130,60,2],'net_each':-458,'paired_replacement_is_source_prescribed':False,'interpretation':'All ingredients are admitted in stated domains; composition is a comparison selected for this question, not a source-prescribed annual rule.'}