Proof library & interchange theory

Proof libraries

A library is a directory of files that is read and checked as one whole, as a partitioned table is one table. Its files are partitions, consecutive parts of the library's theory, and a manifest that lists them. A proof in any partition cites the theorems it uses by reference, never by copy, and every statement of the library has exactly one provider: one proof, one assumption, or one theorem of a definition or of the profile. This page states the rules and what checking a library establishes; ST7 and ST9 give the formats and algorithms.

Results are numbered L. Statement identities are Definition I-6.

Providers

Definition L-1 (provider). A provider is a reference that states a closed statement at its own type parameters by use (kernel K1.9):

  1. a Proven declaration: the statement has a proof;
  2. an Axiom: the statement is an assumption of the library;
  3. a definition's or an instance definition's equation (K1.3, K2.7), a class predicate's definition, a type definition's theorem parts 3 and 4, and a specification's theorem: a statement of a definitional declaration;
  4. any of these declared in the profile, the theory the library extends.

The statement a provider states is its statement, and the provider's statement identity is \(\operatorname{sid}\) of it, keyed in the theory that declares the provider (Definition I-6).

Evidence. The evidence of a Proven declaration of a library is its proof: the PROOF row that its partition's export table names, with the rows that row reaches (ST9.6). The checker declares the theorem only with a proof row it checked, whose sequent \(s\) has the theorem's statement as its canonical closure \(K(s)\) (Definition Q-3d; Definition LC-21 of local checking, Proposition Q-3c).

Rule L1 (one provider). Distinct providers of a library have distinct statement identities.

A theorem that restates a provider's statement up to renaming is not declared again: its names become aliases of the provider (Definition L-3). Only two kinds of Proven declaration besides providers exist:

Definition L-2 (restatement). A restatement of a provider \(p\) is a Proven declaration, other than \(p\), whose statement has \(p\)'s statement identity. A library holds none: the writer leaves out every restatement, which nothing may cite (a witness reuses its provider), and a load refuses two providers of one statement.

Rule L1 across versions. A later version (ST7.2) keeps its base's providers, with two exceptions it records in its manifest:

  • it may supersede a base axiom: the version declares a Proven provider of the statement, and the base's Axiom no longer provides it. The statement keeps one provider, so Rule L1 holds in the version. Both declarations bear the statement's canonical name; the name resolves to the provider the manifest lists (sections 3 and 7);
  • it may replace a base theorem's proof. A provider's identity does not depend on its proof, so the new proof is of the same Proven declaration: the version declares it again with the new proof, and the statement keeps its one provider. The new proof must not rest on the statement it proves: it may cite neither the declaration nor any of its dependents (Definition L-4);
  • it may withdraw a base statement that nothing depends on: no declaration of the base or of the version cites its provider, by its record or by its proof (Definition L-4), and the version does not provide it again.

Publication refuses any other edit, and names, when it refuses a replacement, the dependent the new proof cites. A superseded or withdrawn provider's declaration, and a replaced proof's rows, stay in the base's partitions, so the base's rows still load and a whole load still checks them; the declaration no longer provides the statement, or the proof is no longer the statement's.

Definition L-4 (citations and dependents). A declaration cites the library declarations its ST1.4 record cites (its record citations) and, for a Proven, those its current proof's rows name (its proof citations, ST9.1): the theorem's immediate citations, where a cited theorem counts itself and never what its own proof cites. The dependents of a declaration x are the least set of the version's declarations that holds every declaration citing x or a dependent of x. Both kinds of citation count, because a definition whose witness rests on x is as circular in a proof of x as a theorem that cites x.

Canonical names. A Proven or Axiom provider of the library is named judgment.stmt. followed by the 64 lowercase hexadecimal digits of its statement identity. An Axiom provider with at most six type variables is declared stating its key (Definition I-5). Providers of kinds 3 and 4 keep their names: the profile's names are part of its contract, and a definitional statement is named by its definition.

By Definition I-1, the identity of a Proven or Axiom provider with at most six type variables depends only on its statement's key, so its identity, and the citations of it in every proof, do not depend on any name a source gave the theorem.

Definition L-3 (alias). An alias is a name, the statement identity it names, and the names of the statement's type variables in key order: a nonempty name for each, and no name for two variables of one sort (a type variable is its name and its sort, so two variables of different sorts can share a name). A library gives each name at most one alias. An alias states the theorem as its source did: use of the provider at the type variables it names, in the order of _arguments (Definition I-5).

Definition L-3a (library names). A library name is one or more components joined by ., each matching [a-z][a-z0-9_]*. The first component is not judgment, which canonical names use. An alias's name (Definition L-3) is a library name.

