Anda di halaman 1dari 49

WSAC2010 Talk

11st, January, 2010

Cook-Levin Theorem
Proof and Illustration

Kwak, Nam-ju
Applied Algorithm Laboratory
KAIST

Applied Algorithm Lab. KAIST

Contents
NP
NP-complete
SAT Problem
A Characteristic of NP-complete
Cook-Levin Theorem
Proof of Cook-Levin Theorem
Illustration
Corollary: 3SATNPC
Applied Algorithm Lab. KAIST

NP
Definition
NP is the class of languages that have polynomial
time verifiers.

Definition (informal)
A verifier V for a language A is an algorithm which
accepts a given input w to A if a corresponding
certificate or a proof c exists.

Applied Algorithm Lab. KAIST

NP
Theorem
A language is in NP iff it is decided by some
nondeterministic polynomial time Turing
machine.

Applied Algorithm Lab. KAIST

NP-complete
Definition
A language B is NP-complete if
BNP, and
ANP, APB.

Applied Algorithm Lab. KAIST

NP-complete
Examples
SAT, 3SAT, CLIQUE, VERTEX-COVER,
HAMPATH, SUBSET-SUM, and etc.

Applied Algorithm Lab. KAIST

SAT Problem
Definition
Boolean variables: variables that can take on
the values TRUE and FALSE
Boolean operations: AND, OR, and NOT
Boolean formula: an expression involving
Boolean variable and operations

Applied Algorithm Lab. KAIST

SAT Problem
Definition
satisfiable: if some assignment of 0s and 1s
to the variables make the formula evaluate to
1

Example of a satisfiable Boolean formula


=(xy)(xz)
x=0, y=1, and z=0

Applied Algorithm Lab. KAIST

SAT Problem
Definition (SAT Problem)
SAT = {<>| is a satisfiable Boolean
formula}.

Given a Boolean formula, is it satisfiable?

Applied Algorithm Lab. KAIST

A Characteristic of NP-complete
Theorem
If BNPC and BPC for CNP, then CNPC.

Is there a fundamental problem for the


chain of polynomial time reducibility?
P1PP2P PPnP(?)

Applied Algorithm Lab. KAIST

10

Cook-Levin Theorem
Cook-Levin Theorem
SATNPC

P1PP2P PPnPSAT

Applied Algorithm Lab. KAIST

11

Proof of Cook-Levin Theorem


What to prove is
SATNP (very clear, not treated here)
ANP, APSAT
We would show that for each language ANP with a
given input w to it, it is possible to produce a Boolean
formula which is
satisfiable if wA.

Definition
APB if f such that wAf(w)B and f is
polynomial time computable.
Applied Algorithm Lab. KAIST

12

Proof of Cook-Levin Theorem


NP

input w

Pick one.

Input
Boolean formula
Lets construct
this Boolean
formula!!

SAT

wA or not?

SAT or not?

Applied Algorithm Lab. KAIST

13

Proof of Cook-Levin Theorem


Proof idea
For each language A in NP, with a given input
w for A, produce a Boolean formula that
simulates the deciding NP Turing machine for
A on input w.
Check if the Boolean formula is satisfiable.

Applied Algorithm Lab. KAIST

14

Proof of Cook-Levin Theorem


wA?

NP Turing machine

Focus on this step.

given
transformation

Boolean formula
SAT problem
If satisfiable, wA; otherwise, wA.
Applied Algorithm Lab. KAIST

15

Proof of Cook-Levin Theorem


Proof idea (cont.)
If wA, there exists a series of configurations
that results in the accept state, given w as the
input of the Turing machine.
We would construct a Boolean formula which
is satisfiable if the Turing machine accepts
with the input w.

Applied Algorithm Lab. KAIST

16

Proof of Cook-Levin Theorem


FYI: Turing machine notation example
(q0,0)={(q1,x,R)}, (q1,1)={(q1,y,R)}, (q1, )={(qaccept, ,L)}
This Turing machine accepts {01+}

With 0111 as an input,


q00111
xq1111
xyq111
xyyq11
xyyyq1
xyyyqa
Applied Algorithm Lab. KAIST

17

Proof of Cook-Levin Theorem


Proof
w: input
A: language
N: NP Turing machine that decides A
Assume that N decides whether wA in nk steps,
for some constant k.

Applied Algorithm Lab. KAIST

18

Proof of Cook-Levin Theorem


Proof (cont.)
nknk-celltableau for N on input w
#

q0

w1

w2

wn

start configuration

second configuration

nk

Applied Algorithm Lab. KAIST

nk

nk th configuration

19

Proof of Cook-Levin Theorem


Proof (cont.)
A variable could be represented as xi,j,s.
xi,j,s: true if cell[i,j] is s; otherwise, false.
cell[i,j]: the cell located on the ith row and the
jth column.

Applied Algorithm Lab. KAIST

20

##

qxq0 0q1 w1 w1w


q32 w
2

w
n

wn

##

wn

##

##

qx1

w
q12

#
#

#
#
Proof
Theorem
x
q
of
w Cook-Levin

1

Proof (cont.)

The tableau, without any restriction, can


#
#
contain many invalid series
of configurations.
e.g. cells containing multiple symbols, not
starting with the input w and start state q0,
neighbor configurations not corresponding the
transition rules, not resulting in the accept
state, and etc.

Applied Algorithm Lab. KAIST

21

Proof of Cook-Levin Theorem


Proof (cont.)
Produce a Boolean formula which forces the
tableau to be valid and result in the accept
state.

Applied Algorithm Lab. KAIST

22

Proof of Cook-Levin Theorem


