3-Color, Circuit-SAT and SAT Lecture 24 December 1, 2015 Chandra - - PowerPoint PPT Presentation

3 color circuit sat and sat
SMART_READER_LITE
LIVE PREVIEW

3-Color, Circuit-SAT and SAT Lecture 24 December 1, 2015 Chandra - - PowerPoint PPT Presentation

CS 374: Algorithms & Models of Computation, Fall 2015 3-Color, Circuit-SAT and SAT Lecture 24 December 1, 2015 Chandra & Manoj (UIUC) CS374 1 Fall 2015 1 / 57 Recap NP : languages that have non-deterministic polynomial time


slide-1
SLIDE 1

CS 374: Algorithms & Models of Computation, Fall 2015

3-Color, Circuit-SAT and SAT

Lecture 24

December 1, 2015

Chandra & Manoj (UIUC) CS374 1 Fall 2015 1 / 57

slide-2
SLIDE 2

Recap

NP: languages that have non-deterministic polynomial time algorithms

Chandra & Manoj (UIUC) CS374 2 Fall 2015 2 / 57

slide-3
SLIDE 3

Recap

NP: languages that have non-deterministic polynomial time algorithms A language L is NP-Complete iff L is in NP for every L′ in NP, L′ ≤P L

Chandra & Manoj (UIUC) CS374 2 Fall 2015 2 / 57

slide-4
SLIDE 4

Recap

NP: languages that have non-deterministic polynomial time algorithms A language L is NP-Complete iff L is in NP for every L′ in NP, L′ ≤P L L is NP-Hard if for every L′ in NP, L′ ≤P L.

Chandra & Manoj (UIUC) CS374 2 Fall 2015 2 / 57

slide-5
SLIDE 5

Recap

NP: languages that have non-deterministic polynomial time algorithms A language L is NP-Complete iff L is in NP for every L′ in NP, L′ ≤P L L is NP-Hard if for every L′ in NP, L′ ≤P L.

Theorem (Cook-Levin)

SAT is NP-Complete.

Chandra & Manoj (UIUC) CS374 2 Fall 2015 2 / 57

slide-6
SLIDE 6

Pictorial View

P NP NP-C NP-Hard

Chandra & Manoj (UIUC) CS374 3 Fall 2015 3 / 57

slide-7
SLIDE 7

P and NP

Possible scenarios:

1

P = NP.

2

P = NP

Chandra & Manoj (UIUC) CS374 4 Fall 2015 4 / 57

slide-8
SLIDE 8

P and NP

Possible scenarios:

1

P = NP.

2

P = NP Question: Suppose P = NP. Is every problem in NP \ P also NP-Complete?

Chandra & Manoj (UIUC) CS374 4 Fall 2015 4 / 57

slide-9
SLIDE 9

P and NP

Possible scenarios:

1

P = NP.

2

P = NP Question: Suppose P = NP. Is every problem in NP \ P also NP-Complete?

Theorem (Ladner)

If P = NP then there is a problem/language X ∈ NP \ P such that X is not NP-Complete.

Chandra & Manoj (UIUC) CS374 4 Fall 2015 4 / 57

slide-10
SLIDE 10

Today

NP-Completeness of three problems: 3-Color Circuit SAT SAT (Cook-Levin Theorem) Important: understanding the problems and that they are hard. Proofs and reductions will be sketchy and mainly to give a flavor

Chandra & Manoj (UIUC) CS374 5 Fall 2015 5 / 57

slide-11
SLIDE 11

Part I NP-Completeness of Graph Coloring

Chandra & Manoj (UIUC) CS374 6 Fall 2015 6 / 57

slide-12
SLIDE 12

Graph Coloring

Problem: Graph Coloring Instance: G = (V , E): Undirected graph, integer k. Question: Can the vertices of the graph be colored using k colors so that vertices connected by an edge do not get the same color?

Chandra & Manoj (UIUC) CS374 7 Fall 2015 7 / 57

slide-13
SLIDE 13

Graph 3-Coloring

Problem: 3 Coloring Instance: G = (V , E): Undirected graph. Question: Can the vertices of the graph be colored using 3 colors so that vertices connected by an edge do not get the same color?

Chandra & Manoj (UIUC) CS374 8 Fall 2015 8 / 57

slide-14
SLIDE 14

Graph 3-Coloring

Problem: 3 Coloring Instance: G = (V , E): Undirected graph. Question: Can the vertices of the graph be colored using 3 colors so that vertices connected by an edge do not get the same color?

Chandra & Manoj (UIUC) CS374 8 Fall 2015 8 / 57

slide-15
SLIDE 15

Graph Coloring

