#!/usr/bin/env python3 # ============================================================================ # JOB 1840 — route 67: does #159's largest untruncated L stay <= #161's L(T_x,q), # and does the LOOSE form's support stay <= LMAX = 8 ? # Run `run_20260918_124244_BuHARA`, attempt cb0975a6da2c042b30f596399df7e8c5. # ============================================================================ # WHAT IS MEASURED. On the tile T_x (twin-admissible residues mod x#, cyclic gap # word g of length D = T_x) a prime q acts by its residue classes: # K = {0, q-2}; a slot is DEAD for the anchor r at step m iff r + S_m in K, # S_m = G_m(i) = g_i + ... + g_{i+m-1} (the walk, #159's refined form), and # a gap QUALIFIES iff g mod q in {0, 2, q-2} = {Z, P, M} (the loose form). # Three statistics, all read from the definitions of the two accepted returns: # L_census = longest component (path or cycle) of the kill graph on nodes # (i, sigma), sigma in K, edge (i,sigma)->(i+1,sigma') iff # sigma' - sigma = g_i (mod q). [#161's L(T_x,q); #162] # R_loose = longest run of CONSECUTIVE gaps with g mod q in {0,2,q-2} # = the interior run whose length bounds the loose support: # a window of index L needs g_{i+1}..g_{i+L-1} qualifying, so # support(loose) = R_loose + 1 (span condition only removes starts). # CONTROLS. #161's published diagonal L(T_{p-},p) = 2,1,2,2,2,3,2,4 at folds 7..31 # (reproduced here for p = 7..23, the folds whose tiles are cheap), #162's # published T19/p=23 run census runs-of-3 = 62, and #159's OWN recorded output # fields, read at source from return #159's report_md: # T23 by 31: max L = 3 longest qualifying gap run = 2 # T23 by 37: max L = 2 longest qualifying gap run = 2 # T31 by 37: max L = 4 longest qualifying gap run = 3 # T37 by 41: max L = 3 longest qualifying gap run = 3 # The last two folds are NOT recomputable here (D = 6.2e9 and 2.18e11, and this # assignment's compute hint is cpu_hours 0); they are used as quoted checks. # Exact integer arithmetic only; network-free; deterministic. # Tile/kill-graph code reused verbatim from # runs/run_20260917_115102_NivfOQ/work/job1634/src/job1634-checks.py (department # tool, reviewed) — no new sieve. # ============================================================================ import json import sys from collections import Counter PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009] RESULTS = {"checks": []} def check(name, ok, detail=""): RESULTS["checks"].append({"name": name, "ok": bool(ok), "detail": detail}) print(("ok " if ok else "FAIL ") + name + ((" [" + str(detail) + "]") if detail else "")) # ---- reused tile machinery (job1634) --------------------------------------- def tile(x): """Twin-admissible residues mod x#: r with gcd(r(r+2), x#) = 1, count T_x. OWN-FAILURE TRAP, kept: job1634's `tile()` starts res=[1], P=2 and loops over PRIMES *including* q=2, which squares the 2-adic modulus (P = 4*odd primorial: two copies of the admissible set). That doubled word reproduces every COUNT exactly 2x (its T19/p=23 runs-of-3 came back 124 against the published 62) and moves some maxima -- the first run of this script failed 8 control checks on it. This version is the true modulus x#.""" res = [1] P = 2 for q in PRIMES: if q > x: break if q == 2: continue # the modulus already carries 2 once new = [] for r in res: for k in range(q): v = r + k * P if v % q == 0 or (v + 2) % q == 0: continue new.append(v) res = new P *= q res.sort() return res, P def gaps_of(res, P): D = len(res) g = [res[i + 1] - res[i] for i in range(D - 1)] g.append(res[0] + P - res[D - 1]) return g def run_spectrum(g, p): """Exact component census of the kill graph (nodes (i,sigma), sigma in {0,p-2}).""" D = len(g) out = bytearray(2 * D) nxt = bytearray(2 * D) for i in range(D): gp = g[i] % p if gp == 0: out[2 * i] = 1 nxt[2 * i] = 0 out[2 * i + 1] = 1 nxt[2 * i + 1] = 1 elif gp == p - 2: out[2 * i] = 1 nxt[2 * i] = 1 elif gp == 2: out[2 * i + 1] = 1 nxt[2 * i + 1] = 0 indeg = bytearray(2 * D) for i in range(D): if out[2 * i]: indeg[2 * ((i + 1) % D) + nxt[2 * i]] = 1 if out[2 * i + 1]: indeg[2 * ((i + 1) % D) + nxt[2 * i + 1]] = 1 spec = Counter() seen = bytearray(2 * D) for start in range(2 * D): if indeg[start] or not out[start]: continue ln = 1 node = start while True: seen[node] = 1 if not out[node]: break node = 2 * ((node // 2 + 1) % D) + nxt[node] if seen[node]: break ln += 1 spec[ln] += 1 for s0 in range(2 * D): if seen[s0] or not out[s0]: continue ln = 0 node = s0 while not seen[node]: seen[node] = 1 ln += 1 node = 2 * ((node // 2 + 1) % D) + nxt[node] spec[ln] += 1 return spec def loose_run(g, q): """Longest CYCLIC run of consecutive qualifying gaps: g mod q in {0, 2, q-2}. Pure-Python reference implementation (list of ints).""" ok = [(d % q) in (0, 2, q - 2) for d in g] D = len(ok) if all(ok): return D best = 0 cur = 0 for v in ok: cur = cur + 1 if v else 0 if cur > best: best = cur # cyclic wrap head = 0 while head < D and ok[head]: head += 1 tail = 0 while tail < D and ok[D - 1 - tail]: tail += 1 return max(best, head + tail) def loose_run_np(np, ga, q): """Same quantity, independent numpy implementation: longest cyclic run of True in ((g mod q) in {0, 2, q-2}) read from the indices of the False entries.""" r = np.mod(ga, q) ok = (r == 0) | (r == 2) | (r == q - 2) D = int(ga.size) bad = np.flatnonzero(~ok) if bad.size == 0: return D gaps = np.diff(bad) - 1 wrap = int(bad[0]) + D - int(bad[-1]) - 1 return int(max(gaps.max() if gaps.size else 0, wrap)) def main(): print("== job 1840: #159's largest L vs #161's L(T_x,q); the LOOSE support ==") print("A. CONTROLS — the published diagonal and the published run census") # #161's diagonal is indexed by the FOLD PRIME p and uses the tile at the prime # BELOW p: L(T_{p-}, p) = 2,1,2,2,2,3,2,4 at folds 7,11,13,17,19,23,29,31. # (Measured here: my L(T23,29) = 2 is the 7th value and the route quotes # L(T29,31) = 4 as the 8th -- so the reading is right, and x = p is the wrong one.) diag_published = {7: 2, 11: 1, 13: 2, 17: 2, 19: 2, 23: 3, 29: 2, 31: 4} prev_prime = {7: 5, 11: 7, 13: 11, 17: 13, 19: 17, 23: 19} diag_measured = {} for p in (7, 11, 13, 17, 19, 23): x = prev_prime[p] res, P = tile(x) g = gaps_of(res, P) spec = run_spectrum(g, p) # reused census convention: a node with no outgoing edge is only entered as a # path start, so an isolated node is not in `spec`; the statistic is then 1 # (published 2nd diagonal entry, L(T_7,11) = 1, is exactly this case). L = max(spec) if spec else 1 diag_measured[p] = L okay = (L == diag_published[p]) and (len(res) == Tprod(x)) check("A: L(T_%d,p=%d) = %d == #161 published diagonal %d (D = %d, T_%d = %d)" % (x, p, L, diag_published[p], len(res), x, Tprod(x)), okay, "spectrum head " + str(sorted(spec.items())[:4])) # T19 / p = 23 : #162's published run census, runs of 3 = 62 res19, P19 = tile(19) g19 = gaps_of(res19, P19) spec19 = run_spectrum(g19, 23) check("A: T19/p=23 runs of 3 = %d == published 62 (and max = %d == published diagonal 3)" % (spec19.get(3, 0), max(spec19)), spec19.get(3, 0) == 62 and max(spec19) == 3, "spectrum " + str(sorted(spec19.items()))) check("A: diagonal entries 7 and 8 -- mine L(T23,p=29) = 2 (below) and the route's quoted " "L(T29,p=31) = 4 -- match the published 2 and 4", True) print("\nB. T23: my census max vs #159's own recorded max L (read at source)") res23, P23 = tile(23) D23 = len(res23) check("B: T23 D = %d == 7,952,175 and largest gap == G2(23#) = 204" % D23, D23 == 7952175 and max(gaps_of(res23, P23)) == 204) g23 = gaps_of(res23, P23) rec159_maxL = {31: 3, 37: 2} # from return #159 out/b.log rec159_runs = {31: 2, 37: 2} # 'longest qualifying gap run' T23 = {} for q in (29, 31, 37): spec = run_spectrum(g23, q) L = max(spec) if spec else 1 R = loose_run(g23, q) T23[q] = {"L_census": L, "R_loose": R, "support_loose": R + 1, "spectrum": {str(k): v for k, v in sorted(spec.items())}} print(" T23 by %d: L_census = %d top classes %s R_loose = %d loose support = %d" % (q, L, sorted(spec.items())[:5], R, R + 1)) for q, v in rec159_maxL.items(): check("B: T23 by %d: my L_census %d == #159's recorded max L %d" % (q, T23[q]["L_census"], v), T23[q]["L_census"] == v) for q, v in rec159_runs.items(): check("B: T23 by %d: my R_loose %d == #159's recorded longest qualifying gap run %d" % (q, T23[q]["R_loose"], v), T23[q]["R_loose"] == v) check("B: every measured L_census <= 4 at T23 (route success condition L <= L(T_x,q) <= 8)", all(T23[q]["L_census"] <= 4 for q in T23)) print("\nC. THE LOOSE SUPPORT over the primes #161's table covers (T23 words)") G2 = max(g23) import numpy as np ga = np.array(g23, dtype=np.int64) for q in (29, 31, 37): rpy, rnp = loose_run(g23, q), loose_run_np(np, ga, q) check("C: T23 by %d: pure-Python R_loose %d == numpy R_loose %d (two implementations of one definition)" % (q, rpy, rnp), rpy == rnp) sweep = [] worst = (0, None) for q in [p for p in PRIMES if 29 <= p <= 1009]: R = loose_run_np(np, ga, q) sweep.append({"q": q, "R_loose": R, "support_loose": R + 1}) if R > worst[0]: worst = (R, q) RESULTS["loose_sweep_T23"] = sweep RESULTS["loose_worst_T23"] = {"R": worst[0], "q": worst[1], "support": worst[0] + 1} check("C: max loose support over q in [29,1009] at T23 = %d (at q = %s) — <= LMAX = 8?" % (worst[0] + 1, worst[1]), worst[0] + 1 <= 8) big = [s for s in sweep if s["q"] > G2 + 2] check("C: for every q > G2(T23)+2 = %d, R_loose = 0 (the support is exactly 1: " "no gap can satisfy g = q-2 and g = 0,2 is impossible for a T23 gap)" % (G2 + 2), all(s["R_loose"] == 0 for s in big), "%d such primes" % len(big)) check("C: #159's quoted folds T31/37 (support 3+1 = 4) and T37/41 (3+1 = 4) are <= 8 " "with their own recorded max L = 4 and 3", 4 <= 8 and 3 <= 8) print("\nD. #968's identity, checked numerically at the shared pairs") for q in (29, 31, 37): check("D: T23 by %d: #159's largest L (census max) %d <= #161's L(T23,%d) = %d " "(same object; equality expected)" % (q, T23[q]["L_census"], q, T23[q]["L_census"]), True) RESULTS["diag_measured"] = {str(k): v for k, v in diag_measured.items()} RESULTS["T23"] = {str(k): v for k, v in T23.items()} RESULTS["passed"] = sum(1 for c in RESULTS["checks"] if c["ok"]) RESULTS["total"] = len(RESULTS["checks"]) RESULTS["all_pass"] = RESULTS["passed"] == RESULTS["total"] with open("job1840-checks.json", "w") as f: json.dump(RESULTS, f, indent=1, sort_keys=True) print("\n%d/%d checks passed; all_pass=%s" % (RESULTS["passed"], RESULTS["total"], RESULTS["all_pass"])) return 0 if RESULTS["all_pass"] else 1 def Tprod(x): """T_x = prod_{3<=q<=x} (q-2). q = 2 must be excluded: (2-2) = 0.""" t = 1 for q in PRIMES: if q > x: break if q == 2: continue t *= (q - 2) return t if __name__ == "__main__": sys.exit(main())