#!/usr/bin/env python3 """Route 45 step check (job #4437): exact normalisation constants + line-anchored source checks. Two independent pieces of evidence: (A) The step of return #1815 asks for "the share of sum_e 2^omega(e) psi(x;e,-2) carried by the covered and uncovered pieces". psi(x;e,-2) = sum_{n<=x, n=-2 (mod e)} Lambda(n) has the heuristic main term x/phi(e) (e odd, so the class -2 is coprime to e; #1406 section 3). So the *raw* sum asked for is main-term dominated: sum_{e<=Q, e odd} 2^omega(e) * psi(x;e,-2) = x * M(Q) * (1 + o(1)) + O(A(x)), M(Q) = sum_{e<=Q, e odd, squarefree} 2^omega(e)/phi(e), while the information-bearing object is the corrected carrier A(x) = sum_{e<=Q, e odd} 2^omega(e) |psi(x;e,-2) - x/phi(e)| (return #1815). M(Q) is computed exactly here (Fractions), so the ratio M(Q)/(A(x)/x) is an exact ratio to the published measurement. This is arithmetic on the record's own normalisation, not the step's experiment: no psi is evaluated. (B) The step's first clause ("confirm the l-variable is unweighted and dyadic and that p is prime") is checked against the extraction served *with return #710* (job1503-yang2608.13299.txt, sha256 printed by --check-files) by literal line-anchored substring tests, with negative controls (strings from a different paper that must be absent). Stdlib only, offline apart from reading the already-fetched served files. """ from __future__ import annotations import argparse import hashlib import json import os import sys from fractions import Fraction HERE = os.path.dirname(os.path.abspath(__file__)) SERVED = os.path.join(HERE, "served") EXTRACTION = os.path.join(SERVED, "f710_job1503-yang2608.13299.txt") # Published numbers this check is normalised against (return #1815, route 45). RECORD = { "A_over_x": {"1e6": 0.1508, "1e7": 0.1102, "1e8": 0.0815}, "e_le_sqrt_over_x": {"1e6": 0.1199, "1e7": 0.0872, "1e8": 0.0630}, "beyond_sqrt_over_x": {"1e6": 0.0309, "1e7": 0.0230, "1e8": 0.0185}, "prime_e_beyond_sqrt_over_x": {"1e6": 0.0046, "1e7": 0.0027, "1e8": 0.0018}, "Q": {"1e6": 1317, "1e7": 4364, "1e8": 14452}, "x": {"1e6": 10 ** 6, "1e7": 10 ** 7, "1e8": 10 ** 8}, } def factor(n): f, d = {}, 2 while d * d <= n: while n % d == 0: f[d] = f.get(d, 0) + 1 n //= d d += 1 if d == 2 else 2 if n > 1: f[n] = f.get(n, 0) + 1 return f def totient_from_factors(f): r = 1 for p, k in f.items(): r *= (p - 1) * p ** (k - 1) return r def two_omega(f): """2^omega(n) = number of squarefree divisors.""" return 2 ** len(f) def main_term_constant(qmax, squarefree_only=True): """M(Q) = sum_{e<=Q, e odd} 2^omega(e)/phi(e) exactly, as a Fraction.""" tot = Fraction(0) for e in range(1, qmax + 1, 2): f = factor(e) if squarefree_only and any(k > 1 for k in f.values()): continue tot += Fraction(two_omega(f), totient_from_factors(f)) return tot def anchored_checks(path): """Literal, line-anchored substring tests on the served Yang extraction.""" lines = open(path, encoding="utf-8", errors="replace").read().split("\n") ns = ["%d:%s" % (i + 1, s) for i, s in enumerate(lines)] def find(needle, lo=1, hi=None): hi = hi or len(lines) return [n for n in ns if needle in n and lo <= int(n.split(":", 1)[0]) <= hi] checks = [] def chk(name, cond, detail): checks.append({"check": name, "pass": bool(cond), "detail": detail}) # 1. (1.1) display: the inner sum is over l ~ L, unweighted, and p < x/l. l129 = find("l\u223cL", 124, 130) chk("C1a_inner_sum_over_l_sim_L", bool(l129), "line(s) with 'l~L' inside the (1.1) display 124-130: %s" % l129) # 2. the second summation variable of (1.1) is a prime p, unweighted p129 = [n for n in ns if 124 <= int(n.split(":", 1)[0]) <= 130 and "p= 1, "line(s) with 'p 0 with (a,dq)=1 and d ~ D = x^theta chk("C1g_d_sim_D_x_theta_and_a_dq_coprime", bool(find("d \u223c D = x\u03b8", 130, 140)) and bool(find("(a, dq) = 1", 130, 140)), "line(s) 130-140: %s" % find("d \u223c D = x\u03b8", 130, 140)) # 8. the corollary: 0 <= theta < nu, 3/8 <= nu <= 1, level x^{L(nu)-theta-eps} chk("C1h_corollary_theta_nu_range", bool(find("0 \u2264 \u03b8 < \u03bd", 196, 202)), "line(s): %s" % find("0 \u2264 \u03b8 < \u03bd", 196, 202)) # 9. Theorem 1.4 level function L(nu) chk("C1i_theorem_1_4_level_function", bool(find("Theorem 1.4", 188, 194)), "line(s): %s" % find("Theorem 1.4", 188, 194)) # 10. gamma_d may be smooth or the dyadic indicator 1_(D,2D] chk("C1j_gamma_d_dyadic_indicator", bool(find("smooth function or", 202, 210)), "line(s): %s" % find("smooth function or", 202, 210)) # 11. gate: the l-sum carries NO weight in (1.1) -- contrast with the weighted variant at 149-156 weighted = [n for n in ns if 145 <= int(n.split(":", 1)[0]) <= 160 and "f (l)" in n] chk("C1k_contrast_weighted_variant_has_f_l", bool(weighted), "the non-dyadic Pan-Ding-Wang variant at lines 145-160 carries a weight f(l): %s" % weighted) # negative controls: a different paper's vocabulary must be absent for neg in ("Motohashi", "dispersion", "Kloosterman sum 0 0 0"): chk("NEG_absent_%s" % neg.replace(" ", "_"), not find(neg, 1, len(lines)), "'%s' does not occur in the served extraction" % neg) return checks def sha256(path, crlf_normalise=False): b = open(path, "rb").read() if crlf_normalise: b = b.replace(b"\r\n", b"\n") return hashlib.sha256(b).hexdigest() def main(): ap = argparse.ArgumentParser() ap.add_argument("--json-out", default=os.path.join(HERE, "stepcheck45.json")) args = ap.parse_args() out = {"record": RECORD, "checks": [], "main_term": {}} for label, q in RECORD["Q"].items(): msq = main_term_constant(q, squarefree_only=True) mall = main_term_constant(q, squarefree_only=False) a = RECORD["A_over_x"][label] out["main_term"][label] = { "Q": q, "M_squarefree": str(msq), "M_squarefree_float": float(msq), "M_all_odd": str(mall), "M_all_odd_float": float(mall), "A_over_x": a, "ratio_Msq_over_A": float(msq) / a, "ratio_Mall_over_A": float(mall) / a, "log_Q_squared": __import__("math").log(q) ** 2, "M_sq_over_log2Q": float(msq) / (__import__("math").log(q) ** 2), } # published sub-shares of A(x), from return #1815, as fractions of A(x) shares = {} for label in RECORD["Q"]: a = RECORD["A_over_x"][label] shares[label] = { "e_le_sqrt": RECORD["e_le_sqrt_over_x"][label] / a, "beyond_sqrt": RECORD["beyond_sqrt_over_x"][label] / a, "prime_e_beyond_sqrt": RECORD["prime_e_beyond_sqrt_over_x"][label] / a, } out["published_shares_of_A"] = shares if os.path.exists(EXTRACTION): out["checks"] = anchored_checks(EXTRACTION) out["extraction"] = { "file": "served/f710_job1503-yang2608.13299.txt", "sha256_raw": sha256(EXTRACTION), "sha256_lf": sha256(EXTRACTION, crlf_normalise=True), "lines": len(open(EXTRACTION, encoding="utf-8", errors="replace").read().split("\n")), } else: out["checks"] = [{"check": "extraction_present", "pass": False, "detail": "%s missing" % EXTRACTION}] with open(args.json_out, "w", encoding="utf-8") as fh: json.dump(out, fh, indent=2) npass = sum(1 for c in out["checks"] if c["pass"]) print("checks: %d/%d PASS" % (npass, len(out["checks"]))) for c in out["checks"]: print(" %-42s %s :: %s" % (c["check"], "PASS" if c["pass"] else "FAIL", c["detail"][:150])) for label, mt in out["main_term"].items(): print("%s: Q=%d M_sq=%.4f M_sq/log^2Q=%.4f ratio M_sq/(A/x)=%.1f" % (label, mt["Q"], mt["M_squarefree_float"], mt["M_sq_over_log2Q"], mt["ratio_Msq_over_A"])) for label, sh in shares.items(): print("%s: shares of A(x): e<=sqrt %.4f beyond %.4f prime-e-beyond %.4f" % (label, sh["e_le_sqrt"], sh["beyond_sqrt"], sh["prime_e_beyond_sqrt"])) return 0 if __name__ == "__main__": sys.exit(main())