First-order logic on colored graphs

Lax185574.FirstOrderLogic · concepts/Lax185574/FirstOrderLogic.lean · lax-185574

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    First-order formulas speak about the vertices of a graph. Their atoms say that two vertices are adjacent, that they are equal, or that a vertex has a color. Formulas are closed under negation, conjunction and existential quantification over vertices. The other connectives and the universal quantifier are expressed by these as usual.

    A formula has free variables x₀, …, x_{n−1} for some n, and its quantifier ∃ binds the next variable xₙ. A sentence has no free variables and no colors, and G⊨φG ⊨ φ says that the sentence φ holds in the graph G.

    Concept map
    2 concepts
    100%
    DefinitionThis conceptRelated conceptA → B: B builds on ADescendants are omitted for concepts with more than 10 descendants.

    Lean source view on GitHub

    1import Lax185574.Graphs
    2import Mathlib.Data.Fin.Tuple.Basic
    3
    4/-!
    5---
    6title: First-order logic on colored graphs
    7type: definition
    8---
    9First-order formulas speak about the vertices of a graph. Their atoms
    10say that two vertices are adjacent, that they are equal, or that a
    11vertex has a color. Formulas are closed under negation, conjunction and
    12existential quantification over vertices. The other connectives and the
    13universal quantifier are expressed by these as usual.
    14
    15A formula has free variables x₀, …, x_{n−1} for some n, and its
    16quantifier ∃ binds the next variable xₙ. A *sentence* has no free
    17variables and no colors, and `G ⊨ φ` says that the sentence φ holds in
    18the graph G.
    19
    20# Formalization notes
    21
    22The colors are the elements of a type `K`. Sentences use the empty type
    23of colors. A coloring of a graph assigns to each color the set of
    24vertices that have it, and the sets of different colors may overlap.
    25
    26The type of a formula records how many free variables it may use, so a
    27formula cannot refer to a variable that is not bound or assigned.
    28Variables are numbered by the order in which they are introduced (de
    29Bruijn levels), so a variable keeps its number under a quantifier, and
    30`Fin.snoc a v` extends the assignment `a` of x₀, …, x_{n−1} by the vertex
    31`v` for xₙ.
    32-/
    33
    34namespace Lax185574.FirstOrderLogic
    35
    36open Lax185574.Graphs
    37
    38/-- First-order formulas on graphs with colors from `K`, whose free
    39variables are among `x₀, …, x_{n-1}`. -/
    40inductive Formula (K : Type) : ℕ → Type
    41 /-- `xᵢ` and `xⱼ` are adjacent. -/
    42 | adj {n : ℕ} (i j : Fin n) : Formula K n
    43 /-- `xᵢ` and `xⱼ` are equal. -/
    44 | eq {n : ℕ} (i j : Fin n) : Formula K n
    45 /-- Negation. -/
    46 | not {n : ℕ} (φ : Formula K n) : Formula K n
    47 /-- Conjunction. -/
    48 | and {n : ℕ} (φ ψ : Formula K n) : Formula K n
    49 /-- `∃ xₙ φ`: some vertex can be assigned to `xₙ` so that `φ` holds. -/
    50 | ex {n : ℕ} (φ : Formula K (n + 1)) : Formula K n
    51 /-- `xᵢ` has the color `c`. -/
    52 | color {n : ℕ} (c : K) (i : Fin n) : Formula K n
    53
    54/-- The formula `φ` holds in the graph `G` with the coloring `col`, when
    55the free variable `xᵢ` is assigned the vertex `a i`. -/
    56def Formula.Holds {K : Type} (G : Graph) (col : K → Set (Fin G.n)) :
    57 {n : ℕ} → Formula K n → (Fin n → Fin G.n) → Prop
    58 | _, .adj i j, a => G.Adj (a i) (a j)
    59 | _, .eq i j, a => a i = a j
    60 | _, .not φ, a => ¬ φ.Holds G col a
    61 | _, .and φ ψ, a => φ.Holds G col a ∧ ψ.Holds G col a
    62 | _, .ex φ, a => ∃ v : Fin G.n, φ.Holds G col (Fin.snoc a v)
    63 | _, .color c i, a => a i ∈ col c
    64
    65/-- A sentence: a formula without colors and without free variables. -/
    66abbrev Sentence : Type := Formula Empty 0
    67
    68/-- The sentence `φ` holds in the graph `G`. -/
    69def Models (G : Graph) (φ : Sentence) : Prop :=
    70 φ.Holds G Empty.elim Fin.elim0
    71
    72@[inherit_doc] scoped infix:50 " ⊨ " => Models
    73
    74end Lax185574.FirstOrderLogic
    75
    Formalization notes

    The colors are the elements of a type KK. Sentences use the empty type of colors. A coloring of a graph assigns to each color the set of vertices that have it, and the sets of different colors may overlap.

    The type of a formula records how many free variables it may use, so a formula cannot refer to a variable that is not bound or assigned. Variables are numbered by the order in which they are introduced (de Bruijn levels), so a variable keeps its number under a quantifier, and Fin.snocavFin.snoc a v extends the assignment aa of x₀, …, x_{n−1} by the vertex vv for xₙ.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…