@@ -4,32 +4,44 @@ Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Nelson Spence
55-/
66import Mathlib.Combinatorics.SimpleGraph.Metric
7- import Mathlib.Combinatorics.SimpleGraph.Finite
87
98set_option relaxedAutoImplicit false
109set_option autoImplicit false
1110
1211/-!
1312# Metric balls for simple graphs
1413
15- This file defines the metric ball `SimpleGraph.ball` using the extended
16- distance `SimpleGraph.edist`. Using `edist` (rather than `dist`) ensures
17- that disconnected vertices, which are at distance `⊤`, are correctly
18- excluded from finite-radius balls.
14+ This file defines the open metric ball `SimpleGraph.ball` using the extended
15+ distance `SimpleGraph.edist`, following the convention of `Metric.ball`.
16+
17+ Using strict inequality (`<`) gives the natural property that `ball c ⊤`
18+ equals the support of the connected component containing `c`.
1919
2020## Main definitions
2121
22- - `SimpleGraph.ball` — the set of vertices within extended distance `r`
23- of a center vertex
22+ - `SimpleGraph.ball` — the set of vertices within extended distance strictly
23+ less than `r` of a center vertex
2424
2525 ## Main statements
2626
2727- `SimpleGraph.mem_ball` — membership characterization
28+ - `SimpleGraph.ball_zero` — the zero-radius ball is empty
29+ - `SimpleGraph.ball_one` — the unit ball is `{c}`
30+ - `SimpleGraph.ball_top` — the `⊤`-radius ball is the connected component
2831- `SimpleGraph.ball_mono` — monotonicity in radius
29- - `SimpleGraph.ball_zero` — the zero-radius ball is `{c}`
30- - `SimpleGraph.ball_top` — the `⊤`-radius ball is `Set.univ`
31- - `SimpleGraph.ball_comm` — `v ∈ G.ball c r ↔ c ∈ G.ball v r`
32- - `SimpleGraph.ball_anti` — supergraphs have larger balls
32+ - `SimpleGraph.center_mem_ball` — center belongs to any positive-radius ball
33+ - `SimpleGraph.mem_ball_comm` — membership is symmetric in center and point
34+
35+ ## Implementation notes
36+
37+ The definition uses `ℕ∞` radius to match `SimpleGraph.edist`. For finite
38+ `n : ℕ`, `G.ball c (n + 1)` is the closed ball of radius `n` in the usual
39+ sense (vertices at distance `≤ n`), since `edist c v < n + 1 ↔ edist c v ≤ n`
40+ for natural numbers.
41+
42+ ## References
43+
44+ * `Mathlib.Combinatorics.SimpleGraph.Metric`
3345
3446 ## Tags
3547
@@ -40,80 +52,104 @@ namespace SimpleGraph
4052
4153variable {V : Type *} (G : SimpleGraph V)
4254
43- /-! ### Definition and membership -/
44-
45- /-- The closed ball of radius `r` around vertex `c` in the graph extended metric. -/
55+ /-- The open ball of radius `r` around vertex `c` in the graph extended metric. -/
4656def ball (c : V) (r : ℕ∞) : Set V :=
47- {v | G.edist c v ≤ r}
57+ {v | G.edist c v < r}
4858
4959variable {G}
5060
5161@[simp]
5262theorem mem_ball {c v : V} {r : ℕ∞} :
53- v ∈ G.ball c r ↔ G.edist c v ≤ r :=
63+ v ∈ G.ball c r ↔ G.edist c v < r :=
5464 Iff.rfl
5565
56- theorem edist_le_of_mem_ball {c v : V} {r : ℕ∞} (h : v ∈ G.ball c r) :
57- G.edist c v ≤ r :=
58- h
59-
60- /-! ### Radius extremes -/
66+ @[simp]
67+ theorem ball_zero {c : V} : G.ball c 0 = ∅ := by
68+ ext v; simp [ball]
6169
6270@[simp]
63- theorem ball_zero {c : V} : G.ball c 0 = {c} := by
71+ theorem ball_one {c : V} : G.ball c 1 = {c} := by
6472 ext v
65- simp [ball, nonpos_iff_eq_zero]
73+ simp only [mem_ball, Set.mem_singleton_iff]
74+ constructor
75+ · intro h
76+ have h0 : G.edist c v = 0 := by
77+ have hne : G.edist c v ≠ ⊤ := ne_top_of_lt h
78+ lift G.edist c v to ℕ using hne with d
79+ have : d < 1 := by exact_mod_cast h
80+ exact_mod_cast (show d = 0 from by omega)
81+ exact (edist_eq_zero_iff.mp h0).symm
82+ · rintro rfl; simp
6683
6784@[simp]
68- theorem ball_top {c : V} : G.ball c ⊤ = Set.univ := by
85+ theorem ball_top {c : V} :
86+ G.ball c ⊤ = (G.connectedComponentMk c).supp := by
6987 ext v
70- simp [ball]
71-
72- /-! ### Monotonicity -/
88+ simp only [mem_ball, ConnectedComponent.mem_supp_iff]
89+ constructor
90+ · intro h
91+ exact (ConnectedComponent.eq.mpr
92+ (reachable_of_edist_ne_top (ne_top_of_lt h))).symm
93+ · intro h
94+ exact lt_top_iff_ne_top.mpr
95+ (edist_ne_top_iff_reachable.mpr (ConnectedComponent.eq.mp h.symm))
7396
7497/-- Balls are monotone in the radius. -/
7598theorem ball_mono {c : V} {r₁ r₂ : ℕ∞} (h : r₁ ≤ r₂) :
7699 G.ball c r₁ ⊆ G.ball c r₂ :=
77- fun _ hv ↦ le_trans hv h
78-
79- /-- Supergraphs have larger or equal balls. -/
80- @[gcongr]
81- theorem ball_anti {G' : SimpleGraph V} {c : V} {r : ℕ∞} (h : G ≤ G') :
82- G.ball c r ⊆ G'.ball c r :=
83- fun _ hv ↦ le_trans (edist_anti h) hv
100+ fun _ hv ↦ lt_of_lt_of_le hv h
84101
85- /-! ### Center and symmetry -/
86-
87- /-- The center vertex belongs to any ball around it. -/
88- theorem center_mem_ball {c : V} {r : ℕ∞} :
102+ /-- The center vertex belongs to any ball of positive radius. -/
103+ theorem center_mem_ball {c : V} {r : ℕ∞} (hr : 0 < r) :
89104 c ∈ G.ball c r := by
90- simp [ball]
91-
92- theorem ball_nonempty {c : V} {r : ℕ∞} : (G.ball c r).Nonempty :=
93- ⟨c, center_mem_ball⟩
105+ simp [ball, hr]
94106
95107/-- Ball membership is symmetric in center and point. -/
96- theorem ball_comm {c v : V} {r : ℕ∞} :
108+ theorem mem_ball_comm {c v : V} {r : ℕ∞} :
97109 v ∈ G.ball c r ↔ c ∈ G.ball v r := by
98110 simp [ball, edist_comm]
99111
100- /-! ### Adjacency -/
112+ /-! ### Convenience lemmas (not in first upstream PR) -/
101113
102- theorem ball_one_eq {c : V} :
103- G.ball c 1 = {v | G. edist c v ≤ 1 } :=
104- rfl
114+ theorem edist_lt_of_mem_ball {c v : V} {r : ℕ∞} (h : v ∈ G.ball c r) :
115+ G.edist c v < r :=
116+ h
105117
106- theorem adj_of_mem_ball_one {c v : V} (h : v ∈ G.ball c 1 ) (hne : c ≠ v) :
107- G.Adj c v := by
108- rw [mem_ball] at h
109- exact (edist_le_one_iff_adj_or_eq.mp h).resolve_right hne
118+ theorem ball_nonempty {c : V} {r : ℕ∞} (hr : 0 < r) : (G.ball c r).Nonempty :=
119+ ⟨c, center_mem_ball hr⟩
110120
111- /-! ### Triangle inequality -/
121+ /-- Supergraphs have larger or equal balls. -/
122+ @[gcongr]
123+ theorem ball_anti {G' : SimpleGraph V} {c : V} {r : ℕ∞} (h : G ≤ G') :
124+ G.ball c r ⊆ G'.ball c r :=
125+ fun _ hv ↦ lt_of_le_of_lt (edist_anti h) hv
126+
127+ /-- Vertices adjacent to `c` are in the ball of radius 2. -/
128+ theorem mem_ball_of_adj {c v : V} (h : G.Adj c v) :
129+ v ∈ G.ball c 2 := by
130+ simp only [mem_ball]
131+ have h1 : (1 : ℕ∞) < 2 := by exact_mod_cast (show (1 : ℕ) < 2 from by omega)
132+ exact lt_of_le_of_lt (edist_le_one_iff_adj_or_eq.mpr (Or.inl h)) h1
133+
134+ theorem adj_of_mem_ball_two {c v : V} (h : v ∈ G.ball c 2 ) (hne : c ≠ v) :
135+ G.Adj c v := by
136+ simp only [mem_ball] at h
137+ have hle : G.edist c v ≤ 1 := by
138+ have hne_top : G.edist c v ≠ ⊤ := ne_top_of_lt h
139+ lift G.edist c v to ℕ using hne_top with d
140+ have : d < 2 := by exact_mod_cast h
141+ exact_mod_cast (show d ≤ 1 from by omega)
142+ exact (edist_le_one_iff_adj_or_eq.mp hle).resolve_right hne
112143
113144/-- If `v ∈ ball c r₁` and `w ∈ ball v r₂`, then `w ∈ ball c (r₁ + r₂)`. -/
114145theorem mem_ball_of_mem_ball_of_mem_ball {c v w : V} {r₁ r₂ : ℕ∞}
115146 (hv : v ∈ G.ball c r₁) (hw : w ∈ G.ball v r₂) :
116- w ∈ G.ball c (r₁ + r₂) :=
117- le_trans G.edist_triangle (add_le_add hv hw)
147+ w ∈ G.ball c (r₁ + r₂) := by
148+ simp only [mem_ball] at *
149+ have hw_ne : G.edist v w ≠ ⊤ := ne_top_of_lt hw
150+ calc G.edist c w
151+ ≤ G.edist c v + G.edist v w := G.edist_triangle
152+ _ < r₁ + G.edist v w := (ENat.add_lt_add_iff_right hw_ne).mpr hv
153+ _ ≤ r₁ + r₂ := by gcongr
118154
119155end SimpleGraph
0 commit comments