• Keine Ergebnisse gefunden

Theory of Computer Science D3. Proving NP-Completeness Gabriele R¨oger

N/A
N/A
Protected

Academic year: 2022

Aktie "Theory of Computer Science D3. Proving NP-Completeness Gabriele R¨oger"

Copied!
45
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Theory of Computer Science

D3. Proving NP-Completeness

Gabriele R¨oger

University of Basel

May 10, 2021

(2)

Theory of Computer Science

May 10, 2021 — D3. Proving NP-Completeness

D3.1 Overview

D3.2 Propositional Logic D3.3 Cook-Levin Theorem D3.4 3SAT

D3.5 Summary

(3)

D3. Proving NP-Completeness Overview

D3.1 Overview

(4)

Reminder: P and NP

P: class of languages that are decidable in polynomial time by a deterministic Turing machine

NP: class of languages that are decidable in polynomial time by a non-deterministic Turing machine

(5)

D3. Proving NP-Completeness Overview

Reminder: Polynomial Reductions

Definition (Polynomial Reduction)

LetA⊆Σ andB ⊆Γ be decision problems.

We say thatAcan be polynomially reduced toB,

writtenA≤pB, if there is a functionf : Σ →Γ such that:

I f can be computed inpolynomial time by aDTM I f reducesA toB

I i. e., for allw Σ: w Aifff(w)B f is called apolynomial reductionfromAto B

Transitivity of≤p: IfA≤pB and B≤pC, then A≤pC.

(6)

Reminder: NP-Hardness and NP-Completeness

Definition (NP-Hard, NP-Complete) LetB be a decision problem.

B is called NP-hard ifA≤pB for allproblemsA∈NP.

B is called NP-completeif B∈NP and B is NP-hard.

(7)

D3. Proving NP-Completeness Overview

Proving NP-Completeness by Reduction

I Suppose we know one NP-complete problem

(we will use satisfiability of propositional logic formulas).

I With its help, we can then prove quite easily that further problems are NP-complete.

Theorem (Proving NP-Completeness by Reduction) Let A and B be problems such that:

I A is NP-hard, and I A≤pB.

Then B is also NP-hard.

If furthermore B ∈NP, then B is NP-complete.

(8)

Proving NP-Completeness by Reduction: Proof

Proof.

First part: We must show X ≤pB for all X ∈NP.

FromX ≤pA(becauseA is NP-hard) andA≤pB

(by prerequisite), this follows due to the transitivity of≤p. Second part: follows directly by definition of NP-completeness.

(9)

D3. Proving NP-Completeness Overview

NP-Complete Problems

I There are thousands of known NP-complete problems.

I An extensive catalog of NP-complete problems from many areas of computer science is contained in:

Michael R. Garey and David S. Johnson:

Computers and Intractability —

A Guide to the Theory of NP-Completeness W. H. Freeman, 1979.

I In the remaining chapters, we get to know some of these problems.

(10)

Overview of the Reductions

SAT

3SAT

Clique

IndSet

VertexCover

DirHamiltonCycle

HamiltonCycle

TSP

SubsetSum

Partition

BinPacking

(11)

D3. Proving NP-Completeness Overview

What Do We Have to Do?

I We want to show the NP-completeness of these 11 problems.

I We first show that SATis NP-complete.

I Then it is sufficient to show

I thatpolynomial reductionsexist for all edges in the figure (and thus all problems are NP-hard)

I and that the problems are all in NP.

(It would be sufficient to show membership in NP only for the leaves in the figure. But membership is so easy to show that this would not save any work.)

(12)

D3.2 Propositional Logic

(13)

D3. Proving NP-Completeness Propositional Logic

I We need to establish NP-completeness of one problem

“from scratch”.

I We will use satisfiability of propositional logic formulas.

I So what is this?

Let’s briefly cover the basics.

(14)

Propositional Logic: Syntax

I Let Abe a set of atomic propositions

→ variables that can be true or false

I Everya∈A is a propositional formula over A.

I Ifϕis a propositional formula over A, then so is its negation ¬ϕ.

I Ifϕ1, . . . , ϕn are propositional formulas over A, then so is theconjunction (ϕ1∧ · · · ∧ϕn).

I Ifϕ1, . . . , ϕn are propositional formulas over A, then so is thedisjunction (ϕ1∨ · · · ∨ϕn).

Example

¬(X∧(Y ∨ ¬(Z ∧Y))) is a propositional formula over{X,Y,Z}.

(15)

D3. Proving NP-Completeness Propositional Logic

Propositional Logic: Semantics

I A truth assignmentfor a set of atomic propositions Ais a functionI :A→ {T,F}.

