In the previous two chapters, we clarified what it means for a problem to be decidable or undecidable.

Similar documents
Chapter 9. Computational Complexity; P and NP. In the previous two chapters, we clarified what it means for a problem to be decidable or undecidable.

Chapter 12. Computational Complexity; P and NP. In the previous two chapters, we clarified what it means for a problem to be decidable or undecidable.

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Week 3: Connected Subgraphs

CPSC 665 : An Algorithmist s Toolkit Lecture 4 : 21 Jan Linear Programming

CS 361 Meeting 12 10/3/18

Strongly Connected Components

The Matrix Exponential

cycle that does not cross any edges (including its own), then it has at least

The Matrix Exponential

Introduction to Arithmetic Geometry Fall 2013 Lecture #20 11/14/2013

UNTYPED LAMBDA CALCULUS (II)

The Equitable Dominating Graph

(Upside-Down o Direct Rotation) β - Numbers

Higher order derivatives

On spanning trees and cycles of multicolored point sets with few intersections

Recall that by Theorems 10.3 and 10.4 together provide us the estimate o(n2 ), S(q) q 9, q=1

1 Minimum Cut Problem

Finding low cost TSP and 2-matching solutions using certain half integer subtour vertices

u x v x dx u x v x v x u x dx d u x v x u x v x dx u x v x dx Integration by Parts Formula

On the irreducibility of some polynomials in two variables

Abstract Interpretation. Lecture 5. Profs. Aiken, Barrett & Dill CS 357 Lecture 5 1

Derangements and Applications

What is a hereditary algebra?

Homework #3. 1 x. dx. It therefore follows that a sum of the

The second condition says that a node α of the tree has exactly n children if the arity of its label is n.

Abstract Interpretation: concrete and abstract semantics

SCHUR S THEOREM REU SUMMER 2005

Computing and Communications -- Network Coding

Problem Set 6 Solutions

Fourier Transforms and the Wave Equation. Key Mathematics: More Fourier transform theory, especially as applied to solving the wave equation.

Roadmap. XML Indexing. DataGuide example. DataGuides. Strong DataGuides. Multiple DataGuides for same data. CPS Topics in Database Systems

COMPUTER GENERATED HOLOGRAMS Optical Sciences 627 W.J. Dallas (Monday, April 04, 2005, 8:35 AM) PART I: CHAPTER TWO COMB MATH.

A Uniform Approach to Three-Valued Semantics for µ-calculus on Abstractions of Hybrid Automata

Basic Polyhedral theory

Some remarks on Kurepa s left factorial

First derivative analysis

Mutually Independent Hamiltonian Cycles of Pancake Networks

That is, we start with a general matrix: And end with a simpler matrix:

EEO 401 Digital Signal Processing Prof. Mark Fowler

Supplementary Materials

Addition of angular momentum

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

Construction of asymmetric orthogonal arrays of strength three via a replacement method

BINOMIAL COEFFICIENTS INVOLVING INFINITE POWERS OF PRIMES

COUNTING TAMELY RAMIFIED EXTENSIONS OF LOCAL FIELDS UP TO ISOMORPHISM

BINOMIAL COEFFICIENTS INVOLVING INFINITE POWERS OF PRIMES. 1. Statement of results

u r du = ur+1 r + 1 du = ln u + C u sin u du = cos u + C cos u du = sin u + C sec u tan u du = sec u + C e u du = e u + C


Square of Hamilton cycle in a random graph

Estimation of apparent fraction defective: A mathematical approach

1 Isoparametric Concept

Equidistribution and Weyl s criterion

International Journal of Foundations of Computer Science c World Scientic Publishing Company Searching a Pseudo 3-Sided Solid Orthoconvex Grid ANTONIO

Addition of angular momentum

EEO 401 Digital Signal Processing Prof. Mark Fowler

SOME PARAMETERS ON EQUITABLE COLORING OF PRISM AND CIRCULANT GRAPH.

Function Spaces. a x 3. (Letting x = 1 =)) a(0) + b + c (1) = 0. Row reducing the matrix. b 1. e 4 3. e 9. >: (x = 1 =)) a(0) + b + c (1) = 0

Approximation and Inapproximation for The Influence Maximization Problem in Social Networks under Deterministic Linear Threshold Model

Section 6.1. Question: 2. Let H be a subgroup of a group G. Then H operates on G by left multiplication. Describe the orbits for this operation.

MATH 319, WEEK 15: The Fundamental Matrix, Non-Homogeneous Systems of Differential Equations

Search sequence databases 3 10/25/2016

ECE602 Exam 1 April 5, You must show ALL of your work for full credit.

NEW APPLICATIONS OF THE ABEL-LIOUVILLE FORMULA

Brief Introduction to Statistical Mechanics

International Journal of Scientific & Engineering Research, Volume 6, Issue 7, July ISSN

