#!/usr/bin/env python3 """Single-exhibit checker for the SIEVE-beta(151, 5) claim. Python 3, standard library only. Exact integer arithmetic throughout. This program shares no code with the two counting programs in this bundle (cycle34_h3_count1515.py and cycle34_h3_count1515_check.py); it is a third, independent implementation of the definitions. Definitions (the statement family SIEVE-beta(p, d), specialised to p = 151, d = 5, exactly as formalised in SieveBeta.lean in this bundle). Let g = 6, a primitive root mod 151; logs are discrete logs base 6 mod 151, unique mod 150. An instance at a prime n is the conjunction of: (0) n is prime; (i) n = 1 (mod 24); (ii) (n/151) = -1 (n is a quadratic non-residue mod 151); (iii) for K = (n + 151)/4, EVERY prime divisor q of K and EVERY log e of q satisfy 5 | e (checked over all e in [0, 150); 6 has order exactly 150 mod 151, so this covers all logs); (iv) gcd({log_6 q : q | K} + {150}) = 5 exactly; (v) 2 | K (2 is the forced prime at p = 151). SIEVE-beta(151, 5) is the statement that an instance exists. Job 1 (the single exhibit): verify the witness n = 1321 clause by clause and print the verdict line WITNESS 1321: INSTANCE HOLDS with the recomputed K, factor list, log list and gcd. Job 2 (the filed count's records): recompute every hit in cycle34_h3_count1515.json from n alone and compare K, the distinct factor list, the log list and the gcd against the filed values; check the hit count is 321, the smallest hit is 1321, and the filed N_151_5_at_X0 is 321. Usage: python3 witness_check.py Exit code 0 iff every check passes. """ 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 # --- job 1: the witness, clause by clause --- 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") # --- job 2: recompute every filed hit --- with open(os.path.join(HERE, "cycle34_h3_count1515.json")) as f: data = json.load(f) hits = data["hits"] bad = 0 for h in hits: r = check_instance(h["n"], tab) if r is None: bad += 1 continue if not (r[0] == h["K"] and r[1] == h["factors"] and r[2] == h["logs"] and r[3] == h["gcd_m"]): bad += 1 summary = { "filed_hits": len(hits), "recomputed_mismatches": bad, "smallest_hit": min(h["n"] for h in hits), "filed_N_151_5_at_X0": data["N_151_5_at_X0"], "attrition": data["attrition"], } print(json.dumps(summary, indent=1)) ok = ok and bad == 0 and len(hits) == 321 \ and summary["smallest_hit"] == 1321 \ and data["N_151_5_at_X0"] == 321 print("WITNESS VERIFICATION:", "PASS" if ok else "FAIL") return 0 if ok else 1 if __name__ == "__main__": raise SystemExit(main())