Proof system of first-order logic #
This file formalizes a Hilbert-style proof system of first-order logic.
AxiomandProofdefine the first-order axioms and Hilbert-style proofs as inductive families.Proof Γ p(orΓ ⊢ p) whereΓis a set of formulas, says that propositionpis provable from the first-order axioms and the propositions inΓ(hypotheses).- A few tactics are provided to facilitate proof writing -- e.g.
pintroto introduce local hypothesis as a formula added toΓ,papplyto apply a theorem onto the proof goal, andprwto rewrite the equalities or iffs in the proof goal. - A lot of theorems (e.g. principle of explosion
Proof.false_elim) and metatheorems (e.g. deduction theoremProof.deduction) are proved.
Design note #
There are different ways to design a proof system for first-order logic.
- Hilbert-style systems, which promote minimality in their design, typically have a minimal set of axioms and minimal inference rules (typically, only Modus Ponens).
- Natural deduction usually has a weak notion of axioms and focuses more on inference rules. Those rules include introduction and elimination rules for each logical connectives. Some metatheorems in Hilbert-style systems, like the deduction theorem, become rules in natural deduction.
- Sequent calculus is similar to natural deduction, but has a more "bottom-up" style. In cut-free sequent calculus, a nice property, subformula property, holds, which makes it easy to do automated proof search. Gentzen's cut elimination, a standard result, ensures that any proof using cut can be transformed into a cut-free proof.
We are using Hilbert-style system because it's elegant, it can be easily applied to first-order
theories with infinite axioms (since Γ can be any set) and it's easier to do encoding for proofs
(since Γ does not change in the proof tree). Moreover, with the help of proof tactics, we are able
to write proofs in the style of natural deduction (just as in Lean).
There are formalizations of other systems in Lean, e.g. FFL(lean4-logic) formalizes Tait calculus (a variant of sequent calculus) for first-order logic, and flypitch formalizes natural deduction.
Even within Hilbert-style systems, there are different choices on selecting the axioms and inference rules. The axioms and rules we selected have the following property:
- The only inference rule is Modus Ponens (
Proof.mp). Some systems (e.g. in Mendelson's book) include a GEN rule to introduce universal quantifiers, but in our system it's a metatheorem (Proof.generalization). Also in such systems, the deduction theorem is restricted (e.g. in Mendelson's system, the deduction theorem forΓ ⊢ p ⇒ qrequires no free variable inpused by GEN rule inΓ, p ⊢ q), while ours (Proof.deduction) is not. - The logical axioms do not refer to propositional logic. Some systems (e.g. in Enderton's book) include all propositional tautologies as logical axioms.
- Equality axioms are formalized as logical axioms, not as a theory, because we want equality to be
a part of first-order logic itself. This also makes
prwtactic usable for all first-order theories. - Empty structures are admitted (i.e.
∅ ⊬ ∃ x. ⊤in general). This thanks to the "dependent type design" ofTermandFormula: to prove∃ x. ⊤as aSentence, a closed termt : L.Term 0is needed forProof.exists_intro; but in a language with no constants, no closed term exists.
References #
- FFL (lean4-logic). https://github.com/FormalizedFormalLogic/Foundation
- flypitch. https://github.com/flypitch/flypitch
- Introduction to Mathematical Logic (fourth edition), Elliott Mendelson.
- A Mathematical Introduction to Logic (second edition), Herbert B. Enderton.
First-order axioms. Note that these are logical axioms -- theory related axioms (e.g. arithmetic) should occur as hypotheses.
The axioms in our proof system include:
- 3 axioms for propositional logic,
imp_imp_self,imp_distribandimp_contra; - 3 axioms for quantifiers,
forall_elim,forall_selfandforall_imp; - 5 axioms for equality,
eq_refl,eq_symm,eq_trans,eq_congr_funcandeq_congr_rel; - the universal closure of all axioms generated by 1-3.
- imp_imp_self {L : Language} {x✝ : ℕ} {p q : L.Formula x✝} : L.Axiom (p ⇒ q ⇒ p)
- imp_distrib {L : Language} {x✝ : ℕ} {p q r : L.Formula x✝} : L.Axiom ((p ⇒ q ⇒ r) ⇒ (p ⇒ q) ⇒ p ⇒ r)
- imp_contra {L : Language} {x✝ : ℕ} {p q : L.Formula x✝} : L.Axiom ((~ p ⇒ ~ q) ⇒ q ⇒ p)
- forall_elim {L : Language} {x✝ : ℕ} {p : L.Formula (x✝ + 1)} {t : L.Term x✝} : L.Axiom (∀' p ⇒ p[↦ₛ t]ₚ)
- forall_self {L : Language} {x✝ : ℕ} {p : L.Formula x✝} : L.Axiom (p ⇒ ∀' ↑ₚp)
- forall_imp {L : Language} {x✝ : ℕ} {p q : L.Formula (x✝ + 1)} : L.Axiom (∀' (p ⇒ q) ⇒ ∀' p ⇒ ∀' q)
- eq_refl {L : Language} {x✝ : ℕ} {t : L.Term x✝} : L.Axiom (t ≐ t)
- eq_symm {L : Language} {x✝ : ℕ} {t₁ t₂ : L.Term x✝} : L.Axiom (t₁ ≐ t₂ ⇒ t₂ ≐ t₁)
- eq_trans {L : Language} {x✝ : ℕ} {t₁ t₂ t₃ : L.Term x✝} : L.Axiom (t₁ ≐ t₂ ⇒ t₂ ≐ t₃ ⇒ t₁ ≐ t₃)
- eq_congr_func {L : Language} {x✝ x✝¹ : ℕ} {v₁ v₂ : Fin x✝ → L.Term x✝¹} {f : L.Func x✝} : L.Axiom ((⋀ (i : Fin x✝), v₁ i ≐ v₂ i) ⇒ f ⬝ᶠ v₁ ≐ f ⬝ᶠ v₂)
- eq_congr_rel {L : Language} {x✝ x✝¹ : ℕ} {v₁ v₂ : Fin x✝ → L.Term x✝¹} {r : L.Rel x✝} : L.Axiom ((⋀ (i : Fin x✝), v₁ i ≐ v₂ i) ⇒ r ⬝ʳ v₁ ⇒ r ⬝ʳ v₂)
- all {L : Language} {x✝ : ℕ} {p : L.Formula (x✝ + 1)} : L.Axiom p → L.Axiom (∀' p)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Theory T₁ is a subtheory of T₂ (T₁ ⊆ᵀ T₂) if T₂ can proves all formulas in T₁. When that
is true, all theorems of T₁ are also theorems of T₂ (see Proof.cut).
This is designed as a typeclass so that, if there is an instance of T₁ ⊆ᵀ T₂, all theorems
proved for T₁ can be applied to T₂ automatically when using papply tactic.
Note: we define Subtheory for FormulaSet n in general, but the instances should always be for
Theory.
Instances
Theory T₁ is a subtheory of T₂ (T₁ ⊆ᵀ T₂) if T₂ can proves all formulas in T₁. When that
is true, all theorems of T₁ are also theorems of T₂ (see Proof.cut).
This is designed as a typeclass so that, if there is an instance of T₁ ⊆ᵀ T₂, all theorems
proved for T₁ can be applied to T₂ automatically when using papply tactic.
Note: we define Subtheory for FormulaSet n in general, but the instances should always be for
Theory.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Deduction theorem.
Proof compactness theorem.
Introduce a new hypothesis or a new variable.
Equations
- FirstOrder.Language.Proof.Tactic.tacticPintro = Lean.ParserDescr.node `FirstOrder.Language.Proof.Tactic.tacticPintro 1024 (Lean.ParserDescr.nonReservedSymbol "pintro" false)
Instances For
Repeatedly introduce new hypotheses and variables. pintros n introduces exactly n hypotheses
and variables, while pintros introduces as many as possible.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Close the proof goal using assumption. passumption n will use the n-th assumption (from right
to left, counting from 0), while passumption tries to search for such an assumption.
Equations
- One or more equations did not get rendered due to their size.
Instances For
For goal Γ ⊢ p, phave q proves Γ ⊢ q first and then proves Γ, q ⊢ p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
For goal Γ ⊢ p, psuffices q proves Γ, q ⊢ p first and then proves Γ ⊢ q.
Equations
- One or more equations did not get rendered due to their size.
Instances For
pclear n removes the n-th assumption.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Remove all assumptions except the theory (or formula set) itself.
Equations
- FirstOrder.Language.Proof.Tactic.tacticPclears = Lean.ParserDescr.node `FirstOrder.Language.Proof.Tactic.tacticPclears 1024 (Lean.ParserDescr.nonReservedSymbol "pclears" false)
Instances For
pswap n m swaps the n-th assumption and the m-th assumption.
Equations
- One or more equations did not get rendered due to their size.
Instances For
preplace n p replaces the n-th assumption with a new proposition p, and generate a new goal
to prove p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Revert an assumption through deduction theorem. prevert n reverts the n-th assumption, and
prevert reverts the 0-th assumption.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unify Γ as a subtheory of Δ and return a term of type Γ ⊆ᵀ Δ.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a proof term t of Γ ⊢ p₁ ⇒ ⋯ ⇒ pₙ ⇒ q, papply t apply it on a proof goal of Δ ⊢ ⋯
(Γ should be a subset/subtheory of Δ) with a chain Proof.mp.
papply twill applyton the current goalΔ ⊢ qand create goals for eachΔ ⊢ pᵢ.papply t at h(wherehis an identifier) will applyton the local hypothesishwith typeΔ ⊢ pₙ, replace it withΔ ⊢ qand create goals for otherΔ ⊢ pᵢ.papply t at k(wherekis an number) will applyton thek-th assumptionpₙinΔ(counting from right to left), replace it withqand create goals for otherΔ ⊢ pᵢ.
papply t with d controls the number of Proof.mp (equal to n) to be d. If with is not
presented, papply will try from n = 0 until it succeeds or exhausts all ⇒. For papply at h
or papply at k, d should be greater than or equal to 1.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the n-th assumption using Proof.mp.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Close the goal with given proof term.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If k-th assumption is p₁ ⇒ p₂ ⇒ ⋯ ⇒ pₙ ⇒ q, pspecialize k replace it with q and generate
proof goals for each pᵢ (goals for pᵢ will occur before the original goal).
pspecialize k with d controls the number of Proof.mp.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Proof by contradiction.
Equations
- FirstOrder.Language.Proof.Tactic.tacticPcontra = Lean.ParserDescr.node `FirstOrder.Language.Proof.Tactic.tacticPcontra 1024 (Lean.ParserDescr.nonReservedSymbol "pcontra" false)
Instances For
Close the proof goal t ≐ t or p ⇔ p using reflexivity.
Equations
- FirstOrder.Language.Proof.Tactic.tacticPrefl = Lean.ParserDescr.node `FirstOrder.Language.Proof.Tactic.tacticPrefl 1024 (Lean.ParserDescr.nonReservedSymbol "prefl" false)
Instances For
If the proof goal is t₁ ≐ t₂ or p ⇔ q, replace it with t₂ ≐ t₁ or q ⇔ p using symmetry.
Equations
- FirstOrder.Language.Proof.Tactic.tacticPsymm = Lean.ParserDescr.node `FirstOrder.Language.Proof.Tactic.tacticPsymm 1024 (Lean.ParserDescr.nonReservedSymbol "psymm" false)
Instances For
If the proof goal is t₁ ≐ t₂ (or p ⇔ q), replace it with two goals, t₁ ≐ t and t ≐ t₂ (or
p ⇔ r and r ⇔ q) using transitivity.
A meta variable is generated for t or r if it is not given.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
prw [e₁, ⋯, eₙ] rewrites a proof goal Γ ⊢ p using given rules. A rule e can be either proof
term or a number (refer to an assumption in Γ), having type Δ ⊢ t₁ ≐ t₂ or Δ ⊢ q ⇔ r (and
Δ should be a subset/subtheory of Γ). ←e reverse the direction of rewrite.
prw [e₁, ⋯, eₙ]will rewrite on the current goal.prw [e₁, ⋯, eₙ] at h(wherehis an identifier) will rewrite at the local hypothesish.prw [e₁, ⋯, eₙ] at k(wherekis a number) will rewrite on thek-th assumption inΓ.
prw_debug runs prw tactic while printing debug information.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A theory (formula set in general) is consistent if it does not prove ⊥.
Equations
Instances For
A theory (formula set in general) is complete if for each p it either proves p or proves ~ p.
Note: we do not assume the theory to be consistent. Under this definition, inconsistent theories are also complete.
Equations
- FirstOrder.Language.Complete Γ = ∀ (p : L.Formula n), Γ ⊢ p ∨ Γ ⊢ ~ p