from fractions import Fraction as Q from collections import defaultdict def run(load,check): d=load('C378_DATA.json');groups=defaultdict(list) for f in d['fields']: for h in f['hits']: full=None if f['field']=='cumulative' else d['menus']['regular'][h['input_record_indices'][0]]['full430'] groups[f['field'],full].append(h) paths=[];squares=[] for (field,full),edges in groups.items(): outgoing={h['input']:h for h in edges};incoming={h['output']:h for h in edges} check('source graph has unique successors '+str((field,full)),len(outgoing)==len(incoming)==len(edges)) starts=sorted(set(outgoing)-set(incoming));covered=[] for start in starts: es=[];vertices=[start];seen=set();x=start while x in outgoing: assert x not in seen;seen.add(x);e=outgoing[x];es.append(e);covered.append(e['input']);x=e['output'];vertices.append(x) h=es[0]['signed_scale'];name=str((field,full,start)) check('uniform finite source step '+name,all(e['signed_scale']==h and e['output']-e['input']==h for e in es)) for t,e in enumerate(es): check('moving source gap normal form '+str((field,full,start,t)),e['input']-e['J_pivot']==299*h and e['input']-e['P_pivot']==69*h) if t: prev=es[t-1] check('pivot shift is common gain '+str((field,full,start,t)),e['J_pivot']-prev['J_pivot']==e['P_pivot']-prev['P_pivot']==e['input']-prev['input']==h) fixedJ=prev['J_pivot']+Q(300,299)*(e['input']-prev['J_pivot']);fixedP=prev['P_pivot']+Q(70,69)*(e['input']-prev['P_pivot']) check('fixed-pivot iteration misses next source '+str((field,full,start,t)),fixedJ-e['output']==Q(h,299) and fixedP-e['output']==Q(h,69)) squares.append({'field':field,'full430':full,'first_edge':prev,'second_edge':e,'common_gain':h,'fixed_J_error_from_next_source':str(Q(h,299)),'fixed_P_error_from_next_source':str(Q(h,69))}) paths.append({'field':field,'full430':full,'source_vertices':vertices,'edges':es,'edge_count':len(es),'signed_step':h,'net_coordinate_change':vertices[-1]-vertices[0],'next_source_edge_exists':x in outgoing}) check('all source edges covered exactly once '+str((field,full)),sorted(covered)==sorted(outgoing)) check('four maximal source paths',len(paths)==4 and sorted((p['field'],p['edge_count']) for p in paths)==[('cumulative',3),('cumulative',3),('regular',2),('regular',2)]) check('six consecutive edge pairs',len(squares)==6) return {'step':'C380','paths':paths,'consecutive_edge_pairs':squares,'counts':{'maximal_source_paths':4,'cumulative_max_edges':3,'regular_max_edges':2,'common_coordinate_edges':sum(p['edge_count'] for p in paths),'consecutive_edge_pairs':len(squares)},'interpretation':'The finite source edges compose only when both Flood pivots move by the same signed gain as the input. Cumulative paths step backwards2 within the eight annual Shem members; regular paths advance2 through Gears1,2,3 in each of the two full430 branches. These are source paths through a moving family of comparisons, not repeated application at fixed pivots or permission to extend the source domains.'}