A function \(f: \binary^* \to \binary^*\) is polynomial-time computable if there exists a polynomial-time algorithm that, given input \(x\), computes \(f(x)\).
Let \(A, B \subseteq \binary^*\) be decision problems. We say \(A\) is polynomial-time reducible to \(B\)
if there is a polynomial-time computable function \(f\) such that for all \(x \in \binary^*\):
\[ \fragment{x \in A \iff f(x) \in B} \]
We denote this by \(A \le^P B\).
\(A \le^P B\) means: “B is at least as hard as A” (to within a polynomial-time factor).
Which of the following are possible lengths of \(f(x)\)?
\(|f(x)| \le |x|^c\) if \(f\) is computable in time \(n^c\) for some constant \(c\).
\[ A \le^P B \]
“Reducing from \(A\) to \(B\)”
\[ x \in A \iff f(x) \in B \]
from itertools import combinations as subsets
def reduction_from_independent_set_to_clique(G, k):
V, E = G
Ec = [ {u,v} for (u,v) in subsets(V,2)
if {u,v} not in E and u!=v ]
Gc = (V, Ec)
return (Gc, k)
# Hypothetical polynomial-time algorithm for Independent Set
def independent_set(G, k):
Gp, kp = reduction_from_independent_set_to_clique(G, k)
return clique_algorithm(Gp, kp)
# Hypothetical polynomial-time algorithm for Clique
def clique_algorithm(G, k):
raise NotImplementedError("Not implemented yet...")
reduction_from_independent_set_to_clique
also happens to work in the other directionLet’s now formalize what we mean by “\(B\) is at least as hard as \(A\)”
Theorem: If \(A \le^P B\) and \(B \in \P\), then \(A \in \P\).
Proof:
Since \(B \in \P\), there exists an algorithm \(M_B\) for \(B\) that runs in time \(n^k\) for some constant \(k\)
Since \(A \le^P B\), there exists a polynomial-time reduction \(f\) from \(A\) to \(B\)
(running in time \(n^c\) for some constant \(c\)).
We can construct an algorithm \(M_A\) deciding \(A\) simply by composing \(f\) and \(M_B\): \[ M_A(x) = M_B(f(x)) \]
What is the time complexity of \(M_A\)? Let \(n = |x|\).
Let’s now formalize what we mean by “\(B\) is at least as hard as \(A\)”
Theorem: If \(A \le^P B\) and \(B \in \P\), then \(A \in \P\).
Corollary: If \(A \le^P B\) and \(A \notin \P\), then \(B \notin \P\).
This corollary is the way we typically use reductions:
we know/believe \(A\) is hard, and want to show \(B\) is at least as hard.
Suppose we want to show that \(\probSAT\) is at least as hard as \(\probHamPath\).
Which problem should we reduce to which?
\[ \probHamPath \le^P \probSAT \]
\[ \probHamPath \overset{f}{\longrightarrow} \probSAT \]
A Boolean formula is in conjunctive normal form (CNF) if it is a conjunction of clauses,
where each clause is a disjunction of literals. Example:
\[ \phi = \underbrace{(x \lor \overline{y} \lor \overline{z} \lor w)}_\text{Clause 1} \land \underbrace{(z \lor \overline{w} \lor x)}_\text{Clause 1} \land \underbrace{(y \lor \overline{x})}_\text{Clause 3} \]
\(\encoding{\phi} \in \probSAT\) iff we can pick one literal from each clause to set to “1” without conflicts!
A literal is a variable \(x\) or its negation \(\overline{x} = \neg x\).
A Boolean CNF formula \(\phi\) is a 3-CNF formula if each of its clauses has exactly 3 literals.
Example: \[
\fragment{\phi = (x \lor \overline{y} \lor \overline{z}) \land (z \lor \overline{y} \lor x)}
\]
\[ \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}} \]
This turns out to be just as hard as \(\probSAT\)!
\[ \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}} \]
\[ \probIndSet = \setbuild{\encoding{G, k}}{ G \text{ is an undirected graph with a } k\text{-independent set}} \]
\[ \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}} \]
\[ \probIndSet = \setbuild{\encoding{G, k}}{ G \text{ is an undirected graph with a } k\text{-independent set}} \]
Theorem: \(\probThreeSAT \le^P \probIndSet\).
Proof:
Given a 3-CNF formula \(\phi\), our reduction must produce a pair \((G, k)\) such that: \[ \encoding{\phi} \in \probThreeSAT \; \iff \; \encoding{G, k} \in \probIndSet \]
Set \(k\) equal to the number of clauses in \(\phi\).
To simplify notation, we write \(\phi\) as: \[ \phi = (a_1 \lor b_1 \lor c_1) \land \fragment{(a_2 \lor b_2 \lor c_2) \land} \fragment{\ldots \land (a_k \lor b_k \lor c_k)} \] where \(a_i, b_i, c_i\) are the three literals in clause \(i\).
G will have \(3k\) nodes,
one for each literal in \(\phi\).
\[ \phi = (x \lor x \lor y) \land (\overline{x} \lor \overline{y} \lor \overline{y}) \land (\overline{x} \lor y \lor y) \hspace{6em} \]
Is this formula satisfiable?
Yes: \(x = 0, y = 1\).
\(\encoding{\phi} \in \probThreeSAT\) iff we can pick
one literal from each clause
to set to “1” without conflicts!
Theorem: \(\probThreeSAT \le^P \probIndSet\).
Proof:
Given a 3-CNF formula \(\phi\): \[ \phi = (a_1 \lor b_1 \lor c_1) \land (a_2 \lor b_2 \lor c_2) \land \ldots \land (a_k \lor b_k \lor c_k) \] we produce a pair \((G, k)\) such that: \[ \encoding{\phi} \in \probThreeSAT \; \iff \; \encoding{G, k} \in \probIndSet \]
Set \(k\) equal to the number of clauses in \(\phi\).
We can generate these edges in polynomial time by looping over all pairs of nodes (\(O(|V|^2)\))
and checking the these two conditions by scanning through \(\phi\). (Python code in lecture notes)
Proof that \(\encoding{\phi} \in \probThreeSAT \; \iff \; \encoding{G, k} \in \probIndSet\):