
An Introduction to SAT Solving Applied Logic for Computer Science UWO { December 3, 2017 Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 1 / 46 Plan 1 The Boolean satisfiability problem 2 Converting formulas to conjunctive normal form 3 Tseytin's transformation 4 How SAT solvers work Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 2 / 46 Plan 1 The Boolean satisfiability problem 2 Converting formulas to conjunctive normal form 3 Tseytin's transformation 4 How SAT solvers work Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 3 / 46 Propositional formula Definition Let V be a finite set of Boolean valued variables. A propositional formula on V is defined inductively as follows: each of the constants false, true is a propositional formula on V , any element of V is a propositional formula on V , ′ ′ ′ if φ and φ are propositional formulas on V then ¬φ, (φ), φ ∧ φ , φ ∨ φ , ′ ′ φ → φ , φ ↔ φ are propositional formulas on V as well. Examples and counter-examples p ∨ ¬q is a propositional formula on V = {p; q}, p + ¬q is not a propositional formula on V = {p; q}, p ∨ ¬q is not a propositional formula on V = {p}, () is not a propositional formula on V = {p; q}. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 4 / 46 Assignment Definition Let again V be a finite set of Boolean valued variables. An assignment on V is any map from V to {false; true}. Any assignment v on V induces an assignment on the propositional formulas on V by applying the following rules: if φ and φ′ are propositional formulas on V then we have: 1 v(¬φ) = ¬v(φ), ′ ′ 2 v(φ ∧ φ ) = v(φ) ∧ v(φ) , ′ ′ 3 v(φ ∨ φ ) = v(φ) ∨ v(φ ), ′ ′ 4 v(φ → φ ) = v(φ) → v(φ ), ′ ′ 5 v(φ ↔ φ ) = v(φ) ↔ v(φ ). Example For the set of Boolean variables V = {p; q}. define v(p) = false and v(q) = true. Then, we have: v(p → q) = true. v(p ↔ q) = false. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 5 / 46 Satisfiability (1/4) Definition Let again V be a finite set of Boolean valued variables and let φ propositional formula on V . An assignment v on V is a satisfying assignment for φ if we have v(φ) = true. The propositional formula φ is said satisfiable if there exists a satisfying assignment for φ. Deciding whether or not a propositional formula is satisfiable is called the Boolean satisfiability problem, denoted by SAT. Example p ∧ (q ∨ ¬p) ∧ (¬q ∨ ¬r) is satisfiable for v(p) = true, v(q) = true, v(r) = false. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 6 / 46 Satisfiability (2/4) Example The formula is p ∧ (q ∨ ¬p) ∧ (¬q ∨ ¬p) is unsatisfiable. Indeed: the first clause, namely p, implies that p must be true, then, the second clause, namely (q ∨ ¬p), implies that q must be true, then, the third clause, namely (¬q ∨ ¬p) is false, thus the whole formula cannot be satisfied. Remarks Simple method for checking satisfiability: the truth table method, that is, check all 2n possibilities for v, where n is the number of variables in V . This always works, but has a running time growing exponentially with n. Practical algorithms and software solving SAT problems also run in time n O(2 ) but plays many tricks to terminate computations as early as possible. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 7 / 46 Satisfiability (3/4) Eight queens puzzle: general statement Go to https://en.wikipedia.org/wiki/Eight_queens_puzzle and read. For n = 4, there are two solutions. Exercise: how to phrase the search for those solutions into a SAT problem? Hints: • What should the Boolean variables represent? • What should the propositional formula represent? Remember the rules: • at most one (and at least one) queen in every row, • at most one (and at least one) queen in every column, • at most one queen in every diagonal. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 8 / 46 Satisfiability (4/4) Eight queens puzzle: case n = 2 Associate a Boolean variable with each of the four corners, say a, b, c and d in clock-wise order. Exactly one queen on the top row writes: (a ∨ b) ∧ ¬(a ∧ b). Exactly one queen on the bottom row writes: (c ∨ d) ∧ ¬(c ∧ d). Exactly one queen on the left column writes: (a ∨ d) ∧ ¬(a ∧ d). Exactly one queen on the left column writes: (b ∨ c) ∧ ¬(b ∧ c). No two queens on the same diagonal writes: ¬(a ∧ c) ∧ ¬(b ∧ d). We need some help to determine of the conjunction of these 5 formulas is satisfiable! Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 9 / 46 SAT solvers Modern SAT solvers are based on resolution, and only apply to input formulas in conjunctive normal form (CNF). A conjunctive normal form (CNF) is a conjunction of clauses A clause is a disjunction of literals, say a1 ∨ ⋯ ∨ an, where a1; : : : ; an are literals. A literal is a Boolean variable or the negation of a Boolean variable Hence a CNF is of the form ` 1≤i≤s 1≤j≤tj i;j where the `i;j's are literals. SAT solvers have many applications. Problems involving binary arithmetic program correctness termination of rewriting puzzles like Sudoku can be encoded as SAT problems Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 10 / 46 The yices SAT solver (1/3) Calling sequence The solver yices is simply used by calling yices -e -smt test.smt where test.smt contains the formula to test. The input file uses a Lisp-like syntax where and and or can have any number of arguments. Availability The SAT solver yices is publicly available at http://yices.csl.sri.com/old/download-yices1-full.html for Linux, MacOS and Windows. Important: yices requires the GMP library https://gmplib.org/. Installation under Linux and MacOS is straightforward; some work is needed under Windows, if GMP is not yet installed; see the details in OWL. Important: Here, we use the version 1 of yices. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 11 / 46 The yices 1 SAT solver (2/3) Example (benchmark test.smt :extrapreds ((A) (B) (C) (D)) :formula (and (iff A (and D B)) (implies C B) (not (or A B (not D))) (or (and (not A) C) D) )) produces sat (= A false) (= B false) (= D true) (= C false) Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 12 / 46 The yices 1 SAT solver (3/3) Returning to the n queens puzzle for n = 2. Example (benchmark test.smt :extrapreds ((A) (B) (C) (D)) :formula (and (and (or A B) (not (and A B))) (and (or C D) (not (and C D))) (and (or A D) (not (and A D))) (and (or C B) (not (and C B))) (and (not (and A C)) (not (and B D))) )) produces unsat Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 13 / 46 Plan 1 The Boolean satisfiability problem 2 Converting formulas to conjunctive normal form 3 Tseytin's transformation 4 How SAT solvers work Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 14 / 46 Conjunctive normal form Recall A literal is either a propositional variable or the negation of a propositional variable. A clause is a disjunction of literals. A formula is in conjunctive normal form (CNF), if it is a conjunction of clauses; for instance: (p ∨ ¬q ∨ r) ∧ (q ∨ r) ∧ (¬p ∨ ¬q) ∧ r is a CNF on V = {p; q; r}. definition Let V a finite set of Boolean valued variables. Two clauses C; C′ on V are equivalent if they have the same truth table; in ′ this case we write C ↔ C . Similarly, two formulas φ, on V are equivalent if they have the same truth table; in this case we write φ ↔ . Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 15 / 46 Properties of clauses Recall Let V a finite set of Boolean valued variables and φ, be propositional formulas on V . The following properties hold: commutativity of ∧: φ ∧ ↔ ∧ φ, commutativity of ∨: φ ∨ ↔ ∨ φ, absorption of ∧: φ ∧ φ ↔ φ, absorption of ∨: φ ∨ φ ↔ φ. Consequences If a clause C′ is obtained by reordering the literals of a clause C then the two clauses are equivalent. If a clause contains more than one occurrence of the same literal then it is equivalent to the close obtained by deleting all but one of these occurrences. From these properties, we can represent a clause as a set of literals, by making disjunction implicit and by ignoring replication and order of literals; for instance (p ∨ q ∨ r ∨ ¬r) is represented by the set {p; q; r; ¬r}. Applied Logic for Computer Science An Introduction to SAT Solving UWO { December 3, 2017 16 / 46 Properties of clauses Properties The order of clauses in a CNF formula does not matter; for instance we have: (a ∨ b) ∧ (c ∨ ¬b) ∧ (¬b) ↔ (c ∨ ¬b) ∧ (¬b) ∧ (a ∨ b): If a CNF formula contains more than one occurrence of the same clause then it is equivalent to the formula obtained by deleting all but one of the duplicated occurrences: (a ∨ b) ∧ (c ∨ ¬b) ∧ (a ∨ b) ↔ (a ∨ b) ∧ (c ∨ ¬b): From the properties of clauses and of CNF formulas, we can represent a CNF formula as a set of sets of literals; for instance: (a ∨ b) ∧ (c ∨ ¬b) ∧ (¬b) is represented by the set {{a; b}; {c; ¬b}; {¬b}}.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages48 Page
-
File Size-