from fractions import Fraction from collections import defaultdict def fs(z):return str(z) def run(load,read,check): d=load('PREVIOUS_DATA.json');r=load('C286_DATA.json')['target_register'];comp=max(d['strong_components'],key=len);S=set(comp);adj=defaultdict(list) edges=[a for a in d['arrows'] if a['input'] in S and a['output'] in S and a['input']!=a['output']] for a in edges:adj[a['input']].append(a) cycles=[] for start in comp: def visit(vs,es): for a in adj[vs[-1]]: y=a['output'] if y==start and len(vs)>=2 and any(e['operator']=='E' for e in es+[a]): word=es+[a];s,t=Fraction(1),Fraction(0) for e in word: if e['operator']=='R':s,t=-s,2*e['anchor']-t else:s,t=25*s/23,(25*t-2*e['anchor'])/23 check('cycle_'+str(len(cycles)),s*start+t==start) cycles.append({'vertices':vs+[start],'word':word,'E_count':sum(e['operator']=='E' for e in word),'affine_slope':fs(s),'affine_intercept':fs(t),'identity':s==1 and t==0,'fixed_point':fs(t/(1-s)) if s!=1 else None}) elif y>start and y not in vs:visit(vs+[y],es+[a]) visit([start],[]) old=[c['coordinates'] for c in load('C446_DATA.json')['components'] if set(c['coordinates'])&S] return {'step':'C452','component':comp,'old_components':old,'edges':edges,'E_cycles':cycles,'source_records':[{'coordinate':x,'records':[{'index':i,**z} for i,z in enumerate(r) if z['center']==x]} for x in comp],'counts':{'vertices':len(comp),'nonloop_operator_edges':len(edges),'simple_directed_E_cycles':len(cycles)},'limits':'Cycles are canonicalized by minimum coordinate; directed reversal is a different word only when arrows exist.'}