-
Notifications
You must be signed in to change notification settings - Fork 2
/
SN_W.v
1587 lines (1378 loc) · 41.2 KB
/
SN_W.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
(** Strong normalization of the model of CC+W in the type-based
termination presentation.
*)
Require Import basic Models.
Require SN_ECC_Real.
Import ZFgrothendieck.
Import ZF ZFsum ZFnats ZFrelations ZFord ZFfix.
Require Import ZFfunext ZFfixrec ZFcoc ZFecc ZFuniv_real SATtypes SATw.
Import SN_ECC_Real.
Opaque Real.
Import Sat Sat.SatSet.
(** Typing rules related to ordinals *)
Require Import SN_ord.
(** Judgments with variance *)
Require Import SN_variance.
(** W *)
(** The abstract model construction is a functor based on any
abstract set-theoretical model of W-types. *)
Module Make(W:W_PartialModel).
Module Wsat := SATw.Make(W).
Import W Wsat.
(** Facts derived from the signature *)
(** Back to the subject: W-types model construction *)
Section Wtypes_typing.
Variable o : set.
Hypothesis oo : isOrd o.
Hypothesis oz : zero ∈ o.
Variable e:env.
Variable A B:term.
Hypothesis Atyp : typ e A kind.
Hypothesis Btyp : typ (A::e) B kind.
Let Aw i := El (int A i).
Let Bw i x := El (int B (V.cons x i)).
Let RAw i a := Real (int A i) a.
Let RBw i a b := Real (int B (V.cons a i)) b.
Definition WF i X := W_F (Aw i) (Bw i) X.
Definition RW i o w := rWi (Aw i) (Bw i) (RAw i) (RBw i) o w.
Instance Aw_morph : Proper (eq_val==>eq_set) Aw.
do 2 red; intros.
apply El_morph.
apply int_morph; auto with *.
Qed.
Instance Bw_morph : Proper (eq_val==>eq_set==>eq_set) Bw.
do 3 red; intros.
apply El_morph.
rewrite H; rewrite H0; reflexivity.
Qed.
Instance Bwi_morph i : morph1 (Bw i).
apply Bw_morph; reflexivity.
Qed.
Instance RAw_morph : Proper (eq_val ==> eq_set ==> eqSAT) RAw.
do 3 red; intros.
unfold RAw.
rewrite H; rewrite H0; reflexivity.
Qed.
Instance RAwi_morph i : Proper (eq_set ==> eqSAT) (RAw i).
apply RAw_morph; reflexivity.
Qed.
Instance RBw_morph : Proper (eq_val ==> eq_set ==> eq_set ==> eqSAT) RBw.
do 4 red; intros.
unfold RBw.
rewrite H; rewrite H0; rewrite H1; reflexivity.
Qed.
Instance RBwi_morph i : Proper (eq_set ==> eq_set ==> eqSAT) (RBw i).
apply RBw_morph; reflexivity.
Qed.
Instance WF_morph : Proper (eq_val ==> eq_set ==> eq_set) WF.
do 3 red; intros.
apply W_F_ext; trivial.
apply Aw_morph; trivial.
red; intros.
apply Bw_morph; trivial.
Qed.
Lemma WF_mono i : Proper (incl_set==>incl_set) (WF i).
do 2 red; intros.
unfold WF.
apply W_F_mono; auto with *.
Qed.
Hint Resolve WF_mono.
Instance RW_morph : Proper (eq_val ==> eq_set ==> eq_set ==> eqSAT) RW.
do 4 red; intros.
unfold RW.
apply rWi_morph_gen; auto with *.
apply Aw_morph; trivial.
apply Bw_morph; trivial.
apply RAw_morph; trivial.
apply RBw_morph; trivial.
Qed.
Definition WI (O:term) : term.
(*begin show*)
left; exists (fun i => mkTY (TI (WF i) (int O i)) (RW i (int O i)))
(fun j => Lc.App2 Lc.K (tm A j) (Lc.App2 Lc.K (Lc.Abs(tm B (Lc.ilift j))) (tm O j))).
(*end show*)
do 2 red; intros.
apply mkTY_ext; intros.
apply TI_morph_gen.
apply WF_morph; trivial.
rewrite H; reflexivity.
apply RW_morph; trivial.
rewrite H; reflexivity.
(**)
do 2 red; intros.
rewrite H; reflexivity.
(**)
red; intros.
simpl.
rewrite <- tm_liftable.
rewrite <- tm_liftable.
rewrite <- tm_liftable.
unfold Lc.App2.
f_equal.
f_equal.
f_equal.
f_equal.
apply tm_morph; auto with *.
apply Lc.ilift_binder_lift.
(**)
red; intros.
simpl.
rewrite <- tm_substitutive.
rewrite <- tm_substitutive.
rewrite <- tm_substitutive.
unfold Lc.App2.
f_equal.
f_equal.
f_equal.
f_equal.
apply tm_morph; auto with *.
apply Lc.ilift_binder.
Defined.
Lemma El_int_W O i :
El (int (WI O) i) == cc_bot (TI (WF i) (int O i)).
simpl.
rewrite El_def; reflexivity.
Qed.
Lemma Real_int_W O i x :
x ∈ cc_bot (TI (WF i) (int O i)) ->
eqSAT (Real (int (WI O) i) x) (RW i (int O i) x).
simpl; intros.
rewrite Real_def; auto with *.
intros.
rewrite H1; reflexivity.
Qed.
Lemma typ_WI : forall eps O,
isOrd eps ->
typ e O (Ordt eps) ->
typ e (WI O) kind.
red; intros; simpl.
red in H0; specialize H0 with (1:=H1).
assert (tyA := Atyp _ _ H1).
apply in_int_not_kind in H0.
2:discriminate.
destruct tyA as (Ank,(_,snA)).
destruct (Btyp _ _ (val_ok_cons_default H1 Ank)) as (Bnk,(_,snB)).
split;[|split].
discriminate.
exists nil; exists (WI O);[reflexivity|].
exists empty; simpl; auto.
red; auto.
simpl.
apply real_sn in H0.
apply Lc.sn_K2; trivial.
apply Lc.sn_K2; trivial.
apply Lc.sn_abs.
rewrite tm_subst_cons in snB.
apply Lc.sn_subst in snB; trivial.
Qed.
(** Constructor *)
Definition Wc (x:term) (f:term) : term.
(* begin show *)
left; exists (fun i => mkw (int x i) (int f i))
(fun j => WC (tm x j) (tm f j)).
(* end show *)
do 2 red; intros; apply mkw_morph; apply int_morph; auto with *.
(**)
do 2 red; intros.
rewrite H; reflexivity.
(**)
red; intros.
unfold WC, COUPLE; simpl.
do 2 rewrite tm_liftable.
do 2 rewrite Lc.permute_lift; reflexivity.
(**)
red; intros.
unfold WC, COUPLE; simpl.
do 2 rewrite tm_substitutive.
do 2 rewrite Lc.commut_lift_subst; reflexivity.
Defined.
Lemma typ_Wc : forall O X F,
typ e O (Ordt o) ->
typ e X A ->
typ e F (Prod (subst X B) (lift 1 (WI O))) ->
typ e (Wc X F) (WI (OSucc O)).
red; intros.
red in H0; specialize H0 with (1:=H2).
apply in_int_not_kind in H0.
2:destruct (Atyp _ _ H2); trivial.
red in H1; specialize H1 with (1:=H2).
apply in_int_not_kind in H1.
2:discriminate.
destruct tyord_inv with (3:=H)(4:=H2) as (?,(?,_)); trivial.
apply in_int_intro; try discriminate.
assert (mkw (int X0 i) (int F i) ∈ TI (WF i) (osucc (int O i))).
apply TI_intro with (int O i); auto.
apply W_F_intro.
apply Bw_morph; auto with *.
apply H0.
destruct H1.
red in H1; rewrite El_int_arr in H1.
rewrite El_int_W in H1.
rewrite <- int_subst_eq in H1.
trivial.
split.
red; rewrite El_int_W; auto.
rewrite Real_int_W; auto.
simpl.
unfold RW; apply Real_WC; auto with *.
rewrite w1_eq.
apply H0.
destruct H1.
red in H1; rewrite El_int_prod in H1.
rewrite Real_int_prod in H6; trivial.
revert H6; apply piSAT0_morph; intros.
red; intros.
rewrite w1_eq.
rewrite <- int_subst_eq; reflexivity.
rewrite w1_eq.
rewrite <- int_subst_eq; reflexivity.
rewrite int_cons_lift_eq.
rewrite Real_int_W.
unfold RW; apply rWi_morph; auto with *.
rewrite w2_eq; reflexivity.
apply cc_prod_elim with (2:=H7) in H1.
rewrite int_cons_lift_eq in H1.
rewrite El_int_W in H1; trivial.
Qed.
(* Case analysis *)
Definition mkw_case (b : set -> set -> set) c :=
cond_set (c == mkw (w1 c) (w2 c)) (b (w1 c) (w2 c)).
Definition W_CASE b w :=
mkw_case (fun x f => app (app b x) f) w.
Definition Wcase (b n : term) : term.
(*begin show*)
left; exists (fun i => W_CASE (int b i) (int n i))
(fun j => WCASE (tm b j) (tm n j)).
(*end show*)
do 2 red; intros.
unfold W_CASE.
apply cond_set_morph.
rewrite H; reflexivity.
rewrite H; reflexivity.
(**)
do 2 red; intros.
unfold WCASE; rewrite H; reflexivity.
(**)
red; intros; simpl.
unfold WCASE; simpl.
do 2 rewrite tm_liftable; reflexivity.
(**)
red; intros; simpl.
unfold WCASE; simpl.
do 2 rewrite tm_substitutive; reflexivity.
Defined.
Instance Wcase_morph :
Proper (eq_term ==> eq_term ==> eq_term) Wcase.
do 3 red; intros.
split; red; simpl; intros.
unfold sigma_case.
apply cond_set_morph.
rewrite H0; rewrite H1; reflexivity.
rewrite H; rewrite H0; rewrite H1; reflexivity.
rewrite H; rewrite H0; rewrite H1; reflexivity.
Qed.
Lemma Wcase_iota : forall X F G,
eq_typ e (Wcase G (Wc X F)) (App (App G X) F).
red; red; intros.
simpl.
unfold W_CASE.
unfold mkw_case; rewrite cond_set_ok.
rewrite w1_eq, w2_eq; reflexivity.
rewrite w1_eq, w2_eq; reflexivity.
Qed.
Lemma typ_Wcase P O G n :
typ e O (Ordt o) ->
typ e G (Prod A (Prod (Prod B (lift 2 (WI O))) (App (lift 2 P) (Wc (Ref 1) (Ref 0))))) ->
typ e n (WI (OSucc O)) ->
typ e (Wcase G n) (App P n).
red; intros.
destruct tyord_inv with (3:=H)(4:=H2) as (?,(?,_ )); trivial.
red in H0; specialize H0 with (1:=H2).
apply in_int_not_kind in H0;[|discriminate].
red in H1; specialize H1 with (1:=H2).
apply in_int_not_kind in H1;[|discriminate].
apply in_int_intro; try discriminate.
destruct H0; red in H0.
rewrite El_int_prod in H0.
rewrite Real_int_prod in H5; trivial.
destruct H1; red in H1.
rewrite El_int_W in H1.
rewrite Real_int_W in H6; trivial.
apply and_split; intros.
red; simpl.
rewrite cc_bot_ax in H1; destruct H1.
unfold W_CASE, mkw_case.
rewrite H1.
rewrite cond_set_mt; auto.
apply discr_mt_mkw.
simpl in H1; rewrite TI_mono_succ in H1; auto with *.
apply W_F_elim in H1.
2:apply Bw_morph; auto with *.
destruct H1 as (ty1,(ty2,eqn)).
unfold W_CASE, mkw_case.
rewrite cond_set_ok; trivial.
specialize cc_prod_elim with (1:=H0) (2:=ty1); clear H0; intro H0.
rewrite El_int_prod in H0.
apply eq_elim with (El
(app (int (lift 2 P) (V.cons (w2 (int n i)) (V.cons (w1 (int n i)) i)))
(mkw (w1 (int n i)) (w2 (int n i))))).
apply El_morph.
apply app_ext; auto with *.
rewrite split_lift; do 2 rewrite int_cons_lift_eq; reflexivity.
apply cc_prod_elim with (1:=H0).
rewrite split_lift.
rewrite El_int_arr.
revert ty2; apply eq_elim.
apply cc_arr_morph.
reflexivity.
rewrite int_cons_lift_eq.
rewrite El_int_W; reflexivity.
simpl in H6|-*.
rewrite cc_bot_ax in H1; destruct H1.
(* neutral case *)
rewrite H1 in H6.
unfold WCASE.
eapply prodSAT_elim;[|apply H5].
unfold RW in H6; rewrite rWi_neutral in H6; auto with *.
apply neuSAT_def; trivial.
(* regular case *)
eapply Real_WCASE with (6:=H1) (7:=H6)
(C:=fun x => Real (app (int P i) x) (mkw_case (fun x f => app (app (int G i) x) f) x));
auto with *.
do 2 red; intros.
unfold mkw_case.
rewrite H8.
reflexivity.
revert H5; apply piSAT0_morph; intros.
red; intros; reflexivity.
reflexivity.
specialize cc_prod_elim with (1:=H0) (2:=H8); clear H0; intro H0.
rewrite El_int_prod in H0.
rewrite Real_int_prod; trivial.
apply piSAT0_morph; intros.
red; intros.
rewrite split_lift.
rewrite El_int_arr.
apply in_set_morph; auto with *.
apply cc_arr_morph.
reflexivity.
rewrite int_cons_lift_eq.
rewrite El_int_W; reflexivity.
rewrite split_lift.
rewrite Real_int_arr; trivial.
apply piSAT0_morph; intros.
red; intros.
reflexivity.
reflexivity.
specialize cc_arr_elim with (1:=H9) (2:=H11); clear H9; intro H9.
rewrite int_cons_lift_eq.
rewrite Real_int_W; trivial.
reflexivity.
revert H10; apply eq_elim.
rewrite split_lift.
rewrite El_int_arr; reflexivity.
apply Real_morph.
simpl.
rewrite split_lift; do 2 rewrite int_cons_lift_eq.
reflexivity.
unfold mkw_case; rewrite cond_set_ok.
rewrite w1_eq, w2_eq; reflexivity.
rewrite w1_eq, w2_eq; reflexivity.
Qed.
(*Print Assumptions typ_Wcase.*)
Lemma typ_Wcase' : forall P O G n T,
T <> kind ->
typ e O (Ordt o) ->
sub_typ e (App P n) T ->
typ e G (Prod A (Prod (Prod B (lift 2 (WI O))) (App (lift 2 P) (Wc (Ref 1) (Ref 0))))) ->
typ e n (WI (OSucc O)) ->
typ e (Wcase G n) T.
intros.
apply typ_subsumption with (App P n); auto.
2:discriminate.
apply typ_Wcase with O; trivial.
Qed.
End Wtypes_typing.
Hint Resolve WF_mono.
Lemma typ_WI_type n eps e A B O :
isOrd eps ->
zero ∈ eps ->
A <> kind ->
typ e O (Ordt eps) ->
typ e A (type n) ->
typ (A::e) B (type n) ->
typ e (WI A B O) (type n).
red; intros epso eps_nz Ank tyO tyA tyB i j is_val; simpl.
destruct tyord_inv with (3:=tyO)(4:=is_val) as (oo,(_,osn)); trivial.
clear tyO.
red in tyA; specialize tyA with (1:=is_val).
apply in_int_not_kind in tyA.
2:discriminate.
destruct tyA as (Aty,Asn).
red in Aty.
change (int (type n) i) with (sn_sort (ecc (S n))) in Aty.
apply El_in_grot in Aty; auto.
split;[discriminate|].
assert (G_B : forall a, a ∈ El (int A i) -> El (int B (V.cons a i)) ∈ ecc (S n)).
intros.
assert (val_ok (A::e) (V.cons a i) (I.cons daimon j)).
apply vcons_add_var_daimon; trivial.
apply tyB in H0.
destruct H0; trivial.
destruct H1; trivial.
red in H1; change (int (type n) (V.cons a i)) with (sn_sort (ecc (S n))) in H1.
apply El_in_grot in H1; trivial.
apply and_split; intros.
red; change (int (type n) i) with (sn_sort (ecc (S n))).
simpl int.
apply sn_sort_intro.
intros.
apply RW_morph; auto with *.
apply G_incl with (TI (WF A B i) (W_ord (El(int A i)) (fun x => El(int B (V.cons x i))))); trivial.
apply G_TI; trivial.
apply WF_morph; auto with *.
apply W_ord_ord.
do 2 red; intros.
rewrite H; reflexivity.
apply G_W_ord; auto.
do 2 red; intros.
rewrite H; reflexivity.
intros.
apply G_W_F; auto.
do 2 red; intros.
rewrite H0; reflexivity.
apply W_stages; auto.
do 2 red; intros.
rewrite H; reflexivity.
red in H.
destruct (tyB _ _ (val_ok_cons_default is_val Ank)) as (Bnk,(_,snB)).
change (int (type n) i) with (sn_sort (ecc (S n))).
rewrite Real_sort_sn; trivial.
apply sat_sn in Asn.
apply sat_sn in snB.
rewrite tm_subst_cons in snB.
apply Lc.sn_subst in snB.
simpl.
apply snSAT_intro.
apply Lc.sn_K2; trivial.
apply Lc.sn_K2; trivial.
apply Lc.sn_abs; trivial.
Qed.
(*****************************************************************************)
(** Recursor (without case analysis) *)
(* WFix O M is a fixpoint of domain WI O with body M *)
Definition WFix (O M:term) : term.
(*begin show*)
left.
exists (fun i => WREC (fun o' f => int M (V.cons f (V.cons o' i))) (int O i))
(fun j => WFIX (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j))))).
(*end show*)
do 2 red; intros.
apply WREC_morph.
do 2 red; intros.
apply int_morph; auto with *.
apply V.cons_morph; trivial.
apply V.cons_morph; trivial.
apply int_morph; auto with *.
(* *)
do 2 red; intros.
rewrite H; reflexivity.
(* *)
red; intros.
replace (Lc.lift_rec 1
(WFIX (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j))))) k) with
(WFIX (Lc.lift_rec 1 (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j)))) k)).
simpl.
f_equal.
f_equal.
rewrite <- tm_liftable.
apply tm_morph; auto with *.
rewrite <- Lc.ilift_binder_lift.
apply Lc.ilift_morph.
intros [|k']; simpl; trivial.
apply tm_liftable.
generalize (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j)))); intro.
unfold WFIX, FIXP; simpl.
rewrite <- Lc.permute_lift.
reflexivity.
(* *)
red; intros.
replace (Lc.subst_rec u
(WFIX (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j))))) k) with
(WFIX (Lc.subst_rec u (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j)))) k)).
simpl.
f_equal.
f_equal.
rewrite <- tm_substitutive.
apply tm_morph; auto with *.
rewrite <- Lc.ilift_binder.
apply Lc.ilift_morph.
intros [|k']; simpl; trivial.
apply tm_substitutive.
generalize (Lc.Abs (tm M (Lc.ilift (I.cons (tm O j) j)))); intro.
unfold WFIX, FIXP; simpl.
rewrite <- Lc.commut_lift_subst.
reflexivity.
Defined.
(** Typing rules of WFix *)
Section WFixRules.
Variable infty : set.
Hypothesis infty_ord : isOrd infty.
Hypothesis infty_nz : zero ∈ infty.
Variable E : fenv.
Let e := tenv E.
Variable A B O U M : term.
Hypothesis A_nk : A <> kind.
Hypothesis Aeq : fx_equals E A.
Hypothesis Beq : fx_equals (push_var E A) B.
Definition WIL n := WI (lift n A) (lift_rec n 1 B).
Hypothesis ty_O : typ e O (Ordt infty).
Hypothesis ty_M : typ (Prod (WIL 1 (Ref 0)) U::OSucct O::e)
M (Prod (WIL 2 (OSucc (Ref 1)))
(lift_rec 1 1 (subst_rec (OSucc (Ref 0)) 1 (lift_rec 1 2 U)))).
Hypothesis stab : fx_extends
(push_fun (push_ord E (OSucct O)) (WIL 1 (Ref 0)) U)
(WIL 2 (OSucc (Ref 1)))
M.
Let Wi i o := cc_bot (TI (WF A B i) o).
Let F i := fun o' f => squash (int M (V.cons f (V.cons o' i))).
Let U' i := fun o' x => El (int U (V.cons x (V.cons o' i))).
Notation F' i := (fun o' f => int M (V.cons f (V.cons o' i))).
Local Instance U'morph : forall i, morph2 (U' i).
do 3 red; intros; unfold U'.
rewrite H; rewrite H0; reflexivity.
Qed.
Instance morph_fix_body : forall i, morph2 (F i).
unfold F; do 3 red; intros.
apply squash_morph.
rewrite H; rewrite H0; reflexivity.
Qed.
Lemma ext_fun_ty : forall o i,
ext_fun (Wi i o) (U' i o).
do 2 red; intros.
rewrite H0;reflexivity.
Qed.
Hint Resolve U'morph morph_fix_body ext_fun_ty.
Hypothesis fx_sub_U :
fx_sub (push_var (push_ord E (OSucct O)) (WIL 1 (OSucc (Ref 0)))) U.
Lemma El_int_W_lift O' n i :
El (int (WIL n O') i) == cc_bot (TI (WF A B (V.shift n i)) (int O' i)).
unfold WIL; rewrite El_int_W.
apply cc_bot_morph.
apply TI_morph_gen; auto with *.
red; intros.
unfold WF; apply W_F_ext; auto with *.
rewrite int_lift_eq; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
2:apply V.shift_morph; trivial.
rewrite V.lams0.
rewrite H1; reflexivity.
(*
rewrite H; reflexivity.*)
Qed.
Lemma Real_int_W_lift O' n i x :
x ∈ cc_bot (TI (WF A B (V.shift n i)) (int O' i)) ->
eqSAT (Real (int (WIL n O') i) x) (RW A B (V.shift n i) (int O' i) x).
intros.
unfold WIL; rewrite Real_int_W.
unfold RW.
apply rWi_morph_gen; auto with *.
rewrite int_lift_eq; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
2:apply V.shift_morph; trivial.
rewrite V.lams0.
rewrite H0; reflexivity.
red; intros.
rewrite H0; rewrite int_lift_eq; reflexivity.
do 2 red; intros.
rewrite H1; rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
2:apply V.shift_morph; trivial.
rewrite V.lams0.
rewrite H0; reflexivity.
revert H; apply eq_elim.
apply cc_bot_morph.
apply TI_morph_gen; auto with *.
red; intros.
unfold WF; apply W_F_ext.
rewrite int_lift_eq; reflexivity.
red; intros.
rewrite H1; rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
2:apply V.shift_morph; trivial.
rewrite V.lams0.
reflexivity.
(*apply cc_bot_morph;*) trivial.
Qed.
Lemma Elt_int_W_lift O' n i :
Elt (int (WIL n O') i) == TI (WF A B (V.shift n i)) (int O' i).
simpl; rewrite Elt_def.
apply TI_morph_gen; auto with *.
red; intros.
unfold WF; apply W_F_ext; auto with *.
rewrite int_lift_eq; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite <- V.cons_lams.
2:apply V.shift_morph; trivial.
rewrite V.lams0.
rewrite H1; reflexivity.
(* rewrite H; reflexivity.*)
Qed.
Lemma val_mono_1 i i' j j' y y' f g:
val_mono E i j i' j' ->
isOrd (int O i) ->
isOrd (int O i') ->
int O i ⊆ int O i' ->
isOrd y ->
isOrd y' ->
y ⊆ int O i ->
y' ⊆ int O i' ->
y ⊆ y' ->
f ∈ cc_prod (Wi i y) (U' i y) ->
g ∈ cc_prod (Wi i' y') (U' i' y') ->
fcompat (Wi i y) f g ->
val_mono (push_fun (push_ord E (OSucct O)) (WIL 1 (Ref 0)) U)
(V.cons f (V.cons y i)) (I.cons daimon (I.cons daimon j))
(V.cons g (V.cons y' i')) (I.cons daimon (I.cons daimon j')).
intros is_val Oo Oo' oo' yo y'o yO y'O yy' fty gty eqfg.
apply val_push_fun.
apply val_push_ord; auto.
3:discriminate.
split;[|apply varSAT].
red; rewrite El_int_osucc.
apply ole_lts; trivial.
split;[|apply varSAT].
red; rewrite El_int_osucc.
apply ole_lts; trivial.
split;[|apply varSAT].
red; rewrite El_int_prod.
revert fty; apply eq_elim; apply cc_prod_ext; intros.
rewrite El_int_W_lift; reflexivity.
apply ext_fun_ty.
split;[|apply varSAT].
red; rewrite El_int_prod.
revert gty; apply eq_elim; apply cc_prod_ext; intros.
rewrite El_int_W_lift; reflexivity.
apply ext_fun_ty.
rewrite El_int_W_lift.
trivial.
Qed.
Lemma val_mono_2 i j y y' n n':
val_ok e i j ->
isOrd (int O i) ->
isOrd y ->
isOrd y' ->
y ⊆ y' ->
y' ⊆ int O i ->
n ∈ Wi i y ->
n == n' ->
val_mono (push_var (push_ord E (OSucct O)) (WIL 1 (OSucc (Ref 0))))
(V.cons n (V.cons y i)) (I.cons daimon (I.cons daimon j))
(V.cons n' (V.cons y' i)) (I.cons daimon (I.cons daimon j)).
Proof.
intros.
apply val_push_var; auto with *.
4:discriminate.
apply val_push_ord; auto with *.
4:discriminate.
apply val_mono_refl; trivial.
split;[|apply varSAT].
red; rewrite El_int_osucc.
apply ole_lts; auto.
transitivity y'; trivial.
split;[|apply varSAT].
red; rewrite El_int_osucc.
apply ole_lts; auto.
split;[|apply varSAT].
red; rewrite El_int_W_lift.
revert H5; apply cc_bot_mono.
apply TI_incl; simpl; auto.
split;[|apply varSAT].
red; rewrite El_int_W_lift.
rewrite <- H6.
revert H5; apply cc_bot_mono.
apply TI_incl; simpl; auto.
apply ole_lts; trivial.
Qed.
Let F2m : forall i T, morph2 (fun o' f => int T (V.cons f (V.cons o' i))).
do 3 red; intros.
apply int_morph; [reflexivity|].
repeat apply V.cons_morph; trivial.
reflexivity.
Qed.
Let U2m : forall i T, morph2 (fun o' f => El (int T (V.cons f (V.cons o' i)))).
do 3 red; intros.
apply El_morph; apply F2m; trivial.
Qed.
Set Implicit Arguments.
Let Mty : forall i j,
val_ok e i j ->
forall o',
o' ∈ osucc (int O i) ->
forall f,
f ∈ cc_prod (Wi i o') (U' i o') ->
int M (V.cons f (V.cons o' i)) ∈ cc_prod (Wi i (osucc o')) (U' i (osucc o')).
intros.
assert (val_ok (Prod (WIL 1 (Ref 0)) U :: OSucct O :: e)
(V.cons f (V.cons o' i)) (I.cons daimon (I.cons daimon j))).
apply vcons_add_var_daimon; [| |discriminate].
apply vcons_add_var_daimon; [trivial| |discriminate].
red; simpl; rewrite El_def; auto.
red; rewrite El_int_prod.
revert H1; apply eq_elim; apply cc_prod_ext.
rewrite El_int_W_lift; reflexivity.
apply ext_fun_ty.
apply ty_M in H2.
apply in_int_not_kind in H2.
2:discriminate.
destruct H2 as (H2,_).
red in H2; rewrite El_int_prod in H2.
revert H2; apply eq_elim; apply cc_prod_ext.
rewrite El_int_W_lift; reflexivity.
red; intros.
rewrite int_lift_rec_eq.
rewrite int_subst_rec_eq.
rewrite int_lift_rec_eq.
apply El_morph; apply int_morph; auto with *.
intros [|[|k]].
compute; trivial.
simpl; reflexivity.
compute; fold minus.
replace (k-0) with k; auto with *.
Qed.
Let Mirr : forall i j,
val_ok e i j ->
forall o' o'' f g,
isOrd o' ->
o' ⊆ o'' ->
o'' ∈ osucc (int O i) ->
f ∈ cc_prod (Wi i o') (U' i o') ->
g ∈ cc_prod (Wi i o'') (U' i o'') ->
fcompat (Wi i o') f g ->
fcompat (Wi i (osucc o')) (int M (V.cons f (V.cons o' i))) (int M (V.cons g (V.cons o'' i))).
intros.
assert (Oo: isOrd (int O i)).
destruct tyord_inv with (3:=ty_O)(4:=H); trivial.
assert (o'' ⊆ int O i).
apply olts_le in H2; trivial.
assert (val_mono (push_fun (push_ord E (OSucct O)) (WIL 1 (Ref 0)) U)
(V.cons f (V.cons o' i)) (I.cons daimon (I.cons daimon j))
(V.cons g (V.cons o'' i)) (I.cons daimon (I.cons daimon j))).
apply val_mono_1; auto with *.
apply val_mono_refl; trivial.
eauto using isOrd_inv.
transitivity o''; auto.
apply stab in H7.
rewrite El_int_W_lift in H7; trivial.
Qed.
Let Usub : forall i j,
val_ok e i j ->
forall o' o'' x,
isOrd o' ->
o' ⊆ o'' ->
o'' ∈ osucc (int O i) ->
x ∈ Wi i o' ->
U' i o' x ⊆ U' i o'' x.
intros.
assert (Oo: isOrd (int O i)).
destruct tyord_inv with (3:=ty_O)(4:=H); trivial.
assert (o'' ⊆ int O i).
apply olts_le in H2; trivial.
eapply El_sub with (1:=fx_sub_U).
apply val_mono_2; auto with *.
apply val_mono_refl; eexact H.
eauto using isOrd_inv.
Qed.
Lemma WREC_ok i j :
val_ok e i j ->
WREC_assumptions
(El (int A i)) (fun x => El (int B (V.cons x i))) (int O i) (F' i) (U' i).
intros valok.
destruct tyord_inv with (3:=ty_O)(4:=valok); trivial.
split; auto with *.
apply Bw_morph; reflexivity.
unfold U'; auto.
apply (Mty valok).
apply (Mirr valok).
apply (Usub valok).
Qed.
Lemma int_Prod_intro0 dom F0 f t :
morph1 F0 ->
f ∈ (Π x ∈ El dom, El(F0 x)) ->
(forall x u, [x,u] \real dom ->
app f x ∈ El (F0 x) ->
inSAT (Lc.App t u) (Real (F0 x) (app f x))) ->
[f,t] \real prod dom F0.
split.
red; rewrite El_prod; trivial.
do 2 red; intros; apply H; trivial.
rewrite Real_prod; auto.
apply piSAT0_intro'; intros.
apply H1; auto.
apply cc_prod_elim with (1:=H0); trivial.
exists empty; auto.
rewrite El_prod; trivial.
do 2 red; intros; apply H; trivial.
Qed.
Lemma int_Prod_intro A0 B0 f t i :
f ∈ (Π x ∈ El(int A0 i), El(int B0 (V.cons x i))) ->
(forall x u, [x,u] \real (int A0 i) ->
app f x ∈ El(int B0 (V.cons x i)) ->
inSAT (Lc.App t u) (Real (int B0 (V.cons x i)) (app f x))) ->
[f,t] \real int (Prod A0 B0) i.
intros.
apply int_Prod_intro0; trivial.
do 2 red; intros.
rewrite H1; reflexivity.
Qed.
Lemma typ_wfix :
typ e (WFix O M) (Prod (WI A B O) (subst_rec O 1 U)).
red; intros.
destruct tyord_inv with (3:=ty_O)(4:=H); trivial.
apply in_int_intro.
discriminate.
discriminate.
apply and_split; intros.
red; rewrite El_int_prod.
eapply eq_elim.
2:simpl.
2:apply WREC_typ with (1:=WREC_ok H); auto with *.
apply cc_prod_ext.
rewrite El_int_W.
reflexivity.
red; intros.
rewrite int_subst_rec_eq.
rewrite <- V.cons_lams.
2:apply V.cons_morph; reflexivity.
rewrite V.lams0.
rewrite H3; reflexivity.
(**)
simpl.
rewrite Real_prod; auto with *.
2:intros ? ? ? h; rewrite h; reflexivity.
unfold piSAT.