-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDegrees.v
362 lines (285 loc) · 10.5 KB
/
Degrees.v
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
(* This program is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1 *)
(* of the License, or (at your option) any later version. *)
(* *)
(* This program is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public *)
(* License along with this program; if not, write to the Free *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA *)
(* Usual notions of neighborhood and degree in a graph, direcetd or not.*)
(* The following notions are defined : *)
(* - In_neighbor : relation between 2 vertices of a digraph; *)
(* - Out_neighbor : id; *)
(* - In_neighborhood : list of in_neighbors of a vertex; *)
(* - Out_neighborhood : list of out_neighbors of a vertex; *)
(* - neighbor : relation between 2 vertices; *)
(* - neighborhood : list of neighbors of a vertex; *)
(* - In_degree : nuber of in_neighbors of a vertex; *)
(* - Out_degree : number of out_neighbors of a vertex. *)
(* - degree : number of neighbors of a vertex; *)
(* - isolated : vertex without neighbor; *)
(* - pendant : vertex with only one neighbor. *)
Require Export Graphs.
Section NEIGHBOR.
Variable v : V_set.
Variable a : A_set.
Definition In_neighbor (x y : Vertex) := a (A_ends y x).
Definition Out_neighbor (x y : Vertex) := a (A_ends x y).
Definition Neighbor (x y : Vertex) := A_included (E_set x y) a.
Lemma neighbor_in_neighbor :
forall x y : Vertex, Neighbor x y -> In_neighbor x y.
Proof.
unfold Neighbor, A_included, Included, In_neighbor; intros.
apply H; apply E_left.
Qed.
Lemma neighbor_out_neighbor :
forall x y : Vertex, Neighbor x y -> Out_neighbor x y.
Proof.
unfold Neighbor, A_included, Included, Out_neighbor; intros.
apply H; apply E_right.
Qed.
Lemma In_and_out_neighbor :
forall x y : Vertex, In_neighbor x y -> Out_neighbor x y -> Neighbor x y.
Proof.
unfold Neighbor, A_included, Included, In_neighbor, Out_neighbor
; intros.
inversion H1; auto.
Qed.
End NEIGHBOR.
Section DEGREE.
Fixpoint In_neighborhood (x : Vertex) (v : V_set) (a : A_set)
(d : Digraph v a) {struct d} : V_list :=
match d with
| D_empty => V_nil
| D_vertex v' a' d' x' _ => In_neighborhood x v' a' d'
| D_arc v' a' d' x' y' _ _ _ =>
if V_eq_dec x y'
then x' :: In_neighborhood x v' a' d'
else In_neighborhood x v' a' d'
| D_eq v' _ a' _ _ _ d' => In_neighborhood x v' a' d'
end.
Fixpoint Out_neighborhood (x : Vertex) (v : V_set)
(a : A_set) (d : Digraph v a) {struct d} : V_list :=
match d with
| D_empty => V_nil
| D_vertex v' a' d' x' _ => Out_neighborhood x v' a' d'
| D_arc v' a' d' x' y' _ _ _ =>
if V_eq_dec x x'
then y' :: Out_neighborhood x v' a' d'
else Out_neighborhood x v' a' d'
| D_eq v' _ a' _ _ _ d' => Out_neighborhood x v' a' d'
end.
Fixpoint neighborhood (x : Vertex) (v : V_set) (a : A_set)
(g : Graph v a) {struct g} : V_list :=
match g with
| G_empty => V_nil
| G_vertex v' a' g' x' _ => neighborhood x v' a' g'
| G_edge v' a' g' x' y' _ _ _ _ _ =>
if V_eq_dec x x'
then y' :: neighborhood x v' a' g'
else
if V_eq_dec x y'
then x' :: neighborhood x v' a' g'
else neighborhood x v' a' g'
| G_eq v' _ a' _ _ _ g' => neighborhood x v' a' g'
end.
Fixpoint In_degree (x : Vertex) (v : V_set) (a : A_set)
(d : Digraph v a) {struct d} : nat :=
match d with
| D_empty => 0
| D_vertex v' a' d' x' _ => In_degree x v' a' d'
| D_arc v' a' d' x' y' _ _ _ =>
if V_eq_dec x y'
then S (In_degree x v' a' d')
else In_degree x v' a' d'
| D_eq v' _ a' _ _ _ d' => In_degree x v' a' d'
end.
Lemma In_degree_neighborhood :
forall (x : Vertex) (v : V_set) (a : A_set) (d : Digraph v a),
In_degree x v a d = length (In_neighborhood x v a d).
Proof.
simple induction d; simpl; intros.
trivial.
trivial.
case (V_eq_dec x y); rewrite H; auto.
trivial.
Qed.
Fixpoint Out_degree (x : Vertex) (v : V_set) (a : A_set)
(d : Digraph v a) {struct d} : nat :=
match d with
| D_empty => 0
| D_vertex v' a' d' x' _ => Out_degree x v' a' d'
| D_arc v' a' d' x' y' _ _ _ =>
if V_eq_dec x x'
then S (Out_degree x v' a' d')
else Out_degree x v' a' d'
| D_eq v' _ a' _ _ _ d' => Out_degree x v' a' d'
end.
Lemma Out_degree_neighborhood :
forall (x : Vertex) (v : V_set) (a : A_set) (d : Digraph v a),
Out_degree x v a d = length (Out_neighborhood x v a d).
Proof.
simple induction d; simpl; intros.
trivial.
trivial.
case (V_eq_dec x x0); rewrite H; auto.
trivial.
Qed.
Fixpoint degree (x : Vertex) (v : V_set) (a : A_set)
(g : Graph v a) {struct g} : nat :=
match g with
| G_empty => 0
| G_vertex v' a' g' x' _ => degree x v' a' g'
| G_edge v' a' g' x' y' _ _ _ _ _ =>
if V_eq_dec x x'
then S (degree x v' a' g')
else
if V_eq_dec x y'
then S (degree x v' a' g')
else degree x v' a' g'
| G_eq v' _ a' _ _ _ g' => degree x v' a' g'
end.
Lemma Degree_neighborhood :
forall (x : Vertex) (v : V_set) (a : A_set) (g : Graph v a),
degree x v a g = length (neighborhood x v a g).
Proof.
simple induction g; simpl; intros.
trivial.
trivial.
case (V_eq_dec x x0); intros.
rewrite H; auto.
case (V_eq_dec x y); rewrite H; auto.
trivial.
Qed.
End DEGREE.
Section REMARKABLE_DEGREE.
Definition isolated (x : Vertex) (v : V_set) (a : A_set)
(g : Graph v a) := forall y : Vertex, ~ a (A_ends x y).
Lemma Degree_isolated :
forall (v : V_set) (a : A_set) (g : Graph v a) (x : Vertex),
isolated x v a g -> degree x v a g = 0.
Proof.
unfold isolated; simple induction g; simpl; intros.
trivial.
auto.
case (V_eq_dec x0 x) as [e|n2].
absurd (A_union (E_set x y) a0 (A_ends x0 y)).
auto.
rewrite e; apply A_in_left; apply E_right.
case (V_eq_dec x0 y) as [e|n3].
absurd (A_union (E_set x y) a0 (A_ends x0 x)).
auto.
rewrite e; apply A_in_left; apply E_left.
apply (H x0); red; intros.
elim (H0 y0); apply A_in_right; trivial.
apply (H x); rewrite e0; trivial.
Qed.
Definition pendant (x : Vertex) (v : V_set) (a : A_set)
(g : Graph v a) :=
exists2 y : Vertex,
a (A_ends x y) & (forall z : Vertex, a (A_ends x z) -> z = y).
Lemma Degree_pendant :
forall (v : V_set) (a : A_set) (g : Graph v a) (x : Vertex),
pendant x v a g -> degree x v a g = 1.
Proof.
unfold pendant; simple induction g; simpl; intros.
elim H; intros.
inversion H0.
auto.
case (V_eq_dec x0 x) as [e|n2].
rewrite (Degree_isolated v0 a0 d x0).
trivial.
elim H0; rewrite e; intros.
unfold isolated; red; intros.
absurd (y0 = x1).
red; intros.
absurd (y = x1).
red; intros; elim n0.
rewrite H5; rewrite <- H4; trivial.
apply H2; apply A_in_left; apply E_right.
apply H2; apply A_in_right; trivial.
case (V_eq_dec x0 y) as [e|n3].
rewrite (Degree_isolated v0 a0 d x0).
trivial.
elim H0; rewrite e; intros.
unfold isolated; red; intros.
absurd (y0 = x1).
red; intros.
absurd (x = x1).
red; intros; elim n1.
rewrite H5; rewrite <- H4; trivial.
apply H2; apply A_in_left; apply E_left.
apply H2; apply A_in_right; trivial.
apply H; elim H0; intros.
split with x1.
apply (A_in_union_edge _ _ _ _ _ H1).
apply E_not_set_eq123; auto.
intros; apply H2; apply A_in_right; trivial.
apply H; rewrite e0; trivial.
Qed.
Lemma Degree_not_isolated :
forall (v : V_set) (a : A_set) (g : Graph v a) (x : Vertex),
(exists y : Vertex, a (A_ends x y)) -> degree x v a g > 0.
Proof.
simple induction g; simpl; intros.
elim H; intros.
inversion H0.
auto.
case (V_eq_dec x0 x); intros.
omega.
case (V_eq_dec x0 y); intros.
omega.
apply H; elim H0; intros.
split with x1.
apply (A_in_union_edge _ _ _ _ _ H1).
apply E_not_set_eq123; auto.
apply H; rewrite e0; trivial.
Qed.
Lemma Degree_not_pendant :
forall (v : V_set) (a : A_set) (g : Graph v a) (x : Vertex),
(exists2 y : Vertex,
a (A_ends x y) & (exists2 z : Vertex, a (A_ends x z) & y <> z)) ->
degree x v a g > 1.
Proof.
simple induction g; simpl; intros.
elim H; intros.
inversion H0.
auto.
case (V_eq_dec x0 x) as [e|n2].
apply gt_n_S; apply Degree_not_isolated.
elim H0; rewrite e; intros.
case (V_eq_dec x1 y) as [e0|n3].
elim H2; rewrite e0; intros.
split with x2.
apply (A_in_union_edge _ _ _ _ _ H3).
apply E_not_set_eq24; auto.
split with x1.
apply (A_in_union_edge _ _ _ _ _ H1).
apply E_not_set_eq24; auto.
case (V_eq_dec x0 y) as [e|n3].
apply gt_n_S; apply Degree_not_isolated.
elim H0; rewrite e; intros.
case (V_eq_dec x x1) as [e0|n3].
elim H2; rewrite e0; intros.
split with x2; apply (A_in_union_edge _ _ _ _ _ H3).
apply E_not_set_eq14; trivial.
split with x1; apply (A_in_union_edge _ _ _ _ _ H1).
apply E_not_set_eq14; trivial.
apply H; elim H0; intros.
split with x1.
apply (A_in_union_edge _ _ _ _ _ H1).
apply E_not_set_eq123; auto.
elim H2; intros.
split with x2.
apply (A_in_union_edge _ _ _ _ _ H3).
apply E_not_set_eq123; auto.
trivial.
apply H; rewrite e0; trivial.
Qed.
End REMARKABLE_DEGREE.