from fractions import Fraction as Q from itertools import product def run(load,check): J=Q(300,299);P=Q(70,69);slope=P-J;cum=load('C365_DATA.json')['cumulative_register'];reg=load('C286_DATA.json')['target_register'];rows=[] check('nonzero difference slope',slope==Q(10,897)) check('general unique meeting input coefficient',Q(1,69)/slope==Q(13,10)) check('general common output coefficient',J*Q(13,10)==Q(30,23)) check('460 pivots select598 and600',Q(13,10)*460==598 and Q(30,23)*460==600) def cm(role,c,k):return [p for p in cum if p['role']==role and p['Cainan']==c and p['annual_index']==k] def mt(p):return p['tradition']=='MT' and p['Cainan']==p['Terah60']==p['full430']==1 def sp(p):return p['tradition']=='SP' and p['Cainan']==p['Terah60']==0 and p['full430']==1 for old in load('C319_DATA.json')['rows']: i=old['i'];a=old['a'];b=old['b'];key=f'{a}{b}:i{i}';e=int(i%2==0);cx=old['S']+460;cA=old['q'];cB=cA-460;cj=cA+J*(cx-cA);cp=cB+P*(cx-cB) csrc={'input':cm('Shem',0,i+a),'outer_pivot':cm('Flood',0,i),'inner_pivot':cm('Flood',1,i),'candidate_output':cm('Shem',0,i)} cadmit=all(csrc.values()) and old['cumulative_admitted'];cgood=bool(cadmit and cj==cp==csrc['candidate_output'][0]['coordinate']) check('cumulative normal form '+key,cA-cx==600-a and cp-cj==-slope*(2-a) and (cp==cj)==(a==2)) ns=[p for p in reg if sp(p) and p['role']=='Noah birth' and p['center']==old['n']];assert len(ns)==1;N=ns[0] ms=[p for p in reg if mt(p) and p['role']=='Noah birth' and p['gear']==N['gear']];assert len(ms)==1;M=ms[0] rx=M['center'];rA=old['R'];rB=rA+460;rj=rA+J*(rx-rA);rp=rB+P*(rx-rB) aa=[p for p in reg if mt(p) and p['role'].startswith('Flood') and p['center']==rA] bb=[p for p in reg if sp(p) and aa and p['role']==aa[0]['role'] and p['gear']==aa[0]['gear']] yy=[p for p in reg if mt(p) and p['role']=='Noah birth' and p['gear']==N['gear']+b//2] radmit=bool(aa and bb and yy and old['regular_admitted']);rgood=bool(radmit and rj==rp==yy[0]['center']) check('regular normal form '+key,rx-rA==600+e-b and rp-rj==slope*(2+e-b) and (rp==rj)==(b==2 and e==0)) if bb:check('matched event pivot source '+key,bb[0]['center']==rB and bb[0]['role']==aa[0]['role']) rows.append({'key':key,'a':a,'b':b,'i':i,'rail':N['rail'],'joint_admitted':old['joint_admitted'],'cumulative':{'source_records':csrc,'input_gap':cA-cx,'J_image':str(cj),'P_image':str(cp),'P_minus_J':str(cp-cj),'formal_agreement':cp==cj,'source_agreement':cgood},'regular':{'input':M,'outer_pivot':aa,'inner_pivot':bb,'candidate_output':yy,'input_gap':rx-rA,'J_image':str(rj),'P_image':str(rp),'P_minus_J':str(rp-rj),'formal_agreement':rp==rj,'source_agreement':rgood},'joint_source_agreement':bool(cgood and rgood and old['joint_admitted'])}) sig=lambda part:sorted(x['key'] for x in rows if x[part]['source_agreement']) joint=sorted(x['key'] for x in rows if x['joint_source_agreement']) check('cumulative six source agreements',sig('cumulative')==['20:i3','20:i4','20:i5','22:i3','22:i4','22:i5']) check('regular four source agreements',sig('regular')==['02:i3','02:i5','22:i3','22:i5']) check('joint two source agreements',joint==['22:i3','22:i5']) check('selector agrees with prior different role test',joint==load('C368_DATA.json')['survivors']['conjunction']) boundary=[] for old in load('PREVIOUS_DATA.json')['regular_rows']: if old['rail']!='companion':continue i=old['i'];x=old['input_MT_Noah']['center'];A=old['J_pivot_MT_Flood'];B=next(p for p in reg if sp(p) and p['gear']==A['gear'] and p['role']=='Flood start');target=old['candidate_next_Gear_MT_Noah']['center'];yj=A['center']+J*(x-A['center']);yp=B['center']+P*(x-B['center']);D=B['center']-A['center'] check('companion alternative boundary '+str(i),D==461 and x-B['center']==138 and yp==target and yj-target==Q(1,299) and yp-yj==-Q(1,299)) check('alternative pivots unique meeting not current source '+str(i),Q(13,10)*D==Q(5993,10) and Q(30,23)*D==Q(13830,23) and x-A['center']!=Q(13,10)*D) boundary.append({'i':i,'J_pivot_MT_close':A,'P_pivot_SP_start':B,'pivot_separation':D,'P_standalone_source_hit':True,'joint_agreement':False,'P_minus_J':str(yp-yj),'required_input_gap':str(Q(13,10)*D)}) phases=[] sources=[('cumulative',p['i'],p['input_OFF_Shem']['coordinate'],p['J_pivot_OFF_Flood']['coordinate'],p['P_pivot_ON_Flood']['coordinate'],p['output_OFF_Shem']['coordinate']) for p in load('PREVIOUS_DATA.json')['cumulative_rows'] if p['full_C287']] sources += [('regular',p['i'],p['input_MT_Noah']['center'],p['J_pivot_MT_Flood']['center'],p['P_pivot_SP_Flood']['center'],p['candidate_next_Gear_MT_Noah']['center']) for p in load('PREVIOUS_DATA.json')['regular_rows'] if p['common_source_output']] for field,i,x,A,B,y in sources: for u in [-Q(1,4),Q(1,4)]: cj=A+u+J*(x+u-(A+u));cp=B+u+P*(x+u-(B+u));fj=A+J*(x+u-A);fp=B+P*(x+u-B) check('same-offset component agreement '+str((field,i,u)),cj==cp==y+u) check('fixed pivots fail component equality '+str((field,i,u)),fp-fj==slope*u and fp!=fj and fj-(y+u)==u/299 and fp-(y+u)==u/69) phases.append({'field':field,'i':i,'offset':str(u),'component_preserving_common_image':str(cj),'target_component':str(y+u),'fixed_pivot_P_minus_J':str(fp-fj),'fixed_pivot_J_error':str(fj-y-u),'fixed_pivot_P_error':str(fp-y-u)}) check('phase inventory',len(phases)==12) return {'step':'C371','normal_form':{'difference':'D+P(x-D)-Jx=(10/897)x-D/69','unique_input':'x=13D/10','common_output':'y=30D/23','D460_difference':'(10/897)(x-598)','conditional':'This is agreement of two specified anchored comparisons, not equality of operators or a textual prescription.'},'control_rows':rows,'survivors':{'cumulative':sig('cumulative'),'regular':sig('regular'),'joint':joint},'boundary_controls':boundary,'phase_controls':phases,'counts':{'C319_controls':20,'cumulative_source_agreements':6,'regular_source_agreements':4,'joint_source_agreements':2,'alternative_companion_boundaries':2,'same_offset_phase_agreements':12,'fixed_pivot_phase_agreements':0},'scope':'No new endpoint, boundary, phase, anchor, source state or Gear is adopted.'}