machinechecked 0.1.12__tar.gz → 0.1.13__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.12 → machinechecked-0.1.13}/PKG-INFO +1 -1
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/PKG-INFO +1 -1
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/SOURCES.txt +2 -2
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/cache.py +72 -16
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/ProofLensProbe.lean +55 -19
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/manifest.py +8 -1
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/symbols.py +54 -10
- machinechecked-0.1.13/engine/python/prooflens/web/assets/index-DevCW_Pm.js +278 -0
- machinechecked-0.1.12/engine/python/prooflens/web/assets/index-C8DRs1uO.css → machinechecked-0.1.13/engine/python/prooflens/web/assets/index-GfZV3aEH.css +1 -1
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/index.html +2 -2
- {machinechecked-0.1.12 → machinechecked-0.1.13}/pyproject.toml +1 -1
- machinechecked-0.1.12/engine/python/prooflens/web/assets/index-DXica3gb.js +0 -278
- {machinechecked-0.1.12 → machinechecked-0.1.13}/LICENSE +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/README.md +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/dependency_links.txt +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/entry_points.txt +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/requires.txt +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/machinechecked.egg-info/top_level.txt +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/__init__.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/__main__.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/assess.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/audit.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/bundle.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/cli.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/config.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/prooflens.sty +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/schema/evidence.schema.json +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/schema/inventory.schema.json +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/schema/manifest-claim.schema.json +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/schema/manifest-index.schema.json +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/statuses.json +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/deps.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/evidence.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/export.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/formalization.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/paper.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/pdfclaims.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/pipeline.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/probe.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/promote.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/published.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/replay.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/review_cli.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/review_queue.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/reviews.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/schemas.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/server.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/simple.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/source_regions.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/sources.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/status.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/tex.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/util.py +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/cursor-editorTextHighlight-kG3uUOwL.svg +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/web/theme.css +0 -0
- {machinechecked-0.1.12 → machinechecked-0.1.13}/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.13
|
|
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.12 → machinechecked-0.1.13}/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.13
|
|
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.12 → machinechecked-0.1.13}/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-
|
|
72
|
-
engine/python/prooflens/web/assets/index-
|
|
71
|
+
engine/python/prooflens/web/assets/index-DevCW_Pm.js
|
|
72
|
+
engine/python/prooflens/web/assets/index-GfZV3aEH.css
|
|
73
73
|
engine/python/prooflens/web/assets/pdf.worker.min-yatZIOMy.mjs
|
|
@@ -184,25 +184,79 @@ def _pack(arc: Path, members: list[tuple[Path, str]]) -> None:
|
|
|
184
184
|
raise CacheError("zstd failed while writing the archive")
|
|
185
185
|
|
|
186
186
|
|
|
187
|
+
def _unpacked_size(members: list[tuple[Path, str]]) -> int:
|
|
188
|
+
"""The bytes of the files the archive holds, unpacked."""
|
|
189
|
+
total = 0
|
|
190
|
+
for src, _ in members:
|
|
191
|
+
for f in src.rglob("*"):
|
|
192
|
+
if f.is_file() and not f.is_symlink():
|
|
193
|
+
total += f.stat().st_size
|
|
194
|
+
return total
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _gb(n: float) -> str:
|
|
198
|
+
return f"{n / 1e9:.1f} GB"
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def check_space(project: Path, tmp: Path, man: dict) -> None:
|
|
202
|
+
"""Refuse a restore that cannot fit, before anything is downloaded: the archive needs its
|
|
203
|
+
size in `tmp`, and its unpacked build (recorded by `save`; four times the archive for an
|
|
204
|
+
older manifest) next to the project."""
|
|
205
|
+
size = int(man.get("size") or 0)
|
|
206
|
+
unpacked = int(man.get("unpacked_size") or 4 * size)
|
|
207
|
+
lake = project / ".lake"
|
|
208
|
+
where = lake if lake.exists() else project
|
|
209
|
+
need = {where: unpacked}
|
|
210
|
+
if os.stat(tmp).st_dev == os.stat(where).st_dev:
|
|
211
|
+
need[where] += size
|
|
212
|
+
else:
|
|
213
|
+
need[tmp] = size
|
|
214
|
+
for path, n in need.items():
|
|
215
|
+
free = shutil.disk_usage(path).free
|
|
216
|
+
if free < n:
|
|
217
|
+
raise CacheError(
|
|
218
|
+
f"not enough disk space to restore: {_gb(n)} needed under {path}, {_gb(free)} "
|
|
219
|
+
"free. Free some space (for example a second copy of a dependency at the same "
|
|
220
|
+
"revision, or old build output) and restore again; nothing was changed")
|
|
221
|
+
|
|
222
|
+
|
|
187
223
|
def _unpack(arc: Path, project: Path) -> None:
|
|
188
224
|
"""Unpack an archive written by `_pack` into the project and its path dependencies, with the
|
|
189
|
-
tar `data` filter (no absolute paths, no `..`, no links out of the destination).
|
|
225
|
+
tar `data` filter (no absolute paths, no `..`, no links out of the destination). Everything
|
|
226
|
+
is unpacked into a staging folder first and moved into place only once the whole archive
|
|
227
|
+
has been read, so a failure (a full disk, a corrupt archive) leaves the build as it was."""
|
|
190
228
|
import tarfile
|
|
191
229
|
deps = {d.name: d for d in path_deps(project)}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
230
|
+
stage = Path(tempfile.mkdtemp(prefix=".lean-cache-restore-", dir=project))
|
|
231
|
+
try:
|
|
232
|
+
bases: dict[str, Path] = {}
|
|
233
|
+
z = subprocess.Popen(["zstd", "-d", "-q", "-c", str(arc)], stdout=subprocess.PIPE)
|
|
234
|
+
with tarfile.open(fileobj=z.stdout, mode="r|") as tf:
|
|
235
|
+
for m in tf:
|
|
236
|
+
head, _, rest = m.name.partition("/")
|
|
237
|
+
if head == "project" and rest:
|
|
238
|
+
key, base, m.name = "project", project, rest
|
|
239
|
+
elif head == "path" and rest.partition("/")[0] in deps:
|
|
240
|
+
name, _, m.name = rest.partition("/")
|
|
241
|
+
key, base = f"path-{name}", deps[name]
|
|
242
|
+
else:
|
|
243
|
+
raise CacheError(f"unexpected path in the archive: {m.name}")
|
|
244
|
+
bases[key] = base
|
|
245
|
+
tf.extract(m, stage / key, filter="data")
|
|
246
|
+
if z.wait() != 0:
|
|
247
|
+
raise CacheError("zstd failed while reading the archive")
|
|
248
|
+
for key, base in bases.items():
|
|
249
|
+
root = stage / key
|
|
250
|
+
for f in sorted(root.rglob("*")):
|
|
251
|
+
if f.is_dir() and not f.is_symlink():
|
|
252
|
+
continue
|
|
253
|
+
dest = base / f.relative_to(root)
|
|
254
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
255
|
+
shutil.move(str(f), str(dest))
|
|
256
|
+
except OSError as e:
|
|
257
|
+
raise CacheError(f"the restore failed ({e}); the build was left as it was") from e
|
|
258
|
+
finally:
|
|
259
|
+
shutil.rmtree(stage, ignore_errors=True)
|
|
206
260
|
|
|
207
261
|
|
|
208
262
|
def repository(project: Path) -> str | None:
|
|
@@ -263,7 +317,8 @@ def save(project: Path, out: Path, targets: list[str], pin_file: str | None = No
|
|
|
263
317
|
manifest = {"commit": commit, "project": package_name(project), "layout": 2,
|
|
264
318
|
"inputs_digest": inputs_digest(project), "repository": repository(project),
|
|
265
319
|
"targets": targets or ["(default)"], "dirs": dirs, "sha256": digest,
|
|
266
|
-
"size": size, "
|
|
320
|
+
"size": size, "unpacked_size": _unpacked_size(_members(project)),
|
|
321
|
+
"parts": parts, "licence_files": licences,
|
|
267
322
|
"created": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
268
323
|
**fingerprint(project)}
|
|
269
324
|
(out / f"{name}.json").write_text(json.dumps(manifest, indent=1) + "\n")
|
|
@@ -403,6 +458,7 @@ def restore(project: Path, repo: str | None = None, local: Path | None = None,
|
|
|
403
458
|
if no_history else ""))
|
|
404
459
|
key, stem, man = best
|
|
405
460
|
dist = key[1]
|
|
461
|
+
check_space(project, tmp, man)
|
|
406
462
|
t0 = time.time()
|
|
407
463
|
arc = tmp / f"{stem}.tar.zst"
|
|
408
464
|
pieces = man["parts"] if man.get("parts") else [{"name": arc.name, "sha256": man["sha256"]}]
|
{machinechecked-0.1.12 → machinechecked-0.1.13}/engine/python/prooflens/data/ProofLensProbe.lean
RENAMED
|
@@ -206,10 +206,13 @@ def termsJson (terms : Array (Nat × Nat)) : Json := Id.run do
|
|
|
206
206
|
if tagging fails, and a marker if printing fails, so that one large term cannot stop the probe. -/
|
|
207
207
|
def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Json)) := do
|
|
208
208
|
try
|
|
209
|
-
-- The
|
|
210
|
-
--
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
-- The type of a bound variable is printed (`pp.funBinderTypes`): `∃ Φ : T, …` says what Φ
|
|
210
|
+
-- is. The head of every application is tagged too (`pp.tagAppFns`), so that the function a
|
|
211
|
+
-- term applies is a constant the reader can name. The text and the tagged code are printed
|
|
212
|
+
-- with the same options.
|
|
213
|
+
let typed := fun (o : Options) => o.setBool `pp.funBinderTypes true
|
|
214
|
+
let code ← withOptions (fun o => (typed o).setBool `pp.tagAppFns true) (Widget.ppExprTagged e)
|
|
215
|
+
let text := toString (← withOptions typed (ppExpr e))
|
|
213
216
|
let (segs, terms) := segments vars code none #[] #[]
|
|
214
217
|
return [("text", Json.str text), ("segments", Json.arr segs), ("terms", termsJson terms)]
|
|
215
218
|
catch _ =>
|
|
@@ -222,19 +225,6 @@ def ppFields (e : Expr) (vars : Array FVarId := #[]) : MetaM (List (String × Js
|
|
|
222
225
|
def ppJson (e : Expr) (vars : Array FVarId := #[]) : MetaM Json :=
|
|
223
226
|
return Json.mkObj (← ppFields e vars)
|
|
224
227
|
|
|
225
|
-
/-- The logical shape of a conclusion: a conjunction, disjunction or equivalence as a tree whose
|
|
226
|
-
leaves are pretty-printed propositions. Display only; it changes no record that is assessed. -/
|
|
227
|
-
partial def logicJson (vars : Array FVarId) (e : Expr) : MetaM Json := do
|
|
228
|
-
let op := if e.isAppOfArity ``And 2 then some "and"
|
|
229
|
-
else if e.isAppOfArity ``Or 2 then some "or"
|
|
230
|
-
else if e.isAppOfArity ``Iff 2 then some "iff" else none
|
|
231
|
-
match op with
|
|
232
|
-
| some o => return Json.mkObj [("op", o),
|
|
233
|
-
("args", Json.arr #[← logicJson vars e.appFn!.appArg!, ← logicJson vars e.appArg!])]
|
|
234
|
-
| none => return Json.mkObj [("leaf", ← ppJson e vars)]
|
|
235
|
-
|
|
236
|
-
/-! ## The inspection representation -/
|
|
237
|
-
|
|
238
228
|
def isExistsApp (e : Expr) : Option (Name × Expr) :=
|
|
239
229
|
if e.isAppOfArity ``Exists 2 then
|
|
240
230
|
match e.appArg! with
|
|
@@ -242,6 +232,50 @@ def isExistsApp (e : Expr) : Option (Name × Expr) :=
|
|
|
242
232
|
| _ => none
|
|
243
233
|
else none
|
|
244
234
|
|
|
235
|
+
/-- The logical shape of a conclusion: a conjunction, disjunction, equivalence, negation,
|
|
236
|
+
implication, "for every" or "there is" as a tree whose leaves are pretty-printed propositions. A
|
|
237
|
+
quantifier inside the conclusion is a node (`forall`, `exists`) with its variable's name, type and
|
|
238
|
+
number, and its body as its one part. `vars` is
|
|
239
|
+
threaded through the tree, so that every witness has a variable of its own: two witnesses in
|
|
240
|
+
sibling parts never share one. Display only; it changes no record that is assessed. -/
|
|
241
|
+
partial def logicJson (vars : Array FVarId) (e : Expr) : MetaM (Json × Array FVarId) := do
|
|
242
|
+
let op := if e.isAppOfArity ``And 2 then some "and"
|
|
243
|
+
else if e.isAppOfArity ``Or 2 then some "or"
|
|
244
|
+
else if e.isAppOfArity ``Iff 2 then some "iff" else none
|
|
245
|
+
match op with
|
|
246
|
+
| 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), ("args", Json.arr #[a, b])], vars)
|
|
250
|
+
| none =>
|
|
251
|
+
if e.isAppOfArity ``Not 1 then
|
|
252
|
+
let (a, vars) ← logicJson vars e.appArg!
|
|
253
|
+
return (Json.mkObj [("op", "not"), ("args", Json.arr #[a])], vars)
|
|
254
|
+
if let .forallE n t body bi := e then
|
|
255
|
+
if (← isProp t) && !body.hasLooseBVars then
|
|
256
|
+
-- An implication inside a part: its premise is a part of its own, not an assumption
|
|
257
|
+
-- of the whole statement.
|
|
258
|
+
let (a, vars) ← logicJson vars t
|
|
259
|
+
let (b, vars) ← logicJson vars body
|
|
260
|
+
return (Json.mkObj [("op", "implies"), ("args", Json.arr #[a, b])], vars)
|
|
261
|
+
let tj ← ppJson t vars
|
|
262
|
+
return ← withLocalDecl n bi t fun x => do
|
|
263
|
+
let idx := vars.size
|
|
264
|
+
let (b, vars') ← logicJson (vars.push x.fvarId!) (body.instantiate1 x)
|
|
265
|
+
return (Json.mkObj [("op", "forall"), ("name", n.eraseMacroScopes.toString),
|
|
266
|
+
("var", toJson idx), ("type", tj), ("args", Json.arr #[b])], vars')
|
|
267
|
+
match isExistsApp e with
|
|
268
|
+
| some (_, .lam n t body bi) =>
|
|
269
|
+
let tj ← ppJson t vars
|
|
270
|
+
withLocalDecl n bi t fun x => do
|
|
271
|
+
let idx := vars.size
|
|
272
|
+
let (b, vars') ← logicJson (vars.push x.fvarId!) (body.instantiate1 x)
|
|
273
|
+
return (Json.mkObj [("op", "exists"), ("name", n.eraseMacroScopes.toString),
|
|
274
|
+
("var", toJson idx), ("type", tj), ("args", Json.arr #[b])], vars')
|
|
275
|
+
| _ => return (Json.mkObj [("leaf", ← ppJson e vars)], vars)
|
|
276
|
+
|
|
277
|
+
/-! ## The inspection representation -/
|
|
278
|
+
|
|
245
279
|
/-- Split a proposition into its quantifier prefix and its conclusion. Universal binders are
|
|
246
280
|
`forall` (data), `hypothesis` (a proposition) or `instance`; existential binders are `exists`.
|
|
247
281
|
Definitions are not unfolded: the prefix is the one written in the specification. -/
|
|
@@ -257,8 +291,10 @@ partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[])
|
|
|
257
291
|
let hyps := (acc.filter fun j => j.getObjValD "role" == Json.str "hypothesis").size
|
|
258
292
|
let nm := if n.hasMacroScopes || n.isAnonymous then s!"h{hyps + 1}"
|
|
259
293
|
else n.toString
|
|
294
|
+
-- What an instance supplies: a proposition (`[Nonempty E]`) or data (`[Inhabited E]`).
|
|
295
|
+
let supplies := if isHyp then "proposition" else "data"
|
|
260
296
|
let j := Json.mkObj [("role", role), ("name", nm),
|
|
261
|
-
("type", tj), ("binder", binderStr bi)]
|
|
297
|
+
("type", tj), ("binder", binderStr bi), ("supplies", supplies)]
|
|
262
298
|
telescope (body.instantiate1 x) (acc.push j) (vars.push x.fvarId!)
|
|
263
299
|
| _ =>
|
|
264
300
|
match isExistsApp e with
|
|
@@ -271,7 +307,7 @@ partial def telescope (e : Expr) (acc : Array Json) (vars : Array FVarId := #[])
|
|
|
271
307
|
| _ =>
|
|
272
308
|
-- The conclusion, with its logical shape when it has one (`logic`, display only).
|
|
273
309
|
let fields ← ppFields e vars
|
|
274
|
-
let logic ← logicJson vars e
|
|
310
|
+
let (logic, _) ← logicJson vars e
|
|
275
311
|
let shaped := (logic.getObjVal? "op").toOption.isSome
|
|
276
312
|
return (acc, Json.mkObj (if shaped then fields ++ [("logic", logic)] else fields))
|
|
277
313
|
where
|
|
@@ -102,8 +102,15 @@ def symbol_links(display: dict | None, cid: str, tex: str | None, lean: dict) ->
|
|
|
102
102
|
target = ln.get("lean") or {}
|
|
103
103
|
spec = (lean.get("specs") or {}).get(target.get("decl")) or {}
|
|
104
104
|
pins = ln.get("pins") or {}
|
|
105
|
+
# A link to a sub-term is located by numbers that depend on how the statement is
|
|
106
|
+
# printed, so it also needs the text it was made on (older links have none).
|
|
107
|
+
from .symbols import target_text
|
|
108
|
+
shown = target_text(spec, target)
|
|
105
109
|
stale = (pins.get("statement") != spec.get("fingerprint")
|
|
106
|
-
or not tex or pins.get("source") != sha256_text(tex)
|
|
110
|
+
or not tex or pins.get("source") != sha256_text(tex)
|
|
111
|
+
or shown is None
|
|
112
|
+
or ("target" in pins and pins["target"] != shown)
|
|
113
|
+
or ("term" in target and "target" not in pins))
|
|
107
114
|
out.append({"symbol": ln.get("symbol") or {}, "lean": target, "by": ln.get("by"),
|
|
108
115
|
"stale": bool(stale)})
|
|
109
116
|
return out
|
|
@@ -36,16 +36,33 @@ def _in_math(tex: str, symbol: str) -> bool:
|
|
|
36
36
|
return any(re.search(pat, s) for s in spans)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
def variables(spec: dict) -> list[dict]:
|
|
40
|
+
"""The statement's variables by number: the prefix's binders, then each "there is" inside
|
|
41
|
+
the conclusion at the number the probe gave it."""
|
|
42
|
+
out: list[dict] = list(spec.get("binders", []))
|
|
43
|
+
|
|
44
|
+
def walk(n):
|
|
45
|
+
if n.get("op") == "exists" and isinstance(n.get("var"), int):
|
|
46
|
+
out.extend({} for _ in range(n["var"] + 1 - len(out)))
|
|
47
|
+
out[n["var"]] = {"role": "exists", "name": n.get("name"), "type": n.get("type")}
|
|
48
|
+
for a in n.get("args", []):
|
|
49
|
+
walk(a)
|
|
50
|
+
walk((spec.get("conclusion") or {}).get("logic") or {})
|
|
51
|
+
return out
|
|
52
|
+
|
|
53
|
+
|
|
39
54
|
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, `
|
|
55
|
+
"""The pretty-printed term a sub-term's place names: `b:<i>` a binder's type, `x:<i>` the
|
|
56
|
+
type of the i-th variable (a "there is" inside the conclusion included), `c` the
|
|
41
57
|
conclusion, `l:<n>` the n-th part of a conclusion split by its logic."""
|
|
42
58
|
concl = spec.get("conclusion") or {}
|
|
43
59
|
if where == "c":
|
|
44
60
|
return concl
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
for tag, items in (("b:", spec.get("binders", [])), ("x:", None)):
|
|
62
|
+
if where.startswith(tag) and where[2:].isdigit():
|
|
63
|
+
items = items if items is not None else variables(spec)
|
|
64
|
+
i = int(where[2:])
|
|
65
|
+
return (items[i] or {}).get("type") if i < len(items) else None
|
|
49
66
|
if where.startswith("l:") and where[2:].isdigit():
|
|
50
67
|
leaves = []
|
|
51
68
|
|
|
@@ -61,6 +78,31 @@ def _term_pp(spec: dict, where: str) -> dict | None:
|
|
|
61
78
|
return None
|
|
62
79
|
|
|
63
80
|
|
|
81
|
+
def _text(pp) -> str:
|
|
82
|
+
if not isinstance(pp, dict):
|
|
83
|
+
return pp or ""
|
|
84
|
+
return pp.get("text") or "".join(x.get("t", "") for x in pp.get("segments", []))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def target_text(spec: dict, target: dict) -> str | None:
|
|
88
|
+
"""What a link's Lean side shows, pinned with the link so that a change in how the statement
|
|
89
|
+
is printed or split (which renumbers sub-terms and parts while the statement stays the same)
|
|
90
|
+
makes the link stale instead of pointing it at another object."""
|
|
91
|
+
vs = variables(spec)
|
|
92
|
+
if "term" in target:
|
|
93
|
+
pp = _term_pp(spec, target.get("in", ""))
|
|
94
|
+
terms = (pp or {}).get("terms") or []
|
|
95
|
+
k = target["term"]
|
|
96
|
+
if not isinstance(k, int) or k >= len(terms):
|
|
97
|
+
return None
|
|
98
|
+
return "".join(x.get("t", "") for x in pp["segments"][terms[k]["from"]:terms[k]["to"]])
|
|
99
|
+
i = target.get("var", target.get("binder"))
|
|
100
|
+
if not isinstance(i, int) or i >= len(vs) or not vs[i]:
|
|
101
|
+
return None
|
|
102
|
+
return f"{vs[i].get('name')} : {_text(vs[i].get('type'))}" if "binder" in target \
|
|
103
|
+
else str(vs[i].get("name"))
|
|
104
|
+
|
|
105
|
+
|
|
64
106
|
def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | None = None,
|
|
65
107
|
type_of: str | None = None, term: str | None = None) -> dict:
|
|
66
108
|
"""Record a link from `symbol` in `claim`'s printed statement to the variable `var` (or the
|
|
@@ -91,19 +133,21 @@ def add(cfg: Config, claim: str, symbol: str, decl: str, by: str, var: str | Non
|
|
|
91
133
|
where, _, k = term.partition("#")
|
|
92
134
|
pp = _term_pp(spec, where)
|
|
93
135
|
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>,
|
|
95
|
-
"l:<part>, then the sub-term's number)")
|
|
136
|
+
raise SymbolError(f"{decl} has no sub-term {term!r} (WHERE#K: b:<binder>, x:<variable>, "
|
|
137
|
+
"c or l:<part>, then the sub-term's number)")
|
|
96
138
|
target = {"decl": decl, "term": int(k), "in": where}
|
|
97
139
|
else:
|
|
98
|
-
names = [b.get("name") for b in spec
|
|
140
|
+
names = [b.get("name") for b in variables(spec)]
|
|
99
141
|
want = var if var is not None else type_of
|
|
100
142
|
idx = int(want) if want.isdigit() else (names.index(want) if want in names else None)
|
|
101
143
|
if idx is None or not 0 <= idx < len(names):
|
|
102
|
-
raise SymbolError(f"{decl} has no binder {want!r} (it has
|
|
144
|
+
raise SymbolError(f"{decl} has no binder {want!r} (it has "
|
|
145
|
+
f"{', '.join(str(n) for n in names if n)})")
|
|
103
146
|
target = {"decl": decl, "var": idx} if var is not None else \
|
|
104
147
|
{"decl": decl, "binder": idx, "path": "type"}
|
|
105
148
|
link = {"claim": claim, "symbol": {"tex": symbol, "occurrence": "all"}, "lean": target,
|
|
106
|
-
"by": by, "pins": {"statement": spec.get("fingerprint"), "source": sha256_text(tex)
|
|
149
|
+
"by": by, "pins": {"statement": spec.get("fingerprint"), "source": sha256_text(tex),
|
|
150
|
+
"target": target_text(spec, target)}}
|
|
107
151
|
data = read_json(cfg.symbols) if cfg.symbols.exists() else {"schema": SCHEMA, "links": []}
|
|
108
152
|
data["links"] = [ln for ln in data.get("links", [])
|
|
109
153
|
if not (ln.get("claim") == claim and (ln.get("symbol") or {}).get("tex") == symbol)]
|