Observation: If G is colored with k colors then each color class (nodes of same color) form an independent set in G. Thus, G can be partitioned into k independent sets iff G is k-colorable.

Chandra & Manoj (UIUC) CS374 9 Fall 2015 9 / 57

slide-16
SLIDE 16

Graph Coloring

Observation: If G is colored with k colors then each color class (nodes of same color) form an independent set in G. Thus, G can be partitioned into k independent sets iff G is k-colorable. Graph 2-Coloring can be decided in polynomial time.

Chandra & Manoj (UIUC) CS374 9 Fall 2015 9 / 57

slide-17
SLIDE 17

Graph Coloring

Observation: If G is colored with k colors then each color class (nodes of same color) form an independent set in G. Thus, G can be partitioned into k independent sets iff G is k-colorable. Graph 2-Coloring can be decided in polynomial time. G is 2-colorable iff G is bipartite!

Chandra & Manoj (UIUC) CS374 9 Fall 2015 9 / 57

slide-18
SLIDE 18

Graph Coloring

Observation: If G is colored with k colors then each color class (nodes of same color) form an independent set in G. Thus, G can be partitioned into k independent sets iff G is k-colorable. Graph 2-Coloring can be decided in polynomial time. G is 2-colorable iff G is bipartite! There is a linear time algorithm to check if G is bipartite using BFS

Chandra & Manoj (UIUC) CS374 9 Fall 2015 9 / 57

slide-19
SLIDE 19

Graph Coloring and Register Allocation

Register Allocation

Assign variables to (at most) k registers such that variables needed at the same time are not assigned to the same register

Interference Graph

Vertices are variables, and there is an edge between two vertices, if the two variables are “live” at the same time.

Observations

[Chaitin] Register allocation problem is equivalent to coloring the interference graph with k colors Moreover, 3-COLOR ≤P k-Register Allocation, for any k ≥ 3

Chandra & Manoj (UIUC) CS374 10 Fall 2015 10 / 57

slide-20
SLIDE 20

Class Room Scheduling

Given n classes and their meeting times, are k rooms sufficient?

Chandra & Manoj (UIUC) CS374 11 Fall 2015 11 / 57

slide-21
SLIDE 21

Class Room Scheduling

Given n classes and their meeting times, are k rooms sufficient? Reduce to Graph k-Coloring problem Create graph G a node vi for each class i an edge between vi and vj if classes i and j conflict

Chandra & Manoj (UIUC) CS374 11 Fall 2015 11 / 57

slide-22
SLIDE 22

Class Room Scheduling

Given n classes and their meeting times, are k rooms sufficient? Reduce to Graph k-Coloring problem Create graph G a node vi for each class i an edge between vi and vj if classes i and j conflict Exercise: G is k-colorable iff k rooms are sufficient

Chandra & Manoj (UIUC) CS374 11 Fall 2015 11 / 57

slide-23
SLIDE 23

Frequency Assignments in Cellular Networks

Cellular telephone systems that use Frequency Division Multiple Access (FDMA) (example: GSM in Europe and Asia and AT&T in USA) Breakup a frequency range [a, b] into disjoint bands of frequencies [a0, b0], [a1, b1], . . . , [ak, bk] Each cell phone tower (simplifying) gets one band Constraint: nearby towers cannot be assigned same band,

  • therwise signals will interference

Chandra & Manoj (UIUC) CS374 12 Fall 2015 12 / 57

slide-24
SLIDE 24

Frequency Assignments in Cellular Networks

Cellular telephone systems that use Frequency Division Multiple Access (FDMA) (example: GSM in Europe and Asia and AT&T in USA) Breakup a frequency range [a, b] into disjoint bands of frequencies [a0, b0], [a1, b1], . . . , [ak, bk] Each cell phone tower (simplifying) gets one band Constraint: nearby towers cannot be assigned same band,

  • therwise signals will interference

Problem: given k bands and some region with n towers, is there a way to assign the bands to avoid interference? Can reduce to k-coloring by creating intereference/conflict graph on towers.

Chandra & Manoj (UIUC) CS374 12 Fall 2015 12 / 57

slide-25
SLIDE 25

3 color this gadget.

You are given three colors: red, green and blue. Can the following graph be three colored in a valid way (assuming that some of the nodes are already colored as indicated). (A) Yes. (B) No.

Chandra & Manoj (UIUC) CS374 13 Fall 2015 13 / 57

slide-26
SLIDE 26

3 color this gadget II

You are given three colors: red, green and blue. Can the following graph be three colored in a valid way (assuming that some of the nodes are already colored as indicated). (A) Yes. (B) No.

Chandra & Manoj (UIUC) CS374 14 Fall 2015 14 / 57

slide-27
SLIDE 27

