@@ -254,7 +254,7 @@ Module Lookup (T : Term) (E : EnvironmentSig T).
254254 apply QualitySet.union_spec; right.
255255 do 2 rewrite QualitySetFact.add_iff.
256256 rewrite QualitySetFact.singleton_iff; now repeat right.
257- Qed .
257+ Qed .
258258
259259 Lemma global_ext_qprop_InSet Σ :
260260 QualitySet.In Quality.qProp (global_ext_qualities Σ).
@@ -327,9 +327,18 @@ Module Lookup (T : Term) (E : EnvironmentSig T).
327327 Definition wf_qvar Σ (qv : QVar.t) : Prop :=
328328 QualitySet.In (Quality.qVar qv) (global_ext_qualities Σ).
329329
330+ Definition wf_quality Σ (s : Quality.t) : Prop :=
331+ Quality.on_quality (wf_qvar Σ) True s.
332+
330333 Definition wf_sort Σ (s : sort) : Prop :=
331334 Sort.on_sort (wf_qvar Σ) (wf_universe Σ) True and s.
332335
336+ Definition wf_relevance Σ (r : relevance) : Prop :=
337+ on_relevance (wf_qvar Σ) True r.
338+
339+ Definition wf_aname Σ (na : aname) : Prop :=
340+ wf_relevance Σ na.(binder_relevance).
341+
333342 Definition wf_universe_dec Σ u : {wf_universe Σ u} + {~wf_universe Σ u}.
334343 Proof .
335344 cbv [wf_universe LevelExprSet.In LevelExprSet.this t_set].
@@ -393,12 +402,16 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
393402 Definition lift_wf_term wf_term (j : judgment) := option_default wf_term (j_term j) (unit : Type) × wf_term (j_typ j).
394403 Notation lift_wf_term1 wf_term := (fun (Γ : context) => lift_wf_term (wf_term Γ)).
395404
396- Definition lift_wfu_term wf_term wf_univ (j : judgment) := option_default wf_term (j_term j) (unit : Type) × wf_term (j_typ j) × option_default wf_univ (j_univ j) (unit : Type).
405+ Definition lift_wfu_term wf_term wf_univ wf_rel (j : judgment) :=
406+ option_default wf_term (j_term j) (unit : Type ) × wf_term (j_typ j) ×
407+ option_default wf_rel (j_rel j) (unit : Type) × option_default wf_univ (j_univ j) (unit : Type).
397408
398409 Definition lift_wfb_term wfb_term (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j).
399410 Notation lift_wfb_term1 wfb_term := (fun (Γ : context) => lift_wfb_term (wfb_term Γ)).
400411
401- 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.
412+ Definition lift_wfbu_term wfb_term wfb_univ wfb_rel (j : judgment) :=
413+ option_default wfb_term (j_term j) true && wfb_term (j_typ j) &&
414+ option_default wfb_rel (j_rel j) true && option_default wfb_univ (j_univ j) true.
402415
403416 Definition lift_sorting checking sorting : judgment -> Type :=
404417 fun j => option_default (fun tm => checking tm (j_typ j)) (j_term j) (unit : Type ) ×
@@ -456,18 +469,20 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
456469 destruct j_term; cbn in *; auto.
457470 Defined .
458471
459- Lemma lift_wfbu_term_f_impl (P Q : term -> bool) tm t u r :
460- forall f fu,
461- lift_wfbu_term P (P ∘ tSort) (Judge tm t u r) ->
472+ Lemma lift_wfbu_term_f_impl (P Q : term -> bool) (Pr Qr : relevance -> bool) tm t u r :
473+ forall f fu fr ,
474+ lift_wfbu_term P (P ∘ tSort) Pr (Judge tm t u r) ->
462475 (forall u, f (tSort u) = tSort (fu u)) ->
463476 (forall t, P t -> Q (f t)) ->
464- lift_wfbu_term Q (Q ∘ tSort) (Judge (option_map f tm) (f t) (option_map fu u) r).
477+ (forall r, Pr r -> Qr (fr r)) ->
478+ lift_wfbu_term Q (Q ∘ tSort) Qr (Judge (option_map f tm) (f t) (option_map fu u) (option_map fr r)).
465479 Proof .
466480 unfold lift_wfbu_term; cbn.
467481 intros. rtoProp.
468482 repeat split; auto.
469- 1: destruct tm; cbn in *; auto.
470- destruct u; rewrite //= -H0 //. auto.
483+ + destruct tm; cbn in *; auto.
484+ + destruct r; cbn in *; auto.
485+ + destruct u; rewrite //= -H0 //. auto.
471486 Defined .
472487
473488 Lemma lift_wf_wfb_term (p : _ -> bool) j :
@@ -479,14 +494,15 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
479494 destruct (reflect_option_default HP (j_term j)) => /= //; now constructor.
480495 Qed .
481496
482- Lemma lift_wfu_wfbu_term (p : _ -> bool) (pu : _ -> bool) j :
483- reflectT (lift_wfu_term p pu j) (lift_wfbu_term p pu j).
497+ Lemma lift_wfu_wfbu_term (p : _ -> bool) (pu : _ -> bool) (pr : _ -> bool) j :
498+ reflectT (lift_wfu_term p pu pr j) (lift_wfbu_term p pu pr j).
484499 Proof .
485- set (HP := @reflectT_pred _ p); set (HPu := @reflectT_pred _ pu).
500+ set (HP := @reflectT_pred _ p); set (HPu := @reflectT_pred _ pu); set (HPr := @reflectT_pred _ pr) .
486501 rewrite /lift_wfu_term /lift_wfbu_term.
487502 destruct (HP (j_typ j)) => //;
488503 destruct (reflect_option_default HP (j_term j)) => /= //;
489- destruct (reflect_option_default HPu (j_univ j)) => /= //; now constructor.
504+ destruct (reflect_option_default HPu (j_univ j)) => /= //;
505+ destruct (reflect_option_default HPr (j_rel j)) => /= //; now constructor.
490506 Qed .
491507
492508 Lemma unlift_TermTyp {Pc Ps tm ty u r} :
@@ -558,14 +574,14 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
558574 Qed .
559575
560576 Lemma lift_sorting_fu_it_impl {Pc Qc Ps Qs} {tm : option term} {t : term} {u r} :
561- forall f fu, forall tu: lift_sorting Pc Ps (Judge tm t u r),
577+ forall f fu fr , forall tu: lift_sorting Pc Ps (Judge tm t u r),
562578 let s := tu.2.π1 in
563- option_default (fun rel => isSortRel s rel -> isSortRel (fu s) rel) r True ->
579+ option_default (fun rel => isSortRel s rel -> isSortRel (fu s) (fr rel) ) r True ->
564580 option_default (fun tm => Pc tm t -> Qc (f tm) (f t)) tm unit ->
565581 (Ps t s -> Qs (f t) (fu s)) ->
566- lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u) r ).
582+ lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u) (option_map fr r) ).
567583 Proof .
568- intros ?? (? & ? & Hs & e & er) s Hr HPQc HPQs.
584+ intros ??? (? & ? & Hs & e & er) s Hr HPQc HPQs.
569585 split.
570586 - destruct tm => //=. now apply HPQc.
571587 - eexists. split; [now apply HPQs|].
@@ -584,10 +600,10 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
584600 lift_sorting Qc Qs (judgment_map f j).
585601 Proof .
586602 intro f.
587- replace (judgment_map f j) with (Judge (option_map f (j_term j)) (f (j_typ j)) (option_map id (j_univ j)) (j_rel j)).
588- 2: unfold judgment_map; destruct j_univ => //.
603+ replace (judgment_map f j) with (Judge (option_map f (j_term j)) (f (j_typ j)) (option_map id (j_univ j)) (option_map id ( j_rel j) )).
604+ 2: now unfold judgment_map; destruct j_univ, j_rel => //.
589605 intro tu.
590- apply lift_sorting_fu_it_impl with (fu := id) (tu := tu).
606+ apply lift_sorting_fu_it_impl with (fu := id)(fr := id) (tu := tu).
591607 destruct tu as (? & s & ?); cbn; clear.
592608 destruct j_rel => //.
593609 Qed .
@@ -605,28 +621,28 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
605621 Qed .
606622
607623 Lemma lift_sorting_fu_impl {Pc Qc Ps Qs tm t u r} :
608- forall f fu,
624+ forall f fu fr ,
609625 lift_sorting Pc Ps (Judge tm t u r) ->
610- (forall r s, isSortRelOpt s r -> isSortRelOpt (fu s) r ) ->
626+ (forall r s, isSortRel s r -> isSortRel (fu s) (fr r) ) ->
611627 (forall t T, Pc t T -> Qc (f t) (f T)) ->
612628 (forall t u, Ps t u -> Qs (f t) (fu u)) ->
613- lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u) r ).
629+ lift_sorting Qc Qs (Judge (option_map f tm) (f t) (option_map fu u) (option_map fr r) ).
614630 Proof .
615- intros ?? tu Hr ??.
631+ intros ??? tu Hr ??.
616632 apply lift_sorting_fu_it_impl with (tu := tu); auto.
617- 1: destruct r => //=; apply Hr with (r := Some _) .
633+ 1: by destruct r => //=; apply Hr.
618634 destruct tm => //=. auto.
619635 Qed .
620636
621637 Lemma lift_typing_fu_impl {P Q tm t u r} :
622- forall f fu,
638+ forall f fu fr ,
623639 lift_typing0 P (Judge tm t u r) ->
624640 (forall t T, P t T -> Q (f t) (f T)) ->
625641 (forall u, f (tSort u) = tSort (fu u)) ->
626- (forall r s, isSortRelOpt s r -> isSortRelOpt (fu s) r ) ->
627- lift_typing0 Q (Judge (option_map f tm) (f t) (option_map fu u) r ).
642+ (forall r s, isSortRel s r -> isSortRel (fu s) (fr r) ) ->
643+ lift_typing0 Q (Judge (option_map f tm) (f t) (option_map fu u) (option_map fr r) ).
628644 Proof .
629- intros ?? HT HPQ Hf Hr.
645+ intros ??? HT HPQ Hf Hr.
630646 apply lift_sorting_fu_impl with (1 := HT); tas.
631647 intros; rewrite -Hf; now apply HPQ.
632648 Qed .
@@ -664,11 +680,11 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
664680 apply lift_typing_f_impl with (1 := HT) => //.
665681 Qed .
666682
667- Lemma lift_typing_mapu {P} f fu {tm ty u r} :
683+ Lemma lift_typing_mapu {P} f fu fr {tm ty u r} :
668684 lift_typing0 (fun t T => P (f t) (f T)) (Judge tm ty u r) ->
669685 (forall u, f (tSort u) = tSort (fu u)) ->
670- (forall r s, isSortRelOpt s r -> isSortRelOpt (fu s) r ) ->
671- lift_typing0 P (Judge (option_map f tm) (f ty) (option_map fu u) r ).
686+ (forall r s, isSortRel s r -> isSortRel (fu s) (fr r) ) ->
687+ lift_typing0 P (Judge (option_map f tm) (f ty) (option_map fu u) (option_map fr r) ).
672688 Proof .
673689 intros HT.
674690 eapply lift_typing_fu_impl with (1 := HT) => //.
@@ -706,16 +722,18 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
706722 eauto.
707723 Qed .
708724
709- Lemma lift_typing_subjtyp {P Q Q' j} :
725+ Lemma lift_typing_subjtyp {P Q Q' Qr j} :
710726 lift_typing0 P j ->
711727 (forall t T, P t T -> Q t × Q T) ->
712728 (forall u, Q (tSort u) -> Q' u) ->
713- lift_wfu_term Q Q' j.
729+ (forall T s r, P T (tSort s) -> isSortRel s r -> Qr r) ->
730+ lift_wfu_term Q Q' Qr j.
714731 Proof .
715- intros (Htm & s & Hty & e & er) HPQ HQQ'.
732+ intros (Htm & s & Hty & e & er) HPQ HQQ' HQQr .
716733 repeat split.
717734 - destruct j_term => //=. eapply fst, HPQ, Htm.
718735 - eapply fst, HPQ, Hty.
736+ - destruct j_rel => //=. eapply HQQr; tea.
719737 - destruct j_univ => //=. rewrite e. eapply HQQ', snd, HPQ, Hty.
720738 Qed .
721739
0 commit comments