make_notebook.py — src/20-rh

The script src/20-rh/make_notebook.py of the validation package of the paper 20-rh, rendered with an anchor per line. ▶ run the predicates on Google Colab.

20-rh ledgersrc/20-rh/make_notebook.py · 4.3 KBmake_notebook.pyColab
1#!/usr/bin/env python32"""Builds frc-20-rh.ipynb, the package's Colab notebook: one cell per python-witnessed predicate of the paper's ledger, each cell addressable3from the ledger page by the predicate's accession key as its stable id (`p20037`: Colab opens the notebook at that cell with `#scrollTo=p20037`).4A predicate cell states the predicate (its text, from the site's ledger JSON) and runs `predicate("20:E6")`: the blocks of the checks that5cite the predicate run once per session, the deciding check's source is printed from its `# 20:E6 (p20037)` marker, and every record6citing the predicate is listed with its verdict. Run: python3 make_notebook.py  (then execute the notebook)."""7import json, re, os8import rh as dcommon910PKG = "20-rh"; NB = f"frc-{PKG}.ipynb"; PAPER = "20"11LEDGER_URL = f"https://finitering.space/{PKG}/"; APPENDIX = "A"          # the paper's ledger page and the appendix that carries the ledger12CITE = "Akhtman & Voether, Preprints 2026"; DOI = "https://doi.org/10.20944/preprints202606.0768.v1"                       # the heading's citation, linked to the article13SCRIPT = "rh.py"; SCRIPTS = f"[`{SCRIPT}`](https://finitering.space/src/{PKG}/)"; RUNTIME = "≈ 8 min on Colab; the 10⁸ comb of block C and the 8×10⁷ comb of block D are the slow parts"      # the one script, linked to its source page14LEDGER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "docs", PKG, f"{PKG}-ledger.json")15cells = []16def md(s, cid): cells.append({"cell_type": "markdown", "metadata": {"id": cid}, "source": s})17def code(s, cid): cells.append({"cell_type": "code", "metadata": {"id": cid}, "execution_count": None, "outputs": [], "source": s})1819def plain(tex):20    """The predicate\'s text for a code comment: TeX kept, whitespace collapsed, wrapped at 110 columns."""21    words = " ".join(tex.split()).split(" "); lines, cur = [], "#"22    for w in words:23        if len(cur) + 1 + len(w) > 110: lines.append(cur); cur = "#"24        cur += " " + w25    lines.append(cur); return "\n".join(lines)2627data = json.load(open(LEDGER, encoding="utf-8"))28rows = [r for b in data["blocks"] for r in b["rows"]]29witnessed = [r for r in rows if f"{PAPER}:{r['label']}" in dcommon.PREDICATES]3031md(f"""## Riemann Hypothesis over Finite Holographic Substrate, [{CITE}]({DOI})3233Each cell below verifies one predicate of the paper's predicate ledger (Appendix {APPENDIX}; [{LEDGER_URL[8:]}]({LEDGER_URL})): it runs the34blocks of {SCRIPTS} whose checks cite the predicate, prints the check and lists every record that cites it with its verdict. Any cell can be run first, or *Runtime → Run all* ({RUNTIME}).""", "header")3536# the package from the site as a named requirement through the site's find-links page (docs/pkg/index.html): pip checks the37# installed set first, so a second call in the session is "Requirement already satisfied" (a URL archive would be rebuilt every time)38INSTALL = "!pip install -q frc-20-rh --find-links https://finitering.space/pkg/"39md("""Every cell is self-contained: its first line installs the package from the site (pip reports it already satisfied once it is there), its last runs the predicate. The blocks redraw the paper's numerical figures into `figures/` as they run.""", "note")4041for r in witnessed:42    lab = f"{PAPER}:{r['label']}"43    code(f"{INSTALL}\n# {lab} ({r['key']}) [{r['tag']}] — the deciding check {dcommon.PREDICATES[lab]}\n{plain(r['predicate'])}\nfrom frc_20_rh import predicate; predicate(\"{lab}\")", r['key'])4445md("""## Summary4647The cells above are the paper's python-witnessed predicates; the whole script, block by block, is `python3 rh.py`48(104 checks: 63 exact, 38 [approx], 3 [chart]; `results.json`), `python3 -m frc_20_rh` once installed.""", "summary")49code(f"""{INSTALL}50from frc_20_rh import verify_all51assert verify_all(), "a check failed"52print("all checks pass")""", "run-all")5354nb = {"cells": cells, "metadata": {"colab": {"provenance": [], "toc_visible": True}, "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},55      "language_info": {"name": "python"}}, "nbformat": 4, "nbformat_minor": 5}56for c in nb["cells"]: c["id"] = c["metadata"]["id"]          # nbformat 4.5: the cell id at top level too, the same stable value57with open(NB, "w", encoding="utf-8") as f: json.dump(nb, f, indent=1, ensure_ascii=False); f.write("\n")58print(f"wrote {NB}: {len(cells)} cells, {len(witnessed)} predicate cells")59