OpenTheory export and import¶
OpenTheory [Hurd 2011] is the HOL family's interchange format: an
article is a program for a stack machine whose commands build types,
terms, and theorems with HOL's primitive inference rules, and which an
independent HOL kernel (the opentheory tool, HOL4, or OpenTheory's HOL
Light) checks. It is the first independent auditor of the kernel's
results, and the format in which other provers' theories enter: HOL Light's
from the OpenTheory repository, and Isabelle/HOL's through isabelle_bridge,
in an extended form that keeps type classes.
This page treats export first, then import. The article format is
version 6 [Leslie-Hurd 2014].
Export¶
Definition OT-1 (the translation). A result's derivation is translated as follows:
- its proof is rebuilt and conversion is eliminated (Algorithm EL-2);
- the logic core's primitive constants (\(\mathsf{True}\), \(\mathsf{False}\),
\(\land\), \(\lor\), \(\to\), \(\forall\), \(=\)) are mapped to OpenTheory's
boolpackage constants; the core's defined constants (\(\neg\), \(\leftrightarrow\), \(\exists\)) are written as new constants by their own definitions, so that no equivalence with HOL's definitions is needed; - each of the kernel's natural-deduction rules is translated into HOL
primitive inferences, citing theorems of the
boolpackage proved once in HOL (for example \(\vdash p \Rightarrow q \Rightarrow p \land q\) for \(\land\)-introduction), andpropextinto HOL'sdeductAntisymandeqMp; - the theory's other symbols keep their own names and meanings. Definitions
and specifications become conservative HOL definitions, and type definitions
use
defineTypeOpwith a checked witness. The fixed standard choice foundation supplies a concrete witness from the source existential (ST5.2). Definitions and defined types are specialized where their bodies use overloaded constants; numerals stay terms of the theory's own constants (a mapping to HOL's binary numerals is needed only when a theory is interpreted into HOL's number types); - the theory's axioms (profile axioms, cited laws that are axioms, imported statements, the hypotheses of external claims) become the article's assumptions;
- sorted type variables, classes, and instances, which OpenTheory cannot express, are removed first by the kernel's Theorem Y-6: each sorted type variable becomes an unsorted one with class premises, each class predicate a defined constant, and each use of an arity the cited instance theorem. Overloaded constants are written as one constant per instance definition used (the "unoverloading" of Kunčar and Popescu [2017]).
Theorem OT-2 (each rule translates). Every rule of the kernel's
calculus (its Definition D-3), with conversion eliminated, translates into
a derivation from HOL's primitive rules and the cited bool theorems.
Proof. By cases over the rules: the connective rules are instances of
the bool theorems by INST, EQ_MP, and modus ponens; the quantifier
rules use HOL's \(\forall\)-introduction and elimination derived rules
(GEN, SPEC); the equality rules are HOL's REFL, TRANS, MK_COMB,
ABS, and substitution; use is INST_TYPE and INST of an assumption
or theorem; export is DISCH and GEN; β, ζ, and δ are BETA_CONV
and the definitions' theorems. The bool package proves the derived rules
in HOL [Hurd 2011; Harrison 2009]. \(\square\)
Theorem OT-3 (what the audit confirms). If an independent HOL kernel accepts the article, then the translated statement is derivable in HOL from the translated assumptions. Since HOL's standard semantics agrees with the kernel's on the logic core (the kernel's Definition M-3 is Pitts's semantics of HOL), the audit independently confirms our kernel's judgment, relative to the translated source assumptions and, for type definitions, the fixed standard HOL choice foundation of ST5.2.
Proof. Soundness of HOL [Gordon and Melham 1993; Kumar et al. 2016],
and the agreement of the two semantics on the translated constants: the
mapped core constants have their standard meaning in both, and every other
constant keeps its source definition or is uninterpreted in both, constrained
only by the assumptions. Sorted type definitions extend their predicate by
H ==> P outside their class domain; under the explicit class premises H,
their two source facts follow from the HOL definition.
\(\square\)
This is de Bruijn's criterion applied across kernel lineages: a bug shared
by our kernel and our tests is unlikely to be shared by an independent
HOL kernel. The audit runs in CI on demand; this package writes the
articles and keeps the bool mapping lemmas.
Import¶
Definition OT-4 (article semantics). Running an article executes its
commands on a stack and a dictionary. Its assumptions are the
theorems pushed by axiom, its theorems those recorded by thm, and
its definitions the constants and type operators made by
defineConst, defineConstList, and defineTypeOp. An article is
correct when each of its theorems is derivable in HOL from its
assumptions and definitions; the opentheory tool checks exactly this.
Definition OT-5 (the converter's representation). The converter holds
each HOL theorem \(\{\gamma_1, \dots, \gamma_n\} \vdash \varphi\) on the
article's stack as one proof row of its bank (TD1.8): a sequent whose
hypothesis set holds the \(\gamma_i\) as canonical nodes, without repetitions,
and whose conclusion is \(\varphi\). HOL's bool is Prop, its function
type the kernel's arrow, its equality the kernel's eq; α-equivalent terms
are one de Bruijn node. The article's free variables are locals of the
row's context. A variable that the article's raw syntax has and canonical
construction loses is kept as a retained local of the row (Definition Q-6),
and every hypothesis stays in the set whether a later step uses it or not,
so neither is lost. The theorem's closed form is the row closure
(Definition Q-3)
with \(\bar v\) the row's locals, retained ones included, in binding order
(context order), and the \(\gamma_i\) in closed-form order (Definition Q-2):
the claim a natural-deduction row reads the row as. A thm states the
canonical closure \(K\) of the row's sequent (Definition Q-3d), a closed form
of it whose order of quantifiers and antecedents, and whose names of type
variables, depend on the sequent's content alone (Theorem Q-3a); each of
the two is derivable from the other (Theorem Q-3b). So two articles that
fix one theorem's variables in different orders state one statement. An
article variable whose name begins with · is stored with one more · in
front, ··name, the escape of L1.6, so that it is never a reserved name;
the writer removes the escape from article variable names, and escapes a
dot in a variable's or a type variable's name (ST5.1). Type operators and
constants are found through the name map (Definition OT-8), or else
declared when the article defines them, or else declared as uninterpreted
when the article only uses them, as an assumption's constants.
Algorithm OT-6 (one command, one row). The converter runs the
article's stack machine and commits each inference command as one proof
row of the TD1.8 kind of the same name, its operands the rows and nodes on
the stack: refl, sym, trans, appThm, absThm, betaConv,
assume, eqMp, deductAntisym, proveHyp, and subst, which
instantiates types before terms (Definition Q-8). A declaration command
declares through the construction engine and commits the row of its kind:
| Command | Declaration and row |
|---|---|
axiom |
an Axiom stating the canonical closure K of its sequent, and an axiom row; if an earlier provider has that K at the sequent's shape (Rule L1), no declaration: the engine derives the theorem from the provider by a use row, followed by an inst row when the provider's quantifier or type-variable order differs (Proposition Q-3f) |
thm |
a Proven stating K of the theorem's sequent, whose proof is the theorem's row, and a thm row |
defineConst |
a Definition (not transparent), and a defineConst row stating its equation |
defineConstList |
a specification (the kernel's K2.6, Definition Y-2), and a defineConstList row |
defineTypeOp |
a type definition (K2.6, Definition Y-1), and a defineTypeOp row |
Where canonical construction makes the kernel's fact differ from the article's pushed theorem (a type definition's predicate that loses an erased type parameter, a statement that lacks some of the article's variables), the engine derives the pushed theorem from the kernel's by a fixed sequence of further rows, the classical profile's choice constant supplying closed terms for the missing variables. The converter computes each row's conclusion, hypothesis set and dependency set, but it is untrusted: the checker checks every row (KC1.7) when the bank is checked or the library loaded.
Theorem OT-7 (each command is realized). For every command of the format, if the article's stack holds rows that represent HOL theorems \(T_1, \dots, T_m\) (Definition OT-5) and the command pushes \(T\), the rows Algorithm OT-6 commits for it, once the checker accepts them, end in a row that represents \(T\).
Proof. Each sequent kind 0x00 to 0x0A is the rule of Definition Q-7 or
Q-8 that mirrors the HOL primitive of the same name, and the checker
accepts a row only if its stored conclusion, hypothesis set and dependency
set are those the rule computes from its premises (KC1.7). HOL's
hypotheses form a set, and so does the row's; α-equivalence is identity of
de Bruijn nodes. Where canonical forms merge hypotheses, the row's set may
be smaller than the article's; its sequent is still derivable (Theorem
Q-16), and its closed form is the one the converter gives the article's
theorem, since it forms hypotheses canonically too. A declaration row is
use of the declaration's statement (Definition Q-17), which is the
article's pushed theorem, or the engine's fixed rows derive the pushed
theorem from it, each checked like any other. \(\square\)
Definition OT-8 (the name map). The name map sends OpenTheory names
to kernel declarations, each entry justified by a theorem proved once in
the kernel. It contains the bool package's connectives and quantifiers,
mapped to the logic core's (the export's mapping, read backward), and the
classical constants: HOL's select to the classical profile's choice
operator. When an article defines a mapped name, the reader checks that
the definition is the one the entry expects, and uses the kernel's
declaration with the entry's theorem in place of the pushed equation.
When an article assumes one of HOL's three axioms (η, choice, infinity),
the reader discharges the assumption with the classical profile's
corresponding theorem or axiom.
Theorem OT-9 (import is sound). If the checker accepts the rows of a converted article, every theorem it records is a kernel judgment that depends only on the classical profile's axioms, the declarations the article made (definitions, specifications, type definitions), and the article's remaining assumptions, each declared as an axiom of the library and registered as an imported statement with its source.
Proof. Theorem OT-7 for each step, the name map's theorems for mapped definitions, and the kernel's dependency tracking for the dependencies. The definitions preserve models (the kernel's Theorems M-5, Y-1, Y-2, and Y-3), so they add no logical strength. \(\square\)
Definition OT-10 (extended articles). An extended article starts
with version 6 followed by a "judgment.extended.6" pragma, and may
use the commands of the table below, which plain OpenTheory lacks. Any
other reader rejects it at the first such command.
| Command | Stack effect | Kernel operation |
|---|---|---|
sortedVarType |
pops a list of class names and a name; pushes a type variable with that sort | type_var(name, sort, theory) (K2.8) |
overloadedConst |
pops a type and a name; pushes a constant | an overloaded constant (K2.7) |
defineInstance |
pops a term, a list of types, and a constant; pushes the theorem \(\vdash c[\bar\tau] = t\) | an instance definition (K2.7) |
defineClass |
pops an axiom term, a list of parameter constants, a list of superclass names, and a name; pushes the class's predicate constant | a class (K2.8) |
instance |
pops a theorem, a class name, a list of sorts, and a type operator; records the arity | an instance declaration (K2.8) |
ofClass |
pops a class name and a type; pushes \(\vdash \mathsf{of\_class}_c(\mathsf{TYPE}[\tau])\) | the kernel's of_class rule |
source |
pops five names (prover, release, session, theory, theorem); names the next thm or axiom, supplying provenance for an axiom |
statement naming and provenance |
classRelation |
pops a theorem and two class names; records the checked subclass edge | Declaration.class_relation with the checked implication witness |
definitionThm |
pops an existing definition constant; pushes its defining equation | use at the definition's declared type parameters; adds no declaration or axiom |
defineSortedTypeOp |
as defineTypeOp, with a list of sorted type variables as parameters |
the kernel's type definition (K2.6) |
declareTypeOp |
pops an arity and a name; pushes a type operator | a type constructor declaration |
declareConst |
pops a type and a name; pushes a constant | a constant declaration without a definition |
In extended articles, names must resolve to mapped declarations, declarations
in the article, or declarations in the parent theory. The explicit declaration
commands add no axiom, and strict resolution only refuses, so they add no
logical strength. A source names the next thm or axiom, whichever comes
first (ST6.5): it names a statement and
adds no declaration or axiom. definitionThm requires a visible Definition
declaration, including class predicates; another kind or an unavailable
declaration is refused. Its correctness follows directly from kernel use,
just as for definition equations in Algorithm OT-6.
Import theories (design, not implemented). The Store has no import theories: the converter commits an article's declarations into the library it writes, and nothing moves results between two of them. Definition OT-11 and Theorem OT-12 describe the intended design.
Definition OT-11 (import theories and tiers). An article from another
prover is read into an import theory named after its source. In a
statement article (tier 1), every theorem is pushed by axiom with a
source, so the import theory's theorems are imported statements. In a
proof article (tier 2), theorems are derived by the rules, from the
definitions and from earlier import theories, so they are Proven.
Theorem OT-12 (moving from statements to proofs). Let \(S\) be the import theory of a statement article and \(P\) that of the proof article for the same source theory, and suppose every imported statement of \(S\) is a theorem of \(P\) with the same statement. Then the identity map on shared declarations is an interpretation of \(S\) in \(P\) (Definition IN-1), and every result derived from \(S\) moves to \(P\) by Algorithm IN-2, after which its label no longer lists the imported statements of \(S\).
Proof. Definition IN-1's obligations are the axioms of \(S\), which are theorems of \(P\) by hypothesis; Theorem IN-1 then gives the translated derivations, and Algorithm IN-2 replays them. The labels are computed from the replayed judgments, whose dependencies are \(P\)'s. \(\square\)