| 1 |
(* Uselessly long but why not *) |
| 2 |
|
| 3 |
Local Set Universe Polymorphism. |
| 4 |
|
| 5 |
Module tele. |
| 6 |
(** Telescopes *) |
| 7 |
Inductive tele : Type := |
| 8 |
| TeleO : tele |
| 9 |
| TeleS {X} (binder : X -> tele) : tele. |
| 10 |
|
| 11 |
Arguments TeleS {_} _. |
| 12 |
|
| 13 |
(** The telescope version of Coq's function type *) |
| 14 |
Fixpoint tele_fun (TT : tele) (T : Type) : Type := |
| 15 |
match TT with |
| 16 |
| TeleO => T |
| 17 |
| TeleS b => forall x, tele_fun (b x) T |
| 18 |
end. |
| 19 |
|
| 20 |
Notation "TT -t> A" := |
| 21 |
(tele_fun TT A) (at level 99, A at level 200, right associativity). |
| 22 |
|
| 23 |
(** An eliminator for elements of [tele_fun]. |
| 24 |
We use a [fix] because, for some reason, that makes stuff print nicer |
| 25 |
in the proofs in iris:bi/lib/telescopes.v *) |
| 26 |
Definition tele_fold {X Y} {TT : tele} (step : forall {A : Type}, (A -> Y) -> Y) (base : X -> Y) |
| 27 |
: (TT -t> X) -> Y := |
| 28 |
(fix rec {TT} : (TT -t> X) -> Y := |
| 29 |
match TT as TT return (TT -t> X) -> Y with |
| 30 |
| TeleO => fun x : X => base x |
| 31 |
| TeleS b => fun f => step (fun x => rec (f x)) |
| 32 |
end) TT. |
| 33 |
Arguments tele_fold {_ _ !_} _ _ _ /. |
| 34 |
|
| 35 |
(** A sigma-like type for an "element" of a telescope, i.e. the data it |
| 36 |
takes to get a [T] from a [TT -t> T]. *) |
| 37 |
Inductive tele_arg : tele -> Type := |
| 38 |
| TargO : tele_arg TeleO |
| 39 |
(* the [x] is the only relevant data here *) |
| 40 |
| TargS {X} {binder} (x : X) : tele_arg (binder x) -> tele_arg (TeleS binder). |
| 41 |
|
| 42 |
Definition tele_app {TT : tele} {T} (f : TT -t> T) : tele_arg TT -> T := |
| 43 |
fun a => (fix rec {TT} (a : tele_arg TT) : (TT -t> T) -> T := |
| 44 |
match a in tele_arg TT return (TT -t> T) -> T with |
| 45 |
| TargO => fun t : T => t |
| 46 |
| TargS x a => fun f => rec a (f x) |
| 47 |
end) TT a f. |
| 48 |
Arguments tele_app {!_ _} _ !_ /. |
| 49 |
|
| 50 |
Coercion tele_arg : tele >-> Sortclass. |
| 51 |
Local Coercion tele_app : tele_fun >-> Funclass. |
| 52 |
|
| 53 |
(** Operate below [tele_fun]s with argument telescope [TT]. *) |
| 54 |
Fixpoint tele_bind {U} {TT : tele} : (TT -> U) -> TT -t> U := |
| 55 |
match TT as TT return (TT -> U) -> TT -t> U with |
| 56 |
| TeleO => fun F => F TargO |
| 57 |
| @TeleS X b => fun (F : TeleS b -> U) (x : X) => (* b x -t> U *) |
| 58 |
tele_bind (fun a => F (TargS x a)) |
| 59 |
end. |
| 60 |
Arguments tele_bind {_ !_} _ /. |
| 61 |
|
| 62 |
(** Notation-compatible telescope mapping *) |
| 63 |
(* This adds (tele_app ∘ tele_bind), which is an identity function, around every |
| 64 |
binder so that, after simplifying, this matches the way we typically write |
| 65 |
notations involving telescopes. *) |
| 66 |
Notation "t $ r" := (t r) |
| 67 |
(at level 65, right associativity, only parsing). |
| 68 |
Notation "'λ..' x .. y , e" := |
| 69 |
(tele_app $ tele_bind (fun x => .. (tele_app $ tele_bind (fun y => e)) .. )) |
| 70 |
(at level 200, x binder, y binder, right associativity, |
| 71 |
format "'[ ' 'λ..' x .. y ']' , e"). |
| 72 |
|
| 73 |
(** Telescopic quantifiers *) |
| 74 |
Definition texist {TT : tele} (Ψ : TT -> Prop) : Prop := |
| 75 |
tele_fold ex (fun x => x) (tele_bind Ψ). |
| 76 |
Arguments texist {!_} _ /. |
| 77 |
|
| 78 |
Notation "'∃..' x .. y , P" := (texist (fun x => .. (texist (fun y => P)) .. )) |
| 79 |
(at level 200, x binder, y binder, right associativity, |
| 80 |
format "∃.. x .. y , P"). |
| 81 |
End tele. |
| 82 |
Import tele. |
| 83 |
|
| 84 |
(* This is like Iris' accessors, but in Prop. Just to play with telescopes. *) |
| 85 |
Definition accessor {X : tele} (α β γ : X -> Prop) : Prop := |
| 86 |
∃.. x, α x /\ (β x -> γ x). |
| 87 |
|
| 88 |
(* Working with abstract telescopes. *) |
| 89 |
Section tests. |
| 90 |
Context {X : tele}. |
| 91 |
Implicit Types α β γ : X -> Prop. |
| 92 |
|
| 93 |
Lemma acc_mono_disj α β γ1 γ2 : |
| 94 |
accessor α β γ1 -> accessor α β (λ.. x, γ1 x \/ γ2 x). |
| 95 |
Show. |
| 96 |
Abort. |
| 97 |
End tests. |