forked from MetaCoq/metacoq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCUICParallelReduction.v
1990 lines (1819 loc) · 92.4 KB
/
PCUICParallelReduction.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
(* Distributed under the terms of the MIT license. *)
Require Import ssreflect ssrbool.
From MetaCoq Require Import LibHypsNaming.
From Equations Require Import Equations.
From Coq Require Import Bool String List Program BinPos Compare_dec Omega String Lia.
From MetaCoq.Template Require Import config utils.
From MetaCoq.PCUIC Require Import PCUICAst PCUICAstUtils PCUICInduction PCUICSize
PCUICLiftSubst PCUICUnivSubst PCUICTyping PCUICReduction PCUICWeakening PCUICSubstitution.
(* Type-valued relations. *)
Require Import CRelationClasses.
Require Import Equations.Type.Relation Equations.Type.Relation_Properties.
Local Set Keyed Unification.
Set Asymmetric Patterns.
Derive NoConfusion for term.
Derive Subterm for term.
Derive Signature NoConfusion for All All2.
Lemma size_lift n k t : size (lift n k t) = size t.
Proof.
revert n k t.
fix size_list 3.
destruct t; simpl; rewrite ?list_size_map_hom; try lia.
elim leb_spec_Set; simpl; auto. intros. auto.
now rewrite !size_list.
now rewrite !size_list.
now rewrite !size_list.
now rewrite !size_list.
intros.
destruct x. simpl. now rewrite size_list.
now rewrite !size_list.
now rewrite !size_list.
unfold mfixpoint_size.
rewrite list_size_map_hom. intros.
simpl. destruct x. simpl. unfold def_size. simpl.
now rewrite !size_list.
reflexivity.
unfold mfixpoint_size.
rewrite list_size_map_hom. intros.
simpl. destruct x. unfold def_size; simpl.
now rewrite !size_list.
reflexivity.
Qed.
Require Import RelationClasses Arith.
Arguments All {A} P%type _.
Lemma All_pair {A} (P Q : A -> Type) l :
All (fun x => P x * Q x)%type l <~> (All P l * All Q l).
Proof.
split. induction 1; intuition auto.
move=> [] Hl Hl'. induction Hl; depelim Hl'; intuition auto.
Qed.
Definition on_local_decl (P : context -> term -> Type)
(Γ : context) (t : term) (T : option term) :=
match T with
| Some T => (P Γ t * P Γ T)%type
| None => P Γ t
end.
Lemma term_forall_ctx_list_ind :
forall (P : context -> term -> Type),
(forall Γ (n : nat), P Γ (tRel n)) ->
(forall Γ (i : ident), P Γ (tVar i)) ->
(forall Γ (n : nat) (l : list term), All (P Γ) l -> P Γ (tEvar n l)) ->
(forall Γ s, P Γ (tSort s)) ->
(forall Γ (n : name) (t : term), P Γ t -> forall t0 : term, P (vass n t :: Γ) t0 -> P Γ (tProd n t t0)) ->
(forall Γ (n : name) (t : term), P Γ t -> forall t0 : term, P (vass n t :: Γ) t0 -> P Γ (tLambda n t t0)) ->
(forall Γ (n : name) (t : term),
P Γ t -> forall t0 : term, P Γ t0 -> forall t1 : term, P (vdef n t t0 :: Γ) t1 -> P Γ (tLetIn n t t0 t1)) ->
(forall Γ (t u : term), P Γ t -> P Γ u -> P Γ (tApp t u)) ->
(forall Γ (s : String.string) (u : list Level.t), P Γ (tConst s u)) ->
(forall Γ (i : inductive) (u : list Level.t), P Γ (tInd i u)) ->
(forall Γ (i : inductive) (n : nat) (u : list Level.t), P Γ (tConstruct i n u)) ->
(forall Γ (p : inductive * nat) (t : term),
P Γ t -> forall t0 : term, P Γ t0 -> forall l : list (nat * term),
tCaseBrsProp (P Γ) l -> P Γ (tCase p t t0 l)) ->
(forall Γ (s : projection) (t : term), P Γ t -> P Γ (tProj s t)) ->
(forall Γ (m : mfixpoint term) (n : nat),
All_local_env (on_local_decl (fun Γ' t => P (Γ ,,, Γ') t)) (fix_context m) ->
tFixProp (P Γ) (P (Γ ,,, fix_context m)) m -> P Γ (tFix m n)) ->
(forall Γ (m : mfixpoint term) (n : nat),
All_local_env (on_local_decl (fun Γ' t => P (Γ ,,, Γ') t)) (fix_context m) ->
tFixProp (P Γ) (P (Γ ,,, fix_context m)) m -> P Γ (tCoFix m n)) ->
forall Γ (t : term), P Γ t.
Proof.
intros.
revert Γ t. set(foo:=Tactics.the_end_of_the_section). intros.
Subterm.rec_wf_rel aux t (MR lt size). simpl. clear H1.
assert (auxl : forall Γ {A} (l : list A) (f : A -> term), list_size (fun x => size (f x)) l < size pr0 ->
All (fun x => P Γ (f x)) l).
{ induction l; constructor. eapply aux. red. simpl in H. lia. apply IHl. simpl in H. lia. }
assert (forall mfix, context_size size (fix_context mfix) <= mfixpoint_size size mfix).
{ induction mfix. simpl. auto. simpl. unfold fix_context.
unfold context_size.
rewrite list_size_rev /=. cbn.
rewrite size_lift. unfold context_size in IHmfix.
epose (list_size_mapi_rec_le (def_size size) (decl_size size) mfix
(fun (i : nat) (d : def term) => vass (dname d) ((lift0 i) (dtype d))) 1).
forward l. intros. destruct x; cbn; rewrite size_lift. lia.
unfold def_size, mfixpoint_size. lia. }
assert (auxl' : forall Γ mfix,
mfixpoint_size size mfix < size pr0 ->
All_local_env (on_local_decl (fun Γ' t => P (Γ ,,, Γ') t)) (fix_context mfix)).
{ move=> Γ mfix H0.
move: (fix_context mfix) {H0} (le_lt_trans _ _ _ (H mfix) H0).
induction fix_context; cbn.
- constructor.
- case: a => [na [b|] ty] /=; rewrite {1}/decl_size /context_size /= => Hlt; constructor; auto.
+ eapply IHfix_context. unfold context_size. lia.
+ simpl. apply aux. red. lia.
+ simpl. split.
* apply aux. red. lia.
* apply aux; red; lia.
+ apply IHfix_context; unfold context_size; lia.
+ apply aux. red. lia. }
assert (forall m, list_size (fun x : def term => size (dtype x)) m < S (mfixpoint_size size m)).
{ clear. unfold mfixpoint_size, def_size. induction m. simpl. auto. simpl. lia. }
assert (forall m, list_size (fun x : def term => size (dbody x)) m < S (mfixpoint_size size m)).
{ clear. unfold mfixpoint_size, def_size. induction m. simpl. auto. simpl. lia. }
move aux at top. move auxl at top. move auxl' at top.
!destruct pr0; eauto;
try match reverse goal with
|- context [tFix _ _] => idtac
| H : _ |- _ => solve [apply H; (eapply aux || eapply auxl); red; simpl; try lia]
end.
eapply X12; try (apply aux; red; simpl; lia).
apply auxl'. simpl. lia.
red. apply All_pair. split; apply auxl; simpl; auto.
eapply X13; try (apply aux; red; simpl; lia).
apply auxl'. simpl. lia.
red. apply All_pair. split; apply auxl; simpl; auto.
Defined.
Lemma simpl_subst' :
forall N M n p k, k = List.length N -> p <= n -> subst N p (lift0 (k + n) M) = lift0 n M.
Proof. intros. subst k. rewrite simpl_subst_rec; auto. now rewrite Nat.add_0_r. lia. Qed.
(** All2 lemmas *)
(* Duplicate *)
Lemma All2_app {A} {P : A -> A -> Type} {l l' r r'} :
All2 P l l' -> All2 P r r' ->
All2 P (l ++ r) (l' ++ r').
Proof. induction 1; simpl; auto. Qed.
Definition All2_prop_eq Γ Γ' {A B} (f : A -> term) (g : A -> B) (rel : forall (Γ Γ' : context) (t t' : term), Type) :=
All2 (on_Trel_eq (rel Γ Γ') f g).
Definition All2_prop Γ (rel : forall (Γ : context) (t t' : term), Type) :=
All2 (rel Γ).
(* Scheme pred1_ind_all_first := Minimality for pred1 Sort Type. *)
Lemma All2_All2_prop {P Q : context -> context -> term -> term -> Type} {par par'} {l l' : list term} :
All2 (P par par') l l' ->
(forall x y, P par par' x y -> Q par par' x y) ->
All2 (Q par par') l l'.
Proof.
intros H aux.
induction H; constructor. unfold on_Trel in *.
apply aux; apply r. apply IHAll2.
Defined.
Lemma All2_All2_prop_eq {A B} {P Q : context -> context -> term -> term -> Type} {par par'}
{f : A -> term} {g : A -> B} {l l' : list A} :
All2 (on_Trel_eq (P par par') f g) l l' ->
(forall x y, P par par' x y -> Q par par' x y) ->
All2_prop_eq par par' f g Q l l'.
Proof.
intros H aux.
induction H; constructor. unfold on_Trel in *.
split. apply aux; apply r. apply r. apply IHAll2.
Defined.
Definition All2_prop2_eq Γ Γ' Γ2 Γ2' {A B} (f g : A -> term) (h : A -> B)
(rel : forall (Γ Γ' : context) (t t' : term), Type) :=
All2 (fun x y => on_Trel (rel Γ Γ') f x y * on_Trel_eq (rel Γ2 Γ2') g h x y)%type.
Definition All2_prop2 Γ Γ' {A} (f g : A -> term)
(rel : forall (Γ : context) (t t' : term), Type) :=
All2 (fun x y => on_Trel (rel Γ) f x y * on_Trel (rel Γ') g x y)%type.
Lemma All2_All2_prop2_eq {A B} {P Q : context -> context -> term -> term -> Type} {par par' par2 par2'}
{f g : A -> term} {h : A -> B} {l l' : list A} :
All2_prop2_eq par par' par2 par2' f g h P l l' ->
(forall par par' x y, P par par' x y -> Q par par' x y) ->
All2_prop2_eq par par' par2 par2' f g h Q l l'.
Proof.
intros H aux.
induction H; constructor. unfold on_Trel in *. split.
apply aux. destruct r. apply p. split. apply aux. apply r. apply r. apply IHAll2.
Defined.
(* Lemma All2_All2_prop2 {A} {P Q : context -> term -> term -> Type} {par par'} *)
(* {f g : A -> term} {l l' : list A} : *)
(* All2_prop2 par par' f g P l l' -> *)
(* (forall par x y, P par x y -> Q par x y) -> *)
(* All2_prop2 par par' f g Q l l'. *)
(* Proof. *)
(* intros H aux. *)
(* induction H; constructor. unfold on_Trel in *. split. *)
(* apply aux. destruct r. apply p. apply aux. apply r. apply IHAll2. *)
(* Defined. *)
Section All2_local_env.
Definition on_decl (P : context -> context -> term -> term -> Type)
(Γ Γ' : context) (b : option (term * term)) (t t' : term) :=
match b with
| Some (b, b') => (P Γ Γ' b b' * P Γ Γ' t t')%type
| None => P Γ Γ' t t'
end.
Definition on_decls (P : term -> term -> Type) (d d' : context_decl) :=
match d.(decl_body), d'.(decl_body) with
| Some b, Some b' => (P b b' * P d.(decl_type) d'.(decl_type))%type
| None, None => P d.(decl_type) d'.(decl_type)
| _, _ => False
end.
Section All_local_2.
Context (P : forall (Γ Γ' : context), option (term * term) -> term -> term -> Type).
Inductive All2_local_env : context -> context -> Type :=
| localenv2_nil : All2_local_env [] []
| localenv2_cons_abs Γ Γ' na na' t t' :
All2_local_env Γ Γ' ->
P Γ Γ' None t t' ->
All2_local_env (Γ ,, vass na t) (Γ' ,, vass na' t')
| localenv2_cons_def Γ Γ' na na' b b' t t' :
All2_local_env Γ Γ' ->
P Γ Γ' (Some (b, b')) t t' ->
All2_local_env (Γ ,, vdef na b t) (Γ' ,, vdef na' b' t').
End All_local_2.
Definition on_decl_over (P : context -> context -> term -> term -> Type) Γ Γ' :=
fun Δ Δ' => P (Γ ,,, Δ) (Γ' ,,, Δ').
Definition All2_local_env_over P Γ Γ' := All2_local_env (on_decl (on_decl_over P Γ Γ')).
Lemma All2_local_env_impl {P Q : context -> context -> term -> term -> Type} {par par'} :
All2_local_env (on_decl P) par par' ->
(forall par par' x y, P par par' x y -> Q par par' x y) ->
All2_local_env (on_decl Q) par par'.
Proof.
intros H aux.
induction H; constructor. auto. red in p. apply aux, p.
apply IHAll2_local_env. red. split.
apply aux. apply p. apply aux. apply p.
Defined.
Lemma All2_local_env_app_inv :
forall P (Γ Γ' Γl Γr : context),
All2_local_env (on_decl P) Γ Γl ->
All2_local_env (on_decl (on_decl_over P Γ Γl)) Γ' Γr ->
All2_local_env (on_decl P) (Γ ,,, Γ') (Γl ,,, Γr).
Proof.
induction 2; auto.
- simpl. constructor; auto.
- simpl. constructor; auto.
Qed.
Lemma All2_local_env_length {P l l'} : @All2_local_env P l l' -> #|l| = #|l'|.
Proof. induction 1; simpl; auto. Qed.
Hint Extern 20 (#|?X| = #|?Y|) =>
match goal with
[ H : All2_local_env _ ?X ?Y |- _ ] => apply (All2_local_env_length H)
| [ H : All2_local_env _ ?Y ?X |- _ ] => symmetry; apply (All2_local_env_length H)
| [ H : All2_local_env_over _ _ _ ?X ?Y |- _ ] => apply (All2_local_env_length H)
| [ H : All2_local_env_over _ _ _ ?Y ?X |- _ ] => symmetry; apply (All2_local_env_length H)
end : pcuic.
Ltac pcuic := eauto with pcuic.
Lemma All2_local_env_app':
forall P (Γ Γ' Γ'' : context),
All2_local_env (on_decl P) (Γ ,,, Γ') Γ'' ->
∑ Γl Γr, (Γ'' = Γl ,,, Γr) /\ #|Γ'| = #|Γr| /\ #|Γ| = #|Γl|.
Proof.
intros *.
revert Γ''. induction Γ'. simpl. intros.
exists Γ'', []. intuition auto. eapply (All2_local_env_length X).
intros. unfold app_context in X. depelim X.
destruct (IHΓ' _ X) as [Γl [Γr [Heq HeqΓ]]]. subst Γ'0.
eexists Γl, (Γr,, vass _ t'). simpl. intuition eauto.
destruct (IHΓ' _ X) as [Γl [Γr [Heq HeqΓ]]]. subst Γ'0.
eexists Γl, (Γr,, vdef _ b' t'). simpl. intuition eauto.
Qed.
Lemma app_inj_length_r {A} (l l' r r' : list A) :
app l r = app l' r' -> #|r| = #|r'| -> l = l' /\ r = r'.
Proof.
induction r in l, l', r' |- *. destruct r'; intros; simpl in *; intuition auto; try discriminate.
now rewrite !app_nil_r in H.
intros. destruct r'; try discriminate.
simpl in H.
change (l ++ a :: r) with (l ++ [a] ++ r) in H.
change (l' ++ a0 :: r') with (l' ++ [a0] ++ r') in H.
rewrite !app_assoc in H. destruct (IHr _ _ _ H). now noconf H0.
subst. now apply app_inj_tail in H1 as [-> ->].
Qed.
Lemma app_inj_length_l {A} (l l' r r' : list A) :
app l r = app l' r' -> #|l| = #|l'| -> l = l' /\ r = r'.
Proof.
induction l in r, r', l' |- *. destruct l'; intros; simpl in *; intuition auto; try discriminate.
intros. destruct l'; try discriminate. simpl in *. noconf H.
specialize (IHl _ _ _ H). forward IHl; intuition congruence.
Qed.
Lemma All2_local_env_app_ex:
forall P (Γ Γ' Γ'' : context),
All2_local_env (on_decl P) (Γ ,,, Γ') Γ'' ->
∑ Γl Γr, (Γ'' = Γl ,,, Γr) *
All2_local_env
(on_decl P)
Γ Γl * All2_local_env (on_decl (fun Δ Δ' => P (Γ ,,, Δ) (Γl ,,, Δ'))) Γ' Γr.
Proof.
intros *.
revert Γ''. induction Γ'. simpl. intros.
exists Γ'', []. intuition auto. constructor.
intros. unfold app_context in X. depelim X.
destruct (IHΓ' _ X) as [Γl [Γr [[HeqΓ H2] H3]]]. subst.
eexists _, _. intuition eauto. unfold snoc, app_context.
now rewrite app_comm_cons. constructor. auto. auto.
destruct (IHΓ' _ X) as [Γl [Γr [[HeqΓ H2] H3]]]. subst.
eexists _, _. intuition eauto. unfold snoc, app_context.
now rewrite app_comm_cons. constructor. auto. auto.
Qed.
Lemma All2_local_env_app :
forall P (Γ Γ' Γl Γr : context),
All2_local_env (on_decl P) (Γ ,,, Γ') (Γl ,,, Γr) ->
#|Γ| = #|Γl| ->
All2_local_env (on_decl P) Γ Γl * All2_local_env (on_decl (fun Δ Δ' => P (Γ ,,, Δ) (Γl ,,, Δ'))) Γ' Γr.
Proof.
intros *.
intros. pose proof X as X'.
apply All2_local_env_app' in X as [Γl' [Γr' ?]].
destruct a as [? [? ?]].
apply All2_local_env_app_ex in X' as [Γl2' [Γr2' [[? ?] ?]]].
subst; rename_all_hyps.
unfold app_context in heq_app_context.
eapply app_inj_length_r in heq_app_context; try lia. destruct heq_app_context. subst.
unfold app_context in heq_app_context0.
eapply app_inj_length_r in heq_app_context0; try lia. intuition subst; auto.
pose proof (All2_local_env_length a). lia.
Qed.
Lemma nth_error_pred1_ctx {P} {Γ Δ} i body' :
All2_local_env (on_decl P) Γ Δ ->
option_map decl_body (nth_error Δ i) = Some (Some body') ->
{ body & (option_map decl_body (nth_error Γ i) = Some (Some body)) *
P (skipn (S i) Γ) (skipn (S i) Δ) body body' }%type.
Proof.
intros Hpred. revert i body'.
induction Hpred; destruct i; try discriminate; auto; !intros.
simpl in heq_option_map. specialize (IHHpred _ _ heq_option_map) as [body [Heq Hpred']].
intuition eauto.
noconf heq_option_map. exists b. intuition eauto. cbv. apply p.
simpl in heq_option_map. specialize (IHHpred _ _ heq_option_map) as [body [Heq Hpred']].
intuition eauto.
Qed.
Lemma nth_error_pred1_ctx_l {P} {Γ Δ} i body :
All2_local_env (on_decl P) Γ Δ ->
option_map decl_body (nth_error Γ i) = Some (Some body) ->
{ body' & (option_map decl_body (nth_error Δ i) = Some (Some body')) *
P (skipn (S i) Γ) (skipn (S i) Δ) body body' }%type.
Proof.
intros Hpred. revert i body.
induction Hpred; destruct i; try discriminate; auto; !intros.
simpl in heq_option_map. specialize (IHHpred _ _ heq_option_map) as [body' [Heq Hpred']].
intuition eauto.
noconf heq_option_map. exists b'. intuition eauto. cbv. apply p.
simpl in heq_option_map. specialize (IHHpred _ _ heq_option_map) as [body' [Heq Hpred']].
intuition eauto.
Qed.
Lemma All2_local_env_over_app P {Γ0 Δ Γ'' Δ''} :
All2_local_env (on_decl P) Γ0 Δ ->
All2_local_env_over P Γ0 Δ Γ'' Δ'' ->
All2_local_env (on_decl P) (Γ0 ,,, Γ'') (Δ ,,, Δ'').
Proof.
intros. induction X0; pcuic; constructor; pcuic.
Qed.
Lemma All2_local_env_app_left {P Γ Γ' Δ Δ'} :
All2_local_env (on_decl P) (Γ ,,, Δ) (Γ' ,,, Δ') -> #|Γ| = #|Γ'| ->
All2_local_env (on_decl P) Γ Γ'.
Proof.
intros. eapply All2_local_env_app in X; intuition auto.
Qed.
End All2_local_env.
Section ParallelReduction.
Context (Σ : global_env).
Definition pred_atom t :=
match t with
| tVar _
| tSort _
| tInd _ _
| tConstruct _ _ _ => true
| _ => false
end.
Inductive pred1 (Γ Γ' : context) : term -> term -> Type :=
(** Reductions *)
(** Beta *)
| pred_beta na t0 t1 b0 b1 a0 a1 :
pred1 Γ Γ' t0 t1 ->
pred1 (Γ ,, vass na t0) (Γ' ,, vass na t1) b0 b1 -> pred1 Γ Γ' a0 a1 ->
pred1 Γ Γ' (tApp (tLambda na t0 b0) a0) (subst10 a1 b1)
(** Let *)
| pred_zeta na d0 d1 t0 t1 b0 b1 :
pred1 Γ Γ' t0 t1 ->
pred1 Γ Γ' d0 d1 -> pred1 (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 ->
pred1 Γ Γ' (tLetIn na d0 t0 b0) (subst10 d1 b1)
(** Local variables *)
| pred_rel_def_unfold i body :
All2_local_env (on_decl pred1) Γ Γ' ->
option_map decl_body (nth_error Γ' i) = Some (Some body) ->
pred1 Γ Γ' (tRel i) (lift0 (S i) body)
| pred_rel_refl i :
All2_local_env (on_decl pred1) Γ Γ' ->
pred1 Γ Γ' (tRel i) (tRel i)
(** Case *)
| pred_iota ind pars c u args0 args1 p brs0 brs1 :
All2_local_env (on_decl pred1) Γ Γ' ->
All2 (pred1 Γ Γ') args0 args1 ->
All2 (on_Trel_eq (pred1 Γ Γ') snd fst) brs0 brs1 ->
pred1 Γ Γ' (tCase (ind, pars) p (mkApps (tConstruct ind c u) args0) brs0)
(iota_red pars c args1 brs1)
(** Fix unfolding, with guard *)
| pred_fix mfix0 mfix1 idx args0 args1 narg fn :
All2_local_env (on_decl pred1) Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) pred1 mfix0 mfix1 ->
unfold_fix mfix1 idx = Some (narg, fn) ->
is_constructor narg args1 = true ->
All2 (pred1 Γ Γ') args0 args1 ->
pred1 Γ Γ' (mkApps (tFix mfix0 idx) args0) (mkApps fn args1)
(** CoFix-case unfolding *)
| pred_cofix_case ip p0 p1 mfix0 mfix1 idx args0 args1 narg fn brs0 brs1 :
All2_local_env (on_decl pred1) Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) pred1 mfix0 mfix1 ->
unfold_cofix mfix1 idx = Some (narg, fn) ->
All2 (pred1 Γ Γ') args0 args1 ->
pred1 Γ Γ' p0 p1 ->
All2 (on_Trel_eq (pred1 Γ Γ') snd fst) brs0 brs1 ->
pred1 Γ Γ' (tCase ip p0 (mkApps (tCoFix mfix0 idx) args0) brs0)
(tCase ip p1 (mkApps fn args1) brs1)
(** CoFix-proj unfolding *)
| pred_cofix_proj p mfix0 mfix1 idx args0 args1 narg fn :
All2_local_env (on_decl pred1) Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) pred1 mfix0 mfix1 ->
unfold_cofix mfix1 idx = Some (narg, fn) ->
All2 (pred1 Γ Γ') args0 args1 ->
pred1 Γ Γ' (tProj p (mkApps (tCoFix mfix0 idx) args0))
(tProj p (mkApps fn args1))
(** Constant unfolding *)
| pred_delta c decl body (isdecl : declared_constant Σ c decl) u :
All2_local_env (on_decl pred1) Γ Γ' ->
decl.(cst_body) = Some body ->
pred1 Γ Γ' (tConst c u) (subst_instance_constr u body)
| pred_const c u :
All2_local_env (on_decl pred1) Γ Γ' ->
pred1 Γ Γ' (tConst c u) (tConst c u)
(** Proj *)
| pred_proj i pars narg k u args0 args1 arg1 :
All2_local_env (on_decl pred1) Γ Γ' ->
All2 (pred1 Γ Γ') args0 args1 ->
nth_error args1 (pars + narg) = Some arg1 ->
pred1 Γ Γ' (tProj (i, pars, narg) (mkApps (tConstruct i k u) args0)) arg1
(** Congruences *)
| pred_abs na M M' N N' : pred1 Γ Γ' M M' -> pred1 (Γ ,, vass na M) (Γ' ,, vass na M') N N' ->
pred1 Γ Γ' (tLambda na M N) (tLambda na M' N')
| pred_app M0 M1 N0 N1 :
pred1 Γ Γ' M0 M1 ->
pred1 Γ Γ' N0 N1 ->
pred1 Γ Γ' (tApp M0 N0) (tApp M1 N1)
(* do not handle mkApps yet *)
| pred_letin na d0 d1 t0 t1 b0 b1 :
pred1 Γ Γ' d0 d1 -> pred1 Γ Γ' t0 t1 -> pred1 (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 ->
pred1 Γ Γ' (tLetIn na d0 t0 b0) (tLetIn na d1 t1 b1)
| pred_case ind p0 p1 c0 c1 brs0 brs1 :
pred1 Γ Γ' p0 p1 ->
pred1 Γ Γ' c0 c1 ->
All2 (on_Trel_eq (pred1 Γ Γ') snd fst) brs0 brs1 ->
pred1 Γ Γ' (tCase ind p0 c0 brs0) (tCase ind p1 c1 brs1)
| pred_proj_congr p c c' :
pred1 Γ Γ' c c' -> pred1 Γ Γ' (tProj p c) (tProj p c')
| pred_fix_congr mfix0 mfix1 idx :
All2_local_env (on_decl pred1) Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) pred1 mfix0 mfix1 ->
pred1 Γ Γ' (tFix mfix0 idx) (tFix mfix1 idx)
| pred_cofix_congr mfix0 mfix1 idx :
All2_local_env (on_decl pred1) Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) pred1 mfix0 mfix1 ->
pred1 Γ Γ' (tCoFix mfix0 idx) (tCoFix mfix1 idx)
| pred_prod na M0 M1 N0 N1 : pred1 Γ Γ' M0 M1 -> pred1 (Γ ,, vass na M0) (Γ' ,, vass na M1) N0 N1 ->
pred1 Γ Γ' (tProd na M0 N0) (tProd na M1 N1)
| evar_pred ev l l' :
All2_local_env (on_decl pred1) Γ Γ' ->
All2 (pred1 Γ Γ') l l' -> pred1 Γ Γ' (tEvar ev l) (tEvar ev l')
| pred_atom_refl t :
All2_local_env (on_decl pred1) Γ Γ' ->
pred_atom t -> pred1 Γ Γ' t t.
Notation pred1_ctx Γ Γ' := (All2_local_env (on_decl pred1) Γ Γ').
Ltac my_rename_hyp h th :=
match th with
| pred1_ctx _ _ ?G => fresh "pred" G
| _ => PCUICWeakeningEnv.my_rename_hyp h th
end.
Ltac rename_hyp h ht ::= my_rename_hyp h ht.
Definition extendP {P Q: context -> context -> term -> term -> Type}
(aux : forall Γ Γ' t t', P Γ Γ' t t' -> Q Γ Γ' t t') :
(forall Γ Γ' t t', P Γ Γ' t t' -> (P Γ Γ' t t' * Q Γ Γ' t t')).
Proof.
intros. split. apply X. apply aux. apply X.
Defined.
(* Lemma pred1_ind_all : *)
(* forall P : forall (Γ Γ' : context) (t t0 : term), Type, *)
(* let P' Γ Γ' x y := ((pred1 Γ Γ' x y) * P Γ Γ' x y)%type in *)
(* (forall (Γ Γ' : context) (na : name) (t0 t1 b0 b1 a0 a1 : term), *)
(* pred1 (Γ ,, vass na t0) (Γ' ,, vass na t1) b0 b1 -> P (Γ ,, vass na t0) (Γ' ,, vass na t1) b0 b1 -> *)
(* pred1 Γ Γ' t0 t1 -> P Γ Γ' t0 t1 -> *)
(* pred1 Γ Γ' a0 a1 -> P Γ Γ' a0 a1 -> P Γ Γ' (tApp (tLambda na t0 b0) a0) (b1 {0 := a1})) -> *)
(* (forall (Γ Γ' : context) (na : name) (d0 d1 t0 t1 b0 b1 : term), *)
(* pred1 Γ Γ' t0 t1 -> P Γ Γ' t0 t1 -> *)
(* pred1 Γ Γ' d0 d1 -> P Γ Γ' d0 d1 -> *)
(* pred1 (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 -> *)
(* P (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 -> P Γ Γ' (tLetIn na d0 t0 b0) (b1 {0 := d1})) -> *)
(* (forall (Γ Γ' : context) (i : nat) (body : term), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* option_map decl_body (nth_error Γ' i) = Some (Some body) -> *)
(* P Γ Γ' (tRel i) (lift0 (S i) body)) -> *)
(* (forall (Γ Γ' : context) (i : nat), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* P Γ Γ' (tRel i) (tRel i)) -> *)
(* (forall (Γ Γ' : context) (ind : inductive) (pars c : nat) (u : universe_instance) (args0 args1 : list term) *)
(* (p : term) (brs0 brs1 : list (nat * term)), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* All2 (P' Γ Γ') args0 args1 -> *)
(* All2_prop_eq Γ Γ' snd fst P' brs0 brs1 -> *)
(* P Γ Γ' (tCase (ind, pars) p (mkApps (tConstruct ind c u) args0) brs0) (iota_red pars c args1 brs1)) -> *)
(* (forall (Γ Γ' : context) (mfix : mfixpoint term) (idx : nat) (args0 args1 : list term) (narg : nat) (fn0 fn1 : term), *)
(* unfold_fix mfix idx = Some (narg, fn0) -> *)
(* is_constructor narg args1 = true -> *)
(* All2 (P' Γ Γ') args0 args1 -> *)
(* pred1 Γ Γ' fn0 fn1 -> P Γ Γ' fn0 fn1 -> P Γ Γ' (mkApps (tFix mfix idx) args0) (mkApps fn1 args1)) -> *)
(* (forall (Γ Γ' : context) (ip : inductive * nat) (p0 p1 : term) (mfix : mfixpoint term) (idx : nat) *)
(* (args0 args1 : list term) (narg : nat) (fn0 fn1 : term) (brs0 brs1 : list (nat * term)), *)
(* unfold_cofix mfix idx = Some (narg, fn0) -> *)
(* All2 (P' Γ Γ') args0 args1 -> *)
(* pred1 Γ Γ' fn0 fn1 -> *)
(* P Γ Γ' fn0 fn1 -> *)
(* pred1 Γ Γ' p0 p1 -> *)
(* P Γ Γ' p0 p1 -> *)
(* All2_prop_eq Γ Γ' snd fst P' brs0 brs1 -> *)
(* P Γ Γ' (tCase ip p0 (mkApps (tCoFix mfix idx) args0) brs0) (tCase ip p1 (mkApps fn1 args1) brs1)) -> *)
(* (forall (Γ Γ' : context) (p : projection) (mfix : mfixpoint term) (idx : nat) (args0 args1 : list term) *)
(* (narg : nat) (fn0 fn1 : term), *)
(* unfold_cofix mfix idx = Some (narg, fn0) -> *)
(* All2 (P' Γ Γ') args0 args1 -> *)
(* pred1 Γ Γ' fn0 fn1 -> P Γ Γ' fn0 fn1 -> *)
(* P Γ Γ' (tProj p (mkApps (tCoFix mfix idx) args0)) (tProj p (mkApps fn1 args1))) -> *)
(* (forall (Γ Γ' : context) (c : ident) (decl : constant_body) (body : term), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* declared_constant Σ c decl -> *)
(* forall u : universe_instance, cst_body decl = Some body -> *)
(* P Γ Γ' (tConst c u) (subst_instance_constr u body)) -> *)
(* (forall (Γ Γ' : context) (c : ident) (u : universe_instance), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* P Γ Γ' (tConst c u) (tConst c u)) -> *)
(* (forall (Γ Γ' : context) (i : inductive) (pars narg : nat) (k : nat) (u : universe_instance) *)
(* (args0 args1 : list term) (arg1 : term), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* All2 (pred1 Γ Γ') args0 args1 -> *)
(* All2 (P Γ Γ') args0 args1 -> *)
(* nth_error args1 (pars + narg) = Some arg1 -> *)
(* P Γ Γ' (tProj (i, pars, narg) (mkApps (tConstruct i k u) args0)) arg1) -> *)
(* (forall (Γ Γ' : context) (na : name) (M M' N N' : term), *)
(* pred1 Γ Γ' M M' -> *)
(* P Γ Γ' M M' -> pred1 (Γ,, vass na M) (Γ' ,, vass na M') N N' -> *)
(* P (Γ,, vass na M) (Γ' ,, vass na M') N N' -> P Γ Γ' (tLambda na M N) (tLambda na M' N')) -> *)
(* (forall (Γ Γ' : context) (M0 M1 N0 N1 : term), *)
(* pred1 Γ Γ' M0 M1 -> P Γ Γ' M0 M1 -> pred1 Γ Γ' N0 N1 -> P Γ Γ' N0 N1 -> P Γ Γ' (tApp M0 N0) (tApp M1 N1)) -> *)
(* (forall (Γ Γ' : context) (na : name) (d0 d1 t0 t1 b0 b1 : term), *)
(* pred1 Γ Γ' d0 d1 -> *)
(* P Γ Γ' d0 d1 -> *)
(* pred1 Γ Γ' t0 t1 -> *)
(* P Γ Γ' t0 t1 -> *)
(* pred1 (Γ,, vdef na d0 t0) (Γ',,vdef na d1 t1) b0 b1 -> *)
(* P (Γ,, vdef na d0 t0) (Γ',,vdef na d1 t1) b0 b1 -> P Γ Γ' (tLetIn na d0 t0 b0) (tLetIn na d1 t1 b1)) -> *)
(* (forall (Γ Γ' : context) (ind : inductive * nat) (p0 p1 c0 c1 : term) (brs0 brs1 : list (nat * term)), *)
(* pred1 Γ Γ' p0 p1 -> *)
(* P Γ Γ' p0 p1 -> *)
(* pred1 Γ Γ' c0 c1 -> *)
(* P Γ Γ' c0 c1 -> All2_prop_eq Γ Γ' snd fst P' brs0 brs1 -> *)
(* P Γ Γ' (tCase ind p0 c0 brs0) (tCase ind p1 c1 brs1)) -> *)
(* (forall (Γ Γ' : context) (p : projection) (c c' : term), *)
(* pred1 Γ Γ' c c' -> P Γ Γ' c c' -> P Γ Γ' (tProj p c) (tProj p c')) -> *)
(* (forall (Γ Γ' : context) (mfix0 : mfixpoint term) (mfix1 : list (def term)) (idx : nat), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) -> *)
(* All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) -> *)
(* All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) *)
(* dtype dbody (fun x => (dname x, rarg x)) P' mfix0 mfix1 -> *)
(* P Γ Γ' (tFix mfix0 idx) (tFix mfix1 idx)) -> *)
(* (forall (Γ Γ' : context) (mfix0 : mfixpoint term) (mfix1 : list (def term)) (idx : nat), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) -> *)
(* All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) -> *)
(* All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) dtype dbody (fun x => (dname x, rarg x)) P' mfix0 mfix1 -> *)
(* P Γ Γ' (tCoFix mfix0 idx) (tCoFix mfix1 idx)) -> *)
(* (forall (Γ Γ' : context) (na : name) (M0 M1 N0 N1 : term), *)
(* pred1 Γ Γ' M0 M1 -> *)
(* P Γ Γ' M0 M1 -> pred1 (Γ,, vass na M0) (Γ' ,, vass na M1) N0 N1 -> *)
(* P (Γ,, vass na M0) (Γ' ,, vass na M1) N0 N1 -> P Γ Γ' (tProd na M0 N0) (tProd na M1 N1)) -> *)
(* (forall (Γ Γ' : context) (ev : nat) (l l' : list term), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* All2 (P' Γ Γ') l l' -> P Γ Γ' (tEvar ev l) (tEvar ev l')) -> *)
(* (forall (Γ Γ' : context) (t : term), *)
(* All2_local_env (on_decl pred1) Γ Γ' -> *)
(* All2_local_env (on_decl P) Γ Γ' -> *)
(* pred_atom t -> P Γ Γ' t t) -> *)
(* forall (Γ Γ' : context) (t t0 : term), pred1 Γ Γ' t t0 -> P Γ Γ' t t0. *)
(* Proof. *)
(* intros. revert Γ Γ' t t0 X20. *)
(* fix aux 5. intros Γ Γ' t t'. *)
(* move aux at top. *)
(* destruct 1; match goal with *)
(* | |- P _ _ (tFix _ _) (tFix _ _) => idtac *)
(* | |- P _ _ (tCoFix _ _) (tCoFix _ _) => idtac *)
(* | |- P _ _ (mkApps (tFix _ _) _) _ => idtac *)
(* | |- P _ _ (tCase _ _ (mkApps (tCoFix _ _) _) _) _ => idtac *)
(* | |- P _ _ (tProj _ (mkApps (tCoFix _ _) _)) _ => idtac *)
(* | |- P _ _ (tRel _) _ => idtac *)
(* | |- P _ _ (tConst _ _) _ => idtac *)
(* | H : _ |- _ => eapply H; eauto *)
(* end. *)
(* - simpl. apply X1; auto. *)
(* apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - simpl. apply X2; auto. *)
(* apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - eapply (All2_All2_prop (P:=pred1) (Q:=P') a0 ((extendP aux) Γ Γ')). *)
(* - eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) (g:=fst) a1 (extendP aux Γ Γ')). *)
(* - eapply X4; eauto. *)
(* eapply (All2_All2_prop (P:=pred1) (Q:=P') a (extendP aux Γ Γ')). *)
(* - eapply X5; eauto. *)
(* eapply (All2_All2_prop (P:=pred1) (Q:=P') a (extendP aux Γ Γ')). *)
(* eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) a0 (extendP aux Γ Γ')). *)
(* - eapply X6; eauto. *)
(* eapply (All2_All2_prop (P:=pred1) (Q:=P') a (extendP aux Γ Γ')). *)
(* - eapply X7; eauto. *)
(* apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - eapply X8; eauto. *)
(* apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - apply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - eapply (All2_All2_prop (P:=pred1) (Q:=P) a0). intros. apply (aux _ _ _ _ X20). *)
(* - eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) a (extendP aux Γ Γ')). *)
(* - eapply X15. *)
(* eapply (All2_local_env_impl a). intros. apply X20. *)
(* eapply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* eapply (All2_local_env_impl a0). intros. red. exact X20. *)
(* eapply (All2_local_env_impl a0). intros. red. apply (aux _ _ _ _ X20). *)
(* eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)). *)
(* - eapply X16. *)
(* eapply (All2_local_env_impl a). intros. apply X20. *)
(* eapply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* eapply (All2_local_env_impl a0). intros. red. exact X20. *)
(* eapply (All2_local_env_impl a0). intros. red. apply (aux _ _ _ _ X20). *)
(* eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)). *)
(* - eapply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* - eapply (All2_All2_prop (P:=pred1) (Q:=P') a0 (extendP aux Γ Γ')). *)
(* - eapply (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20). *)
(* Defined. *)
Lemma pred1_ind_all_ctx :
forall (P : forall (Γ Γ' : context) (t t0 : term), Type)
(Pctx : forall (Γ Γ' : context), Type),
(* (Plist : forall {A} (f : A -> term), context -> context -> list A -> list A -> Type), *)
let P' Γ Γ' x y := ((pred1 Γ Γ' x y) * P Γ Γ' x y)%type in
(forall Γ Γ', All2_local_env (on_decl pred1) Γ Γ' -> All2_local_env (on_decl P) Γ Γ' -> Pctx Γ Γ') ->
(* (forall (f : A -> term) (l l' : list A) (g : A -> B), *)
(* All2 (on_Trel pred1 f) l l' -> *)
(* All2 (on_Trel P f) l l' -> *)
(* All2 (on_Trel eq g) l l' -> *)
(* Plist f Γ Γ' l l') -> *)
(forall (Γ Γ' : context) (na : name) (t0 t1 b0 b1 a0 a1 : term),
pred1 (Γ ,, vass na t0) (Γ' ,, vass na t1) b0 b1 -> P (Γ ,, vass na t0) (Γ' ,, vass na t1) b0 b1 ->
pred1 Γ Γ' t0 t1 -> P Γ Γ' t0 t1 ->
pred1 Γ Γ' a0 a1 -> P Γ Γ' a0 a1 -> P Γ Γ' (tApp (tLambda na t0 b0) a0) (b1 {0 := a1})) ->
(forall (Γ Γ' : context) (na : name) (d0 d1 t0 t1 b0 b1 : term),
pred1 Γ Γ' t0 t1 -> P Γ Γ' t0 t1 ->
pred1 Γ Γ' d0 d1 -> P Γ Γ' d0 d1 ->
pred1 (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 ->
P (Γ ,, vdef na d0 t0) (Γ' ,, vdef na d1 t1) b0 b1 -> P Γ Γ' (tLetIn na d0 t0 b0) (b1 {0 := d1})) ->
(forall (Γ Γ' : context) (i : nat) (body : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
option_map decl_body (nth_error Γ' i) = Some (Some body) ->
P Γ Γ' (tRel i) (lift0 (S i) body)) ->
(forall (Γ Γ' : context) (i : nat),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
P Γ Γ' (tRel i) (tRel i)) ->
(forall (Γ Γ' : context) (ind : inductive) (pars c : nat) (u : universe_instance) (args0 args1 : list term)
(p : term) (brs0 brs1 : list (nat * term)),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2 (P' Γ Γ') args0 args1 ->
All2_prop_eq Γ Γ' snd fst P' brs0 brs1 ->
P Γ Γ' (tCase (ind, pars) p (mkApps (tConstruct ind c u) args0) brs0) (iota_red pars c args1 brs1)) ->
(forall (Γ Γ' : context) (mfix0 mfix1 : mfixpoint term) (idx : nat) (args0 args1 : list term) (narg : nat) (fn : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) dtype dbody
(fun x => (dname x, rarg x)) P' mfix0 mfix1 ->
unfold_fix mfix1 idx = Some (narg, fn) ->
is_constructor narg args1 = true ->
All2 (P' Γ Γ') args0 args1 ->
P Γ Γ' (mkApps (tFix mfix0 idx) args0) (mkApps fn args1)) ->
(forall (Γ Γ' : context) (ip : inductive * nat) (p0 p1 : term) (mfix0 mfix1 : mfixpoint term) (idx : nat)
(args0 args1 : list term) (narg : nat) (fn : term) (brs0 brs1 : list (nat * term)),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) dtype dbody
(fun x => (dname x, rarg x)) P' mfix0 mfix1 ->
unfold_cofix mfix1 idx = Some (narg, fn) ->
All2 (P' Γ Γ') args0 args1 ->
pred1 Γ Γ' p0 p1 ->
P Γ Γ' p0 p1 ->
All2_prop_eq Γ Γ' snd fst P' brs0 brs1 ->
P Γ Γ' (tCase ip p0 (mkApps (tCoFix mfix0 idx) args0) brs0) (tCase ip p1 (mkApps fn args1) brs1)) ->
(forall (Γ Γ' : context) (p : projection) (mfix0 mfix1 : mfixpoint term)
(idx : nat) (args0 args1 : list term)
(narg : nat) (fn : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) dtype dbody
(fun x => (dname x, rarg x)) P' mfix0 mfix1 ->
unfold_cofix mfix1 idx = Some (narg, fn) ->
All2 (P' Γ Γ') args0 args1 ->
P Γ Γ' (tProj p (mkApps (tCoFix mfix0 idx) args0)) (tProj p (mkApps fn args1))) ->
(forall (Γ Γ' : context) (c : ident) (decl : constant_body) (body : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
declared_constant Σ c decl ->
forall u : universe_instance, cst_body decl = Some body ->
P Γ Γ' (tConst c u) (subst_instance_constr u body)) ->
(forall (Γ Γ' : context) (c : ident) (u : universe_instance),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
P Γ Γ' (tConst c u) (tConst c u)) ->
(forall (Γ Γ' : context) (i : inductive) (pars narg : nat) (k : nat) (u : universe_instance)
(args0 args1 : list term) (arg1 : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2 (pred1 Γ Γ') args0 args1 ->
All2 (P Γ Γ') args0 args1 ->
nth_error args1 (pars + narg) = Some arg1 ->
P Γ Γ' (tProj (i, pars, narg) (mkApps (tConstruct i k u) args0)) arg1) ->
(forall (Γ Γ' : context) (na : name) (M M' N N' : term),
pred1 Γ Γ' M M' ->
P Γ Γ' M M' -> pred1 (Γ,, vass na M) (Γ' ,, vass na M') N N' ->
P (Γ,, vass na M) (Γ' ,, vass na M') N N' -> P Γ Γ' (tLambda na M N) (tLambda na M' N')) ->
(forall (Γ Γ' : context) (M0 M1 N0 N1 : term),
pred1 Γ Γ' M0 M1 -> P Γ Γ' M0 M1 -> pred1 Γ Γ' N0 N1 ->
P Γ Γ' N0 N1 -> P Γ Γ' (tApp M0 N0) (tApp M1 N1)) ->
(forall (Γ Γ' : context) (na : name) (d0 d1 t0 t1 b0 b1 : term),
pred1 Γ Γ' d0 d1 ->
P Γ Γ' d0 d1 ->
pred1 Γ Γ' t0 t1 ->
P Γ Γ' t0 t1 ->
pred1 (Γ,, vdef na d0 t0) (Γ',,vdef na d1 t1) b0 b1 ->
P (Γ,, vdef na d0 t0) (Γ',,vdef na d1 t1) b0 b1 -> P Γ Γ' (tLetIn na d0 t0 b0) (tLetIn na d1 t1 b1)) ->
(forall (Γ Γ' : context) (ind : inductive * nat) (p0 p1 c0 c1 : term) (brs0 brs1 : list (nat * term)),
pred1 Γ Γ' p0 p1 ->
P Γ Γ' p0 p1 ->
pred1 Γ Γ' c0 c1 ->
P Γ Γ' c0 c1 -> All2_prop_eq Γ Γ' snd fst P' brs0 brs1 ->
P Γ Γ' (tCase ind p0 c0 brs0) (tCase ind p1 c1 brs1)) ->
(forall (Γ Γ' : context) (p : projection) (c c' : term), pred1 Γ Γ' c c' -> P Γ Γ' c c' -> P Γ Γ' (tProj p c) (tProj p c')) ->
(forall (Γ Γ' : context) (mfix0 : mfixpoint term) (mfix1 : list (def term)) (idx : nat),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1)
dtype dbody (fun x => (dname x, rarg x)) P' mfix0 mfix1 ->
P Γ Γ' (tFix mfix0 idx) (tFix mfix1 idx)) ->
(forall (Γ Γ' : context) (mfix0 : mfixpoint term) (mfix1 : list (def term)) (idx : nat),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2_local_env (on_decl (on_decl_over pred1 Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_local_env (on_decl (on_decl_over P Γ Γ')) (fix_context mfix0) (fix_context mfix1) ->
All2_prop2_eq Γ Γ' (Γ ,,, fix_context mfix0) (Γ' ,,, fix_context mfix1) dtype dbody (fun x => (dname x, rarg x)) P' mfix0 mfix1 ->
P Γ Γ' (tCoFix mfix0 idx) (tCoFix mfix1 idx)) ->
(forall (Γ Γ' : context) (na : name) (M0 M1 N0 N1 : term),
pred1 Γ Γ' M0 M1 ->
P Γ Γ' M0 M1 -> pred1 (Γ,, vass na M0) (Γ' ,, vass na M1) N0 N1 ->
P (Γ,, vass na M0) (Γ' ,, vass na M1) N0 N1 -> P Γ Γ' (tProd na M0 N0) (tProd na M1 N1)) ->
(forall (Γ Γ' : context) (ev : nat) (l l' : list term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
All2 (P' Γ Γ') l l' -> P Γ Γ' (tEvar ev l) (tEvar ev l')) ->
(forall (Γ Γ' : context) (t : term),
All2_local_env (on_decl pred1) Γ Γ' ->
Pctx Γ Γ' ->
pred_atom t -> P Γ Γ' t t) ->
forall (Γ Γ' : context) (t t0 : term), pred1 Γ Γ' t t0 -> P Γ Γ' t t0.
Proof.
intros P Pctx P' Hctx. intros. revert Γ Γ' t t0 X20.
fix aux 5. intros Γ Γ' t t'.
move aux at top.
destruct 1; match goal with
| |- P _ _ (tFix _ _) (tFix _ _) => idtac
| |- P _ _ (tCoFix _ _) (tCoFix _ _) => idtac
| |- P _ _ (mkApps (tFix _ _) _) _ => idtac
| |- P _ _ (tCase _ _ (mkApps (tCoFix _ _) _) _) _ => idtac
| |- P _ _ (tProj _ (mkApps (tCoFix _ _) _)) _ => idtac
| |- P _ _ (tRel _) _ => idtac
| |- P _ _ (tConst _ _) _ => idtac
| H : _ |- _ => eapply H; eauto
end.
- simpl. apply X1; auto. apply Hctx.
apply (All2_local_env_impl a). intros. eapply X20.
apply (All2_local_env_impl a). intros. eapply (aux _ _ _ _ X20).
- simpl. apply X2; auto.
apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
- apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
- eapply (All2_All2_prop (P:=pred1) (Q:=P') a0 ((extendP aux) Γ Γ')).
- eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) (g:=fst) a1 (extendP aux Γ Γ')).
- eapply X4; eauto.
apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
eapply (All2_local_env_impl a0). intros. red. red in X20. apply (aux _ _ _ _ X20).
eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)).
eapply (All2_All2_prop (P:=pred1) (Q:=P') a2 (extendP aux Γ Γ')).
- eapply X5; eauto.
apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X21).
eapply (All2_local_env_impl a0). intros. red. red in X21. apply (aux _ _ _ _ X21).
eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)).
eapply (All2_All2_prop (P:=pred1) (Q:=P') a2 (extendP aux Γ Γ')).
eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) a3 (extendP aux Γ Γ')).
- eapply X6; eauto.
apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
eapply (All2_local_env_impl a0). intros. red. red in X20. apply (aux _ _ _ _ X20).
eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)).
eapply (All2_All2_prop (P:=pred1) (Q:=P') a2 (extendP aux Γ Γ')).
- eapply X7; eauto.
apply Hctx, (All2_local_env_impl a). intros. exact a. intros. apply (aux _ _ _ _ X20).
- eapply X8; eauto.
apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
- apply Hctx, (All2_local_env_impl a). exact a. intros. apply (aux _ _ _ _ X20).
- eapply (All2_All2_prop (P:=pred1) (Q:=P) a0). intros. apply (aux _ _ _ _ X20).
- eapply (All2_All2_prop_eq (P:=pred1) (Q:=P') (f:=snd) a (extendP aux Γ Γ')).
- eapply X15.
eapply (All2_local_env_impl a). intros. apply X20.
eapply (Hctx _ _ a), (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20).
eapply (All2_local_env_impl a0). intros. red. exact X20.
eapply (All2_local_env_impl a0). intros. red. apply (aux _ _ _ _ X20).
eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)).
- eapply X16.
eapply (All2_local_env_impl a). intros. apply X20.
eapply (Hctx _ _ a), (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20).
eapply (All2_local_env_impl a0). intros. red. exact X20.
eapply (All2_local_env_impl a0). intros. red. apply (aux _ _ _ _ X20).
eapply (All2_All2_prop2_eq (Q:=P') (f:=dtype) (g:=dbody) a1 (extendP aux)).
- eapply (Hctx _ _ a), (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20).
- eapply (All2_All2_prop (P:=pred1) (Q:=P') a0 (extendP aux Γ Γ')).
- eapply (Hctx _ _ a), (All2_local_env_impl a). intros. apply (aux _ _ _ _ X20).
Defined.
Lemma pred1_refl_gen Γ Γ' t : pred1_ctx Γ Γ' -> pred1 Γ Γ' t t.
Proof.
revert Γ'.
unshelve einduction Γ, t using term_forall_ctx_list_ind;
intros;
try solve [(apply pred_atom; reflexivity) || constructor; auto];
try solve [try red in X; constructor; unfold All2_prop2_eq, All2_prop2, on_Trel in *; solve_all];
intros.
- constructor; eauto. eapply IHt0_2.
constructor; try red; eauto with pcuic.
- constructor; eauto. eapply IHt0_2.
constructor; try red; eauto with pcuic.
- constructor; eauto. eapply IHt0_3.
constructor; try red; eauto with pcuic.
- assert (All2_local_env (on_decl (fun Δ Δ' : context => pred1 (Γ0 ,,, Δ) (Γ' ,,, Δ')))
(fix_context m) (fix_context m)).
{ revert X. clear -X1. generalize (fix_context m).
intros c H1. induction H1; constructor; auto.
- red in t0. red. eapply t0. eapply All2_local_env_app_inv; auto.
- red in t1. red. split.
+ eapply t1. eapply All2_local_env_app_inv; auto.
+ eapply t1. eapply All2_local_env_app_inv; auto.
}
constructor; auto. red.
unfold All2_prop_eq, on_Trel in *.
eapply All_All2; eauto. simpl; intros.
split; eauto. eapply X3; auto.
split. eapply X3. eapply All2_local_env_app_inv; auto. auto.
- assert (All2_local_env (on_decl (fun Δ Δ' : context => pred1 (Γ0 ,,, Δ) (Γ' ,,, Δ')))
(fix_context m) (fix_context m)).
{ revert X. clear -X1. generalize (fix_context m).
intros c H1. induction H1; constructor; auto.
- red in t0. red. eapply t0. eapply All2_local_env_app_inv; auto.
- red in t1. red. split.
+ eapply t1. eapply All2_local_env_app_inv; auto.
+ eapply t1. eapply All2_local_env_app_inv; auto.
}
constructor; auto. red.
eapply All_All2; eauto. simpl; intros.
split; eauto. eapply X3; auto.
split. eapply X3. eapply All2_local_env_app_inv; auto. auto.
Qed.
Lemma pred1_ctx_refl Γ : pred1_ctx Γ Γ.
Proof.
induction Γ. constructor.
destruct a as [na [b|] ty]; constructor; try red; simpl; auto with pcuic.
split; now apply pred1_refl_gen. apply pred1_refl_gen, IHΓ.
Qed.
Hint Resolve pred1_ctx_refl : pcuic.
Lemma pred1_refl Γ t : pred1 Γ Γ t t.
Proof. apply pred1_refl_gen, pred1_ctx_refl. Qed.
Lemma pred1_pred1_ctx {Γ Δ t u} : pred1 Γ Δ t u -> pred1_ctx Γ Δ.
Proof.
intros H; revert Γ Δ t u H.
refine (pred1_ind_all_ctx _ (fun Γ Γ' => pred1_ctx Γ Γ') _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _); intros *.
all:try intros **; rename_all_hyps;