<<

for Data Processing Lecture VIII: Intractable Problems–NP Problems

Alessandro Artale Free University of Bozen-Bolzano [email protected] of Computer Science http://www.inf.unibz.it/˜artale

2019/20 – First Semester MSc in Computational Data Science — UNIBZ

Some material (text, figures) displayed in these slides is courtesy of: Alberto Montresor, Werner Nutt, Kevin Wayne, Jon Kleinberg, Eva Tardos.

A. Artale Algorithms for Data Processing Definition. P = set of decision problems for which there exists a poly-time .

Problems and Algorithms – Decision Problems The Complexity Theory considers called Decision Problems. • s Decision• Problem. X Input encoded asX a finite“yes” binary string ; • Decision ProblemA : Is conceived asX a set of strings on whichs the answer to the is ; yes if s ∈ X Algorithm for a decision problemA s receives an input string , and no if s 6∈ X  ( ) =

A. Artale Algorithms for Data Processing Problems and Algorithms – Decision Problems The Complexity Theory considers so called Decision Problems. • s Decision• Problem. X Input encoded asX a finite“yes” binary string ; • Decision ProblemA : Is conceived asX a set of strings on whichs the answer to the decision problem is ; yes if s ∈ X Algorithm for a decision problemA s receives an input string , and no if s 6∈ X  ( ) =

Definition. P = set of decision problems for which there exists a poly-time algorithm.

A. Artale Algorithms for Data Processing Towards NP — Efficient Verification

• The issue here is the3-SAT contrast between finding a solution Vs. checking a proposed solution.I ConsiderI for example : We do not know a polynomial-time algorithm to find solutions; but Checking a proposed solution can be easily done in polynomial time (just plug 0/1 and check if it is a solution).

A. Artale Algorithms for Data Processing C s; t X • C s; t Definition.• An algorithms ( ) iss ∈ anX efficient certifier for a problemt if: |t|( ≤ p) runs|s| p in polynomial time, and C s; t yes For every string , we have if there exists a string (the certificate) such that ( ) ( () polynomial function), and ( ) = .

Towards NP — Efficient Verification/2 • X t Formalizes the ideaX that a solution to a problem can be checked efficiently. • Checkingt Algorithm for a problem : Checks whether is a solutions for a given“yes” input of problemX ; is called the certificate or witness that contains the evidence that is a instance of .

A. Artale Algorithms for Data Processing Towards NP — Efficient Verification/2 • X t Formalizes the ideaX that a solution to a problem can be checked efficiently. • Checkingt Algorithm for a problem : Checks whether is a solutions for a given“yes” input of problemX ; is called the certificate or witness that contains the evidence that is a instance of . C s; t X • C s; t Definition.• An algorithms ( ) iss ∈ anX efficient certifier for a problemt if: |t|( ≤ p) runs|s| p in polynomial time, and C s; t yes For every string , we have if there exists a string (the certificate) such that ( ) ( () polynomial function), and ( ) = .

A. Artale Algorithms for Data Processing TowardsC s; t NP — Efficient Verification/3X • C s; t Definition.• An algorithms ( ) iss ∈ anX efficient certifier for a problemt if: |t|( ≤ p) runs|s| p in polynomial time, and C s; t yes For every string , we have if there exists a string (the certificate) such that ( ) ( () polynomial function), and ( ) = . C s; t • s X An• efficient certifier ( ): t certificate s X • It is not deciding whether an inputbrutebelongs force to , but It is efficiently evaluating whether a given is a for to belong to . It can be used as an exponential algorithm.

A. Artale Algorithms for Data Processing We can observe⊆ immediately that: A X t  Theorem.C s; t ≡ APs NP. Proof. Let be a polynomial time algorithm that solves . Then, choose = and ( ) ( ).

The NP Class of Problems

Definition. NP = set of decision problems for which there exists an efficient certifier.

Note: NP stands for Nondeterministic Polynomial time.

A. Artale Algorithms for Data Processing The NP Class of Problems

Definition. NP = set of decision problems for which there exists an efficient certifier.

Note: NP stands for Nondeterministic Polynomial time.

We can observe⊆ immediately that: A X t  CTheorem.s; t ≡ APs NP. Proof. Let be a polynomial time algorithm that solves . Then, choose = and ( ) ( ).

A. Artale Algorithms for Data Processing Certifiers and certificates: satisfiability

SAT. Given a CNF formula Φ, does it have a satisfying truth assignment? 3-SAT. SAT where each clause contains exactly 3 literals.

Certificate. An assignment of truth values to the Boolean variables.

Certifier. Check that each clause in Φ has at least one true literal.

instance s x x x x x x x x x Φ = ( 1 ∨ 2 ∨ 3) ∧ ( 1 ∨ 2 ∨ 3) ∧ ( 1 ∨ 2 ∨ 4 )

certificate t x1 = true, x2 = true, x3 = false, x4 = false

Conclusions. SAT ∈ NP, 3-SAT ∈ NP.

7

A. Artale Algorithms for Data Processing ⊆ X ∈ Theorem.• NP ExpTime. C s; t X |t| ≤ p |s| Proof. Consider any problemp NP. • By definition, theres existsC as; poly-timet certifiert ( |t)|for ≤ p |,s where| ( ) for • some polynomialyes C s;()t ; yes To solve instance , run ( ) on strings with ( ) (exponentially many). Return iff ( ) returns for at least one of these potential certificates.

⊆ ⊆

P NP ExpTime P. Decision problems for which there exists a poly-time algorithm. NP. Decision problems for which there exists a poly-time certifier. ExpTime. ⊆Decision problems for which there exists an exponential-time algorithm.

Theorem. P NP.

A. Artale Algorithms for Data Processing ⊆ ⊆

P NP ExpTime P. Decision problems for which there exists a poly-time algorithm. NP. Decision problems for which there exists a poly-time certifier. ExpTime. ⊆Decision problems for which there exists an exponential-time algorithm.

