-
Notifications
You must be signed in to change notification settings - Fork 2
/
Types.v
566 lines (431 loc) · 13.4 KB
/
Types.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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
Require Export Conv.
Require Export Env.
Section Typage.
Inductive wf : env -> Prop :=
| wf_nil : wf nil
| wf_var : forall e T s, typ e T (Srt s) -> wf (T :: e)
with typ : env -> term -> term -> Prop :=
| type_prop :
forall e,
wf e ->
typ e (Srt prop) (Srt kind)
| type_var :
forall e v t,
wf e ->
item_lift t e v ->
typ e (Ref v) t
| type_abs :
forall e T M U s1 s2,
typ e T (Srt s1) ->
typ (T :: e) U (Srt s2) ->
typ (T :: e) M U ->
typ e (Abs T M) (Prod T U)
| type_app :
forall e u v V Ur,
typ e v V ->
typ e u (Prod V Ur) ->
typ e (App u v) (subst v Ur)
| type_prod :
forall e T U s1 s2,
typ e T (Srt s1) ->
typ (T :: e) U (Srt s2) ->
typ e (Prod T U) (Srt s2)
| type_conv :
forall e t U V s,
typ e t U ->
conv U V ->
typ e V (Srt s) ->
typ e t V.
Hint Resolve wf_nil type_prop type_var: coc.
Scheme typ_mind := Minimality for typ Sort Prop
with wf_mind := Minimality for wf Sort Prop.
Lemma typ_wf : forall e t T, typ e t T -> wf e.
simple induction 1; auto with coc.
Qed.
Hint Resolve typ_wf: coc.
Lemma wf_sort :
forall n e f t,
trunc (S n) e f -> wf e -> item t e n -> exists s, typ f t (Srt s).
simple induction n.
do 4 intro.
inversion_clear H.
inversion_clear H0.
intros.
inversion_clear H0.
inversion_clear H.
eauto with coc.
do 6 intro.
inversion_clear H0.
intros.
inversion_clear H2.
inversion_clear H0.
elim H with e0 f t; intros; eauto with coc.
Qed.
Definition inv_type (P : Prop) e t T :=
match t with
| Srt prop => conv T (Srt kind) -> P
| Srt kind => True
| Ref n => forall x, item x e n -> conv T (lift (S n) x) -> P
| Abs A M =>
forall s1 s2 U,
typ e A (Srt s1) ->
typ (A :: e) M U -> typ (A :: e) U (Srt s2) -> conv T (Prod A U) -> P
| App u v =>
forall Ur V,
typ e v V -> typ e u (Prod V Ur) -> conv T (subst v Ur) -> P
| Prod A B =>
forall s1 s2,
typ e A (Srt s1) -> typ (A :: e) B (Srt s2) -> conv T (Srt s2) -> P
end.
Lemma inv_type_conv :
forall P e t U V, conv U V -> inv_type P e t U -> inv_type P e t V.
do 6 intro.
cut (forall x : term, conv V x -> conv U x).
intro.
case t; simpl in |- *; intros.
generalize H1.
elim s; auto with coc; intros.
apply H1 with x; auto with coc.
apply H1 with s1 s2 U0; auto with coc.
apply H1 with Ur V0; auto with coc.
apply H1 with s1 s2; auto with coc.
intros.
apply trans_conv_conv with V; auto with coc.
Qed.
Theorem typ_inversion : forall P e t T, typ e t T -> inv_type P e t T -> P.
simple induction 1; simpl in |- *; intros.
auto with coc.
elim H1; intros.
apply H2 with x; auto with coc.
rewrite H3; auto with coc.
apply H6 with s1 s2 U; auto with coc.
apply H4 with Ur V; auto with coc.
apply H4 with s1 s2; auto with coc.
apply H1.
apply inv_type_conv with V; auto with coc.
Qed.
Lemma inv_typ_kind : forall e t, ~ typ e (Srt kind) t.
red in |- *; intros.
apply typ_inversion with e (Srt kind) t; simpl in |- *; auto with coc.
Qed.
Lemma inv_typ_prop : forall e T, typ e (Srt prop) T -> conv T (Srt kind).
intros.
apply typ_inversion with e (Srt prop) T; simpl in |- *; auto with coc.
Qed.
Lemma inv_typ_ref :
forall (P : Prop) e T n,
typ e (Ref n) T ->
(forall U : term, item U e n -> conv T (lift (S n) U) -> P) -> P.
intros.
apply typ_inversion with e (Ref n) T; simpl in |- *; intros; auto with coc.
apply H0 with x; auto with coc.
Qed.
Lemma inv_typ_abs :
forall (P : Prop) e A M U,
typ e (Abs A M) U ->
(forall s1 s2 T,
typ e A (Srt s1) ->
typ (A :: e) M T -> typ (A :: e) T (Srt s2) -> conv (Prod A T) U -> P) ->
P.
intros.
apply typ_inversion with e (Abs A M) U; simpl in |- *; auto with coc; intros.
apply H0 with s1 s2 U0; auto with coc.
Qed.
Lemma inv_typ_app :
forall (P : Prop) e u v T,
typ e (App u v) T ->
(forall V Ur, typ e u (Prod V Ur) -> typ e v V -> conv T (subst v Ur) -> P) ->
P.
intros.
apply typ_inversion with e (App u v) T; simpl in |- *; auto with coc; intros.
apply H0 with V Ur; auto with coc.
Qed.
Lemma inv_typ_prod :
forall (P : Prop) e T U s,
typ e (Prod T U) s ->
(forall s1 s2,
typ e T (Srt s1) -> typ (T :: e) U (Srt s2) -> conv (Srt s2) s -> P) -> P.
intros.
apply typ_inversion with e (Prod T U) s; simpl in |- *; auto with coc; intros.
apply H0 with s1 s2; auto with coc.
Qed.
Lemma typ_mem_kind : forall e t T, mem_sort kind t -> ~ typ e t T.
red in |- *; intros.
apply typ_inversion with e t T; auto with coc.
generalize e T.
clear H0.
elim H; simpl in |- *; auto with coc; intros.
apply typ_inversion with e0 u (Srt s1); auto with coc.
apply typ_inversion with (u :: e0) v (Srt s2); auto with coc.
apply typ_inversion with e0 u (Srt s1); auto with coc.
apply typ_inversion with (u :: e0) v U; auto with coc.
apply typ_inversion with e0 u (Prod V Ur); auto with coc.
apply typ_inversion with e0 v V; auto with coc.
Qed.
Lemma inv_typ_conv_kind : forall e t T, conv t (Srt kind) -> ~ typ e t T.
intros.
apply typ_mem_kind.
apply red_sort_mem.
elim church_rosser with t (Srt kind); intros; auto with coc.
rewrite (red_normal (Srt kind) x); auto with coc.
red in |- *; red in |- *; intros.
inversion_clear H2.
Qed.
Lemma typ_weak_weak :
forall A e t T,
typ e t T ->
forall n f,
ins_in_env A n e f -> wf f -> typ f (lift_rec 1 t n) (lift_rec 1 T n).
simple induction 1; simpl in |- *; intros; auto with coc.
elim (le_gt_dec n v); intros; apply type_var; auto with coc.
apply ins_item_lift_ge with A e0; auto with coc.
apply ins_item_lift_lt with A e0; auto with coc.
cut (wf (lift_rec 1 T0 n :: f)).
intro.
apply type_abs with s1 s2; auto with coc.
apply wf_var with s1; auto with coc.
rewrite distr_lift_subst.
apply type_app with (lift_rec 1 V n); auto with coc.
cut (wf (lift_rec 1 T0 n :: f)).
intro.
apply type_prod with s1; auto with coc.
apply wf_var with s1; auto with coc.
apply type_conv with (lift_rec 1 U n) s; auto with coc.
Qed.
Theorem thinning :
forall e t T A,
typ e t T -> wf (A :: e) -> typ (A :: e) (lift 1 t) (lift 1 T).
unfold lift in |- *.
intros.
inversion_clear H0.
apply typ_weak_weak with A e; auto with coc.
apply wf_var with s; auto with coc.
Qed.
Lemma thinning_n :
forall n e f t T,
trunc n (e:env) (f:env) ->
typ f t T -> wf e -> typ e (lift n t) (lift n T).
simple induction 1.
intros.
rewrite lift0.
rewrite lift0.
trivial.
intros.
rewrite simpl_lift; auto with coc.
pattern (lift (S k) T) in |- *.
rewrite simpl_lift; auto with coc.
apply thinning; auto with coc.
apply H1; trivial.
inversion_clear H3.
eauto with coc.
Qed.
Lemma wf_sort_lift :
forall n e t, wf e -> item_lift t e n -> exists s, typ e t (Srt s).
simple induction n.
simple destruct e; intros.
elim H0; intros.
inversion_clear H2.
elim H0; intros.
rewrite H1.
inversion_clear H2.
inversion_clear H.
exists s.
replace (Srt s) with (lift 1 (Srt s)); auto with coc.
apply thinning; auto with coc.
apply wf_var with s; auto with coc.
intros.
elim H1; intros.
rewrite H2.
generalize H0.
inversion_clear H3; intros.
rewrite simpl_lift; auto with coc.
cut (wf l); intros.
elim H with l (lift (S n0) x); intros; auto with coc.
inversion_clear H3.
exists x0.
change (typ (y :: l) (lift 1 (lift (S n0) x)) (lift 1 (Srt x0))) in |- *.
apply thinning; auto with coc.
apply wf_var with s; auto with coc.
exists x; auto with coc.
inversion_clear H3.
eauto with coc.
Qed.
Lemma typ_sub_weak :
forall g d t e u U,
typ g d t ->
typ e u U ->
forall f n,
sub_in_env d t n e f ->
wf f -> trunc n f g -> typ f (subst_rec d u n) (subst_rec d U n).
Proof.
simple induction 2; simpl in |- *; intros; auto with coc.
destruct (lt_eq_lt_dec n v) as [[fvar|eq_var]|bvar].
constructor; trivial.
apply sub_item_lift_sup with (1 := H3) (2 := fvar) (3 := H2).
subst v; rewrite sub_item_lift_eq with (1 := H3) (2 := H2).
apply thinning_n with g; auto with coc.
constructor; trivial.
apply nth_sub_inf with (1 := H3); trivial.
cut (wf (subst_rec d T n :: f)); intros.
apply type_abs with s1 s2; auto with coc.
apply wf_var with s1; auto with coc.
rewrite distr_subst.
apply type_app with (subst_rec d V n); auto with coc.
cut (wf (subst_rec d T n :: f)); intros.
apply type_prod with s1; auto with coc.
apply wf_var with s1; auto with coc.
apply type_conv with (subst_rec d U0 n) s; auto with coc.
Qed.
Theorem substitution :
forall e t u U d,
typ (t :: (e:env)) u U -> typ e d t -> typ e (subst d u) (subst d U).
intros.
unfold subst in |- *.
apply typ_sub_weak with e t (t :: e); auto with coc.
apply typ_wf with d t; auto with coc.
Qed.
Theorem typ_unique :
forall e t T, typ e t T -> forall U, typ e t U -> conv T U.
simple induction 1; intros.
apply sym_conv.
apply inv_typ_prop with e0; auto with coc.
apply inv_typ_ref with e0 U v; auto with coc; intros.
elim H1; intros.
rewrite H5.
elim fun_item with (1 := H3) (2 := H6); auto with coc.
apply inv_typ_abs with (1 := H6); intros.
apply trans_conv_conv with (Prod T0 T1); auto with coc.
apply inv_typ_app with (1 := H4); intros.
apply trans_conv_conv with (subst v Ur0); auto with coc.
unfold subst in |- *; apply conv_conv_subst; auto with coc.
apply inv_conv_prod_r with (1 := H3 _ H5).
apply inv_typ_prod with (1 := H4); intros.
apply trans_conv_conv with (Srt s3); auto with coc.
apply trans_conv_conv with U; auto with coc.
Qed.
Theorem type_case :
forall e t T, typ e t T -> (exists s, typ e T (Srt s)) \/ T = Srt kind.
simple induction 1; intros; auto with coc.
left.
elim wf_sort_lift with (2 := H1); trivial; intros.
exists x; auto with coc.
left.
exists s2.
apply type_prod with s1; auto with coc.
left.
elim H3; intros.
elim H4; intros.
apply inv_typ_prod with (1 := H5); intros.
exists s2.
replace (Srt s2) with (subst v (Srt s2)); auto with coc.
apply substitution with V; auto with coc.
discriminate H4.
case s2; auto with coc.
left.
exists kind.
apply type_prop.
apply typ_wf with (1 := H0).
left.
exists s; auto with coc.
Qed.
Lemma type_kind_not_conv :
forall e t T, typ e t T -> typ e t (Srt kind) -> T = Srt kind.
intros.
elim type_case with e t T; intros; auto with coc.
elim H1; intros.
elim inv_typ_conv_kind with e T (Srt x); auto with coc.
apply typ_unique with e t; trivial.
Qed.
Lemma typ_red_env :
forall e t T, typ e t T ->
forall f, red1_in_env red1 e f -> wf f -> typ f t T.
simple induction 1; intros.
auto with coc.
elim red_item with (2 := H1) (3 := H2); auto with coc; intros.
inversion_clear H4.
inversion_clear H6.
elim H1; intros.
elim item_trunc with (1 := H8); intros.
elim wf_sort with (1 := H9) (3 := H8); eauto; intros.
apply type_conv with x x2; auto with coc.
rewrite H6.
replace (Srt x2) with (lift (S v) (Srt x2)); auto with coc.
apply thinning_n with x1; auto with coc.
cut (wf (T0 :: f)); intros.
apply type_abs with s1 s2; auto with coc.
apply wf_var with s1; auto with coc.
apply type_app with V; auto with coc.
cut (wf (T0 :: f)); intros.
apply type_prod with s1; auto with coc.
apply wf_var with s1; auto with coc.
apply type_conv with U s; auto with coc.
Qed.
Lemma subj_red : forall e t T, typ e t T -> forall u, red1 t u -> typ e u T.
simple induction 1; intros.
inversion_clear H1.
inversion_clear H2.
inversion_clear H6.
cut (wf (M' :: e0)); intros.
apply type_conv with (Prod M' U) s2; auto with coc.
apply type_abs with s1 s2; auto with coc.
apply typ_red_env with (T0 :: e0); auto with coc.
apply typ_red_env with (T0 :: e0); auto with coc.
apply type_prod with s1; auto with coc.
apply wf_var with s1; auto with coc.
apply type_abs with s1 s2; auto with coc.
elim type_case with (1 := H2); intros.
inversion_clear H5.
apply inv_typ_prod with (1 := H6); intros.
generalize H2 H3; clear H2 H3.
inversion_clear H4; intros.
apply inv_typ_abs with (1 := H2); intros.
apply type_conv with (subst v T1) s2; auto with coc.
apply substitution with T0; auto with coc.
apply type_conv with V s0; auto with coc.
apply sym_conv.
apply inv_conv_prod_l with (1 := H11).
unfold subst in |- *.
apply conv_conv_subst; auto with coc.
apply inv_conv_prod_r with (1 := H11); auto with coc.
replace (Srt s2) with (subst v (Srt s2)); auto with coc.
apply substitution with V; auto with coc.
apply type_app with V; auto with coc.
apply type_conv with (subst N2 Ur) s2; auto with coc.
apply type_app with V; auto with coc.
unfold subst in |- *.
apply conv_conv_subst; auto with coc.
replace (Srt s2) with (subst v (Srt s2)); auto with coc.
apply substitution with V; auto with coc.
discriminate H5.
inversion_clear H4.
apply type_prod with s1; auto with coc.
apply typ_red_env with (T0 :: e0); auto with coc.
apply wf_var with s1; auto with coc.
apply type_prod with s1; auto with coc.
apply type_conv with U s; auto with coc.
Qed.
Theorem subject_reduction :
forall e t u, red t u -> forall T, typ e t T -> typ e u T.
simple induction 1; intros; auto with coc.
apply subj_red with P; intros; auto with coc.
Qed.
Lemma type_reduction : forall e t T U, red T U -> typ e t T -> typ e t U.
intros.
elim type_case with (1 := H0); intros.
inversion_clear H1.
apply type_conv with T x; auto with coc.
apply subject_reduction with T; trivial.
elim red_normal with (1 := H); trivial.
rewrite H1.
red in |- *; red in |- *; intros.
inversion_clear H2.
Qed.
Lemma typ_conv_conv :
forall e u U v V, typ e u U -> typ e v V -> conv u v -> conv U V.
intros.
elim church_rosser with (1 := H1); auto with coc; intros.
apply typ_unique with e x.
apply subject_reduction with u; trivial.
apply subject_reduction with v; trivial.
Qed.
End Typage.