Computational Models — Lecture 12
Handout Mode
Roded Sharan.
Tel Aviv University.
June, 2018
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 1 / 49
Talk Outline
I NP-completeness
I Satisfiability
I Cook-Levin theorem
I CSAT ∈ NPCI 3SAT ∈ NPCI Clique is NPC
I Hamiltonian Path and Hamiltonian Cycle are NP-Complete
Sipser’s book, 7.4–7.5
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 2 / 49
Section 1
NP Completeness
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 3 / 49
NP Completeness
P
NP
NP-complete
The class of NP-complete languages are
I “hardest” languages in NPI If any NP-complete L ∈ P, then NP = P.
Question 1Are there NP-complete languages?
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 4 / 49
Polynomial-time reducibility
Definition 2 (poly-time computable functions)
A function f : Σ∗ 7→ Σ∗ is polynomial-time computable, if there is a poly-timedeterministic TM thatI starts with input w , and
I halts with f (w) on tape.
Definition 3 (poly-time reduction)
A polynomial-time computable f : Σ∗ 7→ Σ∗ is a poly-time reduction fromlanguage A to B, if x ∈ A⇐⇒ f (x) ∈ B for every x ∈ Σ∗.Is such a reduction from A to B exists, we say that A is poly- time mappingreducible to B, denoted A ≤P B.
The mapping f efficiently converts questions about membership in A tomembership in B.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 5 / 49
Example: CLIQUE ≤P IND-SET
Proof:
Definition 4The complement of a graph G = (V ,E) is a graph Gc = (V ,Ec), whereEc = {(v1, v2) : v1, v2 ∈ V and (v1, v2)6∈E}.
The reduction f (G, k) from CLIQUE to IND-SET simply computes thecomplement of the graph and outputs (Gc , k).
f satisfies:
I U is a clique in G ⇐⇒ U is a independent set in Gc .
I computable in polynomial time!
♣
Remark 5Same reduction shows that IND-SET ≤P CLIQUE
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 6 / 49
Reductions to P
Theorem 6
If A ≤P B and B ∈ P then A ∈ P.
Proof:
I Let f the reduction from A to B, computed by TM Mf .On input x , the TM Mf makes at most cf · |x |af steps.
I Let MB be the poly-time decider for B.On input y , the TM MB makes at most cB · |y |aB steps.
Algorithm 7 (Decider MA for A)
On input x , return MB(f (x))
I MA decides A
I Since |f (x)| ≤ cf |x |af , running time of MB(x), is at mostcB · (cf · |x |af )aB = (cB · caB
f ) · |x |af ·aB ∈ poly(|x |)Hence, A ∈ P
♣ Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 7 / 49
What A ≤P B tells us about B?
Question 8Assume that {0n1n : n ≥ 0} ≤P L. Does it yield that L ∈ P?
Answer: No. (Reduction in the wrong direction!)
Let L = HTM,ε and define f (x) =
{Mstop, x ∈ {0n1n : n ∈ N}Mno−stop, otherwise. .
A ≤P B does tell us that B is “at least as hard" as A.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 8 / 49
NP completeness, formal definition
Definition 9 (NP-complete)
A language B is NP-complete, if
I B ∈ NP, and
I Every A ∈ NP is poly-time reducible to B (i.e., A ≤P B)
Let NPC denote the class of all NP-complete languages.
Compare to
Definition 10 (RE-complete)
A language B is RE-complete, if
I B ∈ RE , and
I Every A ∈ RE is mapping reducible to B.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 9 / 49
Why NP completeness?
Theorem 11
If B ∈ NPC and B ∈ P, then P = NP.
Proof: Immediately follows by Thm 6. ♣
To show P = NP (and make an instant fortune, seewww.claymath.org/millennium/P_vs_NP/), suffices to find a polynomial-timealgorithm for any NP-complete problem.
Question 12Is NPC empty?
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 10 / 49
NPC Is not empty
ANP = {〈M, x ,1n〉 : M is a TM ∧ ∃c ∈ Σ∗ s.t. M(x , c) accepts within n steps}.
Theorem 13ANP ∈ NPC
Proof:
I Clearly ANP ∈ NP.
I Let L ∈ NP, let V be a verifier for L and let p ∈ poly be a bound on therunning time of V (i.e., V(x , ·) halts within p(|x |) steps, for every x ∈ Σ∗).
I Define f (x) = 〈V, x ,1p(|x|)〉.I f is poly-time computable
I x ∈ L⇐⇒ f (x) ∈ ANP.
♣
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 11 / 49
Finding additional NP-complete languages
Theorem 14Assume that
1. B ∈ NP
2. A ∈ NPC and A ≤P B
then B ∈ NPC.
Proof: Home exercise . . .♣
We would like to find L ∈ NPC that is “natural" and “easy" to reduce to.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 12 / 49
Section 2
Satisfiability
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 13 / 49
Boolean variables
I A Boolean variable assumes values
I TRUE (written 1), and FALSE (written 0).
I Boolean operations:
I and: ∧I or: ∨I not: ¬
I Examples:
0 ∧ 1 = 00 ∨ 1 = 1
0 = 1
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 14 / 49
Boolean formulas and SAT
A Boolean formula is an expression involving Boolean variables andoperations.
φ = (x ∧ y) ∨ (x ∧ z)
Definition 15 (satisfiable formula)
A formula is satisfiable, if some Boolean assignment to its variables, makesthe formula evaluate to 1.
The formula φ = (x ∧ y) ∨ (x ∧ z) is satisfiable by the assignment
x = 0y = 1z = 0
The language of satisfied formulas:
SAT = {〈φ〉 : φ is a satisfiable Boolean formula}
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 15 / 49
SAT ∈ NPC
SAT = {〈φ〉 : φ is satisfiable Boolean formula}
Theorem 16 (Cook-Levin (early 70s))SAT ∈ NPC.
I The “most important" NP-complete language.
I It is easy to see that SAT ∈ NP
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 16 / 49
Section 3
Proving SAT ∈ NPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 17 / 49
The proof, high level
I Let L ∈ NP and let N = (Q,Σ, Γ, δ,q0,qa,qr ) be an t-time NTM thataccepts L, for some t ∈ poly.
I Given the string w ∈ {0,1}∗, construct in time O(t(|w |)2) a formula φN,wsuch that:
φN,w ∈ SAT⇐⇒ N accepts w
I Hence, the mapping w 7→ φN,w is a poly-time reduction from L to SAT,establishing L ≤P SAT.
I In the following fix L, N and w ∈ {0,1}n and let t = t(n).
I We assume for simplicity that M(w) halts after exactly t − 1 steps.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 18 / 49
The configuration-history Tableau
Consider the t-by-t Tableau that describes a possible accepting computationhistory of N on input w .
cell[1,1]
cell[1,t(n)]
q 0 0 10 0 . . .
1 2 3 . . . t(n)
0 0
0
1
I First row represents initial configuration of N on input w .I i ’th row represents the i-th configuration in a possible computation of N
on input w .
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 19 / 49
The formula φN,w
I Let S = Q ∪ Γ (the alphabet of the configuration history).
I φN,w uses Boolean variables {xi,j,s}i,j∈[t],s∈S.
φN,w = φCell(N) ∧ φStart(w) ∧ φMove(N) ∧ φAccept(N)
I Given an assignment z for φN,w , let T (z) be the t × t Tableau, defined bysetting the j-th cell in i ’th configuration to s, if xi,j,s = 1 in z.
(T (z) is undefined, if xi,j,s′ = xi,j,s = 1 for some s 6= s′ ∈ S, or xi,j,s = 0for all s ∈ S).
I T (z) will represents a (possible) accepting execution of N(w) iff z is ana satisfying assignment for φN,w .
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 20 / 49
The formula φCell(N)
φCell(N) guarantees that the variables encode legal configurations:
I Each cell (i , j) has at least one letter:∨
s∈S xi,j,s.
I No cell (i , j) has two or more letters∧
s 6=s′∈S xi,j,s ∧ xi,j,s′ .
Together:
φCell(N) =∧i,j
(∨s∈S
xi,j,s
)∧
∧s 6=s′∈S
xi,j,s ∧ xi,j,s′
Claim 17If an assignment z satisfies φCell(N), then T (z) is defined.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 21 / 49
The formula φStart(w)
φStart(w) guarantees that the first row encodes the initial configuration (i.e.,q0w).
φ start(w) =x1,1,q0 ∧ x1,2,w1 ∧ x1,3,w2 ∧ . . . ∧ x1,n+1,wn
∧ x1,n+2, ∧ . . . ∧ x1,t,
Claim 18If z satisfies φCell(N) ∧ φStart(w), then the first line of T (z) is q0w t . . .t︸ ︷︷ ︸
t−n−1
.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 22 / 49
The formula φMove(N)
φMove(N) is the “heart” of φN,w . To construct it, we employ locality ofcomputations.
Observation: Configuration C, with head location h, yields configuration C′
(with respect to δ), if the following holds.
I C′i =Ci for any i /∈ {h − 1,h,h + 1}I C′h−1,h,h+1 is consistent (with respect to δ) with Ch−1,h,h+1.
We check that each configuration in T (z) yields the next one, by inducinglocal “checks” on z.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 23 / 49
φMove(N) – Rectangles
I A rectangle is a 2× 3 configuration sub-table.
I Assume δ(q1,a) = {(q1,b,R)} and δ(q1,b) = {(q2, c, L), (q2,a,R)}.I (some) Legal 2× 3 rectangles:
a q1 b a q1 b a a q1q2 a c a a q2 a a b
a b a b b b a a ba b q2 c b b a a b
I (some) Illegal 2× 3 rectangles:
a b a a q1 b b q1 ba a a q1 a a q2 b q2
I There is a constant number of legal rectangles (determined by δ).
I Denote this set by C = C(δ)
(we will be somewhat liberal.allowing some illegal if notation simpler)
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 24 / 49
φMove(N) – Characterizing legal rectangles
The formula “verifies" that all 2× 3 rectangles in the Tableau are in the list C:
1. a b c∗ b ∗
2.a q bq’ a b’
a q ba b’ q’
(L,q′,b′) ∈ δ(q,b) (R,q′,b′) ∈ δ(q,b)
3. q ∗ ∗∗ ∗ ∗
∗ ∗ q∗ ∗ ∗
• Some rectangles in C are clearly illegal.
• For rectangles on the left-most and right-most side of Tableau, we useslightly different first type rectangles.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 25 / 49
φMove(N)– formal definition
I For each entry (i , j) ∈ [t ]× [t ] and c ∈ C, let φMove,i,j,c be the formulataking the value 1 iff the 2× 3 table of cells in the Tableau whoseupper-left corner is (i , j) is c.
For instance, for entry (1,1) and c =a q1 bq2 a d ,
let φMove,1,1,c = x1,1,a ∧ x1,2,q1 ∧ x1,3,b ∧ x2,1,q2 ∧ x2,2,a ∧ x2,3,d
I Finally, let φMove(N) =∧
(i,j)∨
c∈C φMove,i,j,c .
Claim 19If z satisfies φCell(N) ∧ φStart(w) ∧ φMove(N), then T (z) is a possible configurationhistory of N(w).
Proof: By induction on the row index. Base case: z satisfies φCell(N) ∧φStart(w).Assume configuration defined in rows 1, . . . , i is possible and head is in cell j .The configuration of rows 1, . . . , i + 1 is also possible: Cells of indices not in{j − 1, j , j + 1}, by first type of rectangles in C. Other cells, by second typerectangles in C. Q: Why do we need the third type of cells?
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 26 / 49
The formula φAccept(N)
φAccept(N) guarantees that some row encodes an accepting configuration ( i.e.,uqav ):
φAccept(N) =∨i,j
xi,j,qa
Claim 20If z satisfies φN,w = φCell(N) ∧ φStart(w) ∧ φMove(N) ∧ φAccept(N), then T (z) is anaccepting configuration history of N(w).
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 27 / 49
Correctness of reduction
I The transformation w 7→ φN,w is computable in time O(n2c).
I An assignment satisfying φN,w , corresponds to an acceptingconfiguration history of N(w).
I An accepting configuration history of N(w) corresponds to anassignment satisfying φN,w . (?)
Therefore, N accepts w iff φN,w ∈ SAT. ♣.
I For complete details, consult Sipser chapter 7.4.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 28 / 49
Section 4
CSAT ∈ NPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 29 / 49
CSAT
It is useful to consider a special version of SAT.
I A literal is a variable or negated variable: x or x .
I A clause is several literals joined by ∨s: (x1 ∨ x2 ∨ x3)
I A Boolean formula is in conjunctive normal form (CNF) if it consists ofclauses, connected with ∧s.
I For example: (x1 ∨ x2 ∨ x3 ∨ x4) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6)
I The language of satisfied CNF formulas:
CSAT = {〈φ〉 : φ is satisfiable CNF formula}
I Clearly, CSAT ≤P SAT (no need Cook-Levin for that).
I The proof of Cook-Levin can be modified to show that CSAT is NPC(take home exercise..)
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 30 / 49
Section 5
3SAT ∈ NPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 31 / 49
3SAT
Definition 21A Boolean formula is in k-CNF form, if it is a CNF formula, and all clauseshave k literals.
Example of 3CNF: (x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)
The language of satisfied 3CNF formulas:
3SAT = {〈φ〉 : φ is satisfiable 3CNF formula}
I Clearly 3SAT ≤P SAT.
I and 3SAT ∈ NP.
I We show next that CSAT ≤P 3SAT, yielding that 3SAT ∈ NPC.I Interestingly, 2SAT ∈ P
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 32 / 49
CSAT ≤P 3SAT
I The reduction maps CNF formulae to 3CNF ones “clause by clause”.
I A clause with d ≤ 3 literals is mapped to equivalent clause with 3 literals.
(x1 ∨ x2) 7−→ (x1 ∨ x2 ∨ x2)
I A clause with d > 3 literals is mapped to d − 2 clauses, built on theoriginal literals together with (d − 3) new variables.
φ = (x1 ∨ x2 ∨ x3 ∨ x4 ∨ x8) 7−→φ3 = (x1 ∨ x2 ∨ y1) ∧ (y1 ∨ x3 ∨ y2) ∧ (y2 ∨ x4 ∨ x8)
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 33 / 49
The reduction works!
Claim 22φ has a satisfying assignment iff φ3 does.
Proof’s idea: (for case d > 3)⇐ Given a satisfying assignment for φ3, use the settings of the xi ’s to getsatisfying assignment for φ. Why does it work? For each set of clauses thatcame from a clause in φ, note that each yi sets exactly one clause to true.There are k − 2 clauses but only k − 3 yi ’s. So at least one clause needs tobe satisfied by one of the xj or xj literals. Set this literal to true in φ.
⇒ An assignment satisfying φ, makes at least one literal per clause happy. Inthe “φ3 clause” of this literal the new variables are under no constraints. Usethe d − 2 new variables to set the remaining d − 2 clauses to “true”.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 34 / 49
CSAT ≤P 3SAT, cont.
φ = (x1 ∨ x2 ∨ x3 ∨ x4 ∨ x8) 7−→φ3 = (x1 ∨ x2 ∨ y1) ∧ (y1 ∨ x3 ∨ y2) ∧ (y2 ∨ x4 ∨ x8)
I Doing the above mapping to each clause of a CNF formula, we get a3CNF that is satisfied iff the original one is.
I Since this mapping is polynomial time (?), we get CSAT ≤P 3SAT. ♣.
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 35 / 49
Section 6
Clique is NPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 36 / 49
3SAT ≤P CLIQUE
CLIQUE = {〈G, k〉 : G is an undirected graph with a k -clique}
Claim 233SAT ≤P CLIQUE.
Since CLIQUE ∈ NP, it follows that CLIQUE ∈ NPC.Since IND-SET ∈ NP, and CLIQUE ≤P IND-SET, it follows thatIND-SET ∈ NPC.
Proof’s idea: We’ll construct a poly-time reduction f that maps 3CNF formulaeφ to pairs 〈G, k〉 of graphs and numbers.
The function f will have the property that φ is satisfiable, iff G has a clique ofsize k .
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 37 / 49
Proving 3SAT ≤P CLIQUE
On input φ, a 3CNF formula, the mapping reduction is defined as follows:
let k be the number of clauses in φ.
We construct a graph G = G(φ), see below, and output (G, k).
The graph G is defined as follows:
I Nodes in G are organized into triples t1, . . . , tk .
I Each triple corresponds to a clause of φ
I Each node in a triple corresponds to a literal in corresponding clause.
Ongoing example:
(x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x6 ∨ x4)
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 38 / 49
Nodes of G
φ =(x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x4 ∨ x6)
Add a node per literal
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 39 / 49
Edges of G
Add edges between all vertex pairs, exceptI within same tripleI between contradictory literals (e.g., x3 and x3)
φ = (x1 ∨ x2 ∨ x3) ∧ (x3 ∨ x5 ∨ x6) ∧ (x3 ∨ x4 ∨ x6)
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 40 / 49
φ ∈ 3SAT =⇒ 〈G, k〉 ∈ CLIQUE
Proof: Suppose φ is satisfiable by an assignment ψ.With respect to ψ:I At least one literal is assigned to 1 in every clause (?)I Select a 1-literal in every tuple;I These literals can be joined by edges (?)
Yielding a k -clique in G.
♣Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 41 / 49
〈G, k〉 ∈ CLIQUE =⇒ φ ∈ 3SAT
Proof: Suppose G has a k -clique.
I No two of the cliques nodes are in the same triple. (?)I G has 3k vertexes and k clauses, so each triple has exactly one clique
node.I Assign 1 to each node in cliqueI Assignment has no contradictions (?)
Yielding a satisfying assignment to φ.
♣ Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 42 / 49
Recap
I We’ve constructed a poly-time computable function f .
I We saw that f has the property that φ ∈ 3SAT iff f (φ) ∈ CLIQUE.
I Therefore, f is a poly-time reduction from 3SAT to CLIQUE
=⇒ 3SAT ≤P CLIQUE. ♣
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 43 / 49
Section 7
Hamiltonian Path and Hamiltonian Cycle areNPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 44 / 49
Reminder – Hamiltonian Path
A Hamiltonian path in a directed G visits each node exactly once.
HAMPATH = {〈G, s, t〉 : G has Hamiltonian path from s to t}
Theorem 24HAMPATH ∈ NPC.
Soon
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 45 / 49
Hamiltonian Cycle
A Hamiltonian cycle in a graph is an Hamiltonian path that ends up where itstarts (i.e., s = t).
HAMCYCLE = {〈G〉 : G has Hamiltonian cycle}
Clearly HAMCYCLE ∈ NP. We will show that HAMPATH ≤P HAMCYCLE,
and deduce that HAMCYCLE ∈ NPC
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 46 / 49
HAMPATH ≤P HAMCYCLE.
Proof’s idea:
Hey, is the new vertex really needed? Why not just add an edge from t to s?
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 47 / 49
HAMPATH ≤P HAMCYCLE.
Why the new vertex really needed? Why not just add an edge from t to s?
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 48 / 49
CSAT ≤P HAMPATH
For any CNF formula φ with clauses c1, . . . , c` and variables x1, . . . , xk , weconstruct a directed graph G with vertices s and t , such that
φ ∈ CSAT⇐⇒ 〈G, s, t〉 ∈ HAMPATH
thus establishing
Theorem 25HAMPATH,HAMCYCLE ∈ NPC
Turn to a separate pdf presentation:tau-cm2017a.wdfiles.com/local--files/course-schedule/ham-reduction-new.pdf
Roded Sharan (TAU) Computational Models, Lecture 12 June, 2018 49 / 49