Theorem. P ⊆NP. X ∈ Theorem.• NP ExpTime. C s; t X |t| ≤ p |s| Proof. Consider any problemp NP. • By definition, theres existsC as; poly-timet certifiert ( |t)|for ≤ p |,s where| ( ) for • some polynomialyes C s;()t ; yes To solve instance , run ( ) on all strings with ( ) (exponentially many). Return iff ( ) returns for at least one of these potential certificates. A. Artale Algorithms for Data Processing P Vs. NP

⊆ ⊆ Facts. 6 1 P NP ExpTime; 2 P = ExpTime, then: 6 6

either P = NP, or NP = ExpTime, or both.

A. Artale Algorithms for Data Processing The main question: P vs. NP

Does P = NP? [Cook 1971, Edmonds, Levin, Yablonski, Gödel] Is the decision problem as easy as the certification problem?

EXP EXP NP

P = NP P

If P = NP If P ≠ NP

If yes… Efficient algorithms for 3-SAT, TSP, VERTEX-COVER, FACTOR, … If no… No efficient algorithms possible for 3-SAT, TSP, VERTEX-COVER, …

Consensus opinion. Probably no.

15

A. Artale Algorithms for Data Processing Possible outcomes

P ≠ NP

“ I conjecture that there is no good algorithm for the traveling salesman problem. My reasons are the same as for any mathematical conjecture: (i) It is a legitimate mathematical possibility and (ii) I do not know.” — Jack Edmonds 1966

“ In my view, there is no way to even make intelligent guesses about the answer to any of these questions. If I had to bet now, I would bet that P is not equal to NP. I estimate the half-life of this problem at 25–50 more years, but I wouldn’t bet on it being solved before 2100. ” — Bob Tarjan (2002)

18 A. Artale Algorithms for Data Processing Possible outcomes

P = NP

“ I think that in this respect I am on the loony fringe of the mathematical community: I think (not too strongly!) that P=NP and this will be proved within twenty years. Some years ago, Charles Read and I worked on it quite bit, and we even had a celebratory dinner in a good restaurant before we found an absolutely fatal mistake. ” — Béla Bollobás (2002)

“ In my opinion this shouldn’t really be a hard problem; it’s just that we came late to this theory, and haven’t yet developed any techniques for proving computations to be hard. Eventually, it will just be a footnote in the books. ” — John Conway

20 A. Artale Algorithms for Data Processing Millennium prize

Millennium prize. $1 million for resolution of P ≠ NP problem.

22

A. Artale Algorithms for Data Processing NP-completeness and pop culture

Some writers for and . ・J. Steward Burns. M.S. in mathematics (Berkeley ’93). ・David X. Cohen. M.S. in computer science (Berkeley ’92). ・Al Jean. B.S. in mathematics. (Harvard ’81). ・Ken Keeler. Ph.D. in applied mathematics (Harvard ’90). ・Jeff Westbrook. Ph.D. in computer science (Princeton ’89).

Copyright © 1990, Matt Groening Copyright © 2000, Twentieth Century Fox 23

A. Artale Algorithms for Data Processing X X ∈

Definition. AY problem∈ Y is≤P saidX NP-complete if: 1 NP, and 2 ForX any NP, .

Thus, is as hard as any other NP problem!

NP-complete Problems

Fundamental Question: What are the hardest problems in NP?

A. Artale Algorithms for Data Processing NP-complete Problems

X Fundamental Question: What are the hardest problems in NP? X ∈

Definition. AY problem∈ Y is≤P saidX NP-complete if: 1 NP, and 2 ForX any NP, .

Thus, is as hard as any other NP problem!

A. Artale Algorithms for Data Processing Establishing NP-completeness

Remark. Once we establish first “natural” NP-complete problem, others fall like dominoes.

Recipe. To prove that Y ∈ NP-complete: ・Step 1. Show that Y ∈ NP. ・Step 2. Choose an NP-complete problem X. Step 3. Prove that . ・ X ≤ P Y

Proposition. If X ∈ NP-complete, Y ∈ NP, and X ≤ P Y, then Y ∈ NP-complete.

Pf. Consider any problem W ∈ NP. Then, both W ≤ P X and X ≤ P Y. By transitivity, . ・ W ≤ P Y by definition of by assumption Hence Y ∈ NP-complete. ▪ ・ NP-complete

30

A. Artale Algorithms for Data Processing NP-complete Problems/2 X ∈ X

Theorem.⇐ Let NPX-compIete∈ problems.X ∈ Then, is solvable in poIynomial time if and only⇒ if PX= NP. X ( •) If P = NPY, then∈ Y ≤PPbecauseX YNP. ( •) Let ⊆ be solvable in poIynomial time. Since ⊆is NP-complete, then • For any NP, , and thus is solvable in poIynomial time, thus NP P, and since we already proved that P NP, we finally obtain P = NP.

A. Artale Algorithms for Data Processing The “first” NP-complete problem

Theorem. [Cook 1971, Levin 1973] SAT ∈ NP-complete.

The Complexity of Theorem-Proving Procedures IX 1973 . 3 Stephen A. Cook

University of Toronto

