Recitation 10 - Reductions and P vs. N P Orit Moskovich Gal Rotem Tel Aviv University December 23, 2015 Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 1 / 31
Overview 1 More Reductions... 2 P and N P 3 N P and verifiability Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 2 / 31
Example Example 1 { Every n-state machine M either: } B = (n, m) (1) halts on ε in less than m steps or (2) doesn t halt on ε Prove that B / R. Proof. ( ) Note: Given n, there exists some m such that (n, m ) B (why?) We show a reduction H TM,ε B. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 3 / 31
Example Proof (Cont.) Assume by contradiction that B R and let M B be a TM that decides it. Pseudocode M deciding H TM,ε On input M 1 m = 1, n = Q M 2 While(True): 3 Run M B on (n, m): If M B accepts, break 4 else, m = m + 1 5 Run M on ε for m steps 6 If M halts, accept; Otherwise, reject Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 4 / 31
Example Correctness By ( ), the loops ends, and finds m such that (n, m) B Since M is an n-states TM, and (n, m) B, either: (1) M halts on ε in less than m steps or (2) M doesn t halt on ε Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 5 / 31
Computational Histories Definition 2 Let M be a TM and w an input string. An accepting (rejecting) computation history for M on w is a sequence of configurations: Where: # } {{} # C 1 }{{} 1 C 1 is the start configuration for M on w C R 2 #... # } {{ } C l 2 Each C i+1 legally follows from C i according to the rules of M 3 C l is an accepting (rejecting) configuation for M Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 6 / 31
Example - Computational Histories Example 3 Let WW = {ww w Σ }. Let P WW = { P P is a PDA that accepts some string w WW }. Use computational histories to prove that P WW / R. Proof. We show a reduction A TM m P WW. How? Given M, w we build a PDA P such that: P accepts some string of the form h$h$ M accepts w. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 7 / 31
Example - Computational Histories Mapping Reduction f from A TM to P WW On input M, w 1 Construct the following PDA P: P = On input #C 1 #C R 2 #... #C l $ #C 1 #C R 2 #... #C l $: 1. Push C 1 to stack while confirming that it is the initial configuration for M(w) 2. For each configuration C 2i, until first $ sign: 3. Pop C 2i 1 from stack and verify that C 2i legally follows from C 2i 1 4. Skip C 1, Push C 2 to stack 5. For each configuration C 2i+1, until second $ sign: 6. Pop C 2i from stack and verify that C 2i+1 legally follows from C 2i 7. Verify that C l is an accepting configuration for M(w) 8. If all tests passed, accept Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 8 / 31
Example - Computational Histories Correctness If M, w A TM, then there exists an accepting computation history h of M on w. Therefore, P accepts h$h$, and thus, P P WW. If P P WW, i.e., P accepts h$h$ for some string h. Then, h must be an accepting computation history of M on w (why?). Therefore, M, w A TM. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 9 / 31
Collatz Conjecture Example 4 Let f (n) = { 3n + 1 if n 1 (mod 2) n/2 if n 0 (mod 2) If you start with an integer n and iterate f, you obtain a sequence n, f (n), f (f (n)),... Stop if you ever hit 1. For example, if n = 17, you get the sequence 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. Extensive computer tests have shown that every starting point between 1 and a large integer gives a sequence that ends in 1. Collatz Conjecture: all positive starting points end up at 1. Suppose that A TM was decidable by a TM H. Use H to describe a TM that prints the answer to the Collatz conjecture. In other words, show CC A TM. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 10 / 31
Collatz Conjecture Pseudocode M deciding CC 1 Construct the TM M 1 (calculates the series): M 1 = On input n: 1. c = n 2. While(True): 3. If c == 1, accept 4. c = f (c) 2 Construct the TM M 2 (finds n that contradicts the conjecture): M 2 = On input x: 1. For n = 2, 3,...: 2. If H(M 1, n) rejects, accept 3 Run H on M 2, ε 4 If H accepts, the conjecture is wrong; If H rejects, the conjecture is correct Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 11 / 31
P vs. N P Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 12 / 31
P vs. N P Definition 5 P is the set of languages decidable in polynomial time on deterministic TMs: P = c>0 DTIME(n c ) Definition 6 N P is the set of languages decidable in polynomial time on non-deterministic TMs: N P = c>0 NDTIME(n c ) Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 13 / 31
Verifiability and N P Definition 7 Algorithm V is a verifier for a language L, if x L c {0, 1}. V (x, c) = 1 x / L c {0, 1}. V (x, c) = 1 Theorem 8 A language L N P it has a polynomial time verifier (! ) We measure the time of the verifier only in terms of x, not c. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 14 / 31
Boolean Formulas Definition 9 A Boolean formula is an expression built from: Boolean variables, having one of two values: True 1 False 0 Boolean operations: and or not Examples: 1 0 = 0 1 0 = 1 1 0 = 1 φ = (x y) (y z) Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 15 / 31
Satisfiability Definition 10 A Boolean assignment, V, for a formula φ, is a function from the set of variables of φ to {0, 1}. Example: V (x) = 1, V (y) = 0, V (z) = 0 Definition 11 A formula is satisfiable, if some Boolean assignment to its variables, makes the formula evaluate to 1. Example: φ = (x y) (y z) V (φ) = (V (x) V (y)) (V (y) V (z)) = (1 0) (0 0) = = (1 0) (1 1) = 1 }{{}}{{} 0 1 Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 16 / 31
Satisfiability Example: φ = (x y) (x y) (x y) (x y) Is φ satisfiable? Let s try V (x) = 1, V (y) = 1. V (φ) = (1 1) (1 1) (1 1) (1 1) = = (1 1) (1 1) (1 1) (0 0) = 0 }{{} 0 For any assignment V (x) = v x, V (y) = v y V (φ) = 0. Question How many possible assignments exist for a Boolean formula φ with n variables? Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 17 / 31
SAT Definition 12 SAT = { φ φ is a satisfiable Boolean formula} Theorem 13 SAT N P Proof. A polynomial time verifier, where the witness is the assignment: Verifier V SAT for SAT On input φ, V 1 Replace each variable in φ according to V 2 Evaluate V (φ) 3 If V (φ) = 1, accept; Otherwise, reject Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 18 / 31
SAT Correctness Verifiability: If φ is satisfiable, then there exists a witness V = (1, 0, 0,...) that satisfies φ If φ is not satisfiable, then no assignment V can satisfy φ Polynomial time: Denote by m the number of clauses in φ Denote by n the number of variables in φ V SAT runs in O(n m) time Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 19 / 31
CNF Definition 14 A literal is a variable or negated variable: x or x A clause is several literals joined by s: (x 1 x 2 x 3 ) Definition 15 A Boolean formula is in conjunctive normal form (CNF) if it consists of clauses, connected with s. Example: (x 1 x 2 ) (x 2 x 3 x 4 x 7 ) Definition 16 A Boolean formula is in k-cnf form, if it is a CNF formula, and all clauses have k literals. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 20 / 31
3SAT Definition 17 3SAT = { φ φ is a satisfiable 3CNF formula} Theorem 18 3SAT N P Proof. A polynomial time verifier, where the witness is the assignment: Verifier V 3SAT for 3SAT On input φ, V 1 Replace each variable in φ according to V 2 Evaluate V (φ) 3 If V (φ) = 1, accept; Otherwise, reject Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 21 / 31
3SAT Questions 3SAT P? What about 3SAT = { φ φ is not satisfiable} Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 22 / 31
Clique Definition 19 A clique in an undirected graph G = (V, E) is a subgraph, where every two nodes are connected by an edge. Formally, A V is a clique if v 1 v 2 A. (v 1, v 2 ) E. Definition 20 A k-clique is a clique of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique Definition 19 A clique in an undirected graph G = (V, E) is a subgraph, where every two nodes are connected by an edge. Formally, A V is a clique if v 1 v 2 A. (v 1, v 2 ) E. Definition 20 A k-clique is a clique of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique Definition 19 A clique in an undirected graph G = (V, E) is a subgraph, where every two nodes are connected by an edge. Formally, A V is a clique if v 1 v 2 A. (v 1, v 2 ) E. Definition 20 A k-clique is a clique of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique Definition 19 A clique in an undirected graph G = (V, E) is a subgraph, where every two nodes are connected by an edge. Formally, A V is a clique if v 1 v 2 A. (v 1, v 2 ) E. Definition 20 A k-clique is a clique of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 23 / 31
Clique Definition 21 CLIQUE = { G, k G is an undirected graph with a k-clique} Theorem 22 CLIQUE N P Proof. A polynomial time verifier, where the witness is the clique: Verifier V CLIQUE for CLIQUE On input G, k, c 1 Verify that c is a set of k nodes in G 2 Verify that G contains all edges between nodes in c 3 If both tests pass, accept; Otherwise, reject Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 24 / 31
Independent Set Definition 23 An independent set (IS) in a graph is a set of nodes, no two of which are linked by an edge. Formally, A V is an IS if v 1 v 2 A. (v 1, v 2 ) / E. Definition 24 A k-is is an independent set of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set Definition 23 An independent set (IS) in a graph is a set of nodes, no two of which are linked by an edge. Formally, A V is an IS if v 1 v 2 A. (v 1, v 2 ) / E. Definition 24 A k-is is an independent set of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set Definition 23 An independent set (IS) in a graph is a set of nodes, no two of which are linked by an edge. Formally, A V is an IS if v 1 v 2 A. (v 1, v 2 ) / E. Definition 24 A k-is is an independent set of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set Definition 23 An independent set (IS) in a graph is a set of nodes, no two of which are linked by an edge. Formally, A V is an IS if v 1 v 2 A. (v 1, v 2 ) / E. Definition 24 A k-is is an independent set of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 25 / 31
Independent Set Definition 25 IS = { G, k G is an undirected graph with a k-is} Theorem 26 IS N P Proof. A polynomial time verifier, where the witness is the independent set... Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 26 / 31
Vertex Cover Definition 27 A vertex cover (VC) in a graph is a set of nodes, where every edge of G touches one of those nodes. Formally, A V is a VC if (v 1, v 2 ) E. v 1 A or v 2 A. Definition 28 A k-vc is a vertex cover of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover Definition 27 A vertex cover (VC) in a graph is a set of nodes, where every edge of G touches one of those nodes. Formally, A V is a VC if (v 1, v 2 ) E. v 1 A or v 2 A. Definition 28 A k-vc is a vertex cover of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover Definition 27 A vertex cover (VC) in a graph is a set of nodes, where every edge of G touches one of those nodes. Formally, A V is a VC if (v 1, v 2 ) E. v 1 A or v 2 A. Definition 28 A k-vc is a vertex cover of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover Definition 27 A vertex cover (VC) in a graph is a set of nodes, where every edge of G touches one of those nodes. Formally, A V is a VC if (v 1, v 2 ) E. v 1 A or v 2 A. Definition 28 A k-vc is a vertex cover of size k. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 27 / 31
Vertex Cover Definition 29 VC = { G, k G is an undirected graph with a k-vc} Theorem 30 VC N P Proof. A polynomial time verifier, where the witness is the set of vertices covering G... Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 28 / 31
VC vs. IS Theorem 31 Let G = (V, E) be an undirected graph. Let A V. Then, A is a VC V \ A is an IS. Proof. Let A be a VC. Assume by contradiction that V \ A is not an IS. Therefore, v 1, v 2 V \ A. (v 1, v 2 ) E. But v 1, v 2 / A, and therefore (v 1, v 2 ) is not covered. Contradiction for A being a VC. Let V \ A be an IS. Assume by contradiction that A is not a VC. Therefore, v 1, v 2 / A. (v 1, v 2 ) E. But v 1, v 2 V \ A, and (v 1, v 2 ) E. Contradiction for V \ A being an IS. Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 29 / 31
Clique vs. IS Theorem 32 Let G = (V, E) be an undirected graph. Define H = (V, E ) to be the complement of G iff E = {(u, v) u, v V and (u, v) / E}. Let A V. Then, A is a Clique in G A is an IS in H. Proof. A is a Clique in G v 1 v 2 A. (v 1, v 2 ) E v 1 v 2 A. (v 1, v 2 ) / E A is an IS in H Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 30 / 31
The End Courtesy of https://www.facebook.com/graphsofstuff/ Orit Moskovich and Gal Rotem (TAU) Recitation 10 - Reductions and P vs. NP December 23, 2015 31 / 31