Intoduction
Formalized Formal Logic is aim to formalize some various results of mathematical logic in Lean Theorem Prover.
Kites
Visualization for sublogic/subtheory relations.
Modal Logics
First-Order Arithmetics
Import Graph
Generated by import-graph
References and
References
- J. Han, F. van Doorn, "A formalization of forcing and the unprovability of the continuum hypothesis"
- W. Pohlers, "Proof Theory: The First Step into Impredicativity"
- P. Hájek, P. Pudlák, "Metamathematics of First-Order Arithmetic"
- R. Kaye, "Models of Peano arithmetic"
- 田中 一之 (編), 『ゲーデルと 20 世紀の論理学』
- 菊池 誠 (編), 『数学における証明と真理 ─ 様相論理と数学基礎論』
- P. Blackburn, M. de Rijke, Y. Venema, "Modal Logic"
- Open Logic Project, "The Open Logic Text"
- R. Hakli, S. Negri, "Does the deduction theorem fail for modal logic?"
- G. Boolos, "The Logic of Provability"
- M. C. Fitting, V. W. Marek, and M. Truszczynski, "The Pure Logic of Necessitation"
- T. Kurahashi, "The provability logic of all provability predicates"
- W. Carnielli, C. Pizzi, "Modalities and Multimodalities"
- A. Chagrov, M. Zakharyaschev, "Modal Logic"
- G. E. Hughes, M. J. Cresswell, "A New Introduction to Modal Logic"
- K. Segerberg, "An Essay in Classical Modal Logic"
Related Works
Here is the list of project particularly formalize mathematical logics. If you find something missing from this list or add, report via issues.
Lean 4
m4lvin/lean4-pdl
Propositional dynamic logics.
alexoltean61/hybrid_logic_lean
Hybrid logic. Syntax and semantics for hybrid logic are provided, and some facts and soundness have been proven. However completeness seems to have been not yet formalized.
leanprover-community/con-nf
Formalizing the consistency of Quine's set theory "New Foundations": .
Lean 3
flypitch
Independence of the continuum hypothesis.
bbentzen/ipl
Intuitionistic propositional logic.
Hilbert-style deduction system, Kripke semantics and Henkin-style (constructing maximal prime set and canonical model) completeness proof.
bbentzen/mpl
Normal modal logic.
Hilbert-style deduction system, Kripke semantics and Henkin-style (constructing maximal consistent set and canonical model) completeness proof for .
paulaneeley/modal
Formalization of modal logic and public announcement logic.
minchaowu/ModalTab
Tableaux system for modal logic .
ljt12138/Formalization-PAL
and public announcement logic (PAL). Main result are recursion theorem (reducing public announce modality for any PAL formula) and completeness of .
Isabelle
Lawrence C. Paulson, "Gödel's Incompleteness Theorems"
Formalized Gödel's first and second incompleteness theorems. Remark the second incompleteness theorem is proved on hereditarily finite sets.
Christoph Benzmüller, Woltzenlogel Paleo, "Gödel's God in Isabelle/HOL"
Gödel's ontological argument of God's existence.
jrh13/hol-light/GL
Completeness of Gödel-Löb (provability) modal logic in HOL/Light.
u5943321/Modal-Logic
Modal Logic, based on textbook "Modal Logic" by P. Blackburn, M. de Rijke, Y. Venema in HOL.
Coq
ianshil/PhD_thesis
Coq formalization of several modal logics (related provability logic and etc.) and their caliculi.
hferee/UIML
Uniform interpolants for basic modal logic , Gödel-Löb provability logic , intuitionistic strong Löb logic .
- demo
- Hugo Férée, Iris van der Giessen, Sam van Gool, Ian Shillito, "Mechanised uniform interpolation for modal logics K, GL and iSL"
ana-borges/QRC1-Coq
Quantified modal logic called Quantified Reflection Calculus with one modality .
Christian Doczkal, Gert Smolka, "Completeness and decidability of converse PDL in the constructive type theory of Coq"
Propositional Dynamic Logic.
Christian Doczkal, Gert Smolka, "Constructive Formalization of Hybrid Logic with Eventualities"
Hybrid Logic.
Russell O'Connor's continuous works on Incompleteness Theorem
fondefjobn/S5-Formalization-in-Coq
Modal logic , its Kripke completeness.
Floris van Doorn, "Propositional Calculus in Coq"
Hilbert deduction system, natural deduction system, and sequent calculus for classical propositional logic. Formalized completeness of natural deduction system, the provability equivalence of three calculi, cut-elimination for sequent calculus.
Christoph Benzmüller, Bruno Woltzenlogel Paleo, "Interacting with Modal Logics in the Coq Proof Assistant"
Modal logic and Gödel's ontological argument of existence of God.
mphilipse/coq-multi-agent-systems
Multi-agent epistemic modal logic .
Iris Project
Framework for concurrent saparation logic. Verified in Coq.
First-Order Logic
TODO:
Term and Formula
Notation
Quantification of formulae are defined using de Bruijn index, but we can write terms and formulae by usual binder notation using macro.
variables x y z
is just an example and can take any number of ident
s.
e
is an expression of term/formula.
Binder Notation
Binder notation of term takes either form:
- Term:
‘x y z. e’
, Formula:“x y z. e”
x y z
is the symbol for the bound variables,k:num
-variables denotes the terms inSemiterm L ξ (n + $k)
/Semiformula L ξ (n + $k)
. (n
can be variable)
- Term:
‘x y z | e’
, Formula:“x y z | e”
x y z
is the symbol for the free variables,k:num
-variables denotes the terms inSemiterm L ξ n
/Semiformula L ξ n
. (n
can be variable)
- Term:
‘e’
, Formula:“e”
- An abbreviation of
‘ . e’
/“ . e”
- An abbreviation of
Expression of term/formula
Deduction System for First-Order Logic
Semantics for First-Order Logic
Completeness Theorem
Arithmetics
In this formalization, we prefer developing arithmetic model theoretic, i.e. show instead of (They are equivalent thanks to the completeness theorem.). This approach has several advantages:
- In general, writing a formalized proof (in formalized system!) is very tedious. Meta-proofs, on the other hand, tend to be relatively concise.
- Many definitions and proofs of logic and algebra in Mathlib can be used.
- Metaprogramming can streamline the proof process (especially
definability
). - It is easy to extend predicates and functions. When adding predicates or functions, it is necessary to extend its language by extension by definition in case of formalized proof, but not in model theoretic approach.
This procedure is done as follows. Suppose we wish to prove that the totality of an exponential function can be proved in . First, the graph of the exponential function must be defined. This is achieved by the following two definitions.
-
Semantic definition.
def Exponential {M : Type*} [Zero M] [One M] [Add M] [Mul M] [LT M] [M ⊧ₘ* 𝐈𝚺₀] : M → M → Prop
-
Syntactic definition that expresses the semantic definition.
def exponentialDef : 𝚺₀-Semisentence 2 lemma Exponential.defined : 𝚺₀-Relation (Exponential : M → M → Prop) via exponentialDef ``` Then prove the totality.
theorem Exponential.total {M : Type*} [Zero M] [One M] [Add M] [Mul M] [LT M] [M ⊧ₘ* 𝐈𝚺₀] (x : M) : ∃ y, Exponential x y
Since Exponential
and Exponential.total
are defined in all the model of ,
𝐈𝚺₁ ⊢! ∀' ∃' exponentialDef
is obtained by the completeness theorem. This was the result we wanted to achieve.
Defined Predicates and Functions
Predicate/Function | Notation | Defined in | Totality is proved in | Complexity | Polynomial Bound |
---|---|---|---|---|---|
0 | |||||
1 | |||||
x + y | |||||
x * y | |||||
x = y | - | - | |||
x < y | - | - | |||
x ≤ y | - | - | |||
(modified subtraction) | x - y | ||||
(devides) | x ∣ y | - | - | ||
min x y | |||||
max x y | |||||
x / y | |||||
(remainder) | x % y | ||||
√x | |||||
⟪x, y⟫ | |||||
(first inversion of pairing) | π₁ x | ||||
(second inversion of pairing) | π₂ x | ||||
exp x | none | ||||
log x | |||||
(binary length) | ‖x‖ | ||||
x # y | none | ||||
(number of ones) | nuon x | ||||
, | x ∈ y | - | - | ||
∅ | |||||
x ⊆ y | - | - | |||
⋃ʰᶠ x | none | ||||
x ∪ y | |||||
⋂ʰᶠ x | ? | ||||
x ∩ y | |||||
(cartesian product) | x ×ʰᶠ y | ? | |||
(domain of relation) | domain x | ||||
IsMapping x | - | - | |||
Seq x | - | - | |||
(length of sequence) | lh x | ||||
(concatation of sequence) | x ⁀' y | none | |||
(-th element of sequence) | znth x | ||||
L.Semiterm x y | - | - | |||
L.termSubst n m w t | none | ||||
L.Semiformula x y | - | - |
Theories of Arithmetics
Notation | Description | ||
---|---|---|---|
𝐏𝐀⁻ | Finitely axiomatized fragment of | ||
𝐈open | + Induction of open formula | ||
𝐈𝚺₀ | + Induction of formula | Theory | |
𝐈𝚺₀ + Ω₁ | + -axiom | ||
𝐄𝐀 | Elementary arithmetic | ||
𝐈𝚺₁ | + Induction of formula | Theory | |
𝐏𝐀 | Peano arithmetic |
Theory
Exponential
The graph of exponential is definable by -fomrula, and its inductive properties are proved in .
instance exponential_definable [M ⊧ₘ* 𝐈𝚺₀] : 𝚺₀-Relation (Exponential : M → M → Prop)
lemma exponential_zero_one [M ⊧ₘ* 𝐈𝚺₀] :
Exponential 0 1
lemma exponential_succ_mul_two [M ⊧ₘ* 𝐈𝚺₀] {x y : M} :
Exponential (x + 1) (2 * y) ↔ Exponential x y
Other basic functions, such as are defined by using exponential.
Theory
Exponential
It is proved that the graph of exponential is definable by -formula, and their inductive properties are provable in . In , we can further prove their entireness.
Theory of Hereditary Finite Sets in
Weak theory of sets in (Hereditary Finite Sets) can be developed inside using Ackermann coding and bit predicate. Hereafter, we will use the notation in the sense of bit predicate:
lemma mem_iff_bit [M ⊧ₘ* 𝐈𝚺₁] {i a : M} : i ∈ a ↔ Bit i a
The following comprehension holds.
theorem finset_comprehension₁ [M ⊧ₘ* 𝐈𝚺₁]
{P : M → Prop} (hP : (Γ, 1)-Predicate P) (a : M) :
∃ s < exp a, ∀ i < a, i ∈ s ↔ P i
The basic concepts of set theory, such as union, inter, cartesian product, and mapping, etc. are defined.
Seq
iff is a mapping and its domain is for some .
def Seq [M ⊧ₘ* 𝐈𝚺₁] (s : M) : Prop := IsMapping s ∧ ∃ l, domain s = under l
Primitive Recursion
Let , be a -function. There is a -function such that:
structure Formulae (k : ℕ) where
zero : 𝚺₁-Semisentence (k + 1)
succ : 𝚺₁-Semisentence (k + 3)
structure Construction {k : ℕ} (p : Formulae k) where
zero : (Fin k → M) → M
succ : (Fin k → M) → M → M → M
zero_defined : DefinedFunction zero p.zero
succ_defined : DefinedFunction (fun v ↦ succ (v ·.succ.succ) (v 1) (v 0)) p.succ
variable {k : ℕ} {p : Formulae k} (c : Construction M p) (v : Fin k → M)
def Construction.result (u : M) : M
theorem Construction.result_zero :
c.result v 0 = c.zero v
theorem Construction.result_succ (u : M) :
c.result v (u + 1) = c.succ v u (c.result v u)
Fixpoint
Let be a predicate, which takes a class as a parameter. Then there is a -predicate such that
if satisfies following conditions:
- is -definable if is a set. i.e., a predicate is -definable.
- Monotone: and implies .
- Finite: implies the existence of a s.t. .
structure Blueprint (k : ℕ) where
core : 𝚫₁-Semisentence (k + 2)
structure Construction (φ : Blueprint k) where
Φ : (Fin k → M) → Set M → M → Prop
defined : Arith.Defined (fun v ↦ Φ (v ·.succ.succ) {x | x ∈ v 1} (v 0)) φ.core
monotone {C C' : Set M} (h : C ⊆ C') {v x} : Φ v C x → Φ v C' x
class Construction.Finite (c : Construction M φ) where
finite {C : Set M} {v x} : c.Φ v C x → ∃ m, c.Φ v {y ∈ C | y < m} x
variable {k : ℕ} {φ : Blueprint k} (c : Construction M φ) [Finite c] (v : Fin k → M)
def Construction.Fixpoint (x : M) : Prop
theorem Construction.case :
c.Fixpoint v x ↔ c.Φ v {z | c.Fixpoint v z} x
is if satisfies strong finiteness:
class Construction.StrongFinite (c : Construction M φ) where
strong_finite {C : Set M} {v x} : c.Φ v C x → c.Φ v {y ∈ C | y < x} x
Also structural induction holds.
theorem Construction.induction [c.StrongFinite]
{P : M → Prop} (hP : (Γ, 1)-Predicate P)
(H : ∀ C : Set M, (∀ x ∈ C, c.Fixpoint v x ∧ P x) → ∀ x, c.Φ v C x → P x) :
∀ x, c.Fixpoint v x → P x
Gödel's First Incompleteness Theorem
A deduction system is complete iff it can prove or refute every sentence . Otherwise, is incomplete.
def System.Complete {F S} [System F S] [LogicalConnective F] (𝓢 : S) : Prop :=
∀ f, 𝓢 ⊢! f ∨ 𝓢 ⊢! ~f
Theorem
Let be a -definable arithmetic theory, stronger than and -sound.
Representeation Theorem
Theorem: Let be a r.e. set. Then, there exists a formula such that for all .
lemma re_complete
[𝐑₀ ≼ T] [Sigma1Sound T]
{p : ℕ → Prop} (hp : RePred p) {x : ℕ} :
p x ↔ T ⊢! ↑((codeOfRePred p)/[‘↑x’] : Sentence ℒₒᵣ)
Main Theorem
Theorem: -sound and -definable first-order theory, which is stronger than , is incomplete.
-
Proof.
Define a set of formulae with one variable. is r.e. since is -definable. (one could use Craig's trick to weaken this condition to , but I will not do that here.)
By the representation theorem, there exists a formula that represents . i.e.,
Let . The next follows immediately.
Thus, as is consistent, is undecidable from . ∎
theorem goedel_first_incompleteness
(T : Theory ℒₒᵣ) [𝐑₀ ≼ T] [Sigma1Sound T] [T.Delta1Definable] :
¬System.Complete T
Gödel's Second Incompleteness Theorem
Recall that inside we can do basic set theory and primitive recursion. Many inductive notions and functions on them are defined in or using the fixpoint construction.
We work inside an arbitrary model of .
Coding of Terms and Formulae
Term
Define as follows.
is a quasi-quotation.
is (if is a finite set) and monotone. Let be a fixpoint of . It is since satisfies strong finiteness. Define the function inductively on meaning the largest bounded variable that appears in the term. Define .
Formula
Similarly, Define :
is and monotone. Let be a fixpoint of and define
The function is defined inductively on meaning the largest bounded variable that appears in the formula.
and are again since satisfies strong finiteness.
Formalized Provability
Let be -definable theory. Define :
is a shift of a formula . is a image of shift of . Take fixpoint .
Following holds for all formula (not coded one) and finite set .
- Sound:
lemma LO.Arith.Language.Theory.Provable.sound : (T.codeIn ℕ).Provable ⌜p⌝ → T ⊢! p
- D1:
theorem LO.Arith.provable_of_provable : T ⊢! p → (T.codeIn V).Provable ⌜p⌝
- D2:
- Formalized -completeness: Let be a -sentence.
theorem LO.Arith.sigma₁_complete (hσ : Hierarchy 𝚺 1 σ) : V ⊧ₘ₀ σ → T.Provableₐ (⌜σ⌝ : V)
Now assume that is a theory of arithmetic stronger than and be a theory of arithmetic stronger than . The following holds, thanks to the completeness theorem.
Second Incompleteness Theorem
Assume that is -definable and stronger than .
Fixpoint Lemma
Since the substitution is , There is a formula such that, for all formula with only one variable and ,
holds. (overline denotes the (formalized) numeral of )
Define a sentence for formula (with one variable) as follows.
Lemma:
- Proof. ∎
theorem LO.FirstOrder.Arith.diagonal (θ : Semisentence ℒₒᵣ 1) :
T ⊢!. fixpoint θ ⭤ θ/[⌜fixpoint θ⌝]
Main Theorem
Define Gödel sentence :
Lemma: Gödel sentence is undecidable, i.e., if is consistent, and if .
lemma goedel_unprovable
(T : Theory ℒₒᵣ) [𝐈𝚺₁ ≼ T] [T.Delta1Definable] [System.Consistent T] :
T ⊬ ↑𝗚
lemma not_goedel_unprovable
(T : Theory ℒₒᵣ) [𝐈𝚺₁ ≼ T] [T.Delta1Definable] [ℕ ⊧ₘ* T] :
T ⊬ ∼↑𝗚
Define formalized incompleteness sentence :
Lemma:
lemma consistent_iff_goedel
(T : Theory ℒₒᵣ) [𝐈𝚺₁ ≼ T] [T.Delta1Definable] :
T ⊢! ↑𝗖𝗼𝗻 ⭤ ↑𝗚
Theorem: cannot prove its own consistency, i.e., if is consistent. Moreover, is undecidable from if .
theorem goedel_second_incompleteness
(T : Theory ℒₒᵣ) [𝐈𝚺₁ ≼ T] [T.Delta1Definable] [System.Consistent T] :
T ⊬ ↑𝗖𝗼𝗻
theorem inconsistent_undecidable
(T : Theory ℒₒᵣ) [𝐈𝚺₁ ≼ T] [T.Delta1Definable] [ℕ ⊧ₘ* T] :
System.Undecidable T ↑𝗖𝗼𝗻