#!/usr/bin/env python3 """Job #1502 probe round 3: the *readable* carriers of Motohashi's mechanism. Round 1-2 established: the 1976 paper is paywalled on Project Euclid, J-Stage answers 500 from this computer, and the zbMATH record Zbl 0355.10035 carries NO review text (record-only). Round 3 therefore reads the carriers that a modern reader actually uses: (a) Semantic Scholar for the 1976 record's abstract/open-access pointer, (b) the arXiv API for the 2023 "induction principle over F_q[t]" paper, whose zbMATH review states Motohashi's principle as convolution-preservation, (c) that paper's full HTML text (arXiv LaTeXML), searched for every mention of Motohashi -- an author who *uses* the induction principle has to say how the transfer works. Read-only, public, no credentials. Raw replies saved + hashed in sources/. """ import hashlib import json import os import re import sys import time import urllib.error import urllib.parse import urllib.request HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "sources") os.makedirs(OUT, exist_ok=True) UA = {"User-Agent": "solveathome-local-probe/1 (research)", "Accept": "application/json, text/html, application/xml;q=0.8"} DOI = "10.3792/pja/1195518296" def fetch(url, tries=2, timeout=45, accept=None): last = None for i in range(tries): req = urllib.request.Request(url, headers=dict(UA, **({"Accept": accept} if accept else {}))) try: with urllib.request.urlopen(req, timeout=timeout) as r: return r.status, r.read(), r.geturl() except urllib.error.HTTPError as e: return e.code, e.read(), url except Exception as e: last = repr(e) time.sleep(2) return None, (last or "unknown").encode(), url def save(name, body): with open(os.path.join(OUT, name), "wb") as f: f.write(body) return {"file": name, "bytes": len(body), "sha256": hashlib.sha256(body).hexdigest()} def plain(body): s = body.decode("utf-8", "replace") s = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?", " ", s) s = re.sub(r"(?s)<[^>]+>", " ", s) for a, b in (("'", "'"), (" ?", " "), ("&", "&"), ("<", "<"), (">", ">")): s = re.sub(a, b, s) return re.sub(r"\s+", " ", s).strip() def main(): rec = {"round": 3, "probes": [], "motohashi_mentions": []} # (a) Semantic Scholar: abstract / OA pointer for the 1976 paper url = ("https://api.semanticscholar.org/graph/v1/paper/DOI:%s" "?fields=title,abstract,year,venue,externalIds,openAccessPdf,citationCount" % DOI) status, body, final = fetch(url, accept="application/json") rec["probes"].append({"label": "s2-motohashi", "channel": "semanticscholar", "url": url, "status": status, **save("r3-s2-motohashi.json", body), "text_head": body.decode("utf-8", "replace")[:1500]}) time.sleep(2) # (b) arXiv API: the modern adaptation(s) of the induction principle for label, q in [("arxiv-induction-principle", 'all:"induction principle" AND all:"Bombieri"'), ("arxiv-motohashi", 'all:"Motohashi" AND all:"Bombieri"')]: u = ("http://export.arxiv.org/api/query?search_query=" + urllib.parse.quote(q) + "&start=0&max_results=20&sortBy=relevance") status, body, final = fetch(u, accept="application/atom+xml") ids = re.findall(r"http://arxiv\.org/abs/([^<]+)", body.decode("utf-8", "replace")) titles = re.findall(r"([^<]+)", body.decode("utf-8", "replace")) rec["probes"].append({"label": label, "channel": "arxiv_api", "query": q, "url": u, "status": status, **save("r3-%s.xml" % label, body), "ids": ids[:20], "titles": [t.strip()[:120] for t in titles[1:21]]}) time.sleep(4) # (c) full HTML of the F_q[t] adaptation, then every Motohashi context. # 2302.00459 is the F_q[t] paper named in this folder's own #1500 record. for aid in ["2302.00459"]: u = "https://arxiv.org/html/%s" % aid status, body, final = fetch(u, accept="text/html") p = {"label": "arxiv-html-%s" % aid, "channel": "arxiv_html", "url": u, "status": status, "served_url": final, **save("r3-arxiv-html-%s.html" % aid, body)} txt = plain(body) p["bytes_text"] = len(txt) rec["probes"].append(p) for m in re.finditer(r"Motohashi", txt): s = max(0, m.start() - 400) rec["motohashi_mentions"].append(txt[s:m.start() + 500]) # also record whether the transfer is described as convolution for kw in ["divisib", "dispersion", "convolut", "large sieve", "well-factorable"]: p["kw_%s" % kw] = len(re.findall(kw, txt, re.I)) time.sleep(1) path = os.path.join(HERE, "job1502-sources-r3.json") with open(path, "w") as f: json.dump(rec, f, indent=1, sort_keys=True) print("wrote", path) for p in rec["probes"]: print("%-26s status=%-4s bytes=%-9s sha=%s" % (p["label"], p["status"], p.get("bytes"), p["sha256"][:12])) if p.get("ids"): print(" ids:", p["ids"][:6]) for t in p["titles"][:6]: print(" -", t) if p.get("text_head"): print(" head:", p["text_head"][:300].replace("\n", " ")) if p.get("kw_divisib") is not None: print(" kw:", {k: p["kw_%s" % k] for k in ["divisib", "dispersion", "convolut", "large sieve", "well-factorable"]}) print("motohashi mentions:", len(rec["motohashi_mentions"])) return 0 if __name__ == "__main__": sys.exit(main())