Summary certain recursive set of strings on this alphabet, and we are interested It is shown that any recognition in the problem of finding a good 519.14 problem solved by a polynomial time- lower bound on its possible recog- bounded nondeterministic Turing nition times. We provide no such machine can be "reduced" to the pro- lower bound here, but theorem 1 will » . blem of determining whether a given give evidence that {tautologies} is propositional formula is a tautology. a difficult set to recognize, since « » , Here "reduced" means, roughly speak- many apparently difficult problems , - ing, that the first problem can be can be reduced to determining tau- . solved deterministically in polyno- tologyhood. By reduced we mean, mial time provided an oracle is roughly speaking, that if tauto- - available for solving the second. logyhood could be decided instantly ( , - From this notion of reducible, (by an "oracle") then these problems , , polynomial degrees of difficulty are could be decided in polynomial time. ). - defined, and it is shown that the In order to make this notion precise, . problem of determining tautologyhood we introduce query machines, which - , - has the same polynomial degree as the . - are like Turing machines with oracles : , , problem of determining whether the in [I]. . first of two given graphs is iso- , . - morphic to a subgraph of the second. A query machine is a multitape , Other examples are discussed. A with a distinguished . - method of measuring the complexity of tape called the query tape, and ( 1,2]), - proof procedures for the predicate three distinguished states called . ( , , calculus is introduced and discussed. the query state, yes state, and n._o_ , .) state, respectively. If M is a , - ( - Throughout this paper, a set of query machine and T is a set of ) , strings means a set of strings on strings, then a T-computation of M ( ) , , - some fixed, large, finite alphabet Z. is a computation of M in which « » ( - , .). - This alphabet is large enough to in- initially M is in the initial . clude symbols for all sets described state and has an input string w on f{n) g{n) , here. All Turing machines are deter- its input tape, and each time M ministic recognition devices, unless assumes the query state there is a f(n) ^ (g(n)+2)* g(n) < (f(n) +2)*. the contrary is explicitly stated. string u on the query tape, and « ». the next state M assumes is the . ( ) i. Tautologies and Polynomial Re- yes state if uET and the no state « - , Reducibility. if u~T. We think of an "oracle", , , ( , )», ( , ) — - , which knows T, placing M in the , . ( - Let us fix a formalism for yes state or no state. , , — the propositional calculus in , ; , - ). - , . which formulas are written as . - strings on I. Since we will - Definition . quire infinitely many proposition , . symbols (atoms), each such symbol A set S of strings is P-redu- 1. 500- will consist of a member of Z cible (P for polynomial) to a set . ( followed by a number in binary T of strings iff there is some ). notation to distinguish that query machine M and a polynomial 2. . symbol. Thus a formula of length Q(n) such that for each input string , - n can only have about n/logn w, the T-computation of M with in- ( ). distinct function and predicate put w halts within Q(Iwl) steps 3. , - symbols. The logical connectives (lwl is the length of w~ and ends . ( , , .) are & (and), v (or), and ~(not). 4. . ( in an accepting state iff wcS. ). 5. . ( ). The set of tautologies It is not hard to see that 6. 1 100 - (denoted by {tautologies}) is a P-reducibility is a transitive re- , - lation. Thus the relation E on . - .

-151- 29

A. Artale Algorithms for Data Processing 8.4 NP-Complete Problems 466 Chapter 8 NP and Computation! Intractability 467 for this consistent failure is that these problems simply cannot be solved in In 1971, Cook and Levin independently showed how to do this for very natural problems in 3gT. Maybe the most natural problem choice for a first polynomial time. NP-complete problem is the following Circuit Satisfiability Problem. To specify this problem, we need to make precise what we mean by a circuit. Consider the standard Boolean operators that we used to define the 8.4 NP-Complete Problems Satisfiability Problem: ^ (AND), V (oa), and -, (NOT). Our definition of a circuit In the absence of progress on the ~P = ~T question, people have turned to a is designed to represent a physical circuit built out of gates that implement related but more approachable question: What are the hardest problems in these operators. Thus we define a circuit K to be a labeled, directed acyclic N~p~. Polynomial-time reducibility gives us a way of addressing this question graph such as the one shown in the example of Figure 8.4. and gaining insight into the structure of NT. o The soarces in K (the nodes with no incoming edges) are labeled either Arguably the most natural way to define a "hardest" problem X is via the with one of the constants 0 or 1, or with the name of a distinct variable. following two properties: (i) X E N~P; and (ii) for all Y E 3~T, Y _

A. Artale Algorithms for Data Processing Circuit Satisfiability: The First NP-Complete Problem

Theorem.• [Cook 1971, Levin 1973] Circuit SatisfiabilityX ∈ is XNP≤P-complete.Circuit Satisfiability: [Proof• Sketch] n Show that given an arbitrary problem NP, then • Main Idea: Show that any1 algorithm that takes a fixed number of bits as input and produces a yes/no answer can be represented by a circuit. • This circuit should outputp n on precisely the inputs for which the algorithm outputs • yes. If the algorithm takes ( ) steps, then the circuit has polynomial size. We are not showing this construction but we see how it can be used in the proof.

A. Artale Algorithms for Data Processing Circuit Satisfiability: The First NP-Complete Problem/2 Theorem.• [CookX ∈ 1971, Levin 1973] Circuit Satisfiability is NP-complete. [Proof• Sketch/2] s ∈ X s n Since NP it has an efficient certifier, thus To determine whether , fort some input p nof size , weC s need; t to answer the • followingC question:s; t n p n s t • Is there a certificate of lengthC ( n) sop thatn ( ) = yes? • We view n ( ) as an algorithm on + ( ) bits: the input and thes certificate , and • Convertp n it to a polynomial-size circuit with + ( ) sources. t The first sources will be hard-codedC with the values of the bits in , and • sThe∈ X ( ) sources will be labeledC with variables representing the bits of ; these latter sources will be the inputs to . if and only if the circuit is satisfiable.

A. Artale Algorithms for Data Processing More hard computational problems

Garey and Johnson. Computers and Intractability. ・Appendix includes over 300 NP-complete problems. ・Most cited reference in computer science literature.

37

A. Artale Algorithms for Data Processing More hard computational problems

Aerospace engineering. Optimal mesh partitioning for finite elements. Biology. Phylogeny reconstruction. Chemical engineering. Heat exchanger network synthesis. Chemistry. Protein folding. Civil engineering. Equilibrium of urban traffic flow. Economics. Computation of arbitrage in financial markets with friction. Electrical engineering. VLSI layout. Environmental engineering. Optimal placement of contaminant sensors. Financial engineering. Minimum risk portfolio of given return. Game theory. Nash equilibrium that maximizes social welfare.

Mathematics. Given integer a1, …, an, compute Mechanical engineering. Structure of turbulence in sheared flows. Medicine. Reconstructing 3d shape from biplane angiocardiogram. Operations research. Traveling salesperson problem. Physics. Partition function of 3d Ising model. Politics. Shapley–Shubik voting power. Recreation. Versions of Sudoku, Checkers, Minesweeper, Tetris, Rubik’s Cube. Statistics. Optimal experimental design. 38

A. Artale Algorithms for Data Processing You NP-complete me

40

A. Artale Algorithms for Data Processing Graph k-Coloring While 2-Coloring (Bipartite Graphs) is a P-Time problem, checking whether a graph is 3-colorable is a hard problem. G k G u; v u v k Graph k-colorability. Given a graph and an integer assign a color to each node of so that if ( ) is an edge, then and are assigned different colors from the available colors.

Applications.• Graph colorabilityk is a problem that arises naturallyn whenever one is trying to allocate resources in the presence of conflicts. e.g., assign one of transmitting wavelengths to each of devices; but if two devices are sufficiently close to each other, then they need to be assigned different wavelengths to prevent interference.

A. Artale Algorithms for Data Processing • k

I n 8.7 Graphn Coloring Graph k-Coloring/2487 486 Chapter 8 NP and Computational Intractability Fact 1. There is not fixed constant so that every graph is k-colorable. • For example, take a set of nodes and join each pair of them by an edge, the resulting I Suppose, for example, that we have a collection of n processes on a (8.21) A graph G is 2-colorable if and only if it is bipartite.graph needs colors. Fact 2. No simple efficient algorithm for the 3-Coloring Problem exists. system that can run multiple jobs concurrently, but certain pairs of jobs This means we can use the algorithm from Section 3.4 to decide whether cannot be scheduled at the same time because they both need a particular The following graph is not 3-colorable but does not have a cicle of 4 nodes mutually an input graph G is 2-co!orable in O(m + n) time, whereconnected. n is the number of resource. Over the next k time steps of the system, we’d like to schedule nodes of G and m is the number of edges. ~. each process to run in at least one of them. Is this possible If we construct As soon as we move to k = 3 colors, things become much harder. No a graph G on the set of processes, joining two by an edge if they have a simple efficient algorithm for the 3-Coloring Problem suggests itself, as it did conflict, then a k-coloring of G represents a conflict-free schedule of the for 2-Coloring, and it is also a very difficult problem to reason about. For processes: all nodes colored j can be scheduled in step j, and there will example, one migtit initially suspect that any graph that is not 3-colorable will never be contention for any of the resources. contain a "proof" in the form of four nodes that are all mutually .adjacent Another well-known application arises in the design of compilers. Sup- (and hence would need four different colors)--but this is not true. The graph pose we are compiling a program and are trying to assign each variable in Figure 8.10, for instance, is not 3-colorable for a somewhat more subtle Figure 8.10 A graph that is to one of k registers. If two variables are in use at a common point in (though still explainable) reason, and it is possible to draw much more time, then they cannot be assigned to the same register. (Otherwise one not 3-colorable. complicated graphs that are not 3-colorable forA. Artale reasons that seem very hard to Algorithms for Data Processing would end up overwriting the other.) Thus we can build a graph G on state succinctly. the set of variables, ioining two by an edge if they are both in use at the same time. Now a k-coloring of G corresponds to a safe way of allocating In fact, the case of three colors is already a very hard problem, as we show variables to registers: All nodes colored j can be assigned to register j, now. since no two of them are in use at the same time. Proving 3-Coloring Is NP-Complete o A third application arises in wavelength assignment for wireless commu- nication devices: We’d like to assign one of k transmitting wavelengths (8’22) 3’Coloring is NP-complete: ..... to each of n devices; but if two devices are sufficiently close to each other, then they need to be assigned different wavelengths to prevent Proof. It is easy to see why the problem is in ~. Given G and k, one certificate interference. To deal with this, we build a graph G on the set of devices, that the answer is yes is simply a k-coloring: .One can verify in polynomial time ioining two nodes if they’re close enough to interfere with each other; that at most k colors are used, and that no pair of nodes joined by an edge a k-coloring of t~s graph is now an assignment of wavelengths so that receive the same color. any nodes assigned the same wavelength are far enough apart that in- terference won’t be a problem. (Interestingly, this is an application of Like the other problems in this section, 3-Coloring is a problem that is hard graph coloring where the "colors" being assigned to nodes are positions to relate at a superficial level to other NP-complete problems we’ve seen. So on the electromagnetic spectrum--in other words, under a slightly liberal once again, we’re going to reach all the way back to 3-SAT. Given an arbitrary instance of 3-SAT, with variables x ..... interpretation, they’re actually colors.) 1 xn and clauses C1 ..... Ck, we wi~ solve it using a black box for 3-Coloring. The beginning of the is quite intuitive. Perhaps the main power The Computational Complexity of Graph Coloring of 3-Coloring for encoding Boolean expressions lies in the fact that we can associate graph nodes with particular terms, and by joining them with edges What is the complexity of k-Coloring~- First of all, the case k = 2 is a problem we ensure that they get different colors; this can be used. to set one true and we’ve already seen in Chapter 3. Recall, there, that we considered the problem the other false. So with this in mind, we define nodes u and ~ corresponding of determining whether a graph G is bipartite, and we showed that this is i to each variable x and its negation ~. We also define three "special nodes" equivalent to the following question: Can one color the nodes of G red and i T, F, and B, which we refer to as True, False, and Base. blue so that every edge has one red end and one blue end~. But this latter question is precisely the Graph Coloring Problem in the case To begin, we join each pair of nodes vi, ~ to each other by an edge, and when there are k = 2 colors (i.e., red and blue) available. Thus we have argued we join both these nodes to Base. (This forms a triangle on vi, ~, and Base, for each i.) We also join True, False, and Base into a triangle. The simple graph that Theorem. Graph 3-coloring3-Coloring in an NP-complete is NP problem.-complete k ≤ 3 Graph 3-coloring is in NP. Certificate: a k-coloring of the graph. We can check in polynomial time whether and that every edge in the graph has endpoints with 3-SAT ≤P 3-COLORING 8.7 Graph Coloring 489 different colors. Chapter 8 NP and Computational Intractability 488 G False ~The top node can only be colored if one of u V2, or u31 Show that . 1, does not get the False color. Instance Construction. We first construct the following graph (here is the case with 3 variables):

Figure 8.12 Attaching a subgraph to represent the clause x v ~2.v x3. 1 Figure 8,11 The beginning of the reduction for 3-Coloring.

A. Artale Algorithms for Data Processing This six-node subgraph "attaches" to the rest of G at five existing nodesi G we have defined thus far is pictured in Figure 8.11, and it already has some True, False, and those corresponding to the three terms in the clause that we’re trying to represent (in this case, ~1, ~, and ~.) Now suppose that in some 3- useful properties. coloring of G all three of ~1, W22, and u~ are assigned the False color. Then the o In any B-coloring of G, the nodes vi and ~ must get different co, lots, and lowest two shaded nodes in the subgraph must receive the Base color, the three " shaded nodes above them must receive, respectWely, the False, Base, and True o In any 3-coloring of G, the nodes True, False, and Base must get all three colors, and hence there’s no color that can be assigned to the topmost shaded colors in some permutation. Thus we can refer to the three colors as the node. In other words, a 3-coloring in which none of ~, W22, or vB is assigned 2 True color, the False color, and the Base color, based on which of these the True color cannot be extended to a 3-coloring of this subgraph. three nodes gets which color. In particular, this means that for each i, Finally, and conversely, some hand-checking of cases shows that as long one of ui or u~ gets the True color, and the other gets the False color. For as one of ~, W22, or ~3 is assigned the True color, the ful! subgraph can be the remainder of the construction, we will consider the variable xi to 3-colored. " T only if the node vi gets be set to I in the given instance of ~-SK if and So from this, we can complete the construction: We start with the graph G assigned the True color. defined above, and for each clause in the 3-SAT instance, we attach a six-node So in summary, we now have a graph G in which any 3-coloring implicitly subgraph as shown in Figure 8.12. Let us call the resulting graph G’. determines a truth assignment for the variables in the 3-SAT instance. We now need to grow G so that only satisfying assignments can be extended to 3-colorings of the full graph. How should we do this~. 2 This argument actually gives considerable insight into how one comes up with this subgraph in As in other 3-SAT reductions, let’s consider a clause like xl v x~ v x3._ In the first place. The goal is to have a node like the topmost one that cann6t receive any color. So we the language of 3-colorings of G, it says, "At least one of the nodes vl, vz, or start by "plugging in" three nodes corresponding to the terms, all colored False, at the bottom. For v3 should get the True color." So what we need is a little subgraph that we can each one, we then work upward, pairing it off with a node of a known color to force the node above to have the third color. Proceeding in this way, we can arrive at a node that is forced to have any plug into G, so that any 3-co!oring that extends into this subgraph must have color we want. So we force each of the three different colors, starting from each of the three different the property of assigning the True color to at least one of u~, ~, or u~. Ittakes terms, and then we plug all three of these differently colored nodes into our topmost node, arriving some experimentation to find such a subgraph, but one that works is depicted at the impossibility. in Figure 8.12. • G 3-Coloring is NP-complete/2

• Extend so that there is a satisfying assignments if and only if8.7 the Graph full Coloring graph is 489 Chapter 8 NP and Computational Intractability 488 3-colorable.C x1 ∨ x2 ∨ x3 False ~The top node can only be To each set of 3 nodes in a Clause we a attach a 6-node graph.colored if one For of u1, example,V2, or u31 consider does not get the False color. the clause =

Figure 8.12 Attaching a subgraph to represent the clause x1 v ~2.v x3. Figure 8,11 The beginning of the reduction for 3-Coloring.

This six-node subgraph "attaches" to the rest of G at five existing nodesi G we have defined thus far is pictured in Figure 8.11, and it already has some True, False, and those corresponding to the three terms in the clause that we’re A. Artale trying to represent (in thisAlgorithms case, ~1, for ~, Data and Processing ~.) Now suppose that in some 3- useful properties. coloring of G all three of ~1, W22, and u~ are assigned the False color. Then the o In any B-coloring of G, the nodes vi and ~ must get different co, lots, and lowest two shaded nodes in the subgraph must receive the Base color, the three " shaded nodes above them must receive, respectWely, the False, Base, and True o In any 3-coloring of G, the nodes True, False, and Base must get all three colors, and hence there’s no color that can be assigned to the topmost shaded colors in some permutation. Thus we can refer to the three colors as the node. In other words, a 3-coloring in which none of ~, W22, or vB is assigned 2 True color, the False color, and the Base color, based on which of these the True color cannot be extended to a 3-coloring of this subgraph. three nodes gets which color. In particular, this means that for each i, Finally, and conversely, some hand-checking of cases shows that as long one of ui or u~ gets the True color, and the other gets the False color. For as one of ~, W22, or ~3 is assigned the True color, the ful! subgraph can be 3-colored. the remainder of the construction," T we will consideronly if the the node variable vi gets xi to be set to I in the given instance of ~-SK if and So from this, we can complete the construction: We start with the graph G assigned the True color. defined above, and for each clause in the 3-SAT instance, we attach a six-node So in summary, we now have a graph G in which any 3-coloring implicitly subgraph as shown in Figure 8.12. Let us call the resulting graph G’. determines a truth assignment for the variables in the 3-SAT instance. We now need to grow G so that only satisfying assignments can be extended to 3-colorings of the full graph. How should we do this~. 2 This argument actually gives considerable insight into how one comes up with this subgraph in As in other 3-SAT reductions, let’s consider a clause like xl v x~ v x3._ In the first place. The goal is to have a node like the topmost one that cann6t receive any color. So we the language of 3-colorings of G, it says, "At least one of the nodes vl, vz, or start by "plugging in" three nodes corresponding to the terms, all colored False, at the bottom. For v3 should get the True color." So what we need is a little subgraph that we can each one, we then work upward, pairing it off with a node of a known color to force the node above to have the third color. Proceeding in this way, we can arrive at a node that is forced to have any plug into G, so that any 3-co!oring that extends into this subgraph must have color we want. So we force each of the three different colors, starting from each of the three different the property of assigning the True color to at least one of u~, ~, or u~. Ittakes terms, and then we plug all three of these differently colored nodes into our topmost node, arriving some experimentation to find such a subgraph, but one that works is depicted at the impossibility. in Figure 8.12. 3-Coloring is NP-complete/3 • ⇐ G

• vi True False

• ( , Soundness) Suppose xi is 3-colorable. • Each node is assigned either the or the color (see first graph); True We set theG assignment to accordingly. • As⇒ we said above, there3-SAT must be in every clause at least one variable set to for • otherwise is not 3-colorable (a contradiction). ( , Completeness1 ) Let be satisfiable, then the resulting graph is 3-colorable. Can be showed by a case analysis and by setting to the True color the variable assigned to .

A. Artale Algorithms for Data Processing P or NP-complete

There are Problems in NP which are not known to be in P nor in the class of NP-complete problems.

Theorem [Ladner 1975] Unless P = NP, there exist problems in NP that are in neither P nor NP-complete. GRAPH-ISOMORPHISM INTEGER-FACTORIZATION

NP-intermediate. , , etc.

A. Artale Algorithms for Data Processing Asymmetry of NP

• s Observation. The definitiont of efficientC certification,s; t yes and hence of NP, is asymmetric. YES instances. An input string is a yes instance if and only if there existsa • polynomially bounded so thats ( ) = . By negating thet above statement weC s get:; t no NOI instances. An input string is a no instance if and only if for all polynomially bounded , it is the case that ( ) = . For a no instance, no short proof is guaranteed by the definition.

A. Artale Algorithms for Data Processing SAT UN-SAT

Asymmetry of NP: vs.

UN-SAT

SAT .UN-SAT Given a CNF formula Φ, is thereNO satisfying truth assignment? • • vs. Can prove a CNF formula is satisfiable by specifying an assignment (certificate). How could we prove that a formula is not satisfiable?

A. Artale Algorithms for Data Processing ComplementX Problems X yes no Definition. Given a decision problem , its , denoted as , is the same problem with the and answers reversed. • SAT UN-SAT The• followingVERTEX-COVER are examplesNO-VERTEX-COVER of complementary problems: • Vs. Vs. etc. co-NP. Complements of decision problems in NP.

A. Artale Algorithms for Data Processing P Vs. co-P

X ∈ AX X Theorem. The class PAXis closed underA complementation,yes/no i.e., P= co-P. Proof. Let XP and be a polynomial algorithm solving the decision problem . Then, the algorithm that runs and inverts the answers, is a polynomial algorithm for .

A. Artale Algorithms for Data Processing • Open Question. Does NP = co-NP? Consensus opinion: no.

NP Vs. co-NP X ∈ X ∈ • X s ∈ X Observation. Whent NP it is notC s so; t clearno to see whether NP. Ihas a different nature: An input string if and only ifC for all polynomiallyC X boundedI , it is the case that ( )there = exists. t for all t It is not enough to invert the answer of the efficient certifier to get a certifier for . The critical point is the shift from to .

A. Artale Algorithms for Data Processing NP Vs. co-NP X ∈ X ∈ • X s ∈ X Observation. Whent NP it is notC s so; t clearno to see whether NP. Ihas a different nature: An input string if and only ifC for all polynomiallyC X boundedI , it is the case that ( )there = exists. t for all t It is not enough to invert the answer of the efficient certifier to get a certifier for . The critical point is the shift from to . • Open Question. Does NP = co-NP? Consensus opinion: no.

A. Artale Algorithms for Data Processing NP Vs. co-NP/2

• Open Question. Does NP = co-NP? Consensus opinion:6 no. 6

Theorem.• If NP = co-NP, then P = NP. Proof. We show the contrapositive, i.e., if P = NP, then, NP = co-NP. Since P is closed under complementation, then, if P = NP, then, NP would be closed under complementation as well.

A. Artale Algorithms for Data Processing ∩

Good Characterizations: The Class NP co-NP

∩ • X

Good Characterization.I yes [Edmonds 1965] NP co-NP. If problemI no is in both NP and co-NP, then: • for a instance, there is a succinct certificate; for a instance, there is a succinct disqualifier. Problems for wich there is always a nice certificate for the solution.

A. Artale Algorithms for Data Processing ∩

Good Characterizations: The Class NP co-NP/2 ⊆ ∩

Observation. P NP co-NP. ∩ • Open• Question. Does P = NP co-NP? good characterization Mixed opinions. Many examples where problem found to have a nontrivial but only years later discovered to be in P.

A. Artale Algorithms for Data Processing Primality testing is in NP ∩ co-NP

Theorem. [Pratt 1975] PRIMES ∈ NP ∩ co-NP.

SIAM J. COMPUT. Vol. 4, No. 3, September 1975

EVERY PRIME HAS A SUCCINCT CERTIFICATE* VAUGHAN . PRATTf

Abstract. To prove that a number n is composite, it suffices to exhibit the working for the multiplica- tion of a pair of factors. This working, represented as a, string, is of length bounded by a polynomial in log n. We show that the same property holds for the primes. It is noteworthy that almost no other set is known to have the property thatshort proofs for membership or nonmembership exist for all candidates without being known to have the property that such proofs are easy to come by. It remains an open problem whether a prime n can be recognized in only log n operations of a Turing machine for any fixed The proof system used for certifying primes is as follows. AXIOM. (x, y, 1). INFERENCE RULES. R1 (p, x, a), q (p, x, qa) provided xtp- 1)/q (mod p) and ql(P 1). R2: (p,x,p- 1)p- providedxp- ,___ (modp). THEOREM 1. p is a theorem p is a prime. THEOREM 2. p is a theorem p has a proof of [4 log p lines.

Key words, primes, membership, nondeterministic, proof, NP-complete, computational complexity 1. Proofs. We know of no efficient method that will reliably tell whether a given number is prime or composite. By "efficient", we mean a method for which the time is at most a polynomial in the length of the number written in positional 52 notation. Thus the cost of testing primes and composites is very high. In contrast, A. Artale the cost of selling composites (persuading a potentialAlgorithmscustomer for Datathat you Processinghave one) is very low--in every case, one multiplication suffices. The only catch is that the salesman may need to work overtime to prepare his short sales pitch; the effort is nevertheless rewarded when there are many customers. At a meeting of the American Mathematical Society in 1903, Frank Cole used this property of composites to add dramatic impact to the presentation of his paper. His result was that 267 1 was composite, contradicting a two-centuries- old conjecture of Mersenne. Although it had taken Cole "three years of Sundays" to find the factors, once he had done so he could, in a few minutes and without uttering a word, convince a large audience of his result simply by writing down the arithmetic for evaluating 267 and 193707721 x 761838257287. We now show that the primes are to a lesser extent similarly blessed; one may certify p with a proof of at most [4 log2 p] lines, in a system each of whose inference rules are readily applied in time O(log 3 p). The method is based on the Lucas-Lehmer heuristic (Lehmer (1927)) for testing primeness. In the system to be described, theorems take one of two forms: (i) "p", asserting.that p is prime, or (ii) "(p, x, a)", asserting that we are making progress towards establishing that p is a prime and that x is a primitive root (mod p); a is a progress indicator * Received by the editors May 24, 1974. f Project MAC Massachusetts Institute of Technology, Cambridge, Massachusetts 02139. This research was supported by the National Science Foundation under Grant GJ-34671. Edmonds (1965) discusses a similar situation with a "supervisor and his hard-working assistant". 214 Primality testing is in P

Theorem. [Agrawal–Kayal–Saxena 2004] PRIMES ∈ P.

Annals of Mathematics, 160 (2004), 781–793

Annals of Mathematics, 160 (2004), 781–793

PRIMES is in P

By Manindra Agrawal, Neeraj Kayal, and Nitin Saxena*

PRIMESAbstract is in P

We presentBy Manindra an unconditional Agrawal, deterministic Neeraj Kayal, polynomial-timeand Nitin Saxena algorithm* that determines whether an input number is prime or composite. Abstract 1. Introduction We present an unconditional deterministic polynomial-time algorithm that determinesPrime numbers whether are an of input fundamental number is importance prime or composite. in mathematics in general, and number theory in particular. So it is of great interest to study different properties of prime numbers. Of special interest are those properties that 1. Introduction allow one to determine efficiently if a number is prime. Such efficient tests are also usefulPrime in numbers practice: are a of number fundamental of cryptographic importance protocols in mathematics need large in general, prime 54 numbers.and number theory in particular. So it is of great interest to study different Let PRIMES denote the set of all prime numbers. The definition of prime A. Artale properties of prime numbers. Of specialAlgorithms interest are for those Data properties Processing that numbersallow one already to determine gives a e wayfficiently of determining if a number if isa numberprime. Suchn is in effi PRIMES:cient tests try are dividing n by every number m √n—if any m divides n then it is compos- also useful in practice: a number≤ of cryptographic protocols need large prime ite,numbers. otherwise it is prime. This test was known since the time of the ancient Greeks—itLet PRIMES is a specialization denote the ofset the of allSieve prime of numbers.Eratosthenes The(ca. definition 240 BC) of prime that generatesnumbers alreadyall primes gives less a waythan ofn. determining The test, ifhowever, a number isn ineisffi incient: PRIMES: it takes try Ωdividing(√n) stepsn by to every determine number if nmis prime.√n—if An any effimcientdivides testn shouldthen it need is compos- only a polynomial (in the size of the input≤ = log n ) number of steps. A property ite, otherwise it is prime. This test was⌈ known⌉ since the time of the ancient that almost gives an efficient test is Fermat’s Little Theorem: for any prime Greeks—it is a specialization of the Sieve of Eratosthenesp 1 (ca. 240 BC) that number p, and any number a not divisible by p, a − = 1 (mod p). Given an generates all primes less than n. The test,n 1 however, is inefficient: it takes a and n it can be efficiently checked if a − = 1 (mod n) by using repeated Ω(√n) steps to determine if n isth prime. An efficient test should need only a squaringpolynomial to compute (in the size the of (n the1) inputpower = log of na.) However,number of it steps. is not A a property correct − ⌈ ⌉ testthat sincealmost manygives composites an efficientn testalso is satisfy Fermat’s it for Little some Theorem:a’s (all a for’s in any case prime of Carmichael numbers [Car]). Nevertheless, Fermat’sp 1 Little Theorem became number p, and any number a not divisible by p, a − = 1 (mod p). Given an the basis for many efficient primality tests.n 1 a and n it can be efficiently checked if a − = 1 (mod n) by using repeated squaringSince tothe compute beginning the of ( complexityn 1)th power theory of ina. the However, 1960s—when it is not the a notions correct − oftest complexity since many were composites formalizedn andalso various satisfy complexity it for some classesa’s (all werea’s defined— in case of Carmichael numbers [Car]). Nevertheless, Fermat’s Little Theorem became the*The basis last for two many authors effi werecient partially primality supported tests. by MHRD grant MHRD-CSE-20010018. Since the beginning of complexity theory in the 1960s—when the notions of complexity were formalized and various complexity classes were defined—

*The last two authors were partially supported by MHRD grant MHRD-CSE-20010018. COMPLEXITY DIAGRAM Definitions H The Comlexity Classes NONE = • ∅ PCP NC0 = Functions computable by constant-depth, bounded-fanin circuits. • AC0 = Class of decision problems solvable by a nonuniform family of Boolean circuits, • with polynomial size, depth O(logi(n)), and unbounded fanin. REG = DSP ACE(O(1)): The decision problems that can be solved in constant space • NC1 = Class of decision problems solvable by a nonuniform family of Boolean circuits, • with polynomial size, depth O(log(n)), and fan-in 2. QBF CFL = Context-Free Languages • P SP ACE = NP SP ACE AC1 = Class of decision problems solvable by a nonuniform family of Boolean circuits, GEO • with polynomial size, depth O(log(n)) L = Class of decision problems solvable by a Turing machine restricted to use an SSAT • amount of memory logarithmic in the size of the input. NL = coNL Class of decision problems solvable by a nondeterministic Turing machine • CFL MEM restricted to use an amount of memory logarithmic in the size of the input. − NC = AC: Decidable in polylogarithmic time on a parallel computer with a polynomial • number of processors. INT F AC CSL = NLINSP ACE The class of languages generated by context-sensitive grammars. • P = P olysize(uniform) = The class of decision problems solvable in polynomial time by T AUT OLOGIE • a Turing machine. NP = Nondeterministic Polynomial-Time • SAT coNP = Complement of NP • co NP NP P SP ACE = NP SP ACE = AP = AP P = IP • − HAMILT ON CIRC nk EXPTIME = k DT IME(2 ) − • ∈N nk NEXPTIME =S k NTIME(2 ) MAX CUT • ∈N REC= Class ofS decidable Problems − • RE is the class of decision problems for which a yes“ answer can be verified by a BIN P ACKING ” • Turing machine in a finite amount of time. (If the answer is no,“ on the other hand, − ” the machine might never halt.) CVP P Some Missing Classes Horn SAT EEXPTIME • − NEEXPTIME • NAND CVP EXP SP ACE − • BPP CLIQUE • BQP • CFL MEM The Languages − n A = x x a ∗ REG • { | ∈ { } } ∈ GIP AnBn = anbn n 1 CFL • { | ≥ } ∈ AnBnCn = anbncn n 1 CSL NC = AC TSP • { | ≥ } ∈ BIN P ACKING =Objects of different volumes must be packed into a finite number of • bins of− capacity V in a way that minimizes the number of bins used. NP c ∈ − 2 GLP DT := i Φ1is total / RE AC • { | i } ∈ CHECKERS = The generalized version of the game EXPTIME c P RIMES • ∈ − CHESS = The generalized version of the game chess EXPTIME c • ∈ − CFL MEM = Context Free Grammar Membership • − 2 CLIQUE = If a graph contains a clique of at least a given size k. NP c NC • ∈ − COP Y = uv u = v • { | } CVP = Circuit Value Problem P c • ∈ − – NAND CVP = CVP only using NAND-components P − ∈ 1 GAP = P AT H = D, s, t Dir. Graph D has path from sto t NL c AC • {h i | } ∈ − RE 3 SAT – UGAP = GAP in an undericted graph L c ∈ − − – T REE GAP = GAP in a tree (DAG) L c − ∈ − GEO P SCACE c 2 SAT • ∈ − − GIP = Graph isomorphism problem: Determining whether two graphs are isomorphic NP • ∈ CFL GAP GLP = (A, b) Zm,n Zm x Zn : Ax b NP c • { ∈ × |∃ ∈ ≤ } ∈ − GO = The generalized version of the japanese game Go EXPTIME c NL • ∈ − 2 SAT H := i, x x dom(Φ1) RE c − • {h i | ∈ i } ∈ − L – H = i, x x / H / RE UGAP {h i | ∈ } ∈ HAMILT ON CIRC = If A graph contains a hamilton circle. NP c • − ∈ − INT F AC = integer factorization is the process of breaking down a composite number 1 • NC into smaller non-trivial divisors, which when multiplied together equal the original integer. NP co NP n n n ∈ ∩ − MAX CUT = The Maximum Cut of a Graph. NP c A B C • − ∈ − 0 P ALINDROME = if a word is a palindrome. CFL AC • ∈ P ALINDROME P ARIT Y = a 0, 1 ∗ #1 is odd REG • { ∈ { } | } ∈ PCP = Post correspondence problem NP c REG U1V • ∈ − P LANSAT = set off all strings s L∗ such that s is the statement of a solvable 0 • problem. NEXPTIME c (Without⊆ certain restrictions the problem is NC n EXP SP∈ ACE c.) − A ∈ − P RIMES = Determining whether an input number is prime. P • ∈ QBF = Satisfiability problem for quantified boolean formula P SP ACE c COPY • ∈ − REV ERSI = Generalized Version of the board game. P SP ACE c • ∈ − P ARIT Y SAT = Boolean satisfiability problem NP c • ∈ − – 2 SAT = SAT with CNF with 2 variables per clause NL c − ∈ − T REE GAP – 2 SAT = x x / 2 SAT NL c − { | ∈ − } ∈ − − – 3 SAT = SAT with CNF with 3 variables per clause NP c − ∈ − – Horn SAT = SAT with a conjunction of Horn clauses. P c ST RONG CONNECT − ∈ − – SSAT = Probabilistic satisfiability problem P SP ACE c − ∈ − ST RONG CONNECT NL • − ∈ T AUT OLOGY = If a given boolean formula is a tautology. co NP c • ∈ − TSP = Traveling sales person NP c • ∈ − U1V = u1v u = v REV ERSI • { || | | |} Relations Unsolved Problems NL EXPTIME • This⊆ includes the questions of NL = P ?“, P = NP ?“, P SAP CE = P ?“ and ” ” ” CSL CHESS EXPTIME = P SAP CE?“ 6 6 6 ” 6 Is NC propper? NCi = NCi+1? (and is AC propper?) CHECKERS • ⇔ 6 Is EXPTIME=NEXPTIME? (A direct result of P=NP would be EXPTIME=NEXPTIME) • GO Known Subsets Chomsky hierarchy: • REG = TYPE3 DCF L CFL = TYPE2 CSL = TYPE1 RE = TYPE0 EXPTIME ⊂ ⊂ ⊂ ⊂ NC0 AC0 NC1 L NL NC = AC P NP P SP ACE EXPTIME • NEXPTIME⊂ ⊂ EXP⊂ SP⊂ ACE⊆= NEXP SAP⊆ CE⊆ REC⊆ RE ⊆ ⊆ P LANSAT ⊆ ⊆ ⊆ NL ( P SP ACE ( EXP SP ACE • NC ( P SP ACE and NC CSL • ⊆ NEXPTIME Savich’s Theorem For any function f(n) log(n): DSP ACE(f(n)) NSP ACE(f(n)) L = NL, P SP ACE≥= NP SP ACE, EXP SP ACE⊆ = NEXP SP ACE, ... ⇒ 6

c Lukas Ruge DT I do not give any guarantee on these informations. REC H

A. Artale Algorithms for Data Processing Thank You!

A. Artale Algorithms for Data Processing