#!/usr/bin/env python3 """Witness extraction: the T29 / p = 31 components of size 4 whose internal gap word refutes clause (c) of the served producer's alternation lemma. Producer a3-08 header, verbatim: THE ALTERNATION LEMMA (PROVEN, and the part A5 wants) ... (a) L >= 3 forces at least one gap >= 4p-2; (b) L >= 2k+1 forces at least k of them; (c) the L-1 gaps inside a run have mean at least 3p - p/(L-1). The component table comes from killcensus, which walks the measured T29 gap word with the producer's streaming machine and prints, per component of size L >= 3, the absolute start slot followed by its L-1 internal gaps. Each witness is then re-verified directly on the gap word by following the kill graph node by node. Corrected clause (c): with a = min(aP, aM) (a = 2p-2 if p = 1 mod 6, a = 2p+2 if p = 5 mod 6), the minimum is 3p when L-1 is even and 3p - (3p-a)/(L-1) when L-1 is odd, where aP is the unique residue that is 2 mod p and 0 mod 6 and aM = 6p - aP. Usage: witness_lemma_c.py """ import sys, json import numpy as np def a_plus(p): a = 2 while a % 6: a += p return a def follow(g, p, start, gaps): """Re-verify a component directly: node (start, sigma=0) -> ... -> end.""" sigma = 0 slot = start trace = [] for w in gaps: assert int(g[slot]) == w sigma = (sigma + w) % p assert sigma in (0, p - 2), f"no edge at slot {slot} sigma {sigma}" trace.append((slot, w, sigma)) slot = (slot + 1) % g.size # no incoming edge at the start (gap before start is inert) prev = int(g[(start - 1) % g.size]) % p assert prev not in (0, 2, p - 2), "start slot has an incoming edge" # no outgoing edge at the end out = int(g[slot]) % p assert out not in (0, 2, p - 2), "end slot has an outgoing edge" return trace def main(): path, out = sys.argv[1], sys.argv[2] g = np.fromfile(path, dtype=np.uint16) p = 31 aP, aM = a_plus(p), 6 * p - a_plus(p) a, b = min(aP, aM), max(aP, aM) thr = 4 * p - 2 comps = [] with open(f"{path}.p{p}.comp.txt") as f: for line in f: t = line.split() if t: comps.append((int(t[0]), [int(x) for x in t[1:]])) l4 = [(s, w) for s, w in comps if len(w) == 3] l4.sort() res = {"p": p, "aP": aP, "aM": aM, "small_a": a, "large_b": b, "threshold_4p_2": thr, "n_components_ge3": len(comps), "size4_witnesses": [], "producer_c_threshold_L4": 3 * p - p / 3, "corrected_threshold_L4": 3 * p - (3 * p - a) / 3} for s, w in l4: trace = follow(g, p, s, w) res["size4_witnesses"].append({ "start_slot": s, "gaps": w, "sum": sum(w), "mean": sum(w) / len(w), "classes": ["Z" if x % p == 0 else "P" if x % p == 2 else "M" for x in w], "trace_slots_residues": [[t[0], t[1], t[2]] for t in trace], }) sums = [sum(w) for _, w in l4] res["size4_sums"] = sums res["all_word_60_126_60"] = all(w == [60, 126, 60] for _, w in l4) res["producer_c_holds"] = all(v / 3 >= 3 * p - p / 3 - 1e-12 for v in sums) res["corrected_c_holds"] = all(v / 3 >= 3 * p - (3 * p - a) / 3 - 1e-12 for v in sums) res["corrected_c_tight"] = all(v / 3 == 3 * p - (3 * p - a) / 3 for v in sums) with open(out, "w") as f: json.dump(res, f, indent=2) print(json.dumps({k: res[k] for k in ("p", "aP", "aM", "small_a", "large_b", "n_components_ge3", "size4_sums", "all_word_60_126_60", "producer_c_threshold_L4", "corrected_threshold_L4", "producer_c_holds", "corrected_c_holds", "corrected_c_tight")}, indent=2)) for w in res["size4_witnesses"]: print(f" witness start_slot={w['start_slot']} gaps={w['gaps']} " f"sum={w['sum']} mean={w['mean']:.6f} classes={w['classes']}") return 0 if __name__ == "__main__": sys.exit(main())