#!/usr/bin/env python3 """Job #4551 (route 1 step check): the four-event screen facts and the frozen sample. Reads: served/f1841_screen962-L813.json the served four-event screen (#1841): 22,256 rows served/f347_chordal-triage749-selection.json the frozen selection (#347) served/f361_chordal-pursuit751-results.json the frozen minima (#361) served/f361_chordal-triage749.c the served sweeper (definitions) Writes: screen_facts.json """ import json import math import os import sys from collections import Counter HERE = os.path.dirname(os.path.abspath(__file__)) S = os.path.join(HERE, "served") W = 510510 L = 813 Q4 = (19, 23, 29, 31) Q5 = 37 def support(a, L=L, W=W): return [s for s in range(1, L + 1) if math.gcd(a + s, W) == 1 and math.gcd(a + s + 2, W) == 1] def free_phases(offs, q=Q5): R = {s % q for s in offs} return [t for t in range(q) if ((-t) % q) not in R and ((-t - 2) % q) not in R] def main(): scr = json.load(open(os.path.join(S, "f1841_screen962-L813.json"), encoding="utf-8")) rows = scr["rows"] out = {"rows": len(rows)} # 1. served header out["header"] = {k: scr[k] for k in ("W", "L", "q", "classes", "frozen_classes_skipped", "shapes_swept", "phases_each", "min_minS", "relevance_histogram", "relevant_shapes", "strict_robust_gain_shapes", "max_gain")} # 2. min B2 == min S on every row, B0 <= BT <= B2 <= S eq = sum(1 for r in rows if r["minima"][2] == r["minima"][3]) chain = sum(1 for r in rows if r["minima"][0] <= r["minima"][1] <= r["minima"][2] <= r["minima"][3]) out["rows_minB2_eq_minS"] = eq out["rows_chain_ok"] = chain out["rows_all"] = len(rows) # 3. relevance histogram recomputed rel = Counter(r["minima"][3] - r["minima"][1] for r in rows) out["relevance_histogram_recomputed"] = sorted(rel.items()) out["relevant_rows_all_gain1"] = all(r["gain"] == 1 for r in scr["relevant"]) # 4. hostile tail = 50 smallest minS hostile50 = sorted(rows, key=lambda r: (r["minima"][3], r["a"]))[:50] out["hostile50_minS_hist"] = sorted(Counter(r["minima"][3] for r in hostile50).items()) out["hostile50_family_minS"] = min(r["minima"][3] for r in hostile50) out["hostile50_family_minB2"] = min(r["minima"][2] for r in hostile50) out["hostile50_family_minBT"] = min(r["minima"][1] for r in hostile50) # 5. support reconstruction + free-phase census Nmis = 0 free = {} for r in rows: offs = support(r["a"]) if len(offs) != r["N"]: Nmis += 1 free[r["a"]] = len(free_phases(offs)) out["N_mismatch_rows"] = Nmis out["free_phase_histogram_all"] = sorted(Counter(free.values()).items()) out["classes_without_free_phase"] = sum(1 for v in free.values() if v == 0) out["hostile50_free_hist"] = sorted(Counter(free[r["a"]] for r in hostile50).items()) out["hostile50_without_free_phase"] = [r["a"] for r in hostile50 if free[r["a"]] == 0] out["relevant_without_free_phase"] = [r["a"] for r in scr["relevant"] if free[r["a"]] == 0] out["relevant_free_hist"] = sorted(Counter(free[r["a"]] for r in scr["relevant"]).items()) # 6. the frozen sample: starts, reconstructed supports, free phases, published minima froz_starts = scr["frozen_first_a_skipped"] out["frozen_starts"] = froz_starts out["frozen_N"] = [len(support(a)) for a in froz_starts] out["frozen_free_phases"] = [len(free_phases(support(a))) for a in froz_starts] sel = json.load(open(os.path.join(S, "f347_chordal-triage749-selection.json"), encoding="utf-8")) res = json.load(open(os.path.join(S, "f361_chordal-pursuit751-results.json"), encoding="utf-8")) key_sel = [k for k in ("selected", "shapes", "rows") if isinstance(sel, dict) and k in sel] out["selection_keys"] = sorted(sel.keys()) if isinstance(sel, dict) else "list" out["selection_sel_key"] = key_sel if key_sel: out["selection_first"] = json.dumps(sel[key_sel[0]][:2])[:400] out["results_keys"] = sorted(res.keys()) if isinstance(res, dict) else "list" # frozen minima as published (#361 nests them under "result"; #347's completed a=46841 is not # in #361's list and is published in the served pilot file) mins = [] for t in res.get("results", []): if isinstance(t, dict) and "result" in t: mins.append({"a": t["a"], "minima": t["result"]["minima"]}) pilot = json.load(open(os.path.join(S, "f347_chordal-triage749-pilot.json"), encoding="utf-8")) mins.append({"a": sel["selected"][0]["a"], "minima": pilot["minima"], "from": "pilot#347"}) out["frozen_minima_published"] = mins out["frozen_minB2_eq_minS"] = all(m["minima"][2] == m["minima"][3] for m in mins) out["frozen_family_minS"] = min((m["minima"][3] for m in mins), default=None) with open(os.path.join(HERE, "screen_facts.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) for k in sorted(out): v = out[k] s = json.dumps(v) print("%-34s %s" % (k, s if len(s) < 300 else s[:300] + "...")) return 0 if __name__ == "__main__": sys.exit(main())