| 1 |
Set Implicit Arguments. |
| 2 |
|
| 3 |
Set Printing Universes. |
| 4 |
|
| 5 |
Set Asymmetric Patterns. |
| 6 |
|
| 7 |
Inductive paths {A : Type} (a : A) : A -> Type := |
| 8 |
idpath : paths a a. |
| 9 |
|
| 10 |
Arguments idpath {A a} , [A] a. |
| 11 |
|
| 12 |
Arguments paths_ind [A] a P f y p : rename. |
| 13 |
Arguments paths_rec [A] a P f y p : rename. |
| 14 |
Arguments paths_rect [A] a P f y p : rename. |
| 15 |
|
| 16 |
Notation "x = y :> A" := (@paths A x y) : type_scope. |
| 17 |
Notation "x = y" := (x = y :>_) : type_scope. |
| 18 |
|
| 19 |
Definition transport {A : Type} (P : A -> Type) {x y : A} (p : x = y) (u : P x) : P y := |
| 20 |
match p with idpath => u end. |
| 21 |
|
| 22 |
Definition ap {A B:Type} (f:A -> B) {x y:A} (p:x = y) : f x = f y |
| 23 |
:= match p with idpath => idpath end. |
| 24 |
Arguments ap {A B} f {x y} p : simpl nomatch. |
| 25 |
|
| 26 |
Definition Sect {A B : Type} (s : A -> B) (r : B -> A) := |
| 27 |
forall x : A, r (s x) = x. |
| 28 |
|
| 29 |
(** A typeclass that includes the data making [f] into an adjoint equivalence. *) |
| 30 |
Class IsEquiv {A B : Type} (f : A -> B) := BuildIsEquiv { |
| 31 |
equiv_inv : B -> A ; |
| 32 |
eisretr : Sect equiv_inv f; |
| 33 |
eissect : Sect f equiv_inv; |
| 34 |
eisadj : forall x : A, eisretr (f x) = ap f (eissect x) |
| 35 |
}. |
| 36 |
|
| 37 |
Arguments eisretr {A B} f {_} _. |
| 38 |
Arguments eissect {A B} f {_} _. |
| 39 |
Arguments eisadj {A B} f {_} _. |
| 40 |
|
| 41 |
|
| 42 |
Inductive type_eq (A : Type) : Type -> Type := |
| 43 |
| type_eq_refl : type_eq A A |
| 44 |
| type_eq_impossible : False -> forall B : Type, type_eq A B. |
| 45 |
|
| 46 |
Definition type_eq_sym {A B} (p : type_eq A B) : type_eq B A |
| 47 |
:= match p in (type_eq _ B) return (type_eq B A) with |
| 48 |
| type_eq_refl => type_eq_refl _ |
| 49 |
| type_eq_impossible f B => type_eq_impossible _ f A |
| 50 |
end. |
| 51 |
|
| 52 |
Definition type_eq_sym_type_eq_sym {A B} (p : type_eq A B) : type_eq_sym (type_eq_sym p) = p |
| 53 |
:= match p as p return type_eq_sym (type_eq_sym p) = p with |
| 54 |
| type_eq_refl => idpath |
| 55 |
| type_eq_impossible f _ => idpath |
| 56 |
end. |
| 57 |
|
| 58 |
Module Type LiftT. |
| 59 |
Section local. |
| 60 |
Let type_cast_up_type : Type. |
| 61 |
Proof. |
| 62 |
let U0 := constr:(Type) in |
| 63 |
let U1 := constr:(Type) in |
| 64 |
let unif := constr:(U0 : U1) in |
| 65 |
exact (forall T : U0, { T' : U1 & type_eq T' T }). |
| 66 |
Defined. |
| 67 |
|
| 68 |
Axiom type_cast_up : type_cast_up_type. |
| 69 |
End local. |
| 70 |
|
| 71 |
Definition Lift (T : Type) := projT1 (type_cast_up T). |
| 72 |
Definition lift {T} : T -> Lift T |
| 73 |
:= match projT2 (type_cast_up T) in (type_eq _ T') return T' -> Lift T with |
| 74 |
| type_eq_refl => fun x => x |
| 75 |
| type_eq_impossible bad _ => match bad with end |
| 76 |
end. |
| 77 |
Section equiv. |
| 78 |
Definition lower' {T} : Lift T -> T |
| 79 |
:= match projT2 (type_cast_up T) in (type_eq _ T') return Lift T -> T' with |
| 80 |
| type_eq_refl => fun x => x |
| 81 |
| type_eq_impossible bad _ => match bad with end |
| 82 |
end. |
| 83 |
Definition lift_lower {T} (x : Lift T) : lift (lower' x) = x. |
| 84 |
Proof. |
| 85 |
unfold lower', lift. |
| 86 |
destruct (projT2 (type_cast_up T)) as [|[]]. |
| 87 |
reflexivity. |
| 88 |
Defined. |
| 89 |
Definition lower_lift {T} (x : T) : lower' (lift x) = x. |
| 90 |
Proof. |
| 91 |
unfold lower', lift, Lift in *. |
| 92 |
destruct (type_cast_up T) as [T' p]; simpl. |
| 93 |
let y := match goal with |- ?y => constr:(y) end in |
| 94 |
let P := match (eval pattern p in y) with ?f p => constr:(f) end in |
| 95 |
apply (@transport _ P _ _ (type_eq_sym_type_eq_sym p)); simpl in *. |
| 96 |
generalize (type_eq_sym p); intro p'; clear p. |
| 97 |
destruct p' as [|[]]; simpl. |
| 98 |
reflexivity. |
| 99 |
Defined. |
| 100 |
|
| 101 |
Global Instance isequiv_lift A : IsEquiv (@lift A). |
| 102 |
Proof. |
| 103 |
refine (@BuildIsEquiv |
| 104 |
_ _ |
| 105 |
lift lower' |
| 106 |
lift_lower |
| 107 |
lower_lift |
| 108 |
_). |
| 109 |
compute. |
| 110 |
intro x. |
| 111 |
destruct (type_cast_up A) as [T' p]. |
| 112 |
let y := match goal with |- ?y => constr:(y) end in |
| 113 |
let P := match (eval pattern p in y) with ?f p => constr:(f) end in |
| 114 |
apply (@transport _ P _ _ (type_eq_sym_type_eq_sym p)); simpl in *. |
| 115 |
generalize (type_eq_sym p); intro p'; clear p. |
| 116 |
destruct p' as [|[]]; simpl. |
| 117 |
reflexivity. |
| 118 |
Defined. |
| 119 |
End equiv. |
| 120 |
Definition lower {A} := (@equiv_inv _ _ (@lift A) _). |
| 121 |
End LiftT. |
| 122 |
|
| 123 |
Module Lift : LiftT. |
| 124 |
Section local. |
| 125 |
Let type_cast_up_type : Type. |
| 126 |
Proof. |
| 127 |
let U0 := constr:(Type) in |
| 128 |
let U1 := constr:(Type) in |
| 129 |
let unif := constr:(U0 : U1) in |
| 130 |
exact (forall T : U0, { T' : U1 & type_eq T' T }). |
| 131 |
Defined. |
| 132 |
|
| 133 |
Definition type_cast_up : type_cast_up_type |
| 134 |
:= fun T => existT (fun T' => type_eq T' T) T (type_eq_refl _). |
| 135 |
End local. |
| 136 |
|
| 137 |
Definition Lift (T : Type) := projT1 (type_cast_up T). |
| 138 |
Definition lift {T} : T -> Lift T |
| 139 |
:= match projT2 (type_cast_up T) in (type_eq _ T') return T' -> Lift T with |
| 140 |
| type_eq_refl => fun x => x |
| 141 |
| type_eq_impossible bad _ => match bad with end |
| 142 |
end. |
| 143 |
Section equiv. |
| 144 |
Definition lower' {T} : Lift T -> T |
| 145 |
:= match projT2 (type_cast_up T) in (type_eq _ T') return Lift T -> T' with |
| 146 |
| type_eq_refl => fun x => x |
| 147 |
| type_eq_impossible bad _ => match bad with end |
| 148 |
end. |
| 149 |
Definition lift_lower {T} (x : Lift T) : lift (lower' x) = x. |
| 150 |
Proof. |
| 151 |
unfold lower', lift. |
| 152 |
destruct (projT2 (type_cast_up T)) as [|[]]. |
| 153 |
reflexivity. |
| 154 |
Defined. |
| 155 |
Definition lower_lift {T} (x : T) : lower' (lift x) = x. |
| 156 |
Proof. |
| 157 |
unfold lower', lift, Lift in *. |
| 158 |
destruct (type_cast_up T) as [T' p]; simpl. |
| 159 |
let y := match goal with |- ?y => constr:(y) end in |
| 160 |
let P := match (eval pattern p in y) with ?f p => constr:(f) end in |
| 161 |
apply (@transport _ P _ _ (type_eq_sym_type_eq_sym p)); simpl in *. |
| 162 |
generalize (type_eq_sym p); intro p'; clear p. |
| 163 |
destruct p' as [|[]]; simpl. |
| 164 |
reflexivity. |
| 165 |
Defined. |
| 166 |
|
| 167 |
|
| 168 |
Global Instance isequiv_lift A : IsEquiv (@lift A). |
| 169 |
Proof. |
| 170 |
refine (@BuildIsEquiv |
| 171 |
_ _ |
| 172 |
lift lower' |
| 173 |
lift_lower |
| 174 |
lower_lift |
| 175 |
_). |
| 176 |
compute. |
| 177 |
intro x. |
| 178 |
destruct (type_cast_up A) as [T' p]. |
| 179 |
let y := match goal with |- ?y => constr:(y) end in |
| 180 |
let P := match (eval pattern p in y) with ?f p => constr:(f) end in |
| 181 |
apply (@transport _ P _ _ (type_eq_sym_type_eq_sym p)); simpl in *. |
| 182 |
generalize (type_eq_sym p); intro p'; clear p. |
| 183 |
destruct p' as [|[]]; simpl. |
| 184 |
reflexivity. |
| 185 |
Defined. |
| 186 |
End equiv. |
| 187 |
Definition lower {A} := (@equiv_inv _ _ (@lift A) _). |
| 188 |
End Lift. |
| 189 |
(* Toplevel input, characters 15-24: |
| 190 |
Anomaly: Invalid argument: enforce_eq_instances called with instances of different lengths. |
| 191 |
Please report. *) |