#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Job #1684 ("Leads: new statistic"): DECIDE job #1677's pre-registered two-prime falsifier. QUESTION (pre-registered by run run_20260917_161709_rsqgow in work/PRE-REGISTRATION-1677.md BEFORE any run; the run was cut at its session deadline with a 0-byte log, so the experiment was never decided -- this file decides it): For a prime p, the served kill-step classes on a gap g are Z: g = 0 (mod p) M: g = p-2 (mod p) P: g = 2 (mod p) X: otherwise. Lambda_or(p,q) = longest cyclic window of consecutive slots all covered by p or by q (g_i in S_p union S_q, S_p = {values with class != X}), no state requirement. Lambda_and(p,q) = the same window under the PRODUCT automaton (both primes must kill every gap). Falsifier (support level): Lambda_or(p,q) >= 2 IFF L(T,p) >= 2 or L(T,q) >= 2, for every pair p= 1). Facts used (each an idempotent identity on this automaton, so the vectorized form is exact): (1) L(T,p) >= 2 <=> two adjacent slots are both covered by p. Reason: at a covered slot the backward DP has max(n0,n2) >= 1 from any entered state, and Z/M/P can leave either state, so the DP value at slot j is 1 + max over next states; hence >= 2 exactly on an adjacent covered pair. (2) Lambda_and(p,q) = longest cyclic run of slots covered by p AND by q. Same argument applied to the product automaton (state space {0,p-2} x {0,q-2}; a covered slot leaves either state for each prime, and enters from either), so the recurrence is again "max over next states". Both reduce the experiment to masks on the gap WORD, so no Python-level loop over the 8 M slots is needed (that loop is what produced job #1677's 0-byte log). Objects reused read-only, nothing redefined: tile builder + single-prime automaton = job #1406 / return #640's reviewed `screen.py`, imported by a __file__-relative path; kill classes = N-1644's reconstruction of the served edge (sigma' - sigma = g_i mod p); T23 anchors from #627/#1634. Deterministic, offline, no network. Run through `sah.py exec` with stdout redirected to a log. """ import json import sys import time from pathlib import Path import numpy as np HERE = Path(__file__).resolve() PRIOR = HERE.parents[3] / "run_20260916_111913_U5Xr-Q" / "work" / "job1406" sys.path.insert(0, str(PRIOR)) import screen # noqa: E402 (reviewed tile builder + single-prime automaton, job #1406) LEVEL = 23 PRIME_CAP = 211 # N-1644's bound forces L = 1 above G2 = 204 SHUFFLES = 20 SEED = 1684 def primes_upto(n): out = [] for c in range(3, n + 1, 2): if all(c % d for d in range(3, int(c ** 0.5) + 1, 2)): out.append(c) return out def longest_run(mask): """Longest cyclic run of consecutive True slots (0 if none, D if all).""" D = mask.size idx = np.flatnonzero(~mask) if idx.size == 0: return int(D) runs = np.diff(np.append(idx, idx[0] + D)) - 1 return int(runs.max()) def main(): t0 = time.time() facts = {} anchors = {} res, M, _ = screen.build_tile(LEVEL) D = len(res) g = np.array(screen.gaps_of(res, M), dtype=np.int64) vals, _counts = np.unique(g, return_counts=True) K = int(vals.size) G2 = int(vals.max()) u = np.searchsorted(vals, g) # slot -> value index, one pass Adj = np.zeros((K, K), dtype=bool) # ordered adjacent VALUE pairs A = np.bincount(u * K + np.roll(u, -1), minlength=K * K).reshape(K, K) Adj = A > 0 facts.update(level=LEVEL, period_M=M, D=D, distinct_gaps=K, gap_min=int(vals.min()), gap_max=G2, build_s=round(time.time() - t0, 2)) anchors["D_matches_served_T23"] = D == 7_952_175 anchors["gap_inventory_matches_627"] = (K == 33 and int(vals.min()) == 6 and G2 == 204) anchors["adjacent_pairs_total_equals_D"] = int(A.sum()) == D # --- served single-prime column (reused reviewed automaton; 39 primes) ----------------- plist = [p for p in primes_upto(PRIME_CAP) if p >= 23] t1 = time.time() L1 = screen.row_by_automaton(g, plist) facts["column_s"] = round(time.time() - t1, 2) facts["primes_swept"] = len(plist) anchors["served_L_T23_p29_31_37_41"] = [L1[p] for p in (29, 31, 37, 41)] == [2, 3, 2, 2] anchors["bound_L_is_1_for_p_gt_G2"] = all(L1[p] == 1 for p in plist if p > G2) L19_res, L19_M, _ = screen.build_tile(19) anchors["T19_p23_row"] = screen.row_by_automaton(screen.gaps_of(L19_res, L19_M), [23])[23] == 3 facts["L_column"] = {str(p): int(L1[p]) for p in plist} # --- coverage of the 33 distinct gap values, per prime --------------------------------- cov = {p: ((vals % p == 0) | (vals % p == 2) | (vals % p == (p - 2) % p)) for p in plist} facts["support_primes"] = sorted(p for p in plist if cov[p].any()) facts["inert_primes"] = sorted(p for p in plist if not cov[p].any()) # consistency of the two characterisations of inertness on the word level inert_by_column = sorted(p for p in plist if L1[p] == 1) anchors["inert_two_ways_agree"] = inert_by_column == facts["inert_primes"] # --- the pre-registered order-free filter over all pairs ------------------------------- pairs = [(plist[i], plist[j]) for i in range(len(plist)) for j in range(i + 1, len(plist))] def passes(p, q): c = cov[p] | cov[q] if not c.any(): return False return bool(np.any(Adj & c[:, None] & c[None, :])) passing, both_inert_pass, one_supported_pass = [], [], [] for p, q in pairs: if not passes(p, q): continue passing.append((p, q)) (both_inert_pass if (L1[p] == 1 and L1[q] == 1) else one_supported_pass).append((p, q)) facts["pairs_total"] = len(pairs) facts["pairs_passing_adjacency_filter"] = len(passing) facts["both_inert_pairs_passing"] = both_inert_pass facts["one_supported_pairs_passing"] = len(one_supported_pass) facts["inert_primes_count"] = len(facts["inert_primes"]) # --- exact windows for the pairs that pass (vectorized masks on the word) -------------- exact = [] for p, q in passing: mor = (cov[p] | cov[q])[u] mand = (cov[p] & cov[q])[u] lo = longest_run(mor) la = longest_run(mand) exact.append({"p": p, "q": q, "L_p": int(L1[p]), "L_q": int(L1[q]), "Lambda_or": lo, "Lambda_and": la, "gain_over_max": lo - max(L1[p], L1[q])}) facts["exact_pairs"] = exact facts["gains_positive"] = [e for e in exact if e["gain_over_max"] > 0] facts["max_gain"] = max([e["gain_over_max"] for e in exact], default=0) facts["Lambda_and_max"] = max([e["Lambda_and"] for e in exact], default=0) facts["falsifier_pair_additivity_refuted"] = bool(both_inert_pass) facts["falsifier_sharper_no_gain_refuted"] = bool(facts["gains_positive"]) # --- control 1: cyclic rotations must leave every counted statistic invariant ---------- rot_ok = True for r in (1, 12345, D // 3): ur = np.roll(u, r) if not np.array_equal(np.bincount(ur * K + np.roll(ur, -1), minlength=K * K).reshape(K, K), A): rot_ok = False facts["control_rotation_invariance"] = bool(rot_ok) # --- control 2: random permutation of the same multiset (adjacency destroyed) ---------- rng = np.random.default_rng(SEED) perm_pass, perm_both = [], [] for _ in range(SHUFFLES): up = u[rng.permutation(D)] # numpy permutation, not rng.sample(list) Ap = np.bincount(up * K + np.roll(up, -1), minlength=K * K).reshape(K, K) > 0 c_pass = c_both = 0 for p, q in pairs: c = cov[p] | cov[q] if not c.any(): continue if np.any(Ap & c[:, None] & c[None, :]): c_pass += 1 if L1[p] == 1 and L1[q] == 1: c_both += 1 perm_pass.append(c_pass) perm_both.append(c_both) facts["control_permutation_passing_counts"] = perm_pass facts["control_permutation_passing_mean"] = round(float(np.mean(perm_pass)), 2) facts["control_permutation_passing_sd"] = round(float(np.std(perm_pass)), 2) facts["control_permutation_both_inert_counts"] = perm_both facts["control_permutation_max_both_inert"] = int(max(perm_both, default=0)) facts["wall_s"] = round(time.time() - t0, 2) facts["all_pass"] = bool(all(anchors.values()) and rot_ok) print(json.dumps({"facts": facts, "anchors": anchors}, indent=1, sort_keys=True)) return 0 if facts["all_pass"] else 1 if __name__ == "__main__": sys.exit(main())