Documentation

CslibFrontier.Logics.SecondOrder.WordMSO.Basic

Monadic second-order logic over words #

Monadic second-order logic (MSO) over finite words with alphabet α Libkin, Section 7.4, Thomas, Section 3. A word w of length ℓ is the structure with universe the positions Fin ℓ, their natural order <, and for each letter a the unary predicate P_a = {i | w i = a}. Formulas have first-order variables ranging over positions and monadic second-order (set) variables ranging over sets of positions, with atoms P_a(x), x < y and x ∈ X, the connectives ⊥ and →, and existential quantifiers over both sorts.

Variables are de Bruijn-style: Formula α m n has m free first-order and n free set variables, indexed by Fin m and Fin n. As for Mathlib's FirstOrder.Language.BoundedFormula, a quantifier binds the last index (Fin.last), so an assignment is extended with Fin.snoc. A sentence is a formula without free variables, and defines the language of the words whose structure satisfies it. The empty word is the empty structure, in which every existential quantifier is false and every universal quantifier is true; some sources restrict to nonempty words instead.

Unlike the existential second-order sentences of Cslib.Logic.ESO (one block of existential relation quantifiers over a first-order matrix), MSO allows arbitrary nesting and alternation of set quantifiers, restricted to unary relations.

Main definitions #

Main results #

References #

inductive Cslib.Logic.WordMSO.Formula (α : Type u) :
ℕ → ℕ → Type u

Formulas of monadic second-order logic over words with alphabet α, with m free first-order (position) variables and n free monadic second-order (set) variables. Quantifiers bind the last variable of their sort.

  • letter {α : Type u} {m n : ℕ} (a : α) (x : Fin m) : Formula α m n

    P_a(x): position x carries the letter a.

  • lt {α : Type u} {m n : ℕ} (x y : Fin m) : Formula α m n

    x < y in the order of positions.

  • mem {α : Type u} {m n : ℕ} (x : Fin m) (X : Fin n) : Formula α m n

    x ∈ X: position x belongs to the set X.

  • falsum {α : Type u} {m n : ℕ} : Formula α m n

    Falsity.

  • imp {α : Type u} {m n : ℕ} (φ ψ : Formula α m n) : Formula α m n

    Implication.

  • ex {α : Type u} {m n : ℕ} (φ : Formula α (m + 1) n) : Formula α m n

    Existential quantification over positions, binding first-order variable Fin.last m.

  • exSet {α : Type u} {m n : ℕ} (φ : Formula α m (n + 1)) : Formula α m n

    Existential quantification over sets of positions, binding set variable Fin.last n.

def Cslib.Logic.WordMSO.Formula.Realize {α : Type u} {ℓ : ℕ} (w : Fin ℓ → α) {m n : ℕ} :
Formula α m n → (Fin m → Fin ℓ) → (Fin n → Set (Fin ℓ)) → Prop

Satisfaction of a formula in the word structure with positions Fin ℓ and letters w, under the assignment v of positions to the first-order variables and V of sets of positions to the set variables.

def Cslib.Logic.WordMSO.Formula.not {α : Type u} {m n : ℕ} (φ : Formula α m n) :
Formula α m n

Negation.

def Cslib.Logic.WordMSO.Formula.top {α : Type u} {m n : ℕ} :
Formula α m n

Truth.

def Cslib.Logic.WordMSO.Formula.and {α : Type u} {m n : ℕ} (φ ψ : Formula α m n) :
Formula α m n

Conjunction.

def Cslib.Logic.WordMSO.Formula.or {α : Type u} {m n : ℕ} (φ ψ : Formula α m n) :
Formula α m n

Disjunction.

def Cslib.Logic.WordMSO.Formula.all {α : Type u} {m n : ℕ} (φ : Formula α (m + 1) n) :
Formula α m n

Universal quantification over positions.

def Cslib.Logic.WordMSO.Formula.allSet {α : Type u} {m n : ℕ} (φ : Formula α m (n + 1)) :
Formula α m n

Universal quantification over sets of positions.

def Cslib.Logic.WordMSO.Formula.eq {α : Type u} {m n : ℕ} (x y : Fin m) :
Formula α m n

Equality of positions, defined from the order.

noncomputable def Cslib.Logic.WordMSO.Formula.iInf {α : Type u} {m n : ℕ} {ι : Type u_1} (s : Finset ι) (φ : ι → Formula α m n) :
Formula α m n

The conjunction of the formulas φ i for i ∈ s.

noncomputable def Cslib.Logic.WordMSO.Formula.iSup {α : Type u} {m n : ℕ} {ι : Type u_1} (s : Finset ι) (φ : ι → Formula α m n) :
Formula α m n

The disjunction of the formulas φ i for i ∈ s.

def Cslib.Logic.WordMSO.Formula.first {α : Type u} {m n : ℕ} (x : Fin m) :
Formula α m n

x is the first position: no position is below it.

def Cslib.Logic.WordMSO.Formula.last {α : Type u} {m n : ℕ} (x : Fin m) :
Formula α m n

x is the last position: no position is above it.

