 # NP-Completeness CS 51 Summer 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AA A A AAA.

## Presentation on theme: "NP-Completeness CS 51 Summer 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AA A A AAA."— Presentation transcript:

NP-Completeness CS 51 Summer 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AA A A AAA

CS 512 Cook-Levin Any problem in NP can be – reduced in polynomial time –by a deterministic Turing Machine –to a problem of determining whether a Boolean circuit is satisfiable.

CS 513 Implications Deterministic poly-time algorithm for solving satisfiability implies –Deterministic poly-time algorithm for any problem in NP.

CS 514 Boolean Circuits Theoretical analogue of logic circuits. A Boolean circuit is a collection of –gates –inputs –wires no cycles

CS 515 Kinds of Gates ÇÆ : and not or

CS 516 Gates Wires carry 0 or 1 AND: 1 iff both 1 OR: 1 iff either 1 NOT: opposite Distinguished output gate Æ and : not Ç or

CS 517 Example Æ : Ç Æ x0x0 x1x1 x2x2 : Æ Output gate

CS 518 Example Æ : Ç Æ x0x0 x1x1 x2x2 : Æ Output gate 010 1 0 0 11 1

CS 519 Circuit Satisfiability A circuit is satisfiable –If there is some set of inputs –That produce a 1 The circuit-satisfiability problem tests whether a circuit is satisfiable. –CIRCUIT-SAT = { |C is a satisfiable Boolean circuit}

CS 5110 Circuit Satisfiability Claim: –CIRCUIT-SAT is in NP Why? We will show that circuits can simulate Turing Machines!

CS 5111 Circuits Let t: N ! N be a function, where t(n) ¸ n Let M be a TM that –Takes inputs over alphabet {0,1} –Runs in time t(n)

CS 5112 Claim Let M be a TM that –Takes inputs over alphabet {0,1} –Runs in time t(n) Each n has a Boolean Circuit with O(t 2 (n)) gates that outputs 1 on those inputs of length n accepted by M

CS 5113 Proof Idea Define C n to simulate M on inputs of size n Gates of C n are –Organized in rows –One for each of t(n) steps in M’s computation –Each row represents M’s configuration at that step –Each row wired to previous Technical modification –M accepts or rejects with head at leftomost

CS 5114 Configurations Computation changes: –current state –current head position –tape contents

CS 5115 Configurations Configuration: 1011 q 7 0111 means: –state is q 7 –LHS of tape is 1011, RHS of tape is 0111 –head is on RHS 0

CS 5116 Yields u a q i b v yields u q j a c v if –???

CS 5117 Yields u a q i b v yields u q j a c v if –δ(q i,b) = (q j,c,L)

CS 5118 Yields u a q i b v yields u q j a c v if –δ(q i,b) = (q j,c,L) u a q i b v yields u a c q j v if –???

CS 5119 Yields u a q i b v yields u q j a c v if –δ(q i,b) = (q j,c,L) u a q i b v yields u a c q j v if –δ(q i,b) = (q j,c,R)

CS 5120 Yields u a q i b v yields u q j a c v if –δ(q i,b) = (q j,c,L) u a q i b v yields u a c q j v if –δ(q i,b) = (q j,c,R) q i b v yields q j c v if –???

CS 5121 More Configurations Starting: q 0 w Accepting: w 0 q a w 1 Rejecting: w 0 q r w 1 Halting configurations: –w 0 q a w 1, and –w 0 q r w 1

CS 5122 Accepting a Language C 1 = starting configuration of M on w each C i yields C i+1 C k is an accepting configuration. A Turing machine M accepts an input w if there exits a sequence C 1, C 2, …., C k such that

CS 5123 Tableaux Let M be –(Q, §, ¡, ±, q 0, q a, q r ) The tableau for M on w is –a t(n) by t(n) table. –rows are configurations of M –top row is start configuration of M on w –i th row is configuration at i th step.

CS 5124 Tableaux Why t(n) by t(n)? –How much tape can M read in t(n) steps? –How many configurations can M assume in t(n) steps?

CS 5125 Entries Each entry in the tableau contains –A tape symbol (in ¡ ), or –A state (in Q) Call entry at row i, col j cell[i,j]. –cell[1,i], …, cell[1,t(n)] starting config –And cell[1,1] = q 0, the starting state Recall M modifies so –cell[1,t(n)] is either q a or q r.

CS 5126

CS 5127 Proof Content of cell is determined by neighbors in preceding row. Given –cell[i-1,j-1] –cell[i,j-1] –cell[i+1,j-1] we can determine cell[i,j] –from M's transition function.

CS 5128 Proof Three top tape symbols nowhere near head So middle one unchanged on next row

CS 5129 Constructing the Circuit Circuit C n –has several gates for each cell in the tableau –compute value at a cell from the 3 cells that affect it.

CS 5130 Constructing the Circuit To make the description easier, we –add ``lights'' to show the output –illustrative purposes only

