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.Metric

74 declarations. Mathlib docs · Source

Graph metric

This module defines the SimpleGraph.edist function, which takes pairs of vertices to the length of the shortest walk between them, or ⊤ if they are disconnected. It also defines SimpleGraph.dist which is the ℕ-valued version of SimpleGraph.edist, and SimpleGraph.ball which is the open ball in the graph extended metric.

Main definitions

  • SimpleGraph.edist is the graph extended metric.
  • SimpleGraph.dist is the graph metric.
  • SimpleGraph.ball is the open ball of a given radius around a vertex.

TODO

  • Provide an additional computable version of SimpleGraph.dist for when G is connected.

  • When directed graphs exist, a directed notion of distance, likely ENat-valued.

Tags

graph metric, distance, ball

Metric

Ball

def SimpleGraph.edist E3 #

{V : Type u_1} → SimpleGraph V → V → V → ℕ∞

The extended distance between two vertices is the length of the shortest walk between them. It is ⊤ if no such walk exists.

theorem SimpleGraph.edist_eq_sInf E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v = sInf (Set.range fun w ↦ ↑w.length)

theorem SimpleGraph.Reachable.exists_walk_length_eq_edist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → ∃ p, ↑p.length = G.edist u v

theorem SimpleGraph.Connected.exists_walk_length_eq_edist E1 #

∀ {V : Type u_1} {G : SimpleGraph V}, G.Connected → ∀ (u v : V), ∃ p, ↑p.length = G.edist u v

theorem SimpleGraph.edist_le E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} (p : G.Walk u v), G.edist u v ≤ ↑p.length

theorem SimpleGraph.Walk.edist_le E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} (p : G.Walk u v), G.edist u v ≤ ↑p.length

Alias of SimpleGraph.edist_le.

theorem SimpleGraph.edist_eq_zero_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v = 0 ↔ u = v

theorem SimpleGraph.edist_self E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {v : V}, G.edist v v = 0

theorem SimpleGraph.edist_pos_of_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, u ≠ v → 0 < G.edist u v

theorem SimpleGraph.edist_eq_top_of_not_reachable E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, ¬G.Reachable u v → G.edist u v = ⊤

theorem SimpleGraph.reachable_of_edist_ne_top E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v ≠ ⊤ → G.Reachable u v

theorem SimpleGraph.exists_walk_of_edist_ne_top E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v ≠ ⊤ → ∃ p, ↑p.length = G.edist u v

theorem SimpleGraph.edist_triangle E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v w : V}, G.edist u w ≤ G.edist u v + G.edist v w

theorem SimpleGraph.edist_comm E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v = G.edist v u

theorem SimpleGraph.exists_walk_of_edist_eq_coe E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} {k : ℕ}, G.edist u v = ↑k → ∃ p, p.length = k

theorem SimpleGraph.edist_ne_top_iff_reachable E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v ≠ ⊤ ↔ G.Reachable u v

theorem SimpleGraph.edist_eq_one_iff_adj E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v = 1 ↔ G.Adj u v

The extended distance between vertices is equal to 1 if and only if these vertices are adjacent.

theorem SimpleGraph.edist_le_one_iff_adj_or_eq E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v ≤ 1 ↔ G.Adj u v ∨ u = v

theorem SimpleGraph.edist_eq_two_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.edist u v = 2 ↔ u ≠ v ∧ ¬G.Adj u v ∧ (G.commonNeighbors u v).Nonempty

theorem SimpleGraph.two_lt_edist_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, 2 < G.edist u v ↔ u ≠ v ∧ ¬G.Adj u v ∧ G.commonNeighbors u v = ∅

theorem SimpleGraph.edist_bot_of_ne E1 #

∀ {V : Type u_1} {u v : V}, u ≠ v → ⊥.edist u v = ⊤

theorem SimpleGraph.edist_bot E1 #

∀ {V : Type u_1} {u v : V} [inst : DecidableEq V], ⊥.edist u v = if u = v then 0 else ⊤

theorem SimpleGraph.edist_top_of_ne E1 #

∀ {V : Type u_1} {u v : V}, u ≠ v → ⊤.edist u v = 1

theorem SimpleGraph.edist_top E1 #