3-Coloring is NP-Complete

3-Coloring is in NP.

Non-deterministically guess a 3-coloring for each node Check if for each edge (u, v), the color of u is different from that of v.

Hardness: We will show 3-SAT ≤P 3-Coloring.

Chandra & Manoj (UIUC) CS374 15 Fall 2015 15 / 57

slide-28
SLIDE 28

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x1, . . . , xn and m clauses C1, . . . , Cm. Create graph Gϕ such that Gϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x1, . . . , xn via colors for some nodes in Gϕ.

Chandra & Manoj (UIUC) CS374 16 Fall 2015 16 / 57

slide-29
SLIDE 29

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x1, . . . , xn and m clauses C1, . . . , Cm. Create graph Gϕ such that Gϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x1, . . . , xn via colors for some nodes in Gϕ. create triangle with node True, False, Base

Chandra & Manoj (UIUC) CS374 16 Fall 2015 16 / 57

slide-30
SLIDE 30

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x1, . . . , xn and m clauses C1, . . . , Cm. Create graph Gϕ such that Gϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x1, . . . , xn via colors for some nodes in Gϕ. create triangle with node True, False, Base for each variable xi two nodes vi and ¯ vi connected in a triangle with common Base

Chandra & Manoj (UIUC) CS374 16 Fall 2015 16 / 57

slide-31
SLIDE 31

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x1, . . . , xn and m clauses C1, . . . , Cm. Create graph Gϕ such that Gϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x1, . . . , xn via colors for some nodes in Gϕ. create triangle with node True, False, Base for each variable xi two nodes vi and ¯ vi connected in a triangle with common Base If graph is 3-colored, either vi or ¯ vi gets the same color as True. Interpret this as a truth assignment to vi

Chandra & Manoj (UIUC) CS374 16 Fall 2015 16 / 57

slide-32
SLIDE 32

Reduction Idea

Start with 3SAT formula (i.e., 3CNF formula) ϕ with n variables x1, . . . , xn and m clauses C1, . . . , Cm. Create graph Gϕ such that Gϕ is 3-colorable iff ϕ is satisfiable need to establish truth assignment for x1, . . . , xn via colors for some nodes in Gϕ. create triangle with node True, False, Base for each variable xi two nodes vi and ¯ vi connected in a triangle with common Base If graph is 3-colored, either vi or ¯ vi gets the same color as True. Interpret this as a truth assignment to vi Need to add constraints to ensure clauses are satisfied (next phase)

Chandra & Manoj (UIUC) CS374 16 Fall 2015 16 / 57

slide-33
SLIDE 33

Figure

v1 v1 v2 v2 vn

vn T F Base

Chandra & Manoj (UIUC) CS374 17 Fall 2015 17 / 57

slide-34
SLIDE 34

Clause Satisfiability Gadget

For each clause Cj = (a ∨ b ∨ c), create a small gadget graph gadget graph connects to nodes corresponding to a, b, c needs to implement OR OR-gadget-graph:

a b c a ∨ b a ∨ b ∨ c

Chandra & Manoj (UIUC) CS374 18 Fall 2015 18 / 57

slide-35
SLIDE 35

OR-Gadget Graph

Property: if a, b, c are colored False in a 3-coloring then output node

  • f OR-gadget has to be colored False.

Property: if one of a, b, c is colored True then OR-gadget can be 3-colored such that output node of OR-gadget is colored True.

Chandra & Manoj (UIUC) CS374 19 Fall 2015 19 / 57

slide-36
SLIDE 36

Reduction

create triangle with nodes True, False, Base for each variable xi two nodes vi and ¯ vi connected in a triangle with common Base for each clause Cj = (a ∨ b ∨ c), add OR-gadget graph with input nodes a, b, c and connect output node of gadget to both False and Base

a b c a ∨ b a ∨ b ∨ c T F Base

Chandra & Manoj (UIUC) CS374 20 Fall 2015 20 / 57

slide-37
SLIDE 37

Reduction

a b c a ∨ b a ∨ b ∨ c T F Base

Claim

No legal 3-coloring of above graph (with coloring of nodes T, F, B fixed) in which a, b, c are colored False. If any of a, b, c are colored True then there is a legal 3-coloring of above graph.

Chandra & Manoj (UIUC) CS374 21 Fall 2015 21 / 57

slide-38
SLIDE 38

3 coloring of the clause gadget

s a b c w u v r

T

s a b c w u v r

T

s a b c w u v r

T

FFF - BAD FFT FTF

s a b c w u v r

T

s a b c w u v r

T

s a b c w u v r

T

FTT TFF TFT

s a b c w u v r

T

s a b c w u v r

T

TTF TTT

