Re-checking a library¶
Loads are strict: one stored row that the checker refuses refuses the whole
load. After a checker fix or a profile change, re-check a version to find
out whether it still checks. Library.recheck(budget, workers) loads every
partition of a version and checks every row, without writing anything.
The call¶
var lib = Library.open(path)
var report = lib.recheck(budget, workers=4)
print(report) # version, rows, declarations, providers, exports
Library.recheck builds a fresh bank with the logic core and the profile the
version's manifest names, loads every partition in manifest order with every
check of Algorithm L-5, decides
every theory, and checks every row across workers threads. It returns a
LibraryRecheck: the version, the rows the bank verified, the version's
declarations in load order, the statements they provide, and the theorems
it proves. The report is the same at every worker count.
A failure raises the load's error: FORMAT, DIGEST or IO for a version
or partition that is missing or malformed, VERSION for a partition of
another format, LIBRARY for a row the checker refuses or a manifest over
another profile, LIMIT for an exhausted budget. Nothing of the library or
of your session changes either way. A library written before format 2.2 is
refused earlier, by Library.open (VERSION).
When a version fails¶
A version is never changed in place. Take what fails out of the library with a change, published as a new version (changing a library):
change.replace(name, export)gives a theorem a new proof of the same statement;change.withdraw(key)withdraws a theorem or axiom that nothing in the version cites; withdraw its dependents first, in the same change.
Re-check the new version once it is published.
Example¶
This program publishes a library, opens it, rechecks it and reports what it verified, then opens a session over its snapshot.
Mojo
"""Load a published proof-DAG library, recheck it, open a session snapshot, and import theorems."""
from std.tempfile import mkdtemp
from std.testing import assert_equal, assert_true
from judgment_shell import Session
from judgment_store import Library, StoreErrorKind
from termbank import Budget
def publish_example(path: String) raises:
var lib = Library.create(path, "none")
var budget = Budget(10000000)
var s = Session.open(lib.profile_snapshot(budget))
var t_fact = s.prove_step("basics.truth", s.truth(s.base()))
var t_step = s.truth(s.base())
var both_fact = s.prove_step("pairs.both", s.and_intro(t_step, t_step))
var change = lib.change()
change.add(s.export(t_fact, "basics.truth"))
change.add(s.export(both_fact, "pairs.both"))
_ = change.publish()
def main() raises:
var path = String(mkdtemp(), "/lib")
publish_example(path)
# Open the library and independently recheck every stored proof row.
var lib = Library.open(path)
var budget = Budget(10000000)
var check = lib.recheck(budget, workers=1)
assert_equal(len(lib.theorems()), 2)
assert_true(check.rows > 0)
print("Rechecked", len(lib.theorems()), "theorems")
# Look up a theorem by name or by canonical statement identity.
var info = lib.find("pairs.both").value().copy()
assert_true(Bool(lib.find(String("judgment.stmt.", info.sid))))
assert_true(not lib.find("pairs.none"))
print("Found pairs.both:", info.name, "| unknown absent:", not lib.find("pairs.none"))
# Open a session over the full rechecked snapshot and cite the theorem.
var snap = lib.snapshot(budget, workers=1)
var s = Session.open(snap)
var fact = s.import_fact("pairs.both")
print("Cited from snapshot:", fact)
# Opening a non-existent library directory fails with a typed StoreError.
var refused = String("accepted")
try:
_ = Library.open(String(path, "/missing"))
except error:
refused = String(error.kind)
assert_true(refused != "accepted")
print("Missing library refused:", refused)
Run from the repository root pixi run mojo run -I src docs/examples/store/load_library.mojo
Output
Rechecked 2 theorems
Found pairs.both: pairs.both | unknown absent: True
Cited from snapshot: ⊢ True ∧ True
Missing library refused: MISSING_DEPENDENCY
Python
"""Load a published proof-DAG library, recheck it, open a session snapshot, and import theorems.
This example opens the library that `docs/examples/store/load_library.mojo`
publishes in `publish_example`, at the path in `JUDGMENT_EXAMPLE_LIBRARY` (the
documentation gate publishes it there). See `binary_roundtrip.py` to create and
publish a library from Python.
"""
import os
from judgment import Budget, Library, Session, StoreError
def main():
path = os.environ["JUDGMENT_EXAMPLE_LIBRARY"]
# Open the library and independently recheck every stored proof row.
lib = Library.open(path)
budget = Budget(10000000)
check = lib.recheck(budget, workers=1)
assert len(lib.theorems()) == 2
assert check.rows > 0
print("Rechecked", len(lib.theorems()), "theorems")
# Look up a theorem by name or by canonical statement identity.
info = lib.find("pairs.both")
assert lib.find(f"judgment.stmt.{info.sid}") is not None
assert lib.find("pairs.none") is None
print("Found pairs.both:", info.name, "| unknown absent:", lib.find("pairs.none") is None)
# Open a session over the full rechecked snapshot and cite the theorem.
snap = lib.snapshot(budget, workers=1)
s = Session.open(snap)
fact = s.import_fact("pairs.both")
print("Cited from snapshot:", fact)
# Opening a non-existent library directory fails with a typed StoreError.
refused = "accepted"
try:
Library.open(path + "/missing")
except StoreError as error:
refused = str(error.kind)
assert refused != "accepted"
print("Missing library refused:", refused)
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python/store pixi run python docs/examples/python/store/load_library.py
Output
Rechecked 2 theorems
Found pairs.both: pairs.both | unknown absent: True
Cited from snapshot: ⊢ True ∧ True
Missing library refused: MISSING_DEPENDENCY
See also¶
- ST7.5, the re-checking contract;
- Loading a library;
- Changing a library.