Documentation

CslibFrontier.Computability.Complexity.Problems.Bipartite

Bipartite graphs and odd cycles as undirected connectivity #

An undirected graph instance (Cslib.Complexity.UGraphInstance) is a simple graph on Fin n, given by a symmetric adjacency matrix with zero diagonal. It belongs to Cslib.Complexity.Bipartite when its graph is 2-colourable (SimpleGraph.IsBipartite).

Non-bipartiteness becomes undirected s–t connectivity through the double cover G′ of Goldreich, Exercise 5.16, whose vertices are the pairs (v, b) of a vertex and a side, with an edge between (u, b) and (v, !b) for every edge {u, v}. A vertex x lies on an odd closed walk exactly when (x, 0) and (x, 1) are connected in G′. The instance Cslib.Complexity.Bipartite.oddCycleInstance G takes one copy of G′ for every vertex x, a source joined to (x, 0) in copy x and a target joined to (x, 1) in copy x. The copies are disjoint, so the source reaches the target exactly when some vertex lies on an odd closed walk, that is, when G is not bipartite (Cslib.Complexity.Bipartite.oddCycleInstance_mem_iff). This turns the disjunction over x of Goldreich's guideline into a single query.

The vertices of the instance are numbered so that a counter program can decode them: the source is 0, the target 1, and the vertex (v, b) of copy x is Cslib.Complexity.Bipartite.copyVertex n x v b = 2 + 2 n x + 2 v + b.

Main definitions #

Main results #

References #

Bipartite graphs: the instances whose graph is 2-colourable.

The numbering of the copies of the double cover #

The number of vertices: two copies of each of the n vertices in each of the n copies, a source and a target.

The vertex (v, b) of the copy x.

The copy of a vertex numbered at least 2.

The vertex of the graph that a vertex numbered at least 2 stands for.

The side of a vertex numbered at least 2.

theorem Cslib.Complexity.Bipartite.copy_copyVertex {n x v : ℕ} (b : Bool) (hv : v < n) :
copy n (copyVertex n x v b) = x
theorem Cslib.Complexity.Bipartite.vert_copyVertex {n : ℕ} (x : ℕ) {v : ℕ} (b : Bool) (hv : v < n) :
vert n (copyVertex n x v b) = v
theorem Cslib.Complexity.Bipartite.copyVertex_lt {n x v : ℕ} (b : Bool) (hx : x < n) (hv : v < n) :
theorem Cslib.Complexity.Bipartite.eq_copyVertex {n r : ℕ} (h₂ : 2 ≤ r) (hr : r < numVertices n) :
copy n r < n ∧ vert n r < n ∧ side r < 2 ∧ r = copyVertex n (copy n r) (vert n r) (decide (side r = 1))

Every vertex numbered at least 2 is a vertex of a copy.

The instance #

The edges of the copies of the double cover, the source and the target, on natural numbers: within a copy, (u, b) and (v, !b) are joined when u and v are; the source 0 is joined to (x, 0) and the target 1 to (x, 1) in the copy x.

The copies of the double cover, with the source 0 and the target 1, as an instance of undirected connectivity.

def Cslib.Complexity.Bipartite.cv (G : UGraphInstance) {x v : ℕ} (hx : x < G.n) (hv : v < G.n) (b : Bool) :

The vertex (v, b) of the copy x, as a vertex of the instance.

Translate a vertex and its side to Mathlib's sum representation of the double cover.

theorem Cslib.Complexity.Bipartite.adj_cv_iff (G : UGraphInstance) {x : ℕ} (hx : x < G.n) (u v : Fin G.n) (b c : Bool) :
(oddCycleInstance G).graph.Adj (cv G hx ⋯ b) (cv G hx ⋯ c) ↔ G.graph.bipartiteDoubleCover.Adj (coverVertex G u b) (coverVertex G v c)

Within a numbered copy, adjacency is exactly Mathlib's bipartite double cover. The arithmetic representation is retained for the counter-program writer.

theorem Cslib.Complexity.Bipartite.adj_cv (G : UGraphInstance) {x : ℕ} (hx : x < G.n) {u v : Fin G.n} (h : G.graph.Adj u v) (b : Bool) :
(oddCycleInstance G).graph.Adj (cv G hx ⋯ b) (cv G hx ⋯ !b)

An edge {u, v} of the graph joins (u, b) and (v, !b) in every copy.

theorem Cslib.Complexity.Bipartite.reachable_cv_of_walk (G : UGraphInstance) {x : ℕ} (hx : x < G.n) {v w : Fin G.n} (p : G.graph.Walk v w) (b : Bool) :
(oddCycleInstance G).graph.Reachable (cv G hx ⋯ b) (cv G hx ⋯ (b ^^ p.length.bodd))

A walk of length ℓ from v to w gives a path from (v, b) to (w, b xor parity ℓ) in every copy.

The source reaches the target exactly when the graph is not bipartite.