#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Producer for job #4524 (route 173): the 23# -> 47# finite maxsum certificate. Writes certificate.json. Deterministic; numpy + stdlib only. The heavy step is the exact all-start exclusion of length 22 over D = 7 952 175 base starts (root-capacity necessary test + exact backtracking cover search); the length-21 ladder rungs below it are recorded as well. """ import json import sys import time import numpy as np sys.path.insert(0, ".") import tile_cover_crt as T BASE = 23 S = 24 TOP = 47 Q = [p for p in T.primes_upto(TOP) if p > S] assert Q == [29, 31, 37, 41, 43, 47], Q t0 = time.process_time() a, W = T.twin_slots(BASE) D = int(len(a)) base_gap = T.base_gap(a, W) ladder = [] K = None witness = None for m in range(32, 18, -1): tt = time.process_time() r = T.scan_all(a, W, m, Q, stop_first=True) ladder.append({"m": m, "root_pass": int(r["root_pass"]), "backtracked": int(r["backtracked"]), "covers": int(r["covers"]), "cpu_s": round(time.process_time() - tt, 3)}) print("m", m, ladder[-1], flush=True) if r["covers"] > 0: K = m i, asg = r["first"] c, M = T.crt_copy(W, Q, asg) ok_kill, surv, ngap = T.verify_run(a, W, Q, i, K, c) if i + K <= D: pos = [int(x) for x in a[i:i + K]] pl = int(a[i - 1]) if i > 0 else int(a[-1]) - W pr = int(a[i + K]) if i + K < D else int(a[0]) + W else: pos = [int(a[(i + j) % D]) + ((i + j) // D) * W for j in range(K)] pl = int(a[(i - 1) % D]) + ((i - 1) // D) * W pr = int(a[(i + K) % D]) + ((i + K) // D) * W witness = {"start": int(i), "positions": pos, "copy": str(c), "modulus": str(M), "assignment": {str(q): int(asg[q]) for q in Q}, "neighbour_left": pl, "neighbour_right": pr, "neighbour_gap": int(pr - pl), "all_killed": bool(ok_kill), "neighbours_survive": bool(all(surv))} break assert K is not None, "no cover found in the ladder -- the procedure would continue downward" maxsum_m = K + 1 ms = T.maxsum(a, W, maxsum_m) from fractions import Fraction ratio = Fraction(ms, base_gap) cert = { "schema": "job4524-doubling-certificate-v1", "route_id": 173, "s": S, "base_prime": BASE, "W": int(W), "D": D, "base_gap": int(base_gap), "Q": Q, "K": int(K), "excluded_length": int(K + 1), "maxsum_m": int(maxsum_m), "maxsum": int(ms), "ratio_num": int(ratio.numerator), "ratio_den": int(ratio.denominator), "ratio_decimal": float(ratio), "m8_holds": bool(ratio <= 8), "upper_bound": next(d for d in ladder if d["m"] == K + 1), "ladder": ladder, "witness": witness, "cpu_seconds": round(time.process_time() - t0, 3), "calibration_note": ("D_19 = 378675, base gap 150, K*=13 (top 37) and K*=20 (top 43), " "maxsum14 = 570, maxsum21 = 750 reproduce the published values of " "return #2017 / the doubling-bridge note; the base gaps 150 (19#) and " "204 (23#) are the corpus ladder values."), } with open("certificate.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(cert, fh, indent=1) print("certificate.json written; K =", K, "maxsum", ms, "ratio", ratio, float(ratio), "cpu", cert["cpu_seconds"])