#!/usr/bin/env python3 """Recompute the complete analytic certificate for the accompanying paper. Run from any directory: python3 /path/to/anc/verify.py [--jobs 3]. Requires Python 3.10+, NumPy and mpmath. The published binary Goldbach computation is an external mathematical input. """ import argparse from decimal import Decimal, localcontext import os from pathlib import Path import re import subprocess import sys import time HERE = Path(__file__).resolve().parent def run(relative, *arguments): path = HERE / relative print(f"\nRUN {relative}", flush=True) env = os.environ.copy() env.pop("PYTHONPATH", None) env.pop("PYTHONOPTIMIZE", None) env["PYTHONUNBUFFERED"] = "1" env["OPENBLAS_NUM_THREADS"] = "1" env["OMP_NUM_THREADS"] = "1" env["LC_ALL"] = "C" completed = subprocess.run( [sys.executable, str(path), *map(str, arguments)], cwd=path.parent, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) print(completed.stdout, end="", flush=True) if completed.returncode: raise SystemExit(f"FAIL {relative}: exit {completed.returncode}") return completed.stdout def main(): if not __debug__: raise SystemExit("Assertions must be enabled; do not use python -O.") parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--jobs", type=int, default=3) args = parser.parse_args() if args.jobs < 1: parser.error("--jobs must be positive") import numpy import mpmath started = time.monotonic() print("Chen's theorem for every even integer under GRH") print("Recomputing the complete analytic positivity certificate.") print(f"Python {sys.version.split()[0]}; NumPy {numpy.__version__}; " f"mpmath {mpmath.__version__}; workers {args.jobs}", flush=True) run("common_bounds.py") finite = run("finite_verify.py", "--table", "--workers", args.jobs) reference = (HERE / "finite_reference.log").read_text() assert finite.strip() == reference.strip(), "Finite replay differs from reference." lines = finite.splitlines() rows = [line.split() for line in lines[1:] if not line.startswith("PASS")] assert len(rows) == 20 with localcontext() as context: context.prec = 60 D = Decimal lower = (D(4) * D(10)**18).ln() assert D(rows[0][0]) <= lower and D(rows[-1][1]) >= 50 assert all(D(left[1]) >= D(right[0]) for left, right in zip(rows, rows[1:])) finite_margin = min(D(row[6]) for row in rows) assert finite_margin > D(".004") middle = run("middle/verify_middle.py", "--jobs", args.jobs) assert "PASS 209 complete panels on [50,1500]" in middle table = (HERE / "middle/middle_panels.tsv").read_text().splitlines()[1:] panels = [tuple(map(Decimal, line.split())) for line in table] assert len(panels) == 209 and panels[0][0] == 50 and panels[-1][1] == 1500 assert all(a[1] == b[0] for a, b in zip(panels, panels[1:])) middle_margin = min(row[-1] for row in panels) assert middle_margin > Decimal(".001") ray = run("ray_verify.py") match = re.search(r"^margin \[([^,]+),", ray, flags=re.MULTILINE) assert match is not None ray_margin = Decimal(match[1]) assert ray_margin > Decimal(".01") alpha = min(finite_margin, middle_margin, ray_margin) assert alpha > Decimal(".001") coefficient = (Decimal(".001") * Decimal(".05") * Decimal(".58") / ((Decimal(4)/45) * Decimal(".09"))) assert coefficient > Decimal(".001") print("\nPASS complete continuous coverage: log(4*10^18) to infinity.") print("PASS 20 + 209 = 229 compact intervals and one monotone half-line.") print(f"PASS common normalized margin > 0.001; least compact margin {alpha}.") print("PASS R_2(N) >= N / (1000 log(N)^2) for even N >= 4*10^18.") print("External finite input: Oliveira e Silva, Herzog and Pardi (2014).") print(f"Elapsed seconds: {time.monotonic()-started:.2f}", flush=True) if __name__ == "__main__": main()