#!/usr/bin/env python3 """Independent checker for tree959 non-coverability certificates (stdlib only; shares no code with the producer). Instance: p = 97, old primes <= 97, Q = primes in (97, 194], support a, prefix of the first n slots s >= a with gcd(s(s+2), 97#) = 1. A cover picks one phase b_q per q in Q and kills s when q | s + b_q or q | s + b_q + 2. Certificate: records keyed by path = [[q,b],...] (phases fixed so far). branch record {path, branch: q}: q not yet fixed on the path; every phase b = 0..q-1 must have a verified child path + [[q,b]]. leaf record {path, w}: residual R = slots not killed by the path's phases, Q' = Q minus the path's primes; w = nonnegative integers, one per slot of R in increasing order, with sum_{q in Q'} max_b W(q,b) < sum w, where W(q,b) = sum of w_s over s in R killed by (q,b). A cover through the path would need sum_q W(q,b_q) >= W(R), so the leaf is refuted. The root path [] verified => no cover of the prefix exists. python3 checkcert959.py 9409 48 tree959-9409-48.cert.jsonl """ import json import sys def primes_upto(m): return [k for k in range(2, m + 1) if all(k % d for d in range(2, int(k ** 0.5) + 1))] def main(): a, n, fn = int(sys.argv[1]), int(sys.argv[2]), sys.argv[3] old = primes_upto(97) Q = [q for q in primes_upto(194) if q > 97] D, s = [], a while len(D) < n: if all(s % r and (s + 2) % r for r in old): D.append(s) s += 1 recs = {} for line in open(fn): r = json.loads(line) key = tuple(tuple(x) for x in r['path']) assert key not in recs, 'duplicate path' recs[key] = r seen = set() stats = {'leaves': 0, 'branches': 0, 'maxdepth': 0} def dead(x, q, b): return (x + b) % q == 0 or (x + b + 2) % q == 0 def check(path): assert path in recs, f'missing record for path {list(path)}' seen.add(path) r = recs[path] fixed = [q for q, _ in path] assert len(set(fixed)) == len(fixed) R = [x for x in D if not any(dead(x, q, b) for q, b in path)] Qr = [q for q in Q if q not in fixed] stats['maxdepth'] = max(stats['maxdepth'], len(path)) if 'branch' in r: q = r['branch'] assert q in Qr, 'branch prime already fixed or not in Q' for b in range(q): check(path + ((q, b),)) stats['branches'] += 1 return w = r['w'] assert len(w) == len(R) and all(isinstance(v, int) and v >= 0 for v in w) tot = sum(w) sm = 0 for q in Qr: W = [0] * q for x, v in zip(R, w): W[(-x) % q] += v W[(-x - 2) % q] += v sm += max(W) assert tot > 0 and sm < tot, f'leaf {list(path)} fails: {sm} >= {tot}' stats['leaves'] += 1 check(()) assert len(seen) == len(recs), 'unreferenced records' print(f'PASS: a={a} n={n} L={D[-1] - a + 1} has no phase cover by Q={Q[0]}..{Q[-1]} ({len(Q)} primes); ' f'{stats["branches"]} branch nodes, {stats["leaves"]} leaves, max depth {stats["maxdepth"]}') if __name__ == '__main__': main()