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



Similar documents
CPS 220 Theory of Computation REGULAR LANGUAGES. Regular expressions

The example is taken from Sect. 1.2 of Vol. 1 of the CPN book.

5 2 index. e e. Prime numbers. Prime factors and factor trees. Powers. worked example 10. base. power

QUANTITATIVE METHODS CLASSES WEEK SEVEN

Question 3: How do you find the relative extrema of a function?

Traffic Flow Analysis (2)

Adverse Selection and Moral Hazard in a Model With 2 States of the World

Mathematics. Mathematics 3. hsn.uk.net. Higher HSN23000

MAXIMAL CHAINS IN THE TURING DEGREES

Econ 371: Answer Key for Problem Set 1 (Chapter 12-13)

ME 612 Metal Forming and Theory of Plasticity. 6. Strain

(Analytic Formula for the European Normal Black Scholes Formula)

Use a high-level conceptual data model (ER Model). Identify objects of interest (entities) and relationships between these objects

Upper Bounding the Price of Anarchy in Atomic Splittable Selfish Routing

SPECIAL VOWEL SOUNDS

Parallel and Distributed Programming. Performance Metrics

Factorials! Stirling s formula

Lecture 20: Emitter Follower and Differential Amplifiers

A Note on Approximating. the Normal Distribution Function

Entity-Relationship Model

5.4 Exponential Functions: Differentiation and Integration TOOTLIFTST:

by John Donald, Lecturer, School of Accounting, Economics and Finance, Deakin University, Australia

Version 1.0. General Certificate of Education (A-level) January Mathematics MPC3. (Specification 6360) Pure Core 3. Final.

Cloud and Big Data Summer School, Stockholm, Aug., 2015 Jeffrey D. Ullman

Lecture 3: Diffusion: Fick s first law

Constraint-Based Analysis of Gene Deletion in a Metabolic Network

Chapter 10 Function of a Matrix

C H A P T E R 1 Writing Reports with SAS

Architecture of the proposed standard

Continuity Cloud Virtual Firewall Guide

Remember you can apply online. It s quick and easy. Go to Title. Forename(s) Surname. Sex. Male Date of birth D

Foreign Exchange Markets and Exchange Rates

Establishing Wireless Conference Calls Under Delay Constraints

Intermediate Macroeconomic Theory / Macroeconomic Analysis (ECON 3560/5040) Final Exam (Answers)

Incomplete 2-Port Vector Network Analyzer Calibration Methods

A Theoretical Model of Public Response to the Homeland Security Advisory System

Combinatorial Prediction Markets for Event Hierarchies

FACULTY SALARIES FALL NKU CUPA Data Compared To Published National Data

Expert-Mediated Search

Important Information Call Through... 8 Internet Telephony... 6 two PBX systems Internet Calls... 3 Internet Telephony... 2

Compositional Specification of Commercial Contracts

Quantum Graphs I. Some Basic Structures

Sharp bounds for Sándor mean in terms of arithmetic, geometric and harmonic means

Category 7: Employee Commuting

Repulsive Force

CPU. Rasterization. Per Vertex Operations & Primitive Assembly. Polynomial Evaluator. Frame Buffer. Per Fragment. Display List.

New Basis Functions. Section 8. Complex Fourier Series

Job shop scheduling with unit processing times

WORKERS' COMPENSATION ANALYST, 1774 SENIOR WORKERS' COMPENSATION ANALYST, 1769

Business Systems Analysis with Ontologies

Lecture notes: 160B revised 9/28/06 Lecture 1: Exchange Rates and the Foreign Exchange Market FT chapter 13

STATEMENT OF INSOLVENCY PRACTICE 3.2

Combinatorial Analysis of Network Security

Section 7.4: Exponential Growth and Decay

Budget Optimization in Search-Based Advertising Auctions

New Concepts and Methods in Information Aggregation

Analyzing the Economic Efficiency of ebaylike Online Reputation Reporting Mechanisms

A Graph-based Proactive Fault Identification Approach in Computer Networks

Problem Set 6 Solutions

June Enprise Rent. Enprise Author: Document Version: Product: Product Version: SAP Version:

Type Inference and Optimisation for an Impure World.

Who uses our services? We have a growing customer base. with institutions all around the globe.

Policies for Simultaneous Estimation and Optimization

Performance Evaluation

Current and Resistance

AP Calculus AB 2008 Scoring Guidelines

Logo Design/Development 1-on-1

The Classes P and NP

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

An International Journal of the Polish Statistical Association

On Resilience of Multicommodity Dynamical Flow Networks

Introduction to NP-Completeness Written and copyright c by Jie Wang 1

The Constrained Ski-Rental Problem and its Application to Online Cloud Cost Optimization

Projections - 3D Viewing. Overview Lecture 4. Projection - 3D viewing. Projections. Projections Parallel Perspective

Free ACA SOLUTION (IRS 1094&1095 Reporting)

NP-Completeness and Cook s Theorem

81-1-ISD Economic Considerations of Heat Transfer on Sheet Metal Duct

SPREAD OPTION VALUATION AND THE FAST FOURIER TRANSFORM

The Neolithic transition, a major episode in human history, is

Fundamentals: NATURE OF HEAT, TEMPERATURE, AND ENERGY

Production Costing (Chapter 8 of W&W)

OPINION NO December 28, 1990

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Analyzing Failures of a Semi-Structured Supercomputer Log File Efficiently by Using PIG on Hadoop

