@@ -318,8 +318,8 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
318
318
319
319
(** Well-formedness of local environments embeds a sorting for each variable *)
320
320
321
- Definition on_local_decl (P : context -> judgment -> Type ) Γ d :=
322
- P Γ (j_decl d).
321
+ Notation on_local_decl P Γ d :=
322
+ ( P Γ (j_decl d) ).
323
323
324
324
Definition on_def_type (P : context -> judgment -> Type ) Γ d :=
325
325
P Γ (Typ d.(dtype)).
@@ -332,9 +332,13 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
332
332
Definition lift_wf_term wf_term (j : judgment) := option_default wf_term (j_term j) (unit : Type) × wf_term (j_typ j).
333
333
Notation lift_wf_term1 wf_term := (fun (Γ : context) => lift_wf_term (wf_term Γ)).
334
334
335
+ Definition lift_wfu_term wf_term wf_univ (j : judgment) := option_default wf_term (j_term j) unit × wf_term (j_typ j) × option_default wf_univ (j_univ j) unit.
336
+
335
337
Definition lift_wfb_term wfb_term (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j).
336
338
Notation lift_wfb_term1 wfb_term := (fun (Γ : context) => lift_wfb_term (wfb_term Γ)).
337
339
340
+ Definition lift_wfbu_term wfb_term wfb_univ (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j) && option_default wfb_univ (j_univ j) true.
341
+
338
342
Definition lift_sorting checking sorting : judgment -> Type :=
339
343
fun j => option_default (fun tm => checking tm (j_typ j)) (j_term j) (unit : Type ) ×
340
344
∑ s, sorting (j_typ j) s × option_default (fun u => (u = s : Type)) (j_univ j) unit.
@@ -389,25 +393,52 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
389
393
destruct j_term; cbn in *; auto.
390
394
Defined .
391
395
396
+ Lemma lift_wfbu_term_f_impl (P Q : term -> bool) tm t u :
397
+ forall f fu,
398
+ lift_wfbu_term P (P ∘ tSort) (Judge tm t u) ->
399
+ (forall u, f (tSort u) = tSort (fu u)) ->
400
+ (forall t, P t -> Q (f t)) ->
401
+ lift_wfbu_term Q (Q ∘ tSort) (Judge (option_map f tm) (f t) (option_map fu u)).
402
+ Proof .
403
+ unfold lift_wfbu_term; cbn.
404
+ intros. rtoProp.
405
+ repeat split; auto.
406
+ 1: destruct tm; cbn in *; auto.
407
+ destruct u; rewrite //= -H0 //. auto.
408
+ Defined .
409
+
392
410
Lemma unlift_TermTyp {Pc Ps tm ty u} :
393
411
lift_sorting Pc Ps (Judge (Some tm) ty u) ->
394
412
Pc tm ty.
395
413
Proof .
396
414
apply fst.
397
415
Defined .
398
416
399
- Definition lift_sorting_extract {c s tm ty} (w : lift_sorting c s (TermoptTyp tm ty)) :
417
+ Definition unlift_TypUniv {Pc Ps tm ty u} :
418
+ lift_sorting Pc Ps (Judge tm ty (Some u)) ->
419
+ Ps ty u
420
+ := fun H => eq_rect_r _ H.2.π2.1 H.2.π2.2.
421
+
422
+ Definition lift_sorting_extract {c s tm ty u} (w : lift_sorting c s (Judge tm ty u)) :
400
423
lift_sorting c s (Judge tm ty (Some w.2.π1)) :=
401
424
(w.1, existT _ w.2.π1 (w.2.π2.1, eq_refl)).
402
425
403
426
Lemma lift_sorting_forget_univ {Pc Ps tm ty u} :
404
- lift_sorting Pc Ps (Judge tm ty (Some u) ) ->
427
+ lift_sorting Pc Ps (Judge tm ty u ) ->
405
428
lift_sorting Pc Ps (TermoptTyp tm ty).
406
429
Proof .
407
430
intros (? & ? & ? & ?).
408
431
repeat (eexists; tea).
409
432
Qed .
410
433
434
+ Lemma lift_sorting_forget_body {Pc Ps tm ty u} :
435
+ lift_sorting Pc Ps (Judge tm ty u) ->
436
+ lift_sorting Pc Ps (Judge None ty u).
437
+ Proof .
438
+ intros (? & ? & ? & ?).
439
+ repeat (eexists; tea).
440
+ Qed .
441
+
411
442
Lemma lift_sorting_ex_it_impl_gen {Pc Qc Ps Qs} {tm tm' : option term} {t t' : term} :
412
443
forall tu: lift_sorting Pc Ps (TermoptTyp tm t),
413
444
let s := tu.2.π1 in
@@ -533,6 +564,15 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
533
564
apply lift_typing_f_impl with (1 := HT) => //.
534
565
Qed .
535
566
567
+ Lemma lift_typing_mapu {P} f fu {tm ty u} :
568
+ lift_typing0 (fun t T => P (f t) (f T)) (Judge tm ty u) ->
569
+ (forall u, f (tSort u) = tSort (fu u)) ->
570
+ lift_typing0 P (Judge (option_map f tm) (f ty) (option_map fu u)).
571
+ Proof .
572
+ intros HT.
573
+ eapply lift_typing_fu_impl with (1 := HT) => //.
574
+ Qed .
575
+
536
576
Lemma lift_sorting_impl {Pc Qc Ps Qs j} :
537
577
lift_sorting Pc Ps j ->
538
578
(forall t T, Pc t T -> Qc t T) ->
@@ -563,12 +603,12 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
563
603
564
604
| localenv_cons_abs Γ na t :
565
605
All_local_env Γ ->
566
- typing Γ (Typ t) ->
606
+ typing Γ (j_vass na t) ->
567
607
All_local_env (Γ ,, vass na t)
568
608
569
609
| localenv_cons_def Γ na b t :
570
610
All_local_env Γ ->
571
- typing Γ (TermTyp b t) ->
611
+ typing Γ (j_vdef na b t) ->
572
612
All_local_env (Γ ,, vdef na b t).
573
613
574
614
Derive Signature NoConfusion for All_local_env.
@@ -621,10 +661,12 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
621
661
622
662
Lemma All_local_env_impl_gen (P Q : context -> judgment -> Type ) l :
623
663
All_local_env P l ->
624
- (forall Γ bo ty , P Γ (TermoptTyp bo ty ) -> Q Γ (TermoptTyp bo ty )) ->
664
+ (forall Γ decl , P Γ (j_decl decl ) -> Q Γ (j_decl decl )) ->
625
665
All_local_env Q l.
626
666
Proof .
627
- induction 1; intros; simpl; econstructor; eauto.
667
+ intros H X.
668
+ induction H using All_local_env_ind1. 1: constructor.
669
+ apply All_local_env_snoc; auto.
628
670
Qed .
629
671
630
672
Lemma All_local_env_impl (P Q : context -> judgment -> Type ) l :
@@ -671,6 +713,14 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
671
713
- now eapply IHΓ.
672
714
Defined .
673
715
716
+ Lemma All_local_env_cst {P Γ} : All_local_env (fun _ => P) Γ <~> All (fun d => P (j_decl d)) Γ.
717
+ Proof .
718
+ split.
719
+ - induction 1 using All_local_env_ind1; constructor => //.
720
+ - induction 1. 1: constructor.
721
+ apply All_local_env_snoc => //.
722
+ Defined .
723
+
674
724
Section All_local_env_rel.
675
725
676
726
Definition All_local_rel P Γ Γ'
@@ -685,13 +735,13 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
685
735
:= All_local_env_snoc.
686
736
687
737
Definition All_local_rel_abs {P Γ Γ' A na} :
688
- All_local_rel P Γ Γ' -> P (Γ ,,, Γ') (Typ A)
738
+ All_local_rel P Γ Γ' -> P (Γ ,,, Γ') (j_vass na A)
689
739
-> All_local_rel P Γ (Γ',, vass na A)
690
740
:= localenv_cons.
691
741
692
742
Definition All_local_rel_def {P Γ Γ' t A na} :
693
743
All_local_rel P Γ Γ' ->
694
- P (Γ ,,, Γ') (TermTyp t A) ->
744
+ P (Γ ,,, Γ') (j_vdef na t A) ->
695
745
All_local_rel P Γ (Γ',, vdef na t A)
696
746
:= localenv_cons.
697
747
@@ -803,15 +853,15 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
803
853
| localenv_over_cons_abs Γ na t
804
854
(all : All_local_env (lift_sorting1 checking sorting) Γ) :
805
855
All_local_env_over_sorting Γ all ->
806
- forall (tu : lift_sorting1 checking sorting Γ (Typ t))
856
+ forall (tu : lift_sorting1 checking sorting Γ (j_vass na t))
807
857
(Hs: sproperty Γ all _ _ tu.2.π2.1),
808
858
All_local_env_over_sorting (Γ ,, vass na t)
809
859
(localenv_cons_abs all tu)
810
860
811
861
| localenv_over_cons_def Γ na b t
812
862
(all : All_local_env (lift_sorting1 checking sorting) Γ) :
813
863
All_local_env_over_sorting Γ all ->
814
- forall (tu : lift_sorting1 checking sorting Γ (TermTyp b t))
864
+ forall (tu : lift_sorting1 checking sorting Γ (j_vdef na b t))
815
865
(Hc: cproperty Γ all _ _ tu.1)
816
866
(Hs: sproperty Γ all _ _ tu.2.π2.1),
817
867
All_local_env_over_sorting (Γ ,, vdef na b t)
@@ -919,24 +969,24 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
919
969
| None => fun w => 0
920
970
end w.
921
971
922
- Section lift_sorting_size .
972
+ Section lift_sorting_size_gen .
923
973
Context {checking : term -> term -> Type}.
924
974
Context {sorting : term -> Universe.t -> Type }.
925
975
Context (csize : forall (t T : term), checking t T -> size).
926
976
Context (ssize : forall (t : term) (u : Universe.t), sorting t u -> size).
927
977
928
- Definition lift_sorting_size j (w : lift_sorting checking sorting j) : size :=
929
- option_default_size (fun tm => csize tm _) (j_term j) w.1 + ssize _ _ w.2.π2.1.
978
+ Definition lift_sorting_size_gen base j (w : lift_sorting checking sorting j) : size :=
979
+ base + option_default_size (fun tm => csize tm _) (j_term j) w.1 + ssize _ _ w.2.π2.1.
930
980
931
981
932
- Lemma lift_sorting_size_impl {Qc Qs j} :
982
+ Lemma lift_sorting_size_gen_impl {Qc Qs j} :
933
983
forall tu: lift_sorting checking sorting j,
934
- (forall t T, forall Hty: checking t T, csize _ _ Hty <= lift_sorting_size _ tu -> Qc t T) ->
935
- (forall t u, forall Hty: sorting t u, ssize _ _ Hty <= lift_sorting_size _ tu -> Qs t u) ->
984
+ (forall t T, forall Hty: checking t T, csize _ _ Hty <= lift_sorting_size_gen 0 _ tu -> Qc t T) ->
985
+ (forall t u, forall Hty: sorting t u, ssize _ _ Hty <= lift_sorting_size_gen 0 _ tu -> Qs t u) ->
936
986
lift_sorting Qc Qs j.
937
987
Proof .
938
988
intros (Htm & s & Hty & es) HPQc HPQs.
939
- unfold lift_sorting_size in *; cbn in *.
989
+ unfold lift_sorting_size_gen in *; cbn in *.
940
990
repeat (eexists; tea).
941
991
- destruct (j_term j) => //=.
942
992
eapply HPQc with (Hty := Htm); cbn.
@@ -945,29 +995,45 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
945
995
lia.
946
996
Qed .
947
997
948
- End lift_sorting_size .
998
+ End lift_sorting_size_gen .
949
999
950
- Definition on_def_type_sorting_size {c s} (ssize : forall Γ t u, s Γ t u -> size)
1000
+ Definition on_def_type_size_gen {c s} (ssize : forall Γ t u, s Γ t u -> size) base
951
1001
Γ d (w : on_def_type (lift_sorting1 c s) Γ d) : size :=
952
- ssize _ _ _ w.2.π2.1.
953
- Definition on_def_body_sorting_size {c s} (csize : forall Γ t u, c Γ t u -> size) (ssize : forall Γ t u, s Γ t u -> size)
1002
+ base + ssize _ _ _ w.2.π2.1.
1003
+ Definition on_def_body_size_gen {c s} (csize : forall Γ t u, c Γ t u -> size) (ssize : forall Γ t u, s Γ t u -> size) base
954
1004
types Γ d (w : on_def_body (lift_sorting1 c s) types Γ d) : size :=
955
- csize _ _ _ w.1 + ssize _ _ _ w.2.π2.1.
1005
+ base + csize _ _ _ w.1 + ssize _ _ _ w.2.π2.1.
956
1006
1007
+ Notation lift_sorting_size csize ssize := (lift_sorting_size_gen csize ssize 1).
957
1008
Notation typing_sort_size typing_size := (fun t s (tu: typing_sort _ t s) => typing_size t (tSort s) tu).
958
- Notation lift_typing_size typing_size := (lift_sorting_size typing_size (typing_sort_size typing_size)).
1009
+ Notation lift_typing_size typing_size := (lift_sorting_size_gen typing_size (typing_sort_size typing_size) 0 ).
959
1010
Notation typing_sort_size1 typing_size := (fun Γ t s (tu: typing_sort1 _ Γ t s) => typing_size Γ t (tSort s) tu).
960
- Notation on_def_type_size typing_size := (on_def_type_sorting_size (typing_sort_size1 typing_size)).
961
- Notation on_def_body_size typing_size := (on_def_body_sorting_size typing_size (typing_sort_size1 typing_size)).
1011
+ Notation on_def_type_sorting_size ssize := (on_def_type_size_gen ssize 1).
1012
+ Notation on_def_type_size typing_size := (on_def_type_size_gen (typing_sort_size1 typing_size) 0).
1013
+ Notation on_def_body_sorting_size csize ssize := (on_def_body_size_gen csize ssize 1).
1014
+ Notation on_def_body_size typing_size := (on_def_body_size_gen typing_size (typing_sort_size1 typing_size) 0).
962
1015
(* Will probably not pass the guard checker if in a list, must be unrolled like in on_def_* *)
963
1016
964
- Lemma lift_typing_size_impl {P Q Psize j} :
1017
+ Lemma lift_sorting_size_impl {checking sorting Qc Qs j} csize ssize :
1018
+ forall tu: lift_sorting checking sorting j,
1019
+ (forall t T, forall Hty: checking t T, csize _ _ Hty < lift_sorting_size csize ssize _ tu -> Qc t T) ->
1020
+ (forall t u, forall Hty: sorting t u, ssize _ _ Hty < lift_sorting_size csize ssize _ tu -> Qs t u) ->
1021
+ lift_sorting Qc Qs j.
1022
+ Proof .
1023
+ intros tu Xc Xs.
1024
+ eapply lift_sorting_size_gen_impl with (tu := tu).
1025
+ all: intros.
1026
+ 1: eapply Xc. 2: eapply Xs.
1027
+ all: apply le_n_S, H.
1028
+ Qed .
1029
+
1030
+ Lemma lift_typing_size_impl {P Q j} Psize :
965
1031
forall tu: lift_typing0 P j,
966
1032
(forall t T, forall Hty: P t T, Psize _ _ Hty <= lift_typing_size Psize _ tu -> Q t T) ->
967
1033
lift_typing0 Q j.
968
1034
Proof .
969
1035
intros.
970
- eapply lift_sorting_size_impl with (csize := Psize).
1036
+ eapply lift_sorting_size_gen_impl with (csize := Psize).
971
1037
all: intros t T; apply X.
972
1038
Qed .
973
1039
@@ -1109,17 +1175,19 @@ Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvT
1109
1175
Fixpoint type_local_ctx Σ (Γ Δ : context) (u : Universe.t) : Type :=
1110
1176
match Δ with
1111
1177
| [] => wf_universe Σ u
1112
- | {| decl_body := None; decl_type := t |} :: Δ => type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (TypUniv t u)
1113
- | {| decl_body := Some b; decl_type := t |} :: Δ => type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (TermTyp b t)
1178
+ | {| decl_name := na; decl_body := None; decl_type := t |} :: Δ =>
1179
+ type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (TypUniv t u (* na.(binder_relevance) *) )
1180
+ | {| decl_body := Some _; |} as d :: Δ =>
1181
+ type_local_ctx Σ Γ Δ u × P Σ (Γ ,,, Δ) (j_decl d)
1114
1182
end .
1115
1183
1116
1184
Fixpoint sorts_local_ctx Σ (Γ Δ : context) (us : list Universe.t) : Type :=
1117
1185
match Δ, us with
1118
1186
| [], [] => unit
1119
- | {| decl_body := None; decl_type := t |} :: Δ, u :: us =>
1120
- sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (TypUniv t u)
1121
- | {| decl_body := Some b; decl_type := t |} :: Δ, us =>
1122
- sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (TermTyp b t )
1187
+ | {| decl_name := na; decl_body := None; decl_type := t |} :: Δ, u :: us =>
1188
+ sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (TypUniv t u (* na.(binder_relevance) *) )
1189
+ | {| decl_body := Some _ |} as d :: Δ, us =>
1190
+ sorts_local_ctx Σ Γ Δ us × P Σ (Γ ,,, Δ) (j_decl d )
1123
1191
| _, _ => False
1124
1192
end .
1125
1193
@@ -1640,6 +1708,23 @@ Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvT
1640
1708
Definition on_global_env_ext (Σ : global_env_ext) :=
1641
1709
on_global_env Σ.1 × on_udecl Σ.(universes) Σ.2.
1642
1710
1711
+ Lemma on_global_env_ext_empty_ext g :
1712
+ on_global_env g -> on_global_env_ext (empty_ext g).
1713
+ Proof .
1714
+ intro H; split => //.
1715
+ unfold empty_ext, snd. repeat split.
1716
+ - unfold levels_of_udecl. intros x e. lsets.
1717
+ - unfold constraints_of_udecl. intros x e. csets.
1718
+ - unfold satisfiable_udecl, univs_ext_constraints, constraints_of_udecl, fst_ctx, fst => //.
1719
+ destruct H as ((cstrs & _ & consistent) & decls).
1720
+ destruct consistent; eexists.
1721
+ intros v e. specialize (H v e); tea.
1722
+ - unfold valid_on_mono_udecl, constraints_of_udecl, consistent_extension_on.
1723
+ intros v sat; exists v; split.
1724
+ + intros x e. csets.
1725
+ + intros x e => //.
1726
+ Qed .
1727
+
1643
1728
End GlobalMaps.
1644
1729
1645
1730
Arguments cstr_args_length {_ Pcmp P Σ mdecl i idecl ind_indices cdecl cunivs}.
0 commit comments