Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin.

Similar presentations


Presentation on theme: "CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin."— Presentation transcript:

1 CSCI 3130: Formal languages and automata theory Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130 The Chinese University of Hong Kong The Cook-Levin Theorem Fall 2011

2 NP-completeness P NP (easy to solve) (easy to verify solution) SAT IS CLIQUE VC 3SAT reduces to Cook-Levin theorem: Everything in NP reduces to SAT NP-complete

3 Polynomial-time reductions Language L polynomial-time reduces to L’ if there exists a polynomial-time computable map R that takes an instance x of L into instance y of L’ s.t. x ∈ L if and only if y ∈ L’ LL’L’(CLIQUE)(IS) xy (G, k) (G’, k’) x ∈ Lx ∈ L y ∈ L’y ∈ L’ (G has clique of size k)(G’ has IS of size k’) R

4 SAT and 3SAT SAT = { 〈  〉 :  is a satisfiable Boolean formula } 3SAT = { 〈  〉 :  is a satisfiable 3CNF formula } (x 1 ∨ x 2 ∨ x 2 ) ∧ (x 2 ∨ x 3 ∨ x 4 ) ∧ (x 2 ∨ x 3 ∨ x 5 ) ∧ (x 1 ∨ x 5 ∨ x 5 ) ((x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 )) ∨ ((x 1 ∨ (x 2 ∧ x 3 )) ∧ x 3 )

5 The Cook-Levin Theorem To show this, we need a reduction R such that: Every L ∈ NP reduces to SAT z Boolean formula f z ∈ Lz ∈ L f is satisfiable R

6 NP-completeness of SAT All we know: L has a polynomial-time verifier V –Look at the computation tableau of V on input 〈 z, s 〉 V z | s z2z2 z1z1 q acc … S- th configuration symbol at time T S T … q0q0 b a

7 NP-completeness of SAT n = length of z height of tableau is O(n c ) for some constant c width is at most n c k possible tableau symbols x T, S, u = true,if the (T, S) cell of tableau contains u if not false, u 1 ≤ S ≤ n c 1 ≤ T ≤ n c 1 ≤ u ≤ k S T z2z2 z1z1 … q0q0 q acc … b a

8 NP-completeness of SAT We will design a formula f such that: z Boolean formula f z ∈ Lz ∈ L f is satisfiable R assignment to x T, S, u way to fill up the tableau satisfying assignment accepting computation tableau variables of f : x T, S, u f is satisfiable V accepts 〈 z, s 〉 for some s

9 NP-completeness of SAT We want to construct (in time O(n 2c ) ) a formula f : x T, S, u = true,if the (T, S) cell of tableau contains u if not false, 1 ≤ S ≤ n c 1 ≤ T ≤ n c 1 ≤ u ≤ k f(x 1, 1, 1,..., x nc, nc, k ) = true,if the x s represent a legal and accepting tableau if not false,

10 NP-completeness of SAT f = f cell ∧ f 0 ∧ f move ∧ f acc f cell : “Every cell contains exactly one symbol” “The first row is q 0 z|s ☐... ☐ ” for some s f0:f0: f move : “The moves between rows follow the transitions of V ” f acc : “ q acc appears somewhere in the last row” z2z2 z1z1 q acc … … q0q0 b a

11 NP-completeness of SAT f cell : “Every cell contains exactly one symbol” f cell = f cell 1, 1 ∧... ∧ f cell nc, nc where f cell T, S = (x T, S, 1 ∨... ∨ x T, S, k ) ∧ (x T, S, 1 ∧ x T, S, 2 ) ∧ (x T, S, 1 ∧ x T, S, 3 ) ∧... ∧ (x T, S, k-1 ∧ x T, S, k ) at least one symbol no cell contains two or more symbols “Exactly one of x S, T, 1 ∨... ∨ x S, T, k is true”

12 NP-completeness of SAT f0:f0: “The first row is q 0 z 1 z 2...z n |s 1 s 2...s m f 0 = x 1, 1, q0 ∧ x 1, 2, z1 ∧... ∧ x 1, n+1, zn ∧ x 1, n+2, | for some (possible solution) s 1 s 2...s m ”

13 NP-completeness of SAT f acc : “ q acc appears somewhere in the last row” f acc = x nc, 1, qacc ∨ x nc, 2, qacc ∨... ∨ x nc, nc, qacc

14 Legal and illegal windows … 6 a 3 b 0 x 0 … … 0 a 6 b 0 x 0 … 0 legal windows … 6 # 3 b 0 a 0 … … 0 # 6 b 0 q 5 … 0 … 6 a 3 q 2 a 0 … … 0 q 5 a 6 x 0 … 0 … 6 q 2 a 0 b 0 … … 0 a 6 b 0 q 2 … 0 illegal windows … 6 a 3 a 0 ☐ 0 … … 0 x 6 a 0 ☐ 0 … 0 q2q2 q5q5 a/xLa/xL … 6 a 3 q 2 a 0 … … 0 q 5 a 6 b 0 … 0 … 6 q 2 q 2 a 0 … … 0 q 2 q 2 x 3 … 0 … 6 # 3 q 2 a 0 … … 0 q 5 # 6 x 0 … 0

