#!/usr/bin/env python3 """Independent checks of iecell output where no sieve exists. (1) mirror symmetry: r -> -r-2 maps T_x to itself and reverses the gap word, so N(a,b) = N(b,a); iecell computes the two from different constellations {0,a,a+b} and {0,b,a+b}. (2) marginals: sum_{b<=A-a} N(a,b) <= h_a, sum_{a<=A} h_a <= D. (3) sample cells recomputed by #1918's ie4256.py (big-int Python, separate implementation). Usage: check4301.py c41.json ... -> JSON line per file.""" import json, sys, subprocess ie = sys.argv[1] SAMPLE = [(60, 60), (6, 12), (60, 114), (114, 60), (54, 60), (174, 60)] for f in sys.argv[2:]: d = json.load(open(f)); A = d["A"]; x = d["x"] N = {(a, b): c for a, b, c in d["pairs1"]}; h = {int(k): v for k, v in d["hist"].items()} asym = sum(1 for a in range(6, A + 1, 6) for b in range(6, A - a + 1, 6) if N.get((a, b), 0) != N.get((b, a), 0)) rowbad = sum(1 for a in range(6, A + 1, 6) if sum(N.get((a, b), 0) for b in range(6, A - a + 1, 6)) > h.get(a, 0)) neg = sum(1 for c in list(N.values()) + list(h.values()) if c < 0) hsum_ok = sum(h.values()) <= d["D"] py = {} for a, b in SAMPLE: r = json.loads(subprocess.run([sys.executable, ie, str(x), str(a), str(b)], capture_output=True, text=True, check=True).stdout) py["%d,%d" % (a, b)] = r["count"] == N.get((a, b), 0) print(json.dumps({"x": x, "A": A, "asymmetric_cells": asym, "rows_over_h": rowbad, "negative": neg, "hist_sum_le_D": hsum_ok, "ie4256_py_equal": py}))