#!/usr/bin/env python3 """Audit the four saved Numaro covering designs using the Python standard library. Checks every block and the recorded R4 source partition for all four files. Checks every required subset for C(92,7,4). The other three coverage claims remain conditional on the validity of the original LJCR source coverings. This audit does not check a current leaderboard or certify those large sources. """ import argparse import hashlib import itertools import json import math from pathlib import Path EXPECTED = { "77_25_8.json": (77, 25, 8, 179223, 175063), "79_21_7.json": (79, 21, 7, 165213, 165027), "86_23_7.json": (86, 23, 7, 153683, 153047), "92_7_4.json": (92, 7, 4, 132580, 131122), } def audit(path, expected): raw = path.read_bytes() record = json.loads(raw) v, k, t, baseline, count = expected if tuple(record[key] for key in ("v", "k", "t", "ljcr", "ours")) != expected: raise ValueError(f"{path.name}: metadata differs from the recorded result") blocks = record["blocks"] if len(blocks) != count or count >= baseline: raise ValueError(f"{path.name}: incorrect block count or comparison") seen = set() added_point_count = 0 for block in blocks: if (len(block) != k or len(set(block)) != k or any(type(point) is not int or not 1 <= point <= v for point in block)): raise ValueError(f"{path.name}: malformed block") key = tuple(sorted(block)) if key in seen: raise ValueError(f"{path.name}: duplicate block") seen.add(key) added_point_count += v in block del seen source_a, source_b = record["sources"] if (source_a[:3] != [v - 1, k - 1, t - 1] or source_b[:3] != [v - 1, k, t] or added_point_count != source_a[3] or count - added_point_count != source_b[3]): raise ValueError(f"{path.name}: R4 partition differs from the recorded sources") total = math.comb(v, t) result = { "file": path.name, "sha256": hashlib.sha256(raw).hexdigest(), "v": v, "k": k, "t": t, "baseline": baseline, "blocks": count, "saved": baseline - count, "subsets": total, "sources": record["sources"], "structureChecked": True, "sourcePartitionChecked": True, "coverageExhaustive": t == 4, "uncovered": None, } if t == 4: # Combinatorial-number-system ranks give each t-subset its own byte. binomial = [[math.comb(n, r) if n >= r else 0 for r in range(t + 1)] for n in range(v)] covered = bytearray(total) for block in blocks: for subset in itertools.combinations(sorted(point - 1 for point in block), t): rank = sum(binomial[point][i + 1] for i, point in enumerate(subset)) covered[rank] = 1 result["uncovered"] = total - sum(covered) if result["uncovered"]: raise ValueError(f"{path.name}: {result['uncovered']} subsets are uncovered") return result def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--blocks-dir", type=Path, default=Path(__file__).parent / "beats") parser.add_argument("--json", action="store_true") args = parser.parse_args() try: results = [audit(args.blocks_dir / name, expected) for name, expected in EXPECTED.items()] except (OSError, ValueError, KeyError, TypeError) as error: parser.exit(1, f"Audit failed: {error}\n") if args.json: print(json.dumps(results, indent=2)) return for result in results: cell = f"C({result['v']},{result['k']},{result['t']})" print(f"{cell}: {result['blocks']:,} distinct, well-formed blocks; R4 partition matches") if result["coverageExhaustive"]: print(f" EXHAUSTIVE: {result['uncovered']:,} / {result['subsets']:,} subsets uncovered") else: print(" CONDITIONAL COVERAGE: R4 requires valid original LJCR source coverings") print("Audit complete. This is a historical comparison, not a current-record check.") if __name__ == "__main__": main()