from fractions import Fraction as Q def run(load,check): ratios={'E':Q(25,23),'P':Q(70,69),'J':Q(300,299)};hs=sorted([h for h in load('C396_DATA.json')['hits'] if h['P_return_source_records']],key=lambda h:h['lower_Gear']);edges=[];vertices=sorted({h[k] for h in hs for k in ['E_input','E_output']});paths=[];classes={} check('one shared typed MT Noah vertex',hs[0]['records']['higher_Noah']==hs[1]['records']['lower_Noah'] and vertices==[3031,3033,3035]) def aff(a,k):return(k,(1-k)*a) def comp(a,b):return(a[0]*b[0],a[0]*b[1]+a[1]) for h in hs: for op,u,v,a in [('E',h['E_input'],h['E_output'],h['E_Noah_pivot']),('P',h['E_output'],h['E_input'],h['unique_P_return_pivot']),('J',h['E_output'],h['E_input'],h['J_return_pivot'])]:edges.append({'operator':op,'input':u,'output':v,'pivot':a,'affine':aff(a,ratios[op])}) def visit(start,current,word,counts,transform,trace): e,p,j=[counts[t] for t in ['E','P','J']];slope=ratios['E']**e*ratios['P']**p*ratios['J']**j;expected=(slope,Q(current)-slope*start);key=(start,current,e,p,j) check('path normal form '+str((start,tuple(trace))),transform==expected and (current-start)//2==p+j-e) if key in classes:check('equal counts and endpoints collapse '+str((start,tuple(trace))),classes[key]==transform) else:classes[key]=transform paths.append({'start':start,'end':current,'operators_in_execution_order':word,'edge_indices':trace,'counts':counts.copy(),'affine_coefficients':list(map(str,transform))}) if len(word)==6:return for i,edge in enumerate(edges): if edge['input']==current: cc=counts.copy();cc[edge['operator']]+=1;visit(start,edge['output'],word+edge['operator'],cc,comp(edge['affine'],transform),trace+[i]) for start in vertices:visit(start,start,'',{'E':0,'P':0,'J':0},(Q(1),Q(0)),[]) byends={} for key,tr in classes.items():byends.setdefault(key[:2],[]).append(tr) check('distinct count triples remain distinct within typed endpoints',all(len(v)==len(set(v)) for v in byends.values())) def primeval(q,p): n,d=q.numerator,q.denominator;v=0 while n%p==0:n//=p;v+=1 while d%p==0:d//=p;v-=1 return v vals={str(p):[primeval(ratios[op],p) for op in ['E','P','J']] for p in [7,13,5]} check('operator multiplicative independence',vals=={'7':[0,1,0],'13':[0,0,-1],'5':[2,1,2]}) middle=3033;leftP=comp(edges[1]['affine'],edges[0]['affine']);rightP=comp(edges[3]['affine'],edges[4]['affine']);leftJ=comp(edges[2]['affine'],edges[0]['affine']);rightJ=comp(edges[3]['affine'],edges[5]['affine']) check('central circuits agree across the two source segments',leftP==rightP==aff(middle,ratios['E']*ratios['P']) and leftJ==rightJ==aff(middle,ratios['E']*ratios['J'])) backwards=[p for p in paths if p['start']==3035 and p['end']==3031 and p['operators_in_execution_order']=='EE'];check('two moving-pivot E returns are admitted',len(backwards)==1 and Q(backwards[0]['affine_coefficients'][0])==Q(625,529)) check('finite path inventory',len(paths)==402 and len(vertices)==3 and len(edges)==6) return {'step':'C400','vertices':vertices,'edges':[{**e,'affine':list(map(str,e['affine']))} for e in edges],'path_trials':paths,'normal_form_classes':[{'start':k[0],'end':k[1],'E_count':k[2],'P_count':k[3],'J_count':k[4],'affine_coefficients':list(map(str,v))} for k,v in sorted(classes.items())],'prime_valuation_certificate':vals,'counts':{'source_vertices':3,'source_operator_edges':6,'paths_through_six_edges':len(paths),'affine_classes_with_typed_endpoints':len(classes),'central_cross_segment_circuit_equalities':2},'general_form':'For any admitted path fromu tov with counts(e,p,j), F(t)=v+E^e P^p J^j(t-u), with(v-u)/2=p+j-e. Same endpoints and counts give the same map; prime valuations show different counts cannot give the same slope.','closed_path_form':'At every one of the three source vertices, closed paths havee=p+j and multiplier(1750/1587)^p(7500/6877)^j. Distinct pivot routes with the same counts can represent the same affine map.','interpretation':'This is a reduced coordinate-affine grammar on the union of already admitted source edges. It preserves source/pivot provenance separately. Two successive E returns use different existing pivots, not the fixed-Noah double-E ladder or an extra Gear.'}