#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 49's prior-art search, run on a WORKING channel (see return #796). Bounded: six endpoint queries aimed at the route's uncovered uncertainty -- a cut- and prefix-uniform Möbius-twisted discrepancy for Lambda(n-2)mu(n), and whether published work removes the cut/prefix maximum in exchange for a logarithmically weighted cancellation. Raw Atom responses are frozen with their sha256 so the search record is checkable. """ import hashlib import json import os import re import sys import urllib.parse import urllib.request sys.stdout.reconfigure(encoding="utf-8", errors="replace") RUN = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) OUT = os.path.join(RUN, "evidence", "priorart-1583") UA = {"User-Agent": "solveathome-twin-primes-research/1.0 (route 49 prior art)"} Q = [ ("shifted-mobius-eh", 'abs:"shifted Möbius" AND abs:"Elliott-Halberstam"'), ("diagonal-eh-mobius", 'abs:"diagonal Elliott-Halberstam"'), ("mobius-logarithmic-weight", 'abs:"Möbius" AND abs:"logarithmically weighted"'), ("parity-twin-mobius", 'cat:math.NT AND abs:"parity" AND abs:"Möbius" AND abs:"twin"'), ("uniform-prefix-mobius", 'abs:"Möbius" AND abs:"uniformly" AND abs:"arithmetic progressions" AND abs:"prefix"'), ("recent-twin-2026", 'cat:math.NT AND abs:"twin prime" AND abs:"distribution"&sortBy=submittedDate&sortOrder=descending'), # Round 2: the phrase-in-abstract queries above returned zero, which is itself a datum about # vocabulary (SEARCH-CONVENTIONS.md section 1). Re-ask with the terms the literature uses. ("all-mobius-eh-twin", 'all:"Möbius" AND all:"Elliott-Halberstam" AND abs:"twin"'), ("gonek-hejhal", 'all:"Gonek-Hejhal"'), ("au-vatwani", 'au:Vatwani'), ("parity-barrier-recent", 'abs:"parity barrier"&sortBy=submittedDate&sortOrder=descending'), ("mobius-shifted-primes", 'abs:"Möbius function" AND abs:"shifted primes"'), ("lod-mobius", 'abs:"level of distribution" AND abs:"Möbius"'), ] def fetch(url): req = urllib.request.Request(url, headers=UA) with urllib.request.urlopen(req, timeout=60) as r: return r.status, r.read() def summary(raw): t = raw.decode("utf-8", "replace") tot = re.search(r"]*>(\d+)<", t) ent = re.findall(r"(.*?)", t, re.S) out = [] for e in ent: def one(tag): m = re.search(r"<%s>(.*?)" % (tag, tag), e, re.S) return " ".join(m.group(1).split()) if m else "" out.append({"id": one("id").replace("http://arxiv.org/abs/", ""), "title": one("title"), "published": one("published")[:10]}) return {"total": int(tot.group(1)) if tot else None, "entries": out} def main(): os.makedirs(OUT, exist_ok=True) rec = {"route": 49, "channel": "arXiv API via urllib (return #796 recipe)", "queries": []} for name, q in Q: # spaces must become '+'; the umlaut must be percent-encoded; '&', '=' and '"' are # structural in the API grammar and must survive verbatim. enc = urllib.parse.quote(q.replace(" ", "+"), safe="+&:") url = "https://export.arxiv.org/api/query?search_query=" + enc + "&start=0&max_results=6" r = {"name": name, "query": q} try: st, raw = fetch(url) p = os.path.join(OUT, "qa-%s.xml" % name) open(p, "wb").write(raw) s = summary(raw) r.update({"http_status": st, "bytes": len(raw), "sha256": hashlib.sha256(raw).hexdigest(), "total_results": s["total"], "top": s["entries"], "saved": os.path.relpath(p, RUN).replace("\\", "/")}) except Exception as e: r.update({"error": "%s: %s" % (type(e).__name__, e)}) rec["queries"].append(r) print(json.dumps(r, ensure_ascii=False)[:1200]) with open(os.path.join(RUN, "artifacts", "priorart-1583.json"), "w", encoding="utf-8", newline="\n") as fh: fh.write(json.dumps(rec, ensure_ascii=False, indent=1) + "\n") print(json.dumps({"answered": sum(1 for q in rec["queries"] if q.get("http_status") == 200), "of": len(Q)})) return 0 if __name__ == "__main__": sys.exit(main())