SAT exercises 1 March, 2016 slide 1 Satisability of Boolean Formulas Combinatorics and Algorithms Prof. Emo Welzl Assistant: (CAB G36.1, cannamalai@inf.ethz.ch) URL: http://www.ti.inf.ethz.ch/ew/courses/sat16/
SAT exercises 1 March, 2016 slide 2 Today's exercises 1.3: Associativity of boolean operators 1.12: Four Clauses Suce 1.15: Disjunctive Normal Form 1.18: Counting Formulas 1.25: Number of Vertex Covers 1.28: Horn Formulas Addendum to exercise 1.25: Improved ( 2)-CNF counting
SAT exercises 1 March, 2016 slide 3 1.3. Associativity of boolean operators Denition. An operator is associative if for all operands a, b, c we have (a (b c)) = ((a b) c). If an operator is associative, then we can write expressions without parentheses because of the lack of ambiguity. We saw a short proof of this in the exercise session. In particular, only the order of the operands matter (and not the order of evaluation). We can then interpret an expression involving n operands, x 1... x n as an n-variate function. Check which of {,,,, } are associative and characterize the n-variate functions they induce.
SAT exercises 1 March, 2016 slide 4 1.3. Associativity of boolean operators (2) By straightforward checking: Associative:,,, Not associative:. is not associative because when (x 0, y 1, z 0). x (y z) (x y) z
SAT exercises 1 March, 2016 slide 5 1.3. Associativity of boolean operators (3) Characterization: n i=1 is true i all operands are true. n i=1 is true i at least one operand is true. n i=1 is true i an odd number of operands is true (this is called the parity function). n i=1 : When n is even, it is true i an even number of operands are true, and when n is odd, it is true i an odd number of operands are true. Note that this is the same as saying that the expression is true i an even number of operands is false. The proofs of the characterizations follow by induction on n.
SAT exercises 1 March, 2016 slide 6 1.12. Four Clauses Suce As in Section 1.2, we can represent every boolean function as a CNF formula. Over three variables, this automatically becomes a 3-CNF formula, say F. F could potentially contain 8 possible clauses. Let us enumerate them from C 1 through C 8 in order and pair consecutive clauses: {C 1, C 2 },..., {C 7, C 8 }. If F contains both clauses from some pair thenresolve the two clauses using the last variable (since we are guaranteed that this variable appears positively once and negatively once in each of the clauses in
SAT exercises 1 March, 2016 slide 7 the pair, by our enumeration) to obtain an equivalent clause with only two literals. Therefore, for each pair we retain at most one clause with either 2 or 3 literals, giving us a ( 3)-CNF formula with at most 4 clauses.
SAT exercises 1 March, 2016 slide 8 1.15. Disjunctive Normal Form (1) Let φ(x 1,..., x n ) be the given boolean formula on n variables. Imagine the truth table of φ. We show one row of the truth table here and the corresponding DNF clause. x 1 x 2... x n φ(x 1,..., x n ). 0 1... 0 1 = ( x 1 x 2 x n ).
SAT exercises 1 March, 2016 slide 9 (2) For each assignment α := (x 1 t 1,..., x n t n ) that results in φ(α) evaluating to 1 we make one DNF-clause x i x i : α(x i )=1 x i, x i : α(x i )=0 which has the property that it evaluates to 1 exactly when x i = t i for all i {1,..., n}. (3) Taking the OR of all such clauses we obtain a boolean formula equivalent to φ in disjunctive normal form: x i α {0,1} n : φ(α)=1 x i : α(x i )=1 x i. x i : α(x i )=0
SAT exercises 1 March, 2016 slide 10 1.18. Counting Formulas (1) The function can be represented by its truth table associating a value from {0, 1} to each tuple in {0, 1} n. This yields 2 2n possibilities. (2) To build a k-clause we rst need to choose the k variables which appear in the clause, and for each chosen variable we need to decide if it will be negated or not. Therefore there are ( ) n k 2 k many distinct k-clauses. To build a k-cnf formula, we have to select a subset of them. We hence have 2 (n k ) 2k possibilities. (3) Since there are 2 210 = 2 1024 such functions and only 2 (10 3 ) 23 = 2 960 formulas, there are many boolean functions over 10 variables that cannot be represented as 3-CNF formulae.
SAT exercises 1 March, 2016 slide 11 Question: Can you explain why a 3-CNF cannot express everything? Does this contradict what we did on the rst day (everything can be represented as a 3-CNF)?
SAT exercises 1 March, 2016 slide 12 1.25. Number of Vertex Covers Goal: Design and analyze and algorithm for counting the number of vertex covers. Trivial algorithm: O(2 n poly(n)); test for each of the 2 n subsets of V if it is a vertex cover. Idea: Encode subsets N of V as assignments, and the condition that N is a vertex cover as a 2-CNF formula.
SAT exercises 1 March, 2016 slide 13 The encoding is straight-forward: Each vertex v becomes a variable. The corresponding assignment α N is dened as α N (v) := 0, v N 1, v N. For each edge e = {v 1, v 2 }, we want that at least one vertex is present. This is encoded by the clause {v 1, v 2 }. Therefore F := E and a subset N is a vertex cover if and only if the corresponding assignment α N satises F. An assignment on V encodes exactly one subset N of V ; therefore the number of satisfying assignments is the number of vertex covers.
SAT exercises 1 March, 2016 slide 14 1.28. Horn formulas Correctness. Trivial. We are using only more restrictive rules. Completeness. Let F be Horn and let F be the extension of F by all possible (unit res.-)resolvents, s.t. no pair C, D F can yield a (unit res.-)resolvent not yet contained in F. Note that F is Horn because two clauses with at most one positive literal each contain again at most one positive literal.
SAT exercises 1 March, 2016 slide 15 1.28. Horn formulas (2) Hence if F, then a satisfying assignment α is given by satisfying all 1-clauses and setting the remaining variables to 0. A contradictory pair {u} and {ū} cannot exist since this would have allowed to derive. Suppose α does not satisfy F, then we will show this leads to a contradiction. Let C be a unsatised clause of F with fewest literals. C contains at least 2 literals (as we satised all 1-clauses), and so one literal must be negative x. This literal is satised unless {x} F. However if {x} F we can do unit resolution with C and {x} to obtain a smaller unsatised clause, a contradiction.
SAT exercises 1 March, 2016 slide 16 Addendum to exercise 1.25: Improved counting ( 2)-CNF The best known ( 2)-CNF counting algorithm is by Wahlström and runs in time O(1.2377 n ) using a very rened analysis. Remember our algorithm fib c2s(f,v ): If F is a ( 1)-CNF, the problem is easy. Otherwise let {u, v} be some 2-clause. Return fib c2s(f [u 1] )+fib c2s(f [u 0,v 1] ). How to improve this?
SAT exercises 1 March, 2016 slide 17 Improved ( 2)-CNF counting (2) We introduce an additional case distinction to better exploit the structure. We rst address trivial cases: If F contains the 0-clause, then sat V (F ) = 0. If F = {}, then sat V (F ) = 2 V. If F contains a 1-clause {u}, then sat V (F ) = sat V \vbl{u} (F [u 1] ). Hence we can assume that F is a non-empty 2-CNF formula.
SAT exercises 1 March, 2016 slide 18 Improved ( 2)-CNF counting (3) Let C = {u, v} be some 2-clause. If the variables of u and v do not occur anywhere else in the formula, then sat V (F ) = 3 sat V \vbl{u,v} (F \ {{u, v}}). Otherwise there is D F with vbl(c) vbl(d). There are the following cases: 1. vbl(c) = vbl(d) (the clauses share both variables) 2. C D = 1 (the clauses have complementary literals) 3. C D = 1 (the clauses share a literal)
SAT exercises 1 March, 2016 slide 19 Improved ( 2)-CNF counting (4) 1. vbl(c) = vbl(d): We need to consider 2 out of 4 possibilities of formulas with 2 fewer variables. 2. C D = 1 (the clauses have complementary literals). C = {u, v}, D = {ū, w}. Either set u to 1 and w to 1, or set u to 0 and v to 1. 3. C D = 1 (the clauses share a literal). C = {u, v}, C = {u, w}. Either set u to 1 or set u to 0 and v, w to 1. The rst two cases give running time O( 2 n poly(n)) O(1.415 n ). The last case is the worst case and gives running time O(1.466 n ), a large improvement over O(1.619 n ). (see Appendix A.2 for methods to solve recurrences, also look at Special Assignment 1, Exercise 1 of SAT12)