--- verify1076.py +++ check1088-v2.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Independent checker for job #1076 (route 13 rev6): rebuild the run from the definitions. +"""Independent V2 checker for job #1088 (route 13 rev7), true set unions: rebuild the run from the definitions. Imports neither the producer nor the tightcert kernel. It re-derives, in its own code: * trial-division primality and the admissible-slot scan over [a, a+CAP) (s and s+2 both coprime @@ -8,7 +8,7 @@ F1 computed by an explicit q x |D| kill matrix AND by the plain integer definition sum over (q, b) of the count of killed slots; * every one of the 741 unions: recomputed from the member slot lists, sorted, truncated to the - common N = min |D_i|, with |U| = k*N, member disjointness, the sha256, F1 by the kill matrix, + common N = min |D_i|, with |U| <= k*N, duplicate removal, the sha256, F1 by the kill matrix, F1/k, the member-F1 sum, the gain, subadditivity F1_union >= sum member F1, and the strict uniform-weight inequality sum_q max_b W(q,b) < sum_s w_s with its slack equal to F1; * the per-k min/mean, the min-slack increments, the affine fit of min F1_union against k, the fit @@ -27,11 +27,12 @@ import json import math import sys +from fractions import Fraction from pathlib import Path import numpy as np -ART = Path(sys.argv[1] if len(sys.argv) > 1 else 'kfold1076.json') +ART = Path(sys.argv[1] if len(sys.argv) > 1 else 'union1088-v2.json') SRC443 = Path(sys.argv[2] if len(sys.argv) > 2 else '../job1068/kfold1068.json') CAP = 20000 PLAIN_STRIDE = 100 @@ -48,6 +49,7 @@ if not ok: fails.append(label) print('FAIL', label) + raise SystemExit(1) # Fail early so corrupted-input controls stay cheap. return ok @@ -116,6 +118,9 @@ ref = {(m['p'], m['a']): m for m in src['members']} starts = art['starts'] KMAX = len(starts) +check(art['job'] == 1088 and art['revision'] == 7, 'job/revision') +check(art['primes'] == [199, 211, 223], 'only the assigned new primes') +check(starts == [10007, 20011, 40009, 60013, 80021, 100003, 120011, 140009], 'eight published starts') # the compact artifact must carry every member's slot list, and each must match the checker's own check(sorted(art['member_slots']) == sorted('%d:%d' % (m['p'], m['a']) for m in art['members']), @@ -146,7 +151,7 @@ r = ref.get((p, a)) # #443 used exactly four starts per prime; the four added starts have no row there and must be # reported as unproved, and the four #443 starts must all be present and hash-identical - check((r is not None) == (m['a'] in art['declared_starts']), + check((r is not None) == ((p, a) in ref), 'member row presence matches the declared starts p=%d a=%d' % (p, a)) check(r is None or (r['slot_sha256'] == sha and r['N_F'] == nf and r['F1_member'] == fm), 'member proved against #443 p=%d a=%d' % (p, a)) @@ -163,18 +168,22 @@ check(rec['k'] == len(combo) == len(set(combo)), 'k matches members p=%d %s' % (p, combo)) N = min(len(mems[(p, a)]['D']) for a in combo) parts = [mems[(p, a)]['D'][:N] for a in combo] - for x, y in itertools.combinations(parts, 2): - check(not (set(x) & set(y)), 'members disjoint p=%d %s' % (p, combo)) - U = sorted(s for part in parts for s in part) - check(N == rec['common_N'] and len(U) == rec['union_size'] == rec['k'] * N, - 'union size p=%d k=%d %s' % (p, rec['k'], combo)) - check(U == sorted(parts[0] + [s for part in parts[1:] for s in part]), - 'union is the sorted concatenation p=%d k=%d' % (p, rec['k'])) + raw = sorted(s for part in parts for s in part) + U = sorted(set(raw)) + check(N == rec['common_N'] and len(U) == rec['union_size'] <= rec['k'] * N, + 'true set union size p=%d k=%d' % (p, rec['k'])) + check(rec['source_multiset_size'] == len(raw) == rec['k']*N, + 'source multiset size p=%d k=%d' % (p,rec['k'])) + check(rec['duplicates_removed'] == len(raw)-len(U), + 'deduplicated coordinates p=%d k=%d' % (p,rec['k'])) + if rec['duplicates_removed']: + check(p == 223 and f1_mask(raw,qs) == rec['source_multiset_F1'], + 'preserved multiset F1 p=%d k=%d' % (p,rec['k'])) check(hashlib.sha256(','.join(map(str, U)).encode()).hexdigest() == rec['U_sha256'], 'union sha p=%d k=%d' % (p, rec['k'])) # artifact-internal reconstruction: the compact artifact carries the member slot lists, so the # union must also be rebuildable from what the artifact itself states - Uart = sorted(s for a in combo for s in art['member_slots']['%d:%d' % (p, a)][:N]) + Uart = sorted(set(s for a in combo for s in art['member_slots']['%d:%d' % (p, a)][:N])) check(Uart == U, 'union rebuilt from the artifact member_slots p=%d k=%d' % (p, rec['k'])) f1 = f1_mask(U, qs) n_mask += 1 @@ -185,7 +194,7 @@ next(x['F1_member'] for x in art['members'] if x['p'] == p and x['a'] == a) for a in combo), 'member F1 sum p=%d k=%d' % (p, rec['k'])) check(rec['gain_over_members'] == f1 - rec['member_F1_sum'], 'gain p=%d k=%d' % (p, rec['k'])) - check(f1 >= rec['member_F1_sum'], 'subadditivity p=%d k=%d' % (p, rec['k'])) + check(f1 >= rec['member_F1_sum'], 'measured gain over full members p=%d k=%d' % (p, rec['k'])) cert = rec.get('certificate') check(rec['rule'] == 'uniform_weights', 'rule is uniform weights p=%d k=%d' % (p, rec['k'])) check(cert is not None and 'slots' not in cert and 'weights' not in cert, @@ -283,11 +292,50 @@ check(art['summary']['by_rule'] == {'uniform_weights': len(art['unions'])}, 'summary by_rule') check(art['summary']['by_k'] == {str(k): len(art['primes']) * len(list(itertools.combinations( starts, k))) for k in range(2, KMAX + 1)}, 'summary by_k') -check(art['summary']['members'] == 3 * len(starts), 'summary member count') -check(art['summary']['members_proved_against_443'] == 3 * 4, 'summary proved count') +check(art['summary']['members'] == len(art['primes']) * len(starts), 'summary member count') +check(art['summary']['members_proved_against_443'] == sum((m['p'], m['a']) in ref for m in art['members']), 'summary proved count') check(art['summary']['all_certificates_pass'] is True, 'summary certificates pass') check(art['outcome'].startswith('success:'), 'outcome string') check('inconclusive' not in art['outcome'], 'outcome is not inconclusive') + + +# Rescaling the response changes the OLS objective, not the curve family. +# NumPy weights multiply unsquared residuals, hence w=1/k implements 1/k^2. +for p in art['primes']: + f = art['fit'][str(p)] + kk = np.asarray(sorted(int(k) for k in f['F1_union_min_by_k']), dtype=float) + yy = np.asarray([f['F1_union_min_by_k'][str(int(k))] for k in kk], dtype=float) + slope, intercept = np.polyfit(kk, yy, 1, w=1 / kk) + c = f['per_k_vs_inv_k_intercept'] + d = f['per_k_vs_inv_k_slope'] + check(abs(slope - c) < 1e-9 and abs(intercept - d) < 1e-9, + 'reciprocal-response fit equals weighted raw-affine fit p=%d' % p) + check(np.max(np.abs(yy / kk - (c + d / kk))) < 1e-9 + f['per_k_vs_inv_k_max_residual'], + 'same prediction curve in rescaled coordinates p=%d' % p) + print('p=%d mean_N_F=%.6f c=%.9f c/mean_N_F=%.9f; reciprocal fit = weighted raw-affine fit' + % (p, f['N_F_mean'], c, c / f['N_F_mean'])) + +# The fitted intercept is a fixed linear functional at k=2..8. +# With positive min slack and complete subsets, 0 0) +check(ccap == Fraction(394298, 261397), 'exact positive intercept weight sum') +for p in art['primes']: + f = art['fit'][str(p)] + nm = min(m['N_member'] for m in art['members'] if m['p'] == p) + ys = [Fraction(f['F1_union_min_by_k'][str(k)], k) for k in range(2,9)] + check(all(0 < y <= nm for y in ys), 'finite positive slack range p=%d' % p) + exact_c = sum(h*y for h,y in zip(hh,ys)) + check(abs(float(exact_c)-f['per_k_vs_inv_k_intercept']) < 1e-9, + 'exact rational intercept matches finite fit p=%d' % p) + check((1-ccap)*nm <= exact_c <= ccap*nm, + 'fixed-design positive-slack intercept bound p=%d' % p) +print('fit audit: fixed-design c/mean_N_F < 394298/261397 = %.9f under positive min slack' + % float(ccap)) print('members %d, unions %d; kill-matrix paths %d, plain-Python paths %d (sample stride %d)' % (len(art['members']), len(art['unions']), n_mask, n_plain, PLAIN_STRIDE))