#!/usr/bin/env python3 """Route 21, job #1297 — DISCLOSED FOLLOW-UP to the preregistered instance. The preregistered window (start 1000000) gave delta* = -17/485 < 0. This script asks whether that negative is generic for p=43/N=20 or an artifact of one declared window, by scanning declared window starts, ranking by the occupancy obstruction, and running the same exact rational LP on the best candidates. Same code path as route21_band_margin.py (imported, not reimplemented). This is a scan, not a preregistered single instance; it is reported as such. """ from fractions import Fraction as F import json, sys, time sys.path.insert(0, ".") from route21_band_margin import (primes_upto, owners, build_support, killset_indices, capacities, simplex, N_SLOTS, P_BAND, R_BAND) Q43, Q47 = owners(P_BAND), owners(R_BAND) def occupancy(slots, qs): return {q: max(len(killset_indices(slots, q, c)) for c in range(q)) for q in qs} def solve_delta(slots, qs): """max delta = sum w - sum_q C_q s.t. sum w = 1, w >= 0. Exact.""" nq, n = len(qs), len(slots) nvar = n + nq rows = [] for qi, q in enumerate(qs): seen = set() for c in range(q): ks = tuple(killset_indices(slots, q, c)) if not ks or ks in seen: continue seen.add(ks) r = [F(0)] * nvar for i in ks: r[i] = F(1) r[n + qi] = F(-1) rows.append(r) npair = len(rows) A = [r + [F(1) if j == k else F(0) for j in range(npair)] for k, r in enumerate(rows)] A.append([F(1)] * n + [F(0)] * (nq + npair)) rhs = [F(0)] * npair + [F(1)] obj = [F(1)] * n + [F(-1)] * nq + [F(0)] * npair val, x = simplex(A, rhs, obj) return val, [x[i] for i in range(n)], npair def fold_profile(slots, w, delta, cq): prof = [] for c in range(R_BAND): E = killset_indices(slots, R_BAND, c) wE = sum(w[i] for i in E) live = [i for i in range(len(slots)) if i not in E] cp = capacities(slots, w, Q47, restrict=live) margin = (F(1) - wE) - sum(cp[q][0] for q in Q47) ident = (delta + cq[R_BAND][0] - wE + sum(cq[q][0] - cp[q][0] for q in Q43 if q != R_BAND) - cp[89][0]) prof.append({"phase": c, "deleted": len(E), "w_E": str(wE), "C_prime_89": str(cp[89][0]), "margin": str(margin), "margin_float": float(margin), "identity_holds": ident == margin}) return prof def main(): t0 = time.time() starts = list(range(1000000, 1000000 + 400000, 20000)) # 20 declared windows rep = {"scan": {"rule": "same support rule, declared window starts", "starts_tried": starts, "N": N_SLOTS, "band": "43->47"}} # cheap rank: uniform-weight delta = N - sum_q occ_q (necessary-ish filter) cands = [] for s in starts: sl = build_support(s, N_SLOTS, P_BAND) occ = occupancy(sl, Q43) cands.append({"start": s, "L": sl[-1] - sl[0] + 1, "occ": occ, "sum_occ": sum(occ.values()), "uniform_delta": N_SLOTS - sum(occ.values()), "slots": sl}) cands.sort(key=lambda c: c["sum_occ"]) rep["scan"]["occupancy_table"] = [ {"start": c["start"], "L": c["L"], "sum_occ": c["sum_occ"], "uniform_delta": c["uniform_delta"]} for c in cands] # exact LP on the most promising windows results = [] for c in cands[:6]: val, w, npair = solve_delta(c["slots"], Q43) r = {"start": c["start"], "L": c["L"], "sum_occ": c["sum_occ"], "pair_rows": npair, "delta_star": str(val), "delta_star_float": float(val)} if val > 0: cq = capacities(c["slots"], w, Q43) prof = fold_profile(c["slots"], w, val, cq) ms = [F(p["margin"]) for p in prof] pos = [p for p in prof if F(p["margin"]) > 0] r["witness"] = { "slots": c["slots"], "w_exact": [str(v) for v in w], "C_q": {str(q): str(cq[q][0]) for q in Q43}, "sum_C": str(sum(cq[q][0] for q in Q43)), "C_47_returned": str(cq[R_BAND][0])} r["fold"] = { "identity_holds_every_phase": all(p["identity_holds"] for p in prof), "phases": R_BAND, "positive_phases": len(pos), "min_margin": str(min(ms)), "max_margin": str(max(ms)), "best_phase": max(prof, key=lambda p: F(p["margin"]))["phase"], "C89_min": str(min(F(p["C_prime_89"]) for p in prof)), "C89_max": str(max(F(p["C_prime_89"]) for p in prof)), "profile": prof} results.append(r) rep["scan"]["results"] = results rep["outcome"] = "witness found at start=%d, delta*=%s" % (c["start"], val) rep["seconds"] = round(time.time() - t0, 2) print(json.dumps(rep, indent=1, default=str)) return 0 results.append(r) rep["scan"]["results"] = results rep["outcome"] = "no window among those tried admits delta > 0" rep["seconds"] = round(time.time() - t0, 2) print(json.dumps(rep, indent=1, default=str)) return 0 if __name__ == "__main__": sys.exit(main())