"""Independent check of every fixed-N set union and its exact fit. Published members and N_F records are inputs, not regenerated frontiers. Their slot admissibility is checked directly; all new kill occupancies use matrices, not the producer's Counter path. Rational intercept weights independently check the producer's normal-equation fit and the specified 0.01 threshold. """ from fractions import Fraction as F import hashlib import itertools import json from pathlib import Path import resource import sys import numpy as np resource.setrlimit(resource.RLIMIT_CPU, (40,45)) SOURCE_SHA = '7af3975eef682ce6d26883f499c9feaa8db01bff03e4d922b0d7a6e59a5fb7da' source = Path(sys.argv[2] if len(sys.argv)>2 else 'union1088-v2.json').read_bytes() target = json.loads(Path(sys.argv[1] if len(sys.argv)>1 else 'fixed1094.json').read_text()) count = 0 def check(ok,label): global count count += 1 if not ok: print('FAIL',label) raise SystemExit(1) def prime(n): d = 2 while d*d<=n: if n%d==0: return False d += 1 return n>=2 check(hashlib.sha256(source).hexdigest()==SOURCE_SHA==target['source_sha256'],'source hash') src = json.loads(source) starts = [10007,20011,40009,60013,80021,100003,120011,140009] check(target['job']==1094 and target['route_id']==13 and target['prime']==223,'job/domain') check(target['global_N']==143 and target['starts']==starts,'global N and starts') qs = [q for q in range(224,447) if prime(q)] old = [p for p in range(2,224) if prime(p)] check(target['Q']==qs and all(q>2 for q in qs),'prime band') parts = {} for a in starts: D = src['member_slots']['223:%d'%a] check(D==sorted(set(D)) and len(D)>=143,'source member ordering') check(all(a<=s0 check(f1>0,'strict uniform inequality') ref = reference[combo] check(rec['source_common_N']==ref['common_N'] and rec['source_F1']==ref['F1_union'] and rec['source_U_sha256']==ref['U_sha256'],'reported reference row') same = ref['U_sha256']==sha check(rec['reused'] is same and rec['F1_change']==f1-ref['F1_union'],'reuse and effect') if same: check(f1==ref['F1_union'],'identical source union') reused += 1 mins[str(k)] = min(mins.get(str(k),f1),f1) check(target['min_F1_by_k']==mins,'new minima') old_mins = src['fit']['223']['F1_union_min_by_k'] check(target['reference_min_F1_by_k']==old_mins,'reported reference minima') xx = [F(1,k) for k in range(2,9)] sx,sxx = sum(xx),sum(x*x for x in xx) hh = [(sxx-sx*x)/(7*sxx-sx*sx) for x in xx] check(sum(hh)==1 and sum(h*x for h,x in zip(hh,xx))==0,'intercept weights') def rational_fit(minima): yy = [F(minima[str(k)],k) for k in range(2,9)] c = sum(h*y for h,y in zip(hh,yy)) d = (sum(yy)-7*c)/sx check(sum(x*(y-c-d*x) for x,y in zip(xx,yy))==0,'second normal equation') return c,d,max(abs(y-c-d*x) for x,y in zip(xx,yy)) c,d,res = rational_fit(mins) old_c,old_d,old_res = rational_fit(old_mins) nf = F(sum(m['N_F'] for m in src['members'] if m['p']==223),8) check(nf==F(1213,8),'reported N_F mean') values={'c_exact':c,'d_exact':d,'max_residual_exact':res,'reference_c_exact':old_c, 'reference_NF_mean_exact':nf,'c_over_reference_NF_mean_exact':c/nf, 'reference_c_over_NF_mean_exact':old_c/nf,'coefficient_change_exact':(c-old_c)/nf} for name,value in values.items(): check(target['fit'][name]==[value.numerator,value.denominator],'canonical fraction '+name) check(abs(float(old_c)-src['fit']['223']['per_k_vs_inv_k_intercept'])<1e-9,'published c precision') delta = (c-old_c)/nf summary={'unions':247,'reused_unions':reused,'changed_unions':247-reused, 'all_positive':all_positive,'threshold_exact':[1,100], 'within_threshold':abs(delta)<=F(1,100), 'assigned_success':all_positive and abs(delta)<=F(1,100)} check(target['summary']==summary,'summary and threshold outcome') print('fixed N143: 247 true set unions, reused %d, shortened %d, all strict ratios pass'%(reused,247-reused)) print('min F1 by k2..8: %s'%[mins[str(k)] for k in range(2,9)]) print('reported N_F mean: 1213/8; no frontier regeneration') print('c/mean N_F=%s = %.12f; reference=%s = %.12f'%(str(c/nf),float(c/nf),str(old_c/nf),float(old_c/nf))) print('absolute coefficient change=%s = %.12f; threshold=1/100; passes=%s'%(str(abs(delta)),float(abs(delta)),summary['assigned_success'])) print('checks: %d, failures: 0'%count) print('CHECKER PASS')