Note If the candidate believes that e x = 0 solves to x = 0 or gives an extra solution of x = 0, then withhold the final accuracy mark.

Exercise 1. Sketch the graph of the following function. (x 2

DIFFERENTIAL EQUATION

COHORT MBA. Exponential function. MATH review (part2) by Lucian Mitroiu. The LOG and EXP functions. Properties: e e. lim.

1 General boundary conditions in diffusion

From Elimination to Belief Propagation

Thus, because if either [G : H] or [H : K] is infinite, then [G : K] is infinite, then [G : K] = [G : H][H : K] for all infinite cases.

The Average Sensitivity of Bounded-Depth Formulas

EECE 301 Signals & Systems Prof. Mark Fowler

Aim To manage files and directories using Linux commands. 1. file Examines the type of the given file or directory

The van der Waals interaction 1 D. E. Soper 2 University of Oregon 20 April 2012

2.3 Matrix Formulation

Difference -Analytical Method of The One-Dimensional Convection-Diffusion Equation

Slide 1. Slide 2. Slide 3 DIGITAL SIGNAL PROCESSING CLASSIFICATION OF SIGNALS

CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

A Propagating Wave Packet Group Velocity Dispersion

Separating principles below Ramsey s Theorem for Pairs

ANALYSIS IN THE FREQUENCY DOMAIN

Calculus concepts derivatives

Network Congestion Games

CHAPTER 1. Introductory Concepts Elements of Vector Analysis Newton s Laws Units The basis of Newtonian Mechanics D Alembert s Principle

Hydrogen Atom and One Electron Ions

ME 321 Kinematics and Dynamics of Machines S. Lambert Winter 2002

3 Finite Element Parametric Geometry

Probability and Stochastic Processes: A Friendly Introduction for Electrical and Computer Engineers Roy D. Yates and David J.

6.1 Integration by Parts and Present Value. Copyright Cengage Learning. All rights reserved.

General Notes About 2007 AP Physics Scoring Guidelines

Objective Mathematics

Differentiation of Exponential Functions

Chapter 10. The singular integral Introducing S(n) and J(n)

Economics 201b Spring 2010 Solutions to Problem Set 3 John Zhu

SECTION where P (cos θ, sin θ) and Q(cos θ, sin θ) are polynomials in cos θ and sin θ, provided Q is never equal to zero.

4037 ADDITIONAL MATHEMATICS

u 3 = u 3 (x 1, x 2, x 3 )

Transcription:

Chaptr 7 Computational Complxity 7.1 Th Class P In th prvious two chaptrs, w clarifid what it mans for a problm to b dcidabl or undcidabl. In principl, if a problm is dcidabl, thn thr is an algorithm (i.., a procdur that halts for vry input) that dcids vry instanc of th problm. Howvr, from a practical point of viw, knowing that a problm is dcidabl may b uslss, if th numbr of stps (tim complxity) rquird by th algorithm is xcssiv, for xampl, xponntial in th siz of th input, or wors. For instanc, considr th travling salsman problm, which can b formulatd as follows: 421

422 CHAPTER 7. COMPUTATIONAL COMPLEXITY W hav a st {c 1,..., c n } of citis, and an n n matrix (d ij ) of nonngativ intgrs, th distanc matrix, whr d ij dnots th distanc btwn c i and c j, which mans that d ii = 0 and d ij = d ji for all i j. Th problm is to find a shortst tour of th citis, that is, a prmutation π of {1,..., n} so that th cost C(π) = d π(1)π(2) + d π(2)π(3) + + d π(n 1)π(n) + d π(n)π(1) is as small as possibl (minimal). On way to solv th problm is to considr all possibl tours, i.., n! prmutations. Actually, sinc th starting point is irrlvant, w nd only considr (n 1)! tours, but this still grows vry fast. For xampl, whn n = 40, it turns out that 39! xcds 10 45, a hug numbr.

7.1. THE CLASS P 423 Thus, to captur th ssnc of practically fasibl algorithms, w must limit our computational dvics to run only for a numbr of stps that is boundd by a polynomial in th lngth of th input. W ar ld to th dfinition of polynomially boundd computational modls. Dfinition 7.1.1 A dtrministic Turing machin M is said to b polynomially boundd if thr is a polynomial p(x) so that th following holds: For vry input x Σ, thr is no ID ID n so that ID 0 ID n, with n > p( x ), whr ID 0 = q 0 x is th starting ID. A languag L Σ is polynomially dcidabl if thr is a polynomially boundd Turing machin that accpts L. Th family of all polynomially dcidabl languags is dnotd by P.

424 CHAPTER 7. COMPUTATIONAL COMPLEXITY Rmark: Evn though Dfinition 7.1.1 is formulatd for Turing machins, it can also b formulatd for othr modls, such as RAM programs. Th rason is that th convrsion of a Turing machin into a RAM program (and vic vrsa) producs a program (or a machin) whos siz is polynomial in th original dvic. Th following lmma, although trivial, is usful: Lmma 7.1.2 Th class P is closd undr complmntation. Of cours, many languags do not blong to P. On way to obtain such languags is to us a diagonal argumnt. But thr ar also many natural languags that ar not in P, although this may b vry hard to prov for som of ths languags.

7.2. MORE PROBLEMS 425 7.2 Mor Problms Lt us considr a fw mor problms in ordr to gt a bttr fling for th family P. Rcall that a dirctd graph, G, is a pair G = (V, E), whr E V V. A pair (u, v) E is calld an dg of G (not that u = v is allowd). Givn any two nods u, v V, a path from u to v is any squnc of n + 1 dgs (n 0) (u, v 1 ), (v 1, v 2 ),..., (v n, v). (If n = 1, a path from u to v is simply a singl dg, (u, v).) A graph G is strongly connctd if for vry pair (u, v) V V, thr is a path from u to v. A closd path, or cycl, is a path from som nod u to itslf. W will rstrict out attntion to finit graphs, i.. graphs (V, E) whr V is a finit st.

426 CHAPTER 7. COMPUTATIONAL COMPLEXITY Dfinition 7.2.1 Givn a graph G, an Eulrian cycl is a cycl in G that passs through all th nods (possibly mor than onc) and vry dg of G xactly onc. A Hamiltonian cycl is a cycl that passs through all th nods xactly onc (not, som dgs may not b travrsd at all). Eulrian Cycl Problm: Givn a graph G, is thr an Eulrian cycl in G? Hamiltonian Cycl Problm: Givn a graph G, is thr an Hamiltonian cycl in G? It may com as a surpris that th Eulrian Cycl Problm dos hav a polynomial tim algorithm, but that so far, not such algorithm is known for th Hamiltonian Cycl Problm.

7.2. MORE PROBLEMS 427 Th rason why th Eulrian Cycl Problm is dcidabl in polynomial tim is th following thorm du to Eulr: Thorm 7.2.2 A graph G = (V, E) has an Eulrian cycl iff th following proprtis hold: (1) Th graph G is strongly connctd. (2) Evry nod has th sam numbr of incoming and outgoing dgs. Proving that proprtis (1) and (2) hold if G has an Eulrian cycl is fairly asy. Th convrs is hardr, but not that bad (try!). Thorm 7.2.2 shows that it is ncssary to chck whthr a graph is strongly connctd. This can b don by computing th transitiv closur of E, which can b don in polynomial tim (in fact, O(n 3 )).

428 CHAPTER 7. COMPUTATIONAL COMPLEXITY Chcking proprty (2) can clarly b don in polynomial tim. Thus, th Eulrian cycl problm is in P. Unfortunatly, no thorm analogous to Thorm 7.2.2 is know for Hamiltonian cycls. Rmark: W talkd about problms bing dcidabl in polynomial tim. Obviously, this is quivalnt to dciding som proprty of a crtain class of objcts, for xampl, finit graphs. Our framwork rquirs that w first ncod ths classs of objcts as strings (or numbrs), sinc P consists of languags. Thus, whn w say that a proprty is dcidabl in polynomial tim, w ar rally talking about th ncoding of this proprty as a languag. Thus, w hav to b carful about ths ncodings, but it is rar that ncodings caus problms.

7.3. PROPOSITIONAL LOGIC AND SATISFIABILITY 429 7.3 Propositional Logic and Satisfiability W dfin th syntax and th smantics of propositions in conjunctiv normal form (CNF). Th syntax has to do with th lgal form of propositions in CNF. Such propositions ar intrprtd as truth functions, by assigning truth valus to thir variabls. W bgin by dfining propositions in CNF. Such propositions ar constructd from a countabl st, PV, of propositional (or boolan) variabls, say PV = {x 1, x 2,..., }, using th connctivs (and), (or) and (ngation).

430 CHAPTER 7. COMPUTATIONAL COMPLEXITY W dfin a litral (or atomic proposition), L, as L = x or L = x, also dnotd by x, whr x PV. A claus, C, is a disjunction of pairwis distinct litrals, C = (L 1 L 2 L m ). Thus, a claus may also b viwd as a nonmpty st C = {L 1, L 2,..., L m }. W also hav a spcial claus, th mpty claus, dnotd or (or {}). It corrsponds to th truth valu fals. A proposition in CNF, or boolan formula, P, is a conjunction of pairwis distinct clauss P = C 1 C 2 C n.

7.3. PROPOSITIONAL LOGIC AND SATISFIABILITY 431 Thus, a boolan formula may also b viwd as a nonmpty st P = {C 1,..., C n }, but this tim, th comma is intrprtd as conjunction. W also allow th proposition, and somtims th proposition (corrsponding to th truth valu tru). For xampl, hr is a boolan formula: P = {(x 1 x 2 x 3 ), (x 1 x 2 ), (x 2 x 3 ), (x 3 x 1 ), (x 1 x 2 x 3 )}. In ordr to intrprt boolan formula, w us truth assignmnts. W lt BOOL = {F, T}, th st of truth valus, whr F stands for fals and T stands for tru.

432 CHAPTER 7. COMPUTATIONAL COMPLEXITY A truth assignmnt (or valuation), v, is any function v: PV BOOL. Givn a truth assignmnt, v: PV BOOL, w dfin th truth valu, v(x), of a litral, claus, and boolan formula, X, using th following rcursiv dfinition: (1) v( ) = F, v( ) = T. (2) v(x) = v(x), if x PV. (3) v(x) = v(x), if x PV, whr v(x) = F if v(x) = T and v(x) = T if v(x) = F. (4) v(c) = F if C is a claus and iff v(l i ) = F for all litrals L i in C, othrwis T. (5) v(p ) = T if P is a boolan formula and iff v(c j ) = T for all clauss C j in P, othrwis F.

7.3. PROPOSITIONAL LOGIC AND SATISFIABILITY 433 Dfinition 7.3.1 W say that a truth assignmnt, v, satisfis a boolan formula, P, if v(p ) = T. In this cas, w also writ v = P. A boolan formula, P, is satisfiabl if v = P for som truth assignmnt v, othrwis, it is unsatisfiabl. A boolan formula, P, is valid (or a tautology) if v = P for all truth assignmnts v, in which cas w writ = P. On should chck that th boolan formula P = {(x 1 x 2 x 3 ), (x 1 x 2 ), (x 2 x 3 ), (x 3 x 1 ), (x 1 x 2 x 3 )} is unsatisfiabl.

434 CHAPTER 7. COMPUTATIONAL COMPLEXITY On may think that it is asy to tst whthr a proposition is satisfiabl or not. Try it, it is not that asy! As a mattr of fact, th satisfiability problm, tsting whthr a boolan formula is satisfiabl, also dnotd SAT, is not known to b in P. Morovr, it is an NP-complt problm. Most popl bliv that th satisfiability problm is not in P, but a proof still luds us! Bfor w xplain what is th class N P, lt us rmark that th satisfiability problm for clauss containing at most two litrals (2-satisfiability, or 2-SAT) is solvabl in polynomial tim.

7.3. PROPOSITIONAL LOGIC AND SATISFIABILITY 435 Th first stp consists in obsrving that if vry claus in P contains at most two litrals, thn w can rduc th problm to tsting satisfiability whn vry claus has xactly two litrals. Indd, if P contains som claus (x), thn any valuation satisfying P must mak x tru. Thn, all clauss containing x will b tru, and w can dlt thm, whras w can dlt x from vry claus containing it, sinc x is fals. Similarly, if P contains som claus (x), thn any valuation satisfying P must mak x fals. Thus, in a finit numbr of stps, ithr w gt th mpty claus, and P is unsatisfiabl, or w gt a st of clauss with xactly two litrals.

436 CHAPTER 7. COMPUTATIONAL COMPLEXITY Th numbr of stps is clarly linar in th numbr of litrals in P. For th scond stp, w construct a dirctd graph from P. Th nods of this graph ar th litrals in P, and dgs ar dfind as follows: (1) For vry claus (x y), thr is an dg from x to y and an dg from y to x. (2) For vry claus (x y), thr is an dg from x to y and an dg from y to x (3) For vry claus (x y), thr is an dg from x to y and an dg from y to x. Thn, it can b shown that P is unsatisfiabl iff thr is som x so that thr is a cycl containing x and x. As a consqunc, 2-satisfiability is in P.

7.4. THE CLASS N P, N P-COMPLETENESS 437 7.4 Th Class N P, Polynomial Rducibility, N P-Compltnss On will obsrv that th hard part in trying to solv ithr th Hamiltonian cycl problm or th satisfiability problm, SAT, is to find a solution, but that chcking that a candidat solution is indd a solution can b don asily in polynomial tim. This is th ssnc of problms that can b solvd nondtrmistically in polynomial tim: A solution can b gussd and thn chckd in polynomial tim.

438 CHAPTER 7. COMPUTATIONAL COMPLEXITY Dfinition 7.4.1 A nondtrministic Turing machin M is said to b polynomially boundd if thr is a polynomial p(x) so that th following holds: For vry input x Σ, thr is no ID ID n so that ID 0 ID n, with n > p( x ), whr ID 0 = q 0 x is th starting ID. A languag L Σ is nondtrministic polynomially dcidabl if thr is a polynomially boundd nondtrministic Turing machin that accpts L. Th family of all nondtrministic polynomially dcidabl languags is dnotd by N P.

7.4. THE CLASS N P, N P-COMPLETENESS 439 Of cours, w hav th inclusion P N P, but whthr or not w hav quality is on of th most famous opn problms of thortical computr scinc and mathmatics. In fact, th qustion P N P is on of th opn problms listd by th CLAY Institut, togthr with th Poincaré conjctur and th Rimann hypothsis, among othr problms, and for which on million dollar is offrd as a rward! It is asy to chck that SAT is in N P, and so is th Hamiltonian cycl problm.

440 CHAPTER 7. COMPUTATIONAL COMPLEXITY As w saw in rcursion thory, whr w introducd th notion of many-on rducibility, in ordr to compar th dgr of difficulty of problms, it is usful to introduc th notion of rducibility and th notion of a complt st. Dfinition 7.4.2 A function f: Σ Σ is polynomial-tim computabl if thr is a polynomial p(x) so that th following holds: Thr is a dtrministic Turing machin M computing it so that for vry input x Σ, thr is no ID ID n so that ID 0 ID n, with n > p( x ), whr ID 0 = q 0 x is th starting ID. Givn two languags L 1, L 2 Σ, a polynomial rduction from L 1 to L 2 is a polynomial-tim computabl function f: Σ Σ so that for all u Σ, u L 1 iff f(u) L 2.

7.4. THE CLASS N P, N P-COMPLETENESS 441 For xampl, on can construct a polynomial rduction from th Hamiltonian cycl problm to SAT. Rmarkably, vry languag in N P can b rducd to SAT. Intuitivly, if L 1 is a hard problm and L 1 can b rducd to L 2, thn L 2 is also a hard problm. Thus, SAT is a hardst problm in N P (Sinc it is in N P). Dfinition 7.4.3 A languag L is N P-hard if thr is a polynomial rduction from vry languag L 1 N P to L. A languag L is N P-complt if L N P and L is N P-hard.

442 CHAPTER 7. COMPUTATIONAL COMPLEXITY Thus, an N P-hard languag is as hard to dcid as any languag in N P. Th importanc of N P-complt problms stms from th following thorm: Thorm 7.4.4 Lt L b an N P-complt languag. P = N P iff L P. Thn, Nxt, w prov a famous thorm of Stv Cook and Lonid Lvin (provd indpndntly): SAT is N P-complt.

7.5. THE COOK-LEVIN THEOREM 443 7.5 Th Cook Lvin Thorm: SAT is N P- Complt Instad of showing dirctly that SAT is N P-complt, which is rathr complicatd, w procd in two stps, as suggstd by Lwis and Papadimitriou. (1) First, w dfin a tiling problm adaptd from H. Wang (1961) by Harry Lwis, and w prov that it is N P-complt. (2) W show that th tiling problm can b rducd to SAT. W ar givn a finit st T = {t 1,..., t p } of til pattrns, for short, tils. Copis of ths til pattrns may b usd to til a rctangl of prdtrmind siz 2s s (s > 1). Howvr, thr ar constraints on th way that ths tils may b adjacnt horizontally and vrtically.

444 CHAPTER 7. COMPUTATIONAL COMPLEXITY Th horizontal constraints ar givn by a rlation H T T, and th vrtical constraints ar givn by a rlation V T T. Thus, a tiling systm is a tripl T = (T, V, H), as abov. Th problm is thn as follows: Givn any tiling systm (T, V, H), any intgr s > 1, and any initial row of tils, σ 0 (of lngth 2s), σ 0 : {1, 2,..., s, s + 1,..., 2s} T, find a 2s s-tiling, σ, xtnding σ 0, i.., a function so that σ: {1, 2,..., s, s + 1,..., 2s} {1,..., s} T, (1) σ(m, 1) = σ 0 (m), for all m with 1 m 2s. (2) (σ(m, n), σ(m + 1, n)) H, for all m with 1 m 2s 1, and all n, with 1 n s. (3) (σ(m, n), σ(m, n + 1)) V, for all m with 1 m 2s, and all n, with 1 n s 1.

7.5. THE COOK-LEVIN THEOREM 445 For xampl, considr th following til pattrns: a c, a a c, c a, d, b c d, c b b d, d c c, d d, c d, c d b, d c, d, Th horizontal and th vrtical constraints ar that th lttrs on adjacnt dgs match (blank dgs do not match).

446 CHAPTER 7. COMPUTATIONAL COMPLEXITY For s = 3, givn th bottom row a c b c d c d d d w hav th tiling shown blow: c a c d b d c d d a c a b c d b c d c d d d d a c b c d c d d d

7.5. THE COOK-LEVIN THEOREM 447 Formally, an instanc of th tiling problm is a tripl, ((T, V, H), ŝ, σ 0 ), whr (T, V, H) is a tiling systm, ŝ is th string rprsntation of th numbr s 2, in binary and σ 0 is an initial row of tils (th bottom row). For xampl, if s = 1025 (as a dcimal numbr), thn its binary rprsntation is ŝ = 10000000001. Th lngth of ŝ is log 2 s. Rcall that th input must b a string. This is why th numbr s is rprsntd by a string in binary. If w only includd a singl til σ 0 in position (s + 1, 1), thn th lngth of th input ((T, V, H), ŝ, σ 0 ) would b log 2 s + C + 1 for som constant C corrsponding to th lngth of th string ncoding (T, V, H).

448 CHAPTER 7. COMPUTATIONAL COMPLEXITY Howvr, th rctangular grid has siz 2s 2, which is xponntial in th lngth log 2 s + C + 1 of th input ((T, V, H), ŝ, σ 0 ). Thus, it is impossibl to chck in polynomial tim that a proposd solution is a tiling. Howvr, if w includ in th input th bottom row σ 0 of lngth 2s, thn th siz of th grid is indd polynomial in th siz of th input. Thorm 7.5.1 Th tiling problm dfind arlir is N P-complt. Proof. Lt L Σ b any languag in N P and lt u b any string in Σ. Assum that L is accptd in polynomial tim boundd by p( u ).

7.5. THE COOK-LEVIN THEOREM 449 W show how to construct an instanc of th tiling problm, ((T, V, H) L, ŝ, σ 0 ), whr s = max{2, p( u )}, and whr th bottom row ncods th starting ID, so that u L iff th tiling problm ((T, V, H) L, ŝ, σ 0 ) has a solution. First, not that th problm is indd in N P, sinc w hav to guss a rctangl of siz 2s 2, and that chcking that a tiling is lgal can indd b don in O(s 2 ), whr s is boundd by th th siz of th input ((T, V, H), ŝ, σ 0 ), sinc th input contains th bottom row of 2s symbols (this is th rason for including th bottom row of 2s tils in th input!).

450 CHAPTER 7. COMPUTATIONAL COMPLEXITY Th ida bhind th dfinition of th tils is that, in a solution of th tiling problm, th labls on th horizontal dgs btwn two adjacnt rows rprsnt a lgal ID, upav. In a givn row, th labls on vrtical dgs of adjacnt tils kp track of th chang of stat and dirction. Lt Γ b th tap alphabt of th TM, M. As bfor, w assum that M signals that it accpts u by halting with th output 1 (tru). From M, w crat th following tils: (1) For vry a Γ, tils a a

7.5. THE COOK-LEVIN THEOREM 451 (2) For vry a Γ, th bottom row uss tils a, q 0, a whr q 0 is th start stat. (3) For vry instruction (p, a, b, R, q) δ, for vry c Γ, tils b p, a q, R, q, R q, c c

452 CHAPTER 7. COMPUTATIONAL COMPLEXITY (4) For vry instruction (p, a, b, L, q) δ, for vry c Γ, tils q, c c q, L, q, L b p, a (5) For vry halting stat, p, tils p, 1 p, 1 Th purpos of tils of typ (5) is to fill th 2s s rctangl if and whn M accpts u in strictly lss than s stps. Th vrtical and th horizontal constraints ar that adjacnt dgs hav th sam labl (or no labl).

7.5. THE COOK-LEVIN THEOREM 453 If u = u 1 u k, th initial bottom row σ 0, of lngth 2s, is: B q 0, u 1 u k B whr th til labld q 0, u 1 is in position s + 1. Th xampl blow illustrats th construction: B B B B B B......... B q, c q, c c c r, b f, R q, L p, R f, R q, L p, R f, 1 1 1 p, a p, a a......... B B B B B B

454 CHAPTER 7. COMPUTATIONAL COMPLEXITY It is not hard to chck that u = u 1 u k is accptd by M iff th tiling problm just constructd has a solution. Rmarks. (1) Th problm bcoms hardr if w only spcify a singl til σ 0 as input, instad of a row of lngth 2s. If s is spcifid in binary (or any othr bas, but not in tally notation), thn th 2s 2 grid has siz xponntial in th lngth log 2 s+c +1 of th input ((T, V, H), ŝ, σ 0 ), and this tiling problm is actually N EX P-complt! (2) If w rlax th finitnss condition and rquir that th ntir uppr half-plan b tild, i.., for vry s > 1, thr is a solution to th 2s s-tiling problm, thn th problm is undcidabl. In 1972, Richard Karp publishd a list of 21 N P-complt problms. W finally prov th Cook-Lvin thorm.

7.5. THE COOK-LEVIN THEOREM 455 Thorm 7.5.2 (Cook, 1971, Lvin, 1973) Th satisfiability problm SAT is N P-complt. Proof. W rduc th tiling problm to SAT. Givn a tiling problm, ((T, V, H), ŝ, σ 0 ), w introduc boolan variabls x mnt, for all m with 1 m 2s, all n with 1 n s, and all tils t T. Th intuition is that x mnt = T iff til t occurs in som tiling σ so that σ(m, n) = t. W dfin th following clauss:

456 CHAPTER 7. COMPUTATIONAL COMPLEXITY (1) For all m, n in th corrct rang, as abov, (x mnt1 x mnt2 x mntp ), for all p tils in T. This claus stats that vry position in σ is tild. (2) For any two distinct tils t t T, for all m, n in th corrct rang, as abov, (x mnt x mnt ). This claus stats that a position may not b occupid by mor than on til.

7.5. THE COOK-LEVIN THEOREM 457 (3) For vry pair of tils (t, t ) T T H, for all m with 1 m 2s 1, and all n, with 1 n s, (x mnt x m+1 nt ). This claus nforcs th horizontal adjacncy constraints. (4) For vry pair of tils (t, t ) T T V, for all m with 1 m 2s, and all n, with 1 n s 1, (x mnt x m n+1 t ). This claus nforcs th vrtical adjacncy constraints. (5) For all m with 1 m 2s, (x m1σ0 (m)). This claus stats that th bottom row is corrctly tild with σ 0.

458 CHAPTER 7. COMPUTATIONAL COMPLEXITY It is asily chckd that th tiling problm has a solution iff th conjunction of th clauss just dfind is satisfiabl. Thus, SAT is N P-complt. W sharpn Thorm 7.5.2 to prov that 3-SAT is also N P- complt. This is th satisfiability problm for clauss containing at most thr litrals. W know that w can t go furthr and rtain N P-complttnss, sinc 2-SAT is in P. Thorm 7.5.3 (Cook, 1971) Th satisfiability problm 3-SAT is N P-complt.

7.5. THE COOK-LEVIN THEOREM 459 Proof. W hav to brak long clauss C = (L 1 L k ), i.., clauss containing k 4 litrals, into clauss with at most thr litrals, in such a way that satisfiability is prsrvd. For vry long claus, crat k 3 nw boolan variabls y 1,... y k 3, and th k 2 clauss (L 1 L 2 y 1 ), (y 1 L 3 y 2 ), (y 2 L 4 y 3 ),, (y k 4 L k 2 y k 3 ), (y k 3 L k 1 L k ). Lt C b th conjunction of ths clauss. W claim that C is satisfiabl iff C is.

460 CHAPTER 7. COMPUTATIONAL COMPLEXITY Assum that C is satisfiabl, but that C is not. Thn, for vry truth assignmnt v, w hav v(l i ) = F, for i = 1,..., k. Howvr, C is satisfid by som v, and th only way this can happn is that v(y 1 ) = T, to satisfy th first claus. Thn, v(y 1 ) = F, and w must hav v(y 2 ) = T, to satisfy th scond claus. By induction, w must hav v(y k 3 ) = T, to satisfy th nxt to th last claus. Howvr, th last claus is now fals, a contradiction. Thus, if C is satisfiabl, thn so is C.

7.5. THE COOK-LEVIN THEOREM 461 Convrsly, assum that C is satisfiabl. If so, thr is som truth assignmnt, v, so that v(c) = T, and thus, thr is a smallst indx i, with 1 i k, so that v(l i ) = T (and so, v(l j ) = F for all j < i). Lt v b th assignmnt xtnding v dfind so that v (y j ) = F if max{1, i 1} j k 3, and v (y j ) = T, othrwis. It is asily chckd that v (C ) = T. Anothr vrsion of 3-SAT can b considrd, in which vry claus has xactly thr litrals. W will call this th problm xact 3-SAT.

462 CHAPTER 7. COMPUTATIONAL COMPLEXITY Thorm 7.5.4 (Cook, 1971) Th satisfiability problm for xact 3-SAT is N P-complt. Proof. A claus of th form (L) is satisfiabl iff th following four clauss ar satisfiabl: (L u v), (L u v), (L u v), (L u v). A claus of th form (L 1 L 2 ) is satisfiabl iff th following two clauss ar satisfiabl: (L 1 L 2 u), (L 1 L 2 u). Thus, w hav a rduction of 3-SAT to xact 3-SAT. W now mak som rmarks on th convrsion of propositions to CNF.

7.5. THE COOK-LEVIN THEOREM 463 Rcall that th st of propositions (ovr th connctivs,, and ) is dfind inductivly as follows: (1) Evry propositional lttr, x PV, is a proposition (an atomic proposition). (2) If A is a proposition, thn A is a proposition. (3) If A and B ar propositions, thn (A B) is a proposition. (4) If A and B ar propositions, thn (A B) is a proposition. Two propositions A and B ar quivalnt, dnotd A B, if for all truth assignmnts, v. v = A iff v = B

464 CHAPTER 7. COMPUTATIONAL COMPLEXITY It is asy to show that A B iff th proposition is valid. ( A B) ( B A) Evry proposition, A, is quivalnt to a proposition, A, in CNF. Thr ar svral ways of proving this fact. On mthod is algbraic, and consists in using th algbraic laws of boolan algbra. First, on may convrt a proposition to ngation normal form, or nnf. A proposition is in nnf if occurrncs of only appar in front of propositional variabls, but not in front of compound propositions.

7.5. THE COOK-LEVIN THEOREM 465 Any proposition can b convrtd to an quivalnt on in nnf by using th d Morgan laws: (A B) ( A B) (A B) ( A B) A A. Thn, a proposition in nnf can b convrtd to CNF, but th qustion of uniqunss of th CNF is a bit tricky. For xampl, th proposition has A = (u (x y)) ( u (x y)) A 1 = (u x y) ( u x y) A 2 = (u u) (x y) A 3 = x y, as quivalnt propositions in CNF!

466 CHAPTER 7. COMPUTATIONAL COMPLEXITY W can gt a uniqu CNF quivalnt to a givn proposition if w do th following: (1) Lt Var(A) = {x 1,..., x m } b th st of variabls occurring in A. (2) Dfin a maxtrm w.r.t. Var(A) as any disjunction of m pairwis distinct litrals formd from Var(A), and not containing both som variabl x i and its ngation x i. (3) Thn, it can b shown that for any proposition A that is not a tautology, thr is a uniqu proposition in CNF quivalnt to A, whos clauss consist of maxtrms formd from Var(A). Th abov dfinition can yild strang rsults. For instanc, th CNF of any unsatisfiabl proposition with m distinct variabls is th conjunction of all of its 2 m maxtrms! Th abov notion dos not cop wll with minimality.

7.5. THE COOK-LEVIN THEOREM 467 For xampl, according to th abov, th CNF of A = (u (x y)) ( u (x y)) should b A 1 = (u x y) ( u x y). Thr ar also propositions such that any quivalnt proposition in CNF has siz xponntial in trms of th original proposition. Hr is such an xampl: A = (x 1 x 2 ) (x 3 x 4 ) (x 2n 1 x 2n ). Obsrv that it is in DNF. W will prov a littl latr that any CNF for A contains 2 n occurrncs of variabls.

468 CHAPTER 7. COMPUTATIONAL COMPLEXITY A nic mthod to convrt a proposition in nnf to CNF is to construct a tr whos nods ar labld with sts of propositions using th following (Gntzn-styl) ruls : and P, Q, (P Q), P, Q, (P Q), whr stands for any st of propositions (vn mpty), and th comma stands for union. Thus, it is assumd that (P Q) / in th first cas, and that (P Q) / in th scond cas. Sinc w intrprt a st, Γ, of propositions as a disjunction, a valuation, v, satisfis Γ iff it satisfis som proposition in Γ.

7.5. THE COOK-LEVIN THEOREM 469 Obsrv that a valuation v satisfis th conclusion of a rul iff it satisfis both prmiss in th first cas, and th singl prmis in th scond cas. Using ths ruls, w can build a finit tr whos lavs ar labld with sts of litrals. By th abov obsrvation, a valuation v satisfis th proposition labling th root of th tr iff it satisfis all th propositions labling th lavs of th tr. But thn, a CNF for th original proposition A (in nnf, at th root of th tr) is th conjunction of th clauss apparing as th lavs of th tr. W may xclud th clauss that ar tautologis, and w may discovr in th procss that A is a tautology (whn all lavs ar tautologis).

470 CHAPTER 7. COMPUTATIONAL COMPLEXITY Going back to our bad proposition, A, by induction, w s that any tr for A has 2 n lavs. Howvr, it should b notd that for any proposition, A, w can construct in polynomial tim a formula, A, in CNF, so that A is satisfiabl iff A is satisfiabl, by crating nw variabls. W procd rcursivly. Th trick is that w rplac by (C 1 C m ) (D 1 D n ) (C 1 y) (C m y) (D 1 y) (D n y), whr th C i s and th D j s ar clauss, and y is a nw variabl. It can b shown that th numbr of nw variabls rquird is at most quadratic in th siz of A.

7.5. THE COOK-LEVIN THEOREM 471 Warning: In gnral, th proposition A is not quivalnt to th proposition A. Ruls for daling for can also b cratd. In this cas, w work with pairs of sts of propositions, Γ, whr, th propositions in Γ ar intrprtd conjunctivly, and th propositions in ar intrprtd disjunctivly. W obtain a sound and complt proof systm for propositional logic (a Gntzn-styl proof systm, s Gallir s Logic for Computr Scinc).