Documentation

CslibFrontier.Computability.Complexity.Problems.SharpCycle

Counting simple directed cycles: #CYCLE #

SharpCycle G is the number of simple directed cycles of a graph G (Cslib.Complexity.Graph), read as a directed graph through its arcs (u, v) ∈ G.edges exactly as DirHamCycle reads it. A simple cycle is a Cycle ℕ, a list up to rotation, that is nonempty, has no repeated vertices, contains only declared vertices, and whose consecutive vertices, read cyclically, are joined by arcs (Cslib.Complexity.Graph.IsSimpleCycle). In particular a self-loop is a cycle of length one.

Arora and Barak, Theorem 9.4 (web draft of 2007-01-08, §9.1, printed p. 173 / PDF p. 189) shows that computing #CYCLE is as hard as deciding whether a digraph has a Hamiltonian cycle. The reduction (Cslib.Complexity.SharpCycle.reduce) replaces every arc (u, v) by a gadget of m layers of two nodes, complete between consecutive layers, from u to v. It has 2 ^ m paths from u to v. A simple cycle of the gadget graph is a simple cycle of G with a path chosen through the gadget of each of its arcs, so a cycle of length k of G gives 2 ^ (m * k) cycles. With n distinct vertices and m = n * n + n + 3, G has fewer than 2 ^ m simple cycles, so a Hamiltonian cycle alone gives 2 ^ (m * n) cycles and without one the total stays below 2 ^ (m * n) (Cslib.Complexity.SharpCycle.mem_DirHamCycle_iff). The draft takes m = n log n + 1; any polynomial m with 2 ^ m above the number of cycles of G works. The extra two layers give a factor-four gap, which also rules out a polynomial-time factor-two approximation (Chapter 9, Exercise 5, printed p. 185 / PDF p. 201).

The original vertex v becomes 2 * v (Cslib.Complexity.SharpCycle.origNode) and the gadget nodes are odd (Cslib.Complexity.SharpCycle.gadgetNode), so the two kinds never collide. Every simple cycle of the gadget graph passes through an original vertex, since the layer index grows along arcs between gadget nodes. Starting there, it decomposes into arcs of G and their gadget paths, and the arcs form a simple cycle of G. Conversely, every simple cycle of G and every choice of bits gives a simple cycle of the gadget graph, and different bits give different cycles.

FP for a natural-valued function is read as polynomial-time computability with binary output (ComputableInPolyTime SharpCycle encGraph encNat), with graphs in the encoding encGraph of DirHamCycle.

Main definitions #

Main results #

References #

c is a simple directed cycle of G: a nonempty cycle without repeated vertices, of declared vertices, whose consecutive vertices, read cyclically, are joined by arcs.

theorem Cslib.Complexity.Graph.isSimpleCycle_coe {G : Graph} {p : List ℕ} :
G.IsSimpleCycle ↑p ↔ p ≠ [] ∧ p.Nodup ∧ (∀ v ∈ p, v ∈ G.vertices) ∧ Cycle.Chain (fun (u v : ℕ) => (u, v) ∈ G.edges) ↑p
noncomputable def Cslib.Complexity.SharpCycle (G : Graph) :

#CYCLE Arora and Barak, Theorem 9.4: the number of simple directed cycles of G.

Finitely many cycles #

A graph has finitely many simple cycles.

The gadget graph #

Codec partitioning the nodes of gadgetGraph into original vertices (.inl v) and arc-gadget layer nodes (.inr ((u, v), if b then .inr j else .inl j)).

The node of the original vertex v in the gadget graph.

Node b of layer j of the gadget of the arc (u, v).

The 2 * m nodes of the gadget of the arc e.

The arcs of the gadget of the arc e: from e.1 to both nodes of the first layer, from both nodes of each layer to both nodes of the next, and from both nodes of the last layer to e.2.

The gadget graph of G with m layers: the original vertices and a gadget for every arc.

The number of layers of the reduction, for n distinct vertices: n * n + n + 3.

The reduction from DirHamCycle to #CYCLE Arora and Barak, Theorem 9.4.

Nodes and arcs of the gadget graph #

