machinechecked 0.1.8__tar.gz → 0.1.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {machinechecked-0.1.8 → machinechecked-0.1.9}/PKG-INFO +1 -1
  2. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
  3. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/SOURCES.txt +3 -2
  4. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/assess.py +17 -3
  5. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/cli.py +37 -1
  6. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/config.py +4 -0
  7. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/export.py +6 -1
  8. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/manifest.py +20 -1
  9. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/pipeline.py +31 -8
  10. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/promote.py +10 -4
  11. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/replay.py +23 -0
  12. machinechecked-0.1.9/engine/python/prooflens/symbols.py +97 -0
  13. machinechecked-0.1.8/engine/python/prooflens/web/assets/index--l_fVRcG.css → machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CF9Ifrju.css +1 -1
  14. machinechecked-0.1.9/engine/python/prooflens/web/assets/index-CsVq8qV_.js +286 -0
  15. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/index.html +2 -2
  16. {machinechecked-0.1.8 → machinechecked-0.1.9}/pyproject.toml +1 -1
  17. machinechecked-0.1.8/engine/python/prooflens/web/assets/index-CJsp3IHP.js +0 -286
  18. {machinechecked-0.1.8 → machinechecked-0.1.9}/LICENSE +0 -0
  19. {machinechecked-0.1.8 → machinechecked-0.1.9}/README.md +0 -0
  20. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
  21. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
  22. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/requires.txt +0 -0
  23. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
  24. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/__init__.py +0 -0
  25. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/__main__.py +0 -0
  26. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/audit.py +0 -0
  27. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/bundle.py +0 -0
  28. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/cache.py +0 -0
  29. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/ProofLensProbe.lean +0 -0
  30. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/prooflens.sty +0 -0
  31. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
  32. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
  33. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
  34. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
  35. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/deps.py +0 -0
  36. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/evidence.py +0 -0
  37. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/formalization.py +0 -0
  38. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/paper.py +0 -0
  39. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/pdfclaims.py +0 -0
  40. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/probe.py +0 -0
  41. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/review_cli.py +0 -0
  42. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/review_queue.py +0 -0
  43. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/reviews.py +0 -0
  44. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/schemas.py +0 -0
  45. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/server.py +0 -0
  46. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/simple.py +0 -0
  47. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/sources.py +0 -0
  48. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/tex.py +0 -0
  49. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/util.py +0 -0
  50. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  51. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  52. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  53. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  54. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  55. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  56. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  57. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  58. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  59. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  60. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  61. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  62. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  63. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  64. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  65. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  66. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  67. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  69. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
  70. {machinechecked-0.1.8 → machinechecked-0.1.9}/engine/python/prooflens/web/theme.css +0 -0
  71. {machinechecked-0.1.8 → machinechecked-0.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machinechecked
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Read a mathematical paper beside its Lean formalisation, and see claim by claim what Lean establishes.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://machinechecked.org
@@ -33,6 +33,7 @@ engine/python/prooflens/schemas.py
33
33
  engine/python/prooflens/server.py
34
34
  engine/python/prooflens/simple.py
35
35
  engine/python/prooflens/sources.py
36
+ engine/python/prooflens/symbols.py
36
37
  engine/python/prooflens/tex.py
37
38
  engine/python/prooflens/util.py
38
39
  engine/python/prooflens/data/ProofLensProbe.lean
@@ -62,6 +63,6 @@ engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2
62
63
  engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2
63
64
  engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2
64
65
  engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2
65
- engine/python/prooflens/web/assets/index--l_fVRcG.css
66
- engine/python/prooflens/web/assets/index-CJsp3IHP.js
66
+ engine/python/prooflens/web/assets/index-CF9Ifrju.css
67
+ engine/python/prooflens/web/assets/index-CsVq8qV_.js
67
68
  engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
@@ -140,10 +140,21 @@ class Assessor:
140
140
  return {"state": "not-run", "detail": "no Comparator record for this release"}
141
141
  if "error" in rec:
142
142
  return {"state": "unverified", "detail": rec["error"]}
143
- if not self.project_commit or rec.get("commit") != self.project_commit:
143
+ since = ""
144
+ if not self.project_commit or not rec.get("commit"):
144
145
  return {"state": "unverified",
145
146
  "detail": f"the Comparator record is for commit {str(rec.get('commit'))[:12]}"
146
147
  f", not this one"}
148
+ if rec["commit"] != self.project_commit:
149
+ # A record committed to the project names the commit before the one holding it; it
150
+ # counts when that commit is an ancestor and no Lean input changed since.
151
+ from .replay import unchanged_since
152
+ why = unchanged_since(self.cfg.lean_root, rec["commit"], self.project_commit)
153
+ if why:
154
+ return {"state": "unverified",
155
+ "detail": f"the Comparator record is for commit {rec['commit'][:12]}, not "
156
+ f"this one: {why}"}
157
+ since = f"; replayed at commit {rec['commit'][:12]}, no Lean input changed since"
147
158
  # A record made by `machinechecked replay` also says whether the run passed, whether the
148
159
  # tree was clean, and the environment it ran in; each must hold for the replay to count.
149
160
  if rec.get("passed") is False:
@@ -160,7 +171,7 @@ class Assessor:
160
171
  if thm not in set(rec.get("replayed", [])):
161
172
  return {"state": "not-run", "detail": "the Comparator record does not cover this proof"}
162
173
  return {"state": "pass", "detail": "Comparator replayed the proof in a fresh kernel ("
163
- + ", ".join(rec.get("kernels", ["lean"])) + ")"}
174
+ + ", ".join(rec.get("kernels", ["lean"])) + ")" + since}
164
175
 
