As motivated in Ctx/DirectSum.v, we sometimes have exotic calculi which need specific kinds of contexts. Another such case is when there is a particular subset of types, represented by a predicate, and we wish to talk about contexts containing only these kind of types. Once again, we could do this using concrete lists, by taking the set of types to be elements of the predicate P : T β SProp: ctx (sigS P). The problem is once again that DeBruijn indices on this structure is not the right notion of variables. The set of contexts of some subset of the types is a subset of the set of contexts over that type! In other words, we should rather take sigS (ctx T) (allS P). As such the notion of variable should be the same.
We assume given a notion of context and a strict predicate on types.
Section with_param. Context {T C} {CC : context T C} {CL : context_laws T C} {P : T -> SProp}.
We define the strict predicate on context stating that all elements verify P.
Definition allS (Ξ : C) : SProp := forall x, Ξ β x -> P x. Definition ctxS : Type := sigS allS. Definition coe_ctxS : ctxS -> C := sub_elt.
A variable in the refined context is just a variable in the underlying context.
Definition varS (Ξ : ctxS) (x : T) := Ξ.(sub_elt) β x.
Nil and concatenation respect allS.
Program Definition nilS : ctxS := {| sub_elt := β |}.intros ? i; destruct (c_view_emp i). Qed. Program Definition catS (Ξ Ξ : ctxS) : ctxS := {| sub_elt := Ξ.(sub_elt) +βΆ Ξ.(sub_elt) |}.T, C: Type
CC: context T C
CL: context_laws T C
P: psh TallS βT, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxSallS (sub_elt Ξ +βΆ sub_elt Ξ)T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
x: T
i: sub_elt Ξ β xP xT, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
x: T
j: sub_elt Ξ β xP xnow apply Ξ.(sub_prf). Qed.T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
x: T
j: sub_elt Ξ β xP x
We now construct the instance.
#[global] Instance subset_context : context T ctxS := {| c_emp := nilS ; c_cat := catS ; c_var := varS |}. #[global] Instance subset_context_cat_wkn : context_cat_wkn T ctxS := {| r_cat_l Ξ Ξ t i := @r_cat_l T C _ _ Ξ.(sub_elt) Ξ.(sub_elt) t i ; r_cat_r Ξ Ξ t i := @r_cat_r T C _ _ Ξ.(sub_elt) Ξ.(sub_elt) t i |} .T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tcontext_laws T ctxST, C: Type
CC: context T C
CL: context_laws T C
P: psh Tcontext_laws T ctxST, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (t : T) (i : varS nilS t), c_emp_view t iT, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T) (i : varS (catS Ξ Ξ) t), c_cat_view Ξ Ξ t iT, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T), injective (fun i : varS Ξ t => r_cat_l i)T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T), injective (fun i : varS Ξ t => r_cat_r i)T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T) (i : varS Ξ t) (j : varS Ξ t), Β¬ (r_cat_l i = r_cat_r j)intros ? i; destruct (c_view_emp i).T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (t : T) (i : varS nilS t), c_emp_view t iT, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T) (i : varS (catS Ξ Ξ) t), c_cat_view Ξ Ξ t iT, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
t: T
i: sub_elt Ξ β tc_cat_view Ξ Ξ t (r_cat_l i)T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
t: T
j: sub_elt Ξ β tc_cat_view Ξ Ξ t (r_cat_r j)refine (Vcat_r _).T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ, Ξ: ctxS
t: T
j: sub_elt Ξ β tc_cat_view Ξ Ξ t (r_cat_r j)intros ????? H; exact (r_cat_l_inj _ _ H).T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T), injective (fun i : varS Ξ t => r_cat_l i)intros ????? H; exact (r_cat_r_inj _ _ H).T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T), injective (fun i : varS Ξ t => r_cat_r i)intros ????? H; exact (r_cat_disj _ _ H). Qed.T, C: Type
CC: context T C
CL: context_laws T C
P: psh Tforall (Ξ Ξ : ctxS) (t : T) (i : varS Ξ t) (j : varS Ξ t), Β¬ (r_cat_l i = r_cat_r j)
A couple helpers for manipulating the new variables.
Definition s_prf {Ξ : ctxS} {x} (i : Ξ.(sub_elt) β x) : P x := Ξ.(sub_prf) x i . Definition s_elt_upg {Ξ : ctxS} {x} (i : Ξ.(sub_elt) β x) : sigS P := {| sub_prf := Ξ.(sub_prf) x i |}. Definition s_var_upg {Ξ : ctxS} {x : T} (i : Ξ.(sub_elt) β x) : Ξ β (s_elt_upg i).(sub_elt) := i. End with_param.
In the case of sub-contexts over concrete contexts we provide a wrapper for the "append" operation.
From OGS.Ctx Require Import Ctx Covering. Section with_param. Context {T} {P : T -> SProp}. Program Definition conS (Ξ : ctxS T (ctx T) P) (x : sigS P) : ctxS T (ctx T) P := {| sub_elt := Ξ.(sub_elt) βΆβ x.(sub_elt) |}.T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS PallS P (sub_elt Ξ βΆβ sub_elt x)T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
i: cvar (sub_elt Ξ βΆβ sub_elt x) x0P x0T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
c: ctx T
Heqc: NoConfusion c (sub_elt Ξ βΆβ sub_elt x)
i: cvar c x0P x0T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
Heqc: NoConfusion (Ξ0 βΆβ x0) (sub_elt Ξ βΆβ sub_elt x)P x0T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
y: T
Heqc: NoConfusion (Ξ0 βΆβ y) (sub_elt Ξ βΆβ sub_elt x)
i: var x0 Ξ0P x0T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
Heqc: NoConfusion (Ξ0 βΆβ x0) (sub_elt Ξ βΆβ sub_elt x)P x0rewrite H; now apply x.(sub_prf).T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
Heqc: NoConfusion (Ξ0 βΆβ x0) (sub_elt Ξ βΆβ sub_elt x)
H: x0 = sub_elt xP x0T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
y: T
Heqc: NoConfusion (Ξ0 βΆβ y) (sub_elt Ξ βΆβ sub_elt x)
i: var x0 Ξ0P x0rewrite H in i; now apply Ξ.(sub_prf). Qed. End with_param. #[global] Notation "Ξ βΆβ x" := (conS Ξ x) : ctx_scope.T: Type
P: psh T
Ξ: ctxS T (ctx T) P
x: sigS P
x0: T
Ξ0: ctx T
y: T
Heqc: NoConfusion (Ξ0 βΆβ y) (sub_elt Ξ βΆβ sub_elt x)
i: var x0 Ξ0
H: Ξ0 = sub_elt ΞP x0