# phaseinc1919.py

-- direct check of the phase-incidence reading of the fold count on the tile T_x at fold p: # for each phase b in 0..p-1, count adjacent slot pairs (r, r') of T_x (cyclic) with BOTH r and r' killed by phase b, # where phase b kills residues s with (s+b) mod p in {0, p-2}. Report per-phase counts, their sum, and the two # histogram functionals: pairs = #{g : g = 0, +-2 mod p} and incidences = #{g = +-2} + 2 #{g = 0}. # Algebra: a pair with gap g = 0 (mod p) is killed together by exactly 2 phases, a pair with g = +-2 by exactly 1. import sys, math, json, time import numpy as np PR = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] x = int(sys.argv[1]); p = int(sys.argv[2]); ps = [q for q in PR if q <= x]; P = math.prod(ps) SEG = 1 << 24; t0 = time.time() per_phase = np.zeros(p, dtype=np.int64); carry = None; first = None; last = None g0 = gpm2 = 0 for lo in range(0, P, SEG): hi = min(P, lo + SEG); m = hi - lo keep = np.ones(m, dtype=bool) for q in ps: keep[(-lo) % q::q] = False; keep[(q - 2 - lo) % q::q] = False pos = np.flatnonzero(keep).astype(np.int64) + lo if not len(pos): continue if first is None: first = int(pos[0]) res = (pos % p).astype(np.int64) if carry is not None: res_all = np.concatenate(([carry], res)); pos_all = np.concatenate(([last], pos)) else: res_all = res; pos_all = pos d = np.diff(pos_all) % p; g0 += int(np.count_nonzero(d == 0)); gpm2 += int(np.count_nonzero((d == 2) | (d == p - 2))) for b in range(p): k = (res_all == (-b) % p) | (res_all == (-b - 2) % p) per_phase[b] += int(np.count_nonzero(k[:-1] & k[1:])) carry = int(res[-1]); last = int(pos[-1]) # cyclic wrap pair (last -> first + P) rw = np.array([last % p, (first + P) % p]); gw = (first + P - last) % p g0 += int(gw == 0); gpm2 += int(gw in (2, p - 2)) for b in range(p): k = (rw == (-b) % p) | (rw == (-b - 2) % p); per_phase[b] += int(k[0] and k[1]) S = int(per_phase.sum()) out = {'x': x, 'p': p, 'pairs_g0': g0, 'pairs_gpm2': gpm2, 'pairs_total': g0 + gpm2, 'incidences_sum_over_phases': S, 'identity_holds': S == gpm2 + 2 * g0, 'per_phase': per_phase.tolist(), 'max_phase': int(per_phase.max())} print(f"x={x} p={p}: pairs with g=0: {g0}, g=+-2: {gpm2}, total pairs {g0+gpm2}; sum over phases of both-killed adjacent pairs = {S}; identity S = pairs(+-2) + 2*pairs(0): {S == gpm2 + 2*g0}; max over phases {int(per_phase.max())}") print(f"wall {round(time.time() - t0, 1)}s", file=sys.stderr) json.dump(out, open(f'phaseinc1919-x{x}-p{p}.json', 'w'))