"""job 2958 triage: measure the prefix-vs-run gap on every witness certificate the corpus recorded. The engine reports `witness prefix pre(a)` = the largest m with [0, m-1] covered. Because a_p ranges over ALL residues mod p, the covered set of a+1 is the covered set of a translated by 1, so a witness whose covering also reaches below 0 certifies a LONGER run than its prefix reports. This script reads every `certificate a_p:` line out of 0017's recorded ladder + the two 83# runs, recomputes the prefix independently (it must equal the engine's own printed number -- that is the control) and measures how far the covered run extends below 0. Read-only over job2767/fresh/ (the posted 0017 package). """ import json import os import re HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.abspath(os.path.join(HERE, "..", "..", "..", "..", "..")) FRESH = os.path.join(ROOT, "job2767", "fresh") PRIMES_ALL = [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83] rank_rx = re.compile(r"^=== n=(\d+)\s+primes (\S+)") rung_rx = re.compile(r"^\s+R = (\d+)\s+(COVERABLE|REFUTED)") cert_rx = re.compile(r"^\s+certificate a_p:\s*(.+)$") def c_p(p): return (2 * pow(6, -1, p)) % p def pairs_for(primes): return [(p, c_p(p)) for p in primes] def hit(j, cert): for (p, c), a in zip(pairs_for(PRIMES_ALL[:len(cert)]), cert): if j % p == a % p or j % p == (a + c) % p: return True return False def measure(cert): pre = 0 while pre <= 4000 and hit(pre, cert): pre += 1 lo = 0 while lo > -4000 and hit(lo - 1, cert): lo -= 1 return {"prefix": pre, "run_lo": lo, "run_hi": pre - 1, "run_len": pre - lo} def scan(path, label): rows = [] n = None last_rung = None with open(path, encoding="utf-8", errors="replace") as fh: for line in fh: m = rank_rx.match(line) if m: n = int(m.group(1)) continue m = rung_rx.match(line) if m: last_rung = (int(m.group(1)), m.group(2)) continue m = cert_rx.match(line) if m: toks = m.group(1).split() cert = [int(t.split("/")[0]) for t in toks if "/" in t] if len(cert) != len(toks): continue r = measure(cert) r.update({"file": label, "n": n, "rung_line": last_rung, "classes": len(cert), "cert": cert}) rows.append(r) return rows rows = [] rows += scan(os.path.join(FRESH, "0017-ladder-n02-21.out"), "0017-ladder-n02-21.out") rows += scan(os.path.join(FRESH, "0017-ladder-n21-long.out"), "0017-ladder-n21-long.out") # the route's R = 307 certificate (return #1554, public) A307 = [1, 2, 9, 0, 4, 12, 9, 5, 29, 2, 4, 13, 31, 9, 54, 35, 56, 67, 37, 62, 33] r = measure(A307) r.update({"file": "return #1554 (route 149)", "n": 21, "rung_line": (307, "COVERABLE"), "classes": 21, "cert": A307}) rows.append(r) print("%-30s %4s %-16s %8s %6s %8s %8s" % ( "file", "n", "printed at rung", "prefix", "slack", "run_len", "pre>=rung")) for r in rows: rl = r["rung_line"] # the certificate is the witness FOUND at rung X, and 0018's Lemma 1 reads the rung off its # measured prefix, so prefix >= X is expected, not an error; the column records that. ge = "" if rl is None else ("yes" if r["prefix"] >= rl[0] else "NO") print("%-30s %4s %-16s %8d %6d %8d %8s" % ( r["file"][:30], r["n"], "%s %s" % rl if rl else "-", r["prefix"], -r["run_lo"], r["run_len"], ge)) with open(os.path.join(HERE, "prefix-vs-run.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump({"definition": "prefix = largest m with [0,m-1] covered (what the engine prints); " "run_len = length of the covered run containing position 0 " "(translation-invariant quantity, = the certified rung)", "source_files": ["job2767/fresh/0017-ladder-n02-21.out", "job2767/fresh/0017-ladder-n21-long.out", "return #1554"], "rows": rows}, fh, indent=1, sort_keys=True) fh.write("\n")