#!/usr/bin/env python3 """witness.py -- the witness arithmetic of the 83# ascent (programme 0018). A *configuration* at level n is a choice of one residue a_p per prime p in {5, ..., p_n}; its covered set is the union of the pairs {a_p, a_p + c_p} (mod p) with c_p = 2*6^{-1} mod p, and its PREFIX is pre(a) = min{ j >= 0 : j is in no pair } By Lemma 1 of ../DERIVATION.md, [0, pre(a)-1] is covered, so A144311(n+2) >= 6*pre(a) + 5 , G_2(p_n#) >= 6*pre(a) + 6 . The point of this tool is that a witness obtained for a search target R may have pre(a) STRICTLY LARGER than R. Programme 0017 reported the target R as its rung and thereby understated its own result: the witness found for R = 285 has pre(a) = 288, i.e. the rung is 288, worth +18 in A144311. Every rung of 0018 is therefore taken from pre(a), never from the target. USAGE witness.py check n a0 a1 ... an-1 verify one configuration witness.py pool FILE every line: n R a0 ... an-1 [# note] witness.py capacity n Rmax the root counting bound of Lemma 4 """ import sys def primes_first(n): out, x = [], 5 while len(out) < n: if all(x % d for d in range(2, int(x ** 0.5) + 1)): out.append(x) x += 1 return out def coff(p): s = 0 while (6 * s) % p != 1: s += 1 return (2 * s) % p def pairs(P): return [coff(p) for p in P] def covered(P, C, a, j): return any(j % p == a[i] or j % p == (a[i] + C[i]) % p for i, p in enumerate(P)) def prefix(P, C, a, cap=200000): j = 0 while j < cap and covered(P, C, a, j): j += 1 return j def bounds(n, R): """(A144311(n+2) lower bound, G_2(p_n#) lower bound) from a certified run R""" return 6 * R + 5, 6 * R + 6 def check(n, a): P = primes_first(n) if len(a) != n: return None C = pairs(P) bad = [j for j in range(prefix(P, C, a)) if not covered(P, C, a, j)] pre = prefix(P, C, a) A, G = bounds(n, pre) return P, C, pre, bad, A, G def capacity(n, Rmax): """cap(R) = sum over primes of the largest number of positions of [0,R-1] that one pair can cover. cap(R) < R would REFUTE R outright (Lemma 4); the table shows whether that ever happens at this level.""" P = primes_first(n) C = pairs(P) rows = [] for R in range(2, Rmax + 1): cap = 0 for i, p in enumerate(P): def cnt_res(r): return ((R - 1 - r) // p + 1) if r <= R - 1 else 0 cap += max(cnt_res(r) + cnt_res((r + C[i]) % p) for r in range(p)) rows.append((R, cap)) return rows def main(): if len(sys.argv) < 2: print(__doc__) return 2 mode = sys.argv[1] if mode == "check": n = int(sys.argv[2]) a = [int(x) for x in sys.argv[3:3 + n]] r = check(n, a) if r is None: print("need exactly %d residues" % n) return 2 P, C, pre, bad, A, G = r print("n=%d primes 5..%d" % (n, P[-1])) print(" residues a_p :", a) print(" c_p :", C) print(" uncovered positions inside the prefix:", bad) print(" prefix pre(a) =", pre, " (a covering of [0,%d])" % (pre - 1)) print(" ==> A144311(%d) >= %6d ; G_2(%d#) >= %6d" % (n + 2, A, P[-1], G)) return 0 if mode == "pool": path = sys.argv[2] best = None print("%-4s %-6s %-9s %-9s %-11s %-11s %s" % ("n", "foundR", "pre(a)", "gain", "A144311>=", "G_2>=", "source")) for line in open(path): line = line.strip() if not line or line.startswith("#"): continue head, _, note = line.partition("#") t = head.split() n = int(t[0]); found = int(t[1]); a = [int(x) for x in t[2:2 + n]] P, C, pre, bad, A, G = check(n, a) print("%-4d %-6d %-9d %-9d %-11d %-11d %s" % (n, found, pre, pre - found, A, G, note.strip())) if best is None or pre > best[0]: best = (pre, n, A, G, note.strip()) if best: print() print(" BEST certified rung: R = %d => A144311(%d) >= %d , G_2 >= %d [%s]" % (best[0], best[1] + 2, best[2], best[3], best[4])) return 0 if mode == "capacity": n = int(sys.argv[2]); Rmax = int(sys.argv[3]) rows = capacity(n, Rmax) fire = [r for r in rows if r[1] < r[0]] print("Root counting bound cap(R) at n=%d, R <= %d" % (n, Rmax)) print(" a REFUTATION by counting needs cap(R) < R") print(" %-8s %-10s %s" % ("R", "cap(R)", "cap(R) - R")) for R, cap in rows[:6] + rows[-6:]: print(" %-8d %-10d %+d" % (R, cap, cap - R)) print() print(" how many R in [2,%d] are refutable by counting alone: %d" % (Rmax, len(fire))) print(" smallest such R (if any):", fire[0] if fire else "none") print(" => the counting certificate is VACUOUS here; only search can refute.") return 0 print("unknown mode", mode) return 2 if __name__ == "__main__": sys.exit(main())