Documentation

CslibFrontier.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.edges, 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 Cslib.Complexity.encPathInstance, the graph followed by the two endpoints in binary, and 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

      An instance ⟨G, source, target⟩ of the Hamiltonian path problems Cslib.Complexity.DirHamPath and Cslib.Complexity.HamPath.

      • graph : Graph

        The graph in which to find a Hamiltonian path.

      • source : ℕ

        The start vertex of the path.

      • target : ℕ

        The end vertex of the path.

      Instances For
        theorem Cslib.Complexity.PathInstance.ext {x y : PathInstance} (graph : x.graph = y.graph) (source : x.source = y.source) (target : x.target = y.target) :
        x = y
        theorem Cslib.Complexity.encPathInstance_source_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → PathInstance} :
        theorem Cslib.Complexity.encPathInstance_graph_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → PathInstance} :
        theorem Cslib.Complexity.encPathInstance_target_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → PathInstance} :
        @[reducible, inline]

        The tuple of the fields of encPathInstance.

        Instances For
          theorem Cslib.Complexity.encPathInstance_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → Graph} {x1 x2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encGraph budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encNat budget) :
          Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { graph := x0 x, source := x1 x, target := x2 x }) encIn encPathInstance budget
          theorem Cslib.Complexity.encPathInstance_graph_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → PathInstance} :
          Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ encPathInstance S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (a : γ✝) => (g✝ a).graph) encIn✝ encGraph S✝

          Encoding of PathInstance as (graph, (source, target)) with both endpoints in binary.

          Instances For
            theorem Cslib.Complexity.encPathInstance_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → Graph} {T0 S0 x1 T1 S1 x2 T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encGraph T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encNat T2 S2) :
            Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { graph := x0 x, source := x1 x, target := x2 x }) encIn encPathInstance (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)

            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 : ℕ} :
                    { graph := G, source := s, target := t } ∈ HamPath ↔ ∃ (p : List ℕ), p.Nodup ∧ (∀ (v : ℕ), v ∈ p ↔ v ∈ G.vertices) ∧ p.head? = some s ∧ p.getLast? = some t ∧ List.IsChain G.toSimpleGraph.Adj p

                    Undirected Hamiltonian paths as lists of vertices.

                    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.vertices) (hin : ∀ (u : ℕ), (u, s) ∉ G.edges) :
                    { vertices := G.vertices, edges := (t, s) :: G.edges } ∈ DirHamCycle ↔ { graph := G, source := s, target := t } ∈ DirHamPath

                    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

                            DirHamPath.verifier verifies DirHamPath with certificates of length n ^ 2 for instances of encoded length n.

                            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

                                HamPath.verifier verifies HamPath with certificates of length n ^ 2 for instances of encoded length n.

                                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.