#!/usr/bin/env python3 """job 2752/2753 -- independent recheck of the witness window decomposition for one row. Question: for P=30, U={7,11,13,17,19,23}, q=7, is the filed decomposition consistent? The window's positions must partition into (killed by R) and (killed by U\\R), so |R| + |U\\R| must equal the window length. The filed witness says length 19, |R| = 9 (runs 3,2,1,1,1,1), and "q supplies 5" -- 9+5 = 14, which is not a partition, so at least one of the three numbers is wrong. This recomputes all of them from the definitions, with explicit parentheses (an earlier version of THIS script mis-parenthesised `inR & (a | b)` and produced a third, wrong number). """ import importlib.util import json import os import sys import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) spec = importlib.util.spec_from_file_location("km", os.path.join(HERE, "killer-marginal.py")) km = importlib.util.module_from_spec(spec) spec.loader.exec_module(km) def kill_sel(slots, v): return ((slots % v) == 0) | (((slots + 2) % v) == 0) def main(): P = 30 U = (7, 11, 13, 17, 19, 23) q = 7 R = tuple(v for v in U if v != q) L = P for v in U: L *= v alive = np.tile(km.slot_pattern(P), L // P) aidx = np.flatnonzero(alive) n = int(aidx.size) fU = km.killed_mask(L, U)[aidx] fR = km.killed_mask(L, R)[aidx] # locate the winning union run: starts/ends are RANKS among the killed positions, so the window # in compressed (alive-position) coordinates is idx[start_rank] .. idx[end_rank] idx = np.flatnonzero(fU) brk = np.flatnonzero(np.diff(idx) != 1) starts = np.concatenate(([0], brk + 1)) ends = np.concatenate((brk, [idx.size - 1])) lens = idx[ends] - idx[starts] + 1 k = int(lens.argmax()) r0, r1, ln = int(starts[k]), int(ends[k]), int(lens[k]) winpos = idx[r0:r1 + 1] assert int(winpos.size) == ln slots = aidx[winpos] inR = fR[winpos] qk = kill_sel(slots, q) both = int((inR & qk).sum()) qonly = int((qk & ~inR).sum()) ronly = int((inR & ~qk).sum()) union = int((inR | qk).sum()) per = {str(v): int(kill_sel(slots, v).sum()) for v in U} res = {"P": P, "U": list(U), "q": q, "n_alive_positions": n, "window_ranks": [r0, r1], "window_positions": [int(winpos[0]), int(winpos[-1])], "window_length": ln, "killed_by_R": int(inR.sum()), "killed_by_q": int(qk.sum()), "both": both, "q_only": qonly, "R_only": ronly, "union_R_or_q": union, "fU_true_on_window": int(fU[winpos].sum()), "per_prime_in_window": per} print(json.dumps(res, indent=1)) print("\nPARTITION CHECK: R_only %d + q_only %d + both %d = %d vs window %d (%s)" % (ronly, qonly, both, ronly + qonly + both, ln, "OK" if ronly + qonly + both == ln else "MISMATCH")) print("union(R or q) = %d vs fU on window = %d (%s)" % (union, int(fU[winpos].sum()), "OK" if union == ln and int(fU[winpos].sum()) == ln else "MISMATCH")) return 0 if __name__ == "__main__": sys.exit(main())