I A formula can be true or false under a given truth assignment.

WriteI |=ϕto express that ϕis true underI.

I Atomic variableais true underI iff I(a) =T. I Negation¬ϕis true underI iffϕis not:

I |=¬ϕiffI 6|=ϕ

I Conjunction (ϕ1∧ · · · ∧ϕn) is true underI iff eachϕi is:

I |= (ϕ1∧ · · · ∧ϕn) iffI |=ϕi for alli∈ {1, . . . ,n}

I Disjunction (ϕ1∨ · · · ∨ϕn) is true underI iff someϕi is:

I |= (ϕ1∨ · · · ∨ϕn) iff existsi∈ {1, . . . ,n} such thatI |=ϕi

(16)

Propositional Logic: Example

Consider truth assignmentI ={X 7→F,Y 7→T,Z 7→F}.

Is¬(X ∧(Y ∨ ¬(Z∧Y))) true under I?

(17)

D3. Proving NP-Completeness Propositional Logic

Propositional Logic: Exercise (slido)

Consider truth assignment

I ={X 7→F,Y 7→T,Z 7→F}.

Is(X ∨(¬Z∧Y))true underI?

(18)

More Propositional Logic

I (ϕ→ψ) is a short-hand notation for formula (¬ϕ∨ψ).

I (ϕ→ψ) is true under variable assignmentI if I ϕisnot trueunderI, or

I ψis true underI.

I If (ϕ→ψ) andϕare true underI then alsoψ must be true underI.

I (ϕ↔ψ) is a short-hand notation for formula ((ϕ→ψ)∧(ψ→ϕ))

I (ϕ↔ψ) is true under variable assignmentI if I both,ϕandψare true under I, or

I neitherϕnorψ is true underI.

(19)

D3. Proving NP-Completeness Propositional Logic

Short Notations for Conjunctions and Disjunctions

Short notation for addition:

X

x∈{x1,...,xn}x =x1+x2+· · ·+xn

Analogously (possible because of commutativity of∧ and∨):

^

ϕ∈Xϕ

= (ϕ1∧ϕ2∧ · · · ∧ϕn) _

ϕ∈Xϕ

= (ϕ1∨ϕ2∨ · · · ∨ϕn) forX ={ϕ1, . . . , ϕn}

(20)

SAT Problem

Definition (SAT)

The problemSAT(satisfiability) is defined as follows:

Given: a propositional logic formulaϕ Question: Isϕsatisfiable,

i.e. is there a variable assignmentI such thatI |=ϕ?

(21)

D3. Proving NP-Completeness Cook-Levin Theorem

D3.3 Cook-Levin Theorem

(22)

SAT is NP-complete

Definition (SAT)

The problemSAT(satisfiability) is defined as follows:

Given: a propositional logic formulaϕ Question: Isϕsatisfiable?

Theorem (Cook, 1971; Levin, 1973) SATis NP-complete.

Proof.

SAT∈NP: guess and check.

SATis NP-hard: somewhat more complicated (to be continued) . . .

(23)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (1)

Proof (continued).

We must show: A≤pSATfor all A∈NP.

LetAbe an arbitrary problem in NP.

We have to find a polynomial reduction ofAto SAT, i. e., a functionf computable in polynomial time

such that for every input wordw over the alphabet of A:

w ∈A iff f(w) is a satisfiable propositional formula. . . .

(24)

NP-hardness of SAT (2)

Proof (continued).

BecauseA∈NP, there is an NTM M and a polynomial p such thatM decides the problemA in timep.

Idea: construct a formula that encodes the possible configurations whichM can reach in time p(|w|) on input w

and that issatisfiable if and only if

an accepting configuration can be reachedin this time. . . .

(25)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (3)

Proof (continued).

LetM =hQ,Σ,Γ, δ,q0,qaccept,qrejecti be an NTM forA,

and letp be a polynomial bounding the computation time ofM. Without loss of generality,p(n)≥n for all n.

Letw =w1. . .wn∈Σ be the input forM.

We number the tape positions with natural numbers such that the TM head initially is on position 1.

Observation: withinp(n) computation steps the TM head can only reach positions in the setPos={1, . . . ,p(n) + 1}.

Instead of infinitely many tape positions, we now only

(26)

NP-hardness of SAT (4)

Proof (continued).

We can encode configurations ofM by specifying:

I what the currentstate of M is

I on which position in Pos theTM head is located

I which symbols from Γ thetape contains at positionsPos can be encoded by propositional variables

To encode a fullcomputation(rather than just one configuration), we needcopies of these variables for each computation step.

