machinechecked 0.1.8__tar.gz → 0.1.10__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.10}/PKG-INFO +1 -1
  2. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
  3. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/SOURCES.txt +3 -2
  4. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/assess.py +17 -3
  5. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/cli.py +46 -2
  6. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/config.py +4 -0
  7. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/ProofLensProbe.lean +25 -7
  8. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/export.py +6 -1
  9. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/manifest.py +20 -1
  10. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/pipeline.py +31 -8
  11. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/promote.py +10 -4
  12. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/replay.py +23 -0
  13. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/server.py +11 -6
  14. machinechecked-0.1.10/engine/python/prooflens/symbols.py +151 -0
  15. machinechecked-0.1.10/engine/python/prooflens/web/assets/index-B97yx2Rs.js +286 -0
  16. machinechecked-0.1.8/engine/python/prooflens/web/assets/index--l_fVRcG.css → machinechecked-0.1.10/engine/python/prooflens/web/assets/index-Cm5G8Hy5.css +1 -1
  17. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/index.html +2 -2
  18. {machinechecked-0.1.8 → machinechecked-0.1.10}/pyproject.toml +1 -1
  19. machinechecked-0.1.8/engine/python/prooflens/web/assets/index-CJsp3IHP.js +0 -286
  20. {machinechecked-0.1.8 → machinechecked-0.1.10}/LICENSE +0 -0
  21. {machinechecked-0.1.8 → machinechecked-0.1.10}/README.md +0 -0
  22. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
  23. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
  24. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/requires.txt +0 -0
  25. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
  26. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/__init__.py +0 -0
  27. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/__main__.py +0 -0
  28. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/audit.py +0 -0
  29. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/bundle.py +0 -0
  30. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/cache.py +0 -0
  31. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/prooflens.sty +0 -0
  32. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
  33. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
  34. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
  35. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
  36. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/deps.py +0 -0
  37. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/evidence.py +0 -0
  38. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/formalization.py +0 -0
  39. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/paper.py +0 -0
  40. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/pdfclaims.py +0 -0
  41. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/probe.py +0 -0
  42. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/review_cli.py +0 -0
  43. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/review_queue.py +0 -0
  44. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/reviews.py +0 -0
  45. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/schemas.py +0 -0
  46. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/simple.py +0 -0
  47. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/sources.py +0 -0
  48. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/tex.py +0 -0
  49. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/util.py +0 -0
  50. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  51. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  52. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  53. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  54. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  55. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  56. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  57. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  58. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  59. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  60. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  61. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  62. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  63. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  64. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  65. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  66. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  67. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  69. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
  70. {machinechecked-0.1.8 → machinechecked-0.1.10}/engine/python/prooflens/web/theme.css +0 -0
  71. {machinechecked-0.1.8 → machinechecked-0.1.10}/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.10
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.10
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-B97yx2Rs.js
67
+ engine/python/prooflens/web/assets/index-Cm5G8Hy5.css
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"))
@@ -228,7 +228,12 @@ def cmd_view(a):
228
228
  res = build(cfg, web_dist=_web_dist(a.web), reuse_lean=True)
229
229
  except RuntimeError:
230
230
  res = build(cfg, web_dist=_web_dist(a.web))
231
- serve(res["site"], a.port, None, not a.no_browser)
231
+
232
+ def on_symbol(req):
233
+ from .symbols import from_reader
234
+ from_reader(cfg, req, _web_dist(a.web))
235
+
236
+ serve(res["site"], a.port, None, not a.no_browser, on_symbol=on_symbol)
232
237
  return
233
238
  from .server import serve
234
239
  from .simple import save_link
@@ -526,6 +531,23 @@ def _print_inspect(out: dict, dependencies: bool):
526
531
  print(" (from the cache: no Lean input changed)")
527
532
 
528
533
 