Entry Voice Mail for HiPath Systems. User Manual for Your Telephone

Introduction to Logic in Computer Science: Autumn 2006

Theoretical aspects of investment demand for gold

IHE IT Infrastructure (ITI) Technical Framework Supplement. Cross-Enterprise Document Workflow (XDW) Trial Implementation

EFFECT OF GEOMETRICAL PARAMETERS ON HEAT TRANSFER PERFORMACE OF RECTANGULAR CIRCUMFERENTIAL FINS

Automatic Modeling of Musical Style

Sci.Int.(Lahore),26(1), ,2014 ISSN ; CODEN: SINTE 8 131

OHJ-2306 Introduction to Theoretical Computer Science, Fall

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

Enforcing Fine-grained Authorization Policies for Java Mobile Agents

TIME MANAGEMENT. 1 The Process for Effective Time Management 2 Barriers to Time Management 3 SMART Goals 4 The POWER Model e. Section 1.

A Multi-Heuristic GA for Schedule Repair in Precast Plant Production

Rural and Remote Broadband Access: Issues and Solutions in Australia

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,apath 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 NP, 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 NP, NP-COMPLETENESS 437 7.4 Th Class NP, Polynomial Rducibility, NP-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 NP.

7.4. THE CLASS NP, NP-COMPLETENESS 439 Of cours, w hav th inclusion P NP, 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= NP 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 NP, 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 NP, NP-COMPLETENESS 441 For xampl, on can construct a polynomial rduction from th Hamiltonian cycl problm to SAT. Rmarkably, vry languag in NP 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 NP (Sinc it is in NP). Dfinition 7.4.3 A languag L is NP-hard if thr is a polynomial rduction from vry languag L 1 NPto L. A languag L is NP-complt if L NP and L is NP-hard.

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

7.5. THE COOK-LEVIN THEOREM 443 7.5 Th Cook Lvin Thorm: SAT is NP- Complt Instad of showing dirctly that SAT is NP-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 NP-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 : { s, (s 1),..., 1, 1,...,s 1,s} T, find a 2s s-tiling, σ, xtnding σ 0, i.., a function σ: { s, (s 1),..., 1, 1,...,s 1,s} {1,...,s} T, so that (1) σ(m, 1) = σ 0 (m), for all m = 0, with s m s. (2) (σ(m, n),σ(m +1,n)) H, for all m = 0, with s m s 1, and all n, with 1 n s. (3) (σ(m, n),σ(m, n + 1)) V, for all m = 0, with s m s, 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.

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), s, σ 0 ), whr (T,V,H) is a tiling systm, s 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 s = 10000000001. Th lngth of s is log 2 s. Thorm 7.5.1 Th tiling problm dfind arlir is NP-complt. Proof.LtL Σ b any languag in NP and lt u b any string in Σ. Assum that L is accptd in polynomial tim boundd by p( u ).

448 CHAPTER 7. COMPUTATIONAL COMPLEXITY W show how to construct an instanc of th tiling problm, ((T,V,H) L, s, σ 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, s, σ 0 ) has a solution. First, not that th problm is indd in NP, 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, 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!).

7.5. THE COOK-LEVIN THEOREM 449 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

450 CHAPTER 7. COMPUTATIONAL COMPLEXITY (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

7.5. THE COOK-LEVIN THEOREM 451 (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).

452 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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 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

7.5. THE COOK-LEVIN THEOREM 453 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 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 this tiling problm is actually NEXP-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 NP-complt problms. W finally prov th Cook-Lvin thorm.

454 CHAPTER 7. COMPUTATIONAL COMPLEXITY Thorm 7.5.2 (Cook, 1971, Lvin, 1973) Th satisfiability problm SAT is NP-complt. Proof. W rduc th tiling problm to SAT. Givn a tiling problm, ((T,V,H), s, σ 0 ), w introduc boolan variabls x mnt, for all m = 0, with s m s, 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:

7.5. THE COOK-LEVIN THEOREM 455 (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.

456 CHAPTER 7. COMPUTATIONAL COMPLEXITY (3) For vry pair of tils (t, t ) T T H, for all m = 0, with s m s 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 = 0, with s m s, and all n, with 1 n s 1, (x mnt x mn+1 t ). This claus nforcs th vrtical adjacncy constraints. (5) For all m = 0, with s m s, (x m1σ0 (m)). This claus stats that th bottom row is corrctly tild with σ 0.

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

458 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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.

7.5. THE COOK-LEVIN THEOREM 459 Assum that C is satisfiabl, but that C is not. Thn, for vry truth assignmnt v, w hav v(l i )=F, fori =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.

460 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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.

7.5. THE COOK-LEVIN THEOREM 461 Thorm 7.5.4 (Cook, 1971) Th satisfiability problm for xact 3-SAT is NP-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.

462 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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

7.5. THE COOK-LEVIN THEOREM 463 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.

464 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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!

7.5. THE COOK-LEVIN THEOREM 465 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.

466 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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.

7.5. THE COOK-LEVIN THEOREM 467 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 Γ.

468 CHAPTER 7. COMPUTATIONAL COMPLEXITY Obsrv that a valuation v satisfis th conclusion of a rul iff it sastisfis 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).

7.5. THE COOK-LEVIN THEOREM 469 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.

470 CHAPTER 7. COMPUTATIONAL COMPLEXITY 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).