from fractions import Fraction as Q from itertools import product def run(load,check): out=[];K=529;B=19*K for r in load('C366_DATA.json')['matched_rows']: i=r['i'];e=int(r['rail']=='companion');d=460-e;X,Y,S,Z=r['cumulative_records'];N,M,D,H=r['regular_records'];cs=[(X,S),(Y,Z)];rs=[(N,D),(M,H)];routes=[] for a,b in product([0,1],repeat=2): cb,cd=cs[a];rb,rd=rs[b];T=rd['center']-cb['coordinate'];other=rb['center']-cd['coordinate'];m=a+b;quot,rem=divmod(T,K) check('source interval bridge '+str((i,a,b)),T==other==B-m*d and cd['coordinate']-cb['coordinate']==rb['center']-rd['center']==950) check('529 quotient remainder '+str((i,a,b)),quot==19-m and rem==m*(69+e)) phase=[] for u in [-Q(1,4),Q(1,4)]: check('same phase route '+str((i,a,b,u)),cb['coordinate']+u+T==rd['center']+u and cd['coordinate']+u+T==rb['center']+u);phase.append(str(u)) routes.append({'cumulative_state':a,'regular_context':b,'source_birth':cb,'source_death_seam':cd,'target_birth':rb,'target_death':rd,'translation':T,'K_quotient':quot,'K_remainder':rem,'switch_count':m,'phase_offsets':phase}) check('three distinct bridge constants '+str(i),len({x['translation'] for x in routes})==3) out.append({'i':i,'rail':r['rail'],'native_index':r['native_index'],'OFF_index':r['OFF_index'],'state_gap':d,'routes':routes,'matrix':[[x['translation'] for x in routes[:2]],[x['translation'] for x in routes[2:]]],'remainder_matrix':[[0,69+e],[69+e,2*(69+e)]]}) check('four matrices sixteen source routes',len(out)==4 and sum(len(x['routes']) for x in out)==16) check('complement identity',529-460==69 and 529-459==70) return {'step':'C369','rows':out,'counts':{'matrices':4,'source950_routes':16,'same_phase_route_components':32},'normal_form':'T_ab=19K-(a+b)d=(19-a-b)K+(a+b)(K-d), d=460-e','primary_bridge_matrix':[[10051,9591],[9591,9131]],'companion_bridge_matrix':[[10051,9592],[9592,9133]],'interpretation':'Primary complements are69/138; companion complements70/140. The latter use the explicit compound Cainan plus annual-index gap459. Bridge remainders are duration arithmetic, not calendar residue or newly adopted epoch anchors. Equal bridge constants retain distinct source roles.'}