from fractions import Fraction as Q from math import gcd def run(load,check): P=Q(70,69);J=Q(300,299);pden=P.denominator;jden=J.denominator check('both ratios have unit numerator increment',P.numerator-pden==J.numerator-jden==1) check('reduced integer-output ratios',gcd(P.numerator,pden)==gcd(J.numerator,jden)==1) check('unit gain primitive inputs',P*69-69==J*299-299==1) D=jden-pden;side=D+jden check('primitive pivot and side',D==230 and side==529 and side==2*299-69) check('primitive output pair',J*299==300 and P*69==70 and 300-70==230) check('integer-input rational-family coefficients',gcd(299,69)==23 and Q(299,69)==Q(13,3) and Q(300,23)-13==Q(70,23)-3==Q(1,23)) check('integer outputs require t divisible23',Q(300,23).denominator==23 and Q(70,23).denominator==23) check('C371 rational family consistency',Q(13,10)*D==299 and Q(30,23)*D==300) check('integer input alone is insufficient',Q(13,10)*10==13 and Q(30,23)*10==Q(300,23) and Q(300,23).denominator!=1) scales=[];source=load('C370_DATA.json');oldcum={x['i']:x for x in load('C364_DATA.json')['rows']} for r in source['cumulative_rows']: if not r['full_C287']:continue i=r['i'];S=oldcum[i]['S_ON']['coordinate'];x=r['input_OFF_Shem']['coordinate'];A=r['J_pivot_OFF_Flood']['coordinate'];B=r['P_pivot_ON_Flood']['coordinate'];y=r['output_OFF_Shem']['coordinate'];gain=x-y;sep=A-B;outergap=A-x;innergap=B-x check('cumulative integer grammar '+str(i),gain==2 and sep==D*gain and outergap==299*gain and innergap==69*gain and A-y==300*gain and B-y==70*gain) check('cumulative source first segment equals pivot separation '+str(i),x-S==sep==460 and A-S==side*gain==2*529 and y-S==458) scales.append({'field':'cumulative','i':i,'gain':gain,'source_pivot_separation':sep,'first_source_segment':x-S,'input_gaps':[innergap,outergap],'output_gaps':[B-y,A-y],'whole_side':A-S,'primitive_scale':2,'repaired_partition':[y-S,A-y]}) for r in source['regular_rows']: i=r['i'];N=r['SP_Noah']['center'];x=r['input_MT_Noah']['center'];A=r['J_pivot_MT_Flood']['center'];B=r['P_pivot_SP_Flood']['center'];y=r['candidate_next_Gear_MT_Noah']['center'] if not r['common_source_output']: check('companion keeps distinct source gaps '+str(i),N-x==459 and B-A==460 and x-A==599 and x-B==139 and N-A==1058 and Q(x-A,299)!=Q(x-B,69)) continue gain=y-x;sep=B-A;outergap=x-A;innergap=x-B check('regular integer grammar '+str(i),gain==2 and sep==D*gain and outergap==299*gain and innergap==69*gain and y-A==300*gain and y-B==70*gain) check('regular source first segment equals pivot separation '+str(i),N-x==sep==460 and N-A==side*gain==2*529 and N-y==458) scales.append({'field':'regular','i':i,'gain':gain,'source_pivot_separation':sep,'first_source_segment':N-x,'input_gaps':[innergap,outergap],'output_gaps':[y-B,y-A],'whole_side':N-A,'primitive_scale':2,'repaired_partition':[N-y,y-A]}) check('six source applications with dependent ancestry',len(scales)==6 and all(r['primitive_scale']==2 for r in scales)) check('retained selector',load('PREVIOUS_DATA.json')['survivors']['joint']==['22:i3','22:i5']) check('bridge complement agrees arithmetically',529-460==69 and 529-459==70 and 138==2*69 and 140==2*70) proof=[ 'Assume integer input and output gaps, positive expansion, and equal gains under the two specified ratios.', 'For J, x maps to x+x/299. Integer x and integer output imply m=x/299 is a positive integer; hence x=299m and output300m.', 'For P, z maps to z+z/69. Equal gain m gives z=69m and output70m.', 'The pivot separation is x-z=230m. Conversely these formulas satisfy both conversions for every positive integer m.', 'When a separate source first segment equals that pivot separation, the whole side is (230+299)m=529m.', 'The actual 460-year source separation forces m=2. This is a conditional algebraic explanation of the existing1058=2K side, not a source command to pair the ratios.' ] return {'step':'C372','primitive_integer_family':{'scale':'m positive integer','inner_input':'69m','inner_output':'70m','pivot_separation':'230m','outer_input':'299m','outer_output':'300m','whole_side_if_source_first_segment_equals_pivot_separation':'529m'},'proof':proof,'integer_input_only_family':{'input_outer':'13t','input_inner':'3t','pivot_separation':'10t','common_gain':'t/23','integer_outputs_iff':'t divisible by23','diagnostic_not_source':{'D':10,'outer_input':13,'common_outer_output':'300/23'}},'source_scale':2,'source_applications':scales,'source_counts':{'complete_cumulative_rows':4,'primary_regular_rows':2,'companion_controls_rejected':2},'identity':'2*299-69=529; at sourced scale2:460+598=1058, repaired458+600=1058, and138→140.','interpretation':'A primitive arithmetic consequence of imposing equal P/J gains. The inherited ratios and source geometry supply it; no new historical witness, textual pairing instruction, date anchor or operator is established. Primitive230 is a scalar normal form, not an adopted chronology endpoint or a reopened primer.'}