from fractions import Fraction as F from itertools import product def run(load,check): old=load('C322_DATA.json');rows=[];phase_rows=[];positive=[] for bio in old['biographies']: g=bio['gear'];roles=bio['roles'] for i,a in enumerate(roles): for j,c in enumerate(roles): A=bio['SP_records'][a]['center'];B=bio['MT_records'][a]['center'];C=bio['SP_records'][c]['center'];d=A-C;r=B-C tag=f'{g}/{a}/{c}' check(tag+' partition',A-B==460 and 460+r==d) row={'gear':g,'anchor_role':a,'terminal_role':c,'A_SP':A,'B_MT':B,'C_SP':C,'source_duration':d,'residual':r,'sign':'positive' if r>0 else ('zero' if r==0 else 'negative'),'records':{'A':bio['SP_records'][a],'B':bio['MT_records'][a],'C':bio['SP_records'][c]}} rows.append(row) if r>0:positive.append(row) for p,q,s in product([F(-1,4),F(1,4)],repeat=3): vals=[F(A)+p,F(B)+q,F(C)+s];ds=[vals[0]-vals[1],vals[1]-vals[2],vals[0]-vals[2]];exact=ds==[460,r,d] check(tag+str((p,q,s))+' phase criterion',exact==(p==q==s)) phase_rows.append({'gear':g,'anchor_role':a,'terminal_role':c,'phases':list(map(str,[p,q,s])),'coordinates':list(map(str,vals)),'durations':list(map(str,ds)),'exact':exact,'positive_residual':r>0}) family={} for row in positive: key=str(row['residual']);family.setdefault(key,{'source_duration':row['source_duration'],'annual_instances':0,'role_pairs':[]});family[key]['annual_instances']+=1 pair=[row['anchor_role'],row['terminal_role']] if pair not in family[key]['role_pairs']:family[key]['role_pairs'].append(pair) counts={'annual_candidates':len(rows),'positive_residuals':len(positive),'zero_residuals':sum(x['residual']==0 for x in rows),'negative_residuals':sum(x['residual']<0 for x in rows),'phase_candidates':len(phase_rows),'all_exact_partitions':sum(x['exact'] for x in phase_rows),'positive_exact_partitions':sum(x['exact'] and x['positive_residual'] for x in phase_rows)} check('counts',counts=={'annual_candidates':75,'positive_residuals':18,'zero_residuals':0,'negative_residuals':57,'phase_candidates':600,'all_exact_partitions':150,'positive_exact_partitions':36}) check('residual set',set(family)=={'40','140','490','640'}) check('six role families',sum(len(x['role_pairs']) for x in family.values())==6) return {'step':'C327','rows':rows,'positive_rows':positive,'families':family,'phase_trials':phase_rows,'counts':counts,'relation':'r=d−460; residual identities follow from the held source durations and context translation.','new_independent_witnesses':False,'E_applied':False}