15 NP-completeness of SAT f move : “The moves between rows follow transitions of V ” f move = f move 1, 1 ∧... ∧ f move nc-3, nc-3 a2a2 a1a1 a3a3 a6a6 a4a4 a5a5 f move 2, 2 LW = list of all legal windows = {(a 1, a 2, a 3, a 4, a 5, a 6 ): is legal} a1a1a2a2a3a3 a4a4a5a5a6a6 z2z2 z1z1 q0q0 … q acc … b a f move T, S = (x T, S, a1 ∧ x T, S+1, a2 ∧ x T, S+2, a3 ∧ x T+1, S, a4 ∧ x T+1, S+1, a5 ∧ x T+2, S+1, a6 ) ∨ (a 1, a 2, a 3, a 4, a 5, a 6 ) ∈ LW

16 NP-completeness of SAT z Boolean formula f z ∈ Lz ∈ L f is satisfiable R Let V be a poly-time verifier TM for L. On input z, Construct the formulas f cell, f 0, f move, and f acc Output the formula f = f cell ∧ f 0 ∧ f move ∧ f acc. R := ✔ V accepts z if and only if f is satisfiable. Then R is computable in time O(n 2c ) and

17 How to argue NP-completeness SUBGRAPH = { 〈 G, H 〉 : G and H are graphs where H is a subgraph of G} GH SUBGRAPH is NP -complete 1 23 4 5 67 12 3 4 Every edge of H must be included in G

18 1 23 4 5 67 How to argue NP-completeness Step 1: SUBGRAPH is in NP G H 12 3 4 What is a solution for SUBGRAPH ? A solution s is a map from vertices of H to vertices of G (1 ➝ 4)(2 ➝ 2)(3 ➝ 5)(4 ➝ 7) V := On input 〈 G, H, s 〉 For every edge {u, v} of H : Find u’ and v’ such that u ➝ u’ and v ➝ v’ in s. If {u’, v’} is not an edge in G, reject. Otherwise, accept. Running time = O(m) m = number edges in H ✔

19 How to argue NP-completeness Step 2: Some NP -complete L reduces to SUBGRAPH CLIQUE IND SET VERTEX COVER SAT 3SAT Direction of reduction is important! You want to show SUBGRAPH is harder than L So you assume you can solve SUBGRAPH, and show how to solve L This requires converting instances of L into instances of SUBGRAPH How to choose L ?

20 Tips on choosing L Both CLIQUE and SUBGRAPH are about graph containment, so their complexities may be related It usually makes sense to try and reduce from the problem that looks the most related GH 1 23 4 5 67 12 3 4 G 4 CLIQUESUBGRAPH

21 How to argue NP-completeness Step 3: Reduce CLIQUE to SUBGRAPH SUBGRAPH = { 〈 G, H 〉 : H is a subgraph of G} CLIQUE = { 〈 G, k 〉 : G has a k -clique } R := On input 〈 G, k 〉 Construct the k -clique H Output 〈 G, H 〉 G has a k -clique H is a subgraph of G ✔

22 Cover for triangles A graph has a k -cover for triangles if there are k vertices that touch all the triangles Does it have a 2-cover for triangles? Does it have a 1-cover for triangles? No, because it has two vertex-disjoint triangles Yes TRICOVER = { 〈 G, k 〉 : G has a k -cover for triangles } TRICOVER is NP -complete

23 Cover for triangles Step 1: TRICOVER is in NP What is a solution for TRICOVER ? A solution s is a subset of vertices like {2,5} V := On input 〈 G, k, s 〉, where s is a set of vertices of size k For every triple {u, v, w} of vertices: If {u, v}, {u, w}, {v, w}, are all edges in G : If none of u, v, or w are in s, reject. Otherwise, accept. Running time = O(n 3 ) ✔ 1 23 4 5 67

24 CLIQUE IND SET VERTEX COVER SAT 3SAT SUBGRAPH Cover for triangles Step 2: Some NP -complete L reduces to TRICOVER TRICOVER = { 〈 G, k 〉 : G has a k -cover for triangles } Some vertex in every triangle is covered Some endpoint of every edge is covered VC = { 〈 G, k 〉 : G has a k -vertex cover }

25 Cover for triangles Step 3: Reduce VC to TRICOVER TRICOVER = { 〈 G’, k’ 〉 : G’ has k’ -cover for triangles } VC = { 〈 G, k 〉 : G has a k -vertex cover (for edges) } Idea: Replace edges by triangles GG’G’ vertex-cover in G cover for triangles in G’