Chandra & Manoj (UIUC) CS374 22 Fall 2015 22 / 57

slide-39
SLIDE 39

Reduction Outline

Example

ϕ = (u ∨ ¬v ∨ w) ∧ (v ∨ x ∨ ¬y)

v u ~w y x w ~y ~x ~v ~u F T N

Literals get colour T or F colours have complementary Variable and negation OR−gates Palette

Chandra & Manoj (UIUC) CS374 23 Fall 2015 23 / 57

slide-40
SLIDE 40

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable if xi is assigned True, color vi True and ¯ vi False

Chandra & Manoj (UIUC) CS374 24 Fall 2015 24 / 57

slide-41
SLIDE 41

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable if xi is assigned True, color vi True and ¯ vi False for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c is colored True. OR-gadget for Cj can be 3-colored such that

  • utput is True.

Chandra & Manoj (UIUC) CS374 24 Fall 2015 24 / 57

slide-42
SLIDE 42

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable if xi is assigned True, color vi True and ¯ vi False for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c is colored True. OR-gadget for Cj can be 3-colored such that

  • utput is True.

Chandra & Manoj (UIUC) CS374 24 Fall 2015 24 / 57

slide-43
SLIDE 43

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable if xi is assigned True, color vi True and ¯ vi False for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c is colored True. OR-gadget for Cj can be 3-colored such that

  • utput is True.

Gϕ is 3-colorable implies ϕ is satisfiable if vi is colored True then set xi to be True, this is a legal truth assignment

Chandra & Manoj (UIUC) CS374 24 Fall 2015 24 / 57

slide-44
SLIDE 44

Correctness of Reduction

ϕ is satisfiable implies Gϕ is 3-colorable if xi is assigned True, color vi True and ¯ vi False for each clause Cj = (a ∨ b ∨ c) at least one of a, b, c is colored True. OR-gadget for Cj can be 3-colored such that

  • utput is True.

Gϕ is 3-colorable implies ϕ is satisfiable if vi is colored True then set xi to be True, this is a legal truth assignment consider any clause Cj = (a ∨ b ∨ c). it cannot be that all a, b, c are False. If so, output of OR-gadget for Cj has to be colored False but output is connected to Base and False!

Chandra & Manoj (UIUC) CS374 24 Fall 2015 24 / 57

slide-45
SLIDE 45

Graph generated in reduction...

... from 3SAT to 3COLOR

d X c a b T a b c d F Chandra & Manoj (UIUC) CS374 25 Fall 2015 25 / 57

slide-46
SLIDE 46

Part II Circuit SAT

Chandra & Manoj (UIUC) CS374 26 Fall 2015 26 / 57

slide-47
SLIDE 47

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? ? Inputs:

1

Input vertices (without incoming edges) labelled with 0, 1 or a distinct variable.

2

Every other vertex is labelled ∨, ∧ or ¬.

3

Single node output vertex with no outgoing edges.

Chandra & Manoj (UIUC) CS374 27 Fall 2015 27 / 57

slide-48
SLIDE 48

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? ? ∧ ∨ ∨ ¬ ∧ ∧ Inputs:

1

Input vertices (without incoming edges) labelled with 0, 1 or a distinct variable.

2

Every other vertex is labelled ∨, ∧ or ¬.

3

Single node output vertex with no outgoing edges.

Chandra & Manoj (UIUC) CS374 27 Fall 2015 27 / 57

slide-49
SLIDE 49

Circuits

Definition

A circuit is a directed acyclic graph with

1 ? ? ? ∧ ∨ ∨ ¬ ∧ ∧ Inputs: Output:

1

Input vertices (without incoming edges) labelled with 0, 1 or a distinct variable.

2

Every other vertex is labelled ∨, ∧ or ¬.

3

Single node output vertex with no outgoing edges.

Chandra & Manoj (UIUC) CS374 27 Fall 2015 27 / 57

slide-50
SLIDE 50

CSAT: Circuit Satisfaction

Definition (Circuit Satisfaction (CSAT).)

Given a circuit as input, is there an assignment to the input variables that causes the output to get value 1?

Chandra & Manoj (UIUC) CS374 28 Fall 2015 28 / 57

slide-51
SLIDE 51

CSAT: Circuit Satisfaction

Definition (Circuit Satisfaction (CSAT).)

Given a circuit as input, is there an assignment to the input variables that causes the output to get value 1?

Claim

CSAT is in NP.

1

Certificate: Assignment to input variables.

2

Certifier: Evaluate the value of each gate in a topological sort of DAG and check the output gate value.

Chandra & Manoj (UIUC) CS374 28 Fall 2015 28 / 57

slide-52
SLIDE 52

Circuit SAT vs SAT

