Documentation

Mathlib.Combinatorics.SimpleGraph.Walks.Basic

Walks #

In a simple graph, a walk is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges.

Warning: graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path."

Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994].

Main definitions #

Tags #

walks

inductive SimpleGraph.Walk {V : Type u} (G : SimpleGraph V) :
V โ†’ V โ†’ Type u

A walk is a sequence of adjacent vertices. For vertices u v : V, the type walk u v consists of all walks starting at u and ending at v.

We say that a walk visits the vertices it contains. The set of vertices a walk visits is SimpleGraph.Walk.support.

See SimpleGraph.Walk.nil' and SimpleGraph.Walk.cons' for patterns that can be useful in definitions since they make the vertices explicit.

Instances For
    def SimpleGraph.instDecidableEqWalk.decEq {Vโœ : Type u_1} {Gโœ : SimpleGraph Vโœ} {aโœ aโœยน : Vโœ} [DecidableEq Vโœ] (xโœ xโœยน : Gโœ.Walk aโœ aโœยน) :
    Decidable (xโœ = xโœยน)
    Equations
      Instances For
        instance SimpleGraph.instDecidableEqWalk {Vโœ : Type u_1} {Gโœ : SimpleGraph Vโœ} {aโœ aโœยน : Vโœ} [DecidableEq Vโœ] :
        DecidableEq (Gโœ.Walk aโœ aโœยน)
        Equations
          instance SimpleGraph.Walk.instInhabited {V : Type u} (G : SimpleGraph V) (v : V) :
          Inhabited (G.Walk v v)
          Equations
            @[reducible, match_pattern]
            def SimpleGraph.Adj.toWalk {V : Type u} {G : SimpleGraph V} {u v : V} (h : G.Adj u v) :
            G.Walk u v

            The one-edge walk associated to a pair of adjacent vertices.

            Equations
              Instances For
                @[reducible, match_pattern, inline]
                abbrev SimpleGraph.Walk.nil' {V : Type u} {G : SimpleGraph V} (u : V) :
                G.Walk u u

                Pattern to get Walk.nil with the vertex as an explicit argument.

                Equations
                  Instances For
                    @[reducible, match_pattern, inline]
                    abbrev SimpleGraph.Walk.cons' {V : Type u} {G : SimpleGraph V} (u v w : V) (h : G.Adj u v) (p : G.Walk v w) :
                    G.Walk u w

                    Pattern to get Walk.cons with the vertices as explicit arguments.

                    Equations
                      Instances For
                        theorem SimpleGraph.Walk.exists_eq_cons_of_ne {V : Type u} {G : SimpleGraph V} {u v : V} (hne : u โ‰  v) (p : G.Walk u v) :
                        โˆƒ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p'
                        def SimpleGraph.Walk.length {V : Type u} {G : SimpleGraph V} {u v : V} :
                        G.Walk u v โ†’ โ„•

                        The length of a walk is the number of edges/darts along it.

                        Equations
                          Instances For
                            @[simp]
                            theorem SimpleGraph.Walk.length_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                            (cons h p).length = p.length + 1
                            theorem SimpleGraph.Walk.eq_of_length_eq_zero {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} :
                            p.length = 0 โ†’ u = v
                            theorem SimpleGraph.Walk.adj_of_length_eq_one {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} :
                            p.length = 1 โ†’ G.Adj u v
                            @[simp]
                            theorem SimpleGraph.Walk.exists_length_eq_zero_iff {V : Type u} {G : SimpleGraph V} {u v : V} :
                            (โˆƒ (p : G.Walk u v), p.length = 0) โ†” u = v
                            @[simp]
                            theorem SimpleGraph.Walk.exists_length_eq_one_iff {V : Type u} {G : SimpleGraph V} {u v : V} :
                            (โˆƒ (p : G.Walk u v), p.length = 1) โ†” G.Adj u v
                            @[simp]
                            theorem SimpleGraph.Walk.length_eq_zero_iff {V : Type u} {G : SimpleGraph V} {u : V} {p : G.Walk u u} :
                            def SimpleGraph.Walk.support {V : Type u} {G : SimpleGraph V} {u v : V} :
                            G.Walk u v โ†’ List V

                            The support of a walk is the list of vertices it visits in order.

                            Equations
                              Instances For
                                def SimpleGraph.Walk.darts {V : Type u} {G : SimpleGraph V} {u v : V} :
                                G.Walk u v โ†’ List G.Dart

                                The darts of a walk is the list of darts it visits in order.

                                Equations
                                  Instances For
                                    def SimpleGraph.Walk.edges {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :

                                    The edges of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying SimpleGraph.Walk.darts.

                                    Equations
                                      Instances For
                                        @[simp]
                                        theorem SimpleGraph.Walk.support_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                                        (cons h p).support = u :: p.support
                                        @[simp]
                                        theorem SimpleGraph.Walk.support_ne_nil {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.head_support {V : Type u} {G : SimpleGraph V} {a b : V} (p : G.Walk a b) :
                                        p.support.head โ‹ฏ = a
                                        @[simp]
                                        theorem SimpleGraph.Walk.getLast_support {V : Type u} {G : SimpleGraph V} {a b : V} (p : G.Walk a b) :
                                        p.support.getLast โ‹ฏ = b
                                        @[simp]
                                        theorem SimpleGraph.Walk.start_mem_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.end_mem_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.support_nonempty {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.end_mem_tail_support_of_ne {V : Type u} {G : SimpleGraph V} {u v : V} (h : u โ‰  v) (p : G.Walk u v) :
                                        theorem SimpleGraph.Walk.support_subset_support_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk v w) (hadj : G.Adj u v) :
                                        theorem SimpleGraph.Walk.coe_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        โ†‘p.support = {u} + โ†‘p.support.tail
                                        theorem SimpleGraph.Walk.isChain_adj_cons_support {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                                        @[deprecated SimpleGraph.Walk.isChain_adj_cons_support (since := "2025-09-24")]
                                        theorem SimpleGraph.Walk.chain_adj_support {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :

                                        Alias of SimpleGraph.Walk.isChain_adj_cons_support.

                                        @[deprecated SimpleGraph.Walk.isChain_adj_support (since := "2025-09-24")]
                                        theorem SimpleGraph.Walk.chain'_adj_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :

                                        Alias of SimpleGraph.Walk.isChain_adj_support.

                                        theorem SimpleGraph.Walk.isChain_dartAdj_cons_darts {V : Type u} {G : SimpleGraph V} {d : G.Dart} {v w : V} (h : d.toProd.2 = v) (p : G.Walk v w) :
                                        @[deprecated SimpleGraph.Walk.isChain_dartAdj_cons_darts (since := "2025-09-24")]
                                        theorem SimpleGraph.Walk.chain_dartAdj_darts {V : Type u} {G : SimpleGraph V} {d : G.Dart} {v w : V} (h : d.toProd.2 = v) (p : G.Walk v w) :

                                        Alias of SimpleGraph.Walk.isChain_dartAdj_cons_darts.

                                        @[deprecated SimpleGraph.Walk.isChain_dartAdj_darts (since := "2025-09-24")]
                                        theorem SimpleGraph.Walk.chain'_dartAdj_darts {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :

                                        Alias of SimpleGraph.Walk.isChain_dartAdj_darts.

                                        theorem SimpleGraph.Walk.edges_subset_edgeSet {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) โฆƒe : Sym2 Vโฆ„ :
                                        e โˆˆ p.edges โ†’ e โˆˆ G.edgeSet

                                        Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using โІ) to avoid unsightly coercions.

                                        theorem SimpleGraph.Walk.adj_of_mem_edges {V : Type u} {G : SimpleGraph V} {u v x y : V} (p : G.Walk u v) (h : s(x, y) โˆˆ p.edges) :
                                        G.Adj x y
                                        @[simp]
                                        theorem SimpleGraph.Walk.darts_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                                        (cons h p).darts = { fst := u, snd := v, adj := h } :: p.darts
                                        theorem SimpleGraph.Walk.cons_map_snd_darts {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        u :: List.map (fun (x : G.Dart) => x.toProd.2) p.darts = p.support
                                        theorem SimpleGraph.Walk.map_snd_darts {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        List.map (fun (x : G.Dart) => x.toProd.2) p.darts = p.support.tail
                                        theorem SimpleGraph.Walk.map_fst_darts_append {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        List.map (fun (x : G.Dart) => x.toProd.1) p.darts ++ [v] = p.support
                                        theorem SimpleGraph.Walk.map_fst_darts {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        List.map (fun (x : G.Dart) => x.toProd.1) p.darts = p.support.dropLast
                                        @[simp]
                                        theorem SimpleGraph.Walk.edges_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                                        (cons h p).edges = s(u, v) :: p.edges
                                        @[simp]
                                        theorem SimpleGraph.Walk.length_support {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.length_darts {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.length_edges {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.fst_darts_getElem {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} {i : โ„•} (hi : i < p.darts.length) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.snd_darts_getElem {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} {i : โ„•} (hi : i < p.darts.length) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.support_getElem_zero {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        @[simp]
                                        theorem SimpleGraph.Walk.support_getElem_length {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        theorem SimpleGraph.Walk.mem_darts_iff_infix_support {V : Type u} {G : SimpleGraph V} {u v u' v' : V} {p : G.Walk u v} (h : G.Adj u' v') :
                                        { fst := u', snd := v', adj := h } โˆˆ p.darts โ†” [u', v'] <:+: p.support
                                        theorem SimpleGraph.Walk.mem_support_iff_exists_mem_edges {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} :
                                        w โˆˆ p.support โ†” w = v โˆจ โˆƒ e โˆˆ p.edges, w โˆˆ e
                                        theorem SimpleGraph.Walk.edges_eq_zipWith_support {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} :
                                        p.edges = List.zipWith (fun (x1 x2 : V) => s(x1, x2)) p.support p.support.tail
                                        def SimpleGraph.Walk.edgeSet {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) :
                                        Set (Sym2 V)

                                        The Set of edges of a walk.

                                        Equations
                                          Instances For
                                            @[simp]
                                            theorem SimpleGraph.Walk.mem_edgeSet {V : Type u} {G : SimpleGraph V} {u v : V} {p : G.Walk u v} {e : Sym2 V} :
                                            @[simp]
                                            theorem SimpleGraph.Walk.edgeSet_cons {V : Type u} {G : SimpleGraph V} {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
                                            inductive SimpleGraph.Walk.Nil {V : Type u} {G : SimpleGraph V} {v w : V} :
                                            G.Walk v w โ†’ Prop

                                            Predicate for the empty walk.

                                            Solves the dependent type problem where p = G.Walk.nil typechecks only if p has defeq endpoints.

                                            Instances For
                                              @[simp]
                                              theorem SimpleGraph.Walk.nil_nil {V : Type u} {G : SimpleGraph V} {u : V} :
                                              @[simp]
                                              theorem SimpleGraph.Walk.not_nil_cons {V : Type u} {G : SimpleGraph V} {u v w : V} {h : G.Adj u v} {p : G.Walk v w} :
                                              instance SimpleGraph.Walk.instDecidableNil {V : Type u} {G : SimpleGraph V} {v w : V} (p : G.Walk v w) :
                                              Equations
                                                theorem SimpleGraph.Walk.Nil.eq {V : Type u} {G : SimpleGraph V} {v w : V} {p : G.Walk v w} :
                                                p.Nil โ†’ v = w
                                                theorem SimpleGraph.Walk.not_nil_of_ne {V : Type u} {G : SimpleGraph V} {v w : V} {p : G.Walk v w} :
                                                v โ‰  w โ†’ ยฌp.Nil
                                                @[simp]
                                                theorem SimpleGraph.Walk.darts_eq_nil {V : Type u} {G : SimpleGraph V} {v w : V} {p : G.Walk v w} :
                                                @[simp]
                                                theorem SimpleGraph.Walk.edges_eq_nil {V : Type u} {G : SimpleGraph V} {v w : V} {p : G.Walk v w} :
                                                theorem SimpleGraph.Walk.not_nil_iff {V : Type u} {G : SimpleGraph V} {v w : V} {p : G.Walk v w} :
                                                ยฌp.Nil โ†” โˆƒ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q
                                                theorem SimpleGraph.Walk.nil_iff_eq_nil {V : Type u} {G : SimpleGraph V} {v : V} {p : G.Walk v v} :

                                                A walk with its endpoints defeq is Nil if and only if it is equal to nil.

                                                theorem SimpleGraph.Walk.Nil.eq_nil {V : Type u} {G : SimpleGraph V} {v : V} {p : G.Walk v v} :
                                                p.Nil โ†’ p = Walk.nil

                                                Alias of the forward direction of SimpleGraph.Walk.nil_iff_eq_nil.


                                                A walk with its endpoints defeq is Nil if and only if it is equal to nil.

                                                def SimpleGraph.Walk.notNilRec {V : Type u} {G : SimpleGraph V} {u w : V} {motive : {u w : V} โ†’ (p : G.Walk u w) โ†’ ยฌp.Nil โ†’ Sort u_1} (cons : {u v w : V} โ†’ (h : G.Adj u v) โ†’ (q : G.Walk v w) โ†’ motive (cons h q) โ‹ฏ) (p : G.Walk u w) (hp : ยฌp.Nil) :
                                                motive p hp

                                                The recursion principle for nonempty walks

                                                Equations
                                                  Instances For
                                                    @[simp]
                                                    theorem SimpleGraph.Walk.notNilRec_cons {V : Type u} {G : SimpleGraph V} {u v w : V} {motive : {u w : V} โ†’ (p : G.Walk u w) โ†’ ยฌp.Nil โ†’ Sort u_1} (cons : {u v w : V} โ†’ (h : G.Adj u v) โ†’ (q : G.Walk v w) โ†’ motive (cons h q) โ‹ฏ) (h' : G.Adj u v) (q' : G.Walk v w) :
                                                    notNilRec (fun {u v w : V} => cons) (Walk.cons h' q') โ‹ฏ = cons h' q'
                                                    theorem SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} (hnil : ยฌp.Nil) :
                                                    w โˆˆ p.support โ†” โˆƒ e โˆˆ p.edges, w โˆˆ e
                                                    theorem SimpleGraph.Walk.exists_boundary_dart {V : Type u} {G : SimpleGraph V} {u v : V} (p : G.Walk u v) (S : Set V) (uS : u โˆˆ S) (vS : v โˆ‰ S) :
                                                    โˆƒ d โˆˆ p.darts, d.toProd.1 โˆˆ S โˆง d.toProd.2 โˆ‰ S

                                                    Given a set S and a walk w from u to v such that u โˆˆ S but v โˆ‰ S, there exists a dart in the walk whose start is in S but whose end is not.