Skip to content

Commit a624dbd

Browse files
committed
feat(SimpleGraph): distance equal or greater than two in terms of common neighborhood (leanprover-community#35657)
Two lemmas classifying distances between two vertices according two their common neighborhood. This is the fork version of leanprover-community#12278.
1 parent 3493289 commit a624dbd

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Mathlib/Combinatorics/SimpleGraph/Metric.lean

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,36 @@ lemma edist_le_one_iff_adj_or_eq : G.edist u v ≤ 1 ↔ G.Adj u v ∨ u = v :=
145145
rw [(Order.one_le_iff_pos.mpr h).ge_iff_eq']
146146
exact edist_eq_one_iff_adj
147147

148+
lemma edist_eq_two_iff {u v : V} :
149+
G.edist u v = 2 ↔ u ≠ v ∧ ¬ G.Adj u v ∧ (G.commonNeighbors u v).Nonempty := by
150+
refine ⟨fun h ↦ ⟨?_, ?_, ?_⟩, fun h ↦ le_antisymm ?_ ?_⟩
151+
· simp +decide [← G.edist_eq_zero_iff.not (b := u = v), h]
152+
· simp +decide [← edist_eq_one_iff_adj, h]
153+
· obtain ⟨w, hw⟩ := exists_walk_of_edist_eq_coe h
154+
use w.getVert 1
155+
suffices w.getVert 1 ∈ G.commonNeighbors (w.getVert 0) (w.getVert w.length) by simpa
156+
refine hw ▸ G.mem_commonNeighbors.mp ?_
157+
exact ⟨w.adj_getVert_succ (by simp [hw]), (w.adj_getVert_succ (by simp [hw])).symm⟩
158+
· obtain ⟨w, hw⟩ := h.2.2
159+
rw [mem_commonNeighbors] at hw
160+
have := (Walk.cons hw.1 <| .cons hw.2.symm .nil).edist_le
161+
simp_all
162+
· by_contra! hc
163+
cases ENat.le_one_iff_eq_zero_or_eq_one.mp (Order.le_of_lt_succ hc) <;> simp_all
164+
165+
lemma two_lt_edist_iff {u v : V} :
166+
2 < G.edist u v ↔ u ≠ v ∧ ¬ G.Adj u v ∧ (G.commonNeighbors u v) = ∅ := by
167+
refine ⟨fun h ↦ ?_, fun h ↦ lt_of_le_of_ne ?_ (Ne.symm ?_)⟩
168+
· have hn : u ≠ v := fun hc ↦ by simp [hc] at h
169+
have : ¬ G.Adj u v := fun hc ↦ by simp +decide [edist_eq_one_iff_adj.mpr hc] at h
170+
use hn, this
171+
by_contra! hc
172+
simp [edist_eq_two_iff.mpr ⟨hn, this, hc⟩] at h
173+
· rw [← one_add_one_eq_two]
174+
refine Order.add_one_le_of_lt <| lt_of_le_of_ne ?_ ?_
175+
<;> grind [Order.one_le_iff_pos, pos_iff_ne_zero, edist_eq_zero_iff, edist_eq_one_iff_adj]
176+
· simp_all [edist_eq_two_iff]
177+
148178
lemma edist_bot_of_ne (h : u ≠ v) : (⊥ : SimpleGraph V).edist u v = ⊤ := by
149179
rwa [ne_eq, ← reachable_bot.not, ← edist_ne_top_iff_reachable.not, not_not] at h
150180

Mathlib/Data/ENat/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ theorem one_le_iff_ne_zero : 1 ≤ n ↔ n ≠ 0 :=
303303
lemma lt_one_iff_eq_zero : n < 1 ↔ n = 0 :=
304304
not_le.symm.trans one_le_iff_ne_zero.not_left
305305

306+
lemma le_one_iff_eq_zero_or_eq_one : n ≤ 1 ↔ n = 0 ∨ n = 1 := by
307+
refine ⟨fun h ↦ ?_, fun h ↦ by cases h <;> simp_all⟩
308+
cases n
309+
· simp at h
310+
· rwa [← lt_one_iff_eq_zero, ← le_iff_lt_or_eq]
311+
306312
theorem lt_add_one_iff (hm : n ≠ ⊤) : m < n + 1 ↔ m ≤ n :=
307313
Order.lt_add_one_iff_of_not_isMax (not_isMax_iff_ne_top.mpr hm)
308314

0 commit comments

Comments
 (0)