CNF formulas are a rather restricted form of Boolean formulas. Circuits are a much more powerful (and hence easier) way to express Boolean formulas

Chandra & Manoj (UIUC) CS374 29 Fall 2015 29 / 57

slide-53
SLIDE 53

Circuit SAT vs SAT

CNF formulas are a rather restricted form of Boolean formulas. Circuits are a much more powerful (and hence easier) way to express Boolean formulas However they are equivalent in terms of polynomial-time solvability.

Theorem

SAT ≤P 3SAT ≤P CSAT.

Theorem

CSAT ≤P SAT ≤P 3SAT.

Chandra & Manoj (UIUC) CS374 29 Fall 2015 29 / 57

slide-54
SLIDE 54

Converting a CNF formula into a Circuit

Given 3CNF formulat ϕ with n variables and m clauses, create a Circuit C. Inputs to C are the n boolean variables x1, x2, . . . , xn Use NOT gate to generate literal ¬xi for each variable xi For each clause (ℓ1 ∨ ℓ2 ∨ ℓ3) use two OR gates to mimic formula Combine the outputs for the clauses using AND gates to obtain the final output

Chandra & Manoj (UIUC) CS374 30 Fall 2015 30 / 57

slide-55
SLIDE 55

Example

ϕ =

  • x1 ∨ ∨x3 ∨ x4
  • x1 ∨ ¬x2 ∨ ¬x3
  • ¬x2 ∨ ¬x3 ∨ x4
  • Chandra & Manoj (UIUC)

CS374 31 Fall 2015 31 / 57

slide-56
SLIDE 56

Converting a circuit into a CNF formula

Label the nodes

1 ? ? ? Inputs Output:

∧ ∧ ∧ ∨ ∨ ¬

1 ,a ? ,b ? ,c ,d ? ,e Inputs Output: ∧, k ¬, i ∧, j ∧, f ∨, g ∨, h

(A) Input circuit (B) Label the nodes.

Chandra & Manoj (UIUC) CS374 32 Fall 2015 32 / 57

slide-57
SLIDE 57

Converting a circuit into a CNF formula

Introduce a variable for each node

1 ,a ? ,b ? ,c ,d ? ,e Inputs Output: ∧, k ¬, i ∧, j ∧, f ∨, g ∨, h 1 ,a ? ,b ? ,c ,d ? ,e Inputs Output: ∧, k ¬, i ∧, j ∧, f ∨, g ∨, h

xk xj xi xf xg xh xa xb xc xd xe

(B) Label the nodes. (C) Introduce var for each node.

Chandra & Manoj (UIUC) CS374 33 Fall 2015 33 / 57

slide-58
SLIDE 58

Converting a circuit into a CNF formula

Write a sub-formula for each variable that is true if the var is computed correctly.

1 ,a ? ,b ? ,c ,d ? ,e Inputs Output: ∧, k ¬, i ∧, j ∧, f ∨, g ∨, h

xk xj xi xf xg xh xa xb xc xd xe

xk (Demand a sat’ assignment!) xk = xi ∧ xk xj = xg ∧ xh xi = ¬xf xh = xd ∨ xe xg = xb ∨ xc xf = xa ∧ xb xd = 0 xa = 1 (C) Introduce var for each node. (D) Write a sub-formula for each variable that is true if the var is computed correctly.

Chandra & Manoj (UIUC) CS374 34 Fall 2015 34 / 57

slide-59
SLIDE 59

Converting a circuit into a CNF formula

Convert each sub-formula to an equivalent CNF formula

xk xk xk = xi ∧ xj (¬xk ∨ xi) ∧ (¬xk ∨ xj) ∧ (xk ∨ ¬xi ∨ ¬xj) xj = xg ∧ xh (¬xj ∨ xg) ∧ (¬xj ∨ xh) ∧ (xj ∨ ¬xg ∨ ¬xh) xi = ¬xf (xi ∨ xf ) ∧ (¬xi ∨ xf ) xh = xd ∨ xe (xh ∨ ¬xd) ∧ (xh ∨ ¬xe) ∧ (¬xh ∨ xd ∨ xe) xg = xb ∨ xc (xg ∨ ¬xb) ∧ (xg ∨ ¬xc) ∧ (¬xg ∨ xb ∨ xc) xf = xa ∧ xb (¬xf ∨ xa) ∧ (¬xf ∨ xb) ∧ (xf ∨ ¬xa ∨ ¬xb) xd = 0 ¬xd xa = 1 xa

Chandra & Manoj (UIUC) CS374 35 Fall 2015 35 / 57

slide-60
SLIDE 60

Converting a circuit into a CNF formula

Take the conjunction of all the CNF sub-formulas

