forked from leanprover-community/mathlib
/
aux.lean
291 lines (235 loc) · 10.5 KB
/
aux.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import combinatorics.simple_graph.connectivity
import combinatorics.simple_graph.basic
open function classical
namespace simple_graph
variables {V : Type*} {G : simple_graph V} {u v: V}
namespace walk
local attribute [instance] classical.prop_decidable
@[simp] noncomputable def substitute : Π {u v : V} (p : G.walk u v) {x y : V}
(r : G.walk x y) (h : (⟦⟨x,y⟩⟧ : sym2 V) ∉ r.edges), G.walk u v
| _ _ walk.nil _ _ _ _ := walk.nil
| _ _ (walk.cons' u v w a p) x y r h :=
if fwd : x = u ∧ y = v then by
{ rw ←fwd.1, let p' := p.substitute r h, rw ←fwd.2 at p', exact r.append p', }
else if bwd : x = v ∧ y = u then by
{ rw ←bwd.2, let p' := p.substitute r h, rw ←bwd.1 at p', exact r.reverse.append p', }
else
walk.cons a (p.substitute r h)
lemma substitute_edge_not_mem {u v : V} (p : G.walk u v) {x y : V}
(r : G.walk x y) (h : (⟦⟨x,y⟩⟧ : sym2 V) ∉ r.edges) :
(⟦⟨x,y⟩⟧ : sym2 V) ∉ (p.substitute r h).edges :=
begin
induction p,
{ simp only [substitute, edges_nil, list.not_mem_nil, not_false_iff], },
{ dsimp only [substitute],
split_ifs with fwd bwd,
{ rcases fwd with ⟨rfl,rfl⟩,
simp only [eq_mp_eq_cast, cast_eq, eq_mpr_eq_cast, edges_append, list.mem_append],
push_neg,
exact ⟨h,p_ih,⟩ },
{ rcases bwd with ⟨rfl,rfl⟩,
simp only [eq_mp_eq_cast, cast_eq, eq_mpr_eq_cast, edges_append, edges_reverse,
list.mem_append, list.mem_reverse],
push_neg,
exact ⟨h, p_ih⟩, },
{ simp only [edges_cons, list.mem_cons_iff, quotient.eq, sym2.rel_iff],
rintro ((fwd'|bwd')|r),
exact fwd fwd', exact bwd bwd',
exact p_ih r, }, },
end
lemma cons_is_cycle_iff {u v : V} (p : G.walk v u) (h : G.adj u v) :
(p.cons h).is_cycle ↔ p.is_path ∧ ¬ ⟦(u, v)⟧ ∈ p.edges :=
begin
split,
{ simp only [walk.is_cycle_def, walk.cons_is_trail_iff, ne.def, not_false_iff, walk.support_cons,
list.tail_cons, true_and, simple_graph.walk.is_path_def],
tauto, },
{ exact λ ⟨hp,he⟩, path.cons_is_cycle (⟨p,hp⟩ : G.path v u) h he, },
end
end walk
namespace walk
@[simp] def induce : Π {u v : V} (p : G.walk u v) {H : simple_graph V}
(h : ∀ e, e ∈ p.edges → e ∈ H.edge_set), H.walk u v
| _ _ (walk.nil) H h := walk.nil
| _ _ (walk.cons a p) H h := by
{ refine walk.cons _ (p.induce _);
simp only [walk.edges_cons, list.mem_cons_iff, forall_eq_or_imp, mem_edge_set] at h,
exact h.1, exact h.2, }
variables (w : V) (p : G.walk u v)
{H : simple_graph V} (h : ∀ e, e ∈ p.edges → e ∈ H.edge_set)
lemma induce_id : p.induce (λ e ep, edges_subset_edge_set p ep) = p := by
{ induction p,
simp only [induce],
simp only [p_ih, induce, eq_self_iff_true, heq_iff_eq, and_self], }
abbreviation induce_le (GH : G ≤ H) : H.walk u v :=
p.induce (λ e ep, edge_set_mono GH (edges_subset_edge_set p ep))
lemma induce_eq_map_spanning_subgraphs (GH : G ≤ H) :
p.induce h = p.map (simple_graph.hom.map_spanning_subgraphs GH) := by
{ induction p,
simp only [induce, map_nil],
simp only [p_ih, induce, map_cons, hom.map_spanning_subgraphs_apply, eq_self_iff_true,
heq_iff_eq, and_self], }
@[simp] lemma induce_edges : (p.induce h).edges = p.edges := by
{ induction p,
simp only [induce, edges_nil],
simp only [p_ih, induce, edges_cons, eq_self_iff_true, and_self], }
@[simp] lemma induce_support : (p.induce h).support = p.support := by
{ induction p,
simp only [induce, support_nil, eq_self_iff_true, and_self],
simp only [p_ih, induce, support_cons, eq_self_iff_true, and_self], }
lemma is_path_induce (hp : p.is_path) : (p.induce h).is_path := by
{ induction p,
simp only [induce, is_path.nil],
simp only [cons_is_path_iff, induce, induce_support] at hp ⊢,
simp only [p_ih, hp, not_false_iff, and_self], }
def is_cycle_induce {u : V} (p : G.walk u u) {H : simple_graph V}
(h : ∀ e, e ∈ p.edges → e ∈ H.edge_set) (hp : p.is_cycle) : (p.induce h).is_cycle := by
{ cases p,
{ simp only [induce, is_cycle.not_of_nil] at hp ⊢, exact hp, },
{ simp only [cons_is_cycle_iff, induce, induce_edges] at hp ⊢,
refine ⟨_,hp.right⟩,
apply is_path_induce,
exact hp.left, }, }
abbreviation is_cycle_induce_le {u : V} (p : G.walk u u) {H : simple_graph V}
(GH : G ≤ H) (hp : p.is_cycle) :=
p.is_cycle_induce (λ e ep, edge_set_mono GH (edges_subset_edge_set p ep)) hp
lemma induce_comp {K : simple_graph V} (k : ∀ e, e ∈ p.edges → e ∈ K.edge_set) :
(p.induce h).induce (by {rw p.induce_edges, exact k, }) = p.induce k := by
{ induction p,
simp only [induce],
simp only [induce, eq_self_iff_true, heq_iff_eq, true_and],
apply p_ih, }
@[simp] lemma induce_append (q : G.walk v w) (hq : ∀ e, e ∈ q.edges → e ∈ H.edge_set) :
(p.append q).induce (by { rintro e, simp only [edges_append, list.mem_append], rintro (ep|eq), exact h e ep, exact hq e eq, }) =
(p.induce h).append (q.induce hq) := by
{ induction p,
simp only [induce, nil_append],
simp only [walk.cons_append, induce, eq_self_iff_true, heq_iff_eq, true_and],
apply p_ih, }
@[simp] lemma induce_reverse :
p.reverse.induce (by {simp [edges_reverse, list.mem_reverse], exact h})
= (p.induce h).reverse := by
{ induction p,
simp only [induce, reverse_nil],
simp only [induce, reverse_cons],
rw [induce_append, p_ih], refl,
simp only [edges_cons, list.mem_cons_iff, forall_eq_or_imp, mem_edge_set] at h,
simp only [edges_cons, edges_nil, list.mem_singleton, forall_eq, mem_edge_set],
exact (h.left).symm, }
abbreviation to_delete_edges' (s : set (sym2 V)) (hp : ∀ e, e ∈ p.edges → ¬ e ∈ s) :
(G.delete_edges s).walk u v :=
p.induce (by
{ simp only [edge_set_delete_edges, set.mem_diff],
exact λ e ep, ⟨edges_subset_edge_set p ep, hp e ep⟩, })
end walk
section add_delete_edges
lemma delete_edges_eq_iff (s : set (sym2 V)) :
G.delete_edges s = G ↔ disjoint s G.edge_set :=
begin
split,
{ rintro h ⟨u,v⟩ ⟨es,eG⟩,
rw ←h at eG, obtain ⟨eG',es'⟩ := eG,
exact es' es, },
{ rintro h, ext u v, split,
exact λ x, x.left,
rintro a, refine ⟨a,_⟩,
rintro es, refine h ⟨es,a⟩, },
end
lemma delete_edge_eq_iff (u v) : G.delete_edges {⟦⟨u,v⟩⟧} = G ↔ ¬ G.adj u v :=
by { simp only [delete_edges_eq_iff, set.disjoint_singleton_left, mem_edge_set]}
def add_edges (G : simple_graph V) (s : set (sym2 V)) : simple_graph V :=
{ adj := λ a b, G.adj a b ∨ (a ≠ b) ∧ sym2.to_rel s a b,
symm := λ a b, by
{ rintro (l|⟨ne,r⟩),
{ exact or.inl l.symm, } ,
{ apply or.inr, exact ⟨ne.symm,(sym2.to_rel_symmetric s r)⟩ } },
loopless := λ a, by
{ rintro (l|⟨ne,r⟩), { exact G.loopless a l, }, { exact ne rfl }, } }
lemma le_add_edges (G : simple_graph V) (s : set (sym2 V)) : G ≤ (G.add_edges s) := by
{ rintros a b h, exact or.inl h, }
lemma add_edges_le (G T: simple_graph V) (s : set (sym2 V)) :
G ≤ T → s ⊆ T.edge_set → G.add_edges s ≤ T :=
begin
rintros GT sT,
rintros u v (a|⟨ne,es⟩),
{ exact GT a, },
{ exact sT es, },
end
lemma le_delete_edges (G B : simple_graph V) (s : set (sym2 V)) :
B ≤ G → disjoint s B.edge_set → B ≤ G.delete_edges s :=
begin
rintro BG sB x y a,
exact ⟨BG a, λ as, sB ⟨as,a⟩⟩,
end
lemma add_edge_adj (u v) (h : u ≠ v) : (G.add_edges {⟦⟨u,v⟩⟧}).adj u v := or.inr ⟨h,rfl⟩
lemma add_edges_eq_iff (s : set (sym2 V)) :
G.add_edges s = G ↔ (∀ u v, u ≠ v → ((⟦⟨u,v⟩⟧ : sym2 V) ∈ s) → G.adj u v) :=
begin
split,
{ rintro GseG u v unev uvs, rw ←GseG, right, exact ⟨unev, uvs⟩, },
{ rintro h, ext, dsimp [add_edges], simp only [or_iff_left_iff_imp, and_imp], apply h, },
end
lemma add_edge_eq_iff (u v) (h : u ≠ v) : G.add_edges {⟦⟨u,v⟩⟧} = G ↔ G.adj u v :=
begin
simp [add_edges_eq_iff],
split,
{ rintros h', exact h' u v h (by simp), },
{ rintro h' u v hn (⟨rfl,rfl⟩|⟨rfl,rfl⟩), exact h', exact h'.symm, },
end
lemma add_edge_hom_not_edges (u v) (h : u ≠ v) (h' : ¬ G.adj u v)
{x y : V} (p : G.path x y) :
(⟦⟨u,v⟩⟧ : sym2 V) ∉
((simple_graph.path.map
(simple_graph.hom.map_spanning_subgraphs (le_add_edges G {⟦⟨u,v⟩⟧}))
(function.injective_id) p)).val.edges :=
begin
simp only [subtype.val_eq_coe, path.map_coe, walk.edges_map, list.mem_map,
hom.map_spanning_subgraphs_apply, sym2.map_id', id.def, exists_eq_right],
rintro mem,
apply h',
rw ←mem_edge_set,
apply (simple_graph.walk.edges_subset_edge_set p.val) mem,
end
lemma delete_edge_hom_not_edges (u v) (h : G.adj u v)
{x y : V} (p : (G.delete_edges {⟦⟨u,v⟩⟧}).path x y) :
(⟦⟨u,v⟩⟧ : sym2 V) ∉
((simple_graph.path.map
(simple_graph.hom.map_spanning_subgraphs (delete_edges_le G {⟦⟨u,v⟩⟧}))
(function.injective_id) p)).val.edges :=
begin
simp only [subtype.val_eq_coe, path.map_coe, walk.edges_map, list.mem_map,
hom.map_spanning_subgraphs_apply, sym2.map_id', id.def, exists_eq_right],
rintro mem,
simpa only [mem_edge_set, delete_edges_adj, set.mem_singleton, not_true, and_false]
using p.val.edges_subset_edge_set mem,
end
lemma add_delete_edges {s : set (sym2 V)} (hs : disjoint s G.edge_set) :
(G.add_edges s).delete_edges s = G := sorry
lemma add_delete_edge (u v) (h : ¬ G.adj u v) :
(G.add_edges {⟦⟨u,v⟩⟧}).delete_edges {⟦⟨u,v⟩⟧} = G := sorry
lemma delete_add_edges {s : set (sym2 V)} (hs : s ⊆ G.edge_set) :
(G.delete_edges s).add_edges s = G := sorry
lemma delete_add_edge (u v) (e : G.adj u v) :
(G.delete_edges {⟦⟨u,v⟩⟧}).add_edges {⟦⟨u,v⟩⟧} = G := sorry
end add_delete_edges
namespace walk
variable (c : G.walk u u)
variables {V' : Type*} {G' : simple_graph V'} {f : G →g G'}
lemma is_cycle.to_delete_edges (s : set (sym2 V))
{v : V} {p : G.walk v v} (h : p.is_cycle) (hp : ∀ (e : sym2 V), e ∈ p.edges → e ∉ s) :
(p.to_delete_edges s hp).is_cycle := sorry
lemma map_is_cycle_of_injective (hinj : function.injective f) (hc : c.is_cycle) :
(c.map f).is_cycle := sorry
protected lemma is_cycle.of_map {f : G →g G'} (hc : (c.map f).is_cycle) : c.is_cycle := sorry
lemma map_is_cycle_iff_of_injective (hinj : function.injective f) :
(c.map f).is_cycle ↔ c.is_cycle := sorry
lemma split_along_set' [decidable_eq V] :
∀ {u v : V} (p : G.walk u v) (S : set V) (uS : u ∈ S) (vS : v ∉ S),
∃ (x y : V), G.adj x y ∧ x ∈ S ∧ y ∉ S
| _ _ nil p uS vnS := (vnS uS).elim
| _ _ (cons' u x v a w) S uS vnS := by
{ by_cases h : S x,
{ exact w.split_along_set' S h vnS, },
{ exact ⟨u,x,a,uS,h⟩ }, }
end walk
end simple_graph