Definition L-3b (normalized name). The normalized name of a long name splits it at . and normalizes each component, in order:

  1. a trailing (n), a fact's n-th theorem, becomes _n;
  2. each ' becomes _prime;
  3. each - becomes _;
  4. a _ is inserted between a lowercase letter or digit and the uppercase letter after it, and before the last uppercase letter of a run of two or more that a lowercase letter follows;
  5. ASCII letters are lowercased;
  6. a run of _ becomes one.

A component that is empty or then fails [a-z][a-z0-9_]* (it starts with a digit or _, or holds another character) has no normalized name.

Session, full name Long name Normalized
HOL-Probability, Martingale.martingale_convergence HOL-Probability.Martingale.martingale_convergence hol_probability.martingale.martingale_convergence
HOL, List.sum_list_append HOL.List.sum_list_append hol.list.sum_list_append
HOL, Real.isCont_add HOL.Real.isCont_add hol.real.is_cont_add
HOL-Library, XMLParser.parse HOL-Library.XMLParser.parse hol_library.xml_parser.parse
HOL, Groups.add_0' HOL.Groups.add_0' hol.groups.add_0_prime
HOL, HOL.conjI(2) HOL.HOL.conjI(2) hol.hol.conj_i_2
Pure, Pure.equal_elim Pure.Pure.equal_elim pure.pure.equal_elim

A source's name is its override if the version's override table lists its long name, and otherwise its long name's normalized name. A user's name is given directly, as a library name.

Reuse count. The reuse count of a provider is the number of the library's PROOF rows whose declaration operand names it, each row counted once (ST9.1). A provider with a high reuse count and no alias is a lemma that sources use without naming.

Results with contexts

A theorem's proof row can conclude an open sequent Γ ⊢ φ, with locals and hypotheses in Γ. A library holds closed statements, so such a theorem states a closed form of it: the canonical closure \(K(s)\) of its sequent \(s\).

Definition L-9 (closed form). Let Γ ⊢ φ be a judgment, and Γ' the entries of Γ it uses: its locals and hypotheses, and the locals their types and propositions mention (K1.9), in context order. Let \(x_1, \dots, x_n\) be the locals of Γ' and \(h_1, \dots, h_m\) its hypotheses, each in context order. The closed form of the judgment is

\[ \vdash \forall x_1 \dots x_n.\; h_1 \to \dots \to h_m \to \varphi \]

obtained by transporting the judgment to the context of \(x_1, \dots, x_n\) followed by \(h_1, \dots, h_m\), which is well scoped because a hypothesis mentions only locals before it (K1.5), and then applying imp_intro to \(h_m, \dots, h_1\) and forall_intro to \(x_n, \dots, x_1\). Its shape is \((n, m)\).

The closed forms of one judgment in any two orders of its locals and of its hypotheses are derivable from each other (Theorem Q-3b). \(K(s)\) is the one whose order of quantifiers and antecedents, and whose names of type variables, the canonical search chooses from the sequent's content alone (Definition Q-3d): it does not depend on how the locals are bound or named, nor on the type variables' names (Theorem Q-3a).

A judgment whose sort hypotheses are not witnessed in its theory cannot be declared (K2.8), so it is not entered.

Shape. Every theorem whose proof row concludes an open sequent keeps its shape in its partition (section 9, ST8.4); the checker builds \(K\) of the row's sequent and requires it to be the theorem's statement (ST9.6). The entry's lists of external claims are empty. A session that rests a result on an external claim, such as a computer algebra system's answer, exports the claim as an explicit antecedent before the theorem is published (judgment_shell.export_claims): the closed form is a theorem whatever the claim says, and the claim is an antecedent, never an axiom.

Rule L1 for closed forms. Two sequents of one shape that are renamings of each other, of their locals and of their type variables, have one canonical closure (Theorem Q-3a), so their theorems state one statement. Publishing a theorem whose statement is already provided gives the existing provider; a load refuses a second provider.

Dependencies

A partition cites a declaration when one of its rows names it: a REF row, through its section 1. The dependencies that the manifest lists for a partition are the partitions it is loaded after: a library's sub-partitions form chains, each depending on the one before it, and the first partition of a chain on none (ST9.1). Every constant, type, and class a partition's statements mention is thereby declared in an earlier partition, in the profile, or in the core, and references are resolved only there.

Checking a library

