#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 90 triage: is the recorded n = 25 plateau's residual actually closable? QUESTION. Route 90's next experiment is an EXACT residual-hole repair on the plateau return #1098 recorded, and its weakest unproved assumption is that a residual hole set left by a local maximiser is closable over a small subset of the large primes. This measures that assumption on the recorded state, before a new 2 CPU-h run is funded. OBJECT (A144311, verbatim from the project's own standalone verifier verify-2043.py): "there exist L consecutive integers, each equal to 1 or -1 modulo at least one of the first n primes". A STATE is a residue tuple a_p; offset i is COVERED iff (a_p + i) mod p in {1, p-1} for some p. Class 0 (divisible by p) is NOT the object: using it yields 285 holes where the record says 3. Repair move: reassign a_p -> (c - h) mod p, which makes that prime cover offset h with class c and loses its old coverage. An offset becomes a hole only if EVERY prime that covered it was moved and none of the moves covers it -- so the search looks at offsets grouped by their coverer mask, which is small. This is a BOUNDED SEARCH, not an impossibility proof: a failure is a measured statement about how far depth K reaches, never about existence. Usage: python triage90-residual.py [level] [--depth K] """ import itertools import json import sys from collections import defaultdict PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107] def classes(p): return (1,) if p == 2 else (1, p - 1) def masks_and_cov(residues, n, R): P, cls = PRIMES[:n], [classes(p) for p in PRIMES[:n]] masks = [0] * R for k in range(n): p, a, bit = P[k], residues[k], 1 << k for c in cls[k]: for i in range((c - a) % p, R, p): masks[i] |= bit return masks def holes_of(masks): return [i for i, m in enumerate(masks) if m == 0] def best_run(masks): best = cur = 0 for m in masks: if m: cur += 1 best = max(best, cur) else: cur = 0 return best def covers(k, r, i): p = PRIMES[k] return (r + i) % p in classes(p) def repair(residues, n, R, depth): masks = masks_and_cov(residues, n, R) holes = holes_of(masks) if not holes: return residues[:], holes, {"note": "already covered"}, [] # group offsets by coverer mask; only groups inside the moved set can become holes by_mask = defaultdict(list) for i, m in enumerate(masks): by_mask[m].append(i) # candidate (prime, new residue, class) assignments that cover a given hole def cand_for(h): out = [] for k in range(n): for c in classes(PRIMES[k]): out.append((k, (c - h) % PRIMES[k])) return out cands = [cand_for(h) for h in holes] trials = [] for d in range(1, min(depth, len(holes)) + 1): # pick d holes to assign, then d distinct (prime,residue) moves covering them for chosen in itertools.combinations(range(len(holes)), d): for assign in itertools.product(*[cands[i] for i in chosen]): if len({k for k, _ in assign}) != d: continue moves = dict(assign) # every hole must be covered by some move uncovered = [h for h in holes if not any(covers(k, r, h) for k, r in moves.items())] if uncovered: continue smask = 0 for k in moves: smask |= 1 << k bad = [] for m, offsets in by_mask.items(): if m == 0 or (m & ~smask): continue # some unmoved prime still covers these for i in offsets: if not any(covers(k, r, i) for k, r in moves.items()): bad.append(i) break trials.append((len(bad), tuple(sorted(moves)), tuple(sorted(moves.values())))) if not bad: newres = residues[:] for k, r in moves.items(): newres[k] = r return newres, holes, {"depth": d, "moved_primes": [PRIMES[k] for k in sorted(moves)], "new_residues": {str(PRIMES[k]): r for k, r in moves.items()}}, trials return None, holes, {"depth_searched": depth, "moves_tried": len(trials), "best_tried_holes_left": sorted({t[0] for t in trials})[:5], "examples": [{"holes_left": t[0], "primes": [PRIMES[k] for k in t[1]]} for t in sorted(trials)[:3]]}, trials def main(): target = sys.argv[1] level = "n25" rest = sys.argv[2:] if rest and not rest[0].startswith("--"): level = rest[0] depth = 3 if "--depth" in sys.argv: depth = int(sys.argv[sys.argv.index("--depth") + 1]) d = json.load(open(target, encoding="utf-8")) rec = d["levels"][level] n = int(level[1:]) residues = [int(v) for v in rec["residues"][:n]] out = {"level": level, "n": n, "recorded_best_run": rec.get("best_run_in_best_state"), "recorded_bracket": rec.get("bracket"), "reproduction": [], "repair": []} for t in rec.get("trials") or []: R = int(t["R"]) masks = masks_and_cov(residues, n, R) h, b = holes_of(masks), best_run(masks) out["reproduction"].append({"R": R, "holes": len(h), "holes_recorded": t.get("holes"), "best_run": b, "best_run_recorded": t.get("best_run_in_state"), "matches": bool(len(h) == t.get("holes") and b == t.get("best_run_in_state")), "hole_offsets": h[:8]}) print(json.dumps(out["reproduction"], indent=1)) for t in sorted(rec.get("trials") or [], key=lambda x: -int(x["R"])): R = int(t["R"]) newres, holes, info, _ = repair(residues, n, R, depth) rec_out = {"R": R, "holes": len(holes), "hole_offsets": holes[:8], "result": info} out["repair"].append(rec_out) print("R=%d holes=%d -> %s" % (R, len(holes), json.dumps(info)[:400])) if newres: out["repaired_residues_%d" % R] = newres with open(target.replace(".out.json", "") + ".triage90.json", "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1) print("wrote", target.replace(".out.json", "") + ".triage90.json") if __name__ == "__main__": main()