Reasoning with Quantified Boolean Formulas Martina Seidl Institute for Formal Models and Verification Johannes Kepler University Linz 1
What are QBF? Quantified Boolean formulas (QBF) are formulas of propositional logic + quantifiers Examples: (x y) ( x y) (propositional logic) x y(x y) ( x y) Is there a value for x such that for all values of y the formula is true? y x(x y) ( x y) For all values of y, is there a value for x such that the formula is true? 2
SAT vs. QSAT aka NP vs. PSPACE SAT φ(x 1, x 2, x 3 ) QBF x 1 x 2 x 3 φ(x 1, x 2, x 3 ) Is there a satisfying assignment? Is there a satisfying assignment tree? 3
The Two Player Game Interpretation of QSAT Interpretation of QSAT as two player game for a QBF x 1 a 1 x 2 a 2 x n a n ψ: Player A (existential player) tries to satisfy the formula by assigning existential variables Player B (universal player) tries to falsify the formula by assigning universal variables Player A and Player B make alternately an assignment of the variables in the outermost quantifier block Player A wins: formula is satisfiable, i.e., there is a strategy for assigning the existential variables such that the formula is always satisfied Player B wins: formula is unsatisfiable 4
Promises of QBF QSAT is the prototypical problem for PSPACE. QBFs are suitable as host language for the encoding of many application problems like verification artificial intelligence knowledge representation game solving In general, QBF allow more succinct encodings then SAT 5
Application of a QBF Solver QBF Solver returns 1. yes/no 2. witnesses 6
The Language of QBF The language of quantified Boolean formulas L P over a set of propositional variables P is the smallest set such that if v P {, } then v L P if φ L P then φ L P if φ and ψ L P then φ ψ L P if φ and ψ L P then φ ψ L P if φ L P then vφ L P if φ L P then vφ L P (variables, truth constants) (negation) (conjunction) (disjunction) (existential quantifier) (universal quantifier) 7
Some Notes on Variables and Truth Constants stands for top always true empty conjunction stands for bottom always false empty disjunction literal: variable or negation of a variable examples: l 1 = v, l 2 = w var(l) = v if l = v or l = v complement of literal l: l var(φ): set of variables occurring in QBF φ 8
Some QBF Terminology Example Let Qvψ with Q {, } be a subformula in a QBF φ. Then ψ is the scope of v Q is the quantifier binding of v quant(v) = Q free variable w in φ: w has no quantifier binding in φ bound variable w in QBF φ: w has quantifier binding in φ closed QBF: no free variables bound var a {}}{ a free variable closed QBF {}}{ bound vars y, z scope of y, z {}}{{}}{ y z ((y z) ( y z))) {}}{ (a x }{{} scope of a 9
Prenex Conjunctive Normal Form (PCNF) A QBF φ is in prenex conjunctive normal form iff φ is in prenex normal form φ = Q 1 v 1... Q n v n ψ matrix ψ is in conjunctive normal form, i.e., ψ = C 1 C n where C i are clauses, i.e., disjunctions of literals. Example x y((x y) ( x y)) }{{}}{{} prefix matrix in CNF 10
Some Words on Notation If convenient, we write a conjunction of clauses as a set, i.e., a clause as a set of literals, i.e., C 1... C n = {C 1,..., C n } l 1... l k = {l 1,..., l k } var(φ) for the variables occurring in φ var(l) for the variable of a literal, i.e., Example var(l) = x iff l = x or l = x x y((x y) ( x y)) x y{{x, y}, { x y}} }{{}}{{}}{{}}{{} prefix matrix in CNF prefix matrix in CNF 11
Semantics of QBFs A valuation function I: L P {T, F} for closed QBFs is defined as follows: I( ) = T ; I( ) = F I( ψ) = T iff I(ψ) = F I(φ ψ) = T iff I(φ) = T or I(ψ) = T I(φ ψ) = T iff I(φ) = T and I(ψ) = T I( vψ) = T iff I(ψ[ /v]) = T and I(ψ[ /v]) = T I( vψ) = T iff I(ψ[ /v]) = T or I(ψ[ /v]) = T Note: For QBFs with free variable an additional valuation function v : P {T, F} is needed. 12
Boolean s p l i t (QBF φ ) switch (φ) case : r e t u r n true ; case : r e t u r n false ; case ψ : r e t u r n ( not s p l i t (ψ ) ) ; case ψ ψ : r e t u r n s p l i t (ψ ) && s p l i t (ψ ) ; case ψ ψ : r e t u r n s p l i t (ψ ) s p l i t (ψ ) ; case QXψ : s e l e c t x X ; X = X\{x} ; i f ( Q == ) r e t u r n ( s p l i t ( QX ψ[x/ ] ) && s p l i t ( QX ψ[x/ ] ) ) ; else r e t u r n ( s p l i t ( QX ψ[x/ ] ) s p l i t ( QX ψ[x/ ] ) ) ; 13
Some Simplifications The following rewritings are equivalence preserving: 1. ; ; 2. φ φ; φ ; φ ; φ φ; 3. (Qx φ) φ, Q {, }, x does not occur in φ; Example ab x c yz d{{a, b, c}, {a, b, }, {c, y, d, }, {x, y, }, {x, c, d, }} abc y d{{a, b, c}, {a, b}, {c, y, d}} 14
Boolean splitcnf ( P r e f i x P, matrix ψ ) i f (ψ == ) : r e t u r n true ; i f ( ψ ) : r e t u r n false ; P = QXP,x X, X = X\{x} ; i f ( Q == ) r e t u r n ( splitcnf ( QX P, ψ ) && splitcnf ( QX P, ψ ) ) ; else r e t u r n ( splitcnf ( QX P, ψ ) splitcnf ( QX P, ψ ) ) ; where ψ : take clauses of ψ, delete clauses with x, delete x ψ : take clauses of ψ, delete clauses with x, delete x 15
Unit Clauses A clause C is called unit in a formula φ iff Definition of Unit Literal Elimination C contains exactly one existential literal the universal literals of C are to the right of the existential literal in the prefix The existential literal in the unit clause is called unit literal. Example ab x c y d{{a, b, c, x}, {a, b}, {c, y, d}, {x, y}, {x, c, d}, {y}} Unit literals: x, y 16
Unit Literal Elimination Definition of Unit Literal Let φ be a QBF with unit literal l and let ψ be a QBF obtained from φ by removing all clauses containing l removing all occurrences of l Then φ ψ Example ab x c y d{{a, b, c, x}, {a, b}, {c, y, d}, {x, y}, {x, c, d}, {y}} After unit literal elimiation: ab c{{a, b, c}, {a, b}} 17
Pure Literals A literal l is called pure in a formula φ iff l occurs in φ the complement of l, i.e., l does not occur in φ Definition of Pure Literal Elimination Example ab x c yz d{{a, b, c}, {a, b}, {c, y, d}, {x, y}, {x, c, d}} Pure: a, d, x, y 18
Pure Literal Elimination Definition of Pure Literal Let φ be a QBF with pure literal l and let ψ be a QBF obtained from φ by Example removing all clauses with l if quant(l) = removing all occurences of l if quant(l) = ab x c yz d{{a, b, c}, {a, b}, {c, y, d}, {x, y}, {x, c, d}} After Pure Literal Elimination: b{{b}, { b}} 19
Universal Reduction Example Let φ be a QBF in PCNF and C φ. Let l C with quant(l) = forall k C with quant(k) = k < l, i.e., all existential variables k of C are to the left of l in the prefix. Then l may be removed from C. C\{l} is called the forall reduct (also universal reduct of C). ab x c yz d{{a, b, c, x}, {a, b, x}, {c, y, d}, {x, y}, {x, c, d}}} After Universal Reduction: ab x c yz d{{a, b, x}, {a, b, x}, {c, y}, {x, y}, {x}}} 20
Boolean splitcnf2 ( P r e f i x P, matrix ψ ) (P, ψ) = simplify(p, ψ) ; i f (ψ == ) : r e t u r n true ; i f ( ψ ) : r e t u r n false ; P = QXP,x X, X = X\{x} ; i f ( Q == ) r e t u r n ( splitcnf2 ( QX P, ψ ) && splitcnf2 ( QX P, ψ ) ) ; else r e t u r n ( splitcnf2 ( QX P, ψ ) splitcnf2 ( QX P, ψ ) ) ; where ψ : take clauses of ψ, delete clauses with x, delete x ψ : take clauses of ψ, delete clauses with x, delete x 21
Resolution for QBF Q-Resolution: propositional resolution + universal reduction (UR). Definition Let C 1, C 2 be clauses with existential literal v C 1 and v C 2. 1. Tentative Q-resolvent: C 1 C 2 := (UR(C 1 ) UR(C 2 )) \ {v, v}. 2. If {x, x} C 1 C 2 then no Q-resolvent exists. 3. Otherwise, Q-resolvent C := (C 1 C 2 ). Q-resolution is a sound and complete calculus. Dual variant for QBFs in QDNF. Universals as pivot are also possible. 22
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y Universal-Reduction ψ 0 0 0 0 1 1 Resolution unsat 1 0 1 1 1 0 Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y ψ 0 0 0 0 1 1 1 0 1 1 1 0 unsat y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y ψ 0 0 0 0 1 1 1 0 1 1 1 0 unsat Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y Universal-Reduction ψ 0 0 0 0 1 1 1 0 1 unsat 1 1 0 Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y Universal-Reduction ψ 0 0 0 0 1 1 Resolution unsat 1 0 1 1 1 0 Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y ψ 0 0 0 0 1 1 1 0 1 1 1 0 unsat Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Q-Resolution Example Exclusive OR (XOR): QBF ψ = x y(x y) ( x y) Truth Table x y ψ 0 0 0 0 1 1 1 0 1 1 1 0 unsat Q-Resolution Proof x y x y x x y = x ψ = 0 f y (x) = x (counter model) 23
Example: Q-Resolution Input Formula x 1 y 1 x 2 x 3 y 2 x 4 x 5.( x 1 x 5 ) (y 1 x 4 x 5 ) (x 2 y 2 x 4 ) (x 3 y 2 x 4 ) ( x 2 x 3 y 2 ) (x 1 x 4 ) Q-Resolution Proof DAG x 1 x 5 y 1 x 4 x 5 x 2 y 2 x 4 x 3 y 2 x 4 x 2 x 3 y 2 x 1 x 4 x 2 y 2 x 4 x 1 y 1 y 2 y 1 y 2 x 5 y 2 x 4 x 1 y 2 24
Example: Q-Resolution Input Formula x 1 y 1 x 2 x 3 y 2 x 4 x 5.( x 1 x 5 ) (y 1 x 4 x 5 ) (x 2 y 2 x 4 ) (x 3 y 2 x 4 ) ( x 2 x 3 y 2 ) (x 1 x 4 ) x 1 y 1 x 2 x 3 y 2 x 4 x 5.( x 1 x 5 ) (y 1 x 4 x 5 ) (x 2 y 2 x 4 ) Q-Resolution Proof DAG (x 3 y 2 x 4 ) ( x 2 x 3 y 2 ) (x 1 x 4 ) x 1 x 5 y 1 x 4 x 5 x 2 y 2 x 4 x 3 y 2 x 4 x 2 x 3 y 2 x 1 x 4 x 2 y 2 x 4 x 1 y 1 y 2 y 1 y 2 x 5 y 2 x 4 x 1 y 2 24