∀ {V : Type u_1} {u v : V} [inst : DecidableEq V], ⊤.edist u v = if u = v then 0 else 1

theorem SimpleGraph.Hom.edist_le E1 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} (f : G →g H) (u v : V),
  H.edist (f u) (f v) ≤ G.edist u v

theorem SimpleGraph.Iso.edist_eq E0 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} (f : G ≃g H) (u v : V),
  H.edist (f u) (f v) = G.edist u v

theorem SimpleGraph.edist_anti E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} {G' : SimpleGraph V}, G ≤ G' → G'.edist u v ≤ G.edist u v

Supergraphs have smaller or equal extended distances to their subgraphs.

def SimpleGraph.dist E3 #

{V : Type u_1} → SimpleGraph V → V → V → ℕ

The distance between two vertices is the length of the shortest walk between them. If no such walk exists, this uses the junk value of 0.

theorem SimpleGraph.dist_eq_sInf E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v = sInf (Set.range SimpleGraph.Walk.length)

theorem SimpleGraph.Reachable.coe_dist_eq_edist E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → ↑(G.dist u v) = G.edist u v

theorem SimpleGraph.Reachable.exists_walk_length_eq_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → ∃ p, p.length = G.dist u v

theorem SimpleGraph.Connected.exists_walk_length_eq_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V}, G.Connected → ∀ (u v : V), ∃ p, p.length = G.dist u v

theorem SimpleGraph.dist_le E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} (p : G.Walk u v), G.dist u v ≤ p.length

theorem SimpleGraph.natCast_dist_le_edist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, ↑(G.dist u v) ≤ G.edist u v

theorem SimpleGraph.dist_eq_zero_iff_eq_or_not_reachable E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v = 0 ↔ u = v ∨ ¬G.Reachable u v

theorem SimpleGraph.dist_self E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {v : V}, G.dist v v = 0

theorem SimpleGraph.Reachable.dist_eq_zero_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → (G.dist u v = 0 ↔ u = v)

theorem SimpleGraph.Reachable.pos_dist_of_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → u ≠ v → 0 < G.dist u v

theorem SimpleGraph.Reachable.one_lt_dist_of_ne_of_not_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → u ≠ v → ¬G.Adj u v → 1 < G.dist u v

theorem SimpleGraph.Connected.dist_eq_zero_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Connected → (G.dist u v = 0 ↔ u = v)

theorem SimpleGraph.Connected.pos_dist_of_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Connected → u ≠ v → 0 < G.dist u v

theorem SimpleGraph.Connected.one_lt_dist_of_ne_of_not_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Connected → u ≠ v → ¬G.Adj u v → 1 < G.dist u v

theorem SimpleGraph.dist_eq_zero_of_not_reachable E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, ¬G.Reachable u v → G.dist u v = 0

theorem SimpleGraph.nonempty_of_pos_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, 0 < G.dist u v → Set.univ.Nonempty

theorem SimpleGraph.Connected.dist_triangle E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v w : V}, G.Connected → G.dist u w ≤ G.dist u v + G.dist v w

theorem SimpleGraph.Reachable.dist_triangle_left E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → ∀ (w : V), G.dist u w ≤ G.dist u v + G.dist v w

theorem SimpleGraph.Reachable.dist_triangle_right E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V}, G.Reachable v w → ∀ (u : V), G.dist u w ≤ G.dist u v + G.dist v w

theorem SimpleGraph.dist_comm E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v = G.dist v u

theorem SimpleGraph.dist_ne_zero_iff_ne_and_reachable E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v ≠ 0 ↔ u ≠ v ∧ G.Reachable u v

theorem SimpleGraph.Reachable.of_dist_ne_zero E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v ≠ 0 → G.Reachable u v

theorem SimpleGraph.exists_walk_of_dist_ne_zero E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v ≠ 0 → ∃ p, p.length = G.dist u v

theorem SimpleGraph.dist_eq_one_iff_adj E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.dist u v = 1 ↔ G.Adj u v

The distance between vertices is equal to 1 if and only if these vertices are adjacent.

