#!/usr/bin/env python3 """job2729 — bounded next step proposed in return #1936 (job #2723). Question. For the two-class killed-run word, is the joint law of the pairing counts mu = (mu_q)_{q in Q} (how many positions of one killed run each killer q accounts for) determined by the marginals? Decision (pre-registered, before the pilot): * joint entropy H_obs within 0.5 nats of the product-of-marginals model H_prod -> the marginals determine the law; record a scoped obstruction; * H_prod - H_obs >= 1.0 nat -> the joint law carries extra structure; invest in the next corridor row; * in between -> inconclusive at this level; the next row decides. Method (exact until the entropy summary). Full-period kill flag word; killed runs of length >= 2; for each run the count vector over the FIXED coordinate set Q; the observed joint distribution over distinct vectors vs the product of the per-prime marginal distributions of mu_q; Shannon entropies in nats. """ from __future__ import annotations import math import os import sys from collections import Counter from math import prod HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "..", "job2723")) import kstar_bounds as kb def run_count_vectors(P, Q): """Exact list of count vectors (one per killed run of length >= 2) and lengths.""" Q = sorted(Q) idx = {q: i for i, q in enumerate(Q)} slots = kb.tile_slots(P) M = prod(Q) vecs = [] lens = [] cur = None L = 0 for k in range(M): phase = k * P for r in slots: v = r + phase hits = [q for q in Q if v % q == 0 or (v + 2) % q == 0] if hits: if cur is None: cur = [0] * len(Q) L = 0 for q in hits: cur[idx[q]] += 1 L += 1 else: if cur is not None and L >= 2: vecs.append(tuple(cur)) lens.append(L) cur = None L = 0 if cur is not None and L >= 2: vecs.append(tuple(cur)) lens.append(L) return vecs, lens def entropy(counter): n = sum(counter.values()) if n <= 0: return 0.0 return -sum((c / n) * math.log(c / n) for c in counter.values() if c) def product_entropy(vecs, nQ): """Entropy of the product-of-marginals model over the observed vector support.""" n = len(vecs) marg = [Counter() for _ in range(nQ)] for v in vecs: for i in range(nQ): marg[i][v[i]] += 1 dist = {} for v in set(vecs): p = 1.0 for i in range(nQ): p *= marg[i][v[i]] / n dist[v] = p tot = sum(dist.values()) if tot <= 0: return 0.0 return -sum((p / tot) * math.log(p / tot) for p in dist.values() if p > 0) def case(s): P, Q = kb.corridor(s) period = prod(Q) * len(kb.tile_slots(P)) if period > 3_000_000: return {"s": s, "skipped": True, "period": period} vecs, lens = run_count_vectors(P, Q) if len(vecs) < 5: return {"s": s, "runs": len(vecs), "insufficient": True} obs = Counter(vecs) H_obs = entropy(obs) H_prod = product_entropy(vecs, len(Q)) return {"s": s, "P": P, "Q": Q, "period": period, "runs": len(vecs), "distinct": len(obs), "H_obs": H_obs, "H_prod": H_prod, "delta": H_prod - H_obs, "top": [[list(k), v] for k, v in obs.most_common(5)]} if __name__ == "__main__": import json res = [case(s) for s in (7, 9, 10, 11)] for r in res: print(json.dumps(r, default=str)) with open(os.path.join(HERE, "evidence", "multiplicity_joint_evidence.json"), "w", encoding="utf-8") as f: json.dump({"cases": res, "pre_registered": { "date": "2026-09-27", "rule": "delta = H_prod - H_obs; <0.5 nats = marginals determine " "the law (scoped obstruction); >=1.0 nat = joint structure " "present; between = inconclusive at this level"}}, f, indent=2)