#!/usr/bin/env python3 # -*- coding: utf-8 -*- """job1914-checks.py -- exact + numerical checks for return #49 (paper `kk-lower-bound`). Run: python3 job1914-checks.py > job1914-checks.log 2>&1 No timings, no host paths, no randomness: stdout is byte-reproducible. Standard library only. Every number printed is computed here; nothing is quoted from the manuscript, the review or any producer output. Checks A ledger arithmetic: C_excl = -2ln2 + 2M - 2(1/2+1/3), C_actual = -2ln2 + 2M - 1/2, and the exact rational identity C_excl + 1/2 + 2/3 = C_actual. B the revision's added reconciliation sentence is refuted exactly: the quantity it describes ("full sum with g(2)=g(3)=2 counted") is C_excl + 2(1/2+1/3) = -0.863301, so the printed -2.529967 is the p>=5 sum (g(2)=g(3)=0), not the one described. C two-class Mertens product (Theorem A's repaired step): prod_{3<=p<=z}(1-2/p) * ln(z)^2 -> 4*C2*exp(-2*gamma), C2 = prod_{p>2}(1-1/(p-1)^2), at z = 1e4, 1e5, 1e6, plus the constant 2*C2*exp(-2*gamma). D definitions check for the review's OEIS-normalization paragraph: for the class pair {0,-2} the admissible residues mod 30, the cyclic gap G2(30), and the covered length. """ import math from fractions import Fraction MERTENS = 0.2614972128476428 # Meissel-Mertens M EULER_GAMMA = 0.5772156649015329 C2_TWIN = 0.6601618158468696 # prod_{p>2} (1 - 1/(p-1)^2), the twin-prime constant / 2 results = [] def check(name, ok, detail): results.append((name, bool(ok), detail)) print("%-4s %s %s" % ("PASS" if ok else "FAIL", name, detail)) # ---------------------------------------------------------------- A: ledger arithmetic C_excl = -2 * math.log(2) + 2 * MERTENS - 2 * (Fraction(1, 2) + Fraction(1, 3)) C_actual = -2 * math.log(2) + 2 * MERTENS - Fraction(1, 2) print("A1 C_excl = %.6f (manuscript §6.3 prints -2.529967)" % C_excl) print("A2 C_actual = %.6f (manuscript §6.4 / revision print -1.3633)" % C_actual) check("A1 C_excl = -2.529967 to 1e-6", abs(C_excl + 2.529967) < 1e-6, "%.9f" % C_excl) check("A2 C_actual = -1.363300 to 1e-6", abs(C_actual + 1.363300) < 1e-6, "%.9f" % C_actual) # exact rational part: C_actual - C_excl must be 1/2 + 2/3 = 7/6 with the logs cancelling r_excl = -2 * (Fraction(1, 2) + Fraction(1, 3)) # rational part of C_excl = -5/3 r_act = -Fraction(1, 2) # rational part of C_actual check("A3 C_actual - C_excl = 1/2 + 2/3 exactly (rational parts)", r_act - r_excl == Fraction(1, 2) + Fraction(2, 3), "%s - (%s) = %s" % (r_act, r_excl, r_act - r_excl)) check("A4 C_actual = C_excl + g(2)/2 + g(3)/3 with g(2)=1, g(3)=2", abs(C_actual - (C_excl + Fraction(1, 2) + Fraction(2, 3))) < 1e-15, "residual %.3e" % abs(C_actual - (C_excl + Fraction(1, 2) + Fraction(2, 3)))) # ------------------------------------------- B: refute the added description of -2.529967 C_g22_g32 = C_excl + 2 * (Fraction(1, 2) + Fraction(1, 3)) # the described quantity print("B1 described quantity (g(2)=g(3)=2 counted) = %.6f" % C_g22_g32) check("B1 the described quantity is -0.863300, not -2.529967", abs(C_g22_g32 + 0.863300) < 1e-5 and abs(C_g22_g32 + 2.529967) > 1.0, "%.9f vs printed -2.529967 (gap %.6f)" % (C_g22_g32, C_g22_g32 + 2.529967)) check("B2 the printed -2.529967 is the p>=5 (g(2)=g(3)=0) sum, i.e. the EXCLUDING constant", abs(C_excl + 2.529967) < 1e-6, "C_excl = %.9f" % C_excl) # --------------------------------------- C: two-class Mertens product (numerical, sieve) def primes_upto(n): s = bytearray([1]) * (n + 1) s[0] = s[1] = 0 for i in range(2, int(n ** 0.5) + 1): if s[i]: s[i * i::i] = bytearray(len(s[i * i::i])) return [i for i in range(n + 1) if s[i]] LIMIT = 1000100 PR = primes_upto(LIMIT) print("C0 sieve: %d primes <= %d" % (len(PR), LIMIT)) target2 = 4 * C2_TWIN * math.exp(-2 * EULER_GAMMA) # two-class limit target1 = math.exp(-EULER_GAMMA) # one-class control, prod(1-1/p)*ln z prod2 = 1.0 prod1 = 1.0 rows = [] marks = [10 ** 4, 10 ** 5, 10 ** 6] for p in PR: prod1 *= (1.0 - 1.0 / p) # one-class control: all primes, p=2 included if p == 2: continue # two-class product runs over p > 2 only prod2 *= (1.0 - 2.0 / p) if marks and p >= marks[0]: # first prime past each mark marks.pop(0) rows.append((p, prod2 * math.log(p) ** 2, prod1 * math.log(p))) for z, v2, v1 in rows: print("C1 z=%7d prod_{3<=p<=z}(1-2/p)*ln^2 z = %.6f (limit 4*C2*e^-2g = %.6f)" % (z, v2, target2)) print("C2 z=%7d prod_{p<=z}(1-1/p)*ln z = %.6f (control e^-g = %.6f)" % (z, v1, target1)) z_last = rows[-1][0] check("C3 two-class product approaches 4*C2*exp(-2*gamma) to <1%% at z=%d" % z_last, abs(rows[-1][1] / target2 - 1.0) < 0.01, "ratio %.6f" % (rows[-1][1] / target2)) check("C4 one-class control approaches exp(-gamma) to <1%% at z=%d" % z_last, abs(rows[-1][2] / target1 - 1.0) < 0.01, "ratio %.6f" % (rows[-1][2] / target1)) check("C5 relative error shrinks from z=%d to z=%d (asymptotic, not a coincidence)" % (rows[0][0], z_last), abs(rows[-1][1] / target2 - 1.0) < abs(rows[0][1] / target2 - 1.0), "%.4f -> %.6f" % (abs(rows[0][1] / target2 - 1.0), abs(rows[-1][1] / target2 - 1.0))) two_c2 = 2 * C2_TWIN * math.exp(-2 * EULER_GAMMA) print("C6 2*C2*exp(-2*gamma) = %.6f (revision prints 0.41621)" % two_c2) check("C6 2*C2*exp(-2*gamma) = 0.41621 to 1e-4", abs(two_c2 - 0.41621) < 1e-4, "%.9f" % two_c2) # --------------------------------- D: definitions check behind the OEIS-normalization item def admissible_residues(primes): """Residues t mod prod(p) with t and t+2 divisible by no p -- the class pair {0,-2}.""" mod = 1 for p in primes: mod *= p bad = set() for p in primes: for k in range(mod // p): base = k * p for r in range(p): if (base + r) % p == 0 or (base + r) % p == (p - 2) % p: bad.add(base + r) return mod, sorted(set(range(mod)) - bad) mod30, res30 = admissible_residues([2, 3, 5]) print("D1 admissible residues mod 30 for classes {0,-2}, p in {2,3,5}: %s" % res30) check("D1 three classes mod 30 (2*3*5 with g(2)=1,g(3)=2,g(5)=?)", len(res30) == 3, "count %d" % len(res30)) gaps = [res30[i + 1] - res30[i] for i in range(len(res30) - 1)] + [res30[0] + mod30 - res30[-1]] print("D2 cyclic gaps between admissible residues: %s" % gaps) check("D2 max cyclic gap = 12 = the quoted G2(30)", max(gaps) == 12, "max %d" % max(gaps)) check("D3 that gap exceeds the unscaled OEIS row A072753(3)=2 by 10", max(gaps) - 2 == 10, "G2(30)-A072753(3) = %d" % (max(gaps) - 2)) mod5, res5 = admissible_residues([5]) g5 = [res5[i + 1] - res5[i] for i in range(len(res5) - 1)] + [res5[0] + mod5 - res5[-1]] print("D4 single prime 5: residues %s, gaps %s (covered length %d)" % (res5, g5, max(g5) - 1)) check("D4 prime 5 alone: 3 admissible classes, covered length max gap-1 = 1", len(res5) == 3 and max(g5) - 1 == 1, "residues %s gaps %s" % (res5, g5)) # ------------------------------------------------------------------------------ tally npass = sum(1 for _, ok, _ in results if ok) print("") print("all_pass: %s" % (npass == len(results))) print("checks: %d, passed: %d, failed: %d" % (len(results), npass, len(results) - npass))