theorem SimpleGraph.Adj.diff_dist_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v w : V},
  G.Adj v w → G.dist u w = G.dist u v ∨ G.dist u w = G.dist u v + 1 ∨ G.dist u w = G.dist u v - 1

theorem SimpleGraph.Walk.isPath_of_length_eq_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} (p : G.Walk u v), p.length = G.dist u v → p.IsPath

theorem SimpleGraph.Reachable.exists_path_of_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V}, G.Reachable u v → ∃ p, p.IsPath ∧ p.length = G.dist u v

theorem SimpleGraph.Connected.exists_path_of_dist E1 #

∀ {V : Type u_1} {G : SimpleGraph V}, G.Connected → ∀ (u v : V), ∃ p, p.IsPath ∧ p.length = G.dist u v

theorem SimpleGraph.dist_bot E0 #

∀ {V : Type u_1} {u v : V}, ⊥.dist u v = 0

theorem SimpleGraph.dist_top_of_ne E1 #

∀ {V : Type u_1} {u v : V}, u ≠ v → ⊤.dist u v = 1

theorem SimpleGraph.dist_top E1 #

∀ {V : Type u_1} {u v : V} [inst : DecidableEq V], ⊤.dist u v = if u = v then 0 else 1

theorem SimpleGraph.length_eq_dist_of_subwalk E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v u' v' : V} {p₁ : G.Walk u v} {p₂ : G.Walk u' v'},
  p₁.length = G.dist u v → p₂.IsSubwalk p₁ → p₂.length = G.dist u' v'

theorem SimpleGraph.Hom.dist_le E1 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} {u v : V} (f : G →g H),
  G.Reachable u v → H.dist (f u) (f v) ≤ G.dist u v

theorem SimpleGraph.Iso.dist_eq E0 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} (f : G ≃g H) (u v : V),
  H.dist (f u) (f v) = G.dist u v

theorem SimpleGraph.Reachable.dist_anti E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} {G' : SimpleGraph V}, G ≤ G' → G.Reachable u v → G'.dist u v ≤ G.dist u v

Supergraphs have smaller or equal distances to their subgraphs.

theorem SimpleGraph.Walk.exists_adj_adj_not_adj_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V} {p : G.Walk v w},
  p.length = G.dist v w → 1 < G.dist v w → ∃ x a b, G.Adj x a ∧ G.Adj a b ∧ ¬G.Adj x b ∧ x ≠ b

This bundles and abstracts some facts about the first three vertices of a shortest walk of length at least two: the first and third nodes are different and not connected.

def SimpleGraph.ball E3 #

{V : Type u_1} → SimpleGraph V → V → ℕ∞ → Set V

The open ball of radius r centered at the vertex c in the graph extended metric.

theorem SimpleGraph.mem_ball E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c v : V} {r : ℕ∞}, v ∈ G.ball c r ↔ G.edist v c < r

theorem SimpleGraph.ball_zero E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V}, G.ball c 0 = ∅

The ball of radius zero is empty.

theorem SimpleGraph.ball_one E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V}, G.ball c 1 = {c}

The ball of radius one consists of just the center.

theorem SimpleGraph.ball_two E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V}, G.ball c 2 = insert c (G.neighborSet c)

The ball of radius two consists of the center and its neighbors.

theorem SimpleGraph.ball_top E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V}, G.ball c ⊤ = (G.connectedComponentMk c).supp

The ball of radius ⊤ is the connected component of the center.

theorem SimpleGraph.mem_ball_top E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c v : V}, v ∈ G.ball c ⊤ ↔ G.Reachable v c

A vertex is in the ball of radius ⊤ iff it is reachable from the center.

theorem SimpleGraph.ball_mono E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V} {r₁ r₂ : ℕ∞}, r₁ ≤ r₂ → G.ball c r₁ ⊆ G.ball c r₂

Balls are monotone in the radius.

theorem SimpleGraph.mem_ball_self E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c : V} {r : ℕ∞}, 0 < r → c ∈ G.ball c r

The center vertex belongs to any ball of positive radius.

theorem SimpleGraph.mem_ball_comm E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {c v : V} {r : ℕ∞}, v ∈ G.ball c r ↔ c ∈ G.ball v r

Ball membership is symmetric in center and point.