# crt.py - JOB #637: independent re-enumeration of the CRT bookkeeping that # return #152's target note rests on (derive-0904-L7-transfer.md section 2, and # redteam-0904-item0.md 6.2). No import of the note's producer; own sieve. # Checks, at x = 7, 11, 13: # (a) the number of holes (residues coprime to W = x#) # (b) for each odd p <= x, the count of holes h with h = -2 (mod p) # against the CRT value phi(W)/(p-1) # (c) the union-bound budget B(x) = sum_{3<=p<=x} 1/(p-1), and whether B > 1 # (d) the exact fraction of holes that are NOT twin slots, against the closed # form 1 - prod_{3<=p<=x} (p-2)/(p-1) # Deterministic: stdout only, no timing, no randomness. from fractions import Fraction for x in (7, 11, 13): P = [] for n in range(2, x + 1): if all(n % p for p in P): P.append(n) W = 1 for p in P: W *= p hole = bytearray(W) holes = 0 for r in range(W): if all(r % p for p in P): hole[r] = 1 holes += 1 notTwin = 0 for r in range(W): if hole[r] and not hole[(r + 2) % W]: notTwin += 1 B = Fraction(0) rows = [] for p in P: if p == 2: continue c = 0 for r in range(W): if hole[r] and (r + 2) % p == 0: c += 1 crt = Fraction(holes, p - 1) B += Fraction(1, p - 1) rows.append(" p=%2d: count %5d, phi(W)/(p-1) = %5s, %s" % (p, c, crt, "EQUAL" if c == crt else "MISMATCH")) closed = Fraction(1) for p in P: if p != 2: closed *= Fraction(p - 2, p - 1) closed = 1 - closed print("x = %2d, W = %d, holes = phi(W) = %d" % (x, W, holes)) for r in rows: print(r) print(" union-bound budget B(%d) = %s = %.4f of holes; %s" % (x, B, float(B), "VACUOUS (B > 1)" if B > 1 else "non-vacuous (B <= 1)")) print(" holes that are NOT twin slots = %d (%.4f of holes); closed form " "1 - prod (p-2)/(p-1) = %s = %.4f; %s" % (notTwin, notTwin / holes, closed, float(closed), "AGREE" if Fraction(notTwin, holes) == closed else "DISAGREE")) print()