#!/usr/bin/env python3 """ Job #1850 (explore, route-less rescue of return #23 "tailcount-transport"). WHAT THIS TESTS --------------- Return #23's headline negative is that its exact per-level evaluator "does not chain": (a) the gap histogram is not closed under folding (0 of 50 shuffles), and (b) a fixed-index truncation of the window family prints a constant against a diverging truth. Review #71 (gpt-6-astra, trusted) rejects the manuscript and corrects both: the old *word* does determine the next folded word (positions recoverable up to translation; CRT fixes the shift), so only *scalar* summaries fail to iterate; and dropping the positive right-hand terms of an upper-bound inequality is not an admissible step at all, so (b) is evidence about an invalid object. The obstruction, restated: what blocks a per-fold *certificate* is not where the data comes from, it is the SHAPE of the relaxation. Theorem 1 bounds a TAIL N_new(theta) <= (q-2) N(theta) + 2 sum_{L>=1} Q_L(theta), and the L-range of that tail is what diverges (the window frame fails on the L=1 term, ~39 nats over 233 folds). But the transfer operator is an EQUALITY with an exact total mass, so the same object has a complementary HEAD form. With L_i(theta) = min{ L >= 0 : G_{L+1}(i) >= theta } (G_m(i) = g_i + ... + g_{i+m-1}) the operator identity plus the proven mass identity sum_L nu_q(i,L) = q-2 give, exactly, N_new(theta) = D(q-2) - H(theta), H(theta) = sum_i sum_{L < L_i(theta)} nu_q(i,L). No inequality is introduced. The head has length <= K(theta) by the run-cost cap (Cor A1: c_min(m) = 3qm - (q+2 eta)[m odd]), and H is a count of SHORT windows. This script builds both tiles from the definitions (no corpus producer), extracts nu_q(i,L) directly from the folded tile's own gaps, and measures: (1) CUSTODY: the operator identity N_new = sum_i sum_L [G_{L+1}(i)>=theta] nu, at several theta, and the mass identity sum_L nu_q(i,L) = q-2 at every i. (2) the head identity N_new(theta) = D(q-2) - H(theta) at theta = q^2 and theta = G_2. (3) the LOAD-BEARING question: what fraction of the D(q-2) new gaps sits in the head at theta = q^2, i.e. is "bound the short windows" a live route or a vacuous one. (4) the review's item-4 finiteness input: mbar(T_r) <= 2r, min qualifying gap theta0 = 2q - 2eta, longest qualifying run R, and R <= D-1. (5) the review's item-3 counterexample: the abstract q=7 window (24,30), sum 54 >= 49, with empty interior -- reported for what it is (a statement about the relaxation, not about a primorial tile). PRE-REGISTERED FALSIFIERS (registered before this file was first run) F1 custody: the operator identity must hold at every theta on every fold. If it fails, the nu extraction is wrong and NOTHING below is interpretable. F2 custody: sum_L nu_q(i,L) = q-2 for every old slot i, every fold. F3 custody: N_new(theta) = D(q-2) - H(theta) at every theta tested. F4 LOAD-BEARING (AMENDED -- the first registration was vacuous, disclosed): as first written F4 asked for the head share of the mass at theta = q^2. That is 1.0000 at every fold for a trivial reason: the certificate G_2(T_q) < q^2 HOLDS at every measured fold, so N_new(q^2) = 0 and the head is complete. The informative reading is the THETA-TIGHT one, and the real question is what the head is made of. F4 as amended: at the tight threshold theta = G_2(T_q) (where N_new > 0 and the head is 1 - nmax/D(q-2)), report the split of H into the L = 0 part (plain short old gaps, a first-moment object) and the L >= 1 part (short windows with dead interiors). If the L >= 1 share is small at every fold, a first-moment + cap argument can plausibly lower-bound H and the head route is live. If it is ~1 everywhere, the head route inherits the tail's difficulty and the bounded negative stands. F5 the review's finiteness claim: R <= D-1, and mbar(T_r) <= 2r at every fold. F6 the certificate reading: N_new(q^2) = D(q-2) - H(q^2), so "G_2(T_q) < q^2" is equivalent to "H(q^2) = D(q-2)" (the deficit is read off, not assumed). Usage: python head-form-transport.py [--max-fold 5] [--json OUT] """ import argparse, io, json, sys, time import numpy as np sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace") PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] def primorial(p): r = 1 for x in PRIMES: r *= x if x == p: return r raise ValueError(p) def live_slots(W, primes): """T_x: residues r mod W with gcd(r,W)=1 and gcd(r+2,W)=1 (twin coprime pair set).""" ok = np.ones(W, dtype=bool) for p in primes: ok[0::p] = False sh = np.ones(W, dtype=bool) for p in primes: sh[(-2) % p::p] = False return np.flatnonzero(ok & sh) def fold(x, q): """Build T_x and T_{xq} directly; extract nu_q(i,L) from the folded tile's own gaps.""" px = [p for p in PRIMES if p <= x] pq = [p for p in PRIMES if p <= q] W, Wq = primorial(x), primorial(q) old = live_slots(W, px) D = int(old.size) pos = live_slots(Wq, pq) Dn = int(pos.size) assert Dn == D * (q - 2), (Dn, D, q - 2) # old gap word (cyclic) g_old = np.diff(np.concatenate([old, old[:1] + W])).astype(np.int64) # new gap word (cyclic) nxt = np.concatenate([pos[1:], pos[:1] + Wq]) g_new = (nxt - pos).astype(np.int64) # map each new gap's start/end to old slot indices idx = np.full(W, -1, dtype=np.int32) idx[old] = np.arange(D, dtype=np.int32) istart = idx[pos % W].astype(np.int64) iend = idx[(nxt % W)].astype(np.int64) assert (istart >= 0).all() and (iend >= 0).all() step = (iend - istart) % D # step = number of old slots from the start slot round to the end slot. # step = 1 -> one old gap, no interior (L = 0). # step = 0 -> the window wraps the whole period: interior is D-1 slots (L = D-1), # which is the case q*W itself appears as a gap (the referee's # "an entire big period contains a live slot" boundary). L = (step - 1) % D assert (L >= 0).all() and (L <= D - 1).all() big = np.int64(D + 1) key = istart * big + L uk, cnt = np.unique(key, return_counts=True) ui = (uk // big).astype(np.int64) uL = (uk % big).astype(np.int64) nu = cnt.astype(np.int64) # cumulative sums of the old word twice round, for G_{L+1}(i) cs = np.concatenate([[0], np.cumsum(np.concatenate([g_old, g_old]))]) maxL = int(uL.max()) wsum_all = cs[ui + uL + 1] - cs[ui] # Review item 3 / Fact 2: every COUNTED window (nu > 0) with L >= 1 has an # alternation-legal interior, so Cor A1's cap must hold at its own window sum. cap_all = 1 + (wsum_all + q + 2) // (3 * q) selL = uL >= 1 res_cap_viol = int((uL[selL] > cap_all[selL]).sum()) res_tail_Lrange = int(uL.max()) if uL.size else 0 def window_sum(theta): """RHS of the operator: sum_i sum_L [G_{L+1}(i) >= theta] nu_q(i,L).""" sel = wsum_all >= theta return int(nu[sel].sum()), int(sel.sum()) # head length L_i(theta) = min{L : G_{L+1}(i) >= theta}; cs is strictly increasing, # so one global searchsorted gives every i at once. def head(theta): j = np.searchsorted(cs, cs[:D] + theta, side="left") # j is the first index with cs[j] >= cs[i] + theta; G_{L+1}(i) = cs[i+L+1]-cs[i], # so L_i(theta) = j - i - 1 (>= j > i, so this is >= 0). Lt = np.clip(j - np.arange(D) - 1, 0, D) # L <= D-1 is all there is keep = uL < Lt[ui] H = int(nu[keep].sum()) maxhead = int(Lt.max()) # split of the head: L = 0 (plain short old gaps) vs L >= 1 (short windows # with at least one dead interior slot) H0 = int(nu[(uL == 0) & keep].sum()) return H, maxhead, H0 res = {"cap_violations_review_item3": res_cap_viol, "counted_window_L_range": res_tail_Lrange, "cap_at_q2": 1 + (q * q + q + 2) // (3 * q), "x": x, "q": q, "W": W, "Wq": Wq, "D": D, "D_new": Dn, "q2": q * q, "G2_old": int(g_old.max()), "G2_new": int(g_new.max()), "mbar_old": float(W / D), "mbar_new": float(Wq / Dn), "max_prime_le_x": max(px), "nu_sum_by_i_ok": bool(len(np.unique(np.bincount(ui, weights=nu, minlength=D))) == 1 and np.bincount(ui, weights=nu, minlength=D)[0] == q - 2), "nu_rows": int(uk.size)} # F5: qualifying-gap structure eta = 1 if q % 6 == 1 else -1 theta0 = 2 * q - 2 * eta qual = np.isin(g_old % q, [0, q - 2, 2]) res["eta"] = eta res["theta0_min_qualifying_gap"] = int(theta0) res["min_qualifying_gap_present"] = int(g_old[qual].min()) if qual.any() else None res["num_nonqualifying"] = int((~qual).sum()) # longest cyclic run of qualifying gaps if (~qual).any(): ext = np.concatenate([qual, qual]) best = cur = 0 for v in ext: cur = cur + 1 if v else 0 best = max(best, cur) R = int(best) else: R = D res["R_longest_qualifying_run"] = int(R) res["R_le_D_minus_1"] = bool(R <= D - 1) res["mbar_le_2r"] = bool(W / D <= 2 * max(px)) # (5) the review's abstract window at q = 7 if q == 7: pairs = set() for i in range(D): pairs.add((int(g_old[i]), int(g_old[(i + 1) % D]))) res["has_adjacent_pair_24_30"] = (24, 30) in pairs res["sum24_30_vs_q2"] = 24 + 30 >= q * q # (1)+(2)+(3)+(6): theta sweep rows = [] for theta in sorted({int(g_new.max()), q * q, (q * q) // 2, (q * q) // 4, 2 * q * q}): N_new = int((g_new >= theta).sum()) rhs, n_win = window_sum(theta) H, maxhead, H0 = head(theta) rows.append({"theta": int(theta), "N_new": N_new, "operator_rhs": rhs, "operator_identity_ok": rhs == N_new, "n_counted_windows": n_win, "cap_corA1": 1 + (theta + q + 2) // (3 * q), "head_mass_H": H, "head_max_L": int(maxhead), "head_L0_mass": H0, "head_Lge1_mass": H - H0, "head_Lge1_share_of_head": (H - H0) / H if H else None, "head_identity_ok": N_new == Dn - H, "head_fraction": H / Dn}) res["rows"] = rows return res def main(): ap = argparse.ArgumentParser() ap.add_argument("--max-fold", type=int, default=6) ap.add_argument("--json", default=None) a = ap.parse_args() FOLDS = [(5, 7), (7, 11), (11, 13), (13, 17), (17, 19), (19, 23)] out = [] t0 = time.time() for k, (x, q) in enumerate(FOLDS[:a.max_fold], 1): t = time.time() r = fold(x, q) r["seconds"] = round(time.time() - t, 2) out.append(r) rowq2 = [w for w in r["rows"] if w["theta"] == r["q2"]][0] print("fold %-2d -> %-2d D %-9d D_new %-11d G2_new %-4d | nu identity %s " "| op identity %s | head id %s | head frac at q^2 %.4f (max L %d, cap %d) " "| R %d <= D-1 %s | mbar<=2r %s | %.1fs" % (x, q, r["D"], r["D_new"], r["G2_new"], r["nu_sum_by_i_ok"], all(w["operator_identity_ok"] for w in r["rows"]), all(w["head_identity_ok"] for w in r["rows"]), rowq2["head_fraction"], rowq2["head_max_L"], rowq2["cap_corA1"], r["R_longest_qualifying_run"], r["R_le_D_minus_1"], r["mbar_le_2r"], r["seconds"])) print(" N_new(q^2) = %d (certificate 'G2 < q^2' holds iff this is 0)" % rowq2["N_new"]) print("\n---- falsifier verdicts ----") F1 = all(w["operator_identity_ok"] for r in out for w in r["rows"]) F2 = all(r["nu_sum_by_i_ok"] for r in out) F3 = all(w["head_identity_ok"] for r in out for w in r["rows"]) fr = [w["head_fraction"] for r in out for w in r["rows"] if w["theta"] == r["q2"]] F4 = "LIVE (>=0.90 everywhere)" if min(fr) >= 0.90 else ( "VACUOUS (<=0.50 everywhere)" if max(fr) <= 0.50 else "INTERMEDIATE") F5 = all(r["R_le_D_minus_1"] and r["num_nonqualifying"] > 0 for r in out) print("F1 operator identity every theta/fold :", "PASS" if F1 else "FAIL") print("F2 sum_L nu = q-2 every slot/fold :", "PASS" if F2 else "FAIL") print("F3 head identity every theta/fold :", "PASS" if F3 else "FAIL") print("F4 head share of mass at theta=q^2 :", F4, "min %.4f max %.4f" % (min(fr), max(fr)), "(vacuous: the certificate holds at every measured fold)") # amended F4: composition of the head at the tight threshold print("F4' head composition at theta = G_2(T_q):") for r in out: w = [z for z in r["rows"] if z["theta"] == r["G2_new"]][0] print(" fold %2d->%2d head %d/%d (%.5f) L=0 part %.5f of head L>=1 part %.5f of head" % (r["x"], r["q"], w["head_mass_H"], r["D_new"], w["head_fraction"], 1 - w["head_Lge1_share_of_head"], w["head_Lge1_share_of_head"])) print("review item 3 cap on counted windows (L >= 1):", "no violation at any fold" if all(r["cap_violations_review_item3"] == 0 for r in out) else "VIOLATIONS %s" % [r["cap_violations_review_item3"] for r in out]) print("counted-window L range per fold:", [r["counted_window_L_range"] for r in out], "vs cap at q^2:", [r["cap_at_q2"] for r in out]) print("F5 R <= D-1 and a non-qualifying gap exists :", "PASS" if F5 else "FAIL") print("total %.1fs" % (time.time() - t0)) if a.json: json.dump({"folds": out, "F1": F1, "F2": F2, "F3": F3, "F4": F4, "head_fraction_at_q2": fr}, open(a.json, "w"), indent=1) print("wrote", a.json) if __name__ == "__main__": main()