Skip to content

Commit fb6b1ce

Browse files
committed
feat(Combinatorics/SimpleGraph): basic Adj.toWalk API (leanprover-community#41797)
1 parent b300f2c commit fb6b1ce

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

Mathlib/Combinatorics/SimpleGraph/Connectivity/Subgraph.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ theorem mem_edges_toSubgraph (p : G.Walk u v) {e : Sym2 V} :
215215
theorem edgeSet_toSubgraph (p : G.Walk u v) : p.toSubgraph.edgeSet = p.edgeSet :=
216216
Set.ext fun _ => p.mem_edges_toSubgraph
217217

218+
theorem _root_.SimpleGraph.Adj.toSubgraph_toWalk (h : G.Adj u v) :
219+
h.toWalk.toSubgraph = G.subgraphOfAdj h := by
220+
ext <;> simp
221+
218222
@[simp]
219223
theorem toSubgraph_append (p : G.Walk u v) (q : G.Walk v w) :
220224
(p.append q).toSubgraph = p.toSubgraph ⊔ q.toSubgraph := by induction p <;> simp [*, sup_assoc]

Mathlib/Combinatorics/SimpleGraph/Paths.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ theorem IsPath.nil_iff_eq {u v : V} {p : G.Walk u v} (hp : p.IsPath) : p.Nil ↔
211211
rintro rfl
212212
exact isPath_iff_nil.mp hp
213213

214+
theorem _root_.SimpleGraph.Adj.isPath_toWalk (h : G.Adj u v) : h.toWalk.IsPath := by
215+
simp [h.ne]
216+
214217
theorem IsPath.reverse {u v : V} {p : G.Walk u v} (h : p.IsPath) : p.reverse.IsPath := by
215218
simpa [isPath_def] using h
216219

Mathlib/Combinatorics/SimpleGraph/Walk/Basic.lean

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl
9595
theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
9696
(cons h p).length = p.length + 1 := rfl
9797

98+
theorem _root_.SimpleGraph.Adj.length_toWalk (h : G.Adj u v) : h.toWalk.length = 1 := by
99+
simp
100+
98101
theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v
99102
| nil, _ => rfl
100103

@@ -135,6 +138,9 @@ theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl
135138
theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
136139
(cons h p).support = u :: p.support := rfl
137140

141+
theorem _root_.SimpleGraph.Adj.support_toWalk (h : G.Adj u v) : h.toWalk.support = [u, v] :=
142+
rfl
143+
138144
@[simp]
139145
theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp
140146

@@ -225,6 +231,9 @@ theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl
225231
theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
226232
(cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl
227233

234+
theorem _root_.SimpleGraph.Adj.darts_toWalk (h : G.Adj u v) : h.toWalk.darts = [⟨(u, v), h⟩] :=
235+
rfl
236+
228237
theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by
229238
induction p <;> simp [*]
230239

@@ -245,6 +254,9 @@ theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl
245254
theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) :
246255
(cons h p).edges = s(u, v) :: p.edges := rfl
247256

257+
theorem _root_.SimpleGraph.Adj.edges_toWalk (h : G.Adj u v) : h.toWalk.edges = [s(u, v)] :=
258+
rfl
259+
248260
@[simp, grind =]
249261
theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by
250262
induction p <;> simp [*]
@@ -499,10 +511,11 @@ def ofDarts (l : List G.Dart) (hne : l ≠ []) (hchain : l.IsChain G.DartAdj) :
499511
| d₁ :: d₂ :: l =>
500512
.cons (hchain.rel ▸ d₁.adj) <| ofDarts (d₂ :: l) (l.cons_ne_nil d₂) hchain.of_cons
501513

502-
variable (G) in
503514
@[simp]
504-
theorem ofDarts_singleton (d : G.Dart) :
505-
ofDarts [d] ([].cons_ne_nil d) (.singleton d) = .cons d.adj .nil :=
515+
theorem ofDarts_singleton (d : G.Dart) : ofDarts [d] (by simp) (by simp) = .cons d.adj .nil :=
516+
rfl
517+
518+
theorem ofDarts_singleton' (d : G.Dart) : ofDarts [d] (by simp) (by simp) = d.adj.toWalk :=
506519
rfl
507520

508521
@[simp]

Mathlib/Combinatorics/SimpleGraph/Walk/Chord.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ theorem IsChordless.mem_edges {p : G.Walk u v} (h : p.IsChordless) {u' v' : V}
5454
(hu' : u' ∈ p.support) (hv' : v' ∈ p.support) (hadj : G.Adj u' v') : s(u', v') ∈ p.edges :=
5555
isChordless_iff_forall_mem_edges.mp h hu' hv' hadj
5656

57+
theorem _root_.SimpleGraph.Adj.isChordless_toWalk (h : G.Adj u v) : h.toWalk.IsChordless := by
58+
grind [isChordless_iff_forall_mem_edges, h.support_toWalk, h.edges_toWalk, Adj.ne]
59+
5760
end Walk
5861
end SimpleGraph

0 commit comments

Comments
 (0)