Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax11.Mso

Monadic second-order logic on graphs

concepts/Lax11/Mso.lean · lax-11

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.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Definition

    A formula of monadic second-order logic over graphs is built from three atoms — two vertices are adjacent, two vertices are equal, a vertex belongs to a set — by negation, conjunction, and quantification over vertices and over sets of vertices. A formula holds in a graph under an assignment of vertices to its free vertex variables and of sets of vertices to its free set variables, by the usual reading of the connectives and the quantifiers. The quantifier rank of a formula is the nesting depth of its quantifiers, counting both kinds.

    Lean source view on GitHub

    1import Mathlib.Combinatorics.SimpleGraph.Basic
    2import Mathlib.Data.Fin.Tuple.Basic
    3
    4/-!
    5---
    6title: Monadic second-order logic on graphs
    7type: definition
    8---
    9A formula of monadic second-order logic over graphs is built from three
    10atoms — two vertices are adjacent, two vertices are equal, a vertex
    11belongs to a set — by negation, conjunction, and quantification over
    12vertices and over sets of vertices. A formula holds in a graph under an
    13assignment of vertices to its free vertex variables and of sets of
    14vertices to its free set variables, by the usual reading of the
    15connectives and the quantifiers. The quantifier rank of a formula is
    16the nesting depth of its quantifiers, counting both kinds.
    17
    18# Formalization notes
    19
    20Free variables are counted rather than named: `MSO r s` is the type of
    21formulas with `r` free vertex variables and `s` free set variables, and
    22a quantifier turns a formula with one more free variable of its kind
    23into a formula with one fewer. Satisfaction is therefore a total
    24function of a formula and two environments, `Fin r → Fin n` and
    25`Fin s → Set (Fin n)`, one entry per free variable: there is no partial
    26valuation, no default value for an unassigned variable, and no
    27well-formedness side condition. A sentence is a formula of `MSO 0 0`,
    28so being closed is a property of the type rather than a predicate to
    29check. The price is that variables are de Bruijn positions rather than
    30names; the alternative, named variables, needs capture-avoiding
    31substitution *inside the trusted definition*, which is a considerably
    32worse object to audit than an index.
    33
    34Variables are levels, not indices: a quantifier extends the environment
    35at its *last* position (`Fin.snoc`), so the outermost bound variable of
    36a formula is `0` and the innermost is the last. Nothing in the
    37definition shifts an index.
    38
    39Only negation, conjunction and existential quantification are
    40constructors. Disjunction, implication and universal quantification are
    41the usual abbreviations, written out where they are used: each of them
    42as a constructor would add a case to the definition of satisfaction and
    43buy nothing that is not already there.
    44
    45The logic is monadic second-order logic in its MSO₁ form —
    46quantification over vertices and over *sets of vertices*, with
    47adjacency, equality and membership as the atoms. Sets of edges are not
    48quantified over. This is not a step on the way to a fuller version that
    49was left unfinished: MSO₁ and MSO₂, the logic that also quantifies over
    50edges and sets of edges, are matched to different width measures. MSO₂
    51model checking is tractable on classes of bounded treewidth and is *not*
    52tractable on classes of bounded cliquewidth unless the standard
    53complexity assumptions fail, so a development that proved the MSO₁
    54statement for cliquewidth and then claimed MSO₂ "by the same argument"
    55would be claiming something false. MSO₂ needs its own encoding — the
    56incidence graph, or edge-set variables in the type algebra — and is
    57deferred as one unit, logic and width measure together.
    58-/
    59
    60namespace Lax11.Mso
    61
    62/-- Formulas of monadic second-order logic over the adjacency
    63signature, with `r` free vertex variables and `s` free set variables.
    64Vertex variables are `Fin r`, set variables are `Fin s`, and a
    65quantifier binds the *new last* index. -/
    66inductive MSO : ℕ → ℕ → Type
    67 /-- The vertices `i` and `j` are adjacent. -/
    68 | adj {r s : ℕ} (i j : Fin r) : MSO r s
    69 /-- The vertices `i` and `j` are equal. -/
    70 | eq {r s : ℕ} (i j : Fin r) : MSO r s
    71 /-- The vertex `i` belongs to the set `X`. -/
    72 | mem {r s : ℕ} (i : Fin r) (X : Fin s) : MSO r s
    73 /-- Negation. -/
    74 | not {r s : ℕ} (φ : MSO r s) : MSO r s
    75 /-- Conjunction. -/
    76 | and {r s : ℕ} (φ ψ : MSO r s) : MSO r s
    77 /-- There is a vertex satisfying `φ`, bound at the last index. -/
    78 | exV {r s : ℕ} (φ : MSO (r + 1) s) : MSO r s
    79 /-- There is a set of vertices satisfying `φ`, bound at the last
    80 index. -/
    81 | exS {r s : ℕ} (φ : MSO r (s + 1)) : MSO r s
    82
    83/-- The quantifier rank: the nesting depth of quantifiers, counting
    84both kinds. -/
    85def rank : {r s : ℕ} → MSO r s → ℕ
    86 | _, _, .adj _ _ => 0
    87 | _, _, .eq _ _ => 0
    88 | _, _, .mem _ _ => 0
    89 | _, _, .not φ => rank φ
    90 | _, _, .and φ ψ => max (rank φ) (rank ψ)
    91 | _, _, .exV φ => rank φ + 1
    92 | _, _, .exS φ => rank φ + 1
    93
    94variable {n : ℕ}
    95
    96/-- Satisfaction of a formula in the graph `G`, under a vertex
    97environment `m` and a set environment `A`. -/
    98def Sat (G : SimpleGraph (Fin n)) :
    99 {r s : ℕ} → (Fin r → Fin n) → (Fin s → Set (Fin n)) → MSO r s → Prop
    100 | _, _, m, _, .adj i j => G.Adj (m i) (m j)
    101 | _, _, m, _, .eq i j => m i = m j
    102 | _, _, m, A, .mem i X => m i ∈ A X
    103 | _, _, m, A, .not φ => ¬ Sat G m A φ
    104 | _, _, m, A, .and φ ψ => Sat G m A φ ∧ Sat G m A ψ
    105 | _, _, m, A, .exV φ => ∃ v : Fin n, Sat G (Fin.snoc m v) A φ
    106 | _, _, m, A, .exS φ => ∃ S : Set (Fin n), Sat G m (Fin.snoc A S) φ
    107
    108end Lax11.Mso
    109

    Formalization notes

    Free variables are counted rather than named: MSOrsMSO r s is the type of formulas with rr free vertex variables and ss free set variables, and a quantifier turns a formula with one more free variable of its kind into a formula with one fewer. Satisfaction is therefore a total function of a formula and two environments, FinrFinnFin r → Fin n and FinsSet(Finn)Fin s → Set (Fin n), one entry per free variable: there is no partial valuation, no default value for an unassigned variable, and no well-formedness side condition. A sentence is a formula of MSO00MSO 0 0, so being closed is a property of the type rather than a predicate to check. The price is that variables are de Bruijn positions rather than names; the alternative, named variables, needs capture-avoiding substitution inside the trusted definition, which is a considerably worse object to audit than an index.

    Variables are levels, not indices: a quantifier extends the environment at its last position (Fin.snocFin.snoc), so the outermost bound variable of a formula is 00 and the innermost is the last. Nothing in the definition shifts an index.

    Only negation, conjunction and existential quantification are constructors. Disjunction, implication and universal quantification are the usual abbreviations, written out where they are used: each of them as a constructor would add a case to the definition of satisfaction and buy nothing that is not already there.

    The logic is monadic second-order logic in its MSO₁ form — quantification over vertices and over sets of vertices, with adjacency, equality and membership as the atoms. Sets of edges are not quantified over. This is not a step on the way to a fuller version that was left unfinished: MSO₁ and MSO₂, the logic that also quantifies over edges and sets of edges, are matched to different width measures. MSO₂ model checking is tractable on classes of bounded treewidth and is not tractable on classes of bounded cliquewidth unless the standard complexity assumptions fail, so a development that proved the MSO₁ statement for cliquewidth and then claimed MSO₂ "by the same argument" would be claiming something false. MSO₂ needs its own encoding — the incidence graph, or edge-set variables in the type algebra — and is deferred as one unit, logic and width measure together.

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…