Documentation

CslibFrontier.Algorithms.Lean.VertexCover.Matching

The maximal-matching 2-approximation for vertex cover #

This module formalizes the classical 2-approximation for minimum vertex cover: greedily build a maximal matching and return both endpoints of every matching edge ([CLRS09], Section 35.1, APPROX-VERTEX-COVER and Theorem 35.1).

Model #

The graph is SimpleGraph.fromRel (fun u v => (u, v) ∈ es) for a list es : List (V × V) of edges over a type with decidable equality: two distinct vertices are adjacent when some listed edge joins them in either direction. Self-loops and repeated edges may occur in es; the graph ignores them. Covers and the optimum are Mathlib's SimpleGraph.IsVertexCover and SimpleGraph.vertexCoverNum.

Algorithm and source mapping #

greedyMatching es scans es once, keeping an edge (u, v) when u ≠ v and neither endpoint is already matched; matchingCover es lists the endpoints of the kept edges. [CLRS09]'s APPROX-VERTEX-COVER repeatedly picks an arbitrary remaining edge, adds both endpoints to the cover and deletes the edges incident to them; the scan makes the same choices with "arbitrary" read as "first remaining edge in list order", since an edge is still present exactly when neither endpoint has been matched. The analysis is the source's: the kept edges form a matching (nodup_matchingCover), every vertex cover contains a distinct endpoint of each of them (length_le_encard_of_isVertexCover), and the returned cover has exactly two vertices per kept edge (length_endpoints).

Limitations #

The algorithm is a pure Lean function; a machine-level running time for the Graph encoding is in CslibFrontier.Computability.Complexity.Problems.VertexCover.Approximation.

Main definitions #

Main results #

References #

The algorithm #

The endpoints of a list of edges, in order: [u₁, v₁, u₂, v₂, …].

theorem Cslib.Algorithms.Lean.VertexCover.endpoints_eq_flatMap {V : Type u_1} (M : List (V × V)) :
endpoints M = List.flatMap (fun (e : V × V) => [e.1, e.2]) M

Each edge contributes its two endpoints in order.

theorem Cslib.Algorithms.Lean.VertexCover.mem_endpoints {V : Type u_1} {M : List (V × V)} {v : V} :
v ∈ endpoints M ↔ ∃ e ∈ M, v = e.1 ∨ v = e.2

A vertex is an endpoint of M when it is an endpoint of some edge of M.

Each edge contributes two endpoints.

endpoints distributes over concatenation.

endpoints is monotone for list containment.

def Cslib.Algorithms.Lean.VertexCover.matchingStep {V : Type u_1} [DecidableEq V] (M : List (V × V)) (e : V × V) :
List (V × V)

One step of the greedy matching: keep the edge e when its endpoints are distinct and both unmatched by M. Kept edges are appended, so the matching lists them in scan order.

Greedy maximal matching: scan the edges once, keeping each edge whose endpoints are distinct and not yet matched.

The matching cover: both endpoints of every edge of the greedy maximal matching.

One step of the scan that tracks only the matched vertices C: add both endpoints of e when they are distinct and unmatched.

Invariants of the greedy scan #

The scan only adds edges: the initial matching is contained in the final one.

The scan keeps the endpoints of the matching distinct.

theorem Cslib.Algorithms.Lean.VertexCover.mem_foldl_matchingStep {V : Type u_1} [DecidableEq V] (es : List (V × V)) {M : List (V × V)} {e : V × V} (he : e ∈ List.foldl matchingStep M es) :
e ∈ M ∨ e ∈ es ∧ e.1 ≠ e.2

Every edge of the final matching is in the initial matching or is a listed edge with distinct endpoints.

Maximality. Every listed edge with distinct endpoints meets the final matching.

Scanning with matchingStep and taking endpoints is scanning with coverStep.

The matching cover is computed by the scan that tracks only the matched vertices.

The returned vertices are distinct, so the returned list has the cover's size.

theorem Cslib.Algorithms.Lean.VertexCover.mem_greedyMatching {V : Type u_1} [DecidableEq V] {es : List (V × V)} {e : V × V} (he : e ∈ greedyMatching es) :
e ∈ es ∧ e.1 ≠ e.2

The greedy matching consists of listed edges with distinct endpoints.

theorem Cslib.Algorithms.Lean.VertexCover.mem_matchingCover {V : Type u_1} [DecidableEq V] {es : List (V × V)} {v : V} (hv : v ∈ matchingCover es) :
∃ e ∈ es, v = e.1 ∨ v = e.2

The returned vertices are endpoints of listed edges.

Correctness and the factor 2 #

Feasibility. The matching cover is a vertex cover.

theorem Cslib.Algorithms.Lean.VertexCover.length_le_encard_of_isVertexCover {V : Type u_1} {G : SimpleGraph V} {M : List (V × V)} (hM : (endpoints M).Nodup) (hadj : ∀ e ∈ M, G.Adj e.1 e.2) {c : Set V} (hc : G.IsVertexCover c) :

The matching lower bound. A list of edges of G with pairwise distinct endpoints has at most as many edges as any vertex cover of G has vertices: each edge has an endpoint in the cover, and distinct edges have distinct endpoints.

The factor 2 against any cover. The matching cover has at most twice as many vertices as any vertex cover.

The factor 2 against any finite cover.

The maximal-matching 2-approximation: the matching cover has at most twice the minimum number of vertices in a vertex cover.