wild-inter.net

3SAT ≤p Vertex Cover  ·  an NP-hardness reduction, step by step

A Karp reduction turns every instance of one problem into an instance of another, in polynomial time, so that the answers agree. Here a 3-CNF formula φ with n clauses becomes a graph G with a triangle per clause and an edge between every pair of complementary literals; the threshold is k = 2n. The page builds G, then walks through both directions of the correctness proof. Everything is live: click a literal to fix its variable, click a vertex to put it into or take it out of S.

Small screen: this is the compact demo. The pseudocode and proof with live line highlighting are on the desktop version.
Two views on the same theme: the reduction proves hardness, the equivalences carry it on.
Random clauses, variables
Arrow keys step. Click a literal to make it true; click a vertex to toggle it in S.
— / — Speed 800ms
The formula φ
Click a literal to make it true (its variable is fixed accordingly); click a variable chip to cycle ? → 1 → 0. Dashed chips were chosen by the page to satisfy as many clauses as possible.
The graph G = g(φ)
(a) same clause (b) negations of each other in the cover S satisfied literal uncovered edge
What just happened
The set S
Reduction & correctness proof
Input
One clause per line, exactly three literals; a negative number is a negated variable (-3 is ¬x3; !x3, ~x3, ¬x3 work too, and ∨, |, parentheses are ignored). Lines starting with # are comments.
# φ from the lecture
1 2 -3
-1 3 4
-1 -2 -4
2 3 4
cols 2
assign -1 -2 -3 4
cols c sets how many clause triangles go in one row; assign l₁ l₂ … presets an assignment as a list of true literals. To place a clause by hand, append @ x y to its line (grid units: one clause pitch is 1, so @ 0 0, @ 1 0, @ 0.5 1 …). Limits: 12 clauses, variables x1…x16.