"""Small synthetic checks of an offset-aware counting identity, not a census.""" from functools import lru_cache from math import gcd, prod import json PRIMES = (2, 3, 5, 7, 11, 13) def progression_count(b, m, modulus, residue): return (b + m - residue) // modulus - (b - residue) // modulus def direct(b, m, k, tau): modulus = prod(PRIMES[:k]) return sum(gcd(n * (n + tau), modulus) == 1 for n in range(b + 1, b + m + 1)) @lru_cache(maxsize=4096) def recurrent(b, m, k, tau, mutation="none"): if not k or not m: return m roots = [ (0, -tau % p) if mutation == "duplicate_roots" else tuple(sorted({0, -tau % p})) for p in PRIMES[:k] ] answer = m - sum( progression_count(b, m, PRIMES[i], root) for i in range(k) for root in roots[i] ) for i in range(k): prefix = prod(PRIMES[:i]) for j in range(i + 1, k): p, q = PRIMES[i], PRIMES[j] d = p * q inverse = pow(d, -1, prefix) if prefix > 1 else 0 for a in roots[i]: for z in roots[j]: r = a + p * (((z - a) * pow(p, -1, q)) % q) length = progression_count(b, m, d, r) origin = (b - r) // d + (r * inverse % prefix) offset = tau % prefix if mutation == "fixed_offset" else tau * inverse % prefix answer += recurrent(origin, length, i, offset, mutation) return answer @lru_cache(maxsize=4096) def lower(m, k): if k == 0: return m multiplicities = (1,) + (2,) * (k - 1) answer = m - sum( multiplicities[i] * ((m + p - 1) // p) for i, p in enumerate(PRIMES[:k]) ) for i in range(k): for j in range(i + 1, k): answer += ( multiplicities[i] * multiplicities[j] * lower(m // (PRIMES[i] * PRIMES[j]), i) ) return max(0, answer) def main(): offsets = (-10, -6, -4, -2, 0, 1, 2, 4, 6, 10) origins = (-9, -1, 0, 1, 4, 17, 30, 34) lengths = (0, 1, 2, 3, 5, 6, 11, 17, 35, 36, 49, 70) exact_checks = lower_checks = 0 for k in range(len(PRIMES) + 1): for tau in offsets: for b in origins: for m in lengths: expected = direct(b, m, k, tau) observed = recurrent(b, m, k, tau) assert observed == expected, (b, m, k, tau, expected, observed) exact_checks += 1 if tau % 2 == 0: assert lower(m, k) <= expected, (b, m, k, tau) lower_checks += 1 controls = [] for mutation, case in ( ("duplicate_roots", (1, 1, 1, 0)), ("fixed_offset", (34, 1, 4, 2)), ): correct = direct(*case) mutated = recurrent(*case, mutation) assert correct != mutated, (mutation, case) controls.append({ "mutation": mutation, "b_m_k_tau": case, "expected": correct, "mutated": mutated, "detected": True, }) assert lower(6, 2) == 1 envelope = [] # These are cited calibration values, never computed by this program. published_h2 = {3: 18, 4: 30, 5: 66, 6: 150} for k, known in published_h2.items(): cap = 3 * known bound = next((m for m in range(1, cap + 1) if lower(m, k) > 0), None) envelope.append({ "k": k, "prime": PRIMES[k - 1], "published_h2": known, "search_cap": cap, "first_positive_bound_within_cap": bound, "lower_at_bound": lower(bound, k) if bound is not None else None, "source": "OEIS A288815, revision #19, externally reported; not reproduced", }) print(json.dumps({ "exact_identity_checks": exact_checks, "uniform_lower_bound_checks": lower_checks, "primes": PRIMES, "origins": origins, "lengths": lengths, "offsets": offsets, "controls": controls, "analytic_base_case": {"m": 6, "k": 2, "lower": lower(6, 2)}, "new_uniform_envelope_experiment": envelope, "scope": "Synthetic finite windows only; no extremal-gap or primorial-offset census.", }, sort_keys=True, separators=(",", ":"))) if __name__ == "__main__": main()