#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 49 rescue: how much leverage does the CUT family carry, at fixed x? THE OBSTRUCTION (route 49 revision 3, obstacle.statement): The prescribed experiment fits log(cut-dispersion of D_y) against log log x over x = 2^20..2^27. The lever arm in log log x is 2.629 -> 2.929, a range of 0.300, while a factor-2 change at c = 1 needs ln 2 = 0.693, i.e. x about 2^40 -- and peak RSS is linear in x, ~63 TB there. Neither branch is established, so the route's own question is undecided at EVERY reachable x. THE REPAIR TESTED HERE, measured rather than argued: The route's question is about the admissible CUT, so the cut position is a legitimate independent variable in its own right, and it is FREE. The admissible window is [x^(12/25), x^(1/2)] (the instrument's own comment: below x^(12/25) the Mobius-mean input Q = floor(x/y) > x^(13/25), above x^(1/2) the Bombieri-Vinogradov input fails). Its integer width is x^(1/2) - x^(12/25) = x^(12/25) * (x^(1/50) - 1), i.e. it grows like x^(12/25) -- POLYNOMIALLY -- while the lever arm the route wanted grows like log log x. So this script measures three things at fixed x, none of them a rerun of a published number: (1) the size of the FULL admissible cut family (the population, not a sample); (2) the cost of adding cuts, against the cost of the sieve they share (the cache); (3) the spread over a nested family 7 < 25 < 100 < all, which decides whether the 7-cut spreads the route fitted are SAMPLE spreads of a small subsample. WHY (3) IS DECISIVE EITHER WAY. If the spread stabilises as the family grows, the recorded values are a fair read of the cut-dependence and the route's dispersion experiment can be re-run with real power at reachable x. If the spread moves materially, then the fitted c = 1.8952 was fitted to under-sampled values whose bias is a function of the cut count -- and the count is 7 at every scale, so the bias does not average out across the ladder. Usage: python work/cut-power.py --x 1048576 [--ns 7,25,100,all] """ import argparse import importlib.util import json import math import os import sys import time sys.stdout.reconfigure(encoding="utf-8", errors="replace") RUN = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SPEC = importlib.util.spec_from_file_location( "census", os.path.join(RUN, "work", "centered-census.py")) census = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(census) try: # peak RSS of this process, Windows import ctypes import ctypes.wintypes class PMC(ctypes.Structure): _fields_ = [("cb", ctypes.wintypes.DWORD), ("PageFaultCount", ctypes.wintypes.DWORD), ("PeakWorkingSetSize", ctypes.c_size_t), ("WorkingSetSize", ctypes.c_size_t), ("QuotaPeakPagedPoolUsage", ctypes.c_size_t), ("QuotaPagedPoolUsage", ctypes.c_size_t), ("QuotaPeakNonPagedPoolUsage", ctypes.c_size_t), ("QuotaNonPagedPoolUsage", ctypes.c_size_t), ("PagefileUsage", ctypes.c_size_t), ("PeakPagefileUsage", ctypes.c_size_t)] def peak_rss_gb(): p = PMC() p.cb = ctypes.sizeof(PMC) ctypes.windll.psapi.GetProcessMemoryInfo( ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(p), p.cb) return round(p.PeakWorkingSetSize / 2 ** 30, 3) except Exception: # noqa: BLE001 def peak_rss_gb(): return None def window(x): """The instrument's own admissible window, read from the instrument, not re-derived.""" return math.ceil(x ** (12 / 25)), math.isqrt(x) def evenly(lo, hi, n): if n >= hi - lo + 1: return list(range(lo, hi + 1)) if n == 1: return [lo] return sorted({lo + round(i * (hi - lo) / (n - 1)) for i in range(n)}) def spread_of(rows, key): v = [r[key] / r["x"] for r in rows] return max(v) - min(v) def main(): ap = argparse.ArgumentParser() ap.add_argument("--x", type=int, required=True) ap.add_argument("--ns", default="7,25,100,all") a = ap.parse_args() lo, hi = window(a.x) full = list(range(lo, hi + 1)) specs = [] for tok in a.ns.split(","): specs.append(("all", len(full)) if tok.strip() == "all" else (tok.strip(), int(tok))) t0 = time.time() np_, mu, lam = census.float_arrays(a.x) t_sieve = time.time() - t0 cache = {} curve, t_cuts_total, cut_count = [], 0.0, 0 for label, n in specs: cuts = evenly(lo, hi, n) t1 = time.time() rows = [census.float_cut(a.x, y, np_, mu, lam, cache) for y in cuts] dt = time.time() - t1 t_cuts_total += dt cut_count += len(cuts) curve.append({ "family": label if label == "all" else "n=%s" % label, "cuts": len(cuts), "seconds": round(dt, 3), "spread_over_x": {k: round(spread_of(rows, k), 8) for k in ("Dy", "invariant_I", "T1", "T2", "S", "Epp")}, "gate_resid_max": max(abs(r["resid_G1"]) + abs(r["resid_G2"]) for r in rows), }) out = { "tool": "run-local/cut-power", "question": "route 49 rescue: leverage of the cut family at fixed x, vs the log log x arm", "x": a.x, "admissible_window": {"lo": lo, "hi": hi, "integer_cuts_available": len(full)}, "leverage": { "log_log_x_range_over_route_ladder": [round(math.log(math.log(2 ** 20)), 3), round(math.log(math.log(2 ** 27)), 3)], "log_log_x_range": round(math.log(math.log(2 ** 27)) - math.log(math.log(2 ** 20)), 3), "needed_for_factor_2": round(math.log(2), 3), "integer_cuts_here": len(full), "route_ladder_used_cuts": 7, "sampling_fraction": round(7 / len(full), 5), }, "cost": {"sieve_seconds": round(t_sieve, 3), "cuts_seconds": round(t_cuts_total, 3), "seconds_per_cut": round(t_cuts_total / max(cut_count, 1), 5), "cuts_share_of_total": round(t_cuts_total / (t_cuts_total + t_sieve), 4)}, "curve": curve, "peak_rss_gb": peak_rss_gb(), } print(json.dumps(out, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())