forked from Barry-Jay/lambdaSF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnstar.v
417 lines (388 loc) · 14.3 KB
/
Unstar.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
(* 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 *)
(**********************************************************************)
(* Intensional Lambda Calculus *)
(* *)
(* is implemented in Coq by adapting the implementation of *)
(* Lambda Calculus from Project Coq *)
(* 2015 *)
(**********************************************************************)
(**********************************************************************)
(* Analysis.v *)
(* *)
(* Barry Jay *)
(* *)
(**********************************************************************)
Require Import Arith.
Require Import Max.
Require Import Test.
Require Import General.
Require Import LamSF_Terms.
Require Import LamSF_Substitution_term.
Require Import LamSF_Tactics.
Require Import Beta_Reduction.
Require Import LamSF_Confluence.
Require Import SF_reduction.
Require Import LamSF_reduction.
Require Import LamSF_Normal.
Require Import LamSF_Closed.
Require Import LamSF_Eval.
Require Import Eta.
Require Import Equal.
Require Import Combinators.
Require Import Binding.
Require Import Omega.
(* unstar *)
(*
Fixpoint star M :=
match M with
| Ref 0 => i_op
| Ref (S n) => App k_op (Ref n)
| Op o => App k_op (Op o)
| Abs M1 => Abs (star M1)
| App M1 M2 => App (App s_op (Abs M1)) (Abs M2)
end
.
unstar =
| S M N => abs_S M N
| K M => abs_K M
| M as Abs _ => Abs (unstar (M (Ref 0)))
| O => O
*)
Definition unstar_fn :=
Abs (Abs (App (App (App f_op (Ref 0)) (Ref 0)) (Abs (Abs
(App (App (App (App equal abs_left) (Ref 1)) (Abs (App (Ref 4) (App (Ref 3) (Ref 0)))))
(App (App (App (App equal k_op) (Ref 1)) (App abs_K (Ref 0)))
(App (App (App f_op (Ref 1)) (Ref 2)) (Abs (Abs
(App (App abs_S (Ref 0)) (Ref 2))
)))))))))
.
Definition unstar := App fixpoint unstar_fn.
Theorem unstar_star : forall M, normal M -> lamSF_red (App unstar (star M)) (Abs M).
Proof.
induction M; split_all.
(* 4 *)
unfold unstar. fixtac. fold unstar. unfold unstar_fn.
case n; split_all.
(* 5 *)
eval_lamSF. unfold subst_rec; fold subst_rec. insert_Ref_out.
eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
repeat (rewrite (subst_rec_closed unstar); [| split_all]).
unfold subst_rec; fold subst_rec. insert_Ref_out.
repeat (rewrite (subst_rec_closed abs_K); [| split_all]).
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App (App k_op i_op) M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App (App k_op i_op) M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF. eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed abs_S); [| split_all]).
unfold abs_S.
eval_lamSF.
unfold subst_rec; fold subst_rec. insert_Ref_out.
eapply2 preserves_abs_lamSF_red.
(* 4 *)
eval_lamSF.
unfold subst_rec; fold subst_rec. insert_Ref_out.
eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
unfold subst_rec; fold subst_rec. insert_Ref_out.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App (App k_op i_op) M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App k_op M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 equal_programs; split_all.
eval_lamSF.
repeat (rewrite (subst_rec_closed abs_K); [| split_all]).
unfold abs_K.
eval_lamSF.
relocate_lt.
simpl. auto.
(* 3 *)
unfold unstar. fixtac. fold unstar. unfold unstar_fn.
eval_lamSF. unfold subst_rec; fold subst_rec. insert_Ref_out.
eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
repeat (rewrite (subst_rec_closed unstar); [| split_all]).
unfold subst_rec; fold subst_rec. insert_Ref_out.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App (App k_op i_op) M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App k_op M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 equal_programs; split_all.
eval_lamSF.
repeat (rewrite (subst_rec_closed abs_K); [| split_all]).
unfold abs_K. eval_lamSF. auto.
(* 2 *)
unfold unstar. fixtac. fold unstar. unfold unstar_fn.
eval_lamSF. unfold subst_rec; fold subst_rec. insert_Ref_out.
match goal with
| |- multi_step lamSF_red1 (App (App (App (Op Fop) ?M1) _)?N) _ =>
apply succ_red with (App (App N (left_component M1)) (right_component M1))
end.
eapply2 f_compound_lamSF_red.
rewrite lift_rec_preserves_star. rewrite lift_rec_null.
eapply2 abs_compound_compound.
eapply2 star_compound.
eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
unfold left_component; fold left_component.
rewrite lift_rec_closed;[| split_all].
rewrite subst_rec_closed;[| split_all].
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App k_op M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
unfold_op.
eapply2 equal_programs; split_all.
eval_lamSF.
eapply2 preserves_abs_lamSF_red.
rewrite subst_rec_lift_rec; try omega.
rewrite subst_rec_lift_rec; try omega.
rewrite subst_rec_lift_rec; try omega.
rewrite lift_rec_closed. 2: split_all.
rewrite subst_rec_lift_rec; try omega.
rewrite subst_rec_lift_rec; try omega.
apply transitive_red with (App unstar (star M)).
eapply2 preserves_app_lamSF_red.
eval_lamSF.
rewrite subst_rec_lift_rec2.
auto.
inversion H; eapply2 IHM.
(* 1 *)
unfold unstar. fixtac. fold unstar. unfold unstar_fn.
eval_lamSF. unfold subst_rec; fold subst_rec. insert_Ref_out.
eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
unfold subst_rec; fold subst_rec. insert_Ref_out.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M)?N) _ =>
apply transitive_red with (App (App (App k_op i_op) M)N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
match goal with
| |- lamSF_red (App (App _ ?M) ?N) _ =>
apply transitive_red with
(App (App (App (App equal (left_component M)) (left_component N))
(App (App equal (right_component M)) (right_component N)))
(App k_op i_op))
end.
eapply2 equal_compounds.
simpl.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M) ?N) _ =>
apply transitive_red with
(App (App (App k_op i_op) M) N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF. auto.
eval_lamSF. eval_lamSF.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M) ?N) _ =>
apply transitive_red with
(App (App (App k_op i_op) M) N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
match goal with
| |- lamSF_red (App (App _ ?M) ?N) _ =>
apply transitive_red with
(App (App (App (App equal (left_component M)) (left_component N))
(App (App equal (right_component M)) (right_component N)))
(App k_op i_op))
end.
eapply2 equal_compounds.
simpl.
match goal with
| |- multi_step lamSF_red1 (App (App _ ?M) ?N) _ =>
apply transitive_red with
(App (App (App k_op i_op) M) N)
end.
eapply2 preserves_app_lamSF_red.
eapply2 preserves_app_lamSF_red.
eapply2 unequal_programs; split_all.
eval_lamSF. eval_lamSF. auto.
eval_lamSF. eval_lamSF.
eval_lamSF. eval_lamSF.
repeat (rewrite (subst_rec_closed equal); [| split_all]).
unfold abs_S; unfold subst_rec; fold subst_rec. insert_Ref_out.
eval_lamSF.
unfold subst_rec; fold subst_rec. insert_Ref_out.
eapply2 preserves_abs_lamSF_red.
unfold subst_rec; fold subst_rec. insert_Ref_out.
unfold subst_rec; fold subst_rec. insert_Ref_out.
unfold subst_rec; fold subst_rec. insert_Ref_out.
unfold subst_rec; fold subst_rec. insert_Ref_out.
unfold subst_rec; fold subst_rec. insert_Ref_out.
rewrite subst_rec_lift_rec; try omega.
rewrite subst_rec_lift_rec; try omega.
rewrite lift_rec_lift_rec; try omega.
rewrite lift_rec_null.
simpl.
rewrite subst_rec_lift_rec; try omega.
rewrite subst_rec_lift_rec; try omega.
rewrite lift_rec_lift_rec; try omega.
simpl.
eapply2 preserves_app_lamSF_red.
eval_lamSF.
rewrite subst_rec_lift_rec2. auto.
eval_lamSF.
rewrite subst_rec_lift_rec2. auto.
Qed.
Definition wait M N := App (App s_op (App (App s_op (App k_op M)) (App k_op N))) i_op .
Lemma rank_wait : forall M N, rank (wait M N) = 23 + rank M + rank N.
Proof. unfold_op; unfold rank; fold rank. split_all. omega. Qed.
Definition tag T M := App (App s_op (App k_op M)) (App (App s_op k_op) T).
(*
Definition abs_left := App (App s_op k_op) f_op
*)
Definition abs_tag := tag f_op.
Definition com_tag := tag s_op.
Definition app_tag M N := tag k_op (wait M N).
Ltac unfold_op ::= unfold abs_tag, abs_left, com_tag, app_tag, tag, wait, i_op, id, k_op, f_op, s_op.
Lemma wait_ext : forall M N, beta_eta_eq (wait M N) (App M N).
Proof.
split_all; unfold wait.
assert(beta_eta_eq (App (App s_op (App (App s_op (App k_op M)) (App k_op N))) i_op)
(Abs (App (lift_rec (App (App s_op (App (App s_op (App k_op M)) (App k_op N))) i_op) 0 1) (Ref 0)))) by auto.
simpl in *.
assert(beta_eta_eq (Abs
(App
(App
(App (Op Sop)
(App
(App (Op Sop)
(App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Fop) (Op Fop)) (lift_rec N 0 1))))
(App (App (Op Sop) (App (Op Fop) (Op Fop)))
(App (Op Fop) (Op Fop)))) (Ref 0)))
(Abs (App (App (lift_rec M 0 1) (lift_rec N 0 1)) (Ref 0)))).
eapply2 abs_etared.
assert(beta_eta_eq
(App
(App
(App (Op Sop)
(App
(App (Op Sop) (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Fop) (Op Fop)) (lift_rec N 0 1))))
(App (App (Op Sop) (App (Op Fop) (Op Fop)))
(App (Op Fop) (Op Fop)))) (Ref 0))
(App
(App (App (App (Op Sop) (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Fop) (Op Fop)) (lift_rec N 0 1))) (Ref 0))
(App i_op (Ref 0)))).
auto.
assert(beta_eta_eq
(App
(App
(App
(App (Op Sop)
(App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Fop) (Op Fop)) (lift_rec N 0 1)))
(Ref 0)) (App i_op (Ref 0)))
(App (App (App (App k_op (lift_rec M 0 1)) (Ref 0)) (App (App k_op (lift_rec N 0 1)) (Ref 0)))
(Ref 0))).
eapply2 app_etared.
unfold_op; auto.
assert(beta_eta_eq (App
(App (App (Op Sop) (App (Op Fop) (Op Fop))) (App (Op Fop) (Op Fop)))
(Ref 0)) (App (App k_op (Ref 0)) (App k_op (Ref 0)))).
auto.
assert(beta_eta_eq (App (App k_op (Ref 0)) (App k_op (Ref 0))) (Ref 0)).
unfold_op. eauto.
eauto.
assert(beta_eta_eq (App
(App (App (App k_op (lift_rec M 0 1)) (Ref 0))
(App (App k_op (lift_rec N 0 1)) (Ref 0)))
(Ref 0))
(App (App (lift_rec M 0 1) (lift_rec N 0 1)) (Ref 0))).
unfold_op.
eapply2 app_etared.
eapply trans_etared. eexact H0.
eapply trans_etared. eexact H1.
eapply trans_etared. eexact H2.
eauto.
(* 1 *)
assert(beta_eta_eq (App M N) (Abs (App (lift_rec (App M N) 0 1) (Ref 0)))) by auto.
simpl in *.
eauto.
Qed.
Lemma tag_ext : forall T M, beta_eta_eq (tag T M) M.
Proof. split_all; unfold tag; unfold_op.
assert(beta_eta_eq (App (App (Op Sop) (App (App (Op Fop) (Op Fop)) M))
(App (App (Op Sop) (App (Op Fop) (Op Fop))) T)) (Abs (App (lift_rec (App (App (Op Sop) (App (App (Op Fop) (Op Fop)) M))
(App (App (Op Sop) (App (Op Fop) (Op Fop))) T)) 0 1) (Ref 0)))) .
eapply2 symm_etared.
simpl in *.
assert(beta_eta_eq (Abs
(App
(App
(App (Op Sop) (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Sop) (App (Op Fop) (Op Fop))) (lift_rec T 0 1)))
(Ref 0)))
(Abs (App (lift_rec M 0 1) (Ref 0)))).
eapply2 abs_etared.
assert(beta_eta_eq (App
(App (App (Op Sop) (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)))
(App (App (Op Sop) (App (Op Fop) (Op Fop))) (lift_rec T 0 1)))
(Ref 0))
(App (App (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)) (Ref 0))
(App (App (App (Op Sop) (App (Op Fop) (Op Fop))) (lift_rec T 0 1))
(Ref 0)))). auto.
assert(beta_eta_eq
(App (App (App (App (Op Fop) (Op Fop)) (lift_rec M 0 1)) (Ref 0))
(App (App (App (Op Sop) (App (Op Fop) (Op Fop))) (lift_rec T 0 1))
(Ref 0)))
(App (lift_rec M 0 1) (Ref 0))).
eapply2 app_etared.
eauto.
eauto.
Qed.