#!/usr/bin/env python3 """job #1381 -- measure the gap between the two readings of K*(Q) on the same object. phase_span.c is period_check.c with one added argument: the number of blocks to stream. BLOCKS = 1 -> the m = 0 block alone = the ANCHORED phase tuple (kill iff r = 0 or -2 mod q), read cyclically across the tile seam. BLOCKS = 0 (=prod) -> all phase tuples = the MAX, i.e. period_check.c's K* and the object the route's definition (and #609's theorem, and route 27's identity) use. Path-relative: the binary is built next to this file. """ import pathlib import subprocess BASE = pathlib.Path(__file__).resolve().parent BIN = BASE / "phase_span" CASES = [ (5, [7]), (5, [7, 11]), (7, [11]), (7, [11, 13]), (7, [11, 13, 17]), (11, [13]), (11, [13, 17]), (11, [13, 17, 19]), (13, [17]), (13, [17, 19]), (13, [17, 19, 23]), ] def run(level, blocks, Q): """returns (closed, linear) for the given block limit. `closed` joins the leading and trailing runs across the scanned stretch's seam -- legitimate only at the true period (blocks = prod(Q)), which is what period_check.c always used. `linear` is the run measured inside the stretch with no closure, i.e. the honest value of a single anchored block. """ cmd = [str(BIN), str(level), str(blocks)] + [str(q) for q in Q] r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: return None, None, r.stderr.strip()[:60] closed = linear = None for line in r.stdout.splitlines(): if "K*(Q)=" in line: closed = int(line.split("K*(Q)=")[1].split()[0]) linear = int(line.split("linear=")[1].split()[0]) return closed, linear, "" print(f"{'level':>5} {'Q':<14} {'prod(Q)':>8} {'anchored':>8} {'anch-cyc':>8} {'phase-max':>9} {'gap':>5}") print("-" * 62) rows = [] for level, Q in CASES: _ac, a, err = run(level, 1, Q) # anchored block: use the LINEAR reading m, _ml, err2 = run(level, 0, Q) # full period: seam-closed is the true K* prod = 1 for q in Q: prod *= q if a is None or m is None: print(f"{level:>5} {str(Q):<14} {prod:>8} ERROR {err}{err2}") continue rows.append((level, tuple(Q), prod, a, _ac, m)) print(f"{level:>5} {str(Q):<14} {prod:>8} {a:>8} {_ac:>8} {m:>9} {m - a:>5}") differ = [r for r in rows if r[3] != r[5]] print() print(f"cases: {len(rows)} the two readings differ in {len(differ)}/{len(rows)}") print("anchored (linear) is never larger than the phase-max:", all(r[3] <= r[5] for r in rows)) print("the cyclic closure of a single block can exceed the phase-max:", any(r[4] > r[5] for r in rows)) print(f"largest gap: {max((r[5] - r[3]) for r in rows)}")