First-order logic over a relational vocabulary
Lax512892.FirstOrder · concepts/Lax512892/FirstOrder.lean · lax-512892
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
First-order terms are variables or constants. Formulas are relation atoms, equalities, negations, disjunctions, and existential quantifications. The satisfaction relation gives these constructors their usual semantics, and the quantifier rank is the greatest nesting depth of quantifiers.
Concept map
Lean source view on GitHub
| 1 | import Lax512892.RelationalStructures |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: First-order logic over a relational vocabulary |
| 6 | type: definition |
| 7 | --- |
| 8 | First-order terms are variables or constants. Formulas are relation atoms, |
| 9 | equalities, negations, disjunctions, and existential quantifications. The |
| 10 | satisfaction relation gives these constructors their usual semantics, and the |
| 11 | quantifier rank is the greatest nesting depth of quantifiers. |
| 12 | |
| 13 | # Formalization notes |
| 14 | |
| 15 | `Formula σ k` has exactly `k` available free variables. Variables are finite |
| 16 | levels: an existential quantifier adds the new last variable, and satisfaction |
| 17 | extends an environment with `Fin.snoc`. Consequently a sentence has type |
| 18 | `Formula σ 0`; closedness is enforced by the type rather than checked by a |
| 19 | separate predicate. Conjunction and universal quantification are definable from |
| 20 | the chosen constructors and do not need additional semantic cases. |
| 21 | -/ |
| 22 | |
| 23 | namespace Lax512892.FirstOrder |
| 24 | |
| 25 | open Lax512892.RelationalStructures |
| 26 | |
| 27 | /-- Terms over `σ` with `k` available variables. -/ |
| 28 | inductive Term (σ : Vocabulary) (k : ℕ) : Type |
| 29 | /-- A variable. -/ |
| 30 | | var (i : Fin k) |
| 31 | /-- A constant of the vocabulary. -/ |
| 32 | | const (c : σ.Constant) |
| 33 | |
| 34 | /-- First-order formulas over `σ` with `k` available free variables. -/ |
| 35 | inductive Formula (σ : Vocabulary) : ℕ → Type |
| 36 | /-- A relation atom. -/ |
| 37 | | rel {k : ℕ} (R : σ.Relation) (args : Fin (σ.arity R) → Term σ k) : Formula σ k |
| 38 | /-- Equality of terms. -/ |
| 39 | | eq {k : ℕ} (left right : Term σ k) : Formula σ k |
| 40 | /-- Negation. -/ |
| 41 | | not {k : ℕ} (φ : Formula σ k) : Formula σ k |
| 42 | /-- Disjunction. -/ |
| 43 | | or {k : ℕ} (φ ψ : Formula σ k) : Formula σ k |
| 44 | /-- Existential quantification, binding the new last variable. -/ |
| 45 | | ex {k : ℕ} (φ : Formula σ (k + 1)) : Formula σ k |
| 46 | |
| 47 | namespace Term |
| 48 | |
| 49 | /-- Interpretation of a term in a structure under an environment. -/ |
| 50 | def eval {σ : Vocabulary} {M : Type*} {k : ℕ} (A : Structure σ M) |
| 51 | (env : Fin k → M) : Term σ k → M |
| 52 | | .var i => env i |
| 53 | | .const c => A.constant c |
| 54 | |
| 55 | end Term |
| 56 | |
| 57 | namespace Formula |
| 58 | |
| 59 | /-- Satisfaction of a formula in a structure under an environment for its free |
| 60 | variables. -/ |
| 61 | def Sat {σ : Vocabulary} {M : Type*} (A : Structure σ M) : |
| 62 | {k : ℕ} → Formula σ k → (Fin k → M) → Prop |
| 63 | | _, .rel R args, env => A.relation R (fun i => (args i).eval A env) |
| 64 | | _, .eq left right, env => left.eval A env = right.eval A env |
| 65 | | _, .not φ, env => ¬ Sat A φ env |
| 66 | | _, .or φ ψ, env => Sat A φ env ∨ Sat A ψ env |
| 67 | | _, .ex φ, env => ∃ x : M, Sat A φ (Fin.snoc env x) |
| 68 | |
| 69 | /-- The quantifier rank of a formula. -/ |
| 70 | def quantifierRank {σ : Vocabulary} : {k : ℕ} → Formula σ k → ℕ |
| 71 | | _, .rel _ _ => 0 |
| 72 | | _, .eq _ _ => 0 |
| 73 | | _, .not φ => quantifierRank φ |
| 74 | | _, .or φ ψ => max (quantifierRank φ) (quantifierRank ψ) |
| 75 | | _, .ex φ => quantifierRank φ + 1 |
| 76 | |
| 77 | end Formula |
| 78 | |
| 79 | end Lax512892.FirstOrder |
| 80 |
Formalization notes
has exactly available free variables. Variables are finite levels: an existential quantifier adds the new last variable, and satisfaction extends an environment with . Consequently a sentence has type ; closedness is enforced by the type rather than checked by a separate predicate. Conjunction and universal quantification are definable from the chosen constructors and do not need additional semantic cases.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments