Post on 22-Dec-2015
1
The Cook-Levin Theorem
Zeph Grunschlag
2
Announcements
Last HW due Thursday Please give feedback about course at oracle.seas.columbia.edu/wces
3
Agenda
Proof from definition that CSAT is NP-complete (Cook-Levin Theorem)CSAT P 3SAT so 3SAT is NP-complete
4
Notation for NTM Branching
We need a way of dealing with all the possible choices that a non-deterministic TM can take at any point of the computation. Every NTM has a finite maximum on the number of choices possible, called the branching factor and denoted by b.
Q: What is b for the following?
0 1 32
a|bRbR
a|bR �L
5
Notation for NTM Branching
A: b= 2. This means that computation trees
are binary:
0 1 32
a|bRbR
a|bR �L
0ababa
a0baba
ab0aba ab1aba
aba0ba
abab0a abab1a
aba2ba
crash
ababa0
crash
ababa2
abab3a
6
Notation for NTM Branching
Given a state q and tape-symbol a in a NTM, (q,a ) is a set of possible state-symbol-direction outputs. Order this set and let the k ’th possibility be denoted by:where q’, a’ and D are the transition’s output.
When less than k possibilities were defined, just add transitions that go directly to the reject state and write blank:
Q: What are below?
),','(),(δ Daqaqk
0 1 32bR
a|bR �L
)L,,(),(δ reject qaqk ),0(δ ),0(δ ),,0(δ 221 abb and
a|bR
7
Notation for NTM Branching
A:
0 1 32bR
a|bR �L
)L,,reject(),0(δ
)R,,1( ),0(δ
)R,,0(),0(δ
2
2
1
a
bb
bb
a|bR
8
Boolean Uniqueness Expression
Let’s give some handy boolean expression in conjunctive normal form:
The uniqueness expression U says that exactly one of its arguments is true:
Here stands for the conjunction over all possible i,j.
Q: Why is each a 2-clause?
n
jijijin
in
xxxxx
xixxxU
,1,21
21
)()(
true",!" ),,,(
n
ji 1,
)( ji xx
9
Boolean Uniqueness Expression
A: and are logically equivalent.
Q: What is the size of U in terms of the number of variables?
)( ji xx )( ji xx
10
Boolean Uniqueness Expression
A: O (n2)
It will be convenient also to define U over a range of variable. For example we could express
instead by:),,,( 21 nxxxU
)(},,2,1{ ini xU
11
Cook-Levin TheoremTHM: Suppose we are given a NTM N and
a string w of length n which is decided by N in f (n) or fewer nondeterministic steps. Then there is an explicit cnf formula of length O (f (n)3) which satisfiable iff N accepts w. In particular, when f (n) is a polynomial, has polynomial length in terms of n so that every language in NP reduces to CSAT in polynomial time. Thus CSAT is NP-hard. Finally, as CSAT is in NP, CSAT is NP-complete.
12
Confusing IndicesThe most confusing thing about the
proof of the Cook-Levin Theorem are all the indices. We use the following conventions:a –index for letters in tape alphabetq –index for NTM statesi –index for tape cellst –index for computation step (time)k –index for branching choice
Q: How many choices for each index?
13
Confusing Indices
A: The number of choices area : || the size of tape alphabetq : |Q| the number of statesi : f (n), since ranges from 1 to f (n)t : f (n)+1, since ranges from 0 to f (n)k : b, since ranges from 1 to branching factor b
14
Variables forSimulating NTM
Computation
T-variables will track the possible symbols on the tape cells at each step in computation
Tt,i,a = true iff at time t, i’ th cell reads a
S-variables will track the active state at each step in computation
St,q = true iff at time t in state q
15
Variables forSimulating NTM
Computation
H-variables gives the head’s positionHt,i = true iff at time t reading i’ th cell
C-variables gives the nondeterministic choice at each step in computation
Ct,k = true iff at time t +1 take choice k
16
Boolean Expressions forSimulating NTM
ComputationInitialize the NTM. Insist that at time 0:1) TM should be in the start state2) Given input w = a1 a2 … an, cells 1
through n should contain the ai and all the rest should be blank
3) Head should be at left-most cell i =1Together these give:
1,0
)(
1,,0
1,,0,0start start
φ HTTSnf
nii
n
iaiq i
17
Boolean Expressions forSimulating NTM
Computation
Ending configuration should accept:
accept),(endφ qnfS
18
Boolean Expressions forSimulating NTM
ComputationAt each time step t :A. Machine is in a unique state:
B. Each tape cell has a unique symbol:
)(
0,A )(φ
nf
tqtQq SU
)(
0
)(
1,,B )(φ
nf
t
nf
iaita TU
19
Boolean Expressions forSimulating NTM
ComputationC. Head is reading unique cell:
D. Unique choice considered:
E. If already accepted, accept at t+1:
1)(
0,2,1,D ),,,(φ
nf
tbttt CCCU
1)(
0,1,E acceptaccept
φnf
tqtqt SS
1)(
0)(,2,1,C ),,,(φ
nf
tnfttt HHHU
20
Boolean Expressions forSimulating NTM
ComputationF. If already rejected, reject at t+1:
G. Cells which aren’t being read remain the same at time t+1:
Q: Why can (x y z ) be considered a clause?
1)(
0
)(
1,,1,,,G )(φ
nf
t
nf
i aaitaitit TTH
1)(
0,1,F rejectreject
φnf
tqtqt SS
21
Boolean Expressions forSimulating NTM
Computation
A: (x y z ) is logically equivalent to (x y z )
22
Boolean Expressions forSimulating NTM
ComputationFinally, given the branching choice k,
and the current configuration, the next configuration should follow according to k’th -function choice:
)(
)(
)(
)],','(),(δ[φ
',,1,,,,,
,1,,,,,
',1,,,,,
1)(
0
)(
1 , 1H
aitktqtaitit
Ditktqtaitit
qtktqtaitit
nf
t
nf
i Qqa
b
k k
TCSTH
HCSTH
SCSTH
Daqaq
23
Boolean Expressions forSimulating NTM
ComputationRequiring all of the component cnf
formulas to be true, simulates the NTM:
Finally, let’s make sure that this is a poly-time reduction. The formulas are explicitly defined so running time is same as total space:
endHGFEDCBAstart φφφφφφφφφφ
φ
24
Space complexity
start --O( f (n) )
A --O( f (n) · |Q |2 )
B --O( f (n)2 · ||2 )
C --O( f (n) · f (n)2 )
D --O( f (n) · b 2 )
E --O( f (n) )
F --O( f (n) )
G --O( f (n)2 · || )
H --O( f (n)2 · || · |Q | · b )
end -- O( 1 ) Total: -- O( f (n)3 )
endHGFEDCBAstart φφφφφφφφφφ
φ
25
Conclusion of Cook-Levin Proof
Thus, any NTM that runs in time f (n) can have it’s inputs of size n converted into size O (f (n)3) instances of CSAT.
So if f (n) is a polynomial, the reduction runs in polynomial time on a RAM (since the cube of a polynomial is a polynomial).
This proves that CSAT is NP-complete. �
26
Reducing CSAT to 3SATEach clause with more than 3 literals can be converted
into a conjunction of clauses with at most 3 literals. EG:(a b c d e f ) (a b x )(xc d e f ) (a b x )(xc y )(yd e f ) (a b x )(xc y )(yd z)(ze f ) (a b x )(x c y )(y d z)(z e f )
Q: How many 3-clauses are needed to simulate an n-clause?
27
Reducing CSAT to 3SATA: Each substitution got rid of one extra
variable, except for first. So need n-2 = O (n) 3-clauses to simulate an n-clause.
Therefore, any instance of nSAT of size k is converted to an instance of 3SAT of size O (nk ). Any instance of CSAT of size k is at worst-case, a single clause of size k so can be converted to an instance of 3SAT of size O (k 2). This completes the poly-time reduction from CSAT to 3SAT.
28
Blackboard Exercise
Show that 2SAT is in P.