#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 50's first test, stage 1: put the six mechanism statements in front of me verbatim. The table claims, for each mechanism, WHERE the sign is destroyed. A claim like that has to be made against the statement, not against a paraphrase, so every statement is fetched from the provider and frozen with its sha256. Then two targeted queries ask the other half of the question the route's failure branch needs: is a SIGNED (one-sided / lower-bound) mechanism outside the log-averaging family located? """ import hashlib import json import os import re import sys import time import urllib.error 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", "route50") UA = {"User-Agent": "solveathome-twin-primes-research/1.0 (route 50 triage)"} IDS = ["2607.09110", "2005.03811", "1509.05422", "1809.02518", "2107.02158", "2009.08969"] QUERIES = [ ("signed-mobius-lower", 'abs:"Möbius" AND abs:"lower bound" AND abs:"one-sided"'), ("signed-kloosterman-correlation", 'abs:"Kloosterman" AND abs:"correlation" AND abs:"lower bound"'), ("positivity-mobius-twist", 'abs:"Möbius" AND abs:"positivity"'), ("one-sided-elliott", 'abs:"one-sided" AND abs:"Elliott-Halberstam"'), ] def get(url, tries=3): last = None for i in range(tries): try: req = urllib.request.Request(url, headers=UA) with urllib.request.urlopen(req, timeout=60) as r: return r.status, r.read() except urllib.error.HTTPError as e: last = e if e.code == 429: time.sleep(4 * (i + 1)) continue raise finally: time.sleep(2) raise last def parse(raw): t = raw.decode("utf-8", "replace") tot = re.search(r"]*>(\d+)<", t) out = [] for e in re.findall(r"(.*?)", t, re.S): 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], "abstract": one("summary")}) return (int(tot.group(1)) if tot else None), out def save(name, raw): p = os.path.join(OUT, name) open(p, "wb").write(raw) return os.path.relpath(p, RUN).replace("\\", "/"), hashlib.sha256(raw).hexdigest() def main(): os.makedirs(OUT, exist_ok=True) rec = {"route": 50, "test": "stage 1 - statements verbatim + targeted search", "statements": [], "queries": []} st, raw = get("https://export.arxiv.org/api/query?id_list=" + ",".join(IDS) + "&max_results=20") rel, sha = save("idlist-six.xml", raw) tot, ent = parse(raw) for e in ent: rec["statements"].append({"id": e["id"], "title": e["title"], "published": e["published"], "abstract_chars": len(e["abstract"]), "abstract": e["abstract"]}) print("== %s %s\n %s\n %s\n" % (e["id"], e["published"], e["title"][:100], e["abstract"][:700])) print(json.dumps({"idlist": rel, "sha256": sha, "entries": len(ent)})) for name, q in QUERIES: enc = urllib.parse.quote(q.replace(" ", "+"), safe="+&:") url = "https://export.arxiv.org/api/query?search_query=" + enc + "&start=0&max_results=6" try: st, raw = get(url) rel, sha = save("q-%s.xml" % name, raw) tot, ent = parse(raw) rec["queries"].append({"name": name, "query": q, "total": tot, "saved": rel, "sha256": sha, "titles": [x["id"] + " " + x["title"] for x in ent[:4]]}) print("Q %-32s total=%s %s" % (name, tot, " ;; ".join(x["title"][:58] for x in ent[:3]))) except Exception as e: rec["queries"].append({"name": name, "query": q, "error": "%s: %s" % (type(e).__name__, e)}) print("Q %-32s ERR %s" % (name, e)) with open(os.path.join(RUN, "artifacts", "route50-statements.json"), "w", encoding="utf-8", newline="\n") as fh: fh.write(json.dumps(rec, ensure_ascii=False, indent=1) + "\n") return 0 if __name__ == "__main__": sys.exit(main())