We only need to consider the computation steps Steps={0,1, . . . ,p(n)} becauseM should accept

withinp(n) steps. . . .

(27)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (5)

Proof (continued).

Use the following propositional variables in formulaf(w):

I statet,q (t ∈Steps,q ∈Q)

encodes the state of the NTM in thet-th configuration I headt,i (t ∈Steps,i ∈Pos)

encodes the head position in the t-th configuration I tapet,i,a (t∈Steps,i ∈Pos,a∈Γ)

encodes the tape content in thet-th configuration Constructf(w) such that every satisfying interpretation

I describes asequence of NTM configurations I that begins with the start configuration, I reaches an accepting configuration

(28)

NP-hardness of SAT (6)

Proof (continued).

Auxiliary formula:

oneof X := _

x∈X

x

!

∧ ¬

 _

x∈X

_

y∈X\{x}

(x∧y)

Auxiliary notation:

The symbol⊥stands for an arbitrary unsatisfiable formula

(e.g., (A∧ ¬A), whereA is an arbitrary proposition). . . .

(29)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (7)

Proof (continued).

1. describe the configurations of the TM:

Valid:= ^

t∈Steps

oneof {statet,q|q∈Q} ∧

oneof {headt,i |i ∈Pos} ∧

^

i∈Pos

oneof {tapet,i,a|a∈Γ}

. . .

(30)

NP-hardness of SAT (8)

Proof (continued).

2. begin in the start configuration Init:=state0,q0∧head0,1

n

^

i=1

tape0,i,wi ∧ ^

i∈Pos\{1,...,n}

tape0,i,

. . .

(31)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (9)

Proof (continued).

3. reach an accepting configuration

Accept:= _

t∈Steps

statet,qaccept

. . .

(32)

NP-hardness of SAT (10)

Proof (continued).

4. follow the rules inδ:

Trans:= ^

t∈Steps

statet,qaccept∨statet,qreject∨ _

R∈δ

Rulet,R

!

where. . . .

(33)

D3. Proving NP-Completeness Cook-Levin Theorem

NP-hardness of SAT (11)

Proof (continued).

4. follow the rules inδ (continued):

Rulet,hhq,ai,hq0,a0,Dii:=

statet,q∧statet+1,q0

^

i∈Pos

headt,i → tapet,i,a∧headt+1,i+D∧tapet+1,i,a0

^

i∈Pos

^

a00∈Γ

¬headt,i∧tapet,i,a00

→tapet+1,i,a00

I For i+D, interpret i+ R i+ 1, i+ L max{1,i−1}.

I special case: tape andhead variables with a tape index i+D

(34)

NP-hardness of SAT (12)

Proof (continued).

Putting the pieces together:

Setf(w) :=Valid∧Init∧Accept∧Trans.

I f(w) can be constructed in time polynomial in |w|.

I w ∈A iffM acceptsw in p(|w|) steps w ∈A ifff(w) is satisfiable

w ∈A ifff(w)∈SAT A≤pSAT

SinceA∈NP was arbitrary, this is true for every A∈NP.

HenceSATis NP-hard and thus also NP-complete.

(35)

D3. Proving NP-Completeness 3SAT

D3.4 3SAT

(36)

3SAT

More Propositional Logic: Conjunctive Normal Form

I A literalis an atomic proposition X or its negation¬X. I A clauseis a disjunction of literals,

e.g. (X∨ ¬Y ∨Z)

I A formula inconjunctive normal form is a conjunction of clauses,

e.g. ((X ∨ ¬Y ∨Z)∧(¬X ∨ ¬Z)∧(X ∨Y))

(37)

D3. Proving NP-Completeness 3SAT

Exercise (slido)

Which of the following formulas are in conjunctive normal form?

I ((X ∧ ¬Y ∧Z)∨(¬X ∧ ¬Z)) I (X∨ ¬Y ∨Z)

I ((¬X ∨ ¬Z)∧ ¬(X ∨Y)) I ((¬Y ∨X)∧(Y ∨ ¬Z))

(38)

3SAT

SAT ≤

p

3SAT

SAT

3SAT

Clique

IndSet

VertexCover

DirHamiltonCycle

HamiltonCycle

TSP

SubsetSum

Partition

BinPacking

(39)

D3. Proving NP-Completeness 3SAT

SAT and 3SAT

Definition (Reminder: SAT)

The problemSAT(satisfiability) is defined as follows:

Given: a propositional logic formulaϕ Question: Isϕsatisfiable?

Definition (3SAT)

The problem3SATis defined as follows:

Given: a propositional logic formulaϕ in conjunctive normal form with at most three literals per clause

Question: Isϕsatisfiable?