165
176
  def _environment(self) -> dict:
166
177
  """The audited project's Lean version and Lake manifest hash."""
@@ -252,7 +263,10 @@ class Assessor:
252
263
 
253
264
  if srec:
254
265
  roles = [b["role"] for b in srec.get("binders", [])]
255
- if ("hypothesis" in roles or "instance" in roles) and not cl.get("witness"):
266
+ # A checked refutation needs no witness: a proof of ¬S exhibits an instance meeting
267
+ # S's hypotheses (were they never met, S would hold vacuously and not be refutable).
268
+ if ("hypothesis" in roles or "instance" in roles) and not cl.get("witness") \
269
+ and not res.get("refute_ok"):
256
270
  self.findings.append(_finding(
257
271
  "obligation", "witness", subj,
258
272
  f"{spec} has hypotheses but no witness that they can be met"))
@@ -526,6 +526,22 @@ def _print_inspect(out: dict, dependencies: bool):
526
526
  print(" (from the cache: no Lean input changed)")
527
527
 
528
528
 
529
+ def cmd_symbol(a):
530
+ from . import symbols as sy
531
+ cfg = cfgmod.load(_config_arg(a))
532
+ try:
533
+ if a.action == "add":
534
+ ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of)
535
+ print(f"linked {a.tex} in {a.claim} to {ln['lean']} (by {ln['by']}); "
536
+ "rebuild the site to show it")
537
+ elif a.action == "remove":
538
+ print(f"removed {sy.remove(cfg, a.claim, a.tex)} link(s)")
539
+ else:
540
+ print(sy.listing(cfg))
541
+ except (sy.SymbolError, OSError) as e:
542
+ sys.exit(f"machinechecked: {e}")
543
+
544
+
529
545
  def cmd_serve(a):
530
546
  cfg = cfgmod.load(_config_arg(a))
531
547
  site = Path(a.dir).resolve() if a.dir else cfg.out_dir / "site"
@@ -676,7 +692,9 @@ def main(argv=None):
676
692
  b.add_argument("--skip-tex", action="store_true", help=argparse.SUPPRESS)
677
693
  b.add_argument("--lake", default="lake", help=argparse.SUPPRESS)
678
694
  b.add_argument("--no-lean-build", action="store_true", help=argparse.SUPPRESS)