26 Cover for triangles Step 3: Reduce VC to TRICOVER R := On input 〈 G, k 〉, where G has n vertices and m edges Construct the following graph G’ : G’ has n + m vertices v 1,..., v n, and u ij for every edge {v i, v j } of G For every edge {v i, v j } of G, include the edges {v i, v j }, {v i, u ij }, {v j, u ij } in G’ Output 〈 G’, k 〉. Running time = O(m) m = number of edges in G

27 Cover for triangles Step 4: Argue that the reduction is correct GG’G’ 〈 G, k 〉 ∈ VC 〈 G’, k 〉 ∈ TRICOVER G has a k -vertex cover CC is a k -triangle cover of G’ Old triangles from G are covered New triangles in G’ also covered ✔

28 Cover for triangles Step 4: Argue that the reduction is correct GG’G’ 〈 G, k 〉 ∈ VC 〈 G’, k 〉 ∈ TRICOVER G has a k -vertex cover C’G’ has a k -vertex cover C Some vertices in C may not come from G ! But we can move them and still cover the same triangle ✔ C’ is obtained after moving some vertices of C Since C’ covers all triangles in G’, it must cover all edges in G ✔

29 Coloring CSCI 3230 CSCI 2110 CSCI 3160 CSCI 3130 Suppose you need to schedule exams on same day in 3 time slots YRB 10 30 -12 30 1 30 -3 30 4 30 -6 30 CSCI 3190 Some people are enrolled in multiple classes, so there may be conflicts Task: Schedule the exams so there are no conflicts

30 Coloring Given a graph, we want to color the vertices so every edge has endpoints of different colors G YRB This is called a valid 3-coloring 3COL = { 〈 G 〉 : G has a valid 3-coloring } 3COL is NP -complete

31 Coloring Step 1: 3COL is in NP What is a solution for 3COL ? A solution s is a coloring of vertices like {1B,2R,3Y,4R,5B} V := On input 〈 G, s 〉 For every edge {u, v} of G : If u and v are assigned same color in s, reject. Otherwise, accept. Running time = O(m) ✔ G 12 3 4 5

32 CLIQUE IND SET VERTEX COVER SAT 3SAT SUBGRAPH Coloring Step 2: Some NP -complete L reduces to 3COL 3COL = { 〈 G 〉 : G has a valid 3-coloring } 3COL does not look like any of these problems In such a case it is a good idea to start with 3SAT

33 Coloring Step 3: Reduce 3SAT to 3COL 3COL = { 〈 G 〉 : G has a valid 3-coloring } 3SAT = { 〈  〉 :  is a 3CNF that has a satisfying assignment } Idea: Assignment of  Coloring of G Part I: 3 special vertices T (true), F (false), and X T F X G

34 Coloring Part 2: For each variable x i xixi X xixi Either x i has color of T and x i has color of F Or x i has color of F and x i has color of T Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF TFFTFT

35 Coloring To “encode” the clauses of , we need a gadget Can be colored if and only if at least one literal is colored T T x1x1 x2x2 x3x3 x y z If x or y is colored T, z can be colored T If x and y are colored F, z must be colored F Part 3: For each clause like (x 1 ∨ x 2 ∨ x 3 )

36 Coloring reduction: An example Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF T F F T F T

37 Coloring reduction: An example Example: (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF T F F T F T

38 Coloring Step 3: Reduce 3SAT to 3COL R := On input 〈  〉, where  is a 3CNF: Construct the following graph G : Add 3 special vertices T, F, X connected by a triangle. For every variable x i of , add vertices x i and x i and include the triangle x i, x i, X. Output 〈 G 〉. Running time = O(m + n) n = number of variables m = number of clauses For every clause u ∨ v ∨ w of , connect u, v, w, and T using the gadget below. T u v w

39 Coloring Step 4: Argue that the reduction is correct 〈  〉 ∈ 3SAT  has a SAT assignment a ✔ (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF 〈 G 〉 ∈ 3COL G has a valid 3-coloring Each literal gets “color” as in a Each clause gadget contains a true literal, so it can be colored

40 Coloring Step 4: Argue that the reduction is correct 〈  〉 ∈ 3SAT  has a SAT assignment ✔ (x 1 ∨ x 1 ∨ x 2 ) ∧ (x 1 ∨ x 2 ∨ x 3 ) x1x1 x1x1 x2x2 x2x2 x3x3 x3x3 X TF 〈 G 〉 ∈ 3COL G has a valid 3-coloring c Each variable gets value as in G Since each clause gadget is colored properly, each clause must contain a true literal x i = true, if node x i has same color as T false, if node x i has same color as F


Download ppt "CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong The Cook-Levin."

Similar presentations


Ads by Google