Algorithm L-5 (load). Input: a library's version and a fresh bank that holds the core and the profile the version's manifest names.

  1. Read the version's manifest, check its file hash and the reader's checks of ST7.3, and check that it names the bank's profile.
  2. For each partition, in the manifest's order:
  3. check its manifest record (one theory's sub-partitions in order, each depending on the one before it unless it starts a chain), its length, its file hash, its container, and its Merkle root against the manifest's (ST9.5);
  4. decode its rows, numbered after the rows the earlier partitions of its chain stored, and commit them into the bank in row order (ST9.8): a REF row resolves only among the core, the profile and the declarations already loaded; a DECL row rebuilds its declaration from its bytes, which must have the stated identity, and declares it with the proof its export-table entry names; a LOCAL row is committed together with the fix frame that must follow it, and maps to the bank's local when the bank holds its binding site; every other row is interned, which recomputes its structural data.
  5. Recompute the proof citations of every loaded Proven and compare them with the manifest's declaration index.
  6. Decide every theory and check every committed row (KC1.12); every row must be verified.
  7. Recompute, from the bank, each partition's metadata sections other than its provenance (section 4, which is checked against its own axioms) and its export table, the statement identity of every provider it declares, and the type-variable names of every alias whose provider is loaded, and compare them with what was read; refuse two declarations providing one statement, other than a Proven after a provider that section 8 records as superseded (Rule L1 across versions).
  8. For a whole load: compare the manifest's statements, with their kinds, providers and reuse counts, with the providers the load declared and the profile's, less those the version's changes superseded or withdrew; compare the declaration index, and require a replaced-proof entry for every theorem declared again.
  9. Return the bank. Any refusal drops it.

Theorem L-6 (what a load establishes). If Algorithm L-5 accepts a whole load, then:

  1. every declaration was rebuilt and declared through the checker's rules, every row was checked by the checker, and every theorem's statement is the canonical closure of its proof row's sequent, derivable from the row's judgment; nothing else was declared;
  2. if no two distinct serializations involved have one SHA-256, Rule L1 holds for statements with at most six type variables: no two of the version's providers state one statement up to renaming;
  3. a failure leaves everything outside the load's fresh bank as it was.

Proof. (1) Rows enter the bank only by interning and declarations only through declare, in step 2.2; step 4 requires the checker's driver to verify every committed row, and the check of a Proven reads its proof row as its judgment and requires \(K\) of its sequent to be its statement (ST9.6, Proposition Q-3c), which Theorem Q-3b derives from the row's judgment. References resolve only to declarations already loaded. (2) Step 5 computes the statement identity of every provider from the declaration the bank holds and refuses a second declaration providing one statement, except a Proven that replaces a provider section 8 records as superseded: a superseded Axiom, or a Proven declared again with a new proof. That earlier declaration stays in the bank but is not one of the version's providers (Rule L1 across versions), so each statement keeps one provider. Step 2 of ST7.3 checks that the manifest's identities are strictly increasing, so they are distinct, and step 6 checks that the manifest lists exactly the declared providers and the profile's, less those the version's changes superseded or withdrew. Distinct identities are statements that are not renamings of each other, by Proposition I-6. (3) The load works in a fresh bank, which only a successful load returns (ground rule SG3). \(\square\)

A load of a version's leading partitions checks (1) and (3) for what it loads, and Rule L1 among the loaded providers. A statement-only import (ST9.8) runs no Algorithm L-5: it declares the providers of the statements it imports as stand-ins, so the version's producer is in the importer's trusted base for them. Rule L1 is a property of the library, not of soundness: a library that breaks it can only hold a redundant proof, never establish a false theorem.

Re-checking

Loads are strict: a refusal of any part refuses the whole load. A checker fix or a profile change can make a stored result stop checking; finding and removing those results is an explicit, versioned step, not something a load does.

Definition L-7 (re-checking). Re-checking a library version runs Algorithm L-5 on the whole version in a fresh bank over the current checker and profile, and writes nothing. It either reports what it verified or refuses with the first failure.

Proposition L-8 (withdrawal). Let a version load, and let a change withdraw statements none of whose providers a declaration of the version cites, by its record or its current proof (Definition L-4). Then the new version loads against the same checker and profile, and none of its theorems depends on a withdrawn statement.

Proof. The change appends partitions and keeps the base's, so every declaration the base loaded is loaded again; a withdrawn provider stays declared, and only section 3 stops listing its statement. No declaration cites a withdrawn provider, by hypothesis, and the change's own declarations are refused if they cite one. Rule L1 holds for a subset of providers. \(\square\)

A result that stops checking is repaired by a change that replaces its proof or withdraws it and everything that cites it, published as a new version.

Statements with more than six type variables. Their keys may be chosen by first occurrence after a renaming that re-sorts ACU arguments (Definition I-5), so two renamings of one such statement can have two identities. The library may then hold both; it never identifies different statements.

An assumption that is later proved. Rule L1 holds in each version of a library. A proof of a statement that the library assumes supersedes the Axiom in a new version (Rule L1 across versions): the axiom stays declared in its partition, and the manifest lists the theorem as the statement's provider.

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