-
Notifications
You must be signed in to change notification settings - Fork 0
/
Relations.v
381 lines (306 loc) · 10.2 KB
/
Relations.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
(** * Definition of binary relations, auxiliary results *)
Set Implicit Arguments.
Ltac cgen H := generalize H; clear H.
Ltac celim H := elim H; clear H.
(** A binary relation is a predicate over pairs of processes *)
Definition relation2(X Y: Type) := X -> Y -> Prop.
Definition relation (X: Type) := relation2 X X.
Definition set(X: Type) := X -> Prop.
Section Definitions.
Variables X Y Z: Type.
(** Inclusion *)
Definition incl: relation (relation2 X Y) := fun R1 R2 => forall x y, R1 x y -> R2 x y.
(** Extensional equality *)
Definition eeq: relation (relation2 X Y) := fun R1 R2 => incl R1 R2 /\ incl R2 R1.
Variable R: relation X.
Definition reflexive := forall x, R x x.
Definition transitive := forall y x z, R x y -> R y z -> R x z.
Definition symmetric := forall x y, R x y -> R y x.
Definition antisymmetric := forall x y, R x y -> R y x -> x=y.
End Definitions.
Hint Unfold incl.
Section Operators.
Section O.
Variables X Y Z: Type.
Variable Rxy: relation2 X Y.
Variable Rxy': relation2 X Y.
Variable Ryz: relation2 Y Z.
(* begin hide *)
Definition eta2: relation2 X Y := fun x y => Rxy x y.
(* end hide *)
(** Transposition, composition, union, union `such that' *)
Definition trans: relation2 Y X := fun y x => Rxy x y.
Definition comp: relation2 X Z := fun x z => exists2 y, Rxy x y & Ryz y z.
Definition union2: relation2 X Y := fun x y => Rxy x y \/ Rxy' x y.
Definition union (I: Type) R: relation2 X Y := fun x y => exists i: I, R i x y.
Definition union_st (P: set (relation2 X Y)) := fun x y => exists2 R, P R & R x y.
End O.
Variable X: Type.
Variable R: relation X.
(** Reflexive, transitive closure *)
Inductive star: relation X :=
| star_refl: forall x, star x x
| S_star: forall y x z, R x y -> star y z -> star x z.
(** Transitive closure *)
Definition plus: relation X := comp R star.
End Operators.
Hint Unfold trans.
Hint Immediate star_refl.
Section Eeq1.
Variables I X Y Z: Type.
Variable R' R1': relation2 X Y.
Variable S': relation2 Y Z.
Variable R R1: relation2 X Y.
Variable S : relation2 Y Z.
Variables T' T: relation X.
Variables F' F: I -> relation2 X Y.
Lemma trans_incl: incl R R' -> incl (trans R) (trans R').
Proof. auto. Qed.
Lemma trans_eeq: eeq R R' -> eeq (trans R) (trans R').
Proof. unfold eeq; intuition. Qed.
Lemma comp_incl: incl R R' -> incl S S' -> incl (comp R S) (comp R' S').
Proof.
unfold eeq, comp, incl; intuition.
destruct H1 as [ t ]; exists t; auto.
Qed.
Lemma comp_eeq: eeq R R' -> eeq S S' -> eeq (comp R S) (comp R' S').
Proof.
unfold eeq, comp, incl; intuition;
destruct H0 as [ t ]; exists t; auto.
Qed.
Lemma union_incl: (forall i, incl (F i) (F' i)) -> incl (union F) (union F').
Proof.
unfold eeq, union, incl; intuition.
destruct H0 as [ i ]; exists i; auto.
Qed.
Lemma union_eeq: (forall i, eeq (F i) (F' i)) -> eeq (union F) (union F').
Proof.
unfold eeq, union, incl; intuition;
destruct H0 as [ i ]; destruct (H i); exists i; auto.
Qed.
Lemma union2_incl: incl R R' -> incl R1 R1' -> incl (union2 R R1) (union2 R' R1').
Proof.
unfold incl, union2; intuition.
Qed.
Lemma union2_eeq: eeq R R' -> eeq R1 R1' -> eeq (union2 R R1) (union2 R' R1').
Proof.
unfold eeq, union2, incl; intuition.
Qed.
Lemma star_incl: incl T T' -> incl (star T) (star T').
Proof.
intros H x y XY; induction XY as [ x | w x y XW WY IH ]; auto;
apply S_star with w; auto.
Qed.
Lemma star_eeq: eeq T T' -> eeq (star T) (star T').
Proof.
intro H; destruct H as [ H1 H2 ]; split;
intros x y XY; induction XY as [ x | w x y XW WY IH ]; auto;
apply S_star with w; auto.
Qed.
Lemma plus_incl: incl T T' -> incl (plus T) (plus T').
Proof.
intros H x y XY; destruct XY as [ w XW WY ]; exists w; auto.
apply (star_incl H); assumption.
Qed.
Lemma plus_eeq: eeq T T' -> eeq (plus T) (plus T').
Proof.
intro H; elim H; intros H1 H2; split;
intros x y XY; destruct XY as [ w XW WY ]; exists w; auto.
apply (proj1 (star_eeq H)); assumption.
apply (proj2 (star_eeq H)); assumption.
Qed.
End Eeq1.
Hint Resolve trans_incl.
Hint Resolve comp_incl.
Hint Resolve union_incl.
Hint Resolve star_incl.
Hint Resolve plus_incl.
Hint Resolve trans_eeq.
Hint Resolve comp_eeq.
Hint Resolve union_eeq.
Hint Resolve star_eeq.
Hint Resolve plus_eeq.
Section InclEeq.
Variables X Y: Type.
Variables S R T: relation2 X Y.
Lemma incl_refl: incl R R.
Proof fun x y H => H.
Lemma incl_trans: incl R S -> incl S T -> incl R T.
Proof. unfold incl; auto. Qed.
Lemma eeq_refl: eeq R R.
Proof. intros; split; apply incl_refl. Qed.
Lemma eeq_trans: eeq R S -> eeq S T -> eeq R T.
Proof. unfold eeq, incl; split; intuition. Qed.
Lemma eeq_sym: eeq R S -> eeq S R.
Proof. unfold eeq, incl; split; intuition. Qed.
End InclEeq.
Hint Immediate incl_refl.
Hint Immediate eeq_refl.
Hint Resolve eeq_sym.
Section star.
Variable X: Type.
Variable R: relation X.
Lemma star1: forall x y, R x y -> star R x y.
Proof.
intros x y xRy; eapply S_star; [ apply xRy | apply star_refl ].
Qed.
Lemma star_S: forall x y z, star R x y -> R y z -> star R x z.
Proof.
intros x y z XY YZ; induction XY.
apply star1; assumption.
apply S_star with y; intuition.
Qed.
Lemma star_trans: forall x y z, star R x y -> star R y z -> star R x z.
Proof.
intros x y z xy; induction xy; intuition.
apply S_star with y; assumption.
Qed.
Lemma plus_star: forall x y, plus R x y -> star R x y.
Proof.
intros x y XY; elim XY; intros w XW WY.
apply S_star with w; intuition.
Qed.
Lemma plus_star_plus: forall y x z, plus R x y -> star R y z -> plus R x z.
Proof.
intros y x z XY YZ; elim XY; intros w XW WY.
exists w; intuition.
apply star_trans with y; assumption.
Qed.
Lemma star_plus_plus: forall y x z, star R x y -> plus R y z -> plus R x z.
Proof.
induction 1 as [ x | w x y XW WY IH ]; intros YZ.
assumption.
exists w; intuition.
apply plus_star; assumption.
Qed.
Lemma plus_trans: forall y x z, plus R x y -> plus R y z -> plus R x z.
Proof.
intros y x z XY YZ; apply plus_star_plus with y; try apply plus_star; assumption.
Qed.
Lemma plus1: forall x y, R x y -> plus R x y.
Proof.
intros x y XY; exists y; intuition.
Qed.
Lemma plus_S: forall y x z, star R x y -> R y z -> plus R x z.
Proof.
intros y x z XY YZ; apply star_plus_plus with y; try apply plus1; assumption.
Qed.
Lemma S_plus: forall y x z, R x y -> star R y z -> plus R x z.
Proof.
intros y x z XY YZ; exists y; assumption.
Qed.
End star.
Hint Resolve star1.
Hint Resolve plus1.
Hint Resolve plus_star.
Ltac destar H w :=
match type of H with
star _ ?x ?y => destruct H as [ x | w x y _H1 _H2 ];
[ idtac | generalize (S_plus _ _H1 _H2); clear _H1 _H2; intro H ]
| _ => fail "not a star hypothesis"
end.
Section Plus_WF.
Variable X: Set.
Variable R: relation X.
Hypothesis Rwf: well_founded (trans R).
Lemma Acc_clos_trans : forall x, Acc (trans R) x -> Acc (trans (plus R)) x.
Proof.
induction 1 as [z _ Hz].
apply Acc_intro.
intros y Hy.
elim Hy; intros w Hzw Hwy; clear Hy.
generalize (Hz _ Hzw); clear Hz Hzw; intro Hw.
destruct Hwy; intuition.
apply Acc_inv with x; auto.
exists y; intuition.
Qed.
Hint Resolve Acc_clos_trans.
Theorem plus_wf: well_founded (trans (plus R)).
Proof.
intro; auto.
Qed.
End Plus_WF.
Section Eeq2.
Variables I X Y Z: Type.
Variables R R': relation2 X Y.
Variable S: relation2 Y Z.
Variable T: relation X.
Variable F: I -> relation2 X Y.
Lemma inv_inv: eeq (trans (trans T)) T.
Proof.
intros; unfold trans, eeq, incl; intuition.
Qed.
Lemma inv_comp: eeq (trans (comp R S)) (comp (trans S) (trans R)).
Proof.
intros; unfold comp, trans, eeq, incl; intuition;
destruct H as [ t ]; exists t; auto.
Qed.
Lemma inv_union: eeq (trans (union F)) (union (fun i => trans (F i))).
Proof.
intros; unfold union, trans, eeq, incl; intuition.
Qed.
Lemma inv_star: eeq (trans (star T)) (star (trans T)).
Proof.
split.
unfold incl; induction 1; auto; apply star_S with y; auto.
unfold incl, trans; induction 1; auto; apply star_S with y; auto.
Qed.
Lemma inv_plus: eeq (trans (plus T)) (plus (trans T)).
Proof.
split.
unfold trans; intros x y YX; destruct YX as [ w YW WX ].
cgen YW; cgen y.
induction WX as [ w | t w x WT TX IH ]; intros y YW.
apply plus1; apply YW.
elim IH with w; auto.
intros t' T'Y WT'.
exists t'; intuition.
apply star_S with w; auto.
unfold trans; intros x y XY; destruct XY as [ w XW WY ].
cgen XW; cgen x.
induction WY as [ w | t w y WT TY IH ]; intros x XW.
apply plus1; apply XW.
elim IH with w; auto.
intros t' T'Y WT'.
exists t'; intuition.
apply star_S with w; auto.
Qed.
Lemma inv_union2: eeq (trans (union2 R R')) (union2 (trans R) (trans R')).
Proof.
split; (intros x y H; celim H; intro H; [ left | right ]; auto).
Qed.
Lemma comp_assoc: forall W: Type, forall U: relation2 Z W,
eeq (comp (comp R S) U) (comp R (comp S U)).
Proof.
intros W U; split; intros x y H; destruct H as [ w H1 H2 ];
[ destruct H1 as [ t ] | destruct H2 as [ t ] ];
exists t; auto; exists w; auto.
Qed.
Lemma comp_star_star: eeq (comp (star T) (star T)) (star T).
Proof.
split; intros x y H.
destruct H as [ w ]; apply star_trans with w; assumption.
exists x; auto.
Qed.
Lemma comp_plus_star: eeq (comp (plus T) (star T)) (plus T).
Proof.
split; intros x y H; destruct H as [ w ].
apply plus_star_plus with w; assumption.
exists w; auto.
Qed.
Lemma comp_star_plus: eeq (comp (star T) (plus T)) (plus T).
Proof.
split; intros x y H; destruct H as [ w ].
apply star_plus_plus with w; assumption.
exists x; auto; apply S_plus with w; assumption.
Qed.
End Eeq2.
Hint Immediate inv_inv.
Hint Immediate inv_comp.
Hint Immediate inv_union.
Hint Immediate inv_star.
Hint Immediate inv_plus.
Hint Immediate comp_assoc.
Hint Immediate comp_star_star.
Hint Immediate comp_plus_star.
Hint Immediate comp_star_plus.