Proof (cont.)
One cell can contain exactly one symbol among a
state, a tape alphabet, and a #. (cell)
The first configuration should be corresponding to
input w and the start state q0. (start)
A configuration is derivable from the immediately
previous configuration according to the transition rule
of the Turing machine. (move)
There should exist a cell containing the accept state.
(accept)
=cellstartmoveaccept
Applied Algorithm Lab. KAIST

23

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept

Each cell contain at


least one symbol.

Each cell contain no


more than one
different symbol.

Here, C=Q{#} where Q and are the state set and


tape alphabet of the Turing machine N.
Applied Algorithm Lab. KAIST

24

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept

Each cell of the first row has a


symbol corresponding to the start
configuration where the input is w.

Applied Algorithm Lab. KAIST

25

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept

At least one cell is the accept state.

Applied Algorithm Lab. KAIST

26

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept
move checks whether every 23 window is
legal according to the transition rule of the
Turing machine.
#

#
#

q0

q1

Applied Algorithm Lab. KAIST

27

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept
For example,
(q1,a)={(q1,b,R)}, (q1,b)={(q2,c,L), (q2,a,R)}
a

q1

#
q2
a
c
a
a
b
some examples of legal 23 windows

q1

q1

q1

q1
a
a
q2
b
some examples of illegal 23 windows
Applied Algorithm Lab. KAIST

q2
28

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept
When Si,j is the set of legal (i, j)-windows and
Ui,j is the set of all the (i, j)-windows,
Si,jUi,j, |Ui,j|=|C|6 |Si,j||C|6
|S|=|Si,j|n2k|C|6
That is, the set of legal windows is finite.

Applied Algorithm Lab. KAIST

29

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept

That is, for all legal


(i, j)-windows, which
is represented as
a1

a2

a3

a4

a5

a6

Applied Algorithm Lab. KAIST

30

Proof of Cook-Levin Theorem


Proof (cont.)
=cellstartmoveaccept

Now, we get as we wished.


If is satisfiable, wA. That is, to see if
wA, we just need to check whether is
satisfiable or not.
It is just a SAT problem.
Applied Algorithm Lab. KAIST

31

Proof of Cook-Levin Theorem


What to prove is (restated)

SATNP (very clear, not treated here)


ANP, APSAT

Definition (restated)

APB if f such that wAf(w)B and f is polynomial time


computable.

What weve shown is

w, A, and wA
f(w)=, B=SAT, and =f(w)B=SAT
wASAT
APSAT

Applied Algorithm Lab. KAIST

32

Illustration
N=(Q, , , , q0, qaccept)

Q={q0, q1, qaccept}


={0, 1}, ={0, 1, }
(q0,0)={(q1,0,R)}
(q1,1)={(q1,1,R)}
(q1, )={(qaccept, ,L)}

A=L(N)={01+}={01, 011, 0111, 01111, }


w=0111
Then, wA?
Applied Algorithm Lab. KAIST

33

Illustration
N can decide in n2 steps where n=|w|.
Therefore n2 is 16.
C={q0, q1, qaccept, 0, 1, , #}
#

1616 tableau
Applied Algorithm Lab. KAIST

q0

#
34

Illustration

Applied Algorithm Lab. KAIST

35

Illustration

Applied Algorithm Lab. KAIST

36

Illustration

Applied Algorithm Lab. KAIST

37

Illustration
For move, find out all the legal windows.

q0

q0

q0

q1

q1

q1

q1

q1

q1

q1

q1

q1

q1

q1

q1

q1

q1

qacc

qacc

qacc

No more than n2k|C|6=42*246=410 legal windows exist. (finite)

Applied Algorithm Lab. KAIST

38

Illustration

Applied Algorithm Lab. KAIST

39

Illustration
Now, we get =cellstartmoveaccept.

Applied Algorithm Lab. KAIST

40

Illustration

Solve a SAT problem with this Boolean formula, .


If satisfiable, w=0111A={01+}. (Actually, it is right.)
Applied Algorithm Lab. KAIST

41

Corollary: 3SATNPC
CNFs can be converted into CNFs with
three literals per clause (as explained
soon).
At first, convert cell, start, move, and accept
into CNF.

Applied Algorithm Lab. KAIST

42

Corollary: 3SATNPC
cell, start, and accept are already in CNF.

Applied Algorithm Lab. KAIST

43

Corollary: 3SATNPC
move is converted into CNF using the
distributive laws.

To CNFs have 3 literals per clause


For each clause with less than 3 literals, do
literal replication.
For each clause with more than 3 literals, split
it with new variables.
Applied Algorithm Lab. KAIST

44

Corollary: 3SATNPC
Examples
(a1a2)(a1a2a2)
(a1a2a3a4)(a1a2z)(za3a4)
(a1a2a3a4a5)
(a1a2z1)(z1a3z2)(z2a4a5 )

Applied Algorithm Lab. KAIST

45

Corollary: 3SATNPC
Hence, a SAT problem is able to converted
into a equivalent 3SAT problem (in
polynomial time).
That is, SATP3SAT.
Since SATNPC, considering the definition
of NPC, 3SATNPC, too.

Applied Algorithm Lab. KAIST

46

Conclusion
Theorem (restated)
SATNPC
3SATNPC

All the NP problems are


polynomial time reducible
into SAT.
<Important NP-complete problems>
Picture from http://www.wikipedia.org
Applied Algorithm Lab. KAIST

47

Q&A
Please, ask questions, if any.

Applied Algorithm Lab. KAIST

48

Thank you!

Contents covered are based on Introduction to the Theory of Computation, 2nd ed. written by
Michael Sipser.

The slide theme and the background image are from http://www.m62.net/.
Applied Algorithm Lab. KAIST

49

Anda mungkin juga menyukai