Proof libraries & OpenTheory

What a proof library is

This page explains the model behind proof libraries in plain terms. The other guides show the API; the theory page states the same rules precisely and proves what a load establishes.

The words

A few kernel terms come first. The judgment_core checker is the only code that establishes checked results. A theory is a set of declarations: types, constants, definitions, axioms (statements assumed without proof) and theorems (Proven declarations, statements with a checked proof). A judgment Γ ⊢ φ is a checked result: the proposition φ holds under the context Γ of local variables and hypotheses. A judgment with an empty context is closed. Results live as rows of a termbank.dag bank: term nodes, proof nodes, and the sets, contexts and theories they name.

On top of these, a library uses:

Term Meaning
profile the theory every library extends: none, classical or isabelle; the loading bank builds it as the writer did
statement the proposition of a closed theorem or axiom, up to renaming its type variables
statement identity a SHA-256 digest of a statement's canonical form (Definition I-6); two statements that differ only in type-variable names share it
provider the one declaration that states a statement in the library: a theorem, an axiom, a definition's defining equation (c = t for a definition c := t), or a declaration of the profile; only theorem and axiom providers are named canonically, the others keep their own names
canonical name judgment.stmt. and the 64 hex digits of the statement identity: the name every theorem and axiom provider has
alias a theorem name for a statement, such as the name a source prover or a session gave it
partition one file holding a consecutive part of the library's theory: its declarations and the proof rows of its theorems
manifest the file that lists a version's partitions, providers, aliases, declarations, and what its changes withdrew or superseded
version one manifest; CURRENT names the current one
proof a theorem's proof rows: the PROOF row that concludes it, with every row it reaches

One proof per statement

A library holds each statement once. Rule L1 says that distinct providers have distinct statement identities. Publishing a second proof of a statement the library already provides adds nothing: the writer leaves the second theorem out and keeps only its name, as an alias of the existing statement. A load refuses a library with two providers of one statement.

That is why theorems carry canonical names. A theorem named judgment.stmt.3f9a… can be found from its statement alone, in any program, without knowing what any source called it. Source names survive as aliases: an alias maps a theorem name to a statement identity and lists the statement's type-variable names. A library gives each name at most one alias.

A version may change a statement's provider in two ways only, which its manifest records: it may replace a theorem's proof by a new proof of the same statement, and it may supersede an axiom by a theorem that proves it. Either way the statement keeps one provider.

References, not copies

A proof cites the theorems it uses by reference: a declaration's identity, which is a digest of its content. A library never copies a theorem into a proof that uses it, and a partition stores each row once, so a large library stays as large as its distinct rows.

                 manifest (one version)
   ┌───────────────────────────────────────────────┐
   │ profile identities                            │
   │ partitions, in load order:                    │
   │   library #0  file 5e1c…  depends on —        │
   │   library #1  file a07b…  depends on #0       │
   │ statements: identity → provider, reuse count  │
   │ aliases:    name → statement                  │
   │ declarations: identity → partition, citations │
   │ withdrawn and superseded entries              │
   │ parent:     the previous manifest, if any     │
   └───────────────────────────────────────────────┘
          │                         │
          ▼                         ▼
   parts/5e1c….jlp           parts/a07b….jlp
   ⊢ T                       ⊢ T ∧ T  (cites ⊢ T by reference)

A library's theory is written as numbered sub-partitions of one name. You do not choose them: publication cuts the declarations, in the order they were committed, into runs whose rows stay well within the 64 MiB file limit, and loading joins them. They form a chain: each sub-partition depends on the one before it, numbers its rows after the rows the earlier ones stored, and refers to those rows by number instead of storing them again. Rows are stored in compressed blocks and a partition's metadata sections are DEFLATE-compressed (ST9). A partition's bytes do not record its place in the chain, so two sub-partitions whose rows encode alike are one file: the manifest names it at both positions, and parts/ holds it once.

Versions

Every file in a library is named by the SHA-256 of its bytes and never changes after it is written. A publication adds new files and a new manifest, then replaces the one-line file CURRENT to name that manifest. Each manifest names its parent, the version it was built on, so the versions form a chain. A new version keeps its parent's partitions and appends its own.