534
+ def cmd_symbol(a):
535
+ from . import symbols as sy
536
+ cfg = cfgmod.load(_config_arg(a))
537
+ try:
538
+ if a.action == "add":
539
+ ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of,
540
+ term=a.term)
541
+ print(f"linked {a.tex} in {a.claim} to {ln['lean']} (by {ln['by']}); "
542
+ "rebuild the site to show it")
543
+ elif a.action == "remove":
544
+ print(f"removed {sy.remove(cfg, a.claim, a.tex)} link(s)")
545
+ else:
546
+ print(sy.listing(cfg))
547
+ except (sy.SymbolError, OSError) as e:
548
+ sys.exit(f"machinechecked: {e}")
549
+
550
+
529
551
  def cmd_serve(a):
530
552
  cfg = cfgmod.load(_config_arg(a))
531
553
  site = Path(a.dir).resolve() if a.dir else cfg.out_dir / "site"
@@ -676,7 +698,9 @@ def main(argv=None):
676
698
  b.add_argument("--skip-tex", action="store_true", help=argparse.SUPPRESS)
677
699
  b.add_argument("--lake", default="lake", help=argparse.SUPPRESS)
678
700
  b.add_argument("--no-lean-build", action="store_true", help=argparse.SUPPRESS)
679
- b.add_argument("--reuse-lean", action="store_true", help=argparse.SUPPRESS)
701
+ b.add_argument("--reuse-lean", action="store_true",
702
+ help="reuse the last Lean results when no Lean input changed (after an edit to "
703
+ "the claim inventory or the reviews, say)")
680
704
  b.add_argument("--web", help=argparse.SUPPRESS)
681
705
  b.add_argument("--fail-on-violation", action="store_true", help=argparse.SUPPRESS)
682
706
  b.set_defaults(func=cmd_build)
@@ -772,6 +796,26 @@ def main(argv=None):
772
796
  ins.add_argument("--refresh", action="store_true", help=argparse.SUPPRESS)
773
797
  ins.set_defaults(func=cmd_inspect)
774
798
 
799
+ sy = sub.add_parser("symbol", help="link a symbol of the paper to a Lean object (an assertion "
800
+ "under your name; display only)")
801
+ sys_ = sy.add_subparsers(dest="action", required=True)
802
+ for name in ("add", "remove", "list"):
803
+ p_ = sys_.add_parser(name)
804
+ if name != "list":
805
+ p_.add_argument("claim", help="the claim id, e.g. P:thm:main")
806
+ p_.add_argument("tex", help="the symbol as the paper's TeX writes it, e.g. '\\nu'")
807
+ if name == "add":
808
+ p_.add_argument("decl", help="the claim's Lean statement")
809
+ p_.add_argument("--var", help="the variable it is (a binder's name or index)")
810
+ p_.add_argument("--type-of", dest="type_of", help="the binder whose type it is")
811
+ p_.add_argument("--term", help="the sub-term it is, as WHERE#K: b:<binder>, c (the "
812
+ "conclusion) or l:<part>, and the sub-term's number")
813
+ p_.add_argument("--as", dest="reviewer",
814
+ default=os.environ.get("MACHINECHECKED_REVIEWER"),
815
+ help="human:NAME or llm:MODEL (default: $MACHINECHECKED_REVIEWER)")
816
+ p_.add_argument("-c", "--config", default=None)
817
+ p_.set_defaults(func=cmd_symbol)
818
+
775
819
  s = sub.add_parser("serve")
776
820
  s.add_argument("-c", "--config", default=None)
777
821
  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"),
@@ -167,15 +167,18 @@ def constPrint (ci : ConstantInfo) : MetaM (String × String × Array Name) := d
167
167
 
168
168
  /-- Flatten tagged code into segments; a segment carries the constant it names (`ref`), or the
169
169
  index of the statement's binder it refers to (`var`, a position in `vars`), when the innermost
170
- subexpression around it is one. -/
170
+ subexpression around it is one. Each tagged subexpression is also recorded as the range of
171
+ segments it covers (`terms`, in printing order, an outer one before those inside it), so that the
172
+ reader can select a whole sub-term. -/
171
173
  partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Option (String × Json))
