#!/usr/bin/env python3 """job1645: decide, by exact computation, whether 252 is a gap of the T29 tile. Context (job #1644 / return #856, the gap-multiset support law): the served kill-graph support obeys L(T_x,p) >= 2 <=> some tile gap g satisfies g = 0, +2 or -2 (mod p). For x = 29 the only gap value that can hit 127 is 252 = 6*42 = -2 (mod 127): candidate multiples of 6 in (0, G2] with v mod 127 in {0, 2, 125} are just 252. Hence L(T29,127) = 1 <=> 252 is NOT a gap of T29. The served record (#161) claims the uniform threshold 127 for every column T5..T29. T29 = twin-admissible residues mod P = 2*3*...*29 = 6 469 693 230, i.e. r with gcd(r(r+2), P) = 1; D = |T29| = prod_{q<=29}(q-2) = 214 708 725 gaps, summing to P. The in-memory residue list is out of reach on this box (measured in #1638), so this scans one full period with a SEGMENTED sieve, constant memory. stdout is the artifact and must be byte-reproducible: no timings, no paths, no rates. All timing goes to stderr. """ import json import os import sys import time import numpy as np SMALL = [3, 5, 7, 11, 13, 17, 19, 23, 29] P = 2 # primorial(29) = 2 * prod_{3<=q<=29} q for _q in SMALL: P *= _q CHUNK = 1 << 24 # 16 777 216 positions TARGET = 252 def sieve_chunk(start, size): """Boolean array: True where start+i is twin-admissible mod P.""" a = np.ones(size, dtype=bool) a[(0 - start) % 2::2] = False # r odd (covers r and r+2 both) for q in SMALL: a[(q - start) % q::q] = False # i with (start+i) = 0 (mod q) a[(q - 2 - start) % q::q] = False # i with (start+i)+2 = 0 (mod q) return a def main(): t0 = time.time() divisions = 1 if "--divisions" in sys.argv: divisions = int(sys.argv[sys.argv.index("--divisions") + 1]) span = P // divisions gaps_seen = set() max_gap = 0 count_residues = 0 first_res = None last_res = None prev = None # last admissible position seen so far n252 = 0 off = 0 while off < span: size = min(CHUNK, span - off) a = sieve_chunk(off, size) idx = np.flatnonzero(a) if idx.size: idx = idx + off if prev is None: first_res = int(idx[0]) else: d = int(idx[0]) - prev if d == TARGET: n252 += 1 gaps_seen.add(d) if d > max_gap: max_gap = d if idx.size > 1: diffs = np.diff(idx) m = int(diffs.max()) if m > max_gap: max_gap = m if TARGET in diffs: n252 += int(np.count_nonzero(diffs == TARGET)) for v in np.unique(diffs): gaps_seen.add(int(v)) prev = int(idx[-1]) last_res = int(idx[-1]) count_residues += int(idx.size) off += size # wrap gap: last -> first of next period wrap = first_res + P - last_res if divisions == 1 else None if divisions == 1: if wrap == TARGET: n252 += 1 gaps_seen.add(wrap) if wrap > max_gap: max_gap = wrap out = { "P29": P, "chunk": CHUNK, "divisions": divisions, "scanned_positions": span, "residues_found": count_residues, "distinct_gap_values": len(gaps_seen), "max_gap_seen": max_gap, "full_period": divisions == 1, "target_gap": TARGET, "count_gap_252": n252 if divisions == 1 else None, "252_is_a_gap_of_T29": (n252 > 0) if divisions == 1 else None, "gap_values_ge_240": sorted(v for v in gaps_seen if v >= 240), } if divisions == 1: out["wrap_gap"] = wrap out["L_T29_127_equals_1"] = (n252 == 0) # the law's prediction for the whole T29 column, primes <= 1009 primes = [q for q in range(2, 1010) if all(q % d for d in range(2, int(q ** 0.5) + 1))] L1 = [] for p in primes: L1.append(not any(v % p in (0, 2, p - 2) for v in gaps_seen) if p > 2 else False) ge2 = [p for p, one in zip(primes, L1) if not one] out["predicted_L1_primes_up_to_1009"] = [p for p, one in zip(primes, L1) if one] out["predicted_Lge2_primes_up_to_1009"] = ge2 out["predicted_reads_1_from"] = (max(ge2) + 1) if ge2 else min(primes) out["served_uniform_threshold_127_confirmed"] = (ge2 == [] or max(ge2) < 127) print(json.dumps(out, indent=1, sort_keys=True)) print(f"[stderr] elapsed {time.time() - t0:.1f}s for divisions={divisions}", file=sys.stderr) if __name__ == "__main__": main()