#!/usr/bin/env python3 """Stdlib checker for job #1291 (route 8): is cert1291.json an exact integer Farkas certificate for the frozen split-D51 system { w >= 0 : E w = f, A w >= 0 }? It does not reimplement the model. It executes #453's pinned checker check1090.py (sha256 a73e2921...) verbatim up to its own marker "control on the OLD model": that prefix loads #451's maps (sha-pinned) and defines build_model() and combined(). check1090.py has no input for a new split-model certificate (it checks #451's control and the failed transport only), so this file adds the one missing call: build_model(split=True), then combined() on the new multipliers. Certificate: y >= 0 on conditioned rows, z free on equality rows, every combined column coefficient (A^T y + E^T z)_j <= 0 and f.z = sum of z on normalization rows > 0. Then f.z = z^T E w <= -y^T A w <= 0 for any feasible w, a contradiction. Also runs three damaged copies that must be rejected. No numpy, no scipy, no solver. Usage: python3 check1291.py [cert1291.json] (needs check1090.py and in451/ alongside) """ import hashlib, json, sys from pathlib import Path CHECK1090 = 'a73e29212b0da4519d7024e8f19b8fd84c4fe555e37dceda8f231aa07da3655e' MARK = '# ------------------------------------------------------------------ control on the OLD model' src = Path('check1090.py').read_bytes() assert hashlib.sha256(src).hexdigest() == CHECK1090, 'check1090.py sha256' text = src.decode('utf-8') assert text.count(MARK) == 1 ns = {'__name__': 'check1090_prefix'} exec(compile(text.split(MARK)[0], 'check1090.py[prefix]', 'exec'), ns) build_model, combined = ns['build_model'], ns['combined'] cpath = Path(sys.argv[1] if len(sys.argv) > 1 else 'cert1291.json') craw = cpath.read_bytes() cert = json.loads(craw) assert cert['maps_sha256'] == ns['MAPS'] cols, E, A, labels, cov = build_model(split=True) fails = [] def check(ok, label): print(('ok ' if ok else 'FAIL ') + label) if not ok: fails.append(label) check(cols == 107572 and len(labels) == 3939 and len(cov) == 5091, 'split model dims: %d columns, %d equalities, %d conditioned rows' % (cols, len(labels), len(cov))) check([list(L) for L in labels] == cert['equality_labels'], 'equality row labels match certificate order') check([list(L) for L in cov] == cert['conditioned_labels'], 'conditioned row labels match certificate order') y, z = cert['inequality_multipliers'], cert['equality_multipliers'] check(all(isinstance(t, int) for t in y + z), 'all multipliers are integers') check(len(y) == len(cov) and len(z) == len(labels), 'multiplier arity') def judge(y, z): coef = combined(cols, E, A, y, z) rhs = sum(z[i] for i, L in enumerate(labels) if L[0] in ('normalization', 'normalization_copy')) return max(coef), rhs, min(y), sum(1 for c in coef if c == 0) mx, rhs, ymin, zeros = judge(y, z) check(ymin >= 0, 'y >= 0 (min %d)' % ymin) check(mx <= 0, 'every combined column coefficient <= 0 (max %d, %d columns at exactly 0)' % (mx, zeros)) check(rhs > 0, 'normalization multiplier sum f.z = %d > 0' % rhs) valid = ymin >= 0 and mx <= 0 and rhs > 0 # damaged copies: each must be rejected j = max(range(len(y)), key=lambda r: y[r]) y1 = list(y); y1[j] = -1 d1 = judge(y1, z); check(d1[2] < 0, 'damage 1 (a y entry set to -1) rejected by y >= 0') z2 = [-t for t in z] d2 = judge(y, z2); check(not (d2[0] <= 0 and d2[1] > 0), 'damage 2 (z negated) rejected') y3 = [0] * len(y) d3 = judge(y3, z); check(not (d3[0] <= 0 and d3[1] > 0), 'damage 3 (y zeroed) rejected (max %d)' % d3[0]) # control 4: undo #562's shift (z + delta u). The plain S1 rounding must be rejected, so the # shift is what makes the certificate, and u1111.json must satisfy f.u = 108. U_SHA = '896ea25a40195b554a3ea35242dc40ebafcfd48a0cde4e1797e09766f291968e' if Path('u1111.json').exists(): uraw = Path('u1111.json').read_bytes() check(hashlib.sha256(uraw).hexdigest() == U_SHA, 'u1111.json sha256') u = json.loads(uraw)['u'] fu = sum(u[i] for i, L in enumerate(labels) if L[0] in ('normalization', 'normalization_copy')) check(fu == 108 and min(u) >= 0, 'u >= 0 and f.u = %d' % fu) delta = cert['shift_delta'] z4 = [z[i] + delta * u[i] for i in range(len(z))] d4 = judge(y, z4) check(d4[0] > 0 and d4[1] == rhs + delta * fu, 'control 4 (unshifted S1 rounding, z + %d u) rejected: max %d, f.z %d' % (delta, d4[0], d4[1])) print(json.dumps({'certificate_sha256': hashlib.sha256(craw).hexdigest(), 'columns': cols, 'equalities': len(labels), 'conditioned_rows': len(cov), 'max_combined_coefficient': mx, 'zero_columns': zeros, 'normalization_multiplier_sum': rhs, 'verdict': 'EXACT_FARKAS_SPLIT_D51_INFEASIBLE' if valid else 'NOT_A_CERTIFICATE', 'failures': len(fails)}, sort_keys=True)) raise SystemExit(0 if not fails else 1)