-
Notifications
You must be signed in to change notification settings - Fork 2
/
ObjectSN.v
1362 lines (1157 loc) · 30.7 KB
/
ObjectSN.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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Export basic.
Require Import Models.
Require Import VarMap.
Require Lambda.
Module Lc := Lambda.
Module MakeObject (M: CC_Model).
Import M.
(** Valuations *)
Module Xeq.
Definition t := X.
Definition eq := eqX.
Definition eq_equiv : Equivalence eq := eqX_equiv.
Existing Instance eq_equiv.
End Xeq.
Module V := VarMap.Make(Xeq).
Notation val := V.map.
Notation eq_val := V.eq_map.
Definition vnil : val := V.nil props.
Existing Instance V.cons_morph.
Existing Instance V.cons_morph'.
Existing Instance V.shift_morph.
Existing Instance V.lams_morph.
(* Term valuations *)
Module I := Lambda.I.
(** Pseudo-terms *)
Module T.
Record infterm := {
iint : val -> X;
iint_morph : Proper (eq_val ==> eqX) iint;
itm : Lc.intt -> Lc.term;
itm_morph : Proper (Lc.eq_intt ==> eq) itm;
itm_lift : Lc.liftable itm;
itm_subst : Lc.substitutive itm
}.
Existing Instance iint_morph.
Existing Instance itm_morph.
Definition term := option infterm.
Definition eq_term (x y:term) :=
match x, y with
| Some f, Some g =>
(eq_val ==> eqX)%signature (iint f) (iint g) /\
(Lc.eq_intt ==> eq)%signature (itm f) (itm g)
| None, None => True
| _, _ => False
end.
Instance eq_term_refl : Reflexive eq_term.
red; intros.
destruct x as [(f,mf,g,mg,sg)|]; simpl; auto.
Qed.
Instance eq_term_sym : Symmetric eq_term.
red; intros.
destruct x as [(fx,mfx,gx,mgx,sgx)|];
destruct y as [(fy,mfy,gy,mgy,sgy)|]; simpl in *; auto.
destruct H; split; symmetry; trivial.
Qed.
Instance eq_term_trans : Transitive eq_term.
red; intros.
destruct x as [(fx,mfx,gx,mgx,sgx)|];
destruct y as [(fy,mfy,gy,mgy,sgy)|];
destruct z as [(fz,mfz,gz,mgz,sgz)|];
try contradiction; simpl in *; auto.
destruct H; destruct H0; split.
transitivity fy; trivial.
transitivity gy; trivial.
Qed.
Instance eq_term_equiv : Equivalence eq_term.
constructor; auto with *.
Qed.
Lemma eq_kind : forall (M:term), M = None <-> eq_term M None.
destruct M; simpl; split; contradiction||discriminate||trivial.
Qed.
Definition dummy_term : Lc.term.
exact Lc.K.
Defined.
(* The only fact needed is that dummy_term is a closed term *)
Definition tm (M:term) (j:Lc.intt) :=
match M with
| Some f => itm f j
| None => dummy_term
end.
Instance tm_morph : Proper (eq_term ==> Lc.eq_intt ==> @eq Lc.term) tm.
unfold tm; do 3 red; intros.
destruct x; destruct y; simpl in *; (contradiction||reflexivity||auto).
destruct H; simpl in *.
apply H1; trivial.
Qed.
Lemma tm_substitutive : forall u t j k,
tm t (fun n => Lc.subst_rec u (j n) k) =
Lc.subst_rec u (tm t j) k.
destruct t; simpl; intros; trivial.
apply itm_subst.
Qed.
Lemma tm_liftable : forall j t k,
tm t (fun n => Lc.lift_rec 1 (j n) k) = Lc.lift_rec 1 (tm t j) k.
destruct t; simpl; intros; trivial.
apply itm_lift.
Qed.
Lemma tm_subst_cons : forall x j t,
tm t (I.cons x j) = Lc.subst x (tm t (Lc.ilift j)).
unfold Lc.subst; intros.
rewrite <- tm_substitutive.
apply tm_morph; [reflexivity|red; intros].
red.
destruct a; simpl.
rewrite Lc.lift0; trivial.
rewrite Lc.simpl_subst; trivial; rewrite Lc.lift0; trivial.
Qed.
Definition dummy_int : X.
Proof props.
Definition int (M:term) (i:val) :=
match M with
| Some f => iint f i
| None => dummy_int
end.
Instance int_morph : Proper (eq_term ==> eq_val ==> eqX) int.
unfold int; do 3 red; intros.
destruct x; destruct y; simpl in *; (contradiction||reflexivity||auto).
destruct H; simpl in *.
apply H; trivial.
Qed.
Lemma eq_term_intro : forall T T',
(forall i, int T i == int T' i) ->
(forall j, tm T j = tm T' j) ->
match T, T' with Some _,Some _=>True|None,None=>True|_,_=>False end ->
eq_term T T'.
destruct T as [T|]; destruct T' as [T'|]; simpl; intros; trivial.
split; red; intros.
rewrite H2; auto.
rewrite H2; auto.
Qed.
(** Substitutions *)
Record sub_ := {
sint : val -> val;
sint_morph : Proper (eq_val ==> eq_val) sint;
stm : Lc.intt -> Lc.intt;
stm_morph : Proper (Lc.eq_intt ==> Lc.eq_intt) stm;
stm_lift : forall n, Lc.liftable (fun j => stm j n);
stm_subst : forall n, Lc.substitutive (fun j => stm j n)
}.
Definition sub := sub_.
Definition eq_sub (s1 s2:sub) :=
(eq_val ==> eq_val)%signature (sint s1) (sint s2) /\
(Lc.eq_intt ==> Lc.eq_intt)%signature (stm s1) (stm s2).
Global Instance eq_sub_equiv : Equivalence eq_sub.
split; red; intros.
red; split;red; intros; auto with *.
apply sint_morph; trivial.
apply stm_morph; trivial.
destruct H.
red; split;red; intros; auto with *.
symmetry; apply H; symmetry; trivial.
symmetry; apply H0; symmetry; trivial.
destruct H; destruct H0.
red; split; red; intros.
transitivity (sint y x0); auto.
apply H; reflexivity.
transitivity (stm y x0); auto.
apply H1; reflexivity.
Qed.
Definition sub_comp (s1 s2 : sub) : sub.
(*begin show*)
exists (fun i => sint s1 (sint s2 i))
(fun j => stm s1 (stm s2 j)).
(*end show*)
do 2 red; intros.
do 2 apply sint_morph; trivial.
do 2 red; intros.
do 2 apply stm_morph; trivial.
red; intros.
eapply transitivity.
2:apply (stm_lift s1).
assert (s1m := stm_morph s1).
apply s1m.
intros i.
apply (stm_lift s2).
red; intros.
eapply transitivity.
2:apply (stm_subst s1).
assert (s1m := stm_morph s1).
apply s1m.
intros i.
apply (stm_subst s2).
Defined.
Definition sub_id : sub.
(*begin show*)
exists (fun i => i) (fun j => j).
(*end show*)
do 2 red; intros; trivial.
do 2 red; intros; trivial.
red; intros; reflexivity.
red; intros; reflexivity.
Defined.
Definition sub_cons (t:term) (s:sub) : sub.
(*begin show*)
exists (fun i => V.cons (int t i) (sint s i))
(fun j => I.cons (tm t j) (stm s j)).
(*end show*)
do 2 red; intros.
apply V.cons_morph.
rewrite H; reflexivity.
apply sint_morph; trivial.
do 2 red; intros.
apply I.cons_morph.
rewrite H; reflexivity.
apply stm_morph; trivial.
destruct n; red; intros.
apply tm_liftable.
apply (stm_lift s).
destruct n; red; intros.
apply tm_substitutive.
apply (stm_subst s).
Defined.
Definition sub_lift (k:nat) (s:sub) : sub.
(*begin show*)
exists (V.lams k (sint s)) (I.lams k (stm s)).
(*end show*)
do 2 red; intros.
apply V.lams_morph; auto with *.
apply sint_morph.
do 2 red; intros.
apply I.lams_morph; auto with *.
apply stm_morph.
red; intros.
unfold I.lams.
destruct (le_gt_dec k n); trivial.
unfold I.shift.
apply (stm_lift s).
red; intros.
unfold I.lams.
destruct (le_gt_dec k n); trivial.
unfold I.shift.
apply (stm_subst s).
Defined.
Definition sub_shift (n:nat) : sub.
(*begin show*)
exists (V.shift n) (I.shift n).
(*end show*)
do 2 red; intros.
apply V.shift_morph; trivial.
do 2 red; intros.
apply I.shift_morph; trivial.
red; intros; reflexivity.
red; intros; reflexivity.
Defined.
Definition Sub (t:term) (s:sub) : term.
(*begin show*)
destruct t as [t|]; [left|exact None].
exists (fun i => iint t (sint s i))
(fun j => itm t (stm s j)).
(*end show*)
do 2 red; intros.
apply iint_morph; apply sint_morph; trivial.
do 2 red; intros.
apply itm_morph; apply stm_morph; trivial.
red; intros.
eapply transitivity.
2:apply (itm_lift t).
apply (itm_morph t).
intros i.
apply (stm_lift s).
red; intros.
eapply transitivity.
2:apply (itm_subst t).
apply (itm_morph t).
intros i.
apply (stm_subst s).
Defined.
Lemma int_Sub_eq t s i :
int (Sub t s) i == int t (sint s i).
destruct t as [t|]; simpl;reflexivity.
Qed.
Lemma tm_Sub_eq t s j :
tm (Sub t s) j = tm t (stm s j).
destruct t as [t|]; simpl; reflexivity.
Qed.
Lemma eq_Sub_comp t s1 s2 :
eq_term (Sub (Sub t s1) s2) (Sub t (sub_comp s1 s2)).
apply eq_term_intro; intros.
rewrite !int_Sub_eq.
unfold sub_comp; simpl; reflexivity.
rewrite !tm_Sub_eq.
unfold sub_comp; simpl; reflexivity.
destruct t as [t|]; simpl; trivial.
Qed.
(** Property of substitutivity: whenever a term-denotation contains
a free var, then it comes from the term-valuation (but we can't tell which
var, short of using Markov rule, hence the double negation.
*)
Lemma tm_closed : forall k j M,
Lc.occur k (tm M j) -> ~ forall n, ~ Lc.occur k (j n).
red; intros.
rewrite Lc.occur_subst in H.
rewrite <- tm_substitutive in H.
rewrite <- tm_liftable in H.
apply H; clear H.
apply tm_morph; auto with *.
red; red; intros.
generalize (H0 a).
rewrite Lc.occur_subst; intro.
destruct (Lc.eqterm (Lc.lift_rec 1 (Lc.subst_rec (Lc.Abs (Lc.Ref 0)) (j a) k) k) (j a)); auto.
contradiction.
Qed.
(** Lift and substitution *)
Definition lift_rec (n m:nat) (t:term) : term.
(*begin show*)
destruct t as [t|]; [left|exact None].
exists (fun i => iint t (V.lams m (V.shift n) i))
(fun j => itm t (I.lams m (I.shift n) j)).
(*end show*)
do 2 red; intros.
rewrite H; reflexivity.
(**)
do 2 red; intros.
rewrite H; reflexivity.
(**)
red; intros.
rewrite <- itm_lift.
apply itm_morph; do 2 red; intros.
unfold I.lams.
destruct (le_gt_dec m a); trivial.
(**)
red; intros.
rewrite <- itm_subst.
apply itm_morph; do 2 red; intros.
unfold I.lams.
destruct (le_gt_dec m a); trivial.
Defined.
Instance lift_rec_morph n k :
Proper (eq_term ==> eq_term) (lift_rec n k).
do 2 red; intros.
destruct x; destruct y; try contradiction; try exact I.
red; simpl.
destruct H.
split; red; intros.
apply H.
rewrite H1; reflexivity.
apply H0.
rewrite H1; reflexivity.
Qed.
Lemma int_lift_rec_eq : forall n k T i,
int (lift_rec n k T) i == int T (V.lams k (V.shift n) i).
intros; destruct T as [T|]; simpl; reflexivity.
Qed.
Definition lift n := lift_rec n 0.
Definition lift1 n := lift_rec n 1.
Instance lift_morph : forall k, Proper (eq_term ==> eq_term) (lift k).
do 2 red; simpl; intros.
destruct x as [x|]; destruct y as [y|];
simpl in *; (contradiction||trivial).
destruct H; split.
red; intros.
apply H; rewrite H1; reflexivity.
red; intros.
apply H0; rewrite H1; reflexivity.
Qed.
Lemma int_lift_eq : forall n T i,
int (lift n T) i == int T (V.shift n i).
unfold int; intros;
destruct T as [T|]; simpl; auto. (* BUG: intros needed before destruct *)
2:reflexivity.
rewrite V.lams0.
reflexivity.
Qed.
Lemma int_cons_lift_eq : forall i T x,
int (lift 1 T) (V.cons x i) == int T i.
intros.
rewrite int_lift_eq.
rewrite V.shift_cons; reflexivity.
Qed.
Lemma tm_lift_rec_eq : forall n k T j,
tm (lift_rec n k T) j = tm T (I.lams k (I.shift n) j).
intros; destruct T; simpl; reflexivity.
Qed.
Lemma lift0 : forall A, eq_term (lift 0 A) A.
intros; apply eq_term_intro; intros; [| |destruct A; simpl; trivial].
unfold lift; rewrite int_lift_rec_eq; rewrite V.lams0; reflexivity.
unfold lift; rewrite tm_lift_rec_eq; rewrite I.lams0; reflexivity.
Qed.
Lemma split_lift : forall n T,
eq_term (lift (S n) T) (lift 1 (lift n T)).
destruct T as [T|]; simpl; auto.
split; red; intros.
do 2 rewrite V.lams0.
change (V.shift n (fun k => V.lams 0 (V.shift 1) y k)) with
(V.shift n (V.lams 0 (V.shift 1) y)).
rewrite V.lams0.
rewrite V.shiftS_split.
change (eq_val (fun k => x k) (fun k => y k)) in H.
rewrite H; reflexivity.
do 2 rewrite I.lams0.
change (I.shift n (fun k => I.lams 0 (I.shift 1) y k)) with
(I.shift n (I.lams 0 (I.shift 1) y)).
rewrite I.lams0.
rewrite I.shiftS_split.
change (Lc.eq_intt (fun k => x k) (fun k => y k)) in H.
rewrite H; reflexivity.
Qed.
Definition subst_rec (arg:term) (m:nat) (t:term) : term.
(*begin show*)
destruct t as [body|]; [left|right].
exists (fun i => iint body (V.lams m (V.cons (int arg (V.shift m i))) i))
(fun j => itm body (I.lams m (I.cons (tm arg (I.shift m j))) j)).
(*end show*)
do 2 red; intros.
rewrite H; reflexivity.
(**)
do 2 red; intros.
rewrite H; reflexivity.
(**)
red; intros.
rewrite <- itm_lift.
apply itm_morph; do 2 red; intros.
unfold I.lams.
destruct (le_gt_dec m a); trivial.
destruct (a-m); simpl; auto.
rewrite <- tm_liftable.
reflexivity.
(**)
red; intros.
rewrite <- itm_subst.
apply itm_morph; do 2 red; intros.
unfold I.lams.
destruct (le_gt_dec m a); trivial.
destruct (a-m); simpl; auto.
rewrite <- tm_substitutive.
reflexivity.
Defined.
Instance subst_rec_morph :
Proper (eq_term ==> eq ==> eq_term ==> eq_term) subst_rec.
do 4 red; intros.
subst y0; rename x0 into k.
destruct x1; destruct y1; try contradiction; try exact I.
red; simpl.
destruct H1.
split; red; intros.
apply H0.
rewrite H; rewrite H2; reflexivity.
apply H1.
rewrite H; rewrite H2; reflexivity.
Qed.
Lemma int_subst_rec_eq : forall arg k T i,
int (subst_rec arg k T) i == int T (V.lams k (V.cons (int arg (V.shift k i))) i).
intros; destruct T as [T|]; simpl; reflexivity.
Qed.
Definition subst arg := subst_rec arg 0.
Lemma int_subst_eq : forall N M i,
int M (V.cons (int N i) i) == int (subst N M) i.
destruct M as [M|]; simpl; intros.
2:reflexivity.
rewrite V.lams0.
rewrite V.shift0.
reflexivity.
Qed.
Lemma tm_subst_rec_eq : forall arg k T j,
tm (subst_rec arg k T) j = tm T (I.lams k (I.cons (tm arg (I.shift k j))) j).
intros; destruct T; simpl; reflexivity.
Qed.
Lemma tm_subst_eq : forall u v j,
tm (subst u v) j = Lc.subst (tm u j) (tm v (Lc.ilift j)).
intros.
unfold Lc.subst; rewrite <- tm_substitutive.
destruct v as [v|]; simpl; trivial.
rewrite I.lams0.
rewrite I.shift0.
apply itm_morph.
apply I.cons_ext; simpl.
rewrite Lc.lift0; trivial.
do 2 red; unfold I.shift; simpl; intros.
rewrite Lc.simpl_subst; trivial; rewrite Lc.lift0; trivial.
Qed.
(** Pseudo-term constructors *)
Definition cst (x:X) (t:Lc.term)
(H0 : Lc.liftable (fun _ => t)) (H1 : Lc.substitutive (fun _ => t)) : term.
(* begin show *)
left; exists (fun _ => x) (fun _ => t); trivial.
(* end show *)
do 2 red; reflexivity.
do 2 red; reflexivity.
Defined.
Definition kind : term := None.
Lemma kind_dec (T:term) : {T=kind}+{T<>kind}.
destruct T;[right;discriminate|left;reflexivity].
Qed.
Definition prop : term :=
@cst props (Lc.K) (fun _ _ => eq_refl _) (fun _ _ _ => eq_refl _).
Definition Ref (n:nat) : term.
(* begin show*)
left; exists (fun i => i n) (fun j => j n).
(*end show*)
do 2 red; simpl; auto.
do 2 red; simpl; auto.
red; reflexivity.
red; reflexivity.
Defined.
Definition App (u v:term) : term.
(*begin show*)
left; exists (fun i => app (int u i) (int v i))
(fun j => Lc.App (tm u j) (tm v j)).
(*end show*)
do 2 red; simpl; intros.
rewrite H; reflexivity.
(**)
do 2 red; simpl; intros.
rewrite H; reflexivity.
(**)
red; simpl; intros.
do 2 rewrite <- tm_liftable; trivial.
(**)
red; simpl; intros.
do 2 rewrite <- tm_substitutive; trivial.
Defined.
(* Church-style abstraction: *)
Definition CAbs t m :=
Lc.App2 Lc.K (Lc.Abs m) t.
Definition Abs (A M:term) : term.
(*begin show*)
left; exists (fun i => lam (int A i) (fun x => int M (V.cons x i)))
(fun j => CAbs (tm A j) (tm M (Lc.ilift j))).
(*end show *)
do 2 red; simpl; intros.
apply lam_ext.
rewrite H; reflexivity.
(**)
red; intros.
rewrite H; rewrite H1; reflexivity.
(**)
do 2 red; intros.
rewrite H; trivial.
(**)
red; simpl; intros.
rewrite Lc.ilift_binder_lift; trivial.
do 2 rewrite <- tm_liftable; trivial.
(**)
red; simpl; intros.
rewrite Lc.ilift_binder; trivial.
do 2 rewrite <- tm_substitutive; trivial.
Defined.
(* Encoding product *)
Definition CProd a b :=
Lc.App2 Lc.K a (Lc.Abs b).
Definition Prod (A B:term) : term.
(*begin show*)
left; exists (fun i => prod (int A i) (fun x => int B (V.cons x i)))
(fun j => CProd (tm A j) (tm B (Lc.ilift j))).
(*end show*)
do 2 red; simpl; intros.
apply prod_ext.
rewrite H; reflexivity.
(**)
red; intros.
rewrite H; rewrite H1; reflexivity.
(**)
do 2 red; intros.
rewrite H; trivial.
(**)
red; simpl; intros.
do 2 rewrite <- tm_liftable; trivial.
rewrite Lc.ilift_binder_lift; trivial.
(**)
red; simpl; intros.
do 2 rewrite <- tm_substitutive; trivial.
rewrite Lc.ilift_binder; trivial.
Defined.
Lemma intProd_eq i A B :
int (Prod A B) i = prod (int A i) (fun x => int B (V.cons x i)).
reflexivity.
Qed.
Instance App_morph : Proper (eq_term ==> eq_term ==> eq_term) App.
unfold App; do 3 red; simpl; split; intros.
red; intros.
rewrite H; rewrite H0; rewrite H1; reflexivity.
red; intros.
rewrite H; rewrite H0; rewrite H1; reflexivity.
Qed.
Instance Abs_morph : Proper (eq_term ==> eq_term ==> eq_term) Abs.
unfold Abs; do 4 red; simpl; split; red; intros.
apply lam_ext.
apply int_morph; auto.
red; intros.
rewrite H0; rewrite H1; rewrite H3; reflexivity.
rewrite H0; rewrite H1; rewrite H; reflexivity.
Qed.
Instance Prod_morph : Proper (eq_term ==> eq_term ==> eq_term) Prod.
unfold Prod; do 4 red; simpl; split; red; intros.
apply prod_ext.
rewrite H; rewrite H1; reflexivity.
red; intros.
rewrite H0; rewrite H1; rewrite H3; reflexivity.
rewrite H0; rewrite H1; rewrite H; reflexivity.
Qed.
Lemma discr_ref_prod : forall n A B,
~ eq_term (Ref n) (Prod A B).
red; intros.
simpl in H.
destruct H as (_,H).
red in H.
specialize H with Lc.Ref Lc.Ref.
discriminate H.
reflexivity.
Qed.
Lemma eq_term_lift_ref_fv n k i :
k <= i ->
eq_term (lift_rec n k (Ref i)) (Ref (n+i)).
split; simpl; red; intros.
unfold V.lams.
destruct (le_gt_dec k i).
unfold V.shift; simpl.
replace (n+i) with (k+(n+(i-k))); auto with *.
omega.
unfold I.lams.
destruct (le_gt_dec k i).
unfold I.shift; simpl.
replace (n+i) with (k+(n+(i-k))); auto with *.
omega.
Qed.
Lemma red_lift_ref_bound n k i :
(i < k)%nat ->
eq_term (lift_rec n k (Ref i)) (Ref i).
intros; simpl.
unfold V.lams, V.shift, I.lams, I.shift.
destruct (le_gt_dec k i).
exfalso; omega.
split; red; intros; auto.
Qed.
Lemma red_lift_ref n k i :
eq_term (lift_rec n k (Ref i)) (Ref (if le_gt_dec k i then n+i else i)).
destruct (le_gt_dec k i).
apply eq_term_lift_ref_fv; trivial.
apply red_lift_ref_bound; trivial.
Qed.
(*
Lemma lift1var : forall n, eq_term (lift 1 (Ref n)) (Ref (S n)).
simpl; split; red; intros.
revert n.
change (eq_val (V.lams 0 (V.shift 1) x) (V.shift 1 y)).
rewrite V.lams0; rewrite <- H.
reflexivity.
revert n.
change (Lc.eq_intt (I.lams 0 (I.shift 1) x) (I.shift 1 y)).
rewrite I.lams0; rewrite <- H.
reflexivity.
Qed.
*)
Lemma red_lift_app n A B k :
eq_term (lift_rec n k (App A B)) (App (lift_rec n k A) (lift_rec n k B)).
red; simpl; intros.
split.
red; intros.
apply app_ext.
rewrite int_lift_rec_eq.
rewrite H; reflexivity.
rewrite int_lift_rec_eq.
rewrite H; reflexivity.
red; intros.
do 2 rewrite tm_lift_rec_eq.
rewrite H; trivial.
Qed.
Lemma red_lift_abs n A B k :
eq_term (lift_rec n k (Abs A B)) (Abs (lift_rec n k A) (lift_rec n (S k) B)).
red; simpl; intros.
split.
red; intros.
apply lam_ext.
rewrite int_lift_rec_eq.
rewrite H; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
rewrite H1.
rewrite H.
reflexivity.
do 2 red; intros.
rewrite H2; reflexivity.
red; intros.
apply f_equal2.
rewrite tm_lift_rec_eq.
rewrite H; auto.
rewrite tm_lift_rec_eq.
apply tm_morph; auto with *.
rewrite H.
apply Lc.cross_binder_shift.
Qed.
Lemma red_lift_prod n A B k :
eq_term (lift_rec n k (Prod A B)) (Prod (lift_rec n k A) (lift_rec n (S k) B)).
red; simpl; intros.
split.
red; intros.
apply prod_ext.
rewrite int_lift_rec_eq.
rewrite H; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
rewrite H1.
rewrite H.
reflexivity.
do 2 red; intros.
rewrite H2; reflexivity.
red; intros.
apply f_equal2.
rewrite tm_lift_rec_eq.
rewrite H; auto.
rewrite tm_lift_rec_eq.
apply tm_morph; auto with *.
rewrite H.
apply Lc.cross_binder_shift.
Qed.
Lemma red_sigma_app N A B k :
eq_term (subst_rec N k (App A B)) (App (subst_rec N k A) (subst_rec N k B)).
red; simpl; intros.
split.
red; intros.
apply app_ext.
rewrite int_subst_rec_eq.
rewrite H; reflexivity.
rewrite int_subst_rec_eq.
rewrite H; reflexivity.
red; intros.
do 2 rewrite tm_subst_rec_eq.
rewrite H; trivial.
Qed.
Lemma red_sigma_abs N A B k :
eq_term (subst_rec N k (Abs A B)) (Abs (subst_rec N k A) (subst_rec N (S k) B)).
red; simpl; intros.
split.
red; intros.
apply lam_ext.
rewrite int_subst_rec_eq.
rewrite H; reflexivity.
red; intros.
rewrite int_subst_rec_eq.
rewrite <- V.cons_lams.
rewrite H1.
rewrite H.
reflexivity.
do 2 red; intros.
rewrite H2; reflexivity.
red; intros.
apply f_equal2.
rewrite tm_subst_rec_eq.
rewrite H; auto.
rewrite tm_subst_rec_eq.
apply tm_morph; auto with *.
rewrite H.
apply Lc.cross_binder_cons.
unfold I.shift, Lc.ilift; simpl.
unfold Lc.lift; rewrite <- tm_liftable; trivial.
Qed.
Lemma red_sigma_prod N A B k :
eq_term (subst_rec N k (Prod A B)) (Prod (subst_rec N k A) (subst_rec N (S k) B)).
red; simpl; intros.
split.
red; intros.
apply prod_ext.
rewrite int_subst_rec_eq.
rewrite H; reflexivity.
red; intros.
rewrite int_subst_rec_eq.
rewrite <- V.cons_lams.
rewrite H1.
rewrite H.
reflexivity.
do 2 red; intros.
rewrite H2; reflexivity.
red; intros.
apply f_equal2.
rewrite tm_subst_rec_eq.
rewrite H; auto.
rewrite tm_subst_rec_eq.
apply tm_morph; auto with *.
rewrite H.
apply Lc.cross_binder_cons.
unfold I.shift, Lc.ilift; simpl.
unfold Lc.lift; rewrite <- tm_liftable; trivial.
Qed.
Lemma red_sigma_var_eq N k :
N <> kind ->
eq_term (subst_rec N k (Ref k)) (lift k N).
unfold subst_rec; simpl.
destruct N; simpl.
2:destruct 1; trivial.
intros _.
split; red; intros.
unfold V.lams, V.shift; simpl.
destruct (le_gt_dec k k).
2:omega.
replace (k-k) with 0; auto with *.
simpl V.cons.
apply iint_morph.
do 2 red; intros.
replace (a-0) with a; auto with *.
unfold I.lams; simpl.
destruct (le_gt_dec k k).
2:omega.
replace (k-k) with 0; auto with *.
simpl I.cons.
apply itm_morph.
do 2 red; intros.
unfold I.shift; simpl.
replace (a-0) with a; auto with *.
Qed.
Lemma red_sigma_var_lt N k n :
n < k ->
eq_term (subst_rec N k (Ref n)) (Ref n).
unfold subst_rec; simpl; intros.
split; red; intros.
unfold V.lams, V.shift; simpl.
destruct (le_gt_dec k n); auto.
omega.
unfold I.lams, I.shift; simpl.
destruct (le_gt_dec k n); auto.
omega.
Qed.
Lemma red_sigma_var_gt N k n :
k <= n ->
eq_term (subst_rec N k (Ref (S n))) (Ref n).
unfold subst_rec; simpl; intros.
split; red; intros.
unfold V.lams; simpl.
destruct (le_gt_dec k (S n)); simpl.
unfold V.cons, V.shift; simpl.
destruct k; simpl; auto.
replace (n-k) with (S (n-S k)).
replace (S (k+(n- S k))) with n; auto.
omega.
omega.
omega.
unfold I.lams, I.shift, I.cons; simpl.
destruct (le_gt_dec k (S n)); simpl.
destruct k; simpl; auto.
replace (n-k) with (S (n-S k)).
replace (S (k+(n- S k))) with n; auto.
omega.
omega.
omega.
Qed.
Lemma red_sigma_ref N k i :
N <> kind ->
eq_term (subst_rec N k (Ref i))
match lt_eq_lt_dec k i with
| inleft (left _) => Ref (Peano.pred i)
| inleft (right _) => lift k N
| inright _ => Ref i
end.
intros.
destruct (lt_eq_lt_dec k i) as [[?|?]|?].
destruct i; simpl Peano.pred.
inversion l.
apply red_sigma_var_gt; auto with arith.
subst i; apply red_sigma_var_eq; trivial.
apply red_sigma_var_lt; auto with arith.