Documentation

AlgoLib.Theory.Graph.Structures.SimplePath

Simple paths #

A SimplePath α is a SimpleWalk α whose vertices are pairwise distinct. This file keeps paths as a subtype of simple walks, so every path can be used where a simple walk is expected.

Main definitions #

Every operation is the SimpleWalk one plus a proof that nodup survives.

@[reducible, inline]
abbrev SimpleWalk.IsPath {α : Type u_1} (w : SimpleWalk α) :

A simple walk is a path when it has no repeated vertices.

Equations
Instances For
    def SimplePath (α : Type u_2) :
    Type u_2

    A simple path is a simple walk with no repeated vertex.

    Equations
    Instances For

      Basic accessors #

      @[reducible, inline]
      abbrev SimplePath.val {α : Type u_1} (p : SimplePath α) :

      The underlying simple walk.

      Equations
      Instances For
        @[reducible, inline]
        abbrev SimplePath.vertices {α : Type u_1} (p : SimplePath α) :

        The underlying vertex sequence.

        Equations
        Instances For
          @[reducible, inline]
          abbrev SimplePath.support {α : Type u_1} (p : SimplePath α) :
          List α

          The list of vertices visited by the path.

          Equations
          Instances For
            @[reducible, inline]
            abbrev SimplePath.edges {α : Type u_1} (p : SimplePath α) :
            List (Sym2 α)

            The unordered edges traversed by the path.

            Equations
            Instances For
              @[reducible, inline]
              abbrev SimplePath.arcs {α : Type u_1} (p : SimplePath α) :
              List (α × α)

              The directed arcs traversed by the path.

              Equations
              Instances For
                @[reducible, inline]
                abbrev SimplePath.head {α : Type u_1} (p : SimplePath α) :
                α

                The first vertex of the path.

                Equations
                Instances For
                  @[reducible, inline]
                  abbrev SimplePath.tail {α : Type u_1} (p : SimplePath α) :
                  α

                  The last vertex of the path.

                  Equations
                  Instances For
                    @[reducible, inline]
                    abbrev SimplePath.length {α : Type u_1} (p : SimplePath α) :

                    The number of edges in the path.

                    Equations
                    Instances For
                      theorem SimplePath.nodup {α : Type u_1} (p : SimplePath α) :

                      A path has no repeated vertices.

                      @[implicit_reducible]

                      A simple path is, in particular, a simple walk.

                      Equations

                      Constructors #

                      def SimplePath.singleton {α : Type u_1} (v : α) :

                      The singleton path at v: a single vertex and no edges.

                      Equations
                      Instances For
                        @[simp]

                        The vertex sequence of a singleton path. This is the bridge that lets simp see through SimplePath.singleton down to the VertexSeq layer, where the singleton API lives.

                        @[simp]
                        theorem SimplePath.length_singleton {α : Type u_1} (v : α) :
                        @[simp]
                        theorem SimplePath.head_singleton {α : Type u_1} (v : α) :
                        @[simp]
                        theorem SimplePath.tail_singleton {α : Type u_1} (v : α) :

                        Cycle erasure of any simple walk produces a simple path.

                        Equations
                        Instances For

                          dropHead, dropTail #

                          def SimplePath.dropHead {α : Type u_1} (p : SimplePath α) :

                          Drop the first vertex of a path. Removing an endpoint preserves nodup.

                          Equations
                          Instances For
                            def SimplePath.dropTail {α : Type u_1} (p : SimplePath α) :

                            Drop the last vertex of a path. Removing an endpoint preserves nodup.

                            Equations
                            Instances For

                              append, glue #

                              def SimplePath.append {α : Type u_1} (p q : SimplePath α) (hdisj : ∀ v ∈ p.vertices, v ∈ q.vertices → False) :

                              Concatenate two vertex-disjoint paths, keeping both joining vertices. The disjointness hypothesis is what preserves nodup; it also rules out a stall at the junction.

                              Equations
                              Instances For
                                @[simp]
                                theorem SimplePath.vertices_append {α : Type u_1} (p q : SimplePath α) (hdisj : ∀ v ∈ p.vertices, v ∈ q.vertices → False) :

                                The vertex sequence of an append is the append of the vertex sequences. This is the bridge that lets simp see through SimplePath.append down to the VertexSeq layer, where head_append / tail_append / length_append / mem_append live.

                                def SimplePath.glue {α : Type u_1} (p q : SimplePath α) (h : p.tail = q.head) (hdisj : p.vertices.length ≠ 0 → ∀ v ∈ p.vertices.dropTail, v ∈ q.vertices → False) :

                                Concatenate two paths meeting at a shared vertex, dropping the duplicated joining vertex. When p is nontrivial its remaining vertices must be disjoint from q; when p is a single vertex the result is just q, so no disjointness is required. Guarding the hypothesis by length ≠ 0 keeps the singleton-left case usable, since dropTail leaves a singleton unchanged.

                                Equations
                                Instances For

                                  reverse #

                                  def SimplePath.reverse {α : Type u_1} (p : SimplePath α) :

                                  Reverse a path. Reversal preserves nodup.

                                  Equations
                                  Instances For

                                    prefixUntil, suffixFrom #

                                    def SimplePath.prefixUntil {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                    The prefix of a path ending at the first occurrence of v. A contiguous prefix of a path is a path.

                                    Equations
                                    Instances For
                                      def SimplePath.suffixFrom {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                      The suffix of a path starting at the first occurrence of v. A contiguous suffix of a path is a path.

                                      Equations
                                      Instances For

                                        map #

                                        def SimplePath.map {α : Type u_1} {β : Type u_2} (f : α → β) (hf : Function.Injective f) (p : SimplePath α) :

                                        Map a path through an injective function. Injectivity preserves distinct vertices.

                                        Equations
                                        Instances For

                                          takeWhile, dropWhile #

                                          def SimplePath.takeWhile {α : Type u_1} (p : SimplePath α) (q : α → Prop) [DecidablePred q] :

                                          Take a contiguous prefix of a path, including the first failure if any.

                                          Equations
                                          Instances For
                                            def SimplePath.dropWhile {α : Type u_1} (p : SimplePath α) (q : α → Prop) [DecidablePred q] (h : ∃ v ∈ p.vertices.toList, ¬q v) :

                                            Drop the longest prefix of a path on which q holds. The result is a contiguous suffix, hence a path.

                                            Equations
                                            Instances For

                                              splitAt #

                                              def SimplePath.splitAt {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) :

                                              Split a path at every occurrence of v. Every produced piece is a contiguous subpath.

                                              Equations
                                              Instances For

                                                zip #

                                                def SimplePath.zip {α : Type u_1} {β : Type u_2} (p : SimplePath α) (q : SimplePath β) :
                                                SimplePath (α × β)

                                                Zip two paths into a path of pairs. Pairwise distinct first components are enough to make the pairs pairwise distinct.

                                                Equations
                                                Instances For

                                                  loopErase #

                                                  def SimplePath.loopErase {α : Type u_1} [DecidableEq α] (p : SimplePath α) :

                                                  Remove immediate stalls from a path. Since a path has no repeated vertices, this preserves nodup.

                                                  Equations
                                                  Instances For

                                                    edges #

                                                    @[simp]
                                                    theorem SimplePath.length_edges {α : Type u_1} (p : SimplePath α) :

                                                    The number of traversed edges equals the path's length.

                                                    theorem SimplePath.edges_nodup {α : Type u_1} (p : SimplePath α) :

                                                    A path traverses each edge at most once (a path is a trail).

                                                    @[simp]

                                                    Reversal reverses the edge list.

                                                    Dropping the last vertex cannot introduce new edges.

                                                    Dropping the first vertex cannot introduce new edges.

                                                    theorem SimplePath.edges_prefixUntil_subset {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                                    Taking a prefix cannot introduce new edges.

                                                    theorem SimplePath.edges_suffixFrom_subset {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                                    Taking a suffix cannot introduce new edges.

                                                    arcs #

                                                    @[simp]
                                                    theorem SimplePath.length_arcs {α : Type u_1} (p : SimplePath α) :

                                                    The number of traversed arcs equals the path's length.

                                                    theorem SimplePath.arcs_nodup {α : Type u_1} (p : SimplePath α) :

                                                    A path traverses each directed arc at most once.

                                                    @[simp]
                                                    theorem SimplePath.arcs_reverse {α : Type u_1} (p : SimplePath α) :
                                                    p.reverse.arcs = List.map (fun (a : α × α) => (a.2, a.1)) p.arcs.reverse

                                                    Reversal reverses the arc list and swaps every arc's endpoints.

                                                    Dropping the last vertex cannot introduce new arcs.

                                                    Dropping the first vertex cannot introduce new arcs.

                                                    theorem SimplePath.arcs_prefixUntil_subset {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                                    Taking a prefix cannot introduce new arcs.

                                                    theorem SimplePath.arcs_suffixFrom_subset {α : Type u_1} [DecidableEq α] (p : SimplePath α) (v : α) (h : v ∈ p.vertices) :

                                                    Taking a suffix cannot introduce new arcs.