1 ,a ? ,b ? ,c ,d ? ,e Inputs Output: ∧, k ¬, i ∧, j ∧, f ∨, g ∨, h

xk xj xi xf xg xh xa xb xc xd xe

xk ∧ (¬xk ∨ xi) ∧ (¬xk ∨ xj) ∧ (xk ∨ ¬xi ∨ ¬xj) ∧ (¬xj ∨ xg) ∧ (¬xj ∨xh) ∧ (xj ∨¬xg ∨¬xh) ∧ (xi ∨ xf ) ∧ (¬xi ∨ xf ) ∧ (xh ∨ ¬xd) ∧ (xh ∨ ¬xe) ∧ (¬xh ∨ xd ∨ xe) ∧ (xg ∨ ¬xb) ∧ (xg ∨ ¬xc) ∧ (¬xg ∨ xb ∨ xc) ∧ (¬xf ∨ xa) ∧ (¬xf ∨ xb) ∧ (xf ∨¬xa ∨¬xb) ∧ (¬xd)∧xa We got a CNF formula that is satisfiable if and only if the original circuit is satisfiable.

Chandra & Manoj (UIUC) CS374 36 Fall 2015 36 / 57

slide-61
SLIDE 61

Reduction: CSAT ≤P SAT

1

For each gate (vertex) v in the circuit, create a variable xv

2

Case ¬: v is labeled ¬ and has one incoming edge from u (so xv = ¬xu). In SAT formula generate, add clauses (xu ∨ xv), (¬xu ∨ ¬xv). Observe that xv = ¬xu is true ⇐ ⇒ (xu ∨ xv) (¬xu ∨ ¬xv) both true.

Chandra & Manoj (UIUC) CS374 37 Fall 2015 37 / 57

slide-62
SLIDE 62

Reduction: CSAT ≤P SAT

Continued...

1

Case ∨: So xv = xu ∨ xw. In SAT formula generated, add clauses (xv ∨ ¬xu), (xv ∨ ¬xw), and (¬xv ∨ xu ∨ xw). Again,

  • bserve that
  • xv = xu ∨ xw
  • is true

⇐ ⇒ (xv ∨ ¬xu), (xv ∨ ¬xw), (¬xv ∨ xu ∨ xw) all true.

Chandra & Manoj (UIUC) CS374 38 Fall 2015 38 / 57

slide-63
SLIDE 63

Reduction: CSAT ≤P SAT

Continued...

1

Case ∧: So xv = xu ∧ xw. In SAT formula generated, add clauses (¬xv ∨ xu), (¬xv ∨ xw), and (xv ∨ ¬xu ∨ ¬xw). Again observe that xv = xu ∧ xw is true ⇐ ⇒ (¬xv ∨ xu), (¬xv ∨ xw), (xv ∨ ¬xu ∨ ¬xw) all true.

Chandra & Manoj (UIUC) CS374 39 Fall 2015 39 / 57

slide-64
SLIDE 64

Reduction: CSAT ≤P SAT

Continued...

1

If v is an input gate with a fixed value then we do the following. If xv = 1 add clause xv. If xv = 0 add clause ¬xv

2

Add the clause xv where v is the variable for the output gate

Chandra & Manoj (UIUC) CS374 40 Fall 2015 40 / 57

slide-65
SLIDE 65

Correctness of Reduction

Need to show circuit C is satisfiable iff ϕC is satisfiable ⇒ Consider a satisfying assignment a for C

1

Find values of all gates in C under a

2

Give value of gate v to variable xv; call this assignment a′

3

a′ satisfies ϕC (exercise)

⇐ Consider a satisfying assignment a for ϕC

1

Let a′ be the restriction of a to only the input variables

2

Value of gate v under a′ is the same as value of xv in a

3

Thus, a′ satisfies C

Chandra & Manoj (UIUC) CS374 41 Fall 2015 41 / 57

slide-66
SLIDE 66

Part III Proof of Cook-Levin Theorem

Chandra & Manoj (UIUC) CS374 42 Fall 2015 42 / 57

slide-67
SLIDE 67

Cook-Levin Theorem

Theorem (Cook-Levin)

SAT is NP-Complete. We have already seen that SAT is in NP. Need to prove that every language L ∈ NP, L ≤P SAT

Chandra & Manoj (UIUC) CS374 43 Fall 2015 43 / 57

slide-68
SLIDE 68

Cook-Levin Theorem

Theorem (Cook-Levin)

SAT is NP-Complete. We have already seen that SAT is in NP. Need to prove that every language L ∈ NP, L ≤P SAT Difficulty: Infinite number of languages in NP. Must simultaneously show a generic reduction strategy.