172
- (acc : Array Json) : Array Json :=
174
+ (acc : Array Json) (terms : Array (Nat × Nat)) : Array Json × Array (Nat × Nat) :=
173
175
  match t with
174
176
  | Widget.TaggedText.text s =>
175
177
  match ref with
176
- | some (k, v) => acc.push (Json.mkObj [("t", s), (k, v)])
177
- | none => acc.push (Json.mkObj [("t", s)])
178
- | Widget.TaggedText.append xs => xs.foldl (fun a x => segments vars x ref a) acc
178
+ | some (k, v) => (acc.push (Json.mkObj [("t", s), (k, v)]), terms)
179
+ | none => (acc.push (Json.mkObj [("t", s)]), terms)
180
+ | Widget.TaggedText.append xs =>
181
+ xs.foldl (fun (a, ts) x => segments vars x ref a ts) (acc, terms)
179
182
  | Widget.TaggedText.tag info sub =>
180
183
  let r := match info.info.val.info with
181
184
  | .ofTermInfo ti => match ti.expr with
@@ -183,7 +186,21 @@ partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Opt
183
186
  | .fvar id => (vars.findIdx? (· == id)).map fun i => ("var", toJson i)
184
187
  | _ => none
185
188
  | _ => none
186
- segments vars sub r acc
189
+ let start := acc.size
190
+ let slot := terms.size
191
+ let (acc', terms') := segments vars sub r acc (terms.push (start, start))
192
+ (acc', terms'.set! slot (start, acc'.size))
193
+
194
+ /-- The sub-terms worth selecting: those covering two segments or more, each range once (the
195
+ outermost tag of a range keeps it), and none for a very large term. -/
196
+ def termsJson (terms : Array (Nat × Nat)) : Json := Id.run do
197
+ let mut out : Array Json := #[]
198
+ let mut seen : Array (Nat × Nat) := #[]
199
+ for (a, b) in terms do
200
+ if b - a ≥ 2 && !seen.contains (a, b) then
201
+ seen := seen.push (a, b)
202
+ out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b)])
203
+ return Json.arr (if out.size > 3000 then #[] else out)
187
204
 
188
205
  /-- The fields of a pretty-printed expression with navigable constants and binders; plain text
189
206
  if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe. -/
@@ -193,7 +210,8 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
193
210
  -- term applies is a constant the reader can name; the text is the same.
194
211
  let code ← withOptions (fun o => o.setBool `pp.tagAppFns true) (Widget.ppExprTagged e)
195
212
  let text := toString (← ppExpr e)
196
- return [("text", Json.str text), ("segments", Json.arr (segments vars code none #[]))]
213
+ let (segs, terms) := segments vars code none #[] #[]
214
+ return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms)]
197
215
  catch _ =>
198
216
  try
199
217
  return [("text", Json.str (toString (← ppExpr e)))]
@@ -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`."""
@@ -2,7 +2,9 @@
2
2
 
3
3
  It listens on 127.0.0.1 only. `GET /api/status` tells the reader it may edit; `POST /api/link`
4
4
  with `{"key", "lean": [names] | null, "reject": [names]}` records a link (or removes it, or
5
- rejects suggestions) in `prooflens.links.json` and rebuilds the view.
5
+ rejects suggestions) in `prooflens.links.json` and rebuilds the view. In a full assessment,
6
+ `POST /api/symbol` with `{"action": "add" | "remove", "claim", "tex", "decl", "var" | "type_of",
7
+ "by"}` records or removes a symbol link (docs/SYMBOL_LINKS.md) and rewrites the site.
6
8
  """
7
9
 
8
10
  from __future__ import annotations
@@ -14,8 +16,10 @@ import threading
14
16
  from pathlib import Path
15
17
 
16
18
 
17
- def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
19
+ def serve(site: Path, port: int, on_link=None, open_browser: bool = True, on_symbol=None):
18
20
  lock = threading.Lock()
21
+ editable = on_link is not None or on_symbol is not None
22
+ routes = {"/api/link": on_link, "/api/symbol": on_symbol}
19
23
 
20
24
  class Handler(http.server.SimpleHTTPRequestHandler):
21
25
  def log_message(self, *a):
@@ -31,10 +35,10 @@ def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
31
35
 
32
36
  def do_GET(self):
33
37
  if self.path == "/api/status":
34
- return self._json(200, {"editable": on_link is not None})
38
+ return self._json(200, {"editable": editable})
35
39
  # The data index says the page may edit (only this local server says so; a static
36
40
  # copy of the site never asks a server anything).
37
- if self.path.split("?")[0] == "/data/index.json" and on_link is not None:
41
+ if self.path.split("?")[0] == "/data/index.json" and editable:
38
42
  try:
39
43
  data = json.loads((site / "data" / "index.json").read_text(encoding="utf-8"))
40
44
  except (OSError, ValueError):
@@ -43,13 +47,14 @@ def serve(site: Path, port: int, on_link=None, open_browser: bool = True):
43
47
  return super().do_GET()
44
48
 
45
49
  def do_POST(self):
46
- if self.path != "/api/link" or on_link is None:
50
+ handle = routes.get(self.path)
51
+ if handle is None:
47
52
  return self._json(404, {"error": "not found"})
48
53
  try:
49
54
  n = int(self.headers.get("Content-Length", "0"))
50
55
  req = json.loads(self.rfile.read(n) or b"{}")
51
56
  with lock:
52
- on_link(req)
57
+ handle(req)
53
58
  return self._json(200, {"ok": True})
54
59
  except Exception as e: # the reader shows the message
55
60
  return self._json(400, {"error": str(e)})
@@ -0,0 +1,151 @@
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 _term_pp(spec: dict, where: str) -> dict | None:
40
+ """The pretty-printed term a sub-term's place names: `b:<i>` a binder's type, `c` the
41
+ conclusion, `l:<n>` the n-th part of a conclusion split by its logic."""
42
+ concl = spec.get("conclusion") or {}
43
+ if where == "c":
44
+ return concl
45
+ if where.startswith("b:") and where[2:].isdigit():
46
+ bs = spec.get("binders", [])
47
+ i = int(where[2:])
48
+ return bs[i].get("type") if i < len(bs) else None
49
+ if where.startswith("l:") and where[2:].isdigit():
50
+ leaves = []
51
+
52
+ def walk(n):
53
+ if "leaf" in n:
54
+ leaves.append(n["leaf"])
55
+ for a in n.get("args", []):
56
+ walk(a)
57
+ if concl.get("logic"):
58
+ walk(concl["logic"])
59
+ n = int(where[2:])
60
+ return leaves[n] if n < len(leaves) else None
61
+ return None
62
+
63
+
64
+ def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | None = None,
65
+ type_of: str | None = None, term: str | None = None) -> dict:
66
+ """Record a link from `symbol` in `claim`'s printed statement to the variable `var` (or the
67
+ type of the binder `type_of`) of the Lean statement `decl`, by `by`."""
68
+ from .pipeline import lean_inputs_digest
69
+ from .promote import latest_record
70
+ if not re.fullmatch(r"(human|llm):\S+", by or ""):
71
+ raise SymbolError("name the link's author as human:NAME or llm:MODEL (--as)")
72
+ if sum(x is not None for x in (var, type_of, term)) != 1:
73
+ raise SymbolError("give exactly one of --var NAME, --type-of NAME and --term WHERE#K")
74
+ record = latest_record(cfg)
75
+ body = record["body"]
76
+ if body["provenance"].get("lean_inputs_sha256") != lean_inputs_digest(cfg):
77
+ raise SymbolError("the Lean project changed since the last build: run `machinechecked "
78
+ "build` first, so the link is pinned to the current statement")
79
+ _, chunks, _ = mf.build(record, "symbols")
80
+ chunk = next((c for c in chunks.values() if c["id"] == claim), None)
81
+ if chunk is None:
82
+ raise SymbolError(f"no claim {claim}")
83
+ if decl not in {cl.get("spec") for cl in chunk["clauses"]}:
84
+ raise SymbolError(f"{decl} is not a statement of {claim}")
85
+ tex = chunk.get("statement_tex")
86
+ if not tex or not _in_math(tex, symbol):
87
+ raise SymbolError(f"{symbol!r} does not occur in the mathematics of {claim}'s printed "
88
+ "statement")
89
+ spec = (body.get("lean") or {}).get("specs", {}).get(decl) or {}
90
+ if term is not None:
91
+ where, _, k = term.partition("#")
92
+ pp = _term_pp(spec, where)
93
+ if pp is None or not k.isdigit() or int(k) >= len(pp.get("terms") or []):
94
+ raise SymbolError(f"{decl} has no sub-term {term!r} (WHERE#K: b:<binder>, c or "
95
+ "l:<part>, then the sub-term's number)")
96
+ target = {"decl": decl, "term": int(k), "in": where}
97
+ else:
98
+ names = [b.get("name") for b in spec.get("binders", [])]
99
+ want = var if var is not None else type_of
100
+ idx = int(want) if want.isdigit() else (names.index(want) if want in names else None)
101
+ if idx is None or not 0 <= idx < len(names):
102
+ raise SymbolError(f"{decl} has no binder {want!r} (it has {', '.join(names)})")
103
+ target = {"decl": decl, "var": idx} if var is not None else \
104
+ {"decl": decl, "binder": idx, "path": "type"}
105
+ link = {"claim": claim, "symbol": {"tex": symbol, "occurrence": "all"}, "lean": target,
106
+ "by": by, "pins": {"statement": spec.get("fingerprint"), "source": sha256_text(tex)}}
107
+ data = read_json(cfg.symbols) if cfg.symbols.exists() else {"schema": SCHEMA, "links": []}
108
+ data["links"] = [ln for ln in data.get("links", [])
109
+ if not (ln.get("claim") == claim and (ln.get("symbol") or {}).get("tex") == symbol)]
110
+ data["links"].append(link)
111
+ write_json(cfg.symbols, data)
112
+ return link
113
+
114
+
115
+ def remove(cfg: Config, claim: str, symbol: str) -> int:
116
+ if not cfg.symbols.exists():
117
+ return 0
118
+ data = read_json(cfg.symbols)
119
+ before = len(data.get("links", []))
120
+ data["links"] = [ln for ln in data.get("links", [])
121
+ if not (ln.get("claim") == claim and (ln.get("symbol") or {}).get("tex") == symbol)]
122
+ write_json(cfg.symbols, data)
123
+ return before - len(data["links"])
124
+
125
+
126
+ def listing(cfg: Config) -> str:
127
+ if not cfg.symbols.exists():
128
+ return "no symbol links"
129
+ return "\n".join(f"{ln['claim']} {ln['symbol']['tex']} -> {json.dumps(ln['lean'])} "
130
+ f"(by {ln['by']})" for ln in read_json(cfg.symbols).get("links", []))
131
+
132
+
133
+ def from_reader(cfg: Config, req: dict, web_dist=None) -> None:
134
+ """A symbol link made or removed in the local reader (`POST /api/symbol`), with the checks
135
+ of `symbol add`; the site is then rewritten from the stored evidence (links are display
136
+ only, so nothing is probed or assessed again)."""
137
+ from .pipeline import rebuild_site
138
+
139
+ def text(v):
140
+ return None if v is None else str(v)
141
+ if not isinstance(req.get("claim"), str) or not isinstance(req.get("tex"), str):
142
+ raise SymbolError("a symbol request names a claim and a symbol")
143
+ if req.get("action") == "remove":
144
+ remove(cfg, req["claim"], req["tex"])
145
+ elif req.get("action") == "add":
146
+ add(cfg, req["claim"], req["tex"], str(req.get("decl") or ""), req.get("by"),
147
+ var=text(req.get("var")), type_of=text(req.get("type_of")),
148
+ term=text(req.get("term")))
149
+ else:
150
+ raise SymbolError(f"unknown action {req.get('action')!r}")
151
+ rebuild_site(cfg, web_dist, None)