#!/usr/bin/env python3 """Job #1485 (explore, lane g2-exponent) — a new finite statistic: the 2-RUNG COUNT A(x,p). QUESTION (pre-registered before any number below was computed, 2026-09-16T12:53Z): The published ladder L(level, p) (L-grid-622.json) is ONE number per cell - a maximum, which flips when a single pair appears or disappears, and which #1444 found disagrees with the documented definition in 122 of 126 cells at levels 5, 7, 11; levels 13/17/19/23 were left untested. The new statistic is the COUNT of exactly the events the maximum discards: the adjacent admissible-slot pairs that the definition's 2-set admits. rp = [ n mod p for n in the x#-period admissible slots ] (n = D(x,p) slots, one period) A(x,p) = #{ i in Z_n : {rp[i], rp[i+1 mod n]} is contained in some 2-set {a, a+2} mod p } = #{ i : (rp[i+1] - rp[i]) mod p in {0, 2, p-2} } R2(x,p) = A(x,p) / n (the 2-rung density of the period) Exact link: a run of length >= 2 under the documented rule exists iff two CONSECUTIVE entries share a 2-set, i.e. iff A >= 1. So A refines the published L and exposes the multiplicity L hides. Two closures are reported, because the definition is cyclically closed: A_cyc (successor residue rp[0]) and A_true (true seam residue (rp[0] + M) mod p) - the distinction #1440/#1444 called naive vs true. DECISION IT INFORMS. A corpus row with L = 1 forces A = 0 under the documented definition, so A is a NECESSARY-CONDITION test available at every corpus row from the definition alone, with no producer run. It converts route 34's open producer adjudication into a pre-registered prediction: at any cell with A >= 1 every implementation of the documented statistic returns L >= 2, so a producer value of 1 there is proof that the corpus's implemented rule is not its documented one. FALSIFIER (pre-registered, before any run): F1 If at levels 13 and 17 (untested by #1444) the share of corpus rows with bank L = 1 and A >= 1 is < 0.5, then "the corpus column is not the documented statistic" is FALSIFIED and #1444's 122/126 is a level-5/7/11 artefact; the route dies there. F2 If A_real lies inside the permutation null's central band (mean +- 1.96 sd) in >= 90 % of cells, A carries no arithmetic content and may not be used as a discriminator. CONTROL. Permutation of the residue word inside each cell (multiset preserved, adjacency destroyed), fixed seed, as the repo's convention (permutation / thinning / random sign) permits. The analytic null E[A_perm] is reported too, from the residue histogram, so the control does not rest on the draws alone. GATES (before any new number is believed): G1 #1444's summary at levels 5, 7, 11 reproduced by ITS OWN CODE, byte-identical: 126 cells compared, bank_matches_literal = 4, and naive == literal everywhere (the closure agreement #1440 reported). G2 the vectorised definitional max equals #1444's own max_run at every one of those 126 cells. G3 lit >= 2 <=> A >= 1 in every cell of every level run here. G4 L(T_5, 7) = 2 in the definitional scan and in the bank row (the level-5 diagonal #1444 gated on). REUSE. `job1444-threeway.py` (run run_20260916_125605_wmVIXg) is imported BYTE-IDENTICAL for primes_upto / admissible / max_run and is the gate path; numpy carries only the faster inner loops of the same two objects (checked cell by cell against max_run by G2). Stdout is deterministic JSON, timing on stderr - the rule return #652 was flagged for breaking. """ import argparse import importlib.util import json import pathlib import sys import time import numpy as np # Paths are resolved from this file's own location (never a per-user home path): the script must run # on any machine that has the department tree. /.solveathome/runs//work/ SAH = pathlib.Path(__file__).resolve().parents[3] # the .solveathome root MOD_PATH = str(SAH / "runs/run_20260916_125605_wmVIXg/work/job1444-threeway.py") def load_mod(path): spec = importlib.util.spec_from_file_location("job1444", path) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod def longest_cyclic_run(mask): """Longest run of True in a boolean array, treated cyclically.""" n = mask.size false_idx = np.flatnonzero(~mask) if false_idx.size == 0: return n gaps = np.diff(np.append(false_idx, false_idx[0] + n)) - 1 return int(gaps.max()) def l_doc(residues, p): """Documented statistic, cyclically closed: max_a longest run of entries whose residue in {a,a+2}.""" n = residues.size best = 0 for a in np.unique(residues): a = int(a) mask = (residues == a) | (residues == (a + 2) % p) r = longest_cyclic_run(mask) if r > best: best = r return best def a_count(residues, p, seam_val): """(A_cyc, A_true, counts by difference) for one period word as in the module docstring.""" both = (0, 2, p - 2) n = residues.size d = (np.roll(residues, -1) - residues) % p counts = {} a_cyc = 0 for v in both: c = int(np.count_nonzero(d == v)) counts[str(v)] = c a_cyc += c d_seam = (seam_val - residues[-1]) % p a_true = a_cyc if d[-1] in both: a_true -= 1 if d_seam in both: a_true += 1 return a_cyc, a_true, counts def perm_band(residues, p, iters, seed): rng = np.random.default_rng(seed) both = {0, 2, p - 2} vals = [] w = residues.copy() for _ in range(iters): rng.shuffle(w) d = (np.roll(w, -1) - w) % p vals.append(sum(int(np.count_nonzero(d == v)) for v in both)) m = sum(vals) / len(vals) sd = (sum((v - m) ** 2 for v in vals) / max(1, len(vals) - 1)) ** 0.5 return {"iters": iters, "mean": round(m, 4), "sd": round(sd, 4), "min": min(vals), "max": max(vals)} def analytic_mean(residues, p, n): """E[A_perm] from the residue histogram (ordered pairs of distinct positions).""" counts = np.bincount(residues, minlength=p) tot = 0 for r in np.flatnonzero(counts): c = int(counts[r]) for dd in (0, 2, p - 2): if dd == 0: tot += c * (c - 1) else: tot += c * int(counts[(r + dd) % p]) return tot / (n * (n - 1)) if n > 1 else 0.0 def main(): ap = argparse.ArgumentParser() ap.add_argument("--bank", default=str(SAH / "runs/run_20260916_115338_mH5kbg/work/" "L-grid-622.json")) ap.add_argument("--levels", default="5,7,11,13,17") ap.add_argument("--gate-levels", default="5,7,11") # levels where #1444's own max_run is the gate ap.add_argument("--out", default=None) ap.add_argument("--seed", type=int, default=20260916) args = ap.parse_args() t0 = time.time() mod = load_mod(MOD_PATH) gate_levels = {int(v) for v in args.gate_levels.split(",")} bank = {} for r in json.loads(pathlib.Path(args.bank).read_text())["rows"]: bank[(int(r["level"]), int(r["p"]))] = r["L"] out = {"job": 1485, "statistic": "A(x,p) = # adjacent admissible-slot pairs whose residues lie in one 2-set {a,a+2}; R2 = A/n", "instrument": "job1485-rungcount.py", "seed": args.seed, "bank": args.bank, "levels": {}, "cells": [], "gates": {"G4": None}, "G1_bank_cells_levels_5_7_11": None, "G2_maxrun_mismatches": [], "G3_link_violations": [], "gate4_closure_violations": []} g1_cells = g1_matches = 0 for x in [int(v) for v in args.levels.split(",")]: M = 1 for q in mod.primes_upto(x): M *= q res = mod.admissible(x, M) n = len(res) base = np.array(res, dtype=np.int64) ps = [q for q in mod.primes_upto(200) if q > x] iters = max(20, min(200, 400000 // n)) out["levels"][str(x)] = {"x": x, "M": M, "slots": n, "primes_tested": len(ps), "perm_iters": iters} for j, p in enumerate(ps): residues = base % p lit = l_doc(residues, p) a_cyc, a_true, counts = a_count(residues, p, seam_val=(int(res[0]) + M) % p) band = perm_band(residues, p, iters, args.seed + x * 1000 + p) bl = bank.get((x, p)) cell = {"x": x, "p": p, "D": n, "L_doc": lit, "A_cyc": a_cyc, "A_true": a_true, "R2": round(a_cyc / n, 6), "pairs_by_diff": counts, "bank_L": bl, "perm_mean": band["mean"], "perm_sd": band["sd"], "perm_analytic_mean": round(n * analytic_mean(residues, p, n), 4), "z_perm": (round((a_cyc - band["mean"]) / band["sd"], 3) if band["sd"] else None), "in_perm_band": bool(band["sd"] > 0 and abs(a_cyc - band["mean"]) <= 1.96 * band["sd"])} # gate path: #1444's own max_run on the same cell (levels where it is affordable) if x in gate_levels: rp = [int(v) for v in residues] lit_mod = mod.max_run(rp + [(r + M) % p for r in rp], p, n) nai_mod = mod.max_run(rp + rp, p, n) cell["L_1444_module"] = lit_mod if lit_mod != lit: out["G2_maxrun_mismatches"].append({"x": x, "p": p, "module": lit_mod, "vector": lit}) if nai_mod != lit_mod: out["gate4_closure_violations"].append({"x": x, "p": p, "lit": lit_mod, "naive": nai_mod}) if bl is not None: g1_cells += 1 if bl == lit_mod: g1_matches += 1 if (lit >= 2) != (a_cyc >= 1) and (lit >= 2) != (a_true >= 1): out["G3_link_violations"].append({"x": x, "p": p, "lit": lit, "A_cyc": a_cyc, "A_true": a_true}) if (x, p) == (5, 7): out["gates"]["G4"] = {"definitional_L": lit, "bank_L": bl, "A_cyc": a_cyc, "ok": lit == 2 and bl == 2} out["cells"].append(cell) if j == 0: print(f"level {x}: M={M} slots={n} primes={len(ps)} iters={iters}", file=sys.stderr) out["G1_bank_cells_levels_5_7_11"] = { "cells": g1_cells, "bank_matches_1444_literal": g1_matches, "expected_from_1444": {"cells": 126, "matches": 4}, "ok": g1_cells == 126 and g1_matches == 4} def share(cells, levels): sel = [c for c in cells if c["x"] in levels and c["bank_L"] == 1] hit = [c for c in sel if c["A_cyc"] >= 1] return {"rows_bank_L1": len(sel), "rows_bank_L1_with_A_ge_1": len(hit), "share": (round(len(hit) / len(sel), 4) if sel else None)} h = {"levels_5_7_11": share(out["cells"], {5, 7, 11}), "levels_13_17": share(out["cells"], {13, 17}), "all_levels": share(out["cells"], {5, 7, 11, 13, 17}), "cells_in_perm_band": sum(1 for c in out["cells"] if c["in_perm_band"]), "cells_total": len(out["cells"])} h["bank_rows_L1_but_A0"] = [{"x": c["x"], "p": c["p"]} for c in out["cells"] if c["bank_L"] == 1 and c["A_cyc"] == 0] h["falsifier_F1_fires"] = bool(h["levels_13_17"]["share"] is not None and h["levels_13_17"]["share"] < 0.5) h["falsifier_F2_fires"] = bool(h["cells_in_perm_band"] >= 0.9 * h["cells_total"]) out["headline"] = h out["elapsed_s"] = round(time.time() - t0, 2) if args.out: pathlib.Path(args.out).write_text(json.dumps(out, indent=1, sort_keys=True) + "\n") print(json.dumps({"gates": {"G1": out["G1_bank_cells_levels_5_7_11"], "G2_mismatches": len(out["G2_maxrun_mismatches"]), "G3_link_violations": len(out["G3_link_violations"]), "closure_violations": len(out["gate4_closure_violations"]), "G4": out["gates"]["G4"]}, "headline": h}, sort_keys=True)) print(f"elapsed {out['elapsed_s']}s", file=sys.stderr) if __name__ == "__main__": main()