#!/usr/bin/env python3 """Job #4551 (route 1 step check): the step's GATE clause, tested against the served screen. The step says: "with the 5th prime's phase fixed to a value killing nothing in the window it must reproduce screen962-L813.json minima on the same classes." A phase t of the 5th prime q = 37 kills the support offset s iff (s + t) mod 37 in {0, 35}. So a phase kills NOTHING iff the two residues {-t, -t-2} are both absent from R = {s mod 37 : s in support}. This script reconstructs the support exactly as the served selector (f361_chordal-triage749.c, `select`) does -- s in 1..L with gcd(a+s,W) = gcd(a+s+2,W) = 1 -- for every row of the served screen, and reports how many of the 37 phases are killing-free per class. Reads: f1841_screen962-L813.json (served with #1841). Writes: gate_scan.json """ import json import math import os import sys from collections import Counter HERE = os.path.dirname(os.path.abspath(__file__)) W = 510510 L = 813 FIFTH = 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 freephases(offs, q=FIFTH): R = {s % q for s in offs} free = [] for t in range(q): r = (-t) % q if (r % q) not in R and ((r - 2) % q) not in R: free.append(t) return free def main(): scr = json.load(open(os.path.join(HERE, "served", "f1841_screen962-L813.json"), encoding="utf-8")) rows = scr["rows"] out = {"W": W, "L": L, "q5": FIFTH, "rows": len(rows)} # gate verification: reconstructed N must equal the served N bad = [] perfree = Counter() free_by_row = {} for r in rows: offs = support(r["a"]) if len(offs) != r["N"]: bad.append((r["a"], r["N"], len(offs))) continue fr = freephases(offs) free_by_row[r["a"]] = len(fr) perfree[len(fr)] += 1 out["N_mismatches"] = bad[:10] out["N_mismatch_count"] = len(bad) out["free_phase_histogram"] = sorted(perfree.items()) out["rows_with_zero_free_phases"] = perfree[0] # the step's named classes hostile50 = sorted(rows, key=lambda r: (r["minima"][3], r["a"]))[:50] relevant = scr["relevant"] froz = scr["frozen_first_a_skipped"] out["hostile50_zero_free"] = [r["a"] for r in hostile50 if free_by_row.get(r["a"]) == 0] out["relevant_zero_free"] = [r["a"] for r in relevant if free_by_row.get(r["a"]) == 0] out["hostile50_minS"] = sorted(r["minima"][3] for r in hostile50) out["hostile50_free_hist"] = sorted(Counter(free_by_row.get(r["a"]) for r in hostile50).items()) out["relevant_free_hist"] = sorted(Counter(free_by_row.get(r["a"]) for r in relevant).items()) out["frozen_first_a_skipped"] = froz out["hostile50"] = [{"a": r["a"], "N": r["N"], "minima": r["minima"], "free_phases": free_by_row.get(r["a"])} for r in hostile50] with open(os.path.join(HERE, "gate_scan.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) print("rows %d; N mismatches %d" % (len(rows), len(bad))) print("free-phase histogram over all rows: %s" % (sorted(perfree.items()),)) print("rows where NO phase of 37 kills nothing: %d of %d" % (perfree[0], len(rows))) print("hostile 50: free-phase histogram %s" % (sorted(Counter(free_by_row.get(r['a']) for r in hostile50).items()),)) print("hostile 50 minS set: %s" % (sorted(set(r["minima"][3] for r in hostile50)),)) print("hostile 50 with zero free phases: %s" % (out["hostile50_zero_free"],)) print("relevant 86: free-phase histogram %s" % (sorted(Counter(free_by_row.get(r['a']) for r in relevant).items()),)) print("relevant 86 with zero free phases: %s" % (out["relevant_zero_free"],)) return 0 if __name__ == "__main__": sys.exit(main())