from fractions import Fraction as F from itertools import product def run(load,check): ratio=F(300,299);eps=[F(-1,4),F(1,4)];reg=load('C286_DATA.json')['target_register'];trials=[] for x in load('C344_DATA.json')['rows']: m,r=x['M']['center'],x['R']['center'];primary=x['rail']=='primary' for held in ['Flood','Noah']: role='Noah birth' if held=='Flood' else x['R']['role'];g=x['R']['gear'] if held=='Flood' else x['M']['gear'];targets=[z for z in reg if z['tradition']=='MT' and z['role']==role and z['gear']==g and z['Cainan']==z['Terah60']==z['full430']==1];check(f'i{x["i"]}/{held} target',len(targets)==1);target=targets[0]['center'] for em,er,et in product(eps,repeat=3): me,re=F(m)+em,F(r)+er;out=re+ratio*(me-re) if held=='Flood' else me-ratio*(me-re);ok=out==target+et check(f'i{x["i"]}/{held}/{em}/{er}/{et}',ok==(primary and em==er==et)) trials.append({'i':x['i'],'rail':x['rail'],'held':held,'phases':list(map(str,[em,er,et])),'input_gap':str(me-re),'output':str(out),'actual_target':str(target+et),'residual':str(out-target-et),'exact':ok}) check('64 combinations and8 exact',len(trials)==64 and sum(x['exact'] for x in trials)==8) check('companion fails all',not any(x['exact'] for x in trials if x['rail']=='companion')) check('physical phase separation',ratio*F(1,2)-F(1,2)==F(1,598)) return {'step':'C348','trials':trials,'counts':{'phase_combinations':64,'exact_primary':8,'exact_companion':0},'single_affine_half_year_error':'1/598','center_fixed_primary_component_errors':['-1/1196','1/1196'],'interpretation':'Both held-endpoint repairs require matching existing components. No rounding, added phase or residue-year model is used.'}