CSCI 1010 Models of Computa3on Lecture 11 Proving Languages NP-Complete
Overview P-3me reduc3ons Composi3on of P-3me reduc3ons Reduc3on from CIRCUIT SAT to SAT SAT is NP-complete. 3-SAT is NP-complete. NAESAT is NP-complete. Reduc3on from 3-SAT to INDEPENDENT SET Reduc3on from NAESAT to 3-COLORING John E. Savage CSCI 1010 Lect 11 2
Polynomial-Time Reduc3on Defini6on: A polynomial-6me reduc6on (P- 6me) from language L 1 Γ * to language L 2 Σ * is a reduc6on f : Γ * Σ * (x ε L 1 iff f(x) ε L 2 ) computable by a DTM in 3me polynomial in the length of its input. (f P-6me translates L 1 to L 2 ) w PPP f w R Recognizer R for L 2. The Recognizer for L 1 invokes the recognizer R for L 2. John E. Savage CSCI 1010 Lect 11 3
NP-Complete Language L Γ * is NP-complete if L ϵ NP and L is NP-hard. L is NP-hard if for every L 0 Γ * in NP, we can decide membership in L 0 by invoking a P-3me reduc3on f 0 from L 0 to L. If L is NP-complete and L in P, then P = NP. w PPP f 0 w R Recognizer R for L Recognizer for L 0 in NP invokes recognizer R for L. John E. Savage CSCI 1010 Lect 11 4
Cook and Karp Reduc3ons A Karp reduc3on makes one invoca3on of a P-3me reduc3on from one language to another. Such reduc3ons are called transla6ons. A Cook reduc3on uses a P-3me oracle Turing machine to decide membership in a language. An oracle TM runs, writes a string on the oracle tape, and enters the oracle state. The oracle writes an answer on the oracle tape in one step and the TM resumes. This can be repeated mul3ple 3mes. John E. Savage CSCI 1010 Lect 11 5
Cook Versus Karp Reduc3ons The Cook reduc3on may be more general than the Karp reduc3on although every reduc3on so far is Karp reduc3on. John E. Savage CSCI 1010 Lect 11 6
Composi3on of P-Time Transla3ons Defini6on: Let f 1 : Γ * Σ * and f 2 : Γ * Σ * be transla3ons. The composi6on of f 2 with f 1 computes f 2 ( f 1 (x)). Theorem The composi3on of two P-3me transla3ons is a P-3me transla3on. Proof On input x, DTM compu3ng f 1 generates output f 1 (x) whose length, f 1 (x),is polynomial in x. This is the input to f 2 so its running 3me is polynomial in f 1 (x) which is polynomial in x, the input to the composi3on. John E. Savage CSCI 1010 Lect 11 7
Proving New Languages NP-Complete Theorem Let L a be NP-complete. Let g be a P- 3me transla3on of L a to L b and let L b be in NP. Then, L b is NP-complete. Proof Because L a is NP-complete, for each L 0 in NP there exists an f 0 transla3ng L 0 to L a in P-3me. The composi3on of g with f 0 is a P-3me transla3on. Thus, for each L 0 in NP there exists a P-3me f(x) = g(f 0 (x)) transla3ng L 0 to L b. (L b is NPhard.) Since L b is also in NP, it is NP-complete. John E. Savage CSCI 1010 Lect 11 8
Circuit Sa3sfiability A circuit is sa6sfiable if its nondeterminis3c inputs can be chosen so that the output is 1. CIRCUIT SAT is the set of sa3sfiable circuits. CIRCUIT SAT has been shown NP-complete. We reduce it in P-3me to other problems to show that they are also NP-hard. John E. Savage CSCI 1010 Lect 11 9
Sa6sfiability (SAT) Instance: A set of literals X = {x 1, x 1,..., x n, x n } and clauses C = (c 1,...,c n ), each c i is a subset of X. Yes Instance: There exists an assignment to variables over {0,1} such that each clause has a literal with value 1. No Instance: There is no assignment to variables over {0,1} such that each clause has a literal with value 1. We show that SAT is NP-complete. John E. Savage CSCI 1010 Lect 11 10
Transla3ng CIRCUIT SAT to SAT Consider circuit in SLP form: (1 READ x) g 1 := x; (2 READ y) g 2 := y; (3 NOT 1) g 3 := NOT(g 1 ); (4 NOT 2) g 4 := NOT(g 2 ); (5 AND 1 4) g 5 := g 1 AND g 4 ; (6 AND 3 2) g 6 := g 3 AND g 2 ; (7 OR 5 6) g 7 := g 5 OR g 6 ; (g 7 is the output) John E. Savage CSCI 1010 Lect 11 11
Transla3ng CIRCUIT SAT to SAT These clauses simulate gates. denotes NOT. That is, the clauses are all sa6sfied only when the func6on on the lek is computed. John E. Savage CSCI 1010 Lect 11 12
Transla3ng CIRCUIT SAT to SAT Tables showing why these mappings work. Both clauses sa3sfied when g = x. (g = h ᴠ k) All three clauses sa3sfied when g = h k Note that not all literals in the third clause are True when all clauses sa3sfied. John E. Savage CSCI 1010 Lect 11 13
Transla3ng CIRCUIT SAT to SAT g 1 := x; g 2 := y; (g 1 x) (g 1 x) (g 2 y) (g 2 y) g 3 := NOT(g 1 ); (g 3 g 1 ) (g 3 g 1 ) g 4 := NOT(g 2 ); (g 4 g 2 ) (g 4 g 2 ) g 5 := g 1 AND g 4 ; (g 5 g 1 ) (g 5 g 4 ) (g 5 g 1 g 4 ) g 6 := g 3 AND g 2 ; (g 6 g 3 ) (g 6 g 2 ) (g 6 g 3 g 2 ) g 7 := g 5 OR g 6 ; (g 7 g 5 ) (g 7 g 6 ) (g 7 g 5 g 6 ) (g 7 is the output) (g 7 ) John E. Savage CSCI 1010 Lect 11 14 _ Form AND of all the clauses
SAT is NP-complete Theorem SAT is NP-complete. Proof The above reduc3on from CIRCUIT SAT to SAT maps an instance of CIRCUIT SAT to a instance of SAT. The former is sa3sfied if and only if the laper is sa3sfied. Why? The reduc3on takes 3me polynomial in the length of the input. Thus, SAT is NP-hard. Why is SAT is in NP? It follows that SAT is NP-complete. John E. Savage CSCI 1010 Lect 11 15
3-SAT Instance: Set of literals X = {x 1,x 1,..., x n, x n } & clauses C = (c 1,...,c n ), each c i is a subset of X, c i 3. Yes Instance: There exists an assignment to variables over {0,1} such that each clause has a literal with value 1. No Instance: There is no assignment to variables over {0,1} such that each clause has a literal with value 1. The same proof shows that 3-SAT is NP-complete because each clause has at most three literals. John E. Savage CSCI 1010 Lect 11 16
Not All Equal SAT (NAESAT) NAESAT Instance: An instance of 3-SAT Yes Instance: Each clause is sa3sfied with not all literals being equal (one has value 1, another has value 0). No Instance: Cannot sa3sfy each clause with not all literals being equal. John E. Savage CSCI 1010 Lect 11 17
On Reduc3ons To show that NAESAT is NP-complete, we make the following observa3on: Let f be a transla3on of problem A to problem B, that is, that it maps a Yes instance of A to one of B and a No instance of A to one of B. Instead of showing that f translates a No instance of A to a No instance of B, it suffices to show that the pre-image of f from a Yes instance of B is a Yes instance of A. Then, a No instance of A does not map to a Yes of B. See the following. John E. Savage CSCI 1010 Lect 11 18
Proving Reduc3ons A B Yes A f : A B Yes B No A No B If we show that every element mapping to Yes B is in Yes A, then every element in No A must map to an instance in No B We use this idea to show several problems NP-complete. John E. Savage CSCI 1010 Lect 11 19
NAESAT is NP-Complete Theorem NAESAT is NP-complete. Proof The 3-literal clauses in the reduc3on to 3- SAT have the requisite property (check this). Add a new literal y to the other clauses. We claim that this reduc3on is sa3sfied with not all equal literals iff CIRCUIT SAT is sa3sfied. a) If CIRCUIT SAT is sa3sfied, at least one literal is 1 in each clause. Set y = 0! John E. Savage CSCI 1010 Lect 11 20
NAESAT is NP-Complete Proof (cont.) b) If the instance of NAESAT produced by the reduc3on is a Yes instance, then each clause is sa3sfied with the NAE property. Thus, if we complement all variables, the same property holds. In one of these cases y =0. Choose this case. Then, the values of variables is such as to cause the original instance of CIRCUIT SAT to be sa3sfied. Thus, the instance CIRCUIT SAT is sa3sfied iff the instance of NAESAT is sa3sfied. John E. Savage CSCI 1010 Lect 11 21
Independent Set (IS) Instance: A graph G = (V,E) and integer k. Yes Instance: (G,k) such that there is a set of k ver3ces with no edges between them. Let G be the following graph. Is (G,3) in Independent Set (IS)? If so, why? Is (G,4) in IS? John E. Savage CSCI 1010 Lect 11 22
Independent Set in NP-Complete Theorem Independent Set is NP-complete. Proof We reduce 3-SAT to Independent Set. Modify 3-SAT so that each clause contains three literals and no clause iden3cally true. E.g. if (a+b) exists, add (a+b+z) and (a+b+z), z is new. (a+b) is sa3sfied iff (a+b+z) (a+b+z) is sa3sfied. If a clause contains one variable, create four clauses with all four combina3ons of literals in new variables u and v. This is a P-3me reduc3on. John E. Savage CSCI 1010 Lect 11 23
Independent Set in NP-Complete Proof (cont.) Given an instance of 3-SAT, construct graph G by crea3ng a triangle for each clause. The ver3ces of a triangle are labeled by the literals in a corresponding clause. Add edge between ver3ces in different clauses if one is the NOT of another. Let k = number of clauses. (G,k) an instance of IS. This reduc3on is P-3me. John E. Savage CSCI 1010 Lect 11 24
Example of Reduc3on Example: (x 1 +x 2 +x 3 )(x 1 +x 2 +x 3 )(x 1 +x 2 +x 3 ) maps to (G,3) below. It is sa3sfied by x 1 =x 2 =x 3 =1. John E. Savage CSCI 1010 Lect 11 25
Independent Set in NP-Complete Given a Yes instance of 3-SAT, we show that (G,k) is a Yes instance of IS. Pick one True literal per clause. No edges exist between corresponding ver3ces in (G,k) so they form a Yes instance of IS. John E. Savage CSCI 1010 Lect 11 26
Independent Set in NP-Complete Given a Yes instance (G,k) of IS, we construct a Yes instance of 3-SAT. IS of (G,k) must have one vertex from each triangle. Since labels are not complements, assign value 1 to corresponding literals to obtain a Yes instance of 3- SAT. John E. Savage CSCI 1010 Lect 11 27
3-COLORING Instance: A graph G = (V,E). Yes Instance: G such that three colors can be assigned to ver3ces so that adjacent ver3ces have different colors. Theorem 3-COLORING is NP-complete. Proof By reduc3on from NAESAT. Consider an instance of NAESAT that has three literals in each clause. John E. Savage CSCI 1010 Lect 11 28
3-COLORING Construct a graph G from clauses as follows: Create a variable triangle (ν, x j, x j ) for each j. Create a triangle for each clause. If the r th clause has literals λ 1, λ 2, λ 3 let (r, λ 1 ), (r, λ 1 ), (r, λ 1 ) be labels for the three ver3ces in the rth triangle. Insert edge between (r, λ i ) in a clause triangle and λ i in a variable triangle. John E. Savage CSCI 1010 Lect 11 29
3-COLORING John E. Savage CSCI 1010 Lect 11 30
3-COLORING Given a Yes instance of 3-COLORING, we show it corresponds to a Yes instance of NAESAT. Let colors be {0,1,2}. Let the root ν have color 2. Assign colors in {0,1} to (r, λ i ) and λ i. To the third vertex in clause triangle, assign color 2 If (r, λ i ) has color c in {0,1}, assign value c to λ i. This means that in each clause not all literals have the same value and we have Yes instance of NAESAT. John E. Savage CSCI 1010 Lect 11 31
3-COLORING Given a Yes instance of NAESAT, we show it corresponds to a Yes instance of 3-COLORING. Let ν have color 2 and x j and x j have values that sa3sfy the clauses in the Yes instance. ~ Consider two unequal literals in a clause. If (r, x j ) is one of these, give it a complementary color in ~ {0,1} to x j in the variable triangle. Give the third vertex in clause triangle color 2. This is a 3- COLORING. John E. Savage CSCI 1010 Lect 11 32
Review P-3me reduc3ons Composi3on of P-3me reduc3ons Reduc3on from CIRCUIT SAT to SAT SAT is NP-complete. 3-SAT is NP-complete. NAESAT is NP-complete. Reduc3on from 3-SAT to INDEPENDENT SET Reduc3on from NAESAT to 3-COLORING John E. Savage CSCI 1010 Lect 11 33