#!/usr/bin/env python3 """Job 4297 (route 44 step check): alt deciding index at theta = G2(new) from recorded record-gap witnesses. Definitions are #159's section 0 (T_x = twin slots mod x#, fold by q deletes v = 0, -2 mod q). Claim used: at theta = G2(T_new) every alternation-legal window with G_{L+1}(i) >= theta is realised in some copy with live flanks, i.e. it IS a record gap of T_new, and its index L is the number of T_old slots strictly inside that gap. So the alt deciding index = max over record gaps of that count. Gate: small consecutive folds (13->17, 17->19, 19->23) by full enumeration against #1867's route44-deciding-window.json (deciding_L_alt, N_new). Large folds: the served witnesses only (research/history/staging/phase1-T2b-exact-ladder.md, least position of a maximum), plus mirrors. Stdlib only; prints one JSON object. """ import json, sys PR = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41] def primorial(x): P = 1 for p in PR: if p <= x: P *= p return P def is_slot(v, x): for p in PR: if p > x: break r = v % p if r == 0 or r == p - 2: return False return True def inside_old(a, G, x_old): """T_old slots strictly inside (a, a+G).""" return [v for v in range(a + 1, a + G) if is_slot(v, x_old)] def record_gaps(x): """All maximal gaps of T_x (cyclic), by a bytearray sieve over [0, x#).""" P = primorial(x) arr = bytearray(b"\x01") * P z = bytes(1) for p in PR: if p > x: break for c in {0, (p - 2) % p}: n = len(range(c, P, p)) arr[c::p] = z * n first = arr.find(1) prev, best, starts = first, 0, [] v = arr.find(1, first + 1) count = 1 while v != -1: g = v - prev if g > best: best, starts = g, [prev] elif g == best: starts.append(prev) prev = v count += 1 v = arr.find(1, v + 1) g = first + P - prev if g > best: best, starts = g, [prev] elif g == best: starts.append(prev) return best, starts, count def mirror(a, G, P): # v -> -2 - v maps T_x to itself; the gap [a, a+G] maps to [-2-a-G, -2-a] return (-2 - a - G) % P out = {"job": 4297, "gates": [], "large": []} def served(sha, name): """#1867's route44-deciding-window.json, local copy or server-root /files/, hash-checked.""" import hashlib, os, urllib.request b = open(name, "rb").read() if os.path.exists(name) else \ urllib.request.urlopen("https://solveathome.org/files/" + sha).read() if hashlib.sha256(b).hexdigest() != sha: sys.exit("hash mismatch: " + name) return json.loads(b) r44 = served("47ab726eddaf228f7a05e86d389574c9babbd31549d06b0ec516ffcf868495f4", "r44dw.json") g1867 = {r["fold"]: r for r in r44["F1_deciding_index_per_L"]} n1867 = {r["fold"]: r["N_new"] for r in r44["F2_identity_test"]["folds"]} for xo, q in ((13, 17), (17, 19), (19, 23)): fold = f"{xo}->{q}" G, starts, D = record_gaps(q) Ls = [len(inside_old(a, G, xo)) for a in starts] row = {"fold": fold, "G2_new": G, "D_new": D, "N_new": len(starts), "L_per_record_gap": sorted(Ls), "alt_deciding_derived": max(Ls), "alt_deciding_1867": g1867[fold]["deciding_L_alt"], "N_new_1867": n1867.get(fold)} row["gate_ok"] = (row["alt_deciding_derived"] == row["alt_deciding_1867"] and (row["N_new_1867"] is None or row["N_new_1867"] == row["N_new"])) out["gates"].append(row) # served witnesses: (x_old, q, G2(q#), least position of a maximum, number of maxima) for xo, q, G, a, nmax in ((31, 37, 528, 544899485411, 2), (37, 41, 546, 3784200788231, 4)): P = primorial(q) rows = [] for s in (a, mirror(a, G, P)): ok = is_slot(s, q) and is_slot(s + G, q) and not any(is_slot(v, q) for v in range(s + 1, s + G)) ins = inside_old(s, G, xo) killed_by_q = all(v % q in (0, q - 2) for v in ins) rows.append({"start": s, "record_gap_ok": ok, "old_slots_inside": len(ins), "offsets": [v - s for v in ins], "all_killed_by_q": killed_by_q}) out["large"].append({"fold": f"{xo}->{q}", "G2_new": G, "maxima_recorded": nmax, "witness_pair": rows}) out["all_gates_ok"] = all(r["gate_ok"] for r in out["gates"]) print(json.dumps(out))