=========================================================================== CSC 363 Lecture Summary for Week 9 Fall 2009 =========================================================================== Last week's tutorial had two unanswered questions... 3. Prove or disprove: A_TM (- NP. A_TM is undecidable but all languages in NP are decidable, by definition. So A_TM does not belong to NP. 4. Show that P is closed under complementation, i.e., for all languages L (- P, ~L (- P. Suppose L (- P. By definition, there exists a decider D for L and some constant k (- N such that for all inputs w (- \Sigma*, D accepts w if w (- L and D rejects w if w !(- L, all in time O(|w|^k). Consider the decider D' = D with q_A and q_R interchanged. Then D' runs in time O(|w|^k) for all input strings w (- \Sigma*, and D' accepts w iff D rejects w iff w !(- L, i.e., D' decides ~L in time O(n^k). Hence, ~L (- P. Examples of languages in NP. - Definition: a propositional formula is in Conjunctive Normal Form (CNF) if it is written as a conjunction ("and") of one or more "clauses": C_1 /\ C_2 /\ ... /\ C_r where each clause is a disjunction ("or") of one or more "literals": C_j = (a_{j,1} \/ a_{j,2} \/ ... \/ a_{j,s_j}) where each literal is either a propositional variable or the negation of a propositional variable. For example, (p \/ ~q) /\ q is in CNF, but ~(p /\ q) /\ (r \/ ~p) is NOT in CNF (it is equivalent to some CNF formula, but the property of being in CNF is all about the way the formula is written, *not* what it is equivalent to). The proof of the Cook-Levin Theorem actually shows that CNF-SAT is NPc (where CNF-SAT = { : F is a formula in CNF that is satisfiable }), because it's possible to construct the formula F_x to be in CNF. - Definition: a propositional formula is in 3-CNF if it is in CNF where each clause contains exactly 3 literals, e.g., (p \/ q \/ ~r) /\ (p \/ p \/ ~q) 3SAT = { : F is a formula in 3-CNF that is satisfiable } is NPc: 3SAT (- NP because it's a special case of SAT (same verifier works). 3SAT is NP-hard because CNF-SAT <=p 3SAT. Note: Careful with directions! Trivially, 3SAT <=p CNF-SAT (3SAT is special case of CNF-SAT). But we need other direction to conclude 3SAT is NP-hard, transforming instances of general problem into instances of restricted problem (trickier). Given (a CNF formula), construct (a 3-CNF formula) such that F is satisfiable iff F' is satisfiable, as follows. Note that it is not necessary to make F and F' logically equivalent in order to achieve this. For each clause C of F: - If C = (a1), then replace C with (a1 \/ a1 \/ a1). - If C = (a1 \/ a2), then replace C with (a1 \/ a1 \/ a2). - If C = (a1 \/ a2 \/ a3), then leave C the same. - If C = (a1 \/ a2 \/ ... \/ ar) where r > 3, then replace C with (a1 \/ a2 \/ z1) /\ (~z1 \/ a3 \/ z2) /\ (~z2 \/ a4 \/ z3) /\ ... /\ (~z{r-4} \/ a{r-2} \/ z{r-3}) /\ (~z{r-3} \/ a{r-1} \/ ar), where z1, z2, ..., z{r-3} are new variables (not in F). For example, if F = (x1 \/ x2) /\ (~x1) /\ (x2 \/ ~x3 \/ x3 \/ x5 \/ ~x4) then F' = (x1 \/ x1 \/ x2) /\ (~x1 \/ ~x1 \/ ~x1) /\ (x2 \/ ~x3 \/ z3) /\ (~z3 \/ x3 \/ z4) /\ (~z4 \/ x5 \/ ~x4) Clearly, this transformation can be carried out in polytime: at most, each clause of length r gets replaced with O(r) 3-clauses using O(r) new variables. Also, if F is satisfiable, then there is an assignment of truth values to the variables of F that makes at least one literal true in each clause of F. This assignment can be extended to include values for the new variables of F' that will make each clause of F' true: - For 1-/2-/3-clauses of F with at least one true literal, the corresponding clause in F' is also true because it contains the same literals, at least one of which is true. - For r-clauses of F with at least one true literal, say the original clause is (a1 \/ a2 \/ ... \/ ar) and the true literal is ai. Then pick values for the new variables as follows: . if i=1 or i=2, then (a1 \/ a2 \/ z1) is satisfied so pick z1 = z2 = ... = z{r-3} = false to satisfy every other clause; . if i=r-1 or i=r, then (~z{r-3} \/ a{r-1} \/ ar) is satisfied so pick z1 = z2 = ... = z{r-3} = true to satisfy every other clause; . if 2 < i < r-1, then (~z{i-2} \/ ai \/ z{i-1}) is satisfied so pick z1 = z2 = ... = z{i-2} = true to satisfy the first i-2 clauses and pick z{i-1} = zi = ... = z{r-3} = false to satisfy the last r-i-1 clauses. For example, if x3 = true satisfies (x2 \/ ~x3 \/ x3 \/ x5 \/ ~x4), then pick z1 = true and z2 = false to satisfy (x2 \/ ~x3 \/ z1) /\ (~z1 \/ x3 \/ z2) /\ (~z2 \/ x5 \/ ~x4) (the first clause is satisfied by z1 = true, the second clause is satisfied by x3 = true, the last clause is satisfied by z2 = false). Finally, if F' is satisfiable, then the assignment of values to the variables of F' must include values to the variables of F that satisfy F: - If the new clause (a1 \/ a2 \/ a3) is satisfied, then the original clause is also satisfied because it's the same, and similarly for the new clauses (a1 \/ a1 \/ a2) and (a1 \/ a1 \/ a1), because they are logically equivalent to the original clauses. - If the new clauses (a1 \/ a2 \/ z1) /\ (~z1 \/ a3 \/ z2) /\ (~z2 \/ a4 \/ z3) /\ ... /\ (~z{r-4} \/ a{r-2} \/ z{r-3}) /\ (~z{r-3} \/ a{r-1} \/ ar) are satisfied, then: . if none of the new variables z1, ..., z{r-3} is set to false, then (~z{r-3} \/ a{r-1} \/ ar) can only be satisfied by setting a{r-1} = true or ar = true; . else, if z1 is set to false, then (a1 \/ a2 \/ z1) can only be satisfied by setting a1 = true or a2 = true; . else let zi be the first new variable set to false (so z1 = z2 = ... = z{i-1} = true): (~z{i-1} \/ a{i+1} \/ zi) can only be satisfied by setting a{i+1} = true; in all cases, one of the original literals must be set to true so the original clause (a1 \/ a2 \/ ... \/ ar) is also satisfied. We have shown that any CNF formula F can be transformed in polytime to a 3-CNF formula F' such that F is satisfiable iff F' is satisfiable; this completes the polytime reduction from CNF-SAT to 3SAT. - VERTEX-COVER (VC for short) = { : G is a graph that contains a vertex cover of size k, i.e., a set C of k vertices such that each edge of G has at least one endpoint in C } . VC (- NP: certificate = vertex cover of size k. . VC is NP-hard: 3SAT <=p VC. Given F = (a1 \/ b1 \/ c1) /\ ... /\ (ar \/ br \/ cr), where ai,bi,ci in {x1,~x1,x2,~x2,...,xs,~xs}, construct G=(V,E) and k such that F satisfiable iff G contains vertex cover of size k, as follows: k = s + 2r V = { a1,b1,c1, ..., ar,br,cr, x1,~x1, ..., xs,~xs } E = { (xi,~xi) : 1 <= i <= s } U { (ai,bi),(bi,ci),(ci,ai) : 1 <= i <= r } U { (l,x) : l = ai or bi or ci, and x = xj or ~xj corresponding to l } For example, if F = (x1 \/ ~x2 \/ ~x4) /\ (x2 \/ ~x3 \/ x1) /\ (~x3 \/ x4 \/ ~x2), then a1=x1, b1=~x2, c1=~x4, a2=x2, b2=~x3, c2=x1, a3=~x3, b3=x4, c3=~x2 so k = 4 + 2*3 = 10 V = {a1,b1,c1, a2,b2,c2, a3,b3,c3, x1,~x1, x2,~x2, x3,~x3, x4,~x4} E = { (x1,~x1), (x2,~x2), (x3,~x3), (x4,~x4), (a1,b1), (b1,c1), (c1,a1), (a1,x1), (b1,~x2), (c1,~x4), (a2,b2), (b2,c2), (c2,a2), (a2,x2), (b2,~x3), (c2,x1), (a3,b3), (b3,c3), (c3,a3), (a3,~x3), (b3,x4), (c3,~x2) } Clearly, construction can be done in polytime (with one scan of F).