#!/usr/bin/env python3 """Job #1502 checks: re-derive every quoted claim from the saved raw sources. Nothing here is re-typed: each check reads the saved reply/PDF text in work/job1502/sources/ and asserts the exact substring the report quotes, or the sha256 of the file it came from. Run from the folder root: python3 .solveathome/runs//work/job1502/job1502-checks.py exit 0 = every check passed; the JSON record is written next to this file. """ import hashlib import json import os import re import sys HERE = os.path.dirname(os.path.abspath(__file__)) SRC = os.path.join(HERE, "sources") OUT = os.path.join(HERE, "job1502-checks.json") CHECKS = [] def check(name, ok, detail): CHECKS.append({"name": name, "ok": bool(ok), "detail": detail}) print("%-5s %-58s %s" % ("PASS" if ok else "FAIL", name[:58], str(detail)[:150])) return ok def sha(name): with open(os.path.join(SRC, name), "rb") as f: return hashlib.sha256(f.read()).hexdigest() def text(name): with open(os.path.join(SRC, name), "rb") as f: return f.read().decode("utf-8", "replace") def strip_html(s): 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) def main(): r1 = json.load(open(os.path.join(HERE, "job1502-sources.json"))) r2 = json.load(open(os.path.join(HERE, "job1502-sources-r2.json"))) r3 = json.load(open(os.path.join(HERE, "job1502-sources-r3.json"))) r4 = json.load(open(os.path.join(HERE, "job1502-sources-r4.json"))) m1976 = text("r5-motohashi1976.txt") # pdftotext -layout of the PDF below flat = re.sub(r"\s+", " ", m1976) # quotes are compared with whitespace folded def quoted(s): return re.sub(r"\s+", " ", s) in flat adapt = strip_html(text("r4-ar5iv.html")) # arXiv:2301.12669 full text # --- channel calibration (same run, same channels) ------------------------- cal = r1["channels"][0] check("zbMATH API calibrated in-run (control query returns hits)", cal["status"] == 200 and cal["hits"] >= 2, "control 'Jacobsthal function' status=%s hits=%s" % (cal["status"], cal["hits"])) check("arXiv API calibrated in-run (control query returns a paper)", r3["probes"][1]["status"] == 200 and "2301.12669v1" in r3["probes"][1]["ids"], "ids=%s" % r3["probes"][1]["ids"][:3]) # --- the 1976 paper was recovered as a primary text ------------------------ check("Motohashi 1976 recovered as PDF from the publisher (bronze OA)", os.path.getsize(os.path.join(SRC, "r5-euclid.pdf")) == 243573 and sha("r5-euclid.pdf").startswith("fed9756aa1fae3b1"), "bytes=%d sha=%s" % (os.path.getsize(os.path.join(SRC, "r5-euclid.pdf")), sha("r5-euclid.pdf")[:16])) check("the PDF converts to text with the paper's own title author page", "MOTOHASHI" in m1976 and "Nihon University" in m1976 and "Proc. Japan Acad., 52 (1976)" in m1976, "chars=%d" % len(m1976)) # --- Q1: convolution/divisibility transfer, stated by the author ----------- check("1976 Theorem 1 = convolution transfer, verbatim", quoted("Theorem 1. Let f and g have the properties (), (.), (C). Then " "the multiplicative convolution f.g does so."), "quoted §1 of the paper (line breaks folded)") check("1976 §2 divisor-indexed decomposition, verbatim", quoted("E(y q, l; f .g)--") and quoted("f(u)E(y/u; q, l; g)") and quoted("g(v){E(y/v; q, Iv; f)"), "sums over divisors u, v of the convolution variable") # --- Q2: the engine is the large sieve, not the dispersion method ---------- check("1976 engine = large sieve over characters (verbatim)", quoted("we appeal to the large sieve method coupled with the device of Chen [3]"), "quoted §2 (line breaks folded)") check("no dispersion input anywhere in the 1976 text", len(re.findall("dispersion", m1976, re.I)) == 0, "occurrences of 'dispersion' in the 3-page text: %d" % len(re.findall("dispersion", m1976, re.I))) check("characters are the hypothesis channel: (.) = small-conductor χ", quoted("If the conductor of a non-principal character X is"), "quoted §1 property (.)") check("(C) is BV-type equidistribution at level q <= x^{1/2}", "max max IE(y; q, l; f)l=O(x (log x)-)" in m1976 and "q_x/" in m1976, "quoted §1 property (C), OCR form") # --- Q3: the moving, divisor-dependent cutoff is internal to the proof ----- check("1976 §2 carries a v-dependent moving endpoint (min(y/v, ...))", quoted("min (y/v, x (log x) -) q, l f)}"), "the second term is a difference of class sums truncated at a divisor-dependent endpoint") check("that term is disposed of by the co-factor's property (C)/(.), not by dispersion", quoted("readily estimated by the property (C)"), "quoted §2") # --- the modern adaptation agrees, and does not use dispersion either ------ check("adaptation restates the principle as convolution-preservation", "then it also holds for their Dirichlet convolution" in adapt, "arXiv:2301.12669 abstract, ar5iv text") check("adaptation's engine is the large sieve over multiplicative characters", "we need a large sieve estimate involving multiplicative characters" in adapt.replace(" ", " "), "quoted §1 of arXiv:2301.12669") check("adaptation mentions dispersion only historically (Linnik / Drappeau)", len(re.findall("dispersion", adapt, re.I)) == 3 and "The dispersion method in binary additive problems" in adapt, "3 occurrences, all in the introduction/references") # --- what the bibliographic channels did and did not give ------------------ z = r2["probes"][0] check("zbMATH record Zbl 0355.10035 exists but carries NO review text", z["status"] == 200 and z["results"][0]["identifier"] == "0355.10035" and z["results"][0]["review_text"] is None, "identifier=%s review_text=None" % z["results"][0]["identifier"]) s2 = json.load(open(os.path.join(SRC, "r3-s2-motohashi.json"))) check("Semantic Scholar gave the bronze-OA PDF pointer that made the read possible", (s2.get("openAccessPdf") or {}).get("status") == "BRONZE" and "1195518296.pdf" in ((s2.get("openAccessPdf") or {}).get("url") or ""), "openAccessPdf.status=%s citationCount=%s" % ((s2.get("openAccessPdf") or {}).get("status"), s2.get("citationCount"))) check("J-Stage mirror is unavailable from this computer (500 on all three paths)", all(p["status"] == 500 for p in r2["probes"] if p["label"].startswith("jstage")), "3/3 status=500") # --- housekeeping: the ledger path this job must still take --------------- check("the day's route cap is NOT what this job needs first (no route field set)", json.load(open(os.path.join(HERE, "..", "..", "assignment.json")))["research_route_id"] is None, "research_route_id=null: explore/discover, proposal is optional") rec = {"job_id": 1502, "run": os.path.basename(os.path.dirname(os.path.dirname(HERE))), "tool": "job1502-checks.py", "sources": { "r5-euclid.pdf": sha("r5-euclid.pdf"), "r5-motohashi1976.txt": sha("r5-motohashi1976.txt"), "r4-ar5iv.html": sha("r4-ar5iv.html"), "r3-s2-motohashi.json": sha("r3-s2-motohashi.json"), "r2-an035510035.json": sha("r2-an035510035.json"), }, "checks": CHECKS, "passed": sum(1 for c in CHECKS if c["ok"]), "total": len(CHECKS)} with open(OUT, "w") as f: json.dump(rec, f, indent=1, sort_keys=True) print("%d/%d passed -> %s" % (rec["passed"], rec["total"], OUT)) return 0 if rec["passed"] == rec["total"] else 1 if __name__ == "__main__": sys.exit(main())