-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.v
341 lines (299 loc) · 10.5 KB
/
basics.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
(* This file formalises some basic properties of the relations from
Section 4, including lemmas 4.3, 4.4 and generalised versions of
lemmas 4.5, 4.7. *)
Require Export defs.
Require Export tactics.
Require Export star.
Require Export equality.
Lemma lem_root_active_bot : root_active bot.
Proof.
unfold root_active.
unfold has_rnf.
intro H.
destruct H as [t [H1 H2]].
revert H1.
inversion_clear H2.
- ycrush.
- inversion_clear H; sauto; inversion_clear H0.
- inversion_clear H; sauto; inversion_clear H0.
- inversion_clear H; sauto; inversion_clear H0.
Qed.
Section Basic_clos_props.
Variable R : relation term.
Variable MorR : morphism R.
Lemma lem_comp_morphism : morphism (comp_clos R).
Proof.
unfold morphism.
intros x y H.
induction H; intros x0 y0 Heq1 Heq2.
- constructor; pose_term_eq; sauto.
- rewrite H0 in Heq1.
inversion Heq1; subst; intuition; fold term_eq in *;
inversion Heq2; subst; intuition; fold term_eq in *;
solve [ constructor; pose_term_eq; eauto ].
- rewrite H0 in Heq1.
inversion Heq1; subst; intuition; fold term_eq in *;
inversion Heq2; subst; intuition; fold term_eq in *;
solve [ constructor; pose_term_eq; eauto ].
- inversion Heq1; subst; intuition; fold term_eq in *;
inversion Heq2; subst; intuition; fold term_eq in *;
solve [ constructor; pose_term_eq; eauto ].
Qed.
Add Parametric Morphism : (comp_clos R) with
signature term_eq ==> term_eq ==> iff as comp_mor.
Proof.
split; intro; eapply lem_comp_morphism; pose_term_eq; eauto.
Qed.
Add Parametric Morphism : (star R) with
signature term_eq ==> term_eq ==> iff as star_mor.
Proof.
split; intro; eapply lem_star_morphism; pose_term_eq; eauto.
Qed.
(******************************************************************************)
Definition red R := star (comp_clos R).
Hint Unfold red.
Add Parametric Morphism : (red R) with
signature term_eq ==> term_eq ==> iff as red_mor.
Proof.
split; intro; eapply lem_star_morphism; pose lem_comp_morphism; pose_term_eq; eauto.
Qed.
Lemma lem_red_refl : forall x y, x == y -> red R x y.
Proof.
yelles 2.
Qed.
Lemma lem_red_refl_0 : reflexive term (red R).
Proof.
pose_term_eq; yelles 2.
Qed.
Lemma lem_red_trans : transitive term (red R).
Proof.
generalize lem_comp_morphism; unfold transitive; pose_star; eauto.
Qed.
Lemma lem_red_step : forall x y z, comp_clos R x y -> red R y z -> red R x z.
Proof.
generalize lem_comp_morphism; pose_star; eauto.
Qed.
Lemma lem_red_app_l : forall x x', red R x x' -> forall y, red R (app x y) (app x' y).
Proof.
intros x x' H.
induction H; intro.
- rewrite H; apply lem_red_refl_0.
- apply lem_red_step with (y := app y y0).
+ constructor 2; pose_term_eq; eauto.
+ auto.
Qed.
Lemma lem_red_app_r : forall y y', red R y y' -> forall x, red R (app x y) (app x y').
Proof.
intros y y' H.
induction H; intro.
- rewrite H; apply lem_red_refl_0.
- apply lem_red_step with (y := app x0 y).
+ constructor 3; pose_term_eq; eauto.
+ auto.
Qed.
Lemma lem_red_app : forall x x' y y', red R x x' -> red R y y' ->
red R (app x y) (app x' y').
Proof.
eauto using lem_red_app_l, lem_red_app_r, lem_red_trans.
Qed.
Lemma lem_red_abs : forall x x', red R x x' -> red R (abs x) (abs x').
Proof.
intros x x' H.
induction H.
- rewrite H; apply lem_red_refl_0.
- apply lem_red_step with (y := abs y); csolve.
Qed.
Lemma lem_red_step_rev : forall x y z, red R x y -> comp_clos R y z -> red R x z.
Proof.
intros x y z H.
revert z.
induction H.
- intros; rewrite H; econstructor 2; [ eauto | constructor; pose_term_eq; eauto ].
- eauto using lem_red_step.
Qed.
Lemma lem_step_to_red : forall x y, comp_clos R x y -> red R x y.
Proof.
intros; eapply lem_red_step; eauto using lem_red_refl_0.
Qed.
(******************************************************************************)
Lemma lem_inf_morphism : morphism (inf_clos (star R)).
Proof.
assert (Hm: morphism (star R)) by eauto using lem_star_morphism.
unfold morphism.
enough (forall x y, inf_clos (star R) x y ->
forall x' y', y == y' -> x == x' ->
inf_clos (star R) x' y') by ycrush.
coinduct CH; intros x1 y1 Heq1 Heq2;
inversion Heq1; subst; intuition; fold term_eq in *; econstructor; pose_term_eq; eauto.
Qed.
Lemma lem_inf_refl_0 : reflexive term (inf_clos (star R)).
Proof.
pose_star; coinduction on 0.
Qed.
(* Lemma 4.3, (1) *)
Lemma lem_inf_refl : forall x y, x == y -> inf_clos (star R) x y.
Proof.
pose_star; pose_term_eq; coinduction on 0.
Qed.
(* Lemma 4.3, (2) *)
Lemma lem_inf_prepend : forall x y z, star R x y -> inf_clos (star R) y z -> inf_clos (star R) x z.
Proof.
pose_star; csolve on 4.
Qed.
(* Lemma 4.3, (3) *)
Lemma lem_star_to_inf : forall x y, star R x y -> inf_clos (star R) x y.
Proof.
Reconstr.reasy (lem_inf_refl_0, lem_inf_prepend) (reflexive).
Qed.
(* Lemma 4.4 *)
Lemma lem_inf_subset (S : relation term) : (forall x y, R x y -> S x y) ->
forall x y, inf_clos (star R) x y -> inf_clos (star S) x y.
Proof.
pose_star; coinduction using eauto.
Qed.
Lemma lem_comp_subst_closed : subst_closed R -> subst_closed (comp_clos R).
Proof.
unfold subst_closed.
intros H x x'.
enough (comp_clos R x x' -> forall n y, comp_clos R (x [n := y]) (x' [n := y])) by scrush.
intro H1; induction H1; intros; try rewrite H0; pose_term_eq; csolve.
Qed.
Lemma lem_comp_shift_closed : shift_closed R -> shift_closed (comp_clos R).
Proof.
unfold shift_closed.
intro H.
enough (forall t t', comp_clos R t t' -> forall d c, comp_clos R (shift d c t) (shift d c t')) by scrush.
intros t t' H1; induction H1; intros; try rewrite H0; pose_term_eq; csolve.
Qed.
Lemma lem_star_subst_closed : subst_closed R -> subst_closed (star R).
Proof.
unfold subst_closed.
intro H; sauto.
induction H0; try rewrite H0; pose_star; eauto.
Qed.
Lemma lem_star_shift_closed : shift_closed R -> shift_closed (star R).
Proof.
unfold shift_closed.
intro H; sauto.
induction H0; try rewrite H0; pose_star; eauto.
Qed.
Lemma lem_inf_shift_closed : shift_closed R -> shift_closed (inf_clos R).
Proof.
unfold shift_closed.
intro H0.
coinduction H using auto.
- autorewrite with shints.
constructor.
assert (shift d c bot = bot) by (autorewrite with shints; reflexivity).
yelles 1.
- clear H; autorewrite with shints; ysplit.
+ constructor.
assert (shift d c (var n) = var (n + d)) by (autorewrite with shints; sauto).
yelles 1.
+ constructor.
assert (shift d c (var n) = var n) by (autorewrite with shints; sauto).
yelles 1.
- autorewrite with shints.
apply inf_clos_app with (x := shift d c x) (y := shift d c y).
+ assert (app (shift d c x) (shift d c y) = shift d c (app x y)) by (autorewrite with shints; reflexivity).
yelles 1.
+ auto.
+ auto.
- autorewrite with shints.
apply inf_clos_abs with (x := shift d (c + 1) x).
+ assert (abs (shift d (c + 1) x) = shift d c (abs x)) by (autorewrite with shints; reflexivity).
yelles 1.
+ auto.
Qed.
End Basic_clos_props.
(******************************************************************************)
(* Lemma 4.5, generalised *)
Lemma lem_inf_subst (R : relation term):
morphism R -> subst_closed R -> shift_closed R ->
forall s s' t t', inf_clos (star R) s s' -> inf_clos (star R) t t' ->
forall n, inf_clos (star R) (subst n t s) (subst n t' s').
Proof.
intros Hm H0 H1.
assert (Hs0: subst_closed (star R)) by auto using lem_star_subst_closed.
clear H0; unfold subst_closed in Hs0.
assert (Hs1: shift_closed (star R)) by auto using lem_star_shift_closed.
clear H1; unfold shift_closed in Hs1.
coinduct H.
- clear H; intros; autorewrite with shints.
constructor.
assert (HH: bot = bot [n := t]) by (autorewrite with shints; auto).
rewrite HH; clear HH.
eauto.
- clear H; intros.
assert (inf_clos (star R) (var n [n0 := t]) (var n [n0 := t'])).
autorewrite with shints; repeat ysplit.
+ solve [ constructor; pose_star; sauto ].
+ generalize lem_inf_shift_closed; unfold shift_closed; auto.
+ solve [ constructor; pose_star; sauto ].
+ eapply lem_inf_prepend; sauto.
- intros; autorewrite with shints.
apply inf_clos_app with (x := x[n := t]) (y := y[n := t]).
+ assert (HH: app (x [n := t]) (y [n := t]) = (app x y) [n := t]) by
(autorewrite with shints; reflexivity).
rewrite HH.
auto.
+ eauto.
+ eauto.
- intros; autorewrite with shints.
apply inf_clos_abs with (x := x [n + 1 := t]).
+ assert (HH: abs (x [n + 1 := t]) = abs x [n := t]) by
(autorewrite with shints; reflexivity).
rewrite HH.
auto.
+ eauto.
Qed.
Definition appendable (R : relation term) :=
forall t1 t2 t3, inf_clos R t1 t2 -> R t2 t3 -> inf_clos R t1 t3.
(* Lemma 6.2, generalised Lemma 4.7 *)
Lemma lem_inf_trans (R : relation term) : appendable R -> transitive term (inf_clos R).
Proof.
unfold appendable; unfold transitive.
intro Ha.
coinduction H on 4 using eauto.
- assert (HH: inf_clos R x (app x0 y0)) by eauto.
inversion HH; subst.
econstructor; eauto.
- assert (HH: inf_clos R x (abs x0)) by eauto.
inversion HH; subst.
econstructor; eauto.
Qed.
Lemma lem_inf_reflexive (R : relation term) : reflexive term R -> reflexive term (inf_clos R).
Proof.
intro; coinduction on 0.
Qed.
Lemma lem_R_to_inf (R : relation term) : morphism R -> reflexive term R ->
forall x y, R x y -> inf_clos R x y.
Proof.
intros Hm Hr.
pose lem_inf_reflexive; coinduction CH on 1.
Qed.
Lemma lem_inf_to_aux (R : relation term) : morphism R ->
forall x y, inf_clos (star R) x y -> aux_clos R x y.
Proof.
unfold aux_clos.
pose lem_inf_morphism; pose lem_R_to_inf; pose lem_inf_refl_0; ycrush.
Qed.
Lemma lem_inf_prepend_step (R : relation term) :
transitive term R -> forall x y z, R x y -> inf_clos R y z -> inf_clos R x z.
Proof.
csolve on 5.
Qed.
Lemma lem_aux_to_inf (R : relation term) :
appendable (star R) -> forall x y, aux_clos R x y -> inf_clos (star R) x y.
Proof.
intros Ha.
unfold aux_clos.
coinduction CH using eauto.
- inversion H0; subst.
assert (inf_clos (inf_clos (star R)) x1 x') by (pose lem_inf_prepend_step; pose lem_inf_trans; ycrush).
assert (inf_clos (inf_clos (star R)) y y') by (pose lem_inf_prepend_step; pose lem_inf_trans; ycrush).
cosolve CH.
- inversion H0; subst.
assert (inf_clos (inf_clos (star R)) x1 x') by (pose lem_inf_prepend_step; pose lem_inf_trans; ycrush).
cosolve CH.
Qed.