"""Independent check of Step 6 (the load-bearing unconditional remainder bound) of attack-0829n-X-upper.md, at the note's own engine-identity anchor Q = 9281. Step 6 asserts: for squarefree d | P(z), d > 1, r_d = A_d - C * g(d), g(d) = 2^omega(d)/d, C = A_1, |r_d| < B(d) = 3 * 2^omega(d) * (1 + 1/d), using only that A is an interval in fixed residue classes (no equidistribution). The note reports max |r_d|/B(d) = 0.4600 over its own 3702 moduli x 1227 anchors. This is a fresh implementation (pure Python) of A_d, r_d and B(d). """ import math import sys def is_prime(n): if n < 2: return False if n % 2 == 0: return n == 2 i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True def main(): Q = int(sys.argv[1]) if len(sys.argv) > 1 else 9281 DDRIVE = int(sys.argv[2]) if len(sys.argv) > 2 else 701 assert is_prime(Q) Qp = Q + 1 while not is_prime(Qp): Qp += 1 lo, hi = Q * Q, Qp * Qp A = [a for a in range(lo, hi - 2) if a % 30 in (11, 17, 29) and lo <= a + 2 < hi] C = len(A) print(f"Q={Q} Q'={Qp} |A| = C = {C}") # actives: primes >= 7 (P(z) is their product up to z) actives = [p for p in range(7, DDRIVE + 1) if is_prime(p)] activ_set = set(actives) # squarefree d <= DDRIVE whose prime factors are all actives def sf_allowed(d): n, f = d, 2 ps = [] while f * f <= n: if n % f == 0: ps.append(f) n //= f if n % f == 0: return None f += 1 if n > 1: ps.append(n) if any(p not in activ_set for p in ps): return None return ps worst = (0.0, None) checked = 0 for d in range(2, DDRIVE + 1): ps = sf_allowed(d) if ps is None: continue checked += 1 # d | a(a+2) <=> for every p | d: a = 0 or -2 (mod p) Ad = sum(1 for a in A if all(a % p == 0 or (a + 2) % p == 0 for p in ps)) g = (2 ** len(ps)) / d r = Ad - C * g B = 3 * (2 ** len(ps)) * (1 + 1 / d) ratio = abs(r) / B if ratio > worst[0]: worst = (ratio, d, Ad, r, B) print(f"checked {checked} squarefree d <= {DDRIVE} built from actives >= 7") print(f"max |r_d|/B(d) = {worst[0]:.4f} at d = {worst[1]}") print(f" A_d={worst[2]} r_d={worst[3]:.6f} B(d)={worst[4]:.6f}") print("Step 6 bound |r_d| < B(d) holds strictly:", worst[0] < 1.0) print("(note reports max 0.4600 over its own 3702 moduli x 1227 anchors)") if __name__ == "__main__": main()