def Cslib.Logic.WordMSO.Formula.succ {α : Type u} {m n : ℕ} (x y : Fin m) :
Formula α m n

y is the successor of x: x < y and no position lies strictly between them.

def Cslib.Logic.WordMSO.Formula.IsFO {α : Type u} {m n : ℕ} :
Formula α m n → Prop

The first-order fragment: formulas without set quantifiers.

@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_letter {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (a : α) (x : Fin m) :
Realize w (letter a x) v V ↔ w (v x) = a
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_lt {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x y : Fin m) :
Realize w (lt x y) v V ↔ v x < v y
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_mem {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x : Fin m) (X : Fin n) :
Realize w (mem x X) v V ↔ v x ∈ V X
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_falsum {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_imp {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ ψ : Formula α m n} :
Realize w (φ.imp ψ) v V ↔ Realize w φ v V → Realize w ψ v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_ex {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ : Formula α (m + 1) n} :
Realize w φ.ex v V ↔ ∃ (i : Fin ℓ), Realize w φ (Fin.snoc v i) V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_exSet {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ : Formula α m (n + 1)} :
Realize w φ.exSet v V ↔ ∃ (S : Set (Fin ℓ)), Realize w φ v (Fin.snoc V S)
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_not {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ : Formula α m n} :
Realize w φ.not v V ↔ ¬Realize w φ v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_top {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} :
Realize w top v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_and {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ ψ : Formula α m n} :
Realize w (φ.and ψ) v V ↔ Realize w φ v V ∧ Realize w ψ v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_or {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ ψ : Formula α m n} :
Realize w (φ.or ψ) v V ↔ Realize w φ v V ∨ Realize w ψ v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_all {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ : Formula α (m + 1) n} :
Realize w φ.all v V ↔ ∀ (i : Fin ℓ), Realize w φ (Fin.snoc v i) V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_allSet {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {φ : Formula α m (n + 1)} :
Realize w φ.allSet v V ↔ ∀ (S : Set (Fin ℓ)), Realize w φ v (Fin.snoc V S)
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_eq {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x y : Fin m) :
Realize w (eq x y) v V ↔ v x = v y
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_iInf {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {ι : Type u_1} (s : Finset ι) (φ : ι → Formula α m n) :
Realize w (iInf s φ) v V ↔ ∀ i ∈ s, Realize w (φ i) v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_iSup {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} {ι : Type u_1} (s : Finset ι) (φ : ι → Formula α m n) :
Realize w (iSup s φ) v V ↔ ∃ i ∈ s, Realize w (φ i) v V
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_first {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x : Fin m) :
Realize w (first x) v V ↔ ↑(v x) = 0
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_last {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x : Fin m) :
Realize w (last x) v V ↔ ↑(v x) + 1 = ℓ
@[simp]
theorem Cslib.Logic.WordMSO.Formula.realize_succ {α : Type u} {m n ℓ : ℕ} {w : Fin ℓ → α} {v : Fin m → Fin ℓ} {V : Fin n → Set (Fin ℓ)} (x y : Fin m) :
Realize w (succ x y) v V ↔ ↑(v y) = ↑(v x) + 1
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_letter {α : Type u} {m n : ℕ} (a : α) (x : Fin m) :
(letter a x).IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_lt {α : Type u} {m n : ℕ} (x y : Fin m) :
(lt x y).IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_mem {α : Type u} {m n : ℕ} (x : Fin m) (X : Fin n) :
(mem x X).IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_imp {α : Type u} {m n : ℕ} {φ ψ : Formula α m n} :
(φ.imp ψ).IsFO ↔ φ.IsFO ∧ ψ.IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_ex {α : Type u} {m n : ℕ} {φ : Formula α (m + 1) n} :
φ.ex.IsFO ↔ φ.IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.not_isFO_exSet {α : Type u} {m n : ℕ} (φ : Formula α m (n + 1)) :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_not {α : Type u} {m n : ℕ} {φ : Formula α m n} :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_and {α : Type u} {m n : ℕ} {φ ψ : Formula α m n} :
(φ.and ψ).IsFO ↔ φ.IsFO ∧ ψ.IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_or {α : Type u} {m n : ℕ} {φ ψ : Formula α m n} :
(φ.or ψ).IsFO ↔ φ.IsFO ∧ ψ.IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_all {α : Type u} {m n : ℕ} {φ : Formula α (m + 1) n} :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_eq {α : Type u} {m n : ℕ} (x y : Fin m) :
(eq x y).IsFO
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_first {α : Type u} {m n : ℕ} (x : Fin m) :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_last {α : Type u} {m n : ℕ} (x : Fin m) :
@[simp]
theorem Cslib.Logic.WordMSO.Formula.isFO_succ {α : Type u} {m n : ℕ} (x y : Fin m) :
(succ x y).IsFO
@[reducible, inline]

An MSO sentence over the alphabet α: a formula without free variables.

The language defined by a sentence: the words whose word structure satisfies it.

A language is MSO-definable when it is the language of some MSO sentence.

A language is first-order definable (in FO[<] with letter predicates) when it is the language of some sentence without set quantifiers.

First-order definable languages are MSO-definable.