#!/usr/bin/env python3 """Erdos-Straus pilot, Cycle 15 WILD — C3 band kernel (Kaggle, CPU). Self-contained (stdlib only). Carries the C3 band decision for primes p = 3 (mod 4), 107 <= p <= 38880, per the frozen design in wild/CYCLE15_BRIEF.md S5: tier 1 counting (actual |S|, u; brief eq. (*)) -> FAILS tier 2 exhaustive (Cand(u) <= 3,000,000) -> FAILS or NEVER-ZERO tier 3 constructive search for a BAD-5, verified by a second path (subset products over residues) -> FAILS; failure to find decides NOTHING -> UNDECIDED. Primes 7..103 are already decided locally (Gate B table) and are not re-decided here; primes > 38880 are decided by the brief's counting theorem (P0^(5) = 38880) and are out of scope. CONTROL GATES FIRST (compute_allocation.md S5): Gate A reproduces Cycle 14's stored C2 classification fields at the 23 shifts p <= 199 (embedded below from results/wild_cycle14_classify.json); Gate B reproduces the locally decided Cycle 15 C3 table at 13 primes (embedded from results/wild_cycle15_classify.json). Any mismatch aborts loudly (SystemExit) and voids everything after. Checkpointing: one JSON line per decided prime appended to the checkpoint file in the working directory, flushed per prime; summary JSON rewritten per prime. A time guard (10.5 h) stops the run cleanly and names the remaining primes NOT ATTEMPTED. Modes: ES_C15_CONTROL_ONLY=1 -> gates only. ES_C15_PRIMES="107,127" -> smoke list for the main job. All in-kernel verdicts are PROVISIONAL until re-judged at home (compute_allocation.md S5). Exact integer arithmetic on every exact-claim path; the seeded RNG is used only to order search attempts, never in a verdict. """ import itertools import json import math import os import random import sys import time START = time.time() TIME_BUDGET_S = 10.5 * 3600 WORKDIR = "/kaggle/working" if os.path.isdir("/kaggle/working") else "." CKPT = os.path.join(WORKDIR, "es_c15_c3_checkpoint.jsonl") SUMMARY = os.path.join(WORKDIR, "es_c15_c3_summary.json") EMBED_C2_GATE = json.loads('{"103": {"A_holds": false, "S_size": 3, "S_sorted": [0, 44, 58], "U": [1, 3, 5, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 97, 99, 101], "bad_count": 15270, "cand_relevant_triples_in_U": 19552, "covered1_count": 3, "covered3_in_U": 4282, "smallest_bad_triple": [1, 1, 3], "u": 48}, "107": {"A_holds": false, "S_size": 3, "S_sorted": [0, 36, 70], "U": [1, 3, 5, 7, 9, 11, 13, 15, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 91, 93, 95, 97, 99, 101, 103, 105], "bad_count": 17390, "cand_relevant_triples_in_U": 22050, "covered1_count": 3, "covered3_in_U": 4660, "smallest_bad_triple": [1, 1, 3], "u": 50}, "11": {"A_holds": false, "S_size": 3, "S_sorted": [0, 2, 8], "U": [1, 9], "bad_count": 0, "cand_relevant_triples_in_U": 2, "covered1_count": 3, "covered3_in_U": 2, "smallest_bad_triple": null, "u": 2}, "127": {"A_holds": false, "S_size": 3, "S_sorted": [0, 54, 72], "U": [1, 3, 5, 7, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 119, 121, 123, 125], "bad_count": 30974, "cand_relevant_triples_in_U": 37760, "covered1_count": 3, "covered3_in_U": 6786, "smallest_bad_triple": [1, 1, 3], "u": 60}, "131": {"A_holds": false, "S_size": 3, "S_sorted": [0, 58, 72], "U": [1, 3, 5, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 125, 127, 129], "bad_count": 34338, "cand_relevant_triples_in_U": 41602, "covered1_count": 3, "covered3_in_U": 7264, "smallest_bad_triple": [1, 1, 3], "u": 62}, "139": {"A_holds": false, "S_size": 1, "S_sorted": [0], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137], "bad_count": 51568, "cand_relevant_triples_in_U": 54672, "covered1_count": 1, "covered3_in_U": 3104, "smallest_bad_triple": [1, 1, 3], "u": 68}, "151": {"A_holds": false, "S_size": 3, "S_sorted": [0, 70, 80], "U": [1, 3, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 147, 149], "bad_count": 54878, "cand_relevant_triples_in_U": 64752, "covered1_count": 3, "covered3_in_U": 9874, "smallest_bad_triple": [1, 1, 9], "u": 72}, "163": {"A_holds": false, "S_size": 1, "S_sorted": [0], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161], "bad_count": 84188, "cand_relevant_triples_in_U": 88480, "covered1_count": 1, "covered3_in_U": 4292, "smallest_bad_triple": [1, 1, 3], "u": 80}, "167": {"A_holds": false, "S_size": 9, "S_sorted": [0, 32, 40, 54, 72, 94, 112, 126, 134], "U": [1, 3, 5, 7, 9, 13, 15, 17, 19, 21, 23, 25, 27, 31, 33, 35, 37, 39, 41, 45, 47, 49, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 117, 119, 121, 125, 127, 129, 131, 133, 135, 139, 141, 143, 145, 147, 149, 151, 153, 157, 159, 161, 163, 165], "bad_count": 44056, "cand_relevant_triples_in_U": 70226, "covered1_count": 9, "covered3_in_U": 26170, "smallest_bad_triple": [1, 1, 3], "u": 74}, "179": {"A_holds": false, "S_size": 3, "S_sorted": [0, 70, 108], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 161, 163, 165, 167, 169, 171, 173, 175, 177], "bad_count": 95450, "cand_relevant_triples_in_U": 109650, "covered1_count": 3, "covered3_in_U": 14200, "smallest_bad_triple": [1, 1, 3], "u": 86}, "19": {"A_holds": false, "S_size": 1, "S_sorted": [0], "U": [1, 3, 5, 7, 11, 13, 15, 17], "bad_count": 68, "cand_relevant_triples_in_U": 112, "covered1_count": 1, "covered3_in_U": 44, "smallest_bad_triple": [1, 1, 3], "u": 8}, "191": {"A_holds": false, "S_size": 9, "S_sorted": [0, 30, 44, 72, 74, 116, 118, 146, 160], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 53, 55, 57, 59, 61, 63, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 127, 129, 131, 133, 135, 137, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189], "bad_count": 73190, "cand_relevant_triples_in_U": 109650, "covered1_count": 9, "covered3_in_U": 36460, "smallest_bad_triple": [1, 1, 3], "u": 86}, "199": {"A_holds": false, "S_size": 3, "S_sorted": [0, 92, 106], "U": [1, 3, 5, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 193, 195, 197], "bad_count": 134230, "cand_relevant_triples_in_U": 152000, "covered1_count": 3, "covered3_in_U": 17770, "smallest_bad_triple": [1, 1, 3], "u": 96}, "23": {"A_holds": false, "S_size": 9, "S_sorted": [0, 2, 4, 6, 8, 14, 16, 18, 20], "U": [1, 21], "bad_count": 0, "cand_relevant_triples_in_U": 2, "covered1_count": 9, "covered3_in_U": 2, "smallest_bad_triple": null, "u": 2}, "31": {"A_holds": false, "S_size": 3, "S_sorted": [0, 6, 24], "U": [1, 3, 5, 7, 11, 13, 17, 19, 23, 25, 27, 29], "bad_count": 144, "cand_relevant_triples_in_U": 352, "covered1_count": 3, "covered3_in_U": 208, "smallest_bad_triple": [1, 1, 3], "u": 12}, "43": {"A_holds": false, "S_size": 1, "S_sorted": [0], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41], "bad_count": 1248, "cand_relevant_triples_in_U": 1520, "covered1_count": 1, "covered3_in_U": 272, "smallest_bad_triple": [1, 1, 3], "u": 20}, "47": {"A_holds": false, "S_size": 9, "S_sorted": [0, 2, 8, 18, 20, 26, 28, 38, 44], "U": [1, 7, 9, 11, 13, 17, 19, 27, 29, 33, 35, 37, 39, 45], "bad_count": 108, "cand_relevant_triples_in_U": 546, "covered1_count": 9, "covered3_in_U": 438, "smallest_bad_triple": [1, 1, 9], "u": 14}, "59": {"A_holds": false, "S_size": 3, "S_sorted": [0, 8, 50], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 23, 25, 27, 31, 33, 35, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57], "bad_count": 2070, "cand_relevant_triples_in_U": 3250, "covered1_count": 3, "covered3_in_U": 1180, "smallest_bad_triple": [1, 1, 3], "u": 26}, "67": {"A_holds": false, "S_size": 1, "S_sorted": [0], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65], "bad_count": 5260, "cand_relevant_triples_in_U": 5952, "covered1_count": 1, "covered3_in_U": 692, "smallest_bad_triple": [1, 1, 3], "u": 32}, "7": {"A_holds": false, "S_size": 3, "S_sorted": [0, 2, 4], "U": [], "bad_count": 0, "cand_relevant_triples_in_U": 0, "covered1_count": 3, "covered3_in_U": 0, "smallest_bad_triple": null, "u": 0}, "71": {"A_holds": false, "S_size": 9, "S_sorted": [0, 6, 20, 26, 32, 38, 44, 50, 64], "U": [1, 5, 7, 11, 13, 17, 19, 21, 23, 25, 27, 31, 33, 37, 39, 43, 45, 47, 49, 51, 53, 57, 59, 63, 65, 69], "bad_count": 916, "cand_relevant_triples_in_U": 3250, "covered1_count": 9, "covered3_in_U": 2334, "smallest_bad_triple": [1, 1, 19], "u": 26}, "79": {"A_holds": false, "S_size": 3, "S_sorted": [0, 4, 74], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 37, 41, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77], "bad_count": 6050, "cand_relevant_triples_in_U": 8400, "covered1_count": 3, "covered3_in_U": 2350, "smallest_bad_triple": [1, 1, 3], "u": 36}, "83": {"A_holds": false, "S_size": 3, "S_sorted": [0, 10, 72], "U": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 33, 35, 37, 39, 43, 45, 47, 49, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81], "bad_count": 7210, "cand_relevant_triples_in_U": 9842, "covered1_count": 3, "covered3_in_U": 2632, "smallest_bad_triple": [1, 1, 3], "u": 38}}') EMBED_C3_LOCAL = json.loads('{"103": {"S_size": 3, "bad5_count": 222084, "cand5": 2598960, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 48, "verdict": "FAILS"}, "11": {"S_size": 3, "bad5_count": 0, "cand5": 6, "route": "exhaustive", "smallest_bad5": null, "u": 2, "verdict": "C3 NEVER-ZERO"}, "19": {"S_size": 1, "bad5_count": 48, "cand5": 792, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 8, "verdict": "FAILS"}, "23": {"S_size": 9, "bad5_count": 0, "cand5": 6, "route": "exhaustive", "smallest_bad5": null, "u": 2, "verdict": "C3 NEVER-ZERO"}, "31": {"S_size": 3, "bad5_count": 32, "cand5": 4368, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 12, "verdict": "FAILS"}, "43": {"S_size": 1, "bad5_count": 6288, "cand5": 42504, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 20, "verdict": "FAILS"}, "47": {"S_size": 9, "bad5_count": 98, "cand5": 8568, "route": "exhaustive", "smallest_bad5": [1, 9, 9, 9, 9], "u": 14, "verdict": "FAILS"}, "59": {"S_size": 3, "bad5_count": 6548, "cand5": 142506, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 26, "verdict": "FAILS"}, "67": {"S_size": 1, "bad5_count": 88814, "cand5": 376992, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 32, "verdict": "FAILS"}, "7": {"S_size": 3, "bad5_count": 0, "cand5": 0, "route": "vacuity", "smallest_bad5": null, "u": 0, "verdict": "C3 NEVER-ZERO"}, "71": {"S_size": 9, "bad5_count": 1678, "cand5": 142506, "route": "exhaustive", "smallest_bad5": [1, 7, 13, 13, 13], "u": 26, "verdict": "FAILS"}, "79": {"S_size": 3, "bad5_count": 40768, "cand5": 658008, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 36, "verdict": "FAILS"}, "83": {"S_size": 3, "bad5_count": 55848, "cand5": 850668, "route": "exhaustive", "smallest_bad5": [1, 1, 1, 1, 1], "u": 38, "verdict": "FAILS"}}') BAND_LO, BAND_HI = 107, 38880 EXHAUSTIVE_CAP = 3_000_000 SEARCH_RESTARTS = 300 SEARCH_TRIES_PER_SLOT = 200 def is_prime(n): if n < 2: return False if n % 2 == 0: return n == 2 i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True def prim_root(p): phi = p - 1 facs = set() x = phi d = 2 while d * d <= x: if x % d == 0: facs.add(d) while x % d == 0: x //= d d += 1 if d == 2 else 2 if x > 1: facs.add(x) g = 2 while any(pow(g, phi // q, p) == 1 for q in facs): g += 1 return g def shift_data(p): """Return (g, F, S set, U list, TS target set) for shift p.""" mod = p - 1 T = mod // 2 g = prim_root(p) tab = {} v = 1 for e in range(mod): tab[v] = e v = v * g % p F = ([2] if p % 8 == 7 else []) + ([3] if p % 3 == 2 else []) sums = {0} for q in F: f = tab[q] sums = {s + c * f for s in sums for c in (-1, 0, 1)} S = {s % mod for s in sums} covered = {(T - s) % mod for s in S} U = [e for e in range(1, mod, 2) if e not in covered] TS = {(T - s) % mod for s in S} return g, F, S, U, TS def signed_sums_hit(logs, mod, TS): sums = {0} for e in logs: sums = {s + e for s in sums} | {s - e for s in sums} return any(sm % mod in TS for sm in sums) def triple_covered(trip, mod, TS): return signed_sums_hit(trip, mod, TS) def is_bad5(quint, mod, TS): for idxs in itertools.combinations(range(5), 3): if triple_covered([quint[i] for i in idxs], mod, TS): return False return not signed_sums_hit(list(quint), mod, TS) def verify_bad5_second_path(p, g, F, quint_logs): """Independent path: subset products over rad residues (forced residues + one residue per BAD-5 log), counting sign-vector products equal to -1 mod p. Must be exactly 0, and mechanism (A) must fail (no forced-only hit).""" residues = list(F) + [pow(g, e, p) for e in quint_logs] cnt = 0 for signs in itertools.product((-1, 0, 1), repeat=len(residues)): v = 1 for s, q in zip(signs, residues): if s == 1: v = v * q % p elif s == -1: v = v * pow(q, -1, p) % p if v == p - 1: cnt += 1 return cnt == 0 def c2_layer(p): g, F, S, U, TS = shift_data(p) mod = p - 1 T = mod // 2 cand = math.comb(len(U) + 2, 3) - len(U) if U else 0 bad = 0 smallest = None covered_rel = 0 for trip in itertools.combinations_with_replacement(U, 3): cov = triple_covered(list(trip), mod, TS) if len(set(trip)) >= 2: if cov: covered_rel += 1 else: bad += 1 if smallest is None: smallest = list(trip) return { "A_holds": T in S, "covered1_count": len(S), "U": U, "u": len(U), "S_size": len(S), "S_sorted": sorted(S), "bad_count": bad, "cand_relevant_triples_in_U": cand, "covered3_in_U": covered_rel, "smallest_bad_triple": smallest, } def c3_exhaustive(p): g, F, S, U, TS = shift_data(p) mod = p - 1 u = len(U) covered3 = set() for trip in itertools.combinations_with_replacement(U, 3): if triple_covered(list(trip), mod, TS): covered3.add(trip) cnt = 0 first = None for quint in itertools.combinations_with_replacement(U, 5): ok = True for idxs in itertools.combinations(range(5), 3): if tuple(sorted(quint[i] for i in idxs)) in covered3: ok = False break if not ok: continue if signed_sums_hit(list(quint), mod, TS): continue cnt += 1 if first is None: first = list(quint) return {"u": u, "S_size": len(S), "cand5": math.comb(u + 4, 5) if u else 0, "bad5_count": cnt, "smallest_bad5": first} def control_gates(): print("CONTROL GATE A: Cycle 14 C2 fields at 23 shifts <= 199", flush=True) for p_str, want in sorted(EMBED_C2_GATE.items(), key=lambda kv: int(kv[0])): got = c2_layer(int(p_str)) for field, wv in want.items(): gv = got[field] if gv != wv: raise SystemExit(f"CONTROL ABORT gate A: p={p_str} field {field}: got {gv!r} want {wv!r}") print(f" gate A p={p_str} MATCH", flush=True) print("CONTROL GATE A: 23/23 MATCH", flush=True) print("CONTROL GATE B: Cycle 15 local C3 table at 13 primes", flush=True) for p_str, want in sorted(EMBED_C3_LOCAL.items(), key=lambda kv: int(kv[0])): p = int(p_str) if want["route"] == "vacuity": g, F, S, U, TS = shift_data(p) got = {"u": len(U), "S_size": len(S), "cand5": 0, "bad5_count": 0, "smallest_bad5": None} else: got = c3_exhaustive(p) for field in ("u", "S_size", "cand5", "bad5_count", "smallest_bad5"): if got[field] != want[field]: raise SystemExit(f"CONTROL ABORT gate B: p={p} field {field}: got {got[field]!r} want {want[field]!r}") print(f" gate B p={p} MATCH (route {want['route']}, verdict {want['verdict']})", flush=True) print("CONTROL GATE B: 13/13 MATCH", flush=True) def search_bad5(p, g, F, S, U, TS): mod = p - 1 rng = random.Random(p * 1000003 + 15) u = len(U) for attempt in range(1, SEARCH_RESTARTS + 1): chosen = [] failed = False for slot in range(5): placed = False for _ in range(SEARCH_TRIES_PER_SLOT): cand = U[rng.randrange(u)] tent = chosen + [cand] if len(tent) >= 3: bad = False for idxs in itertools.combinations(range(len(tent)), 3): if triple_covered([tent[i] for i in idxs], mod, TS): bad = True break if bad: continue if len(tent) == 5 and signed_sums_hit(tent, mod, TS): continue chosen = tent placed = True break if not placed: failed = True break if failed: continue quint = sorted(chosen) if is_bad5(quint, mod, TS) and verify_bad5_second_path(p, g, F, quint): return quint, attempt return None, SEARCH_RESTARTS def decide_prime(p): g, F, S, U, TS = shift_data(p) u = len(U) cand5 = math.comb(u + 4, 5) if u else 0 excl = 2 * len(S) * u**3 * (u + 1) + 16 * len(S) * u**4 if u else 0 base = {"p": p, "u": u, "S_size": len(S), "cand5": cand5} if u == 0: return {**base, "verdict": "C3 NEVER-ZERO", "route": "vacuity", "bad5_count": 0, "smallest_bad5": None} if cand5 > excl: return {**base, "verdict": "FAILS", "route": "counting", "bad5_count": None, "smallest_bad5": None, "counting_margin": cand5 - excl} if cand5 <= EXHAUSTIVE_CAP: got = c3_exhaustive(p) return {**base, "verdict": "FAILS" if got["bad5_count"] else "C3 NEVER-ZERO", "route": "exhaustive", "bad5_count": got["bad5_count"], "smallest_bad5": got["smallest_bad5"]} quint, attempts = search_bad5(p, g, F, S, U, TS) if quint is not None: return {**base, "verdict": "FAILS", "route": "search-exhibit", "bad5_count": None, "smallest_bad5": quint, "search_attempts": attempts, "verified_second_path": True} return {**base, "verdict": "UNDECIDED", "route": "search (budget exhausted)", "bad5_count": None, "smallest_bad5": None, "search_attempts": attempts} def main(): control_gates() if os.environ.get("ES_C15_CONTROL_ONLY") == "1": print("CONTROL-ONLY MODE: gates passed, main job NOT ATTEMPTED", flush=True) return smoke = os.environ.get("ES_C15_PRIMES") if smoke: primes = [int(x) for x in smoke.split(",") if x.strip()] else: primes = [p for p in range(BAND_LO, BAND_HI + 1) if p % 4 == 3 and is_prime(p)] results = [] not_attempted = [] with open(CKPT, "a") as ck: for i, p in enumerate(primes): if time.time() - START > TIME_BUDGET_S: not_attempted = primes[i:] print(f"TIME GUARD: stopping at p={p}; {len(not_attempted)} primes NOT ATTEMPTED", flush=True) break rec = decide_prime(p) rec["elapsed_s"] = round(time.time() - START, 1) results.append(rec) ck.write(json.dumps(rec, sort_keys=True) + "\n") ck.flush() print(f"[{i+1}/{len(primes)}] p={p} u={rec['u']} -> {rec['verdict']} by {rec['route']}", flush=True) summary = { "decided": len(results), "by_route": {}, "undecided": [r["p"] for r in results if r["verdict"] == "UNDECIDED"], "not_attempted": not_attempted, "results": results, } for r in results: summary["by_route"][r["route"]] = summary["by_route"].get(r["route"], 0) + 1 with open(SUMMARY, "w") as fh: json.dump(summary, fh, indent=1) print(f"DONE: {len(results)} decided/attempted, undecided={summary['undecided']}, not_attempted={len(not_attempted)}", flush=True) if __name__ == "__main__": main()