CURRENT ──► manifest v3 ──parent──► manifest v2 ──parent──► manifest v1
               │                       │                       │
               └── parts it names ─────┴── shared ─────────────┘

A reader reads CURRENT once and then opens only immutable files, so it sees one complete version even while a writer publishes the next one. The library format gives the files byte by byte. A writer states the version it builds on (its base); if CURRENT has moved, the publication is refused with CONFLICT. See operations for the directory and its maintenance.

Libraries are written in library format 2.2: manifest header 4, over termbank format 2. A reader opens that format only; unsupported versions are refused (versions and compatibility).

Proofs and closed forms

Every theorem in a library carries its proof as rows of its partition: each proof row stores its conclusion, so the checker checks every row on its own, in parallel. A load commits the rows into a fresh bank and the checker checks every one of them; a theorem is declared only with a proof row the checker verified, whose closed form is the theorem's statement.

A library holds closed statements, but a proof can conclude an open sequent: x : α, h : x = x ⊢ x = x. Such a theorem states its closed form, ⊢ ∀x. x = x → x = x: its locals become leading universal quantifiers and its hypotheses become antecedents. The order of those quantifiers and antecedents, and the names of the type variables, are chosen from the sequent's content alone: the closed form is its canonical closure (Definition Q-3d). So a theorem's statement, and with it its statement identity, does not depend on the order its locals were fixed in, on their names, or on where in a session it was proved. The pair (locals, hypotheses) is its shape, here (1, 1), which its partition records.

A local variable is identified by where it is bound: the context it extends, its type and its name. A partition stores each local as its type and name, followed by the context entry that binds it, whose parent is the context the local extends.

An answer from an external tool, such as a computer algebra system, is a claim: a session keeps it as a hypothesis with its provenance and exports it as an explicit antecedent before the theorem is published. The theorem is then true whatever the tool said. See external claims.

What a load lets you believe

Library.snapshot and Library.recheck run Algorithm L-5. In plain terms, when they return (Theorem L-6):

  1. every declaration was rebuilt and every row checked by your checker, in a fresh bank, and nothing else was declared;
  2. the library holds at most one provider per statement (barring a SHA-256 collision, and for statements with at most six type variables);
  3. if they raise instead, nothing outside the fresh bank changed.

So the loaded theorems are as trustworthy as your checker and your profile. The files themselves are never trusted.

A statement-only import is the one exception, and it is explicit: a session that imports a theorem with import_theorem gets its statement as an axiom stand-in, without its proof, and trusts the library version's producer for it (ST9.8). Open the library's snapshot instead when you need the proof checked.

What a library file cannot make you believe

A library is untrusted input. Its bytes can be damaged, edited or written by a hostile party, and the guarantees above still hold, because:

  • Only the checker establishes results. Loading never deserializes a trusted handle; every row is interned again and checked, and every declaration is rebuilt from its bytes.
  • Axioms stay visible. An axiom in a library is an Axiom declaration of the loaded theory, and evidence labels list it with its provenance class and source. Loading a library can add assumptions, but it cannot hide them.
  • Claims stay antecedents. A claim reaches a library only as an antecedent of a theorem's statement; it never becomes a fact.
  • The profile is yours. The manifest names the profile it was built against; the loader builds that profile itself, and refuses a library over a profile it does not know.

What a library can do is state theorems you did not ask for, and rest them on its own axioms. Check what you rely on: compute an evidence label (judgment_shell.label) for a theorem before you depend on it.

Re-checking and withdrawal

Loads are strict: one failing row refuses the whole load. After a checker fix or a profile change, some stored results may stop checking. Re-checking a version (Library.recheck) loads it whole into a fresh bank and checks every row, without touching your session; a row that no longer checks is refused (LIBRARY), and nothing is written. Statements are taken out of later versions explicitly, with change().withdraw, and a proof is replaced with change().replace (changing a library). See re-checking.

A repaired result is a new proof, published in a later version.

judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub