-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLambdaES_FV.v
292 lines (265 loc) · 11.9 KB
/
LambdaES_FV.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
(***************************************************************************
* Formalization of ES calculi *
* *
* Properties of free variables *
* *
* Fabien Renaud, 2011 *
* Flávio L. C. de Moura, 2015 *
***************************************************************************)
Set Implicit Arguments.
Require Import Metatheory LambdaES_Defs.
Lemma fv_open_ : forall t k x y, x<>y -> (x \in fv ({k~>pterm_fvar y}t ) <-> x \in fv t).
Proof.
intro t; induction t. intros k x y H. simpls.
case_nat. simpls. split. intro H0.
apply in_singleton in H0. contradiction.
intro H0. apply in_empty in H0. contradiction.
simpls. split. intro H0; assumption. intro H0; assumption.
intros k x y H. simpls.
split. intro H0; assumption. intro H0; assumption.
intros k x y H. simpls. rewrite in_union. rewrite in_union.
split. intro H0. destruct H0. left.
generalize H0. apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
intro H0. destruct H0. left.
generalize H0. apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
simpls. intros k x y.
apply (IHt (S k) x y) ; assumption.
simpls. intros k x y H.
rewrite in_union. rewrite in_union.
split. intro H0. destruct H0. left.
generalize H0. apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
intro H0. destruct H0.
left. generalize H0.
apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
simpls. intros k x y.
rewrite in_union. rewrite in_union. intro H.
split. intro H0. destruct H0.
left. generalize H0.
apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
intro H0. destruct H0.
left. generalize H0.
apply IHt1; assumption.
right. generalize H0.
apply IHt2; assumption.
Qed.
Lemma fv_open_in_neq : forall t x y, x<>y -> (x \in fv(t^y ) <-> x \in fv t).
Proof. intros. apply fv_open_. assumption. Qed.
Lemma notin_fv_close : forall t k x, x \notin fv (close_rec k x t).
Proof.
intro. induction t ; intros ; simpl ; auto ; unfold close ; simpl.
case_var ; simpl ; auto.
Qed.
Lemma fv_in_or_notin : forall t x, x \in fv t \/ x \notin fv t.
Proof.
intros t x. induction t ; simpl ; auto.
case_eq (x==v) ; intros.
rewrite e. left. rewrite in_singleton. reflexivity.
right. auto.
destruct IHt1 ; destruct IHt2 ; auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
destruct IHt1 ; destruct IHt2 ; auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
destruct IHt1 ; destruct IHt2 ; auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
left. rewrite in_union. auto.
Qed.
Lemma fv_notin_open : forall t x z, x <> z -> (x \notin fv t <-> x \notin fv (t^z)).
Proof.
intros t. unfold open. generalize 0 as k. induction t ; intros k x z neq ; split ; intros x_notin ; simpl ; auto.
unfolds open ; simpls ; auto.
compare k n ; intros.
rewrite e. case_nat ; simpl ; auto. case_nat ; simpl ; auto.
rewrite notin_union. split.
apply (IHt1 k x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
rewrite notin_union. split.
apply (IHt1 k x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
apply (IHt (S k) x z) ; auto.
apply (IHt (S k) x z) ; auto.
rewrite notin_union. split.
apply (IHt1 (S k) x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
simpls. rewrite notin_union in *. destruct x_notin. split.
apply (IHt1 (S k) x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
rewrite notin_union. split.
apply (IHt1 (S k) x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
simpls. rewrite notin_union in *. destruct x_notin. split.
apply (IHt1 (S k) x z) ; simpls ; auto.
apply (IHt2 k x z) ; simpls ; auto.
Qed.
Lemma fv_open_subset : forall t k u, fv ({k~>u}t) << fv t \u fv u.
Proof.
intros t. induction t ; intros k x ; try simpl_subset.
induction n ; simpl ; case_nat ; simpl ; simpl_subset.
simpl. specialize (IHt1 k x). specialize (IHt2 k x). VSD.fsetdec.
simpl. apply IHt.
simpl. specialize (IHt1 (S k) x). specialize (IHt2 k x). VSD.fsetdec.
simpl. specialize (IHt1 (S k) x). specialize (IHt2 k x). VSD.fsetdec.
Qed.
Lemma fv_open_notin : forall t x k, x \notin fv ({k ~>pterm_fvar x}t) -> fv ({k~>pterm_fvar x}t) = fv t.
Proof.
intro t. induction t ; intros ; simpls ; auto.
case_nat ; simpls ; try reflexivity.
rewrite notin_singleton in H. contradiction H. reflexivity.
rewrite IHt1 ; auto. rewrite IHt2 ; auto.
rewrite IHt1 ; auto. rewrite IHt2 ; auto.
rewrite IHt1 ; auto. rewrite IHt2 ; auto.
Qed.
Lemma fv_in_open : forall t a x k, a \in fv ({k ~> pterm_fvar x}t) -> a \in fv t \u {{x}}.
Proof.
intros t a x k H. assert (fv ({k ~> pterm_fvar x}t) << fv t \u {{x}}). apply fv_open_subset. VSD.fsetdec.
Qed.
Lemma fv_open_in : forall t x, x \in fv (t^x) ->
fv (t^x) [=] fv t \u {{x}}.
Proof.
intros t. unfold open. generalize 0 as k. induction t ; intros k x x_in.
(* bvar *)
induction n ; unfold open ; simpl.
rewrite union_empty_l. case_nat.
reflexivity.
simpls. case_nat. contradiction (in_empty x_in).
case_nat.
simpl. rewrite union_empty_l. reflexivity.
simpls. case_nat.
case_nat. contradiction (e). simpls. contradiction (in_empty x_in).
case_nat. contradiction (in_empty x_in).
(* fvar *)
unfolds open. simpls. apply in_singleton in x_in.
rewrite x_in. rewrite union_same. reflexivity.
(* app *)
simpls.
rewrite in_union in x_in.
destruct x_in.
(* x \in fv ({k ~> pterm_fvar x}t1) *)
specialize (IHt1 k x H) ; rewrite IHt1 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
(* x \in fv ({k ~> pterm_fvar x}t2) *)
specialize (IHt2 k x H) ; rewrite IHt2 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
(* abs *)
simpls. rewrite <- IHt with (k:= S k). reflexivity. assumption.
(* Subs *)
simpls.
rewrite in_union in x_in.
destruct x_in.
(* x \in fv ({S k ~> pterm_fvar x}t1) *)
specialize (IHt1 (S k) x H) ; rewrite IHt1 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
(* x \in fv ({k ~> pterm_fvar x}t2) *)
specialize (IHt2 k x H) ; rewrite IHt2 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
(* Subs' *)
simpls.
rewrite in_union in x_in.
destruct x_in.
(* x \in fv ({S k ~> pterm_fvar x}t1) *)
specialize (IHt1 (S k) x H) ; rewrite IHt1 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
(* x \in fv ({k ~> pterm_fvar x}t2) *)
specialize (IHt2 k x H) ; rewrite IHt2 ; unfold VarSet.Equal.
intros a ; split ; intros a_in ; rewrite in_union in a_in ; destruct a_in ; try VSD.fsetdec .
compare a x ; intros ; [ VSD.fsetdec | rewrite fv_open_ in H0 ; VSD.fsetdec].
compare a x ; intros. VSD.fsetdec. rewrite in_union in *. destruct H0.
rewrite fv_open_ ; [VSD.fsetdec | assumption].
rewrite fv_open_ ; [VSD.fsetdec | assumption].
Qed.
Lemma fv_open_both_notin : forall t t' x, fv (t^x) [=] fv (t'^x) -> x \notin fv t -> x \notin fv t' -> fv t [=] fv t'.
Proof.
intros. assert (x \in fv (t ^x) \/ x \notin fv (t^x)). apply fv_in_or_notin. destruct H2.
(* x \in fv (t ^ x) *)
assert (x \in fv(t' ^x)). VSD.fsetdec.
rewrite (fv_open_in t H2) in H. rewrite (fv_open_in t' H3) in H.
VSD.fsetdec.
(* x \notin fv (t ^ x) *)
assert (x \notin fv(t' ^x)). VSD.fsetdec.
unfolds open.
rewrite (fv_open_notin t 0 H2) in H. rewrite (fv_open_notin t' 0 H3) in H.
assumption.
Qed.
Lemma fv_open_both_subset_notin : forall t t' x, fv (t^x) << fv (t'^x) -> x \notin fv t -> x \notin fv t' -> fv t << fv t'.
Proof.
intros. assert (x \in fv (t ^x) \/ x \notin fv (t^x)). apply fv_in_or_notin. destruct H2.
(* x \in fv (t ^ x) *)
assert (x \in fv(t' ^x)). VSD.fsetdec.
rewrite (fv_open_in t H2) in H. rewrite (fv_open_in t' H3) in H.
VSD.fsetdec.
(* x \notin fv (t ^ x) *)
unfolds open.
rewrite (fv_open_notin t 0 H2) in H. rewrite fv_open_subset in H.
simpl in H. VSD.fsetdec.
Qed.
Lemma fv_open_both_subset_context_notin : forall t t' x y, x<> y -> fv (t^x) << fv (t'^x) \u {{y}} ->
x \notin fv t -> x \notin fv t' -> fv t << fv t' \u {{y}}.
Proof.
intros. assert (x \in fv (t ^x) \/ x \notin fv (t^x)). apply fv_in_or_notin. destruct H3.
(* x \in fv (t ^ x) *)
assert (x \in fv(t' ^x)). VSD.fsetdec.
rewrite (fv_open_in t H3) in H0. rewrite (fv_open_in t' H4) in H0.
VSD.fsetdec.
(* x \notin fv (t ^ x) *)
unfolds open.
rewrite (fv_open_notin t 0 H3) in H0. rewrite fv_open_subset in H0.
simpl in H0. VSD.fsetdec.
Qed.
Lemma fv_open_both_notin_open : forall t t' x, fv (t^x) [=] fv (t'^x) -> x \notin fv (t^x) ->
x \notin fv (t'^x) -> fv t [=] fv t'.
Proof. intros. unfolds open. rewrite fv_open_notin in H ; rewrite fv_open_notin in H ; assumption. Qed.
Lemma fv_close : forall t k x, fv (close_rec k x t) [=] ((fv t) \rem x).
Proof.
intro t. induction t ; intros k x ; simpl ; try VSD.fsetdec.
case_var ; simpls ; VSD.fsetdec.
rewrite IHt2. rewrite IHt1. VSD.fsetdec.
apply IHt.
rewrite IHt2. rewrite IHt1. VSD.fsetdec.
rewrite IHt2. rewrite IHt1. VSD.fsetdec.
Qed.
Lemma fv_close' : forall t k x, x \notin fv (close_rec k x t).
Proof.
intro t. induction t ; intros k x ; simpl ; try VSD.fsetdec.
case_var ; simpls ; VSD.fsetdec.
apply notin_union. split.
apply IHt1. apply IHt2.
apply IHt.
apply notin_union. split.
apply IHt1. apply IHt2.
apply notin_union. split.
apply IHt1. apply IHt2.
Qed.