#!/usr/bin/env python3 """Independent stdlib checker for job #1090 (no numpy, no scipy, no solver). It rebuilds, from #451's maps only, the two systems and the two multipliers, and re-establishes the two exact statements this return rests on: CONTROL the OLD model (#1086: 19 common singleton vectors, independent anchor-pair joints) with #451's own integer Farkas certificate: every column combined coefficient <= 0 and the normalization multiplier sum = 288 > 0. This is what licenses the model builder, since it reproduces a published infeasibility refutation on a rebuilt model. NEGATIVE the transported reading of that certificate for the NEW model (ordinary singleton vectors split into independently normalized per-star copies, anchors common): the best achievable vector of this shape still has a strictly positive combined coefficient on at least one column, so this certificate cannot certify the relaxed system. The diagnosis is printed: the transfer needs z_norm(q,h) <= min_b z[marginal (h,q,h,q,b)] per PHASE on each side, while the old certificate only satisfies the per-prime SUM condition z_norm(q) <= sum_b z[marginal (101,q,101,q,b)] + sum_b z[marginal (103,q,103,q,b)]. Exit 0 only if the control verifies, the negative reproduces, and the artifact's recorded numbers agree. Everything is Python integers. """ import hashlib import itertools import json import sys from pathlib import Path ART = Path(sys.argv[1] if len(sys.argv) > 1 else 'ds1090.json') IN = Path('in451') MAPS = 'ef8a0916df05899f858e69bb67fa0f292b41416614ef87ad2ee9a869dbd424a1' GLOBAL = '28007cef45a1a1fc5642b207ca4c19c3325808add1a05684626e851091a40836' def load(name, sha): raw = (IN / name).read_bytes() assert hashlib.sha256(raw).hexdigest() == sha, name return json.loads(raw) mapping = load('maps1086.json', MAPS) cert = load('global1086.json', GLOBAL)['certificate'] fails = [] nchk = 0 def check(ok, label): global nchk nchk += 1 if not ok: fails.append(label) print('FAIL', label) D = mapping['slots'] Q = mapping['Q'] H = mapping['anchors'] maps = mapping['phase_maps'] size = {q: len(maps[str(q)]['representatives']) for q in Q} ordq = [q for q in Q if q not in H] # ------------------------------------------------------------------ model builders def build_model(split): """Columns, labels and entries for the old (split=False) or new (split=True) system.""" sng = {} if split: for h in H: sng[(h, None)] = None for q in ordq: for h in H: sng[(q, h)] = None else: for q in Q: sng[(q, None)] = None cursor = 0 for key in sorted(sng, key=lambda k: (k[0], -1 if k[1] is None else k[1])): sng[key] = cursor cursor += size[key[0]] blocks = {} for p, q, owner in mapping['pairs']: blocks[p, q, owner] = (cursor, size[p], size[q]) cursor += size[p] * size[q] def svar(q, owner): return sng[(q, None)] if q in H else (sng[(q, owner)] if split else sng[(q, None)]) def paircol(p, a, q, b, owner): lo, hi = sorted((p, q)) off, nlo, nhi = blocks[lo, hi, owner] return off + a * nhi + b if p == lo else off + b * nhi + a E, A, labels, rhs, cov = [], [], [], [], [] cols = cursor def eq(entries, label, value=0): r = len(rhs) for c, v in entries: E.append((r, c, v)) labels.append(label) rhs.append(value) if split: for h in H: eq([(sng[(h, None)] + a, 1) for a in range(size[h])], ['normalization', h], 1) for q in ordq: for h in H: eq([(sng[(q, h)] + a, 1) for a in range(size[q])], ['normalization_copy', q, h], 1) else: for q in Q: eq([(sng[(q, None)] + a, 1) for a in range(size[q])], ['normalization', q], 1) for p, q, owner in mapping['pairs']: sp, sq = svar(p, owner), svar(q, owner) for a in range(size[p]): eq([(paircol(p, a, q, b, owner), 1) for b in range(size[q])] + [(sp + a, -1)], ['marginal', p, q, owner, p, a]) for b in range(size[q]): eq([(paircol(q, b, p, a, owner), 1) for a in range(size[p])] + [(sq + b, -1)], ['marginal', p, q, owner, q, b]) killing = {q: [[a for a, hit in enumerate(maps[str(q)]['kill_indices']) if i in hit] for i in range(len(D))] for q in Q} for h in H: for a, hit in enumerate(maps[str(h)]['kill_indices']): for i in range(len(D)): if i in hit: continue r = len(cov) cov.append([h, a, i]) A.append((r, sng[(h, None)] + a, -1)) for q in Q: if q != h: for b in killing[q][i]: A.append((r, paircol(h, a, q, b, h), 1)) return cols, E, A, labels, cov def combined(ncols, E, A, y, z): coef = [0] * ncols for r, c, v in E: # multiplier is per ROW, so index z by r (not by position) if z[r]: coef[c] += z[r] * v for r, c, v in A: if y[r]: coef[c] += y[r] * v return coef # ------------------------------------------------------------------ control on the OLD model cols_o, E_o, A_o, lab_o, cov_o = build_model(split=False) check(len(A_o) > 0 and len(cov_o) == len(cert['inequality_multipliers']), 'old conditioned arity') check(len(lab_o) == len(cert['equality_multipliers']), 'old equality arity') y_o = cert['inequality_multipliers'] z_o = cert['equality_multipliers'] co = combined(cols_o, E_o, A_o, y_o, z_o) rhs_o = sum(z_o[i] for i, L in enumerate(lab_o) if L[0] == 'normalization') check(max(co) <= 0, 'control: every combined coefficient <= 0 (max=%d)' % max(co)) check(rhs_o == 288 and rhs_o > 0, 'control: RHS 288 > 0 (got %d)' % rhs_o) check(cols_o == 106599, 'control: 106599 columns (got %d)' % cols_o) # ------------------------------------------------------------------ the NEW model and the transport cols_n, E_n, A_n, lab_n, cov_n = build_model(split=True) z_n = [0] * len(lab_n) norm_old, marg_old = {}, {} for i, L in enumerate(lab_o): if L[0] == 'normalization': norm_old[L[1]] = z_o[i] else: marg_old[tuple(L)] = z_o[i] sum_by = {} phase_by = {} for L, v in marg_old.items(): _, p, q, owner, endpoint, a = L if endpoint in ordq: sum_by[(endpoint, owner)] = sum_by.get((endpoint, owner), 0) + v phase_by.setdefault((endpoint, owner), []).append(v) split = {} for i, L in enumerate(lab_n): if L[0] == 'normalization': z_n[i] = norm_old[L[1]] elif L[0] == 'marginal': z_n[i] = marg_old[tuple(L)] else: q, h = L[1], L[2] if q not in split: zn, h0, h1 = norm_old[q], min(H), max(H) split[q] = {h0: min(zn, sum_by.get((q, h0), 0))} split[q][h1] = zn - split[q][h0] z_n[i] = split[q][h] cn = combined(cols_n, E_n, A_n, y_o, z_n) rhs_n = sum(z_n[i] for i, L in enumerate(lab_n) if L[0] in ('normalization', 'normalization_copy')) check(cols_n == 107572, 'new: 107572 columns (got %d)' % cols_n) check(len(lab_n) == 3939, 'new: 3939 equalities (got %d)' % len(lab_n)) check(rhs_n == 288, 'transport: RHS still 288 (got %d)' % rhs_n) check(max(cn) > 0, 'NEGATIVE: the transported certificate FAILS on the new model (max=%d)' % max(cn)) # the diagnosis: per-phase vs per-sum requirement, and the best possible split by sum gaps = [] for q in ordq: zn = norm_old[q] m1 = min(phase_by.get((q, min(H)), [0])) m2 = min(phase_by.get((q, max(H)), [0])) gaps.append([q, zn, sum_by.get((q, min(H)), 0), sum_by.get((q, max(H)), 0), m1, m2, zn - (m1 + m2)]) check(min(g[6] for g in gaps) > 0, 'no per-phase split exists for any ordinary prime (min over primes of z_norm - m1 - m2 = %d)' % min(g[6] for g in gaps)) # ------------------------------------------------------------------ artifact agreement art = json.loads(ART.read_text(encoding='utf-8')) check(art['control']['certificate_verifies'] is True, 'artifact control flag') check(art['control']['max_combined_coefficient'] == max(co), 'artifact control max coefficient') check(art['control']['normalization_multiplier_sum'] == rhs_o, 'artifact control RHS') check(art['split_feasibility']['variables'] == cols_n and art['split_feasibility']['equalities'] == len(lab_n), 'artifact new dimensions') print('old model: %d columns, %d equalities, %d conditioned rows, arrow %d, max coef %d, RHS %d' % (cols_o, len(lab_o), len(cov_o), len(A_o), max(co), rhs_o)) print('new model: %d columns, %d equalities, %d conditioned rows, %d nonzeros' % (cols_n, len(lab_n), len(cov_n), len(A_n) + len(E_n))) print('transported certificate: max combined coefficient %d, RHS %d -> %s' % (max(cn), rhs_n, 'VALID' if max(cn) <= 0 and rhs_n > 0 else 'INVALID')) print('per-ordinary-prime reason (z_norm, side sums, side phase minima, deficit):') for g in gaps: print(' q=%3d z_norm=%7d sums=(%7d,%7d) phase_min=(%7d,%7d) deficit=%6d' % tuple(g)) print('checks: %d, failures: %d' % (nchk, len(fails))) print('CHECKER', 'PASS' if not fails else 'FAIL') raise SystemExit(0 if not fails else 1)