--- a/grid.py +++ b/grid.py @@ -42,9 +42,18 @@ import numpy as np HERE = pathlib.Path(__file__).parent -_spec = importlib.util.spec_from_file_location("det", str(HERE.parent / "readings" / "determine.py")) -det = importlib.util.module_from_spec(_spec) -_spec.loader.exec_module(det) +def build_tile(level): + """Direct divisibility sieve; the finite published domain ends at level23.""" + assert level in (5,7,11,13,17,19,23), "outside published finite domain" + primes = primes_upto(level) + modulus = 1 + for q in primes: + modulus *= q + allowed = np.ones(modulus, dtype=np.bool_) + for q in primes: + allowed[::q] = False + allowed[q-2::q] = False + return np.flatnonzero(allowed), modulus T0 = time.time() LEVELS = [5, 7, 11, 13, 17, 19, 23] # T_29 handled by the streaming engine, not here @@ -108,6 +117,7 @@ ok = lambda x, y: (x == y) or abs(int(x) - int(y)) in (2, p - 2) best = cur = 0 s1 = s2 = last = -1 + tail_count = 0 for i in range(pd.size): rr = int(pd[i]) % p ext = False @@ -119,11 +129,12 @@ if ext: cur += 1 else: - cur = 2 if (last >= 0 and ok(last, rr)) else 1 - if cur == 2: + cur = tail_count + 1 if (last >= 0 and ok(last, rr)) else 1 + if cur > 1: s1, s2 = last, rr else: s1, s2 = rr, -1 + tail_count = tail_count + 1 if rr == last else 1 last = rr if cur > best: best = cur @@ -170,8 +181,16 @@ # holds pos + P, so a witness crossing the seam reads {29, 41} at T_5 where the cyclic # continuation of the base slot 29 is 11 (41 = 11 + 30). Comparing raw values rejected that # legal witness; comparing mod P verifies it, and the wrap is still reported. - if not np.array_equal(base[idx] % Pbase, w % Pbase): + lifted = base[idx] + ((i0 + np.arange(L)) // D) * Pbase + if not np.array_equal(lifted, w): return {"ok": False, "why": "the witness is not %d consecutive cyclic tile slots" % L} + import math + if any(math.gcd(int(v)*(int(v)+2), Pbase) != 1 for v in w): + return {"ok": False, "why": "witness contains a non-admissible slot"} + actual = [r for r in range(int(w[0]), int(w[-1])+1) + if math.gcd(r*(r+2), Pbase) == 1] + if actual != [int(v) for v in w]: + return {"ok": False, "why": "a true admissible slot was skipped"} return {"ok": True, "residues": res, "start": int(start), "base_index": i0, "copies_spanned": int((i0 + L - 1) // D), "values": [int(w[0]), int(w[-1])]} @@ -180,7 +199,7 @@ primes = [p for p in primes_upto(P_MAX) if p > 2] rows, gates, bad = [], [], [] for level in LEVELS: - pos, P = det.tile(level) + pos, P = build_tile(level) D = int(pos.size) pd = np.concatenate([pos, pos + P]) log("T_%d: D=%d, frame=%d, %d primes to sweep" % (level, D, pd.size,