| 1 |
Require Import TestSuite.funext. |
| 2 |
Require Import Corelib.Program.Tactics. |
| 3 |
|
| 4 |
Global Set Primitive Projections. |
| 5 |
|
| 6 |
Global Set Universe Polymorphism. |
| 7 |
|
| 8 |
Global Unset Universe Minimization ToSet. |
| 9 |
|
| 10 |
Class Category : Type := |
| 11 |
{ |
| 12 |
Obj : Type; |
| 13 |
Hom : Obj -> Obj -> Type; |
| 14 |
compose : forall {a b c : Obj}, (Hom a b) -> (Hom b c) -> (Hom a c); |
| 15 |
id : forall {a : Obj}, Hom a a; |
| 16 |
}. |
| 17 |
|
| 18 |
Arguments Obj {_}, _. |
| 19 |
Arguments id {_ _}, {_} _, _ _. |
| 20 |
Arguments Hom {_} _ _, _ _ _. |
| 21 |
Arguments compose {_} {_ _ _} _ _, _ {_ _ _} _ _, _ _ _ _ _ _. |
| 22 |
|
| 23 |
Coercion Obj : Category >-> Sortclass. |
| 24 |
|
| 25 |
Definition Opposite (C : Category) : Category := |
| 26 |
{| |
| 27 |
|
| 28 |
Obj := Obj C; |
| 29 |
Hom := fun a b => Hom b a; |
| 30 |
compose := |
| 31 |
fun a b c (f : Hom b a) (g : Hom c b) => compose C c b a g f; |
| 32 |
id := fun c => id C c; |
| 33 |
|}. |
| 34 |
|
| 35 |
Record Functor (C C' : Category) : Type := |
| 36 |
{ |
| 37 |
FO : C -> C'; |
| 38 |
FA : forall {a b}, Hom a b -> Hom (FO a) (FO b); |
| 39 |
}. |
| 40 |
|
| 41 |
Arguments FO {_ _} _ _. |
| 42 |
Arguments FA {_ _} _ {_ _} _, {_ _} _ _ _ _. |
| 43 |
|
| 44 |
Section Opposite_Functor. |
| 45 |
Context {C D : Category} (F : Functor C D). |
| 46 |
|
| 47 |
Program Definition Opposite_Functor : (Functor (Opposite C) (Opposite D)) := |
| 48 |
{| |
| 49 |
FO := FO F; |
| 50 |
FA := fun _ _ h => FA F h; |
| 51 |
|}. |
| 52 |
|
| 53 |
End Opposite_Functor. |
| 54 |
|
| 55 |
Section Functor_Compose. |
| 56 |
Context {C C' C'' : Category} (F : Functor C C') (F' : Functor C' C''). |
| 57 |
|
| 58 |
Program Definition Functor_compose : Functor C C'' := |
| 59 |
{| |
| 60 |
FO := fun c => FO F' (FO F c); |
| 61 |
FA := fun c d f => FA F' (FA F f) |
| 62 |
|}. |
| 63 |
|
| 64 |
End Functor_Compose. |
| 65 |
|
| 66 |
Section Algebras. |
| 67 |
Context {C : Category} (T : Functor C C). |
| 68 |
Record Algebra : Type := |
| 69 |
{ |
| 70 |
Alg_Carrier : C; |
| 71 |
Constructors : Hom (FO T Alg_Carrier) Alg_Carrier |
| 72 |
}. |
| 73 |
|
| 74 |
Record Algebra_Hom (alg alg' : Algebra) : Type := |
| 75 |
{ |
| 76 |
Alg_map : Hom (Alg_Carrier alg) (Alg_Carrier alg'); |
| 77 |
|
| 78 |
Alg_map_com : compose (FA T Alg_map) (Constructors alg') |
| 79 |
= compose (Constructors alg) Alg_map |
| 80 |
}. |
| 81 |
|
| 82 |
Arguments Alg_map {_ _} _. |
| 83 |
Arguments Alg_map_com {_ _} _. |
| 84 |
Program Definition Algebra_Hom_compose |
| 85 |
{alg alg' alg'' : Algebra} |
| 86 |
(h : Algebra_Hom alg alg') |
| 87 |
(h' : Algebra_Hom alg' alg'') |
| 88 |
: Algebra_Hom alg alg'' |
| 89 |
:= |
| 90 |
{| |
| 91 |
Alg_map := compose (Alg_map h) (Alg_map h') |
| 92 |
|}. |
| 93 |
|
| 94 |
Next Obligation. Proof. Admitted. |
| 95 |
|
| 96 |
Lemma Algebra_Hom_eq_simplify (alg alg' : Algebra) |
| 97 |
(ah ah' : Algebra_Hom alg alg') |
| 98 |
: (Alg_map ah) = (Alg_map ah') -> ah = ah'. |
| 99 |
Proof. Admitted. |
| 100 |
|
| 101 |
Program Definition Algebra_Hom_id (alg : Algebra) : Algebra_Hom alg alg := |
| 102 |
{| |
| 103 |
Alg_map := id |
| 104 |
|}. |
| 105 |
|
| 106 |
Next Obligation. Admitted. |
| 107 |
|
| 108 |
Definition Algebra_Cat : Category := |
| 109 |
{| |
| 110 |
Obj := Algebra; |
| 111 |
Hom := Algebra_Hom; |
| 112 |
compose := @Algebra_Hom_compose; |
| 113 |
id := Algebra_Hom_id; |
| 114 |
|}. |
| 115 |
|
| 116 |
End Algebras. |
| 117 |
|
| 118 |
Arguments Alg_Carrier {_ _} _. |
| 119 |
Arguments Constructors {_ _} _. |
| 120 |
Arguments Algebra_Hom {_ _} _ _. |
| 121 |
Arguments Alg_map {_ _ _ _} _. |
| 122 |
Arguments Alg_map_com {_ _ _ _} _. |
| 123 |
Arguments Algebra_Hom_id {_ _} _. |
| 124 |
|
| 125 |
Section CoAlgebras. |
| 126 |
Context {C : Category}. |
| 127 |
|
| 128 |
Definition CoAlgebra (T : Functor C C) := |
| 129 |
@Algebra (Opposite C) (Opposite_Functor T). |
| 130 |
|
| 131 |
Definition CoAlgebra_Hom {T : Functor C C} := |
| 132 |
@Algebra_Hom (Opposite C) (Opposite_Functor T). |
| 133 |
|
| 134 |
Definition CoAlgebra_Hom_id {T : Functor C C} := |
| 135 |
@Algebra_Hom_id (Opposite C) (Opposite_Functor T). |
| 136 |
|
| 137 |
Definition CoAlgebra_Cat (T : Functor C C) := |
| 138 |
@Algebra_Cat (Opposite C) (Opposite_Functor T). |
| 139 |
|
| 140 |
End CoAlgebras. |
| 141 |
|
| 142 |
Program Definition Type_Cat : Category := |
| 143 |
{| |
| 144 |
Obj := Type; |
| 145 |
Hom := (fun A B => A -> B); |
| 146 |
compose := fun A B C (g : A -> B) (h : B -> C) => fun (x : A) => h (g x); |
| 147 |
id := fun A => fun x => x |
| 148 |
|}. |
| 149 |
|
| 150 |
Local Obligation Tactic := idtac. |
| 151 |
|
| 152 |
Program Definition Prod_Cat (C C' : Category) : Category := |
| 153 |
{| |
| 154 |
Obj := C * C'; |
| 155 |
Hom := |
| 156 |
fun a b => |
| 157 |
((Hom (fst a) (fst b)) * (Hom (snd a) (snd b)))%type; |
| 158 |
compose := |
| 159 |
fun a b c f g => |
| 160 |
((compose (fst f) (fst g)), (compose (snd f)(snd g))); |
| 161 |
id := fun c => (id, id) |
| 162 |
|}. |
| 163 |
|
| 164 |
Class Terminal (C : Category) : Type := |
| 165 |
{ |
| 166 |
terminal : C; |
| 167 |
t_morph : forall (d : Obj), Hom d terminal; |
| 168 |
t_morph_unique : forall (d : Obj) (f g : (Hom d terminal)), f = g |
| 169 |
}. |
| 170 |
|
| 171 |
Arguments terminal {_} _. |
| 172 |
Arguments t_morph {_} _ _. |
| 173 |
Arguments t_morph_unique {_} _ _ _ _. |
| 174 |
|
| 175 |
Coercion terminal : Terminal >-> Obj. |
| 176 |
|
| 177 |
Definition Initial (C : Category) := Terminal (Opposite C). |
| 178 |
Existing Class Initial. |
| 179 |
|
| 180 |
Record Product {C : Category} (c d : C) : Type := |
| 181 |
{ |
| 182 |
product : C; |
| 183 |
Pi_1 : Hom product c; |
| 184 |
Pi_2 : Hom product d; |
| 185 |
Prod_morph_ex : forall (p' : Obj) (r1 : Hom p' c) (r2 : Hom p' d), (Hom p' product); |
| 186 |
}. |
| 187 |
|
| 188 |
Arguments Product _ _ _, {_} _ _. |
| 189 |
|
| 190 |
Arguments Pi_1 {_ _ _ _}, {_ _ _} _. |
| 191 |
Arguments Pi_2 {_ _ _ _}, {_ _ _} _. |
| 192 |
Arguments Prod_morph_ex {_ _ _} _ _ _ _. |
| 193 |
|
| 194 |
Coercion product : Product >-> Obj. |
| 195 |
|
| 196 |
Definition Has_Products (C : Category) : Type := forall a b, Product a b. |
| 197 |
|
| 198 |
Existing Class Has_Products. |
| 199 |
|
| 200 |
Program Definition Prod_Func (C : Category) {HP : Has_Products C} |
| 201 |
: Functor (Prod_Cat C C) C := |
| 202 |
{| |
| 203 |
FO := fun x => HP (fst x) (snd x); |
| 204 |
FA := fun a b f => Prod_morph_ex _ _ (compose Pi_1 (fst f)) (compose Pi_2 (snd f)) |
| 205 |
|}. |
| 206 |
|
| 207 |
Arguments Prod_Func _ _, _ {_}. |
| 208 |
|
| 209 |
Definition Sum (C : Category) := @Product (Opposite C). |
| 210 |
|
| 211 |
Arguments Sum _ _ _, {_} _ _. |
| 212 |
|
| 213 |
Definition Has_Sums (C : Category) : Type := forall (a b : C), (Sum a b). |
| 214 |
|
| 215 |
Existing Class Has_Sums. |
| 216 |
|
| 217 |
Program Definition sum_Sum (A B : Type) : (@Sum Type_Cat A B) := |
| 218 |
{| |
| 219 |
product := (A + B)%type; |
| 220 |
Prod_morph_ex := |
| 221 |
fun (p' : Type) |
| 222 |
(r1 : A -> p') |
| 223 |
(r2 : B -> p') |
| 224 |
(X : A + B) => |
| 225 |
match X return p' with |
| 226 |
| inl a => r1 a |
| 227 |
| inr b => r2 b |
| 228 |
end |
| 229 |
|}. |
| 230 |
Next Obligation. simpl; auto. Defined. |
| 231 |
Next Obligation. simpl; auto. Defined. |
| 232 |
|
| 233 |
#[export] Program Instance Type_Cat_Has_Sums : Has_Sums Type_Cat := sum_Sum. |
| 234 |
|
| 235 |
Definition Sum_Func {C : Category} {HS : Has_Sums C} : |
| 236 |
Functor (Prod_Cat C C) C := Opposite_Functor (Prod_Func (Opposite C) HS). |
| 237 |
|
| 238 |
Arguments Sum_Func _ _, _ {_}. |
| 239 |
|
| 240 |
#[export] Program Instance unit_Type_term : Terminal Type_Cat := |
| 241 |
{ |
| 242 |
terminal := unit; |
| 243 |
t_morph := fun _ _=> tt |
| 244 |
}. |
| 245 |
|
| 246 |
Next Obligation. Proof. Admitted. |
| 247 |
|
| 248 |
Program Definition term_id : Functor Type_Cat (Prod_Cat Type_Cat Type_Cat) := |
| 249 |
{| |
| 250 |
FO := fun a => (@terminal Type_Cat _, a); |
| 251 |
FA := fun a b f => (@id _ (@terminal Type_Cat _), f) |
| 252 |
|}. |
| 253 |
|
| 254 |
Definition S_nat_func : Functor Type_Cat Type_Cat := |
| 255 |
Functor_compose term_id (Sum_Func Type_Cat _). |
| 256 |
|
| 257 |
Definition S_nat_alg_cat := Algebra_Cat S_nat_func. |
| 258 |
|
| 259 |
CoInductive CoNat : Set := |
| 260 |
| CoO : CoNat |
| 261 |
| CoS : CoNat -> CoNat |
| 262 |
. |
| 263 |
|
| 264 |
Definition S_nat_coalg_cat := @CoAlgebra_Cat Type_Cat S_nat_func. |
| 265 |
|
| 266 |
Set Printing Universes. |
| 267 |
Program Definition CoNat_alg_term : Initial S_nat_coalg_cat := |
| 268 |
{| |
| 269 |
terminal := _; |
| 270 |
t_morph := _ |
| 271 |
|}. |
| 272 |
|
| 273 |
Next Obligation. Admitted. |
| 274 |
Next Obligation. Admitted. |
| 275 |
|
| 276 |
Axiom Admit : False. |
| 277 |
|
| 278 |
Next Obligation. |
| 279 |
Proof. |
| 280 |
intros d f g. |
| 281 |
assert(H1 := (@Alg_map_com _ _ _ _ f)). clear. |
| 282 |
assert (inl tt = inr tt) by (exfalso; apply Admit). |
| 283 |
discriminate. |
| 284 |
all: exfalso; apply Admit. |
| 285 |
Show Universes. |
| 286 |
Qed. |