Documentation

Complexity.Computability.Complexity.Problems.Hamiltonian

Hamiltonian paths and cycles #

A graph, given by a list of vertices and a list of edges, is read as a directed graph through its arcs (u, v) ∈ G.2, or as an undirected graph through Cslib.Complexity.Graph.toSimpleGraph restricted to the declared vertices (SimpleGraph.induce). In both readings the vertices are the declared ones: repeated vertex entries count once, and edges with an undeclared endpoint are never used.

All four problems are in NP. A certificate names an ordering of the distinct declared vertices: for a vertex list of length m, it is read as one block of m bits for each distinct declared vertex, and each block names the entry of the vertex list whose position is its number of set bits (Graph.decodeVertexList). The verifiers check that the decoded list contains every declared vertex exactly once and nothing else (Graph.verifyOrdering), and then the endpoint, length and edge conditions. Every ordering has a certificate of length n ^ 2 for instances of encoded length n. Path instances (G, s, t) are encoded by encPair encGraph (encPair encNat encNat), cycle instances by encGraph.

Main definitions #

Main results #

References #

p is a Hamiltonian path of the directed graph G from s to t: it lists every declared vertex exactly once, starts at s, ends at t, and consecutive vertices are joined by arcs.

Instances For

    p is a Hamiltonian cycle of the directed graph G: a nonempty list of every declared vertex exactly once whose consecutive vertices, read cyclically, are joined by arcs.

    Instances For

      The directed graphs with a Hamiltonian path from s to t Sipser, Section 7.3.

      Instances For

        The directed graphs with a Hamiltonian cycle [Kar72].

        Instances For

          The graphs with a Hamiltonian path from s to t through their declared vertices Sipser, Theorem 7.55.

          Instances For

            The graphs with a Hamiltonian cycle through their declared vertices [Kar72].

            Instances For

              Lists of vertices #

              theorem Cycle.chain_coe_iff_isChain_append_take_one {α : Type u_1} {R : α → α → Prop} {p : List α} :
              Chain R ↑p ↔ List.IsChain R (p ++ List.take 1 p)

              A list is a closed chain exactly when appending its first element gives a chain.

              theorem Cslib.Complexity.mem_HamPath_iff {G : Graph} {s t : ℕ} :
              (G, s, t) ∈ HamPath ↔ ∃ (p : List ℕ), p.Nodup ∧ (∀ (v : ℕ), v ∈ p ↔ v ∈ G.1) ∧ p.head? = some s ∧ p.getLast? = some t ∧ List.IsChain G.toSimpleGraph.Adj p

              Undirected Hamiltonian paths as lists of vertices.

              theorem Cslib.Complexity.mem_HamCycle_iff {G : Graph} :
              G ∈ HamCycle ↔ ∃ (p : List ℕ), p.Nodup ∧ (∀ (v : ℕ), v ∈ p ↔ v ∈ G.1) ∧ 3 ≤ p.length ∧ Cycle.Chain G.toSimpleGraph.Adj ↑p

              Undirected Hamiltonian cycles as lists of vertices.

              Closing a path into a cycle #

              theorem Cslib.Complexity.Graph.mem_DirHamCycle_cons_iff {G : Graph} {s t : ℕ} (hs : s ∈ G.1) (hin : ∀ (u : ℕ), (u, s) ∉ G.2) :

              Closing a Hamiltonian path with an arc back to its start. If no arc of G enters the declared vertex s, then adding the arc (t, s) creates a Hamiltonian cycle exactly when G has a Hamiltonian path from s to t.

              Verifying lists of vertices #

              Executable arc test of a directed graph: (u, v) is an edge of G.

              Instances For
                @[simp]

                arcBool decides whether (u, v) is an edge of the list.

                Executable test that r holds between all consecutive entries of p.

                Instances For
                  theorem Cslib.Complexity.Graph.chainBool_eq_true_iff {r : ℕ → ℕ → Bool} {R : ℕ → ℕ → Prop} (hr : ∀ (u v : ℕ), r u v = true ↔ R u v) {p : List ℕ} :

                  chainBool r decides List.IsChain R when r decides R.

                  Executable test that r holds between all consecutive entries of p read cyclically: from each entry to the next one, and from the last entry to the first.

                  Instances For
                    theorem Cslib.Complexity.Graph.cycleChainBool_eq_true_iff {r : ℕ → ℕ → Bool} {R : ℕ → ℕ → Prop} (hr : ∀ (u v : ℕ), r u v = true ↔ R u v) {p : List ℕ} :

                    cycleChainBool r decides Cycle.Chain R when r decides R: the empty list passes, and a one-entry list [a] passes exactly when R a a.

                    Polynomial-time verification #

                    Testing whether r holds between consecutive entries of a computed list is polynomial-time, for an input-dependent polynomial-time test r.

                    Testing whether r holds between cyclically consecutive entries of a computed list is polynomial-time, for an input-dependent polynomial-time test r.

                    Membership in NP #

                    The verifier for DirHamPath: decode a list of vertices from the certificate (Graph.decodeVertexList) and check that it lists every declared vertex exactly once, starts at s, ends at t, and that consecutive vertices are joined by arcs.

                    Instances For

                      The verifier for DirHamCycle: decode a list of vertices from the certificate (Graph.decodeVertexList) and check that it is nonempty, lists every declared vertex exactly once, and that cyclically consecutive vertices are joined by arcs.

                      Instances For

                        DirHamCycle.verifier verifies DirHamCycle with certificates of length n ^ 2 for graphs of encoded length n.

                        The verifier for HamPath: decode a list of vertices from the certificate (Graph.decodeVertexList) and check that it lists every declared vertex exactly once, starts at s, ends at t, and that consecutive vertices are adjacent.

                        Instances For

                          The verifier for HamCycle: decode a list of vertices from the certificate (Graph.decodeVertexList) and check that it has at least three vertices, lists every declared vertex exactly once, and that cyclically consecutive vertices are adjacent.

                          Instances For

                            HamCycle.verifier verifies HamCycle with certificates of length n ^ 2 for graphs of encoded length n.