679
- b.add_argument("--reuse-lean", action="store_true", help=argparse.SUPPRESS)
695
+ b.add_argument("--reuse-lean", action="store_true",
696
+ help="reuse the last Lean results when no Lean input changed (after an edit to "
697
+ "the claim inventory or the reviews, say)")
680
698
  b.add_argument("--web", help=argparse.SUPPRESS)
681
699
  b.add_argument("--fail-on-violation", action="store_true", help=argparse.SUPPRESS)
682
700
  b.set_defaults(func=cmd_build)
@@ -772,6 +790,24 @@ def main(argv=None):
772
790
  ins.add_argument("--refresh", action="store_true", help=argparse.SUPPRESS)
773
791
  ins.set_defaults(func=cmd_inspect)
774
792
 
793
+ sy = sub.add_parser("symbol", help="link a symbol of the paper to a Lean object (an assertion "
794
+ "under your name; display only)")
795
+ sys_ = sy.add_subparsers(dest="action", required=True)
796
+ for name in ("add", "remove", "list"):
797
+ p_ = sys_.add_parser(name)
798
+ if name != "list":
799
+ p_.add_argument("claim", help="the claim id, e.g. P:thm:main")
800
+ p_.add_argument("tex", help="the symbol as the paper's TeX writes it, e.g. '\\nu'")
801
+ if name == "add":
802
+ p_.add_argument("decl", help="the claim's Lean statement")
803
+ p_.add_argument("--var", help="the variable it is (a binder's name or index)")
804
+ p_.add_argument("--type-of", dest="type_of", help="the binder whose type it is")
805
+ p_.add_argument("--as", dest="reviewer",
806
+ default=os.environ.get("MACHINECHECKED_REVIEWER"),
807
+ help="human:NAME or llm:MODEL (default: $MACHINECHECKED_REVIEWER)")
808
+ p_.add_argument("-c", "--config", default=None)
809
+ p_.set_defaults(func=cmd_symbol)
810
+
775
811
  s = sub.add_parser("serve")
776
812
  s.add_argument("-c", "--config", default=None)
777
813
  s.add_argument("--dir")
@@ -60,6 +60,7 @@ class Config:
60
60
  out_dir: Path
61
61
  review_check: str | None = None
62
62
  display: Path | None = None
63
+ symbols: Path | None = None
63
64
  issues: str | None = None # "owner/repo" where the reader's "Raise issue" opens issues
64
65
  site_url: str | None = None # the public address of the published site, for permalinks
65
66
  author: str | None = None # the name the audit is published under (audit.json)
@@ -142,6 +143,9 @@ def load(path: str | Path) -> Config:
142
143
  review_check=raw.get("review", {}).get("check"),
143
144
  # Display corrections (TeX descriptions, printed numbers), outside the inventory.
144
145
  display=(base / proj["display"]).resolve() if "display" in proj else None,
146
+ # Links from symbols of the paper to Lean objects, each an author's assertion (display
147
+ # only, docs/SYMBOL_LINKS.md).
148
+ symbols=(base / proj.get("symbols", "symbols.json")).resolve(),
145
149
  issues=issue_repo(proj.get("issues"), str(path)),
146
150
  site_url=proj.get("site_url"),
147
151
  author=proj.get("author"),
@@ -130,6 +130,8 @@ def public_claim(chunk: dict, pub) -> dict:
130
130
  rung["detail"] = "located in the compiled paper"
131
131
  clauses.append(c)
132
132
  out["clauses"] = clauses
133
+ # A symbol link names paper TeX and a place in the Lean statement: published with both.
134
+ out["symbols"] = list(chunk.get("symbols", [])) if pub.source_text and pub.lean else []
133
135
  out["decls"] = dict(chunk.get("decls", {}))