(40)

3SAT

3SAT is NP-Complete (1)

Theorem (3SATis NP-Complete) 3SATis NP-complete.

(41)

D3. Proving NP-Completeness 3SAT

3SAT is NP-Complete (2)

Proof.

3SAT∈NP: guess and check.

3SATis NP-hard: We showSAT≤p3SAT.

I Let ϕbe the given input for SAT. LetSub(ϕ) denote the set of subformulas of ϕ, includingϕitself.

I For all ψ∈Sub(ϕ), we introduce a new proposition Xψ. I For each new proposition Xψ, define the following

auxiliary formula χψ:

I Ifψ=Afor an atomA: χψ =(XψA) I Ifψ=¬ψ0: χψ =(Xψ↔ ¬Xψ0)

I Ifψ= (ψ0ψ00): χψ=(Xψ (Xψ0Xψ00)) I Ifψ= (ψ0ψ00): χ =(X (X 0X 00))

(42)

3SAT

3SAT is NP-Complete (3)

Proof (continued).

I Consider the conjunction of all these auxiliary formulas, χall :=V

ψ∈Sub(ϕ)χψ.

I Every variable assignment I for the original variables can be extended to a variable assignmentI0

under which χall is true in exactly one way:

for eachψ∈Sub(ϕ), setI0(Xψ) =T iff I |=ψ.

I It follows thatϕ is satisfiable iff (χall∧Xϕ) is satisfiable.

I This formula can be computed in linear time.

I It can also be converted to 3-CNF in linear time because it is the conjunction of constant-size parts involving at most three variables each.

(Each part can be converted to 3-CNF independently.) I Hence, this describes a polynomial-time reduction.

(43)

D3. Proving NP-Completeness 3SAT

Restricted 3SAT

Note: 3SAT remains NP-complete if we also require that I every clause containsexactly three literals and I a clause may not contain the same literal twice Idea:

I remove duplicated literals from each clause.

I add new variables: X,Y,Z

I add new clauses: (X∨Y ∨Z), (X∨Y ∨ ¬Z), (X ∨ ¬Y ∨Z), (¬X∨Y ∨Z), (X ∨ ¬Y ∨ ¬Z), (¬X ∨Y ∨ ¬Z),

(¬X∨ ¬Y ∨Z)

satisfied if and only if X,Y,Z are all true I fill up clauses with fewer than three literals

(44)

D3.5 Summary

(45)

D3. Proving NP-Completeness Summary

Summary

I Thousands of important problems are NP-complete.

I The satisfiability problem of propositional logic (SAT) is NP-complete.

I Proof idea forNP-hardness:

I Every problem in NP can be solved by an NTM in polynomial timep(|w|) for inputw.

I Given a wordw, construct a propositional logic formulaϕ that encodes the computation steps of the NTM on inputw.

I Constructϕso that it is satisfiable if and only if there is an accepting computation of lengthp(|w|).

I Usually (as seen for3SAT), the easiest way to show that another problem is NP-complete is to

I show that it is in NP with a guess-and-check algorithm, and

Referenzen

ÄHNLICHE DOKUMENTE

 Vitamin K2: In der medizinischen Praxis hat sich zur Prävention und Therapie von Atherosklerose und Osteoporose Vitamin K in der Form von Vita- min K2 (Menachinon MK-7)

Cohendet, 1997; Danish Agency for Science Technology and Innovation, 2008; Hertzfeld, 2002; Prognos AG, 2008). Face-to-face interviews were held in this evaluation with twenty key

Ziel ist es, dass ihr während des Abspielens des Filmes gleichzeitig die Stimme nachmachen könnt.“.. Auftrag für

Wenn Sie schwanger sind oder stillen, oder wenn Sie vermuten, schwanger zu sein oder beabsichtigen, schwanger zu werden, fragen Sie vor der Anwendung dieses Arzneimittels Ihren

– Wenn eine der aufgeführten Nebenwirkungen Sie erheblich beein- trächtigt oder Sie Nebenwirkungen bemerken, die nicht in dieser Gebrauchsinformation angegeben sind, informieren

Evaluation, Treatment, and Prevention of Vitamin D Deficiency: an Endocrine Society Clinical Practice Guideline.. The Journal of Clinical Endocrinology &

a) Ich und/oder Mitglieder der Bietergemeinschaft und/oder Subunternehmer verfüge(n) bereits jetzt über das gesamte in der Leistungsbeschreibung geforderte Personal. Wenn „NEIN“. b)

D3.2 Turing Machines as Words D3.3 Special Halting Problem D3.4 Reprise: Type-0 Languages D3.5 Reductions..