#!/usr/bin/env python3 """Single-exhibit checker for the SIEVE-beta(151, 5) claim - runner form. This is job 1 of witness_check.py (same bundle), extracted unchanged so the file is fully self-contained: the platform reproduction runner executes one artefact in isolation, and witness_check.py's job 2 reads the filed count record, which is not present there. This file reads no files and takes no arguments; it verifies the witness n = 1321 clause by clause from the definitions and exits 0 iff every check passes. For the full two-job check (witness + all 321 filed hits), run witness_check.py from the bundle. Definitions: as in witness_check.py and SieveBeta.lean. """ import json import os from math import gcd HERE = os.path.dirname(os.path.abspath(__file__)) P = 151 G = 6 def is_prime_td(n): if n < 2: return False d = 2 while d * d <= n: if n % d == 0: return False d += 1 if d == 2 else 2 return True def distinct_factors_td(m): out = [] d = 2 while d * d <= m: if m % d == 0: out.append(d) while m % d == 0: m //= d d += 1 if d == 2 else 2 if m > 1: out.append(m) return out def log_table(): tab = {} cur = 1 for e in range(150): tab[cur] = e cur = (cur * G) % P assert len(tab) == 150, "6 must have order exactly 150 mod 151" assert cur == 1 return tab def check_instance(n, tab): """Return (K, factors, logs, gcd_m) if n satisfies (0) and (i)-(v), else None. All clauses recomputed from n alone.""" if not is_prime_td(n): # (0) return None if n % 24 != 1: # (i) return None if pow(n, 75, P) != P - 1: # (ii), Euler return None if any((x * x) % P == n % P for x in range(P)): # (ii), brute force return None if (n + P) % 4 != 0: return None K = (n + P) // 4 facs = distinct_factors_td(K) logs = [] for q in facs: # (iii) e = tab[q % P] # every log of q is e + 150t, and 5 | 150, so # 5 | e iff 5 divides every log of q if e % 5 != 0: return None logs.append(e) g = 150 # (iv) for e in logs: g = gcd(g, e) if g != 5: return None if K % 2 != 0: # (v) return None return K, facs, logs, g def main(): tab = log_table() ok = True # --- the witness, clause by clause (job 1 of # witness_check.py; identical code path) --- n = 1321 w = check_instance(n, tab) print("witness 1321 recomputed:", w) checks = { "witness satisfies (0) and (i)-(v)": w is not None, "K == 368": w is not None and w[0] == 368, "368 == 2^4 * 23": 2 ** 4 * 23 == 368, "factors == [2, 23]": w is not None and w[1] == [2, 23], "logs == [70, 115]": w is not None and w[2] == [70, 115], "gcd(70, 115, 150) == 5": gcd(gcd(70, 115), 150) == 5, "pow(6, 70, 151) == 2": pow(6, 70, 151) == 2, "pow(6, 115, 151) == 23": pow(6, 115, 151) == 23, "order of 6 mod 151 == 150": len(tab) == 150, } for k, v in checks.items(): print(f" {k}: {v}") ok = ok and v if w is not None: print("WITNESS 1321: INSTANCE HOLDS " f"(K = {w[0]}, factors = {w[1]}, logs = {w[2]}, " f"gcd = {w[3]})") else: print("WITNESS 1321: INSTANCE FAILS") print("WITNESS VERIFICATION:", "PASS" if ok else "FAIL") return 0 if ok else 1 if __name__ == "__main__": raise SystemExit(main())