The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V30. Combinatorics

Mathlib.Combinatorics.SimpleGraph.Walk.Counting

25 declarations and 6 deprecated aliases. Mathlib docs · Source

Counting walks of a given length

Main definitions

  • walkLengthTwoEquivCommonNeighbors: bijective correspondence between walks of length two from u to v and common neighbours of u and v. Note that u and v may be the same.
  • finsetWalkLength: the Finset of length-n walks from u to v. This is used to give {p : G.walk u v | p.length = n} a Fintype instance, and it can also be useful as a recursive description of this set when V is finite.

TODO: should this be extended further?

theorem SimpleGraph.finsetWalkLength.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (n : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n_1 : ℕ),
  n = n_1.succ →
    (match n with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_2 n_1

theorem SimpleGraph.finsetWalkLength.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (n : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
  n = 0 →
    (match n with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_1 ()

theorem SimpleGraph.Walk.setOfPred_length_eq_zero E1 #

∀ {V : Type u} (G : SimpleGraph V) (u : V), {p | p.length = 0} = {SimpleGraph.Walk.nil}

theorem SimpleGraph.Walk.setOfPred_length_eq_zero_of_ne E1 #

∀ {V : Type u} (G : SimpleGraph V) {u v : V}, u ≠ v → {p | p.length = 0} = ∅

theorem SimpleGraph.Walk.setOfPred_length_eq_add_one E1 #

∀ {V : Type u} (G : SimpleGraph V) (u v : V) (n : ℕ),
  {p | p.length = n + 1} = ⋃ w, ⋃ (h : G.Adj u w), SimpleGraph.Walk.cons h '' {p' | p'.length = n}

def SimpleGraph.walkLengthTwoEquivCommonNeighbors E1 #

{V : Type u} → (G : SimpleGraph V) → (u v : V) → { p // p.length = 2 } ≃ ↑(G.commonNeighbors u v)

Walks of length two from u to v correspond bijectively to common neighbours of u and v. Note that u and v may be the same.

theorem SimpleGraph.walkLengthTwoEquivCommonNeighbors_symm_apply_coe E0 #

∀ {V : Type u} (G : SimpleGraph V) (u v : V) (w : ↑(G.commonNeighbors u v)),
  ↑((G.walkLengthTwoEquivCommonNeighbors u v).symm w) = (SimpleGraph.Adj.toWalk ⋯).concat ⋯

theorem SimpleGraph.walkLengthTwoEquivCommonNeighbors_apply_coe E0 #

∀ {V : Type u} (G : SimpleGraph V) (u v : V) (p : { p // p.length = 2 }),
  ↑((G.walkLengthTwoEquivCommonNeighbors u v) p) = (↑p).snd

def SimpleGraph.finsetWalkLength E1 #

{V : Type u} → (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → ℕ → (u v : V) → Finset (G.Walk u v)

The Finset of length-n walks from u to v. This is used to give {p : G.walk u v | p.length = n} a Fintype instance, and it can also be useful as a recursive description of this set when V is finite.

See SimpleGraph.coe_finsetWalkLength_eq for the relationship between this Finset and the set of length-n walks.

theorem SimpleGraph.coe_finsetWalkLength_eq E0 #

∀ {V : Type u} (G : SimpleGraph V) [inst : DecidableEq V] [inst_1 : G.LocallyFinite] (n : ℕ) (u v : V),
  ↑(G.finsetWalkLength n u v) = {p | p.length = n}

theorem SimpleGraph.mem_finsetWalkLength_iff E0 #

∀ {V : Type u} {G : SimpleGraph V} [inst : DecidableEq V] [inst_1 : G.LocallyFinite] {n : ℕ} {u v : V} {p : G.Walk u v},
  p ∈ G.finsetWalkLength n u v ↔ p.length = n

def SimpleGraph.finsetWalkLengthLT E1 #

{V : Type u} → (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → ℕ → (u v : V) → Finset (G.Walk u v)

The Finset of walks from u to v with length less than n. See finsetWalkLength for context. In particular, we use this definition for SimpleGraph.Path.instFintype.

theorem SimpleGraph.coe_finsetWalkLengthLT_eq E0 #

∀ {V : Type u} (G : SimpleGraph V) [inst : DecidableEq V] [inst_1 : G.LocallyFinite] (n : ℕ) (u v : V),
  ↑(G.finsetWalkLengthLT n u v) = {p | p.length < n}

theorem SimpleGraph.mem_finsetWalkLengthLT_iff E0 #

∀ {V : Type u} {G : SimpleGraph V} [inst : DecidableEq V] [inst_1 : G.LocallyFinite] {n : ℕ} {u v : V} {p : G.Walk u v},
  p ∈ G.finsetWalkLengthLT n u v ↔ p.length < n

instance SimpleGraph.fintypeSetWalkLength E0 #

{V : Type u} →
  (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype ↑{p | p.length = n}

instance SimpleGraph.fintypeSubtypeWalkLength E0 #

{V : Type u} →
  (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype { p // p.length = n }

theorem SimpleGraph.set_walk_length_toFinset_eq E0 #

∀ {V : Type u} (G : SimpleGraph V) [inst : DecidableEq V] [inst_1 : G.LocallyFinite] (n : ℕ) (u v : V),
  {p | p.length = n}.toFinset = G.finsetWalkLength n u v

theorem SimpleGraph.card_set_walk_length_eq E0 #

∀ {V : Type u} (G : SimpleGraph V) [inst : DecidableEq V] [inst_1 : G.LocallyFinite] (u v : V) (n : ℕ),
  Fintype.card ↑{p | p.length = n} = (G.finsetWalkLength n u v).card

See SimpleGraph.adjMatrix_pow_apply_eq_card_walk for the cardinality in terms of the nth power of the adjacency matrix.

instance SimpleGraph.fintypeSetWalkLengthLT E0 #

{V : Type u} →
  (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype ↑{p | p.length < n}

instance SimpleGraph.fintypeSubtypeWalkLengthLT E0 #

{V : Type u} →
  (G : SimpleGraph V) → [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype { p // p.length < n }

instance SimpleGraph.fintypeSetPathLength E0 #

{V : Type u} →
  (G : SimpleGraph V) →
    [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype ↑{p | p.IsPath ∧ p.length = n}

instance SimpleGraph.fintypeSubtypePathLength E0 #

{V : Type u} →
  (G : SimpleGraph V) →
    [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype { p // p.IsPath ∧ p.length = n }

instance SimpleGraph.fintypeSetPathLengthLT E0 #

{V : Type u} →
  (G : SimpleGraph V) →
    [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype ↑{p | p.IsPath ∧ p.length < n}

instance SimpleGraph.fintypeSubtypePathLengthLT E0 #

{V : Type u} →
  (G : SimpleGraph V) →
    [DecidableEq V] → [G.LocallyFinite] → (u v : V) → (n : ℕ) → Fintype { p // p.IsPath ∧ p.length < n }

instance SimpleGraph.Path.instFintype E0 #

{V : Type u} →
  (G : SimpleGraph V) → [DecidableEq V] → [Fintype V] → [DecidableRel G.Adj] → {u v : V} → Fintype (G.Path u v)

Deprecated aliases

NameNew nameSince
SimpleGraph.Walk.setOf_length_eq_add_oneSimpleGraph.Walk.setOfPred_length_eq_add_one2026-07-09
SimpleGraph.Walk.setOf_length_eq_zeroSimpleGraph.Walk.setOfPred_length_eq_zero2026-07-09
SimpleGraph.Walk.setOf_length_eq_zero_of_neSimpleGraph.Walk.setOfPred_length_eq_zero_of_ne2026-07-09
SimpleGraph.set_walk_length_succ_eqSimpleGraph.Walk.setOfPred_length_eq_add_one2026-05-12
SimpleGraph.set_walk_length_zero_eq_of_neSimpleGraph.Walk.setOfPred_length_eq_zero_of_ne2026-05-12
SimpleGraph.set_walk_self_length_zero_eqSimpleGraph.Walk.setOfPred_length_eq_zero2026-05-12