#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Job #1410 (route 27): an INDEPENDENT |Q| = {p} covering-capacity instrument, used as the falsification test route 27 itself names -- "one entry of #161's grid that an independent level-x, Q = {p} instrument does not reproduce refutes the identity as stated". Difference from the lane that produced the numbers. Return #637/#640 decided rows with the gap-tuple reduction and then a two-state (parity) automaton over the gap sequence, both of which consume the gaps of the tile. This file never looks at a gap: for each prime p and each translate a it takes the literal definition straight off the tile, killed(r) <=> r mod p in {a, a+2}, slot r in T_x (r, r+2 both coprime to x#) and asks for the longest run of *consecutive slots* that is entirely killed, L(T_x, p) = max_a max cyclic run length of consecutive killed slots (free translate) The max over a is the "free translate" the route says K*'s phase freedom supplies, so this is the left-hand side of the identity computed the way the definition reads, with no structural shortcut. Runs are found with bytes.translate + a regex (C speed), so |T_23| = 7 952 175 slots is affordable. Checks run here: (A) the eight-entry diagonal of the brief, L(T_{p-}, p) = 2,1,2,2,2,3,2,4 at folds 7..31, entries with x <= 23 recomputed by the direct instrument (the two entries with x = 29, 31 need the 29# / 31# tiles, ~6.2e9 / 1.9e11 slots, and are reported infeasible on this machine); (B) direct instrument vs the two-state automaton of work/job1406/screen.py on the same tiles, so the two lanes are compared on primes the diagonal does not cover; (C) the tile against the corpus anchors |T_19| = 378 675, |T_23| = 7 952 175, and #627's T_23 gap inventory (33 distinct gaps, 6..204), which pins the tile builder to the corpus's tile. Usage: python3 direct-capacity.py [--out dir] [--quick] """ import argparse, json, re, time from pathlib import Path def allowed_classes(p): """Residues r mod p with r and r+2 both coprime to p (the tile's admissible classes).""" return [c for c in range(p) if c % p != 0 and (c + 2) % p != 0] def build_tile(level): """Sorted admissible residues mod (2*3*...*level) by incremental CRT, |T_x| = prod_{3<=q<=x}(q-2). Copied unchanged from work/job1406/screen.py (same builder the #640 row came from).""" res, M = [1], 2 chain = [] p = 3 while p <= level: cls = allowed_classes(p) inv = pow(M % p, -1, p) new = [] for r in res: base = r for c in cls: new.append(base + M * (((c - r) * inv) % p)) res, M = new, M * p chain.append((p, len(res))) p += 2 while p <= level and any(p % q for q in range(3, int(p ** 0.5) + 1, 2)) is False: p += 2 res.sort() return res, M, chain def gaps_of(res, M): n = len(res) g = [0] * n g[0] = res[0] + M - res[n - 1] for i in range(1, n): g[i] = res[i] - res[i - 1] return g def direct_row(res, primes): """The definition straight off the tile: max over translates a of the longest cyclic run of consecutive slots whose residues mod p all lie in {a, a+2}. No gaps, no automaton.""" n = len(res) out = {} for p in primes: payload = bytes(r % p for r in res) * 2 # slot residues, doubled for cyclicity best, best_a = 0, None for a in range(p): a2 = (a + 2) % p tbl = bytearray(256) # 0 everywhere except the two killed classes tbl[a] = 1 tbl[a2] = 1 flags = payload.translate(bytes(tbl)) m = 0 for mt in re.finditer(b"\x01+", flags): L = mt.end() - mt.start() if L > m: m = L if m > n: m = n # a cyclic run cannot exceed the period if m > best: best, best_a = m, a out[p] = {"L": 1 + best, "run": best, "translate": best_a} return out def row_by_automaton(g, primes): """The lane's own instrument (from work/job1406/screen.py), kept verbatim for the cross-check.""" n = len(g) gg = list(g) * 2 out = {} for p in primes: cmap = {} l0 = l2 = 0 best = 0 for j in range(2 * n - 1, -1, -1): c = gg[j] % p cl = cmap.get(c) if cl is None: cl = 0 if c == 0 else 1 if c == 2 else 2 if c == p - 2 else 3 cmap[c] = cl if cl == 0: n0, n2 = 1 + l0, 1 + l2 elif cl == 1: n0, n2 = 1 + l2, 0 elif cl == 2: n0, n2 = 0, 1 + l0 else: n0 = n2 = 0 l0, l2 = n0, n2 if j < n and max(n0, n2) > best: best = max(n0, n2) out[p] = 1 + best return out def isprime(p): return p > 1 and all(p % q for q in range(2, int(p ** 0.5) + 1)) def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default=".") ap.add_argument("--quick", action="store_true", help="skip the T_23 tile") a = ap.parse_args() out = Path(a.out) out.mkdir(parents=True, exist_ok=True) rec = {"job": 1410, "route": 27, "instrument": "direct max-over-translate on the tile", "tiles": {}, "diagonal": {}, "cross_check": {}, "anchors": {}, "seconds": {}, "observed_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} # (A) the brief's diagonal, L(T_{p-}, p) for folds 7..31 diag = [(7, 11, 2), (11, 13, 1), (13, 17, 2), (17, 19, 2), (19, 23, 2), (23, 29, 3), (29, 31, 2), (31, 37, 4)] t0 = time.time() levels = {} for x, p, want in diag: if x > 23: rec["diagonal"][f"T_{x},p={p}"] = { "expected": want, "measured": None, "agrees": None, "note": "tile has prod(q-2) = %d slots; not affordable here" % _count(x)} continue if a.quick and x > 19: rec["diagonal"][f"T_{x},p={p}"] = {"expected": want, "measured": None, "agrees": None, "note": "skipped by --quick"} continue ts = time.time() res, M, chain = build_tile(x) g = gaps_of(res, M) got = direct_row(res, [p]) levels[x] = (res, M, g, chain) rec["tiles"][f"T_{x}"] = {"period_M": M, "slots": len(res), "fold_chain_tail": chain[-1], "build_s": round(time.time() - ts, 1)} rec["diagonal"][f"T_{x},p={p}"] = {"expected": want, "measured": got[p]["L"], "run": got[p]["run"], "translate": got[p]["translate"], "agrees": got[p]["L"] == want} print(f"diagonal T_{x}, p={p}: direct instrument L={got[p]['L']} (brief says {want}) " f"agree={got[p]['L'] == want} [{(time.time()-ts):.1f}s]", flush=True) rec["seconds"]["diagonal"] = round(time.time() - t0, 1) # (C) anchors: the corpus's own tile facts (#627 for the T_23 inventory) if 19 in levels: rec["anchors"]["|T_19|"] = {"measured": len(levels[19][0]), "corpus": 378675} if 23 in levels: res23, M23, g23, _ = levels[23] rec["anchors"]["|T_23|"] = {"measured": len(res23), "corpus": 7952175} rec["anchors"]["T_23_gap_inventory"] = {"distinct": len(set(g23)), "min": min(g23), "max": max(g23), "corpus": "33 distinct, 6..204"} # (B) cross-check the two instruments on the same tiles, primes the diagonal does not cover for x in (19, 23): if x not in levels: continue res, M, g, _ = levels[x] primes = [q for q in range(x + 1, 48) if isprime(q)] t1 = time.time() direct = direct_row(res, primes) auto = row_by_automaton(g, primes) same = all(direct[q]["L"] == auto[q] for q in primes) rec["cross_check"][f"T_{x}"] = { "primes": primes, "direct": {str(q): direct[q]["L"] for q in primes}, "automaton": {str(q): auto[q] for q in primes}, "agree": same, "seconds": round(time.time() - t1, 1)} print(f"cross-check T_{x}: direct == automaton on primes {primes}: {same} " f"[{time.time()-t1:.1f}s]", flush=True) print(" direct :", [direct[q]["L"] for q in primes]) print(" automaton:", [auto[q] for q in primes]) rec["seconds"]["total"] = round(time.time() - t0, 1) (out / "direct-capacity.json").write_text(json.dumps(rec, indent=1), encoding="utf-8") print("wrote", out / "direct-capacity.json") def _count(x): c, p, q = 1, 3, x while p <= x: c *= p - 2 p += 2 while p <= x and any(p % r == 0 for r in range(3, int(p ** 0.5) + 1, 2)): p += 2 return c if __name__ == "__main__": main()