Skip to content

Commit 970ca71

Browse files
committed
feat(Combinatorics/SimpleGraph/Walk): relate edges and darts (leanprover-community#41720)
1 parent 169c26b commit 970ca71

3 files changed

Lines changed: 26 additions & 29 deletions

File tree

Mathlib/Combinatorics/SimpleGraph/Connectivity/Subgraph.lean

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -281,42 +281,18 @@ theorem toSubgraph_adj_penultimate {u v} (w : G.Walk u v) (h : ¬ w.Nil) :
281281
simpa [show w.length - 1 + 1 = w.length by lia]
282282
using w.toSubgraph_adj_getVert (by lia : w.length - 1 < w.length)
283283

284+
lemma adj_toSubgraph_iff_mem_edges {u v u' v' : V} {p : G.Walk u v} :
285+
p.toSubgraph.Adj u' v' ↔ s(u', v') ∈ p.edges := by
286+
rw [← mem_edges_toSubgraph, Subgraph.mem_edgeSet]
287+
284288
theorem toSubgraph_adj_iff {u v u' v'} (w : G.Walk u v) :
285289
w.toSubgraph.Adj u' v' ↔ ∃ i, s(w.getVert i, w.getVert (i + 1)) =
286290
s(u', v') ∧ i < w.length := by
287-
constructor
288-
· intro hadj
289-
unfold Walk.toSubgraph at hadj
290-
match w with
291-
| .nil =>
292-
simp only [singletonSubgraph_adj, Pi.bot_apply, Prop.bot_eq_false] at hadj
293-
| .cons h p =>
294-
simp only [Subgraph.sup_adj, subgraphOfAdj_adj, Sym2.eq, Sym2.rel_iff', Prod.mk.injEq,
295-
Prod.swap_prod_mk] at hadj
296-
cases hadj with
297-
| inl hl =>
298-
use 0
299-
simp only [Walk.getVert_zero, zero_add, getVert_cons_succ]
300-
refine ⟨?_, by simp only [length_cons, Nat.zero_lt_succ]⟩
301-
exact Sym2.eq_iff.mpr hl
302-
| inr hr =>
303-
obtain ⟨i, hi⟩ := (toSubgraph_adj_iff _).mp hr
304-
use i + 1
305-
simp only [getVert_cons_succ]
306-
constructor
307-
· exact hi.1
308-
· simp only [Walk.length_cons, Nat.add_lt_add_right hi.2 1]
309-
· rintro ⟨i, hi⟩
310-
rw [← Subgraph.mem_edgeSet, ← hi.1, Subgraph.mem_edgeSet]
311-
exact toSubgraph_adj_getVert _ hi.2
291+
grind [adj_toSubgraph_iff_mem_edges, mk_mem_edges_iff_exists]
312292

313293
lemma mem_support_of_adj_toSubgraph {u v u' v' : V} {p : G.Walk u v} (hp : p.toSubgraph.Adj u' v') :
314294
u' ∈ p.support := p.mem_verts_toSubgraph.mp (p.toSubgraph.edge_vert hp)
315295

316-
lemma adj_toSubgraph_iff_mem_edges {u v u' v' : V} {p : G.Walk u v} :
317-
p.toSubgraph.Adj u' v' ↔ s(u', v') ∈ p.edges := by
318-
rw [← p.mem_edges_toSubgraph, Subgraph.mem_edgeSet]
319-
320296
theorem toSubgraph_le_iff {w : G.Walk u v} (hnil : ¬w.Nil) {G' : G.Subgraph} :
321297
w.toSubgraph ≤ G' ↔ w.edgeSet ⊆ G'.edgeSet := by
322298
refine ⟨fun hw e he ↦ Subgraph.edgeSet_mono hw <| w.mem_edges_toSubgraph.mpr he, fun hw ↦ ?_⟩

Mathlib/Combinatorics/SimpleGraph/Walk/Basic.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def darts {u v : V} : G.Walk u v → List G.Dart
125125
This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/
126126
def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge
127127

128+
theorem edges_eq_map_darts (p : G.Walk u v) : p.edges = p.darts.map Dart.edge :=
129+
rfl
130+
128131
@[simp]
129132
theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl
130133

@@ -253,6 +256,16 @@ theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := b
253256
@[simp, grind =]
254257
theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges]
255258

259+
/-- Use `edge_getElem_darts` to rewrite in the reverse direction. -/
260+
theorem getElem_edges_eq_edge_getElem_darts {p : G.Walk u v} {i : ℕ} (h : i < p.edges.length) :
261+
p.edges[i] = (p.darts[i]'(by grind)).edge :=
262+
List.getElem_map ..
263+
264+
/-- Use `getElem_edges_eq_edge_getElem_darts` to rewrite in the reverse direction. -/
265+
theorem edge_getElem_darts {p : G.Walk u v} {i : ℕ} (h : i < p.darts.length) :
266+
p.darts[i].edge = p.edges[i]'(by grind) := by
267+
rw [getElem_edges_eq_edge_getElem_darts]
268+
256269
@[simp]
257270
theorem fst_darts_getElem {p : G.Walk u v} {i : ℕ} (hi : i < p.darts.length) :
258271
p.darts[i].fst = p.support.dropLast[i]'(by grind) := by

Mathlib/Combinatorics/SimpleGraph/Walk/Traversal.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ theorem darts_getElem_eq_getVert {u v : V} {p : G.Walk u v} (n : ℕ) (h : n < p
129129
rw [p.length_darts] at h
130130
ext <;> simp [p.getVert_eq_support_getElem (le_of_lt h), p.getVert_eq_support_getElem h]
131131

132+
theorem getElem_edges {p : G.Walk u v} {i : ℕ} (h : i < p.edges.length) :
133+
p.edges[i] = s(p.getVert i, p.getVert (i + 1)) := by
134+
simp [getElem_edges_eq_edge_getElem_darts, darts_getElem_eq_getVert]
135+
136+
theorem mk_mem_edges_iff_exists {u' v' : V} (p : G.Walk u v) :
137+
s(u', v') ∈ p.edges ↔ ∃ i < p.length, s(p.getVert i, p.getVert (i + 1)) = s(u', v') := by
138+
constructor <;> grind [getElem_edges, List.mem_iff_getElem]
139+
132140
theorem adj_of_infix_support {u v u' v'} {p : G.Walk u v} (h : [u', v'] <:+: p.support) :
133141
G.Adj u' v' := by
134142
have ⟨k, hk, h⟩ := List.infix_iff_getElem?.mp h

0 commit comments

Comments
 (0)