#!/usr/bin/env python3 """Job 2821: verify the witnesses, then build the block table from the JSON the engines wrote. Two jobs, both mechanical: 1. WITNESS CHECK (third language, direct integer arithmetic). For every level the engines report, re-derive from the raw integers that each witness entry r is a level-s slot (gcd(r,P) = gcd(r+2,P) = 1), is killed by a prime of Q(s) (r or r+2 divisible by it), and that consecutive witness entries are consecutive slots (no slot of the level strictly between them). A witness of length K proves K*(s) >= K, independently of how the engine found it. 2. BLOCK TABLE. For each block [p_k, p_{k+1}) build K*(p_k) the first rung of the block K*(p_{k+1}-1) the last rung (pre-boundary) K*(p_{k+1}) the next block's first rung D_k = K*(p_{k+1}) - K*(p_k) the route's ladder statistic delta = K*(p_{k+1}) - K*(p_{k+1}-1) the boundary transfer gain = K*(p_{k+1}-1) - K*(p_k) the interior gain E_k = pi(2p_{k+1}-2) - pi(2p_k) the interior entries the corrected corollary allows and the identity D_k = gain + delta, the corollary's guarantee gain >= E_k, and the decisive comparison delta vs -E_k (the corrected corollary ALONE stops guaranteeing a growing ladder exactly when delta < -E_k). python ladder-table.py [ ...] """ import glob import io import json import math import os import sys def primes_upto(n): return [m for m in range(2, n + 1) if all(m % d for d in range(2, int(math.isqrt(m)) + 1))] def load(paths): vals = {} for p in paths: d = json.load(io.open(p, encoding="utf-8")) for r in d.get("rows", []): if not r.get("refused"): vals[r["s"]] = r return vals def check_witness(row): """Return (ok, note). Checks slotsness, kill, and slot-consecutiveness of the whole witness.""" P, Q, s = row["P"], row["Q"], row["s"] w = row.get("witness") or [] if not w: return False, "no witness" for e in w: r = e["r"] if math.gcd(r, P) != 1 or math.gcd(r + 2, P) != 1: return False, "r=%d is not a level-%d slot" % (r, s) if not any(r % q == 0 or (r + 2) % q == 0 for q in Q): return False, "r=%d is not killed by Q(%d)" % (r, s) if e.get("isSlot") is False: return False, "engine itself reports r=%d not a slot" % r # consecutive SLOTS: between two witness entries there must be no level-s slot for a, b in zip(w, w[1:]): for r in range(a["r"] + 1, b["r"]): if math.gcd(r, P) == 1 and math.gcd(r + 2, P) == 1: return False, "slot %d lies between witness entries %d and %d" % (r, a["r"], b["r"]) if len(w) != row["K"]: return False, "witness length %d != K* %d" % (len(w), row["K"]) return True, "length %d, all slots, all killed, consecutive" % len(w) def main(): paths = sys.argv[1:] or sorted(glob.glob("job2821/kstar-*.json")) vals = load(paths) print("== witness check (independent integer arithmetic) ==") out = {"source_files": paths, "witness": {}, "blocks": []} for s in sorted(vals): ok, note = check_witness(vals[s]) out["witness"][str(s)] = {"ok": ok, "note": note, "K": vals[s]["K"]} print(" s=%-3d K*=%-4d %s %s" % (s, vals[s]["K"], "OK " if ok else "FAIL", note)) print("\n== exact K*(s) on record, from these runs ==") for s in sorted(vals): print(" s=%-3d P=%-9d Q=%-24s K*=%d" % (s, vals[s]["P"], str(vals[s]["Q"]), vals[s]["K"])) print("\n== block table ==") pr = primes_upto(60) hdr = ("block K*(p_k) K*(p+1-1) K*(p_next) D_k delta gain E_k " "gain>=E_k? delta<-E_k?") print(hdr) for p, nx in zip(pr, pr[1:]): if p not in vals or (nx - 1) not in vals or nx not in vals: continue k0, pre, k1 = vals[p]["K"], vals[nx - 1]["K"], vals[nx]["K"] D, delta, gain = k1 - k0, k1 - pre, pre - k0 E = len(primes_upto(2 * nx - 2)) - len(primes_upto(2 * p)) row = {"block": p, "K_at_p_k": k0, "K_pre_boundary": pre, "K_at_p_next": k1, "D_k": D, "delta": delta, "gain": gain, "E_k": E, "identity_D_eq_gain_plus_delta": D == gain + delta, "corollary_gain_ge_E": gain >= E, "delta_lt_minus_E": delta < -E} out["blocks"].append(row) print("%5d %8d %10d %11d %5d %7d %6d %5d %11s %12s" % (p, k0, pre, k1, D, delta, gain, E, row["corollary_gain_ge_E"], row["delta_lt_minus_E"])) print("\n== what each number rests on ==") print(" C1 levels 5,6,7,9,10,11 : reproduced exactly by both engines; published in #609") print(" s=12,13 : two independent traversals agree (slot enumeration + integer scan)") print(" s=15,16,17,18 : full-period slot enumeration; lower bound witnessed and checked") print(" s=19 : refused (2.9e11 slot-lift pairs), so block 17->19 is OPEN here") out["rests_on"] = { "published": [5, 6, 7, 9, 10, 11], "two_independent_traversals": [12, 13], "enumeration_with_witness": [15, 16, 17, 18], "refused": [19], } with io.open("job2821/ladder-table.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1, sort_keys=True) fh.write("\n") print("\nwrote job2821/ladder-table.json") return 0 if all(v["ok"] for v in out["witness"].values()) else 1 if __name__ == "__main__": sys.exit(main())