Importing articles¶
OpenTheory articles are text files of
primitive proof commands exported by HOL-family provers. Article.open
opens an article directly as a TheoremSource, and
LibraryChange.add_article converts and checks an article into a library's
next version.
Reading and adding an article¶
var art = Article.open(path, profile="none")
var change = lib.change()
change.add_article(path, "HOL Light|refl-1|example|refl")
var version = change.publish()
Article.open(path, profile="none", source="", scratch="")checks the article through the proof-DAG converter and exposes its exported theorems throughart.theorems()andSession.import_theorem[Article](art, name).LibraryChange.add_article(path, source="")records the article in a pending change;publishconverts it over the library's profile and existing statements, checks every row, and writes it as new partitions of the next version.sourceis the provenance of the article's axioms,PROVER|RELEASE|SESSION|THEORY; an axiom without one is refused at publication.Article.write(path, exports, budget)writes session theorems as an OpenTheory article (changing a library).
Statements and variables¶
A library provides each statement once (Rule L1), so what an article
restates is not stored again. An axiom whose sequent the profile, the
base version or an earlier command already provides declares nothing: the
converter proves it from that provider. A thm of such a sequent declares
and exports nothing, though a version-6 source naming it still names the
provided statement. Statements are matched by the canonical closure of the
sequent (ST6.2), so the
order in which the article binds its free variables and lists its
hypotheses, and the names of its variables and type variables, do not
matter. Otherwise an axiom declares an axiom and a thm a theorem, each
stating that canonical closure. Looking a statement up writes nothing, so
the library's bytes do not depend on which statements were looked up.
An article variable is its name and its type: x : bool and
x : bool → bool are two variables. Names that begin with · are reserved
for internal variables; an article's own variable with such a name is
stored with one more · in front, and written back under its own name.
Limits and budgets¶
All decoding, conversion, and verification work is explicitly bounded by the
caller's Budget and ArticleLimits (G3). Refusals and budget exhaustion
leave the library directory and any open session unchanged (G9).
IO and temporary-file ownership¶
Article.open_io(path, ...) defers file reading, checking, and temporary
library creation until the action runs. The returned Article owns the
temporary directory. For cleanup tied to an IO scope, prefer
Article.resource(path, ...).use(body): fp_mojo acquires the article, runs
the body's IO, then removes the temporary library after success, failure,
or cancellation. Cleanup waits for blocking workers to finish. Failed
acquisition removes its partial temporary library too.
write_article_io(path, exports^, ...) takes ownership of the exported
proof data and defers encoding, optional read-back verification, and atomic
file publication. It does not copy the proof rows. The synchronous
Article.write and write_article adapters preserve their borrowed-input
API by copying the export data into the owned action; use the consuming IO
API when that copy would be expensive. Session.export prepares the proof
value for these writers; it does not publish files.
These import/export entry points run file effects through fp_mojo IO. The converter's input preparation and final publication belong to its IO operation as well as its decoding and checking workers. Existing worker pools remain separate and joined; blocking leaves never submit recursively into the pool that is waiting for them. Public file actions are blocking operations: cancellation waits for a running operation, and does not promise to roll back a completed publication.
Example¶
"""Import OpenTheory articles into a proof-DAG library and read their checked theorems."""
from std.tempfile import mkdtemp
from std.testing import assert_equal, assert_true
from judgment_shell import Session
from judgment_store import Article, Library
from termbank import Budget
comptime REFL_ART = String(
"6\nversion\n",
"\"bool\"\ntypeOp\nnil\nopType\n0\ndef\npop\n",
"\"->\"\ntypeOp\n0\nref\n0\nref\nnil\ncons\ncons\nopType\n1\ndef\npop\n",
"\"->\"\ntypeOp\n0\nref\n1\nref\nnil\ncons\ncons\nopType\n2\ndef\npop\n",
"\"p\"\n0\nref\nvar\n3\ndef\npop\n3\nref\nvarTerm\n4\ndef\npop\n",
"\"=\"\nconst\n2\nref\nconstTerm\n4\nref\nappTerm\n4\nref\nappTerm\n5\ndef\npop\n",
"4\nref\nrefl\nnil\n5\nref\nthm\n",
)
def main() raises:
var dir = mkdtemp()
var art_path = String(dir, "/refl.art")
with open(art_path, "w") as f:
f.write(REFL_ART)
# Open the article directly as a TheoremSource to inspect its theorems.
var art = Article.open(art_path)
assert_equal(len(art.theorems()), 1)
print("Article theorems:", len(art.theorems()))
# Publish the article into a library and recheck it.
var lib_path = String(dir, "/lib")
var lib = Library.create(lib_path, "none")
var change = lib.change()
change.add_article(art_path, "example.refl")
_ = change.publish()
var reopened = Library.open(lib_path)
var budget = Budget(10000000)
var check = reopened.recheck(budget, workers=1)
assert_true(check.rows > 0)
var snap = reopened.profile_snapshot(budget)
var s = Session.open(snap)
var imported = s.import_theorem[Library](reopened, reopened.theorems()[0].name)
assert_true(Bool(imported.imported()))
print("Imported from library:", reopened.theorems()[0].kind)
Run from the repository root pixi run mojo run -I src docs/examples/store/import_articles.mojo
Output
Article theorems: 1
Imported from library: theorem