While this submission is a draft, it cannot be used by other submissions.

QSAT, quantified Boolean formulas

Lax134656.Qsat · concepts/Lax134656/Qsat.lean · lax-134656

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

    An instance is a fully quantified Boolean formula given as a structure: its elements are variables and clauses, with the positive and negative occurrences of variables in clauses as for CNF instances, a mark on the quantified variables, a mark on those quantified universally, and a binary relation ordering the variables as they appear in the quantifier prefix, outermost first. The instance is well formed when that relation is a strict linear order on the quantified variables. The matrix holds under a valuation when every clause contains a true literal on a quantified variable.

    Truth is defined as a game on positions made of the set of variables already quantified and a valuation: a position is won when every variable is quantified and the matrix holds, when the next variable of the prefix is existential and one of its two values leads to a won position, or when it is universal and both values do. An instance is a yes-instance of QSAT when it is well formed and the initial position is won; QSAT is the decision problem of the structures isomorphic to such an instance. The number of alternations is not bounded.

    Concept map
    3 concepts; 15 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.ModelTheory.Semantics
    2import Lax904597.Problems
    3import Lax485149.Problems
    4
    5/-!
    6---
    7title: QSAT, quantified Boolean formulas
    8type: definition
    9---
    10An instance is a fully quantified Boolean formula given as a structure: its
    11elements are variables and clauses, with the positive and negative
    12occurrences of variables in clauses as for CNF instances, a mark on the
    13quantified variables, a mark on those quantified universally, and a binary
    14relation ordering the variables as they appear in the quantifier prefix,
    15outermost first. The instance is well formed when that relation is a strict
    16linear order on the quantified variables. The matrix holds under a
    17valuation when every clause contains a true literal on a quantified
    18variable.
    19
    20Truth is defined as a game on positions made of the set of variables
    21already quantified and a valuation: a position is won when every variable
    22is quantified and the matrix holds, when the next variable of the prefix is
    23existential and one of its two values leads to a won position, or when it
    24is universal and both values do. An instance is a yes-instance of QSAT when
    25it is well formed and the initial position is won; QSAT is the decision
    26problem of the structures isomorphic to such an instance. The number of
    27alternations is not bounded.
    28-/
    29
    30namespace Lax134656.Qsat
    31
    32open Lax904597.Problems Lax485149.Problems
    33
    34open FirstOrder
    35
    36open FirstOrder.Language
    37
    38/-- The relation symbols of the language. -/
    39inductive qsatRel : ℕ → Type where
    40/-- `isVar x`: the element `x` is a quantified propositional variable. -/
    41 | isVar : qsatRel 1
    42/-- `allVar x`: the variable `x` is quantified universally. -/
    43 | allVar : qsatRel 1
    44/-- `prefixLt x y`: the variable `x` is quantified outside the variable
    45 `y`. -/
    46 | prefixLt : qsatRel 2
    47/-- `isClause c`: the element `c` is a clause of the matrix. -/
    48 | isClause : qsatRel 1
    49/-- `posIn c x`: the variable `x` occurs positively in the clause `c`. -/
    50 | posIn : qsatRel 2
    51/-- `negIn c x`: the variable `x` occurs negatively in the clause `c`. -/
    52 | negIn : qsatRel 2
    53 deriving DecidableEq
    54
    55/-- The relational vocabulary of fully quantified Boolean formulas: that of
    56CNF instances, together with the marks and the order describing the quantifier
    57prefix. -/
    58def qsat : FirstOrder.Language :=
    59 ⟨fun _ => Empty, qsatRel⟩
    60
    61instance instIsRelationalQsat : FirstOrder.Language.IsRelational qsat := fun _ =>
    62 (inferInstance : IsEmpty Empty)
    63
    64/-- `isVar x`: the element `x` is a quantified propositional variable. -/
    65abbrev qsIsVar : qsat.Relations 1 :=
    66 .isVar
    67
    68/-- `allVar x`: the variable `x` is quantified universally. -/
    69abbrev qsAllVar : qsat.Relations 1 :=
    70 .allVar
    71
    72/-- `prefixLt x y`: the variable `x` is quantified outside the variable
    73 `y`. -/
    74abbrev qsPrefixLt : qsat.Relations 2 :=
    75 .prefixLt
    76
    77/-- `isClause c`: the element `c` is a clause of the matrix. -/
    78abbrev qsIsClause : qsat.Relations 1 :=
    79 .isClause
    80
    81/-- `posIn c x`: the variable `x` occurs positively in the clause `c`. -/
    82abbrev qsPosIn : qsat.Relations 2 :=
    83 .posIn
    84
    85/-- `negIn c x`: the variable `x` occurs negatively in the clause `c`. -/
    86abbrev qsNegIn : qsat.Relations 2 :=
    87 .negIn
    88
    89open FirstOrder
    90
    91open Language Structure
    92
    93section Reading
    94
    95variable {A : Type} [qsat.Structure A]
    96
    97/-- The element `x` is a quantified propositional variable. -/
    98def IsQVar (x : A) : Prop := RelMap qsIsVar ![x]
    99
    100/-- The variable `x` is quantified universally. -/
    101def IsQAll (x : A) : Prop := RelMap qsAllVar ![x]
    102
    103/-- The variable `x` is quantified outside the variable `y`. -/
    104def QPrec (x y : A) : Prop := RelMap qsPrefixLt ![x, y]
    105
    106variable (A) in
    107/-- An instance is *well formed* when the quantifier prefix is a strict linear
    108order on the marked variables. Malformed instances are no-instances; the
    109condition is first-order, so the membership proof can check it. -/
    110structure QsatWf : Prop where
    111 /-- The prefix order only relates quantified variables. -/
    112 isVar_of_prec : ∀ x y : A, QPrec x y → IsQVar x ∧ IsQVar y
    113 /-- The prefix order is irreflexive. -/
    114 irrefl : ∀ x : A, ¬QPrec x x
    115 /-- The prefix order is transitive. -/
    116 trans : ∀ x y z : A, QPrec x y → QPrec y z → QPrec x z
    117 /-- The prefix order is total on the quantified variables. -/
    118 total : ∀ x y : A, IsQVar x → IsQVar y → x ≠ y → QPrec x y ∨ QPrec y x
    119
    120/-- The matrix: every clause contains a literal on a *quantified* variable that
    121the valuation `τ` makes true. Elements that are not clauses impose nothing,
    122exactly as for satisfiability; an occurrence on an element that the
    123prefix does not quantify is not a literal, so the matrix depends on `τ` only
    124through its values on the variables. -/
    125def QsatMatrix (τ : A → Prop) : Prop :=
    126 ∀ c : A, RelMap qsIsClause ![c] →
    127 ∃ x : A, IsQVar x ∧
    128 ((RelMap qsPosIn ![c, x] ∧ τ x) ∨ (RelMap qsNegIn ![c, x] ∧ ¬τ x))
    129
    130/-- Adding a variable to the set of already-quantified ones. -/
    131def qAdd (D : A → Prop) (x : A) : A → Prop := fun y => y = x ∨ D y
    132
    133/-- Giving the value `b` to the variable `x` in the valuation `τ`. -/
    134def qUpd (τ : A → Prop) (x : A) (b : Bool) : A → Prop :=
    135 fun y => (y = x ∧ b = true) ∨ (y ≠ x ∧ τ y)
    136
    137/-- The variable `x` is the one the position `D` quantifies next: it is the
    138`prefixLt`-least variable that `D` does not contain. -/
    139def QLeast (D : A → Prop) (x : A) : Prop :=
    140 IsQVar x ∧ ¬D x ∧ ∀ y : A, IsQVar y → ¬D y → ¬QPrec y x
    141
    142end Reading
    143
    144section Game
    145
    146variable {A : Type} [qsat.Structure A]
    147
    148/-- **The quantifier game**: the existential player wins the position `(D, τ)`.
    149Either every variable is already quantified and the matrix holds, or the next
    150variable is existential and one of its two values wins, or it is universal and
    151both of its values win. -/
    152inductive QsatWins : (A → Prop) → (A → Prop) → Prop
    153 /-- Every variable has been quantified: the position is won exactly when the
    154 matrix holds. -/
    155 | leaf {D τ : A → Prop} (hD : ∀ x : A, IsQVar x → D x) (hm : QsatMatrix τ) : QsatWins D τ
    156 /-- The next variable is existential: the existential player picks a value
    157 winning the rest of the game. -/
    158 | ex {D τ : A → Prop} {x : A} (hx : QLeast D x) (hq : ¬IsQAll x) (b : Bool)
    159 (h : QsatWins (qAdd D x) (qUpd τ x b)) : QsatWins D τ
    160 /-- The next variable is universal: both values must win the rest of the
    161 game. -/
    162 | all {D τ : A → Prop} {x : A} (hx : QLeast D x) (hq : IsQAll x)
    163 (h : ∀ b : Bool, QsatWins (qAdd D x) (qUpd τ x b)) : QsatWins D τ
    164
    165end Game
    166
    167section Problem
    168
    169variable {A : Type} [qsat.Structure A]
    170
    171variable (A) in
    172/-- **The yes-instances of QSAT**: a well-formed instance whose quantified
    173formula is true, i.e., whose initial position – nothing quantified yet, the
    174empty valuation – is won by the existential player. -/
    175def QsatHolds : Prop :=
    176 QsatWf A ∧ QsatWins (fun _ : A => False) (fun _ : A => False)
    177
    178end Problem
    179
    180/-- QSAT: is the fully quantified Boolean formula described by the instance
    181true? -/
    182def QSAT : DecisionProblem qsat := DecisionProblem.ofPred fun A _ => QsatHolds A
    183
    184end Lax134656.Qsat
    185

    Discussion

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

    Loading discussion…