Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. import init.setoid
  2. import data.set
  3. open set
  4.  
  5. structure category [class] :=
  6. (obj : Type)
  7. (hom : obj → obj → Type)
  8. (id : ∀ (x : obj), hom x x)
  9. (comp : ∀ {a b c : obj}, hom b c → hom a b → hom a c)
  10. (assoc : ∀ {a b c d} {f : hom a b} {g : hom b c} {h : hom c d},
  11. comp h (comp g f) = comp (comp h g) f)
  12. (id_left : ∀ {a b} {f : hom a b}, comp !id f = f)
  13. (id_right : ∀ {a b} {f : hom a b}, comp f !id = f)
  14. open category
  15.  
  16. namespace category
  17. notation `∘` := comp
  18. infixr `⟶`:25 := hom
  19.  
  20. notation f `∘[` C `]` g:25 := @comp C _ _ _ f g
  21.  
  22. definition op [instance] (C : category) : category :=
  23. category.mk
  24. (@obj C)
  25. (λx y, @hom C y x)
  26. (@id C)
  27. (λa b c f g, comp g f)
  28. (λa b c d f g h, eq.symm !assoc)
  29. (λa b f, id_right)
  30. (λa b f, id_left)
  31.  
  32. structure setmap {S S' : Type} (A : set S) (B : set S') : Type :=
  33. (mapping : S → S')
  34. (mapsin : ∀ x, x ∈ A → mapping x ∈ B)
  35. open setmap
  36.  
  37. definition setmap_comp {A B C : set Type} (g : setmap B C) (f : setmap A B) : setmap A C :=
  38. setmap.mk
  39. (λx, mapping g (mapping f x))
  40. (take x, assume xin : x ∈ A, !mapsin (!mapsin xin))
  41.  
  42. axiom setmap_eq {A B : set Type} (f g : setmap A B) : (∀ x, mapping f x = mapping g x) → f = g
  43.  
  44. definition Sets [instance] : category :=
  45. category.mk
  46. (set Type)
  47. (λx y, setmap x y)
  48. (λx, setmap.mk (λu, u) (take x, λp, p))
  49. (λa b c g f, setmap_comp g f)
  50. (λa b c d h g f, rfl)
  51. (λa b f, begin apply !setmap_eq, intro x, apply rfl end)
  52. (λa b f, begin apply !setmap_eq, intro x, apply rfl end)
  53.  
  54. definition homset {C : category} (a b : @obj C) : Type := set (@hom C a b)
  55.  
  56. definition Types [instance] : category :=
  57. category.mk
  58. Type
  59. (λx y, x → y)
  60. (λx u, u)
  61. (λa b c g f, λu, g (f u))
  62. (λa b c d h g f, rfl)
  63. (λa b f, rfl)
  64. (λa b f, rfl)
  65.  
  66. structure iso {C : category} (a b : @obj C) :=
  67. (mapr : @hom C a b)
  68. (mapl : @hom C b a)
  69. (isorl : (mapr ∘[C] mapl) = id b)
  70. (isolr : (mapl ∘[C] mapr) = id a)
  71.  
  72. notation a `≅` b := @iso _ a b
  73. notation a `≅[` C `]` b := @iso C a b
  74.  
  75. end category
  76. open category
  77.  
  78. structure functor (C : category) (D : category) :=
  79. (fobj : @obj C → @obj D)
  80. (fmap : ∀ {a b : @obj C}, @hom C a b → @hom D (fobj a) (fobj b))
  81. (preserve_id : ∀ {a : @obj C}, fmap (@id C a) = @id D (fobj a))
  82. (preserve_comp : ∀ {a b c : @obj C} {g : @hom C b c} {f : @hom C a b},
  83. fmap (g ∘[C] f) = (fmap g ∘[D] fmap f))
  84. open functor
  85.  
  86. namespace functor
  87. variables {C D E : category}
  88.  
  89. definition functor_comp (G : functor D E) (F : functor C D) : functor C E :=
  90. functor.mk
  91. (λx, fobj G (fobj F x))
  92. (λa b f, fmap G (fmap F f))
  93. (λa, calc
  94. fmap G (fmap F (@id C a)) = fmap G (@id D (fobj F a)) : preserve_id F
  95. ... = @id E (fobj G (fobj F a)) : preserve_id G)
  96. (λa b c g f, calc
  97. fmap G (fmap F (g ∘[C] f)) = fmap G (fmap F g ∘[D] fmap F f) : preserve_comp F
  98. ... = (fmap G (fmap F g) ∘[E] fmap G (fmap F f)) : preserve_comp G)
  99.  
  100. notation G `∘f` F := functor_comp G F
  101.  
  102. definition functor_id : functor C C :=
  103. functor.mk
  104. (λx, x)
  105. (λa b f, f)
  106. (λa, rfl)
  107. (λa b c g f, rfl)
  108.  
  109. inductive eqArrow {a b : @obj C} (f : @hom C a b) : ∀ {x y : @obj C}, @hom C x y → Type :=
  110. | arr : ∀ {g : @hom C a b}, f = g → eqArrow f g
  111.  
  112. axiom functor_eq {C D : category} (F G : functor C D) :
  113. (∀ {a b : @obj C} (f : @hom C a b), eqArrow (fmap F f) (fmap G f)) → F = G
  114.  
  115. end functor
  116. open functor
  117.  
  118. definition Cat : category :=
  119. category.mk
  120. category
  121. functor
  122. @functor_id
  123. @functor_comp
  124. (λa b c d F G H, functor_eq _ _ (λa b f, !eqArrow.arr (calc
  125. fmap (H ∘f (G ∘f F)) f = fmap H (fmap G (fmap F f)) : rfl
  126. ... = fmap ((H ∘f G) ∘f F) f : rfl)))
  127. (λa b F, functor_eq _ _ (λa b f, !eqArrow.arr rfl))
  128. (λa b F, functor_eq _ _ (λa b f, !eqArrow.arr rfl))
  129.  
  130. structure natrans {C D : category} (F G : functor C D) :=
  131. (component : ∀ (x : @obj C), @hom D (fobj F x) (fobj G x))
  132. (naturality : ∀ {a b : @obj C} {f : @hom C a b},
  133. (component b ∘[D] fmap F f) = (fmap G f ∘[D] component a))
  134. open natrans
  135.  
  136. namespace natrans
  137. variables {C D : category} {F G H : functor C D}
  138. notation F `⇒` G := natrans F G
  139.  
  140. definition natrans_comp (ε : G ⇒ H) (η : F ⇒ G) : F ⇒ H :=
  141. natrans.mk
  142. (λx, (component ε x ∘[D] component η x))
  143. (λa b f, calc
  144. ((component ε b ∘[D] component η b) ∘[D] fmap F f) = (component ε b ∘[D] (component η b ∘[D] fmap F f)) : assoc
  145. ... = (component ε b ∘[D] (fmap G f ∘[D] component η a)) : naturality η
  146. ... = ((component ε b ∘[D] fmap G f) ∘[D] component η a) : assoc
  147. ... = ((fmap H f ∘[D] component ε a) ∘[D] component η a) : naturality ε
  148. ... = (fmap H f ∘[D] (component ε a ∘[D] component η a)) : assoc)
  149.  
  150. definition natrans_id : F ⇒ F :=
  151. natrans.mk
  152. (λx, @id D (fobj F x))
  153. (λa b f, calc
  154. (@id D (fobj F b) ∘[D] fmap F f) = fmap F f : @id_left
  155. ... = (fmap F f ∘[D] @id D (fobj F a)) : @id_right)
  156.  
  157. axiom natrans_eq {C D : category} {F G : functor C D} (α β : F ⇒ G) :
  158. (∀ x, eqArrow (component α x) (component β x)) → α = β
  159.  
  160. end natrans
  161. open natrans
  162.  
  163. -- one can define Sets-valued hom functor?
  164. -- or Setoids-valued?
  165.  
  166. definition homfunctor (C : category) (r : @obj C) : functor (op C) Types :=
  167. functor.mk
  168. (λx, @hom C x r)
  169. (λa b f, λu, (u ∘[C] f))
  170. (λa, funext (take x, id_right))
  171. (λa b c g f, funext (take u, assoc))
  172.  
  173. definition homnat (C : category) {a b : @obj C} (f : @hom C a b) : (homfunctor C a) ⇒ (homfunctor C b) :=
  174. natrans.mk
  175. (λx, λu, f ∘[C] u)
  176. (λx y k, funext (take u, assoc))
  177.  
  178. definition funcat (C D : category) : category :=
  179. category.mk
  180. (functor C D)
  181. natrans
  182. (λx, natrans_id)
  183. (λa b c, natrans_comp)
  184. (λa b c d f g h, natrans_eq _ _ (λx, eqArrow.arr assoc))
  185. (λa b f, natrans_eq _ _ (λx, eqArrow.arr id_left))
  186. (λa b f, natrans_eq _ _ (λx, eqArrow.arr id_right))
  187.  
  188. notation `[` C `,` D `]` := funcat C D
  189. notation `PSh[` C `]` := [ op C, Types ]
  190.  
  191. definition yoneda (C : category) : functor C PSh[C] :=
  192. functor.mk
  193. (λx, homfunctor C x)
  194. (λa b f, homnat C f)
  195. (λa, natrans_eq _ _ (λx, !eqArrow.arr (funext (λy, id_left))))
  196. (λa b c g f, natrans_eq _ _ (λx, eqArrow.arr (funext (λy, calc _ = _ : assoc))))
  197.  
  198. lemma Yoneda (C : category) (F : functor (op C) Types) (r : @obj C) :
  199. @hom PSh[C] (fobj (yoneda C) r) F ≅[Types] fobj F r
  200. := iso.mk
  201. (λα, component α r (@id C r))
  202. (λu, natrans.mk
  203. (λx f, fmap F f u)
  204. (λa b f, funext (λ (x : a ⟶ r), calc
  205. ((λf, fmap F f u) ∘[Types] (fmap (fobj (yoneda C) r) f)) x = fmap F (x ∘[C] f) u : rfl
  206. ... = (fmap F (f ∘[op C] x)) u : rfl
  207. ... = (fmap F f ∘[Types] fmap F x) u : congr_fun !preserve_comp
  208. ... = ((fmap F f) ∘[Types] (λ (f : a ⟶ r), fmap F f u)) x : rfl)))
  209. (calc
  210. fmap F (@id C r) = @id Types (fobj F r) : !preserve_id)
  211. (funext (λα, natrans_eq _ _ (λx, eqArrow.arr (funext (λu, calc
  212. fmap F u (component α r (@id C r)) = (fmap F u ∘[Types] component α r) (@id C r) : rfl
  213. ... = (component α x ∘[Types] fmap (fobj (yoneda C) r) u) (@id C r) : congr_fun !naturality
  214. ... = component α x (@id C r ∘[C] u) : rfl
  215. ... = component α x u : congr_arg _ id_left)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement