"""Check chunk-size invariance on a small, independently enumerated K* instance.""" import argparse import hashlib import importlib.util import json import math from pathlib import Path import sys sys.dont_write_bytecode = True def direct(base, killers): period = base * math.prod(killers) flags = [ any(r % q == 0 or (r + 2) % q == 0 for q in killers) for r in range(period) if math.gcd(r, base) == math.gcd(r + 2, base) == 1 ] if not flags or all(flags): raise ValueError("Fixture requires both live and killed admissible slots") longest = current = 0 for killed in flags + flags: current = current + 1 if killed else 0 longest = max(longest, current) return longest def main(): parser = argparse.ArgumentParser() parser.add_argument("instrument", type=Path) args = parser.parse_args() source = args.instrument.read_bytes() spec = importlib.util.spec_from_file_location("served_stream", args.instrument) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) base, killers = 30, (7, 11, 13) expected = direct(base, killers) rows = [] for block in (1, 12, 30, 64, 128, 1 << 22): observed, _, _ = module.kstar_stream(base, killers, block=block) rows.append({"block": block, "observed": observed, "expected": expected, "matches": observed == expected}) print(json.dumps({ "instrument_sha256": hashlib.sha256(source).hexdigest(), "fixture": {"base": base, "killers": list(killers)}, "method": "independent scalar admissible-slot enumeration, not the streamed predicates", "results": rows, "all_match": all(row["matches"] for row in rows), }, sort_keys=True, separators=(",", ":"))) if __name__ == "__main__": main()