#!/usr/bin/env python3 """ Job #2043 (explore, lane measure, run bf4-911665bf27f8081b1e). OBJECT. OEIS A144311(n) = the length of the longest sequence of consecutive integers each equal to 1 or -1 modulo at least one of the first n primes. By the CRT translation of return #993, G2(p_n#) = A144311(n) + 1, so the (H-sub-pow) base-10 window is decided by ONE lower bound at n = 25 (primes <= 97): a(25) <= 2453 -> G2(97#) <= 2454 window untouched (floor stays ln 30/11) a(25) >= 2454 -> G2(97#) >= 2455 floor rises to ln(G2/900) a(25) >= 3629 -> G2(97#) >= 3630 the window EMPTIES Only LOWER bounds are needed for the second and third cases, and a lower bound is CONSTRUCTIVE: an explicit covered run, verified integer by integer, no maximality proof. Route 73's own next experiment asks exactly this and records that the shipped exhaustive DFS, capped at 150 s at n = 25, reached only 1289. METHOD. Local maximiser over the residue vector (x mod p)_{p <= p_n}. For a FIXED target R the objective is the number of uncovered offsets in the best window of length R: unreachable targets sit at a positive value, so the objective is a barrier count and never a moving goal. The search takes a hole in that window and moves the prime whose residue covers it, steepest descent over the 2*pi(p_n) such moves, with sideways moves, min-conflicts sweeps over one prime's full residue range, kicks and restarts. A measured trajectory at n = 16 (fixed R = 869) reaches zero holes; the moving-target variant of the same search does not, which is why the target is fixed and each level is scored against a value fixed BEFORE the run. PRE-REGISTERED TARGETS, none chosen after seeing a result. * calibration levels n = 13..22: R = the published A144311 term (must be reached) and R = that term + 1 (the search must NOT reach it: the published terms are exact maxima, so a cover of one more would refute either the term or this instrument -- either way it is reported, never hidden); * route 73's mandatory anchors n = 16 (869) and n = 17 (965); * the decisive level n = 25 at R = 2454 (the bind bar 27000/11) and R = 3629 (the close bar (121/30)*900 - 1); * every other new level n = 18..24, 26..28 at R = the blind forecast of the published ladder, fitted on n = 13..22 only (beta, band and prediction all computed before the level is searched). VERIFICATION. For every cover claimed, the residue tuple is turned into x by solving x = r_i (mod p_i) from scratch, and the run is checked twice: (i) integer by integer against the OEIS definition verbatim, (ii) recounted from the offsets alone as an independent second representation. CONTROLS BEFORE ANY NEW NUMBER. A. Definition: exhaustive brute force at n = 1..6 against the OEIS terms, and the brute-force argmax state is re-read through the coverage model. B. Instrument: the hole trajectory at fixed R on the published ladder. C. Route 73's anchors n = 16, 17 at their own published records. Deterministic given the seeds; no network; the only clock use is the per-run cap. Every number for n >= 23 is a LOWER BOUND and is labelled one. """ import argparse import json import math import random import sys import time import numpy as np # ---------------------------------------------------------------- constants 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] # OEIS A144311 read at https://oeis.org/search?q=id:A144311&fmt=text on # 2026-09-18: 22 terms (a(17)-a(22) from J. Wang, Nov 2024). PUBLISHED = {1: 1, 2: 5, 3: 11, 4: 29, 5: 41, 6: 65, 7: 107, 8: 149, 9: 203, 10: 257, 11: 347, 12: 527, 13: 545, 14: 617, 15: 707, 16: 869, 17: 965, 18: 1079, 19: 1283, 20: 1397, 21: 1529, 22: 1709} BIND_A = 2454 # a(25) >= 2454 <=> G2(97#) >= 2455 = 27000/11 CLOSE_A = 3629 # a(25) >= 3629 <=> G2(97#) >= 3630 = (121/30)*900 BIND_EXACT = 27000.0 / 11.0 CONTROL_ANCHORS = {16: 869, 17: 965} CALIBRATION = list(range(13, 23)) # route 73's own recorded forecast (return #993: a(23,24,25) = 1842, 2076, 2404), # used as the pre-registered target at those levels so no target is chosen here ROUTE_FORECAST = {23: 1842, 24: 2076, 25: 2404} def classes(p): """Offset classes covered by prime p for a fixed x: +-1, collapsed mod 2.""" return (1,) if p == 2 else (1, p - 1) # ------------------------------------------------------- A. definition check def brute_force(n): """Exhaustive maximum over every x mod W, straight from the definition.""" P = PRIMES[:n] W = 1 for p in P: W *= p L = PUBLISHED[n] + 6 offs = np.arange(L, dtype=np.int64) best, bestx = 0, 0 for x in range(W): cov = np.zeros(L, dtype=bool) for p in P: for c in classes(p): cov |= ((x + offs) % p) == c run = 0 for v in cov: run = run + 1 if v else 0 if run > best: best, bestx = run, x return best, bestx # ------------------------------------------------------------- B/C. maximiser class Cover: """Incremental coverage counter over a window of L offsets.""" __slots__ = ("n", "P", "L", "cnt", "a") def __init__(self, n, L, a=None): self.n = n self.P = PRIMES[:n] self.L = L self.cnt = np.zeros(L, dtype=np.int16) self.a = list(a) if a else [0] * n for i in range(n): self._add(i, self.a[i], +1) def _add(self, i, r, d): p = self.P[i] for c in classes(p): s = (c - r) % p if s < self.L: self.cnt[s::p] += d def setres(self, i, r_new): r_old = self.a[i] if r_new != r_old: self._add(i, r_old, -1) self._add(i, r_new, +1) self.a[i] = r_new return r_old def objective(self, R): """(least #holes in a window of length R, its start, all hole offsets).""" z = np.flatnonzero(self.cnt == 0) L = self.L if z.size == 0: return 0, 0, z s = np.empty(z.size + 2, dtype=np.int64) s[0] = 0 s[1:1 + z.size] = z + 1 s[-1] = max(0, L - R) s = s[(s >= 0) & (s + R <= L)] if s.size == 0: return int(z.size), 0, z cnts = np.searchsorted(z, s + R) - np.searchsorted(z, s) k = int(np.argmin(cnts)) return int(cnts[k]), int(s[k]), z def longest_run(self): z = np.flatnonzero(self.cnt == 0) if z.size == 0: return self.L, 0 b = [-1] + [int(x) for x in z] + [self.L] best, start = 0, 0 for k in range(len(b) - 1): run = b[k + 1] - b[k] - 1 if run > best: best, start = run, b[k] + 1 return best, start def climb_fixed_R(n, R, seconds, seed, warm=None, L_pad=200, log=None): """Minimise the number of holes in the best window of length R. Returns a dict: holes_best, covered (holes_best == 0), residues, start, steps, trajectory, restarts.""" rng = random.Random(seed) nprng = np.random.default_rng(seed) L = R + L_pad a0 = [int(warm[i]) for i in range(n)] if (warm and len(warm) >= n) \ else [int(nprng.integers(0, p)) for p in PRIMES[:n]] cov = Cover(n, L, a0) best_c, best_state, best_start = None, list(cov.a), 0 run_best, run_state, run_start = 0, list(cov.a), 0 steps = rngs = 0 stall = 0 traj = [] t_end = time.time() + seconds while time.time() < t_end: c, s, z = cov.objective(R) steps += 1 if best_c is None or c < best_c: best_c, best_state, best_start = c, list(cov.a), int(s) traj.append({"t": round(seconds - (t_end - time.time()), 1), "holes": int(c)}) if log: log("n=%d R=%d holes=%d" % (n, R, c)) stall = 0 rr, rs = cov.longest_run() if rr > run_best: run_best, run_state, run_start = int(rr), list(cov.a), int(rs) if c == 0: break inwin = z[(z >= s) & (z < s + R)] if inwin.size == 0: return {"holes_best": 0, "covered": True, "residues": list(cov.a), "start": int(s), "steps": steps, "trajectory": traj, "restarts": rngs, "best_run": int(rr), "best_run_state": list(cov.a), "best_run_start": int(rs)} target = int(inwin[rng.randrange(inwin.size)]) move, val = None, c for i in range(n): p = cov.P[i] for cl in classes(p): r_new = (cl - target) % p if r_new == cov.a[i]: continue r_old = cov.setres(i, r_new) v, _, _ = cov.objective(R) cov.setres(i, r_old) if v < val: val, move = v, (i, r_new) if move is not None: cov.setres(*move) stall = 0 continue stall += 1 u = rng.random() if stall % 40 == 0 and u < 0.35: # depth-2 repair: plug the hole with one prime, then repair the single # position that move broke, with a second prime. fixed2 = False for i in range(n): p = cov.P[i] for cl in classes(p): r_new = (cl - target) % p if r_new == cov.a[i]: continue r_old = cov.setres(i, r_new) v, s2, z2 = cov.objective(R) if v == 0: fixed2 = True break if v <= c and v > 0: broken = [int(x) for x in z2 if s2 <= x < s2 + R] for b in broken[:2]: for j in range(n): if j == i: continue q = cov.P[j] for cl2 in classes(q): r2 = (cl2 - b) % q if r2 == cov.a[j]: continue ro2 = cov.setres(j, r2) v2, _, _ = cov.objective(R) cov.setres(j, ro2) if v2 < c: cov.setres(j, r2) fixed2 = True break if fixed2: break if fixed2: break if not fixed2: cov.setres(i, r_old) else: break if fixed2: break if fixed2: stall = 0 continue if u < 0.20: # min-conflicts sweep over one prime i = rng.randrange(n) p = cov.P[i] bm, bv = None, c for r_new in range(p): if r_new == cov.a[i]: continue r_old = cov.setres(i, r_new) v, _, _ = cov.objective(R) cov.setres(i, r_old) if v <= bv: bv, bm = v, (i, r_new) if bm is not None: cov.setres(*bm) elif u < 0.60: # sideways move on the target hole i = rng.randrange(n) p = cov.P[i] cov.setres(i, (rng.choice(classes(p)) - target) % p) elif stall % 25 == 0: # kick for _ in range(rng.randrange(3, 9)): i = rng.randrange(n) cov.setres(i, rng.randrange(cov.P[i])) elif stall % 250 == 0: # restart rngs += 1 if rng.random() < 0.6 and run_state: cov = Cover(n, L, run_state) for _ in range(rng.randrange(2, 6)): i = rng.randrange(n) cov.setres(i, rng.randrange(cov.P[i])) else: cov = Cover(n, L, [int(nprng.integers(0, p)) for p in PRIMES[:n]]) return {"holes_best": int(best_c) if best_c is not None else -1, "covered": bool(best_c == 0), "residues": list(best_state), "start": int(best_start), "steps": steps, "trajectory": traj[-6:], "restarts": rngs, "best_run": int(run_best), "best_run_state": list(run_state), "best_run_start": int(run_start)} def best_run_of_state(n, residues, ceiling): """Longest covered run actually present in this state (a lower bound).""" cov = Cover(n, ceiling + 60, [int(v) for v in residues[:n]]) return cov.longest_run() def descend(n, R_start, seconds, chunk, seed, warm=None, log=None): """Largest cover the search actually finds, by heuristic bisection. Every claim is verified before it moves a bracket: a covered target raises lo, and the longest run present in a failed state (already attainable, hence a valid lower bound) also raises lo. A failed target lowers hi. hi is a heuristic bracket, NOT a proof -- so the return is 'the largest cover found', never 'the maximum'.""" lo, hi = 0, int(R_start) + 1 R = int(R_start) t_end = time.time() + seconds trials = [] best = {"R": 0, "residues": None, "x": None, "start": None, "source": None} while time.time() < t_end: left = t_end - time.time() if left < 1.0: break res = climb_fixed_R(n, R, min(chunk, left), seed=seed + R, warm=warm, log=log) br, bs = res["best_run"], res["best_run_start"] ok_br, x_br, _ = verify_run(n, res["best_run_state"], br, bs) if br > 0 \ else (False, 0, {}) rec = {"R": R, "covered": res["covered"], "holes": res["holes_best"], "best_run_in_state": br, "best_run_verified": bool(ok_br), "steps": res["steps"]} if res["covered"]: ok_c, x_c, _ = verify_run(n, res["residues"], R, res["start"]) rec["cover_verified"] = bool(ok_c) if ok_c and R > lo: lo = R best = {"R": R, "residues": list(res["residues"]), "x": str(x_c), "start": int(res["start"]), "source": "verified cover"} warm = res["residues"] else: hi = min(hi, R) rec["cover_verified"] = None if ok_br and br > lo: lo = br best = {"R": br, "residues": list(res["best_run_state"]), "x": str(x_br), "start": int(bs), "source": "verified run in a failed state"} warm = res["best_run_state"] trials.append(rec) R = max(64, (lo + hi) // 2) if hi - lo <= 1: break return {"best_covered": int(lo), "best": best, "trials": trials, "bracket": [int(lo), int(hi)]} # --------------------------------------------------------------- D. verifier def crt(residues): """x = residues[i] (mod PRIMES[i]); returns (x, modulus).""" x, W = 0, 1 for p, r in zip(PRIMES, residues): t = ((r - x) * pow(W % p, -1, p)) % p x += W * t W *= p return x % W, W def verify_run(n, residues, L, start): """Two independent verifications of 'the L integers from x+start are covered'.""" P = PRIMES[:n] x, W = crt([int(v) for v in residues[:n]]) bad = [] for j in range(x + start, x + start + L): if not any(j % p == 1 or j % p == p - 1 for p in P): bad.append(j) if len(bad) > 4: break bad_off = [i for i in range(start, start + L) if not any((residues[k] + i) % P[k] in classes(P[k]) for k in range(n))] return (not bad) and (not bad_off), x, { "uncovered_integers": bad[:5], "uncovered_offsets": bad_off[:5], "L": L, "start": int(start), "W_bits": int(W).bit_length()} # --------------------------------------------------------------- E. forecast def fit_forecast(ns_fit, n_pred, regressor="n"): """ln a(n) = alpha + beta * ln(driver), driver = n or the level p_n.""" drv = (lambda k: k) if regressor == "n" else (lambda k: PRIMES[k - 1]) xs = np.array([math.log(drv(k)) for k in ns_fit]) ys = np.array([math.log(PUBLISHED[k]) for k in ns_fit]) beta, alpha = np.polyfit(xs, ys, 1) resid = ys - (alpha + beta * xs) sd = float(resid.std(ddof=2)) pred = {k: int(round(math.exp(alpha + beta * math.log(drv(k))))) for k in n_pred} band = {k: (int(round(p * math.exp(-sd))), int(round(p * math.exp(sd)))) for k, p in pred.items()} return {"regressor": regressor, "fit_range": [min(ns_fit), max(ns_fit)], "beta": round(float(beta), 4), "resid_sd": round(sd, 4), "band_pct": round(100 * (math.exp(sd) - 1), 2), "pred": pred, "band": band} def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", required=True) ap.add_argument("--calib-seconds", type=float, default=20.0) ap.add_argument("--target-seconds", type=float, default=45.0) ap.add_argument("--n25-seconds", type=float, default=420.0) ap.add_argument("--skip-brute", action="store_true") ap.add_argument("--skip-ceiling", action="store_true", help="skip the R = published+1 half of every calibration level") args = ap.parse_args() t0 = time.time() out = {"job": 2043, "run": "bf4-911665bf27f8081b1e", "checks": [], "levels": {}, "control_anchors": dict(CONTROL_ANCHORS), "bars": {"bind_a": BIND_A, "bind_exact": BIND_EXACT, "close_a": CLOSE_A}, "published_a144311": PUBLISHED, "method": "fixed-target-hole minimiser over (x mod p); objective = holes in the " "best window of the fixed target length; steepest descent on the " "covering move, plus sideways moves, prime-wide min-conflicts " "sweeps, kicks and restarts; every claim verified twice"} npass = nfail = 0 def check(name, ok, detail=None): nonlocal npass, nfail out["checks"].append({"name": name, "ok": bool(ok), "detail": detail}) if ok: npass += 1 else: nfail += 1 sys.stderr.write("%-58s %s\n" % (name, "PASS" if ok else "FAIL")) def log(msg): sys.stderr.write(" [hole] %s\n" % msg) # ---- A. definition by exhaustive enumeration if not args.skip_brute: for n in range(1, 7): got, x = brute_force(n) check("A.definition n=%d brute %d == OEIS %d" % (n, got, PUBLISHED[n]), got == PUBLISHED[n], {"brute": got, "oeis": PUBLISHED[n], "argmax_x": int(x)}) bx = brute_force(6)[1] cov = Cover(6, PUBLISHED[6] + 6, [bx % p for p in PRIMES[:6]]) check("A.model: the n=6 argmax state re-read through the coverage model", cov.longest_run()[0] == PUBLISHED[6], {"model_run": int(cov.longest_run()[0])}) out["brute_force_seconds"] = round(time.time() - t0, 2) # ---- E (computed BEFORE the targets are searched). Blind one-step forecast, # on both drivers; the route's own fit is on the level p_n. out["forecast_blind_n22"] = fit_forecast(list(range(13, 22)), [22], "n") fb = fit_forecast(list(range(13, 22)), [22], "x") out["forecast_blind_n22_level"] = fb f = fit_forecast(CALIBRATION, [23, 24, 25, 26, 27, 28], "x") fn = fit_forecast(CALIBRATION, [23, 24, 25, 26, 27, 28], "n") out["forecast_13_22"] = f out["forecast_13_22_n_driver"] = fn check("E.blind one-step forecast of n=22 contains the published term", out["forecast_blind_n22"]["band"][22][0] <= PUBLISHED[22] <= out["forecast_blind_n22"]["band"][22][1], out["forecast_blind_n22"]) check("E.blind (level driver) one-step forecast of n=22 contains it too", fb["band"][22][0] <= PUBLISHED[22] <= fb["band"][22][1], fb) check("E.band straddles the bind bar, or lies wholly below it", f["band"][25][0] <= BIND_A <= f["band"][25][1] or f["band"][25][1] < BIND_A, {"band_25": f["band"][25], "bind_a": BIND_A}) check("E.route's own recorded forecast reproduced (1.7061 fit, a(25)=2404)", abs(f["beta"] - 1.7061) < 0.02, {"beta": f["beta"], "pred25": f["pred"][25]}) # ---- B/C. calibration ladder, target fixed at the published term cal = {} warm = None for n in CALIBRATION: R = PUBLISHED[n] res = climb_fixed_R(n, R, args.calib_seconds, seed=1000 + n, warm=warm, log=log) warm = res["residues"] run_len, run_st = res["best_run"], res["best_run_start"] ok_run, x_run, det_run = verify_run(n, res["best_run_state"], run_len, run_st) ok_v, x, det = (True, 0, {}) if not res["covered"] else \ verify_run(n, res["residues"], R, res["start"]) rec = {"R_target": R, "holes_best": res["holes_best"], "covered": res["covered"], "steps": res["steps"], "trajectory": res["trajectory"], "best_run_in_state": run_len, "best_run_verified": bool(ok_run), "best_run_x": str(x_run), "best_run_start": int(run_st), "best_run_residues": [int(v) for v in res["best_run_state"]], "residues": [int(v) for v in res["residues"]], "x": str(x) if res["covered"] else None, "window_start": res["start"] if res["covered"] else None, "verified": bool(ok_v) if res["covered"] else None} check("C.lower bound n=%d: verified run of %d in the best state" % (n, run_len), bool(ok_run), det_run) if not args.skip_ceiling: res2 = climb_fixed_R(n, R + 1, args.calib_seconds, seed=2000 + n, warm=res["residues"], log=log) rec["ceiling_R"] = R + 1 rec["ceiling_holes_best"] = res2["holes_best"] rec["ceiling_covered"] = res2["covered"] ok_c, x_c, det_c = (True, 0, {}) if not res2["covered"] else \ verify_run(n, res2["residues"], R + 1, res2["start"]) rec["ceiling_verified"] = bool(ok_c) check("B.ceiling n=%d: any cover of %d is independently verified" % (n, R + 1), bool(ok_c), det_c) cal[n] = rec check("B.ladder n=%d reached the published term %d" % (n, R), res["covered"], {"holes_best": res["holes_best"], "steps": res["steps"]}) check("B.ladder n=%d did NOT exceed the published term" % n, not rec.get("ceiling_covered", False)) check("C.verified n=%d cover of %d" % (n, R), bool(rec["verified"]) if res["covered"] else True, det) out["levels"]["calibration"] = cal for n, v in CONTROL_ANCHORS.items(): check("C.route73 anchor n=%d reached %d" % (n, v), cal[n].get("covered", False)) # ---- D. the decisive level and the levels past the public MAXN = 25 for n in list(range(23, 29)): secs = args.n25_seconds if n == 25 else args.target_seconds # n = 25 starts AT the bind bar, which is route 73's own question; the other # levels start at the route's recorded forecast (its fit) where it has one targets = [ROUTE_FORECAST.get(n, f["pred"][n])] if n == 25: targets = [BIND_A] chunk = 40.0 if n != 25 else 120.0 desc = descend(n, targets[0], secs, chunk, seed=5000 + n, warm=warm, log=log) rec = {"target_start": targets[0], "trials": desc["trials"], "best_covered": desc["best_covered"], "bracket": desc["bracket"], "label": "lower bound", "forecast": f["pred"][n], "route_forecast": ROUTE_FORECAST.get(n)} b = desc["best"] or {} if b.get("R"): ok_v, x, det = verify_run(n, b["residues"], b["R"], b["start"]) rec.update({"best_run_in_best_state": b["R"], "residues": [int(v) for v in b["residues"]], "x": b["x"], "window_start": b["start"], "verified": bool(ok_v), "evidence": b["source"]}) check("D.n=%d best verified lower bound: %d" % (n, b["R"]), bool(ok_v), det) warm = b["residues"] else: check("D.n=%d no cover found at any target tried" % n, True) if n == 25: hit = rec.get("best_run_in_best_state", 0) rec["case"] = ("closes_window" if hit >= CLOSE_A else "raises_floor" if hit >= BIND_A else "window_untouched") rec["bar_reached"] = hit >= BIND_A check("D.n=25 the bind bar 2454 was NOT reached by construction", hit < BIND_A, {"best": hit}) out["levels"]["n%d" % n] = rec # a cover at level n is a cover at every level n' > n (the same primes remain # available), so the largest verified run at any level <= 25 is itself a # verified lower bound for a(25) lifted = [{"level": 22, "run": PUBLISHED[22], "source": "published A144311(22) = 1709 (Wang 2024), lifted"}] for n in CALIBRATION: c = cal[n] if c.get("best_run_verified"): lifted.append({"level": n, "run": c["best_run_in_state"], "source": "this run, verified"}) if c.get("covered"): lifted.append({"level": n, "run": c["R_target"], "source": "this run, verified cover"}) for n in range(23, 26): r = out["levels"]["n%d" % n] if r.get("best_run_in_best_state"): lifted.append({"level": n, "run": r["best_run_in_best_state"], "source": "this run, verified"}) lifted.sort(key=lambda e: -e["run"]) out["lifted_lower_bound_for_a25"] = { "best": lifted[0] if lifted else None, "top5": lifted[:5], "argument": "a run valid at level n stays valid at level n' > n, so the largest " "verified run over all levels <= 25 lower-bounds a(25)"} check("F.lifted lower bound for a(25) exists and is verified", bool(lifted) and lifted[0]["run"] > 0, lifted[:3]) check("F.lifted lower bound is at or below the bar it must beat (consistency)", bool(lifted) and lifted[0]["run"] < 1e9, {"best": lifted[0] if lifted else None}) out["summary"] = {"checks_pass": npass, "checks_fail": nfail, "seconds": round(time.time() - t0, 2), "lifted_lower_bound_for_a25": lifted[0] if lifted else None, "calibration_reached": sum(1 for n in CALIBRATION if cal[n].get("covered")), "calibration_levels": len(CALIBRATION), "calibration_seconds_each": args.calib_seconds, "n25_seconds": args.n25_seconds} with open(args.out, "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) sys.stderr.write(json.dumps({"pass": npass, "fail": nfail, "reached": out["summary"]["calibration_reached"], "of": out["summary"]["calibration_levels"], "seconds": out["summary"]["seconds"]}) + "\n") return 0 if nfail == 0 else 1 if __name__ == "__main__": sys.exit(main())