#!/usr/bin/env python3 """Job 966: independent stdlib checker for Part B's certificates (no LP solver). Rebuilds each matrix from input.json (first 66 slots, phases (-s)%q, (-s-2)%q) and perms966.json (A'_q[s,b] = A_q[pi_q(s), b]), then from the saved rational witnesses recomputes exactly u = sum_q max_b sum_{s in K(q,b)} w_s (w >= 0 renormalised to sum 1) >= tau* l = min_s sum_{(q,b): s in K(q,b)} lambda_qb (each block renormalised to 1) <= tau* and decides every identity-vs-control comparison (u_id < l_j or u_j <= l_id). usage: python3 check966.py input.json perms966.json certs966.json """ import json, sys from fractions import Fraction as F d = json.load(open(sys.argv[1])); P = json.load(open(sys.argv[2])); C = json.load(open(sys.argv[3]))['certificates'] Q = d['Q']; slots = d['slots'][:66]; N = len(slots) base = {q: [((-s) % q, (-s - 2) % q) for s in slots] for q in Q} def matrix(tag): if tag == 'identity': return base pi = P['controls'][int(tag.split()[1]) - 1] return {q: [base[q][pi[str(q)][i]] for i in range(N)] for q in Q} def bounds(c): A = matrix(c['matrix']) w = [max(F(x), F(0)) for x in c['w']]; sw = sum(w); w = [x / sw for x in w] u = F(0) for q in Q: acc = {} for (a, b), x in zip(A[q], w): acc[a] = acc.get(a, 0) + x; acc[b] = acc.get(b, 0) + x u += max(acc.values()) lam = {} for q, b, x in c['lambda']: lam[(q, b)] = lam.get((q, b), F(0)) + max(F(x), F(0)) tot = {q: sum(v for (qq, b), v in lam.items() if qq == q) for q in Q} assert all(tot[q] > 0 for q in Q) cov = [sum(lam.get((q, a), 0) / tot[q] + (lam.get((q, b), 0) / tot[q] if b != a else 0) for q, (a, b) in ((q, A[q][i]) for q in Q)) for i in range(N)] return min(cov), u res = {c['matrix']: bounds(c) for c in C} l0, u0 = res['identity'] print("identity: %.12f <= tau* <= %.12f (T in [%.9f, %.9f])" % (l0, u0, 1 - u0, 1 - l0)) better = worse = 0 for j in range(1, 32): l, u = res['control %d' % j] b, wz = u0 < l, u <= l0 better += b; worse += wz print("control %2d: [%.9f, %.9f] identity better: %s control >= identity: %s" % (j, l, u, b, wz)) print("certified identity better %d, control >= identity %d, unresolved %d; R = %d/32" % (better, worse, 31 - better - worse, 1 + worse))