-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rewriting_Defs.v
247 lines (203 loc) · 9.71 KB
/
Rewriting_Defs.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
(***************************************************************************
* Formalization of ES calculi *
* *
* General rewriting definitions for explicit substitutions *
* *
* Fabien Renaud & St\u00e9phane Zimmerman, 2011 *
* Flavio L. C. de Moura & Daniel L. Ventura & Washington R. Segundo, 2014 *
***************************************************************************)
Require Import Metatheory.
Require Import LambdaES_Defs.
Require Import LambdaES_Infra.
Require Import LambdaES_FV.
Require Import List.
(** Given a relation Red, constructs its contextual closure *)
Inductive contextual_closure (Red : pterm -> pterm -> Prop) : pterm -> pterm -> Prop :=
| redex : forall t s, Red t s -> contextual_closure Red t s
| app_left : forall t t' u, term u -> contextual_closure Red t t' ->
contextual_closure Red (pterm_app t u) (pterm_app t' u)
| app_right : forall t u u', term t -> contextual_closure Red u u' ->
contextual_closure Red (pterm_app t u) (pterm_app t u')
| abs_in : forall t t' L, (forall x, x \notin L -> contextual_closure Red (t^x) (t'^x)) -> contextual_closure Red (pterm_abs t) (pterm_abs t')
| subst_left : forall t t' u L, term u ->
(forall x, x \notin L -> contextual_closure Red (t^x) (t'^x)) ->
contextual_closure Red (pterm_sub t u) (pterm_sub t' u)
| subst_right : forall t u u', body t -> contextual_closure Red u u' ->
contextual_closure Red (pterm_sub t u) (pterm_sub t u')
.
(** Given a relation Red, constructs its contextual closure just over Lterms *)
Inductive L_contextual_closure (Red : pterm -> pterm -> Prop) : pterm -> pterm -> Prop :=
| L_redex : forall t s, Red t s -> L_contextual_closure Red t s
| L_app_left : forall t t' u, Lterm u -> L_contextual_closure Red t t' ->
L_contextual_closure Red (pterm_app t u) (pterm_app t' u)
| L_app_right : forall t u u', Lterm t -> L_contextual_closure Red u u' ->
L_contextual_closure Red (pterm_app t u) (pterm_app t u')
| L_abs_in : forall t t' L, (forall x, x \notin L -> L_contextual_closure Red (t^x) (t'^x))
-> L_contextual_closure Red (pterm_abs t) (pterm_abs t')
.
(** Given a relation Red, constructs its parallel contextual closure *)
Inductive p_contextual_closure (Red : pterm -> pterm -> Prop) : pterm -> pterm -> Prop :=
| p_redex : forall t s, Red t s -> p_contextual_closure Red t s
| p_app : forall t t' u u', p_contextual_closure Red t t' -> p_contextual_closure Red u u' ->
p_contextual_closure Red (pterm_app t u) (pterm_app t' u')
| p_abs_in : forall t t' L, (forall x, x \notin L -> p_contextual_closure Red (t^x) (t'^x)) ->
p_contextual_closure Red (pterm_abs t) (pterm_abs t')
| p_subst : forall t t' u u' L, (forall x, x \notin L -> p_contextual_closure Red (t^x) (t'^x)) ->
p_contextual_closure Red u u' ->
p_contextual_closure Red (pterm_sub t u) (pterm_sub t' u')
.
(** Given a relation Red, constructs the parallel contextual closure
fr labelled terms. *)
(*
Inductive p_lab_contextual_closure (Red : pterm -> pterm -> Prop) :
pterm -> pterm -> Prop :=
| p_lab_redex : forall t s, Red t s -> p_lab_contextual_closure Red t s
| p_lab_app : forall t t' u u', p_lab_contextual_closure Red t t' ->
p_lab_contextual_closure Red u u' ->
p_lab_contextual_closure Red (pterm_app t u) (pterm_app t' u')
| p_lab_abs_in : forall t t' L, (forall x, x \notin L ->
p_lab_contextual_closure Red (t^x) (t'^x)) ->
p_lab_contextual_closure Red (pterm_abs t) (pterm_abs t')
| p_lab_subst : forall t t' u u' L, (forall x, x \notin L ->
p_lab_contextual_closure Red (t^x) (t'^x)) ->
p_lab_contextual_closure Red u u' ->
p_lab_contextual_closure Red (t[u]) (t'[u'])
| p_lab_subst' : forall t t' u u' L, (forall x, x \notin L ->
p_lab_contextual_closure Red (t^x) (t'^x)) ->
u =e u' ->
p_lab_contextual_closure Red (t[[u]]) (t'[[u']])
.
*)
Hint Constructors contextual_closure.
(** Given a relation Red, constructs its transitive closure *)
Inductive trans_closure (Red : pterm -> pterm -> Prop) : pterm -> pterm -> Prop :=
| one_step_reduction : forall t u, Red t u -> trans_closure Red t u
| transitive_reduction : forall t u v, Red t u -> trans_closure Red u v -> trans_closure Red t v
.
(** Given a relation Red, constructs its reflexive closure *)
Inductive star_closure (Red : pterm -> pterm -> Prop) : pterm -> pterm -> Prop :=
| reflexive_reduction : forall t, star_closure Red t t
| star_trans_reduction : forall t u, trans_closure Red t u -> star_closure Red t u
.
(* ********************************************************************** *)
(** Properties of relations *)
Definition red_regular (R : pterm -> pterm -> Prop) :=
forall t t', R t t' -> term t /\ term t'.
Definition red_regular' (R : pterm -> pterm -> Prop) :=
forall t t', R t t' -> (term t <-> term t').
Definition red_refl (R : pterm -> pterm -> Prop) :=
forall t, term t -> R t t.
Definition red_in (R : pterm -> pterm -> Prop) :=
forall t x u u', term t -> R u u' ->
R ([x ~> u]t) ([x ~> u']t).
Definition red_all (R : pterm -> pterm -> Prop) :=
forall x t t', R t t' ->
forall u u', R u u' ->
R ([x~>u]t) ([x~>u']t').
Definition red_out (R : pterm -> pterm -> Prop) :=
forall x u t t', term u -> R t t' ->
R ([x~>u]t) ([x~>u]t').
Definition red_out' (R : pterm -> pterm -> Prop) :=
forall x y t t', R t t' ->
R ([x~>pterm_fvar y]t) ([x~>pterm_fvar y]t').
Definition red_rename (R : pterm -> pterm -> Prop) :=
forall x t t' y,
x \notin (fv t) -> x \notin (fv t') ->
R (t ^ x) (t' ^ x) ->
R (t ^ y) (t' ^ y).
Definition red_rename' (R : pterm -> pterm -> Prop) :=
forall x t t' y,
x \notin (fv t) -> x \notin (fv t') ->
y \notin (fv t) -> y \notin (fv t') ->
R (t ^ x) (t' ^ x) ->
R (t ^ y) (t' ^ y).
Definition red_swap (R : pterm -> pterm -> Prop) :=
forall x t t' y,
R t t' ->
R ([(x,y)]t) ([(x,y)]t').
Definition red_through (R : pterm -> pterm -> Prop) :=
forall x t1 t2 u1 u2,
x \notin (fv t1) -> x \notin (fv u1) ->
R (t1 ^ x) (u1 ^ x) -> R t2 u2 ->
R (t1 ^^ t2) (u1 ^^ u2).
Definition red_not_fv (R: pterm -> pterm -> Prop) :=
forall x t t', R t t' ->
x \notin (fv t) -> x \notin (fv t').
Definition red_fv (R: pterm -> pterm -> Prop) :=
forall x t t', R t t' ->
x \in (fv t') -> x \in (fv t).
Definition L_red_regular (R : pterm -> pterm -> Prop) :=
forall t t', R t t' -> Lterm t /\ Lterm t'.
Definition L_red_regular' (R : pterm -> pterm -> Prop) :=
forall t t', R t t' -> (Lterm t <-> Lterm t').
Definition L_red_refl (R : pterm -> pterm -> Prop) :=
forall t, Lterm t -> R t t.
Definition L_red_in (R : pterm -> pterm -> Prop) :=
forall t x u u', Lterm t -> R u u' ->
R ([x ~> u]t) ([x ~> u']t).
Definition L_red_out (R : pterm -> pterm -> Prop) :=
forall x u t t', Lterm u -> R t t' ->
R ([x~>u]t) ([x~>u]t').
(** maybe realocate begin *)
(** Reduction on lists **)
Definition R_list (R : pterm -> pterm -> Prop) (l : list pterm) (l' : list pterm) :=
exists t, exists t', exists l0, exists l1, l = (l0 ++ t :: l1) /\ l' = (l0 ++ t' :: l1) /\ R t t'.
Lemma R_list_h: forall (R : pterm -> pterm -> Prop) a b lt,
R a b -> R_list R (a :: lt) (b :: lt).
Proof.
intros. unfold R_list. exists a. exists b. exists (nil (A := pterm)). exists lt.
simpl. split; trivial; split; trivial.
Qed.
Lemma R_list_t: forall (R : pterm -> pterm -> Prop) a lt lt',
(R_list R lt lt') -> R_list R (a :: lt) (a :: lt').
Proof.
unfold R_list. intros.
case H; clear H. intros b H.
case H; clear H. intros b' H.
case H; clear H. intros l H.
case H; clear H. intros l' H.
destruct H. destruct H0.
rewrite H. rewrite H0.
exists b. exists b'.
exists (a :: l). exists l'. simpl.
split; trivial. split; trivial.
Qed.
Lemma term_mult_app : forall t lu, term (t // lu) <-> term t /\ (term %% lu).
Proof.
intros t lu. induction lu; simpl; split;
intro H; try apply H; try split; trivial.
apply term_distribute_over_application in H.
apply IHlu. apply H.
apply term_distribute_over_application in H.
split. apply H. apply IHlu. apply H.
apply term_distribute_over_application. split.
apply IHlu. split; apply H. apply H.
Qed.
Lemma Lterm_mult_app : forall t lu, Lterm (t // lu) <-> Lterm t /\ (Lterm %% lu).
Proof.
intros t lu. induction lu; simpl; split;
intro H; try apply H; try split; trivial.
inversion H. apply IHlu; trivial.
inversion H. split; trivial. apply IHlu; trivial.
destruct H. destruct H0. apply Lterm_app; trivial.
apply IHlu; split; trivial.
Qed.
Lemma ctx_red_t_mult_app : forall R t lu lu', term t -> term %% lu -> R_list (contextual_closure R) lu lu' -> (contextual_closure R) (t // lu) (t // lu').
Proof.
intros R t lu lu' Tt Tlu H. unfold R_list in H.
case H; clear H; intros t0 H.
case H; clear H; intros t1 H.
case H; clear H; intros l0 H.
case H; clear H; intros l1 H.
destruct H. destruct H0.
rewrite H. rewrite H0. rewrite H in Tlu.
clear H H0. induction l0; simpl. destruct l1; simpl.
apply app_right; trivial.
apply app_right; trivial.
simpl in Tlu. rewrite term_distribute_over_application.
rewrite term_mult_app. destruct Tlu. destruct H0.
split; trivial. split; trivial.
simpl in Tlu. destruct Tlu.
apply app_left; trivial.
apply IHl0; trivial.
Qed.