Built with Alectryon, running Coq+SerAPI v8.17.0+0.17.1. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+πŸ–±οΈ to focus. On Mac, use ⌘ instead of Ctrl.

Sub-context structure

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 := βˆ… |}.
  
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

allS βˆ…
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 T
Ξ“, Ξ”: ctxS

allS (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 Ξ“ βˆ‹ x

P x
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ“, Ξ”: ctxS
x: T
j: sub_elt Ξ” βˆ‹ x
P x
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ“, Ξ”: ctxS
x: T
j: sub_elt Ξ” βˆ‹ x

P x
now apply Ξ”.(sub_prf). Qed.

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 T

context_laws T ctxS
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

context_laws T ctxS
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

forall (t : T) (i : varS nilS t), c_emp_view t i
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
forall (Ξ“ Ξ” : ctxS) (t : T) (i : varS (catS Ξ“ Ξ”) t), c_cat_view Ξ“ Ξ” t i
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
forall (Ξ“ Ξ” : 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 T
forall (Ξ“ Ξ” : 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 T
forall (Ξ“ Ξ” : ctxS) (t : T) (i : varS Ξ“ t) (j : varS Ξ” t), Β¬ (r_cat_l i = r_cat_r j)
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

forall (t : T) (i : varS nilS t), c_emp_view t i
intros ? i; destruct (c_view_emp i).
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

forall (Ξ“ Ξ” : ctxS) (t : T) (i : varS (catS Ξ“ Ξ”) t), c_cat_view Ξ“ Ξ” t i
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ“, Ξ”: ctxS
t: T
i: sub_elt Ξ“ βˆ‹ t

c_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 Ξ” βˆ‹ t
c_cat_view Ξ“ Ξ” t (r_cat_r j)
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T
Ξ“, Ξ”: ctxS
t: T
j: sub_elt Ξ” βˆ‹ t

c_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

forall (Ξ“ Ξ” : ctxS) (t : T), injective (fun i : varS Ξ“ t => r_cat_l i)
intros ????? H; exact (r_cat_l_inj _ _ H).
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

forall (Ξ“ Ξ” : ctxS) (t : T), injective (fun i : varS Ξ” t => r_cat_r i)
intros ????? H; exact (r_cat_r_inj _ _ H).
T, C: Type
CC: context T C
CL: context_laws T C
P: psh T

forall (Ξ“ Ξ” : ctxS) (t : T) (i : varS Ξ“ t) (j : varS Ξ” t), Β¬ (r_cat_l i = r_cat_r j)
intros ????? H; exact (r_cat_disj _ _ H). Qed.

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 P

allS 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) x0

P x0
T: 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 x0

P x0
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)

P x0
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
P x0
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)

P x0
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 x

P x0
rewrite H; now apply x.(sub_prf).
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

P x0
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
rewrite H in i; now apply Ξ“.(sub_prf). Qed. End with_param. #[global] Notation "Ξ“ β–Άβ‚› x" := (conS Ξ“ x) : ctx_scope.