#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Independent checker for the job #4524 certificate (route 173, finite doubling ladder). Consumes `certificate.json` in the current directory. Stdlib + numpy + sympy only; no network; no producer code is imported (this file re-implements the tile, the cyclic maxsum, the root-capacity necessary test and the exact cover search independently, and validates that pipeline against direct physical-copy enumeration on small periods). Run: python3 check-job4524.py # prints one line per check, then "N/N checks passed" Exit 0 iff every check passed. Scope: the certificate is the 23# -> 47# finite ladder of the maxsum bridge. Nothing here bounds G2, beta_2 or twin-prime infinitude. """ import json import math import sys import numpy as np import sympy as sp CHECKS = [] def chk(name, ok, detail=""): ok = bool(ok) CHECKS.append((name, ok, detail)) print(("PASS " if ok else "FAIL ") + name + (" :: " + str(detail) if detail else "")) return ok # --------------------------------------------------------------- independent tile construction def primorial(base): """Product of all primes <= base (sympy's own primorial counts the first n primes).""" return int(sp.prod(list(sp.primerange(2, base + 1)))) def build_tile(base): """T_s by a direct numpy sieve over [0, base#): mark n with n%p==0 or (n+2)%p==0.""" W = primorial(base) bad = np.zeros(W, dtype=bool) bad[0::2] = True # 2 | W, so a twin slot is odd for p in sp.primerange(3, base + 1): bad[0::p] = True # p | n bad[(p - 2) % p::p] = True # p | n+2 a = np.flatnonzero(~bad).astype(np.int64) return a, W def cyc_gaps(a, W): g = np.empty(a.size, dtype=np.int64) g[:-1] = a[1:] - a[:-1] g[-1] = a[0] + W - a[-1] return g def cyclic_extension(a, W, m): """First m terms of the periodic extension a_i (index i free, value a_{i mod D} + floor(i/D)W).""" D = a.size idx = np.arange(D + m) return a[idx % D] + (idx // D) * W def maxsum(a, W, m): D = a.size r, sh = m % D, m // D return int((a[(np.arange(D) + r) % D] - a).max()) + sh * W # --------------------------------------------------------------- independent capacity + search def capacity_all(a, W, m, Q): """Exact root-capacity upper bound for every cyclic start (cumsum formulation). cap_i = sum_q max_t #{ j < m : a_{i+j} === t or t+2 (mod q) }, an upper bound on the number of window slots any assignment can cover; cap_i < m rules a cover out. """ D = a.size ext = cyclic_extension(a, W, m) cap = np.zeros(D, dtype=np.int64) for q in Q: r = (ext % q).astype(np.int32) best = np.zeros(D, dtype=np.int64) for t in range(q): sel = (r == t) | (r == ((t + 2) % q)) cs = np.concatenate(([0], np.cumsum(sel, dtype=np.int64))) cnt = cs[m:m + D] - cs[:D] # cnt[i] = #{ j in [i, i+m) : sel[j] } np.maximum(best, cnt, out=best) cap += best return cap, ext def has_cover(res_by_q, Q, prune=True): """Exact existence test for one window; `res_by_q[k][j] = a_{i+j} mod Q[k]`.""" m = len(res_by_q[0]) nq = len(Q) mk = [] for k, q in enumerate(Q): tab = [0] * q for j, t in enumerate(res_by_q[k]): tab[t] |= 1 << j mk.append(tab) full = (1 << m) - 1 memo = {} def rec(left, unused): if left == 0: return True if unused == 0: return False key = (left, unused) if key in memo: return memo[key] if prune: cap = 0 for k in range(nq): if (unused >> k) & 1: q = Q[k] tab = mk[k] b = 0 for t in range(q): v = ((tab[t] | tab[(t - 2) % q]) & left).bit_count() if v > b: b = v cap += b if cap < left.bit_count(): memo[key] = False return False bit = left & -left j = bit.bit_length() - 1 for k in range(nq): if not ((unused >> k) & 1): continue q = Q[k] tab = mk[k] for r in {res_by_q[k][j], (res_by_q[k][j] + 2) % q}: nl = left & ~(tab[r] | tab[(r - 2) % q]) if nl != left and rec(nl, unused & ~(1 << k)): memo[key] = True return True memo[key] = False return False return rec(full, (1 << nq) - 1) def scan_all(a, W, m, Q, stop_first=False): cap, ext = capacity_all(a, W, m, Q) surv = np.nonzero(cap >= m)[0] res = [(ext % q).astype(np.int32) for q in Q] n_cov = 0 first = None seen = 0 for i in surv: ii = int(i) seen += 1 if has_cover([r[ii:ii + m].tolist() for r in res], Q): n_cov += 1 if first is None: first = ii if stop_first: break return {"pass": int(surv.size), "checked": seen, "covers": n_cov, "first": first} # --------------------------------------------------------------- physical-copy brute force def brute_kstar(base, top): a, W = build_tile(base) Q = [int(p) for p in sp.primerange(base + 1, top + 1)] reps = 1 for q in Q: reps *= q assert a.size * reps <= 4_000_000 pos = np.concatenate([a + c * W for c in range(reps)]) killed = np.zeros(pos.size, dtype=bool) for q in Q: killed |= (pos % q == 0) | ((pos + 2) % q == 0) if killed.all(): return int(pos.size), Q, a, W idx = np.nonzero(~killed)[0] D = pos.size best = 0 for t in range(idx.size): s, e = int(idx[t]), int(idx[(t + 1) % idx.size]) best = max(best, (e - s - 1) % D) return best, Q, a, W def crt_ladder(base, top, mmax=12): a, W = build_tile(base) Q = [int(p) for p in sp.primerange(base + 1, top + 1)] K = 0 for m in range(1, mmax + 1): if scan_all(a, W, m, Q, stop_first=True)["covers"] > 0: K = m else: break return K, a, W, Q # --------------------------------------------------------------- main def main(): cert = json.load(open("certificate.json", encoding="utf-8")) W = int(cert["W"]) D = int(cert["D"]) K = int(cert["K"]) Q = [int(q) for q in cert["Q"]] a, Wr = build_tile(int(cert["base_prime"])) chk("W == product of primes <= 23", W == primorial(23), W) chk("W rebuilt by the direct sieve", Wr == W, Wr) chk("s == 24 and Q == primes in (24, 48]", cert["s"] == 24 and Q == [int(p) for p in sp.primerange(25, 48)], Q) chk("D == prod_{3<=p<=23}(p-2)", D == int(sp.prod( [p - 2 for p in sp.primerange(3, 24)])), D) chk("tile length == D", a.size == D, a.size) chk("tile strictly increasing in [0, W)", bool((np.diff(a) > 0).all() and a[0] >= 0 and a[-1] < W)) chk("every tile slot is a twin slot mod 23#", bool((np.gcd(a, W) == 1).all() and (np.gcd(a + 2, W) == 1).all())) bg = int(cyc_gaps(a, W).max()) chk("base gap recomputed == certificate", bg == int(cert["base_gap"]), bg) chk("base gap 204 == corpus ladder value for 23#", bg == 204, bg) chk("cyclic maxsum_%d == certificate maxsum" % (K + 1), maxsum(a, W, K + 1) == int(cert["maxsum"]), int(cert["maxsum"])) chk("maxsum monotone sanity maxsum21 <= maxsum22 <= maxsum23", maxsum(a, W, 21) <= maxsum(a, W, 22) <= maxsum(a, W, 23)) w = cert["witness"] st = int(w["start"]) pos = [int(x) for x in w["positions"]] chk("K == 21 and witness has K positions", K == 21 and len(pos) == K and int(cert["excluded_length"]) == K + 1, K) chk("witness positions are the K consecutive base slots at start", pos == [int(x) for x in a[st:st + K]] and 0 <= st < D) chk("witness left/right neighbours are the adjacent base slots", int(w["neighbour_left"]) == int(a[st - 1]) and int(w["neighbour_right"]) == int(a[st + K])) chk("witness neighbour gap == right-left", int(w["neighbour_gap"]) == int(w["neighbour_right"]) - int(w["neighbour_left"]), w["neighbour_gap"]) copy = int(w["copy"]) asg = {int(k): int(v) for k, v in w["assignment"].items()} crt_ok = all((copy * W + asg[q]) % q == 0 for q in Q) chk("copy solves c*W == -r_q (mod q) for every entering prime", crt_ok, copy) # sympy: the CRT system has a unique class, and the certificate's copy is it sol = sp.ntheory.modular.crt([q for q in Q], [(-asg[q] * pow(W % q, -1, q)) % q for q in Q]) chk("sympy CRT agrees with the certificate copy and modulus", int(sol[0]) % int(sol[1]) == copy % int(sol[1]) and int(sol[1]) == int(w["modulus"]), sol) killed = [] for j in range(K): x = int(a[st + j]) + copy * W killed.append(any(x % q == 0 or (x + 2) % q == 0 for q in Q)) chk("all K physical witness slots are killed (exact integer divisibility)", all(killed)) surv = [] for x0 in (int(w["neighbour_left"]), int(w["neighbour_right"])): x = x0 + copy * W surv.append(not any(x % q == 0 or (x + 2) % q == 0 for q in Q)) chk("both neighbouring physical slots survive", all(surv)) # the copy is the CRT point of the assignment: each prime kills through the assigned residue chk("each prime in Q actually strikes at least one witness slot", all(any((int(a[st + j]) + copy * W) % q == 0 or (int(a[st + j]) + copy * W + 2) % q == 0 for j in range(K)) for q in Q)) rn, rd = int(cert["ratio_num"]), int(cert["ratio_den"]) chk("ratio is the reduced fraction maxsum/base_gap", sp.Rational(int(cert["maxsum"]), bg) == sp.Rational(rn, rd) and rn == 77 and rd == 17, "%d/%d" % (rn, rd)) chk("(M8) at s = 24: maxsum_22 <= 8 * base_gap", int(cert["maxsum"]) <= 8 * bg, "%d <= %d" % (int(cert["maxsum"]), 8 * bg)) lad = {int(r["m"]): r for r in cert["ladder"]} chk("certificate ladder excludes every length 22..32 with 0 covers", all(lad[m]["covers"] == 0 for m in range(K + 1, 33)), sorted(lad)) chk("certificate ladder has the length-21 row with a cover", lad[21]["covers"] >= 1) # ---- the decisive independent recomputation: no cover of length 22 over all D starts s22 = scan_all(a, W, K + 1, Q) chk("independent exclusion at length 22: 0 covers over all D starts", s22["covers"] == 0, "root-pass %d, backtracked %d" % (s22["pass"], s22["checked"])) chk("independent survivor count at length 22 == certificate row", s22["pass"] == int(lad[22]["root_pass"]), "%d == %d" % (s22["pass"], int(lad[22]["root_pass"]))) s21 = scan_all(a, W, 21, Q, stop_first=True) chk("independent lower witness at length 21 exists", s21["covers"] >= 1, s21["first"]) # ---- small-period controls against direct physical-copy enumeration ctl = [(5, 11), (7, 13), (7, 17), (11, 17), (11, 19)] okc = True detail = [] for base, top in ctl: kb, _, _, _ = brute_kstar(base, top) kc, _, _, _ = crt_ladder(base, top) okc &= (kb == kc) detail.append("%d#->%d: brute %d CRT %d" % (base, top, kb, kc)) chk("small-period controls: CRT ladder == physical-copy walk", okc, "; ".join(detail)) # ---- the capacity bound never excludes a genuinely coverable start (small periods) okb = True for base, top in [(7, 13), (7, 17), (11, 17)]: aa, WW = build_tile(base) QQ = [int(p) for p in sp.primerange(base + 1, top + 1)] for m in range(1, 9): cap, ext = capacity_all(aa, WW, m, QQ) res = [(ext % q).astype(np.int32) for q in QQ] true_cov = set() for i in range(aa.size): if has_cover([r[i:i + m].tolist() for r in res], QQ, prune=False): true_cov.add(i) bad = [i for i in true_cov if cap[i] < m] if bad: okb = False print(" capacity undercount at", base, top, m, bad[:3]) chk("root-capacity bound validated against exhaustive search on small periods", okb) # ---- negative controls bad_copy = copy + 1 bad_kill = all(any((int(a[st + j]) + bad_copy * W) % q == 0 or (int(a[st + j]) + bad_copy * W + 2) % q == 0 for q in Q) for j in range(K)) chk("negative control: corrupting the witness copy is rejected", not bad_kill) chk("negative control: a length-23 window is excluded as well", scan_all(a, W, 23, Q)["covers"] == 0) chk("negative control: mutated maxsum is detected", maxsum(a, W, 22) != int(cert["maxsum"]) + 6) # ---- calibration against the published 19# values of return #2017 / the bridge note a19, W19 = build_tile(19) bg19 = int(cyc_gaps(a19, W19).max()) Q4 = [23, 29, 31, 37] Q6 = [23, 29, 31, 37, 41, 43] r4 = scan_all(a19, W19, 14, Q4) c4 = scan_all(a19, W19, 13, Q4, stop_first=True) r6 = scan_all(a19, W19, 21, Q6) c6 = scan_all(a19, W19, 20, Q6, stop_first=True) chk("calibration 19#: D, base gap, maxsum14, maxsum21 match the published values", a19.size == 378675 and bg19 == 150 and maxsum(a19, W19, 14) == 570 and maxsum(a19, W19, 21) == 750) chk("calibration 19#: K*=13 through 37 (cover at 13, none at 14)", c4["covers"] >= 1 and r4["covers"] == 0 and r4["pass"] == 1346, "pass14 %d" % r4["pass"]) chk("calibration 19#: K*=20 through 43 (cover at 20, none at 21)", c6["covers"] >= 1 and r6["covers"] == 0 and r6["pass"] == 52246, "pass21 %d" % r6["pass"]) n_pass = sum(1 for _, ok, _ in CHECKS if ok) print("%d/%d checks passed" % (n_pass, len(CHECKS))) return 0 if n_pass == len(CHECKS) else 1 if __name__ == "__main__": sys.exit(main())