Transcript Lecture 19
Cook-Levin Theorem
• Circuit Satisfiability
– A “first” NP-complete problem
• Reduction overview
• Example reduction
Circuit Satisfiability
• 5 types of gates
–
–
–
–
–
G10
Constant (T/F)
And
Or
Not
Variable
G8
• Input size is total number
of gates
• One output
• Question
– Is there an assignment
of truth values to the
variable gates that
causes the output of the
circuit to be true?
G5
X1
G9
G6
X2
G7
X3
T
Reduction Overview
• We need to develop a reduction that can be
applied to ANY problem in NP
• This leads to two key issues
– How do we represent the input for an arbitrary
problem in NP?
– What do we know about an arbitrary problem
in NP?
Encoding Inputs
• We assume the input is encoded as a string of 0’s
and 1’s
• Example: input is an undirected graph
– First specify the number of nodes in binary
– Then use an adjacency matrix to represent edges
1
2
3
11 010101010
Arbitrary problem in NP
• If Π belongs to NP, then there exists a verification
algorithm A along with a set of certificates C
• Given any input x to Π, we construct a circuit to
simulate the computation of A on x with the
certificate C represented as variable gates
11 010101010
Input x
R
Circuit representing
computation of A on x
with certificate C
Example
• We will show an example with the
Hamiltonian Path Problem
• Key concept
– Representation of computation of A on x as a
sequence of configurations
– Configuration: With a configuration and the
code for A, you should be able to complete the
computation of A on x
Verification algorithm, certificate for HP
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer = false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer = false;
7.
return answer;
}
Certificate: A path which is a permutation of the V nodes in the graph
Configurations of HPV computation
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
• What information
should be recorded in
a configuration of this
program?
• Current instruction
(PC)
• value of all variables
• Input x
• Certificate
1
2
3
PC G=(V,E) Path i answer used
11 0 10101010
Configuration Description
One computation of HPV
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
1
2
3
11 0 10101010
Path P = 1, 2, 3
PC G=(V,E) Path i answer used
001 11 010101010011 011011000
010 11 010101010011 011011000
011 11 010101010011011011100
100 11 010101010011 011011100
101 11 010101010011 011101100
001 11 010101010011011101100
010 11 010101010011 011101100
011 11 010101010011 011101110
One computation of HPV cont’d
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
1
2
3
11 0 10101010
Path P = 1, 2, 3
PC G=(V,E) Path i answer used
011 11 010101010011 011101110
100 11 010101010011 011101110
101 11 010101010011 011111110
001 11 010101010011 011111110
110 11 010101010011 011111110
111 11 010101010011 011111110
Second computation of HPV
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
1
2
3
11 0 10101010
Path P = 2, 3, 1
PC G=(V,E) Path i answer used
001 11 010101010101 101011000
010 11 010101010101 101011000
011 11 010101010101101011010
100 11 010101010101 101011010
101 11 010101010101 101101010
001 11 010101010101101101010
010 11 010101010101 101101010
011 11 010101010101 101101011
Second computation of HPV cont’d
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
1
2
3
11 0 10101010
Path P = 2, 3, 1
PC G=(V,E) Path i answer used
011 11 010101010101 101101011
100 11 010101010011 011100011
101 11 010101010011 011110011
001 11 010101010011 011110011
110 11 010101010011 011110011
111 11 010101010011 011110011
Computation represented as a Boolean Circuit
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
001 11 010101010101 101011000
GATES
010 11 010101010101 101011000
GATES
011 11 010101010101 101011010
GATES
1
2
3
GATES
11 0 10101010
Path P = 2, 3, 1
111 11 0101010100110 11110011
Output of Circuit
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
001 11 010101010101 101011000
GATES
010 11 010101010101 101011000
GATES
011 11 010101010101 101011010
GATES
1
2
3
GATES
11 0 10101010
Path P = 2, 3, 1
111 11 0101010100110 11110011
Constant Input Gates
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
001 11 010101010 101 101011000
GATES
010 11 010101010101 101011000
GATES
011 11 010101010101 101011010
GATES
1
2
3
GATES
11 0 10101010
Path P = 2, 3, 1
111 11 0101010100110 11110011
Variable Input Gates
bool HPV(graph G=(V,E), path P) {
int i = 1;
bool answer = true;
bool used[V] = false; /* initialized to all
false */
1.
if i = V goto 6;
2.
if (used[P[i]] = = true) answer =
false; else used[i] = true;
3.
if (!E(P[i],P[i+1])) answer = false;
4.
i++;
5.
goto 1;
6.
if (used[P[i]] = = true) answer =
false;
7.
return answer;
}
Certificate: A path which is a permutation
of the V nodes in the graph
001 11 010101010 ? ? ? ? ? ? 011000
GATES
010 11 010101010 ? ? ? ? ? ? 011000
GATES
011 11 010101010 ? ? ? ? ? ? 011010
GATES
1
2
3
GATES
11 0 10101010
111 11 010101010 ? ? ? ? ? ? 110011
Answer-Preserving Nature
•
The HP input below
has an HP if and
only if there exists
an assignment of
PATH variables in
red such that the
CIRCUIT will
output 1.
001 11 010101010 ? ? ? ? ? ? 011000
GATES
1
2
3
GATES
11 010 101010
111 11 010101010 ? ? ? ? ? ? 11
Polynomial Time
•
•
•
1
The number of “rows” is
polynomial in the input size
since A is assumed to be a
polynomial time verification
algorithm
The number of columns is
polynomial in the input size
since the certificate must have
polynomial size and the
variables used must be
polynomial in number
GATES is essentially constantsized as GATES is essentially
independent of the input;
GATES depends mostly on the
verification algorithm
2
3
001 11 010101010 ? ? ? ? ? ? 011000
GATES
GATES
11 010 101010
111 11 010101010 ? ? ? ? ? ? 11
Different sized inputs
•
•
There is a minor issue with size
The number of columns does change
depending on the size of the input
1
2
3
1
2
3
1
3
4
11 010101010
001 11 010101010 ? ? ? ? ? ? 011000
11 011 101110
001 11 011101110 ? ? ? ? ? ? 011000
1 00 010 0 101 1 010 00100
2
001 1 00 010 0 101 1 010 00100 ? ? ? ? ? ? ? ? 0 0 11 0 000
General Case
•
Input Cert. Vars
In the general case, PC
the input represented 001 11 010101010 ? ? ? ? ? ?
as a string of bits is
GATES
transformed in an Based on Verification Algorithm
answer-preserving
fashion into a
polynomial-sized
Boolean circuit.
11 010101010
GATES
11 010101010 ? ? ? ? ? ?