theorem Cslib.Complexity.SharpCycle.gadgetNode_inj {u v j u' v' j' : ℕ} {b b' : Bool} :
gadgetNode u v j b = gadgetNode u' v' j' b' ↔ u = u' ∧ v = v' ∧ j = j' ∧ b = b'
theorem Cslib.Complexity.SharpCycle.mem_gadgetArcs {m u v x y : ℕ} :
(x, y) ∈ gadgetArcs m (u, v) ↔ (∃ (b : Bool), x = origNode u ∧ y = gadgetNode u v 0 b) ∨ (∃ (j : ℕ) (b : Bool) (b' : Bool), j + 1 < m ∧ x = gadgetNode u v j b ∧ y = gadgetNode u v (j + 1) b') ∨ ∃ (b : Bool), x = gadgetNode u v (m - 1) b ∧ y = origNode v
theorem Cslib.Complexity.SharpCycle.gadgetNode_mem_vertices_gadgetGraph {m : ℕ} {G : Graph} {u v j : ℕ} {b : Bool} (huv : (u, v) ∈ G.edges) (hj : j < m) :
theorem Cslib.Complexity.SharpCycle.eq_gadgetNode_of_origNode {m : ℕ} {G : Graph} {u y : ℕ} (h : (origNode u, y) ∈ (gadgetGraph m G).edges) :
∃ (v : ℕ) (b : Bool), (u, v) ∈ G.edges ∧ y = gadgetNode u v 0 b

The arcs leaving an original vertex enter the first layer of a gadget.

theorem Cslib.Complexity.SharpCycle.of_gadgetNode {m : ℕ} {G : Graph} {u v j y : ℕ} {b : Bool} (h : (gadgetNode u v j b, y) ∈ (gadgetGraph m G).edges) :
(u, v) ∈ G.edges ∧ ((j + 1 < m ∧ ∃ (b' : Bool), y = gadgetNode u v (j + 1) b') ∨ j = m - 1 ∧ y = origNode v)

The arcs leaving layer j of a gadget enter the next layer, or the end of the arc after the last layer.

Walks through gadgets #

Decomposing paths of the gadget graph #

Nodes of walks #

Cycles of the gadget graph #

Counting #

A Hamiltonian cycle of G gives 2 ^ (m * n) cycles of the gadget graph.

Without a Hamiltonian cycle, four times the gadget cycle count is below 2 ^ (m * n).

Theorem 9.4, the reduction Arora and Barak, Theorem 9.4: with n distinct vertices and m = n * n + n + 3 layers, G has a Hamiltonian cycle exactly when the gadget graph has at least 2 ^ (m * n) simple cycles.

Polynomial time #

The node of an original vertex is computable in polynomial time.

A factor-two estimate of the cycle count decides Hamiltonicity using the factor-four gap. The inequalities avoid division: #CYCLE ≤ 2A and A ≤ 2#CYCLE.

Theorem 9.4, decision Arora and Barak, Theorem 9.4: if the number of simple cycles is computable in polynomial time with binary output, then DirHamCycle ∈ P.

Arora–Barak, Theorem 9.4 Arora and Barak, Theorem 9.4: if #CYCLE, the number of simple directed cycles, is computable in polynomial time with binary output, then P = NP, for every encoding.

theorem Cslib.Complexity.P_eq_NP_of_polyTime_approx_SharpCycle {A : Graph → ℕ} (hA : Turing.MultiTapeTM.ComputableInPolyTime A encGraph Turing.MultiTapeTM.encNat) (hlo : ∀ (G : Graph), SharpCycle G ≤ 2 * A G) (hhi : ∀ (G : Graph), A G ≤ 2 * SharpCycle G) {α : Type} (enc : α ↪ List Bool) :
P enc = NP enc

Arora–Barak, Chapter 9, Exercise 5 (2007-01-08 draft, printed p. 185 / PDF p. 201): a deterministic polynomial-time factor-1/2 approximation to #CYCLE implies P = NP. For binary natural output the guarantee #CYCLE/2 ≤ A ≤ 2#CYCLE is written without division.