Chandra & Manoj (UIUC) CS374 43 Fall 2015 43 / 57

slide-69
SLIDE 69

High-level Plan

What does it mean that L ∈ NP? L ∈ NP implies that there is a non-deterministic TM M and polynomial p() such that L = {x ∈ Σ∗ | M accepts x in at most p(|x|) steps}

Chandra & Manoj (UIUC) CS374 44 Fall 2015 44 / 57

slide-70
SLIDE 70

High-level Plan

What does it mean that L ∈ NP? L ∈ NP implies that there is a non-deterministic TM M and polynomial p() such that L = {x ∈ Σ∗ | M accepts x in at most p(|x|) steps} We will describe a reduction fM that depends on M, p such that: fM takes as input a string x and outputs a SAT formula fM(x) fM runs in time polynomial in |x| x ∈ L if and only if fM(x) is satisfiable

Chandra & Manoj (UIUC) CS374 44 Fall 2015 44 / 57

slide-71
SLIDE 71

Plan continued

x fM(x)

fM

poly-time computable

fM(x) is satisfiable if and only if x ∈ L fM(x) is satisfiable if and only if non-det M accepts x in p(|x|) steps

Chandra & Manoj (UIUC) CS374 45 Fall 2015 45 / 57

slide-72
SLIDE 72

Plan continued

x fM(x)

fM

poly-time computable

fM(x) is satisfiable if and only if x ∈ L fM(x) is satisfiable if and only if non-det M accepts x in p(|x|) steps BIG IDEA fM(x) will express “M on input x accepts in p(|x|) steps” fM(x) will encode a computation history of M on x fM(x) will be a carefully constructed CNF formulat s.t if we have a satisfying assignment to it, then we will be able to see a complete accepting computation of M on x down to the last detail of where the head is, what transistion is chosen, what the tape contents are, at each step.

Chandra & Manoj (UIUC) CS374 45 Fall 2015 45 / 57

slide-73
SLIDE 73

Tableu of Computation

M runs in time p(|x|) on x. Entire computation of M on x can be represented by a “tableau”

time tape cell position

1 2 3 1 2 3 p(|x|) p(|x|) state q0 state q2 1 1 1 blanks blanks 4

Row i gives contents of all cells at time i At time 0 tape has input x followed by blanks Each row long enough to hold all cells M might ever have scanned.

Chandra & Manoj (UIUC) CS374 46 Fall 2015 46 / 57

slide-74
SLIDE 74

Variable of fM(x)

Four types of variable to describe computation of M on x T(b, h, i) : tape cell at position h holds symbol b at time i. 1 ≤ h ≤ p(|x|), b ∈ Γ, 0 ≤ i ≤ p(|x|) H(h, i): read/write head is at position h at time i. 1 ≤ h ≤ p(|x|), 0 ≤ i ≤ p(|x|) S(q, i) state of M is q at time i q ∈ Q, 0 ≤ i ≤ p(|x|) I(j, i) instruction number j is executed at time i M is non-deterministic, need to specify transitions in some way. Number transitions as 1, 2, . . . , ℓ where j’th transition is < qj, bj, q′

j, b′ j, dj > indication (q′ j, b′ j, dj) ∈ δ(qj, bj),

direction dj ∈ {−1, 0, 1}. Number of variables is O(p(|x|)2) where constant in O() hides dependence on fixed machine M.

Chandra & Manoj (UIUC) CS374 47 Fall 2015 47 / 57

slide-75
SLIDE 75

Notation

Some abbreviations for ease of notation m

k=1 xk means x1 ∧ x2 ∧ . . . ∧ xm

m

k=1 xk means x1 ∨ x2 ∨ . . . ∨ xm

(x1, x2, . . . , xk) is a formula that means exactly one of x1, x2, . . . , xm is true. Can be converted to CNF form

Chandra & Manoj (UIUC) CS374 48 Fall 2015 48 / 57

slide-76
SLIDE 76

Clauses of fM(x)

fM(x) is the conjunction of 8 clause groups: fM(x) = ϕ1 ∧ ϕ2 ∧ ϕ3 ∧ ϕ4 ∧ ϕ5 ∧ ϕ6 ∧ ϕ7 ∧ ϕ8 where each ϕi is a CNF formula. Described in subsequent slides. Property: fM(x) is satisfied iff there is a truth assignment to the variables that simultaneously satisfy ϕ1, . . . , ϕ8.

Chandra & Manoj (UIUC) CS374 49 Fall 2015 49 / 57

slide-77
SLIDE 77

ϕ1

ϕ1 asserts (is true iff) the variables are set T/F indicating that M starts in state q0 at time 0 with tape contents containing x followed by blanks. Let x = a1a2 . . . an ϕ1 = S(q, 0) state at time 0 is q0

  • and