CS 5131 Constructing the Circuit To make the description easier, we –add ``lights'' to show the output –illustrative purposes only Let k = number of elements in ¡ [ Q. –each cell has k possible lights –grand total of k ¢ t 2 (n) lights –only one light can be lit, –that light indicates contents of cell.

CS 5132 Construction Model each light as light[i,j,s], where –1 · i,j · t(n) –s 2 ¡ –one and only one light on in each cell –if light[i,j,s] is on, then cell[i,j] = s.

CS 5133 Constructing the Circuit Pick light[i,j,s] in cell[i,j]. This light should be on iff cell[i,j] = s. Only three cells can affect this cell: –cell[i-1,j-1], –cell[i,j-1], and –cell[i+1,j-1]. How they affect the cell determined by transition function ±.

CS 5134 Construction Suppose that if –cell[i-1,j-1] = a 1, –cell[i,j-1] = b 1, and –cell[i+1,j-1] = c 1. then cell[i,j] = s, according to ±. Wire the circuit so that –light[i,j,s] = light[i-1,j-1, a 1 ] Æ light[i-1,j-1, b 1 ] Æ light[i-1,j-1, c 1 ]

CS 5135 Construction Wire the circuit so that –light[i,j,s] = light[i-1,j-1, a 1 ] Æ light[i-1,j-1, b 1 ] Æ light[i-1,j-1, c 1 ]

CS 5136 Construction In general, more than one setting (a 1,b 1,c 1 ), …, (a k,b k,c k ) of cell[i-1,j-1].cell[i,j-1],cell[i+1,j-1] can yield s. Wire the circuit so that –a i,b i,c i connected by Æ gates –different settings connected by Ç gates

CS 5137

CS 5138 First Row Hardwired for start configuration light[1,1,q 0 ] is initially on.

CS 5139 First Roiw light[1,2,1], …, light[1,n+1,1] connected to w 1,…w n light[1,2,0], …, light[1,n+1,0] connected to w 1,…w n by NOT gates

CS 5140 First Row light[1,n+2,_],…light[1,t(n),_] all on

CS 5141 Construction We have constructed a circuit that simulates M through its t(n) th step. Need one gate to be the output gate of the circuit M accepts w iff it is –in q a, and –at left-hand end of tape Choose light[t(n),1,q a ]. Completes proof M simulated by C n

CS 5142 Theorem CIRCUIT-SAT is NP-complete Is clearly in NP? (why?) We must show that any language A in NP is reducible to CIRCUIT-SAT We must give a polynomial time reduction mapping strings to circuits

CS 5143 Proof We must give a polynomial time reduction mapping strings to circuits –f(w) = C So that –W 2 A, C is satisfiable

CS 5144 Proof Let V be a poly-time verifier for A –Input –c is a certificate for x Now –Construct circuit simulating V –Fill in x inputs to circuit with w –Remaining inputs are for c Output this circuit, call it C

CS 5145 Proof Output this circuit, call it C –If C is satisfiable, a certificate exists, and w 2 A –If w 2 A, certificate exists, and C is satisfiable

CS 5146 Proof Check that circuit construction is poly time –Verifier running time is n k –Circuit size is O(n 2k ) –Circuit is simple and running time of reduction is O(n 2k )

CS 5147 3-SAT Boolean expression in CNF –Conjunctive normal form With no more than three literals –Literal = variable or its complement

CS 5148 Theorem 3-SAT is NP-Complete Obviously in NP Reduction of CIRCUIT-SAT to 3- SAT

CS 5149 Proof Let C be a circuit with –Inputs x 1, …, x k –Gates g 1, …,g m We build Boolean formula Á such that –x i correspond to input wires –g i correspond to gate output wires Relabel variables w 1, …, w k+m

CS 5150 NOT Gates For each NOT gate in C with input w i, output w j, add clauses –(w i Ç w j ) Æ ( : w i Ç w j ) Both clauses satisfied when assignment to w i and w j mirror NOT gate

CS 5151 AND Gates For each AND gate with inputs w i and w j, and output w k, add clauses –(w i Ç w j Ç : w k ) Æ –(w i Ç : w j Ç : w k ) Æ –( : w i Ç w j Ç : w k ) Æ –( : w i Ç : w j Ç w k ) Satisfied when assignments mirror AND

CS 5152 OR Gates For each OR gate with inputs w i and w j, and output w k, add clauses –(w i Ç w j Ç : w k ) Æ –(w i Ç : w j Ç w k ) Æ –( : w i Ç w j Ç w k ) Æ –( : w i Ç : w j Ç w k ) Satisfied when assignments mirror OR

CS 5153 Details All clauses have no more than 3 literals –If they have fewer, then repeat

CS 5154 Details Satisfying assignment for C yields satisfying assignment for Á by assigning g i vars according to C Satisfying assignment for Á yields satisfying assignment for C because it describes C’s computation with output 1 Reduction is poly-time