5.8 Verify an exported proof in Isabelle/HOL¶
Tutorial sequence · Previous: 5.7 Exchange proofs with OpenTheory
Goal: prove Cantor's theorem in pure polymorphic HOL inside judgment with
zero axioms, export the derivation as an OpenTheory version 6 article
(cantor.art), and independently verify every inference step inside
Isabelle/HOL's kernel using
isabelle-opentheory.
Complete the Store setup from Lesson 5.4
first (libjudgment_store.so on Linux, libjudgment_store.dylib on macOS).
1. Theorem and diagonalization proof¶
Cantor's theorem states that for any type \(A\), no function \(f : A \to (A \to \mathrm{Prop})\) is surjective onto the predicate space \(A \to \mathrm{Prop}\):
The derivation uses pure higher-order logic with zero axioms:
- Define the diagonal predicate \(D := \lambda y:A.\; (f(y)(y) \to \bot)\).
- Instantiate surjectivity at \(D\) and eliminate the existential with
obtainto fix a witness \(w : A\) satisfying \(f(w) = D\). - Rewrite \(f(w)\) to \(D\) in \(f(w)(w)\) and apply \(\beta\)-reduction (
rfl) to obtain the propositional equality \(f(w)(w) = (f(w)(w) \to \bot)\). - Derive \(f(w)(w) \to \bot\), rewrite back along the equality to derive \(f(w)(w)\), and apply modus ponens to obtain \(\bot\).
The Mojo and Python programs below prove Cantor's theorem over the classical
profile (which supplies the HOL definitions of True, False, ∧, ∨, →,
∀, and ∃ needed to write natural-deduction proofs to OpenTheory) and export
bit-identical 5,354-line OpenTheory v6 articles:
Mojo
"""Prove Cantor's theorem in pure HOL and export an OpenTheory v6 article."""
from std.sys import argv
from std.tempfile import mkdtemp
from std.testing import assert_equal
from judgment import Session, arrow, exists, forall, implies, lambda_
from judgment_store import Article, Library
from termbank import Budget
def main() raises:
var directory = mkdtemp()
var args = argv()
var path = String(args[1]) if len(args) > 1 else String(directory, "/cantor.art")
var budget = Budget(50_000_000)
var lib = Library.create(String(directory, "/classical"), "classical")
var s = Session.open(lib.profile_snapshot(budget))
# Cantor's theorem: no f : A -> (A -> Prop) is surjective onto A -> Prop.
var p = s.theorem("cantor")
var a = p.type_var("A")
var pred_t = arrow(a, s.prop_type())
var f = p.var("f", arrow(a, pred_t))
# Diagonal predicate D(y) := (f(y)(y) -> False).
var y = p.bound_var("y", a)
var diag = lambda_(y, implies(f(y)(y), s.false_()))
var x = p.bound_var("x", a)
var g = p.bound_var("g", pred_t)
var surj = forall(g, exists(x, f(x) == g))
p.goal(implies(surj, s.false_()))
# Assume f is surjective; instantiate at diag and obtain w with f(w) = diag.
var h_surj = p.intro("h_surj")
var h_ex = p.use(h_surj, terms=[diag])
var obtained = p.obtain(h_ex, "w")
var w = obtained[0]
var hw = obtained[1]
# Step 1: f(w)(w) = (f(w)(w) -> False) by rewriting f(w) -> diag and beta-reduction.
var fw = f(w)(w)
var eq_claim = p.have("fw_eq", fw == implies(fw, s.false_()))
_ = eq_claim.lhs().at(f(w)).rw(hw)
eq_claim.rfl()
var fw_eq = eq_claim.fact()
# Step 2: derive f(w)(w) -> False.
var nfw_claim = p.have("nfw", implies(fw, s.false_()))
var h_fw = nfw_claim.intro("h_fw")
var imp_claim = nfw_claim.have("fw_imp", implies(fw, s.false_()))
_ = imp_claim.focus().rw(fw_eq, reverse=True)
imp_claim.exact(h_fw)
nfw_claim.exact(nfw_claim.use(imp_claim.fact(), using=[h_fw]))
var nfw = nfw_claim.fact()
# Step 3: derive f(w)(w) from fw_eq and nfw, reaching False.
var fw_claim = p.have("fw_holds", fw)
_ = fw_claim.focus().rw(fw_eq)
fw_claim.exact(nfw)
p.exact(p.use(nfw, using=[fw_claim.fact()]))
var theorem = p.finish()
assert_equal(len(theorem.axioms()), 0)
assert_equal(len(theorem.admissions()), 0)
print("Proved:", theorem)
print("Axioms:", len(theorem.axioms()), "| Admissions:", len(theorem.admissions()))
# Export as an OpenTheory v6 article (with checked read-back).
Article.write(path, [s.export(theorem, "logic.cantor")], budget, profile="classical")
var article = Article.open(path, profile="classical")
var proved_count = 0
for entry in article.theorems():
if entry.kind == "theorem":
proved_count += 1
assert_equal(proved_count, 1)
print("Exported OpenTheory v6 theorems:", proved_count)
Run from the repository root pixi run mojo run -I src docs/examples/store/opentheory_isabelle.mojo
Output
Proved: [A] ⊢ ∀f:(A → A → Prop). (∀g:(A → Prop). ∃x:A. f(x) = g) → False
Axioms: 0 | Admissions: 0
Exported OpenTheory v6 theorems: 1
Python
"""Prove Cantor's theorem in pure HOL and export an OpenTheory v6 article."""
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from judgment import Article, Budget, Library, Session, arrow, exists, forall, implies, lambda_
def main():
with TemporaryDirectory() as directory:
path = sys.argv[1] if len(sys.argv) > 1 else str(Path(directory) / "cantor.art")
budget = Budget(50_000_000)
lib = Library.create(str(Path(directory) / "classical"), "classical")
s = Session.open(lib.profile_snapshot(budget))
# Cantor's theorem: no f : A -> (A -> Prop) is surjective onto A -> Prop.
p = s.theorem("cantor")
a = p.type_var("A")
pred_t = arrow(a, s.prop_type())
f = p.var("f", arrow(a, pred_t))
# Diagonal predicate D(y) := (f(y)(y) -> False).
y = p.bound_var("y", a)
diag = lambda_(y, implies(f(y)(y), s.false_()))
x = p.bound_var("x", a)
g = p.bound_var("g", pred_t)
surj = forall(g, exists(x, f(x) == g))
p.goal(implies(surj, s.false_()))
# Assume f is surjective; instantiate at diag and obtain w with f(w) = diag.
h_surj = p.intro("h_surj")
h_ex = p.use(h_surj, terms=[diag])
w, hw = p.obtain(h_ex, "w")
# Step 1: f(w)(w) = (f(w)(w) -> False) by rewriting f(w) -> diag and beta-reduction.
fw = f(w)(w)
eq_claim = p.have("fw_eq", fw == implies(fw, s.false_()))
eq_claim.lhs().at(f(w)).rw(hw)
eq_claim.rfl()
fw_eq = eq_claim.fact()
# Step 2: derive f(w)(w) -> False.
nfw_claim = p.have("nfw", implies(fw, s.false_()))
h_fw = nfw_claim.intro("h_fw")
imp_claim = nfw_claim.have("fw_imp", implies(fw, s.false_()))
imp_claim.focus().rw(fw_eq, reverse=True)
imp_claim.exact(h_fw)
nfw_claim.exact(nfw_claim.use(imp_claim.fact(), using=[h_fw]))
nfw = nfw_claim.fact()
# Step 3: derive f(w)(w) from fw_eq and nfw, reaching False.
fw_claim = p.have("fw_holds", fw)
fw_claim.focus().rw(fw_eq)
fw_claim.exact(nfw)
p.exact(p.use(nfw, using=[fw_claim.fact()]))
theorem = p.finish()
assert len(theorem.axioms()) == 0
assert len(theorem.admissions()) == 0
print("Proved:", theorem)
print("Axioms:", len(theorem.axioms()), "| Admissions:", len(theorem.admissions()))
# Export as an OpenTheory v6 article (with checked read-back).
Article.write(path, [s.export(theorem, "logic.cantor")], budget, profile="classical")
article = Article.open(path, profile="classical")
proved = [entry for entry in article.theorems() if entry.kind == "theorem"]
assert len(proved) == 1
print("Exported OpenTheory v6 theorems:", len(proved))
if __name__ == "__main__":
main()
Run from the repository root PYTHONPATH=bindings/python:docs/examples/python/store pixi run python docs/examples/python/store/opentheory_isabelle.py
Output
Proved: [A] ⊢ ∀f:(A → A → Prop). (∀g:(A → Prop). ∃x:A. f(x) = g) → False
Axioms: 0 | Admissions: 0
Exported OpenTheory v6 theorems: 1
2. Export cantor.art¶
Pass an output file path to either the Mojo or Python program to write
cantor.art into a working directory:
mkdir -p /tmp/isabelle-cantor
PYTHONPATH=bindings/python pixi run python \
docs/examples/python/store/opentheory_isabelle.py /tmp/isabelle-cantor/cantor.art
Or in Mojo (direct package; thin-client programs import Article, Library,
and Budget from judgment as in
Lesson 5.4):
pixi run build-store
pixi run mojo run -I build \
docs/examples/store/opentheory_isabelle.mojo /tmp/isabelle-cantor/cantor.art
Both produce the exact same OpenTheory v6 article (5,354 lines). Its only
constants and type constructors are the core HOL symbols (core.arrow,
core.Prop, core.eq, core.forall, core.imp, core.and, core.exists,
core.True, core.False), and its only article axiom commands are the
standard HOL logical connective definitions.
3. Independently check cantor.art in Isabelle/HOL¶
The OpenTheory website points to
xrchz/isabelle-opentheory for
replaying OpenTheory articles inside Isabelle/HOL. It reads every command in an
.art file and executes the corresponding primitive inferences directly through
Isabelle's Standard ML kernel (Thm.reflexive, Thm.symmetric,
Thm.transitive, Thm.combination, Thm.abstract_rule, Thm.beta_conversion,
Thm.assume, Thm.implies_intr, Thm.implies_elim, Thm.instantiate).
Because upstream xrchz/isabelle-opentheory targeted Isabelle2019, this
repository includes a small compatibility script
(docs/examples/store/isabelle_verify/update_isabelle_opentheory.py) that
updates its ML calls (TVars.make, Vars.make, Names.make_set,
Global_Theory.add_def, File.read_lines, Parse.path_input) for
Isabelle2025/2026 without altering any logical inference step.
Prepare the Isabelle session directory:
git clone --depth 1 https://github.com/xrchz/isabelle-opentheory.git /tmp/isabelle-opentheory
python3 docs/examples/store/isabelle_verify/update_isabelle_opentheory.py \
/tmp/isabelle-opentheory/opentheory.ML /tmp/isabelle-cantor/opentheory.ML
cp docs/examples/store/isabelle_verify/ROOT \
docs/examples/store/isabelle_verify/CheckCantor.thy \
/tmp/isabelle-cantor/
CheckCantor.thy maps judgment's core type and constant names to Isabelle's
HOL equivalents, proves the standard HOL connective definitions inside
Isabelle (by auto, no unchecked axioms), replays cantor.art via art_file,
and proves cantor_verified directly from the replayed theorem:
theory CheckCantor
imports Main
keywords "art_file" :: thy_decl
begin
(* ... type_definition_Collect_iff and ML_file "opentheory.ML" ... *)
setup \<open>
fold OpenTheory.add_tyop
[("core.arrow", @{type_name "fun"}),
("core.Prop", @{type_name "bool"})]
\<close>
setup \<open>
fold OpenTheory.add_const
[("core.eq", @{const_name "HOL.eq"}),
("core.forall", @{const_name "All"}),
("core.imp", @{const_name "HOL.implies"}),
("core.or", @{const_name "HOL.disj"}),
("core.and", @{const_name "HOL.conj"}),
("core.exists", @{const_name "Ex"}),
("core.True", @{const_name "True"}),
("core.False", @{const_name "False"})]
\<close>
lemma [opentheory]: "True = ((\<lambda>p::bool. p) = (\<lambda>p. p))" by auto
lemma [opentheory]: "All = (\<lambda>P. P = (\<lambda>x::'a. True))" unfolding fun_eq_iff by auto
lemma [opentheory]: "(\<longrightarrow>) = (\<lambda>p q. (p \<and> q) = p)" unfolding fun_eq_iff by auto
lemma [opentheory]: "(\<and>) = (\<lambda>p q. (\<lambda>f. f p q :: bool) = (\<lambda>f. f True True))"
apply (simp add: fun_eq_iff, safe, simp_all)
apply (drule_tac x="\<lambda>x y. x" in spec, simp)
apply (drule_tac x="\<lambda>x y. y" in spec, simp)
done
lemma [opentheory]: "(\<or>) = (\<lambda>p q. \<forall>r. (p \<longrightarrow> r) \<longrightarrow> (q \<longrightarrow> r) \<longrightarrow> r)" unfolding fun_eq_iff by auto
lemma [opentheory]: "Ex = (\<lambda>P. \<forall>q. (\<forall>x::'a. P x \<longrightarrow> q) \<longrightarrow> q)" unfolding fun_eq_iff by auto
lemma [opentheory]: "False = (\<forall>p. p)" by auto
art_file "cantor.art" "?0" \<rightharpoonup> "a" "_authoring_type_0_0" \<rightharpoonup> "a"
theorem cantor_verified:
"\<forall>f::'a \<Rightarrow> 'a \<Rightarrow> bool. (\<forall>g::'a \<Rightarrow> bool. \<exists>x::'a. f x = g) \<longrightarrow> False"
by (rule opentheory)
thm cantor_verified
thm_oracles cantor_verified
end
Run Isabelle/HOL in batch mode and inspect the build log:
isabelle build -v -D /tmp/isabelle-cantor
isabelle build_log CheckCantor | tail -n 16
Output (verified on Isabelle2026 in ~0.7 s):
Running CheckCantor ...
CheckCantor: theory CheckCantor.CheckCantor
Timing CheckCantor (8 threads, 0.711s elapsed time, 0.810s cpu time, 0.035s GC time, factor 1.14)
Finished CheckCantor (0:00:02 elapsed time)
Output (line 67 of "/tmp/isabelle-cantor/CheckCantor.thy"):
\<forall>bound44. (\<forall>bound45. \<exists>bound46. bound44 bound46 = bound45) \<longrightarrow> False
Output (line 69 of "/tmp/isabelle-cantor/CheckCantor.thy"):
theorem cantor_verified: \<forall>f. (\<forall>g. \<exists>x. f x = g) \<longrightarrow> False
Output (line 74 of "/tmp/isabelle-cantor/CheckCantor.thy"):
oracles:
4. What this audit establishes¶
- Independent kernel verification: Isabelle/HOL did not run
judgment, did not trustjudgment_core, and did not usesorryor any oracle (oracles:is empty). It replayed every primitive inference step fromcantor.artthrough its own ML kernel. - No extra axioms: the five
axiomcommands insidecantor.artare the standard HOL definitions of the logical connectives (True,All,-->,/\,Ex,False), each proved as a theorem in Isabelle/HOL'sMainbeforeart_fileruns. - No vendor lock-in: the resulting
cantor_verifiedis an ordinary Isabelle/HOL theorem usable in downstream Isabelle theories.
Exercise¶
Edit /tmp/isabelle-cantor/cantor.art to delete one eqMp or trans line (or
replace the final thm target with False), then re-run
isabelle build -v -D /tmp/isabelle-cantor. What happens?
Answer
isabelle build fails with an ML kernel error on the corrupted line:
opentheory.ML cannot construct an Isabelle thm from an invalid stack
transition or mismatched conclusion, because Isabelle's kernel rejects any
inference that does not match its primitive rules.
Next: 5.9 Transport theorems between theories with interpretations.