n

h=1 T(ah, h, 0) at time 0 cells 1 to n have a1 to an

p(|x|

h=n+1)T(B, h, 0) at time 0 cells n + 1 to p(|x|) have blanks

  • and

H(1, 0) head at time 0 is in position 1

Chandra & Manoj (UIUC) CS374 50 Fall 2015 50 / 57

slide-78
SLIDE 78

ϕ2

ϕ2 asserts M in exactly one state at any time i ϕ2 = p(|x|)

i=0

  • ⊕(S(q0, i), S(q1, i), . . . , S(q|Q|, i))
  • Chandra & Manoj (UIUC)

CS374 51 Fall 2015 51 / 57

slide-79
SLIDE 79

ϕ3

ϕ3 asserts that each tape cell holds a unique symbol at any given time. ϕ3 =

p(|x|)

  • i=0

p(|x|)

  • h=1

⊕(T(b1, h, i), T(b2, h, i), . . . , T(b|Γ|, h, i)) For each time i and for each cell position h exactly one symbol b ∈ Γ at cell position h at time i

Chandra & Manoj (UIUC) CS374 52 Fall 2015 52 / 57

slide-80
SLIDE 80

ϕ4

ϕ4 asserts that the read/write head of M is in exactly one position at any time i ϕ4 =

p(|x|)

  • i=0

(⊕ (H(1, i), H(2, i), . . . , H(p(|x|), i)))

Chandra & Manoj (UIUC) CS374 53 Fall 2015 53 / 57

slide-81
SLIDE 81

ϕ5

ϕ5 asserts that M accepts Let qa be unique accept state of M without loss of generality assume M runs all p(|x|) steps ϕ5 = S(qa, p(|x|)) State at time p(|x|) is qa the accept state. If we don’t want to make assumption of running for all steps ϕ5 =

p(|x|)

  • i=1

S(qa, i) which means M enters accepts state at some time.

Chandra & Manoj (UIUC) CS374 54 Fall 2015 54 / 57

slide-82
SLIDE 82

ϕ6

ϕ6 asserts that M executes a unique instruction at each time ϕ6 =

p(|x|)

  • i=0

⊕(I(1, i), I(2, i), . . . , I(m, i)) where m is max instruction number.

Chandra & Manoj (UIUC) CS374 55 Fall 2015 55 / 57

slide-83
SLIDE 83

ϕ7

ϕ7 ensures that variables don’t allow tape to change from one moment to next if the read/write head was not there. “If head is not at position h at time i then at time i + 1 the symbol at cell h must be unchanged” ϕ7 =

  • i
  • h
  • b=c
  • H(h, i) ⇒ T(b, h, i)
  • T(c, h, i + 1)
  • since A ⇒ B is same as ¬A ∨ B, rewrite above in CNF form

ϕ7 =

  • i
  • h
  • b=c

(H(h, i) ∨ ¬T(b, h, i) ∨ ¬T(c, h, i + 1))

Chandra & Manoj (UIUC) CS374 56 Fall 2015 56 / 57

slide-84
SLIDE 84

ϕ8

ϕ8 asserts that changes in tableu/tape correspond to transitions of M (as Lenny says, this is the big cookie). Let j’th instruction be < qj, bj, q′

j, b′ j, dj >

ϕ8 =

i

  • j(I(j, i) ⇒ S(qj, i)) If instr j executed at time i then state must be correct to do j
  • i
  • j(I(j, i) ⇒ S(q′

j, i + 1)) and at next time unit, state must be the proper next state for instr j

  • i
  • h
  • j[(I(j, i) H(h, i)) ⇒ T(bj, h, i)] if j was executed and head was at

position h, then cell h has correct symbol for j

  • i
  • j
  • h[(I(j, i) ∧ H(h, i)) ⇒ T(b′

j, h, i + 1)] if j was done then at time i with

head at h then at next time step symbol b′

j was indeed written in position h

  • i
  • j
  • h[(I(j, i) ∧ H(h, i)) ⇒ H(h + dj, i + 1)] and head is moved properly

according to instr j. Chandra & Manoj (UIUC) CS374 57 Fall 2015 57 / 57

slide-85
SLIDE 85

Proof of Correctness

(Sketch) Given M, x, poly-time algorithm to construct fM(x) if fM(x) is satisfiable then the truth assignment completely specifies an accepting computation of M on x if M accepts x then the accepting computation leads to an ”obvious” truth assignment to fM(x). Simply assign the variables according to the state of M and cells at each time i. Thus M accepts x if and only if fM(x) is satisfiable

Chandra & Manoj (UIUC) CS374 58 Fall 2015 58 / 57