134
136
  out["findings"] = [_pick(f, ["id", "tier", "code", "subject", "message", "trigger",
135
137
  "signal", "dismissed", "dismissal_stale"])
@@ -254,7 +256,10 @@ def export(cfg: Config, out: Path, release: str | None = None,
254
256
  relrec = read_json(cfg.out_dir / "releases" / f"{release}.json") if release \
255
257
  else read_json(rels[-1])
256
258
  record = ev.load(cfg.out_dir, relrec["evidence"])
257
- index, chunks, store = mf.build(record, relrec["release"])
259
+ # With the display layer the site is built with (descriptions, printed numbers, symbol
260
+ # links): what is shown changes, never what is assessed.
261
+ from .pipeline import load_display
262
+ index, chunks, store = mf.build(record, relrec["release"], load_display(cfg))
258
263
  pubs = {p.id: p.publish for p in cfg.papers}
259
264
  full_index, full_chunks, full_store = index, chunks, store
260
265
  if paper is not None:
@@ -122,6 +122,24 @@ def ladder(cl: dict, anchor: dict | None, mode: str | None, src_ok: bool | None)
122
122
  return rungs
123
123
 
124
124
 
125
+ def symbol_links(display: dict | None, cid: str, tex: str | None, lean: dict) -> list[dict]:
126
+ """The claim's symbol links, each as its author recorded it and whether it is stale: the
127
+ statement it points into has another fingerprint now, or the claim's printed text changed.
128
+ Display only (docs/SYMBOL_LINKS.md)."""
129
+ out = []
130
+ for ln in (display or {}).get("symbols", []):
131
+ if ln.get("claim") != cid:
132
+ continue
133
+ target = ln.get("lean") or {}
134
+ spec = (lean.get("specs") or {}).get(target.get("decl")) or {}
135
+ pins = ln.get("pins") or {}
136
+ stale = (pins.get("statement") != spec.get("fingerprint")
137
+ or not tex or pins.get("source") != sha256_text(tex))
138
+ out.append({"symbol": ln.get("symbol") or {}, "lean": target, "by": ln.get("by"),
139
+ "stale": bool(stale)})
140
+ return out
141
+
142
+
125
143
  def build(evidence: dict, release: str, display: dict | None = None
126
144
  ) -> tuple[dict, dict[str, dict]]:
127
145
  """The presentation manifest of `evidence`. `display` (the project's display overlay) gives
@@ -248,7 +266,8 @@ def build(evidence: dict, release: str, display: dict | None = None
248
266
  "class": status_class(a["status"]), "anchor": anchor, "source_matches": src_ok,
249
267
  "statement_tex": (anchor or {}).get("statement"),
250
268
  "blockers": [shown_names(b, clause_tex) for b in a.get("blockers", [])],
251
- "clauses": clauses, "decls": decls, "findings": fs}
269
+ "clauses": clauses, "decls": decls, "findings": fs,
270
+ "symbols": symbol_links(display, c["id"], (anchor or {}).get("statement"), lean)}
252
271
 
253
272
  prov = body["provenance"]
254
273
  index = {"schema": SCHEMA, "release": release, "evidence": evidence["id"],
@@ -243,20 +243,38 @@ def line_hashes(inv: dict, pid: str, src: Path) -> dict:
243
243
  return out
244
244
 
245
245
 
246
+ class StaleEvidence(RuntimeError):
247
+ """The stored evidence does not cover the project as it now is (or there is none): a build
248
+ is needed first. The message names the command."""
249
+
250
+
251
+ NO_RELEASE = "no release: run `machinechecked build` first"
252
+
253
+
254
+ def inventory_changed(cfg: Config, body: dict) -> str | None:
255
+ """Why the stored evidence `body` does not cover the current claim inventory, if it does
256
+ not."""
257
+ inv = read_json(cfg.inventory)
258
+ validate(inv, "inventory")
259
+ if canonical_json(inv["claims"]) != canonical_json(body["inventory"]["claims"]):
260
+ return ("the claim inventory changed since the last build: its Lean and LaTeX results "
261
+ "may not cover it; run `machinechecked build --reuse-lean` (or `machinechecked "
262
+ "build` if a Lean input changed too)")
263
+ return None
264
+
265
+
246
266
  def reassess(cfg: Config, web_dist: Path | None = None, release: str | None = None,
247
267
  log=print) -> dict:
248
268
  """Assess the latest evidence again with the current rules and the current review files,
249
269
  without probing or compiling, and store the result as a new evidence record and release."""
250
270
  rels = ev.releases(cfg.out_dir)
251
271
  if not rels:
252
- raise RuntimeError("no release: run `prooflens build` first")
272
+ raise StaleEvidence(NO_RELEASE)
253
273
  old = ev.load(cfg.out_dir, read_json(rels[-1])["evidence"])["body"]
274
+ why = inventory_changed(cfg, old)
275
+ if why:
276
+ raise StaleEvidence(why)
254
277
  inv = read_json(cfg.inventory)
255
- validate(inv, "inventory")
256
- if canonical_json(inv["claims"]) != canonical_json(old["inventory"]["claims"]):
257
- raise RuntimeError("the claim inventory changed since the stored evidence: its Lean and "
258
- "LaTeX results may not cover it; run `prooflens build` (with "
259
- "--reuse-lean if no Lean input changed)")
260
278
  reviews, review_hashes = load_reviews(cfg.reviews, cfg.ai_reviewers, cfg.root)
261
279
  dismissals = load_dismissals(cfg.dismissals)
262
280
  comp = cfg.comparator_log
@@ -299,7 +317,7 @@ def rebuild_site(cfg: Config, web_dist: Path | None = None, release: str | None
299
317
  included only if the one on disk is the one the evidence records."""
300
318
  rels = ev.releases(cfg.out_dir)
301
319
  if not rels:
302
- raise RuntimeError("no release: run `prooflens build` first")
320
+ raise StaleEvidence(NO_RELEASE)
303
321
  rel = read_json(cfg.out_dir / "releases" / f"{release}.json") if release else \
304
322
  read_json(rels[-1])
305
323
  record = ev.load(cfg.out_dir, rel["evidence"])
@@ -313,7 +331,12 @@ def rebuild_site(cfg: Config, web_dist: Path | None = None, release: str | None
313
331
 
314
332
 
315
333
  def load_display(cfg: Config) -> dict | None:
316
- return read_json(cfg.display) if cfg.display and cfg.display.exists() else None
334
+ """What changes what is shown and never what is assessed: the display overlay, and the
335
+ symbol links (docs/SYMBOL_LINKS.md)."""
336
+ out = read_json(cfg.display) if cfg.display and cfg.display.exists() else None
337
+ if cfg.symbols and cfg.symbols.exists():
338
+ out = {**(out or {}), "symbols": read_json(cfg.symbols).get("links", [])}
339
+ return out
317
340
 
318
341
 
319
342
  def write_preview(site: Path, index: dict, chunks: dict, store: dict, pdfs: dict,
@@ -48,7 +48,7 @@ class PromoteError(RuntimeError):
48
48
  def latest_record(cfg: Config) -> dict:
49
49
  rels = sorted((cfg.out_dir / "releases").glob("*.json"), key=lambda p: p.stat().st_mtime)
50
50
  if not rels:
51
- raise PromoteError("no release: run `prooflens build` first")
51
+ raise PromoteError("no release: run `machinechecked build` first")
52
52
  return ev.load(cfg.out_dir, read_json(rels[-1])["evidence"])
53
53
 
54
54
 
@@ -175,10 +175,16 @@ def plan(cfg: Config, reports: list[dict], accept_same_family: bool = False,
175
175
  allow_revealed: bool = False):
176
176
  """For each report: (report, current record, reasons it is refused)."""
177
177
  body = latest_record(cfg)["body"]
178
- from .pipeline import lean_inputs_digest
178
+ from .pipeline import inventory_changed, lean_inputs_digest
179
+ # Both before anything is written: promotion reassesses at the end, and stale evidence would
180
+ # leave markers written and the assessment not updated.
181
+ why = inventory_changed(cfg, body)
182
+ if why:
183
+ raise PromoteError(why)
179
184
  if body["provenance"].get("lean_inputs_sha256") != lean_inputs_digest(cfg):
180
- raise PromoteError("the Lean project changed since the last build: run `prooflens build` "
181
- "first, so the reports are checked against the current declarations")
185
+ raise PromoteError("the Lean project changed since the last build: run `machinechecked "
186
+ "build` first, so the reports are checked against the current "
187
+ "declarations")
182
188
  lean = body.get("lean") or {}
183
189
  out = []
184
190
  for r in reports:
@@ -43,6 +43,29 @@ def lean_changes(lean_root: Path) -> list[str]:
43
43
  return out
44
44
 
45
45
 
46
+ def unchanged_since(lean_root: Path, commit: str, head: str) -> str | None:
47
+ """Why a replay made at `commit` does not cover `head`, or None when it does: `commit` is an
48
+ ancestor of `head` and no Lean input of the project differs between them. (Committing the
49
+ replay record makes a new commit; that alone changes nothing the replay checked.)"""
50
+ import subprocess
51
+
52
+ def git(*args):
53
+ return subprocess.run(["git", *args], cwd=lean_root, capture_output=True, text=True)
54
+ if git("cat-file", "-e", f"{commit}^{{commit}}").returncode != 0:
55
+ return (f"commit {commit[:12]} is not in this clone's history (fetch more history to "
56
+ "check that no Lean input changed since)")
57
+ if git("merge-base", "--is-ancestor", commit, head).returncode != 0:
58
+ return f"commit {commit[:12]} is not an ancestor of this one"
59
+ d = git("diff", "--name-only", commit, head, "--", ".")
60
+ if d.returncode != 0:
61
+ return f"could not compare commit {commit[:12]} with this one"
62
+ changed = [p for p in d.stdout.splitlines() if p.endswith(LEAN_INPUT)]
63
+ if changed:
64
+ return (f"Lean inputs changed since commit {commit[:12]} (" + ", ".join(changed[:3])
65
+ + (", …" if len(changed) > 3 else "") + ")")
66
+ return None
67
+
68
+
46
69
  def replay(lean_root: Path, config: Path, out: Path, comparator: str = "comparator",
47
70
  lake: str = "lake", timeout: int = 6 * 3600) -> dict:
48
71
  """Run Comparator on `config` in the project at `lean_root` and write its record to `out`."""
@@ -0,0 +1,97 @@
1
+ """Symbol links: a symbol of a claim's printed statement linked to an object of its Lean
2
+ statement, recorded as a named person's assertion (`machinechecked symbol add`).
3
+
4
+ A link says that a symbol of the paper (`\\nu`, `\\mathbb R^j`) is a given variable of the Lean
5
+ statement, or a given binder's type. Saying so is what a statement review checks, so a link is
6
+ kept as its author's: it names them, it is pinned to the statement's fingerprint and to the
7
+ claim's printed text, it is shown as stale when either changes, and no status reads it
8
+ (docs/SYMBOL_LINKS.md). The links are kept in the configuration's `symbols` file
9
+ (`symbols.json` by default).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import re
16
+
17
+ from . import manifest as mf
18
+ from .config import Config
19
+ from .util import read_json, sha256_text, write_json
20
+
21
+ SCHEMA = "machinechecked/symbols@1"
22
+
23
+
24
+ class SymbolError(RuntimeError):
25
+ pass
26
+
27
+
28
+ def _in_math(tex: str, symbol: str) -> bool:
29
+ """Whether `symbol` occurs in a math part of `tex` (between $…$, \\(…\\), \\[…\\] or in a
30
+ display environment), as a whole command (`\\nu` is not the start of `\\nuexample`)."""
31
+ pat = ((r"(?<![A-Za-z\\])" if re.match(r"[A-Za-z]", symbol) else "") + re.escape(symbol)
32
+ + (r"(?![A-Za-z])" if re.search(r"[A-Za-z]$", symbol) else ""))
33
+ spans = re.findall(r"\$\$.*?\$\$|\$.*?\$|\\\(.*?\\\)|\\\[.*?\\\]|"
34
+ r"\\begin\{(?:equation|align|gather)\*?\}.*?\\end\{(?:equation|align|gather)\*?\}",
35
+ tex, re.S)
36
+ return any(re.search(pat, s) for s in spans)
37
+
38
+
39
+ def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | None = None,
40
+ type_of: str | None = None) -> dict:
41
+ """Record a link from `symbol` in `claim`'s printed statement to the variable `var` (or the
42
+ type of the binder `type_of`) of the Lean statement `decl`, by `by`."""
43
+ from .pipeline import lean_inputs_digest
44
+ from .promote import latest_record
45
+ if not re.fullmatch(r"(human|llm):\S+", by or ""):
46
+ raise SymbolError("name the link's author as human:NAME or llm:MODEL (--as)")
47
+ if (var is None) == (type_of is None):
48
+ raise SymbolError("give exactly one of --var NAME and --type-of NAME")
49
+ record = latest_record(cfg)
50
+ body = record["body"]
51
+ if body["provenance"].get("lean_inputs_sha256") != lean_inputs_digest(cfg):
52
+ raise SymbolError("the Lean project changed since the last build: run `machinechecked "
53
+ "build` first, so the link is pinned to the current statement")
54
+ _, chunks, _ = mf.build(record, "symbols")
55
+ chunk = next((c for c in chunks.values() if c["id"] == claim), None)
56
+ if chunk is None:
57
+ raise SymbolError(f"no claim {claim}")
58
+ if decl not in {cl.get("spec") for cl in chunk["clauses"]}:
59
+ raise SymbolError(f"{decl} is not a statement of {claim}")
60
+ tex = chunk.get("statement_tex")
61
+ if not tex or not _in_math(tex, symbol):
62
+ raise SymbolError(f"{symbol!r} does not occur in the mathematics of {claim}'s printed "
63
+ "statement")
64
+ spec = (body.get("lean") or {}).get("specs", {}).get(decl) or {}
65
+ names = [b.get("name") for b in spec.get("binders", [])]
66
+ want = var if var is not None else type_of
67
+ idx = int(want) if want.isdigit() else (names.index(want) if want in names else None)
68
+ if idx is None or not 0 <= idx < len(names):
69
+ raise SymbolError(f"{decl} has no binder {want!r} (it has {', '.join(names)})")
70
+ target = {"decl": decl, "var": idx} if var is not None else \
71
+ {"decl": decl, "binder": idx, "path": "type"}
72
+ link = {"claim": claim, "symbol": {"tex": symbol, "occurrence": "all"}, "lean": target,
73
+ "by": by, "pins": {"statement": spec.get("fingerprint"), "source": sha256_text(tex)}}
74
+ data = read_json(cfg.symbols) if cfg.symbols.exists() else {"schema": SCHEMA, "links": []}
75
+ data["links"] = [ln for ln in data.get("links", [])
76
+ if not (ln.get("claim") == claim and (ln.get("symbol") or {}).get("tex") == symbol)]
77
+ data["links"].append(link)
78
+ write_json(cfg.symbols, data)
79
+ return link
80
+
81
+
82
+ def remove(cfg: Config, claim: str, symbol: str) -> int:
83
+ if not cfg.symbols.exists():
84
+ return 0
85
+ data = read_json(cfg.symbols)
86
+ before = len(data.get("links", []))
87
+ data["links"] = [ln for ln in data.get("links", [])
88
+ if not (ln.get("claim") == claim and (ln.get("symbol") or {}).get("tex") == symbol)]
89
+ write_json(cfg.symbols, data)
90
+ return before - len(data["links"])
91
+
92
+
93
+ def listing(cfg: Config) -> str:
94
+ if not cfg.symbols.exists():
95
+ return "no symbol links"
96
+ return "\n".join(f"{ln['claim']} {ln['symbol']['tex']} -> {json.dumps(ln['lean'])} "
97
+ f"(by {ln['by']})" for ln in read_json(cfg.symbols).get("links", []))