machinechecked 0.1.13__tar.gz → 0.1.14__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.
- {machinechecked-0.1.13 → machinechecked-0.1.14}/PKG-INFO +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/SOURCES.txt +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/assess.py +4 -2
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/cli.py +3 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/ProofLensProbe.lean +61 -42
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/manifest.py +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/source_regions.py +61 -9
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/symbols.py +42 -5
- machinechecked-0.1.13/engine/python/prooflens/web/assets/index-DevCW_Pm.js → machinechecked-0.1.14/engine/python/prooflens/web/assets/index-YAI0NIYT.js +3 -3
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/index.html +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/pyproject.toml +1 -1
- {machinechecked-0.1.13 → machinechecked-0.1.14}/LICENSE +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/README.md +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/requires.txt +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/__init__.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/__main__.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/audit.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/bundle.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/cache.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/config.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/prooflens.sty +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/statuses.json +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/deps.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/evidence.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/export.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/formalization.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/paper.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/pdfclaims.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/pipeline.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/probe.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/promote.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/published.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/replay.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/review_cli.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/review_queue.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/reviews.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/schemas.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/server.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/simple.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/sources.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/status.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/tex.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/util.py +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/cursor-editorTextHighlight-kG3uUOwL.svg +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/index-GfZV3aEH.css +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/web/theme.css +0 -0
- {machinechecked-0.1.13 → machinechecked-0.1.14}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: machinechecked
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
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
|
{machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: machinechecked
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
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
|
{machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/machinechecked.egg-info/SOURCES.txt
RENAMED
|
@@ -68,6 +68,6 @@ engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2
|
|
|
68
68
|
engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2
|
|
69
69
|
engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2
|
|
70
70
|
engine/python/prooflens/web/assets/cursor-editorTextHighlight-kG3uUOwL.svg
|
|
71
|
-
engine/python/prooflens/web/assets/index-DevCW_Pm.js
|
|
72
71
|
engine/python/prooflens/web/assets/index-GfZV3aEH.css
|
|
72
|
+
engine/python/prooflens/web/assets/index-YAI0NIYT.js
|
|
73
73
|
engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
|
|
@@ -25,7 +25,7 @@ from __future__ import annotations
|
|
|
25
25
|
from .status import fields
|
|
26
26
|
|
|
27
27
|
from .reviews import Review, history
|
|
28
|
-
from .source_regions import SCHEME as SOURCE_SCHEME, matches as source_matches
|
|
28
|
+
from .source_regions import SCHEME as SOURCE_SCHEME, changed_line, matches as source_matches
|
|
29
29
|
|
|
30
30
|
OUT_OF_SCOPE = {"expository", "literature", "empirical", "proof-step", "part-of", "duplicate"}
|
|
31
31
|
|
|
@@ -541,9 +541,11 @@ class Assessor:
|
|
|
541
541
|
"revision (python -m prooflens.source_regions --config FILE "
|
|
542
542
|
f"--paper {pid}); then rebuild"))
|
|
543
543
|
elif not source_matches(c, t):
|
|
544
|
+
where = changed_line(c, region) if region else None
|
|
544
545
|
detail = region.get("error") or (
|
|
545
546
|
"is missing; rebuild the source evidence" if not region else
|
|
546
|
-
"differs from the frozen source region"
|
|
547
|
+
"differs from the frozen source region"
|
|
548
|
+
+ (f": {where}" if where else ""))
|
|
547
549
|
self.findings.append(_finding(
|
|
548
550
|
"violation", "source-changed", c["id"],
|
|
549
551
|
f"the source region at {c['location']} {detail}"))
|
|
@@ -535,7 +535,7 @@ def cmd_symbol(a):
|
|
|
535
535
|
try:
|
|
536
536
|
if a.action == "add":
|
|
537
537
|
ln = sy.add(cfg, a.claim, a.tex, a.decl, a.reviewer, var=a.var, type_of=a.type_of,
|
|
538
|
-
term=a.term)
|
|
538
|
+
term=a.term, at=a.at)
|
|
539
539
|
print(f"linked {a.tex} in {a.claim} to {ln['lean']} (by {ln['by']}); "
|
|
540
540
|
"rebuild the site to show it")
|
|
541
541
|
elif a.action == "remove":
|
|
@@ -808,6 +808,8 @@ def main(argv=None):
|
|
|
808
808
|
p_.add_argument("--type-of", dest="type_of", help="the binder whose type it is")
|
|
809
809
|
p_.add_argument("--term", help="the sub-term it is, as WHERE#K: b:<binder>, c (the "
|
|
810
810
|
"conclusion) or l:<part>, and the sub-term's number")
|
|
811
|
+
p_.add_argument("--at", help="the sub-term it is, by its identity in the proposition "
|
|
812
|
+
"(the `id` the reader's data gives it)")
|
|
811
813
|
p_.add_argument("--as", dest="reviewer",
|
|
812
814
|
default=os.environ.get("MACHINECHECKED_REVIEWER"),
|
|
813
815
|
help="human:NAME or llm:MODEL (default: $MACHINECHECKED_REVIEWER)")
|
{machinechecked-0.1.13 → machinechecked-0.1.14}/engine/python/prooflens/data/ProofLensProbe.lean
RENAMED
|
@@ -169,16 +169,19 @@ def constPrint (ci : ConstantInfo) : MetaM (String × String × Array Name) := d
|
|
|
169
169
|
index of the statement's binder it refers to (`var`, a position in `vars`), when the innermost
|
|
170
170
|
subexpression around it is one. Each tagged subexpression is also recorded as the range of
|
|
171
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
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
reader can select a whole sub-term, with its position in the whole proposition (`root`, the
|
|
173
|
+
position of the printed expression, extended by the tag's own `subexprPos`): the identity of a
|
|
174
|
+
sub-term, which depends on the proposition only, not on how it is printed or split. -/
|
|
175
|
+
partial def segments (vars : Array FVarId) (root : SubExpr.Pos) (t : Widget.CodeWithInfos)
|
|
176
|
+
(ref : Option (String × Json)) (acc : Array Json) (terms : Array (Nat × Nat × String)) :
|
|
177
|
+
Array Json × Array (Nat × Nat × String) :=
|
|
175
178
|
match t with
|
|
176
179
|
| Widget.TaggedText.text s =>
|
|
177
180
|
match ref with
|
|
178
181
|
| some (k, v) => (acc.push (Json.mkObj [("t", s), (k, v)]), terms)
|
|
179
182
|
| none => (acc.push (Json.mkObj [("t", s)]), terms)
|
|
180
183
|
| Widget.TaggedText.append xs =>
|
|
181
|
-
xs.foldl (fun (a, ts) x => segments vars x ref a ts) (acc, terms)
|
|
184
|
+
xs.foldl (fun (a, ts) x => segments vars root x ref a ts) (acc, terms)
|
|
182
185
|
| Widget.TaggedText.tag info sub =>
|
|
183
186
|
let r := match info.info.val.info with
|
|
184
187
|
| .ofTermInfo ti => match ti.expr with
|
|
@@ -188,23 +191,26 @@ partial def segments (vars : Array FVarId) (t : Widget.CodeWithInfos) (ref : Opt
|
|
|
188
191
|
| _ => none
|
|
189
192
|
let start := acc.size
|
|
190
193
|
let slot := terms.size
|
|
191
|
-
let
|
|
192
|
-
(acc', terms'
|
|
194
|
+
let id := toString (root.append info.subexprPos)
|
|
195
|
+
let (acc', terms') := segments vars root sub r acc (terms.push (start, start, id))
|
|
196
|
+
(acc', terms'.set! slot (start, acc'.size, id))
|
|
193
197
|
|
|
194
198
|
/-- The sub-terms worth selecting: those covering two segments or more, each range once (the
|
|
195
199
|
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
|
|
200
|
+
def termsJson (terms : Array (Nat × Nat × String)) : Json := Id.run do
|
|
197
201
|
let mut out : Array Json := #[]
|
|
198
202
|
let mut seen : Array (Nat × Nat) := #[]
|
|
199
|
-
for (a, b) in terms do
|
|
203
|
+
for (a, b, id) in terms do
|
|
200
204
|
if b - a ≥ 2 && !seen.contains (a, b) then
|
|
201
205
|
seen := seen.push (a, b)
|
|
202
|
-
out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b)])
|
|
206
|
+
out := out.push (Json.mkObj [("from", toJson a), ("to", toJson b), ("id", Json.str id)])
|
|
203
207
|
return Json.arr (if out.size > 3000 then #[] else out)
|
|
204
208
|
|
|
205
209
|
/-- The fields of a pretty-printed expression with navigable constants and binders; plain text
|
|
206
|
-
if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe.
|
|
207
|
-
|
|
210
|
+
if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe.
|
|
211
|
+
`root` is the position of `e` in the whole proposition (`id`). -/
|
|
212
|
+
def ppFields (e : Expr) (vars : Array FVarId := #[]) (root : SubExpr.Pos := .root) :
|
|
213
|
+
MetaM (List (String × Json)) := do
|
|
208
214
|
try
|
|
209
215
|
-- The type of a bound variable is printed (`pp.funBinderTypes`): `∃ Φ : T, …` says what Φ
|
|
210
216
|
-- is. The head of every application is tagged too (`pp.tagAppFns`), so that the function a
|
|
@@ -213,8 +219,9 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
|
|
|
213
219
|
let typed := fun (o : Options) => o.setBool `pp.funBinderTypes true
|
|
214
220
|
let code ← withOptions (fun o => (typed o).setBool `pp.tagAppFns true) (Widget.ppExprTagged e)
|
|
215
221
|
let text := toString (← withOptions typed (ppExpr e))
|
|
216
|
-
let (segs, terms) := segments vars code none #[] #[]
|
|
217
|
-
return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms)
|
|
222
|
+
let (segs, terms) := segments vars root code none #[] #[]
|
|
223
|
+
return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms),
|
|
224
|
+
("id", Json.str (toString root))]
|
|
218
225
|
catch _ =>
|
|
219
226
|
try
|
|
220
227
|
return [("text", Json.str (toString (← ppExpr e)))]
|
|
@@ -222,8 +229,8 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
|
|
|
222
229
|
return [("text", Json.str "(not printable)"),
|
|
223
230
|
("error", Json.str (toString (← err.toMessageData.toString)))]
|
|
224
231
|
|
|
225
|
-
def ppJson (e : Expr) (vars : Array FVarId := #[]) : MetaM Json :=
|
|
226
|
-
return Json.mkObj (← ppFields e vars)
|
|
232
|
+
def ppJson (e : Expr) (vars : Array FVarId := #[]) (root : SubExpr.Pos := .root) : MetaM Json :=
|
|
233
|
+
return Json.mkObj (← ppFields e vars root)
|
|
227
234
|
|
|
228
235
|
def isExistsApp (e : Expr) : Option (Name × Expr) :=
|
|
229
236
|
if e.isAppOfArity ``Exists 2 then
|
|
@@ -237,77 +244,89 @@ implication, "for every" or "there is" as a tree whose leaves are pretty-printed
|
|
|
237
244
|
quantifier inside the conclusion is a node (`forall`, `exists`) with its variable's name, type and
|
|
238
245
|
number, and its body as its one part. `vars` is
|
|
239
246
|
threaded through the tree, so that every witness has a variable of its own: two witnesses in
|
|
240
|
-
sibling parts never share one.
|
|
241
|
-
|
|
247
|
+
sibling parts never share one. `pos` is the position of `e` in the whole proposition; each
|
|
248
|
+
node and variable carries its own (`id`). Display only; it changes no record that is assessed. -/
|
|
249
|
+
partial def logicJson (vars : Array FVarId) (e : Expr) (pos : SubExpr.Pos) :
|
|
250
|
+
MetaM (Json × Array FVarId) := do
|
|
242
251
|
let op := if e.isAppOfArity ``And 2 then some "and"
|
|
243
252
|
else if e.isAppOfArity ``Or 2 then some "or"
|
|
244
253
|
else if e.isAppOfArity ``Iff 2 then some "iff" else none
|
|
245
254
|
match op with
|
|
246
255
|
| some o =>
|
|
247
|
-
let (a, vars) ← logicJson vars e.appFn!.appArg!
|
|
248
|
-
let (b, vars) ← logicJson vars e.appArg!
|
|
249
|
-
return (Json.mkObj [("op", o), ("
|
|
256
|
+
let (a, vars) ← logicJson vars e.appFn!.appArg! pos.pushAppFn.pushAppArg
|
|
257
|
+
let (b, vars) ← logicJson vars e.appArg! pos.pushAppArg
|
|
258
|
+
return (Json.mkObj [("op", o), ("id", Json.str (toString pos)),
|
|
259
|
+
("args", Json.arr #[a, b])], vars)
|
|
250
260
|
| none =>
|
|
251
261
|
if e.isAppOfArity ``Not 1 then
|
|
252
|
-
let (a, vars) ← logicJson vars e.appArg!
|
|
253
|
-
return (Json.mkObj [("op", "not"), ("
|
|
262
|
+
let (a, vars) ← logicJson vars e.appArg! pos.pushAppArg
|
|
263
|
+
return (Json.mkObj [("op", "not"), ("id", Json.str (toString pos)),
|
|
264
|
+
("args", Json.arr #[a])], vars)
|
|
254
265
|
if let .forallE n t body bi := e then
|
|
255
266
|
if (← isProp t) && !body.hasLooseBVars then
|
|
256
267
|
-- An implication inside a part: its premise is a part of its own, not an assumption
|
|
257
268
|
-- of the whole statement.
|
|
258
|
-
let (a, vars) ← logicJson vars t
|
|
259
|
-
let (b, vars) ← logicJson vars body
|
|
260
|
-
return (Json.mkObj [("op", "implies"), ("
|
|
261
|
-
|
|
269
|
+
let (a, vars) ← logicJson vars t pos.pushBindingDomain
|
|
270
|
+
let (b, vars) ← logicJson vars body pos.pushBindingBody
|
|
271
|
+
return (Json.mkObj [("op", "implies"), ("id", Json.str (toString pos)),
|
|
272
|
+
("args", Json.arr #[a, b])], vars)
|
|
273
|
+
let tj ← ppJson t vars pos.pushBindingDomain
|
|
262
274
|
return ← withLocalDecl n bi t fun x => do
|
|
263
275
|
let idx := vars.size
|
|
264
|
-
let (b, vars') ←
|
|
276
|
+
let (b, vars') ←
|
|
277
|
+
logicJson (vars.push x.fvarId!) (body.instantiate1 x) pos.pushBindingBody
|
|
265
278
|
return (Json.mkObj [("op", "forall"), ("name", n.eraseMacroScopes.toString),
|
|
266
|
-
("var", toJson idx), ("
|
|
279
|
+
("var", toJson idx), ("id", Json.str (toString pos)), ("type", tj),
|
|
280
|
+
("args", Json.arr #[b])], vars')
|
|
267
281
|
match isExistsApp e with
|
|
268
282
|
| some (_, .lam n t body bi) =>
|
|
269
|
-
|
|
283
|
+
-- The witness is bound by the predicate `fun x => …`, the second argument of `Exists`.
|
|
284
|
+
let lam := pos.pushAppArg
|
|
285
|
+
let tj ← ppJson t vars lam.pushBindingDomain
|
|
270
286
|
withLocalDecl n bi t fun x => do
|
|
271
287
|
let idx := vars.size
|
|
272
|
-
let (b, vars') ←
|
|
288
|
+
let (b, vars') ←
|
|
289
|
+
logicJson (vars.push x.fvarId!) (body.instantiate1 x) lam.pushBindingBody
|
|
273
290
|
return (Json.mkObj [("op", "exists"), ("name", n.eraseMacroScopes.toString),
|
|
274
|
-
("var", toJson idx), ("
|
|
275
|
-
|
|
291
|
+
("var", toJson idx), ("id", Json.str (toString lam)), ("type", tj),
|
|
292
|
+
("args", Json.arr #[b])], vars')
|
|
293
|
+
| _ => return (Json.mkObj [("leaf", ← ppJson e vars pos)], vars)
|
|
276
294
|
|
|
277
295
|
/-! ## The inspection representation -/
|
|
278
296
|
|
|
279
297
|
/-- Split a proposition into its quantifier prefix and its conclusion. Universal binders are
|
|
280
298
|
`forall` (data), `hypothesis` (a proposition) or `instance`; existential binders are `exists`.
|
|
281
299
|
Definitions are not unfolded: the prefix is the one written in the specification. -/
|
|
282
|
-
partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[])
|
|
283
|
-
MetaM (Array Json × Json) := do
|
|
300
|
+
partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[])
|
|
301
|
+
(pos : SubExpr.Pos := .root) : MetaM (Array Json × Json) := do
|
|
284
302
|
match e with
|
|
285
303
|
| .forallE n t body bi =>
|
|
286
304
|
let isHyp ← isProp t
|
|
287
305
|
let role :=
|
|
288
306
|
if bi.isInstImplicit then "instance" else if isHyp then "hypothesis" else "forall"
|
|
289
|
-
let tj ← ppJson t vars
|
|
307
|
+
let tj ← ppJson t vars pos.pushBindingDomain
|
|
290
308
|
withLocalDecl n bi t fun x => do
|
|
291
309
|
let hyps := (acc.filter fun j => j.getObjValD "role" == Json.str "hypothesis").size
|
|
292
310
|
let nm := if n.hasMacroScopes || n.isAnonymous then s!"h{hyps + 1}"
|
|
293
311
|
else n.toString
|
|
294
312
|
-- What an instance supplies: a proposition (`[Nonempty E]`) or data (`[Inhabited E]`).
|
|
295
313
|
let supplies := if isHyp then "proposition" else "data"
|
|
296
|
-
let j := Json.mkObj [("role", role), ("name", nm),
|
|
314
|
+
let j := Json.mkObj [("role", role), ("name", nm), ("id", Json.str (toString pos)),
|
|
297
315
|
("type", tj), ("binder", binderStr bi), ("supplies", supplies)]
|
|
298
|
-
telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!)
|
|
316
|
+
telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!) pos.pushBindingBody
|
|
299
317
|
| _ =>
|
|
300
318
|
match isExistsApp e with
|
|
301
319
|
| some (_, .lam n t body bi) =>
|
|
302
|
-
let
|
|
320
|
+
let lam := pos.pushAppArg
|
|
321
|
+
let tj ← ppJson t vars lam.pushBindingDomain
|
|
303
322
|
withLocalDecl n bi t fun x => do
|
|
304
323
|
let j := Json.mkObj [("role", "exists"), ("name", n.eraseMacroScopes.toString),
|
|
305
|
-
("type", tj), ("binder", binderStr bi)]
|
|
306
|
-
telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!)
|
|
324
|
+
("id", Json.str (toString lam)), ("type", tj), ("binder", binderStr bi)]
|
|
325
|
+
telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!) lam.pushBindingBody
|
|
307
326
|
| _ =>
|
|
308
327
|
-- The conclusion, with its logical shape when it has one (`logic`, display only).
|
|
309
|
-
let fields ← ppFields e vars
|
|
310
|
-
let (logic, _) ← logicJson vars e
|
|
328
|
+
let fields ← ppFields e vars pos
|
|
329
|
+
let (logic, _) ← logicJson vars e pos
|
|
311
330
|
let shaped := (logic.getObjVal? "op").toOption.isSome
|
|
312
331
|
return (acc, Json.mkObj (if shaped then fields ++ [("logic", logic)] else fields))
|
|
313
332
|
where
|
|
@@ -110,7 +110,7 @@ def symbol_links(display: dict | None, cid: str, tex: str | None, lean: dict) ->
|
|
|
110
110
|
or not tex or pins.get("source") != sha256_text(tex)
|
|
111
111
|
or shown is None
|
|
112
112
|
or ("target" in pins and pins["target"] != shown)
|
|
113
|
-
or ("term" in target and "target" not in pins))
|
|
113
|
+
or (("term" in target or "at" in target) and "target" not in pins))
|
|
114
114
|
out.append({"symbol": ln.get("symbol") or {}, "lean": target, "by": ln.get("by"),
|
|
115
115
|
"stale": bool(stale)})
|
|
116
116
|
return out
|
|
@@ -82,16 +82,25 @@ class Region:
|
|
|
82
82
|
end_column: int
|
|
83
83
|
kind: str
|
|
84
84
|
text: str
|
|
85
|
+
lines: tuple[str, ...] = ()
|
|
85
86
|
|
|
86
87
|
@property
|
|
87
88
|
def sha256(self) -> str:
|
|
88
89
|
return hashlib.sha256(self.text.encode("utf-8")).hexdigest()
|
|
89
90
|
|
|
91
|
+
@property
|
|
92
|
+
def line_sha256(self) -> list[str]:
|
|
93
|
+
"""One digest per source line the passage spans (the whole line, raw, without its line
|
|
94
|
+
terminator), so that a change can be located, a passage that only moved can be told
|
|
95
|
+
from a changed one, and any checker can verify the pins from the file's lines alone."""
|
|
96
|
+
return [hashlib.sha256(line.encode("utf-8")).hexdigest() for line in self.lines]
|
|
97
|
+
|
|
90
98
|
def record(self) -> dict:
|
|
91
|
-
# The evidence needs bounds and
|
|
99
|
+
# The evidence needs bounds and digests, not an additional public copy of the text.
|
|
92
100
|
return {"file": self.file, "start_line": self.start_line, "end_line": self.end_line,
|
|
93
101
|
"start_column": self.start_column, "end_column": self.end_column,
|
|
94
|
-
"kind": self.kind, "scheme": SCHEME, "sha256": self.sha256
|
|
102
|
+
"kind": self.kind, "scheme": SCHEME, "sha256": self.sha256,
|
|
103
|
+
"line_sha256": self.line_sha256}
|
|
95
104
|
|
|
96
105
|
|
|
97
106
|
def positive(value, name: str) -> int:
|
|
@@ -100,6 +109,10 @@ def positive(value, name: str) -> int:
|
|
|
100
109
|
return value
|
|
101
110
|
|
|
102
111
|
|
|
112
|
+
def _span(lines: list[str], first: int, last: int) -> tuple[str, ...]:
|
|
113
|
+
return tuple(l.rstrip("\r\n") for l in lines[first - 1:last])
|
|
114
|
+
|
|
115
|
+
|
|
103
116
|
def extract(root: Path, claim: dict) -> Region:
|
|
104
117
|
loc = location(claim)
|
|
105
118
|
if loc is None:
|
|
@@ -129,7 +142,8 @@ def extract(root: Path, claim: dict) -> Region:
|
|
|
129
142
|
end = starts[end_line - 1] + end_col - 1
|
|
130
143
|
if start >= end or not text[start:end].strip():
|
|
131
144
|
raise RegionError("source region is empty or reversed")
|
|
132
|
-
return Region(name, line, end_line, start_col, end_col, "span", text[start:end]
|
|
145
|
+
return Region(name, line, end_line, start_col, end_col, "span", text[start:end],
|
|
146
|
+
_span(lines, line, end_line))
|
|
133
147
|
start = starts[line - 1] + len(first) - len(first.lstrip())
|
|
134
148
|
opening = ENV.match(text, start)
|
|
135
149
|
if opening and opening.group(1) == "begin" and opening.group(2).rstrip("*") in DISPLAYS:
|
|
@@ -143,13 +157,14 @@ def extract(root: Path, claim: dict) -> Region:
|
|
|
143
157
|
end_line = text.count("\n", 0, end) + 1
|
|
144
158
|
end_column = end - (text.rfind("\n", 0, end) + 1) + 1
|
|
145
159
|
return Region(name, line, end_line, start - starts[line - 1] + 1,
|
|
146
|
-
end_column, "environment", text[start:end]
|
|
160
|
+
end_column, "environment", text[start:end],
|
|
161
|
+
_span(lines, line, end_line))
|
|
147
162
|
raise RegionError("source environment has no matching end")
|
|
148
163
|
if first.lstrip().startswith(r"\begin"):
|
|
149
164
|
raise RegionError("unsupported or malformed environment; select an explicit source region")
|
|
150
165
|
if not first.strip() or first.lstrip().startswith("%"):
|
|
151
166
|
raise RegionError("source line is blank or a comment; select the actual passage")
|
|
152
|
-
return Region(name, line, line, 1, len(first) + 1, "line", first)
|
|
167
|
+
return Region(name, line, line, 1, len(first) + 1, "line", first, (first,))
|
|
153
168
|
|
|
154
169
|
|
|
155
170
|
def collect(inventory: dict, paper: str, root: Path) -> dict:
|
|
@@ -174,6 +189,30 @@ def matches(claim: dict, tex: dict) -> bool:
|
|
|
174
189
|
and claim["source_sha256"] == rec.get("sha256"))
|
|
175
190
|
|
|
176
191
|
|
|
192
|
+
def same_revision(pin: str, revision: str) -> bool:
|
|
193
|
+
"""Whether an inventory's pin names the snapshot's revision: the same value, or an
|
|
194
|
+
abbreviated commit hash (at least 7 hexadecimal digits) of it."""
|
|
195
|
+
return pin == revision or bool(re.fullmatch(r"[0-9a-f]{7,40}", pin)
|
|
196
|
+
and re.fullmatch(r"[0-9a-f]{40}", revision)
|
|
197
|
+
and revision.startswith(pin))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def changed_line(claim: dict, rec: dict) -> str | None:
|
|
201
|
+
"""Where a passage differs from its pins, from the line digests both sides keep: the first
|
|
202
|
+
changed line, by its place in the passage and in the file, or a change in its length."""
|
|
203
|
+
old, new = claim.get("source_line_sha256"), rec.get("line_sha256")
|
|
204
|
+
if not old or not new:
|
|
205
|
+
return None
|
|
206
|
+
for i, (a, b) in enumerate(zip(old, new)):
|
|
207
|
+
if a != b:
|
|
208
|
+
return (f"line {i + 1} of the passage (line {rec['start_line'] + i} of "
|
|
209
|
+
f"{rec['file']}) changed")
|
|
210
|
+
if len(old) != len(new):
|
|
211
|
+
return (f"the passage has {len(new)} lines, not {len(old)}: lines were "
|
|
212
|
+
+ ("added" if len(new) > len(old) else "removed") + " at its end")
|
|
213
|
+
return None
|
|
214
|
+
|
|
215
|
+
|
|
177
216
|
def migration_plan(inventory: dict, paper: str, root: Path, revision: str) -> tuple[dict, list]:
|
|
178
217
|
"""Rehash only the original frozen snapshot; never edit a review or a paper revision."""
|
|
179
218
|
result = deepcopy(inventory)
|
|
@@ -182,7 +221,7 @@ def migration_plan(inventory: dict, paper: str, root: Path, revision: str) -> tu
|
|
|
182
221
|
if claim["paper"] != paper or location(claim) is None:
|
|
183
222
|
continue
|
|
184
223
|
pin = claim.get("commit") or inventory.get("papers", {}).get(paper, {}).get("commit")
|
|
185
|
-
if not pin or str(pin).removeprefix("arxiv:")
|
|
224
|
+
if not pin or not same_revision(str(pin).removeprefix("arxiv:"), revision):
|
|
186
225
|
raise RegionError(f"{claim['id']}: original paper revision must match {revision}")
|
|
187
226
|
scheme = claim.get("source_hash_scheme")
|
|
188
227
|
if scheme not in (None, SCHEME):
|
|
@@ -192,27 +231,40 @@ def migration_plan(inventory: dict, paper: str, root: Path, revision: str) -> tu
|
|
|
192
231
|
if scheme == SCHEME:
|
|
193
232
|
if expected != region.sha256:
|
|
194
233
|
raise RegionError(f"{claim['id']}: region differs from its frozen hash")
|
|
234
|
+
if claim.get("source_line_sha256") != region.line_sha256:
|
|
235
|
+
# The same passage: add the line digests it was pinned without.
|
|
236
|
+
claim["source_line_sha256"] = region.line_sha256
|
|
237
|
+
changes.append({"claim": claim["id"], "old_sha256": expected,
|
|
238
|
+
"lines_added": True, **region.record()})
|
|
195
239
|
continue
|
|
196
240
|
name, line = location(claim)
|
|
197
241
|
original = source_file(root, name).read_text(encoding="utf-8").split("\n")[line - 1]
|
|
198
242
|
legacy = hashlib.sha256(" ".join(original.split()).encode("utf-8")).hexdigest()
|
|
199
243
|
if not expected or expected != legacy:
|
|
200
244
|
raise RegionError(f"{claim['id']}: legacy hash does not match the original snapshot")
|
|
201
|
-
claim.update(source_sha256=region.sha256, source_hash_scheme=SCHEME
|
|
245
|
+
claim.update(source_sha256=region.sha256, source_hash_scheme=SCHEME,
|
|
246
|
+
source_line_sha256=region.line_sha256)
|
|
202
247
|
changes.append({"claim": claim["id"], "old_sha256": expected, **region.record()})
|
|
203
248
|
if not any(c["paper"] == paper for c in inventory["claims"]):
|
|
204
249
|
raise RegionError(f"no claims for paper {paper}")
|
|
205
250
|
return result, changes
|
|
206
251
|
|
|
207
252
|
|
|
253
|
+
def _indent(raw: bytes) -> int:
|
|
254
|
+
"""The indentation of a JSON file, so that a rewrite changes only the fields it updates."""
|
|
255
|
+
m = re.search(rb"\n( +)\S", raw)
|
|
256
|
+
return len(m.group(1)) if m else 2
|
|
257
|
+
|
|
258
|
+
|
|
208
259
|
def write_plan(path: Path, before: bytes, result: dict) -> None:
|
|
209
|
-
"""Atomically replace the inventory only if it is still the one that was planned
|
|
260
|
+
"""Atomically replace the inventory only if it is still the one that was planned, in its
|
|
261
|
+
own indentation."""
|
|
210
262
|
temporary = None
|
|
211
263
|
try:
|
|
212
264
|
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=path.parent,
|
|
213
265
|
prefix=".source-regions-", delete=False) as handle:
|
|
214
266
|
temporary = Path(handle.name)
|
|
215
|
-
json.dump(result, handle, ensure_ascii=False, indent=
|
|
267
|
+
json.dump(result, handle, ensure_ascii=False, indent=_indent(before))
|
|
216
268
|
handle.write("\n")
|
|
217
269
|
handle.flush()
|
|
218
270
|
os.fsync(handle.fileno())
|
|
@@ -78,6 +78,33 @@ def _term_pp(spec: dict, where: str) -> dict | None:
|
|
|
78
78
|
return None
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
def printed(spec: dict):
|
|
82
|
+
"""Every printed expression of a statement record: the binders' types, the conclusion, the
|
|
83
|
+
parts and quantifiers of its logic, and the exact proposition."""
|
|
84
|
+
for b in spec.get("binders", []):
|
|
85
|
+
yield b.get("type")
|
|
86
|
+
concl = spec.get("conclusion") or {}
|
|
87
|
+
yield concl
|
|
88
|
+
|
|
89
|
+
def walk(n):
|
|
90
|
+
yield n.get("leaf")
|
|
91
|
+
yield n.get("type")
|
|
92
|
+
for a in n.get("args", []):
|
|
93
|
+
yield from walk(a)
|
|
94
|
+
yield from walk(concl.get("logic") or {})
|
|
95
|
+
yield spec.get("exact")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def term_by_id(spec: dict, at: str) -> str | None:
|
|
99
|
+
"""The text of the sub-term whose identity is `at` (its position in the whole proposition,
|
|
100
|
+
as the probe records it), wherever the statement prints it."""
|
|
101
|
+
for pp in printed(spec):
|
|
102
|
+
for t in (pp or {}).get("terms") or [] if isinstance(pp, dict) else []:
|
|
103
|
+
if t.get("id") == at:
|
|
104
|
+
return "".join(x.get("t", "") for x in pp["segments"][t["from"]:t["to"]])
|
|
105
|
+
return None
|
|
106
|
+
|
|
107
|
+
|
|
81
108
|
def _text(pp) -> str:
|
|
82
109
|
if not isinstance(pp, dict):
|
|
83
110
|
return pp or ""
|
|
@@ -89,6 +116,8 @@ def target_text(spec: dict, target: dict) -> str | None:
|
|
|
89
116
|
is printed or split (which renumbers sub-terms and parts while the statement stays the same)
|
|
90
117
|
makes the link stale instead of pointing it at another object."""
|
|
91
118
|
vs = variables(spec)
|
|
119
|
+
if "at" in target:
|
|
120
|
+
return term_by_id(spec, target["at"]) if isinstance(target["at"], str) else None
|
|
92
121
|
if "term" in target:
|
|
93
122
|
pp = _term_pp(spec, target.get("in", ""))
|
|
94
123
|
terms = (pp or {}).get("terms") or []
|
|
@@ -104,15 +133,16 @@ def target_text(spec: dict, target: dict) -> str | None:
|
|
|
104
133
|
|
|
105
134
|
|
|
106
135
|
def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | None = None,
|
|
107
|
-
type_of: str | None = None, term: str | None = None) -> dict:
|
|
136
|
+
type_of: str | None = None, term: str | None = None, at: str | None = None) -> dict:
|
|
108
137
|
"""Record a link from `symbol` in `claim`'s printed statement to the variable `var` (or the
|
|
109
138
|
type of the binder `type_of`) of the Lean statement `decl`, by `by`."""
|
|
110
139
|
from .pipeline import lean_inputs_digest
|
|
111
140
|
from .promote import latest_record
|
|
112
141
|
if not re.fullmatch(r"(human|llm):\S+", by or ""):
|
|
113
142
|
raise SymbolError("name the link's author as human:NAME or llm:MODEL (--as)")
|
|
114
|
-
if sum(x is not None for x in (var, type_of, term)) != 1:
|
|
115
|
-
raise SymbolError("give exactly one of --var NAME, --type-of NAME
|
|
143
|
+
if sum(x is not None for x in (var, type_of, term, at)) != 1:
|
|
144
|
+
raise SymbolError("give exactly one of --var NAME, --type-of NAME, --term WHERE#K and "
|
|
145
|
+
"--at ID")
|
|
116
146
|
record = latest_record(cfg)
|
|
117
147
|
body = record["body"]
|
|
118
148
|
if body["provenance"].get("lean_inputs_sha256") != lean_inputs_digest(cfg):
|
|
@@ -135,7 +165,14 @@ def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | Non
|
|
|
135
165
|
if pp is None or not k.isdigit() or int(k) >= len(pp.get("terms") or []):
|
|
136
166
|
raise SymbolError(f"{decl} has no sub-term {term!r} (WHERE#K: b:<binder>, x:<variable>, "
|
|
137
167
|
"c or l:<part>, then the sub-term's number)")
|
|
138
|
-
|
|
168
|
+
# A sub-term is recorded by its identity in the proposition when the probe gives one,
|
|
169
|
+
# which no change in how the statement is printed or split can move.
|
|
170
|
+
tid = pp["terms"][int(k)].get("id")
|
|
171
|
+
target = {"decl": decl, "at": tid} if tid else {"decl": decl, "term": int(k), "in": where}
|
|
172
|
+
elif at is not None:
|
|
173
|
+
if term_by_id(spec, at) is None:
|
|
174
|
+
raise SymbolError(f"{decl} has no sub-term with the identity {at!r}")
|
|
175
|
+
target = {"decl": decl, "at": at}
|
|
139
176
|
else:
|
|
140
177
|
names = [b.get("name") for b in variables(spec)]
|
|
141
178
|
want = var if var is not None else type_of
|
|
@@ -189,7 +226,7 @@ def from_reader(cfg: Config, req: dict, web_dist=None) -> None:
|
|
|
189
226
|
elif req.get("action") == "add":
|
|
190
227
|
add(cfg, req["claim"], req["tex"], str(req.get("decl") or ""), req.get("by"),
|
|
191
228
|
var=text(req.get("var")), type_of=text(req.get("type_of")),
|
|
192
|
-
term=text(req.get("term")))
|
|
229
|
+
term=text(req.get("term")), at=text(req.get("at")))
|
|
193
230
|
else:
|
|
194
231
|
raise SymbolError(f"unknown action {req.get('action')!r}")
|
|
195
232
|
rebuild_site(cfg, web_dist, None)
|