cat/src/Cat/Categories/Cat.agda

307 lines
12 KiB
Agda
Raw Normal View History

2018-02-02 14:33:54 +00:00
-- There is no category of categories in our interpretation
{-# OPTIONS --cubical --allow-unsolved-metas #-}
module Cat.Categories.Cat where
2018-03-21 13:39:56 +00:00
open import Cat.Prelude renaming (proj₁ to fst ; proj₂ to snd)
open import Cat.Category
2018-02-05 15:35:33 +00:00
open import Cat.Category.Functor
open import Cat.Category.Product
open import Cat.Category.Exponential hiding (_×_ ; product)
open import Cat.Category.NaturalTransformation
2018-03-21 13:39:56 +00:00
open import Cat.Categories.Fun
-- The category of categories
2018-01-24 15:38:28 +00:00
module _ ( ' : Level) where
RawCat : RawCategory (lsuc ( ')) ( ')
2018-03-21 12:25:24 +00:00
RawCategory.Object RawCat = Category '
RawCategory.Arrow RawCat = Functor
RawCategory.𝟙 RawCat = Functors.identity
2018-03-21 12:25:24 +00:00
RawCategory._∘_ RawCat = F[_∘_]
2018-03-08 10:54:13 +00:00
-- NB! `ArrowsAreSets RawCat` is *not* provable. The type of functors,
-- however, form a groupoid! Therefore there is no (1-)category of
-- categories. There does, however, exist a 2-category of 1-categories.
--
-- Because of this there is no category of categories.
Cat : (unprovable : IsCategory RawCat) Category (lsuc ( ')) ( ')
2018-03-21 12:25:24 +00:00
Category.raw (Cat _) = RawCat
Category.isCategory (Cat unprovable) = unprovable
2018-03-08 10:54:13 +00:00
-- | In the following we will pretend there is a category of categories when
-- e.g. talking about it being cartesian closed. It still makes sense to
-- construct these things even though that category does not exist.
--
-- If the notion of a category is later generalized to work on different
-- homotopy levels, then the proof that the category of categories is cartesian
-- closed will follow immediately from these constructions.
-- | the category of categories have products.
module CatProduct { ' : Level} ( 𝔻 : Category ') where
private
2018-03-08 10:54:13 +00:00
module = Category
module 𝔻 = Category 𝔻
2018-03-21 12:25:24 +00:00
module _ where
private
Obj = .Object × 𝔻.Object
Arr : Obj Obj Set '
Arr (c , d) (c' , d') = [ c , c' ] × 𝔻 [ d , d' ]
𝟙 : {o : Obj} Arr o o
𝟙 = .𝟙 , 𝔻.𝟙
_∘_ :
{a b c : Obj}
Arr b c
Arr a b
Arr a c
_∘_ = λ { (bc∈C , bc∈D) (ab∈C , ab∈D) [ bc∈C ab∈C ] , 𝔻 [ bc∈D ab∈D ]}
rawProduct : RawCategory '
RawCategory.Object rawProduct = Obj
RawCategory.Arrow rawProduct = Arr
RawCategory.𝟙 rawProduct = 𝟙
RawCategory._∘_ rawProduct = _∘_
open RawCategory rawProduct
arrowsAreSets : ArrowsAreSets
arrowsAreSets = setSig {sA = .arrowsAreSets} {sB = λ x 𝔻.arrowsAreSets}
2018-03-21 12:25:24 +00:00
isIdentity : IsIdentity 𝟙
isIdentity
= Σ≡ (fst .isIdentity) (fst 𝔻.isIdentity)
, Σ≡ (snd .isIdentity) (snd 𝔻.isIdentity)
postulate univalent : Univalence.Univalent isIdentity
instance
isCategory : IsCategory rawProduct
IsCategory.isAssociative isCategory = Σ≡ .isAssociative 𝔻.isAssociative
IsCategory.isIdentity isCategory = isIdentity
IsCategory.arrowsAreSets isCategory = arrowsAreSets
IsCategory.univalent isCategory = univalent
2018-03-08 10:54:13 +00:00
object : Category '
Category.raw object = rawProduct
2018-03-08 10:54:13 +00:00
proj₁ : Functor object
proj₁ = record
2018-03-08 10:54:13 +00:00
{ raw = record
{ omap = fst ; fmap = fst }
; isFunctor = record
{ isIdentity = refl ; isDistributive = refl }
}
2018-03-08 10:54:13 +00:00
proj₂ : Functor object 𝔻
proj₂ = record
2018-03-08 10:54:13 +00:00
{ raw = record
{ omap = snd ; fmap = snd }
; isFunctor = record
{ isIdentity = refl ; isDistributive = refl }
}
module _ {X : Category '} (x₁ : Functor X ) (x₂ : Functor X 𝔻) where
2018-01-24 15:38:28 +00:00
private
2018-03-08 10:54:13 +00:00
x : Functor X object
x = record
{ raw = record
{ omap = λ x x₁.omap x , x₂.omap x
; fmap = λ x x₁.fmap x , x₂.fmap x
}
; isFunctor = record
2018-03-08 10:54:13 +00:00
{ isIdentity = Σ≡ x₁.isIdentity x₂.isIdentity
; isDistributive = Σ≡ x₁.isDistributive x₂.isDistributive
}
}
where
open module x = Functor x₁
open module x = Functor x₂
isUniqL : F[ proj₁ x ] x₁
2018-03-05 16:10:41 +00:00
isUniqL = Functor≡ refl
2018-01-24 15:38:28 +00:00
isUniqR : F[ proj₂ x ] x₂
2018-03-05 16:10:41 +00:00
isUniqR = Functor≡ refl
2018-01-24 15:38:28 +00:00
isUniq : F[ proj₁ x ] x₁ × F[ proj₂ x ] x₂
isUniq = isUniqL , isUniqR
2018-01-24 15:38:28 +00:00
isProduct : ∃![ x ] (F[ proj₁ x ] x₁ × F[ proj₂ x ] x₂)
isProduct = x , isUniq
2018-01-24 15:38:28 +00:00
module _ { ' : Level} (unprovable : IsCategory (RawCat ')) where
private
Cat = Cat ' unprovable
module _ ( 𝔻 : Category ') where
private
module P = CatProduct 𝔻
2018-03-08 09:22:21 +00:00
rawProduct : RawProduct Cat 𝔻
2018-03-08 10:54:13 +00:00
RawProduct.object rawProduct = P.object
2018-03-08 09:45:15 +00:00
RawProduct.proj₁ rawProduct = P.proj₁
RawProduct.proj₂ rawProduct = P.proj₂
2018-03-08 09:20:29 +00:00
2018-03-08 09:28:05 +00:00
isProduct : IsProduct Cat _ _ rawProduct
IsProduct.ump isProduct = P.isProduct
2018-01-24 15:38:28 +00:00
2018-03-08 09:22:21 +00:00
product : Product Cat 𝔻
2018-03-08 09:20:29 +00:00
Product.raw product = rawProduct
Product.isProduct product = isProduct
2018-01-24 15:38:28 +00:00
instance
hasProducts : HasProducts Cat
hasProducts = record { product = product }
2018-03-08 10:54:13 +00:00
-- | The category of categories have expoentntials - and because it has products
-- it is therefory also cartesian closed.
module CatExponential { : Level} ( 𝔻 : Category ) where
2018-03-08 10:20:51 +00:00
private
module = Category
module 𝔻 = Category 𝔻
2018-03-08 10:54:13 +00:00
Category = Category
open Fun 𝔻 renaming (identity to idN)
2018-03-21 12:25:24 +00:00
omap : Functor 𝔻 × .Object 𝔻.Object
2018-03-08 10:54:13 +00:00
omap (F , A) = Functor.omap F A
2018-01-25 11:01:37 +00:00
2018-03-08 10:54:13 +00:00
-- The exponential object
object : Category
object = Fun
2018-03-21 12:25:24 +00:00
module _ {dom cod : Functor 𝔻 × .Object} where
open Σ dom renaming (proj₁ to F ; proj₂ to A)
open Σ cod renaming (proj₁ to G ; proj₂ to B)
private
2018-03-08 10:20:51 +00:00
module F = Functor F
module G = Functor G
fmap : (pobj : NaturalTransformation F G × [ A , B ])
2018-03-08 10:20:51 +00:00
𝔻 [ F.omap A , G.omap B ]
2018-03-21 12:25:24 +00:00
fmap ((θ , θNat) , f) = 𝔻 [ θ B F.fmap f ]
-- Alternatively:
--
-- fmap ((θ , θNat) , f) = 𝔻 [ G.fmap f ∘ θ A ]
--
-- Since they are equal by naturality of θ.
2018-03-08 10:54:13 +00:00
open CatProduct renaming (object to _⊗_) using ()
2018-03-21 12:25:24 +00:00
module _ {c : Functor 𝔻 × .Object} where
open Σ c renaming (proj₁ to F ; proj₂ to C)
2018-03-21 13:39:56 +00:00
ident : fmap {c} {c} (NT.identity F , .𝟙 {A = snd c}) 𝔻.𝟙
ident = begin
2018-03-21 12:25:24 +00:00
fmap {c} {c} (Category.𝟙 (object ) {c}) ≡⟨⟩
fmap {c} {c} (idN F , .𝟙) ≡⟨⟩
𝔻 [ identityTrans F C F.fmap .𝟙 ] ≡⟨⟩
𝔻 [ 𝔻.𝟙 F.fmap .𝟙 ] ≡⟨ 𝔻.leftIdentity
F.fmap .𝟙 ≡⟨ F.isIdentity
𝔻.𝟙
where
module F = Functor F
2018-03-21 12:25:24 +00:00
module _ {F×A G×B H×C : Functor 𝔻 × .Object} where
open Σ F×A renaming (proj₁ to F ; proj₂ to A)
open Σ G×B renaming (proj₁ to G ; proj₂ to B)
open Σ H×C renaming (proj₁ to H ; proj₂ to C)
2018-03-08 10:20:51 +00:00
private
module F = Functor F
module G = Functor G
module H = Functor H
module _
{θ×f : NaturalTransformation F G × [ A , B ]}
{η×g : NaturalTransformation G H × [ B , C ]} where
2018-03-21 12:25:24 +00:00
open Σ θ×f renaming (proj₁ to θNT ; proj₂ to f)
open Σ θNT renaming (proj₁ to θ ; proj₂ to θNat)
open Σ η×g renaming (proj₁ to ηNT ; proj₂ to g)
open Σ ηNT renaming (proj₁ to η ; proj₂ to ηNat)
2018-01-24 15:38:28 +00:00
private
ηθNT : NaturalTransformation F H
2018-03-21 12:25:24 +00:00
ηθNT = NT[_∘_] {F} {G} {H} ηNT θNT
open Σ ηθNT renaming (proj₁ to ηθ ; proj₂ to ηθNat)
isDistributive :
2018-03-08 10:20:51 +00:00
𝔻 [ 𝔻 [ η C θ C ] F.fmap ( [ g f ] ) ]
𝔻 [ 𝔻 [ η C G.fmap g ] 𝔻 [ θ B F.fmap f ] ]
isDistributive = begin
2018-03-08 10:20:51 +00:00
𝔻 [ (ηθ C) F.fmap ( [ g f ]) ]
≡⟨ ηθNat ( [ g f ])
2018-03-08 10:20:51 +00:00
𝔻 [ H.fmap ( [ g f ]) (ηθ A) ]
≡⟨ cong (λ φ 𝔻 [ φ ηθ A ]) (H.isDistributive)
2018-03-08 10:20:51 +00:00
𝔻 [ 𝔻 [ H.fmap g H.fmap f ] (ηθ A) ]
≡⟨ sym 𝔻.isAssociative
𝔻 [ H.fmap g 𝔻 [ H.fmap f ηθ A ] ]
≡⟨ cong (λ φ 𝔻 [ H.fmap g φ ]) 𝔻.isAssociative
𝔻 [ H.fmap g 𝔻 [ 𝔻 [ H.fmap f η A ] θ A ] ]
≡⟨ cong (λ φ 𝔻 [ H.fmap g φ ]) (cong (λ φ 𝔻 [ φ θ A ]) (sym (ηNat f)))
𝔻 [ H.fmap g 𝔻 [ 𝔻 [ η B G.fmap f ] θ A ] ]
≡⟨ cong (λ φ 𝔻 [ H.fmap g φ ]) (sym 𝔻.isAssociative)
𝔻 [ H.fmap g 𝔻 [ η B 𝔻 [ G.fmap f θ A ] ] ]
≡⟨ 𝔻.isAssociative
𝔻 [ 𝔻 [ H.fmap g η B ] 𝔻 [ G.fmap f θ A ] ]
≡⟨ cong (λ φ 𝔻 [ φ 𝔻 [ G.fmap f θ A ] ]) (sym (ηNat g))
𝔻 [ 𝔻 [ η C G.fmap g ] 𝔻 [ G.fmap f θ A ] ]
≡⟨ cong (λ φ 𝔻 [ 𝔻 [ η C G.fmap g ] φ ]) (sym (θNat f))
𝔻 [ 𝔻 [ η C G.fmap g ] 𝔻 [ θ B F.fmap f ] ]
2018-03-08 10:54:13 +00:00
eval : Functor (CatProduct.object object ) 𝔻
eval = record
{ raw = record
{ omap = omap
; fmap = λ {dom} {cod} fmap {dom} {cod}
}
; isFunctor = record
{ isIdentity = λ {o} ident {o}
; isDistributive = λ {f u n k y} isDistributive {f} {u} {n} {k} {y}
}
}
2018-02-23 09:44:23 +00:00
2018-03-08 10:54:13 +00:00
module _ (𝔸 : Category ) (F : Functor (𝔸 ) 𝔻) where
postulate
parallelProduct
2018-03-08 10:54:13 +00:00
: Functor 𝔸 object Functor
Functor (𝔸 ) (object )
transpose : Functor 𝔸 object
eq : F[ eval (parallelProduct transpose (Functors.identity { = })) ] F
-- eq : F[ :eval: ∘ {!!} ] ≡ F
-- eq : Cat [ :eval: ∘ (HasProducts._|×|_ hasProducts transpose (𝟙 Cat {o = })) ] ≡ F
-- eq' : (Cat [ :eval: ∘
-- (record { product = product } HasProducts.|×| transpose)
-- (𝟙 Cat)
-- ])
-- ≡ F
-- For some reason after `e8215b2c051062c6301abc9b3f6ec67106259758`
-- `catTranspose` makes Agda hang. catTranspose : ∃![ F~ ] (Cat [
-- :eval: (parallelProduct F~ (𝟙 Cat {o = }))] F) catTranspose =
-- transpose , eq
2018-03-08 10:54:13 +00:00
-- We don't care about filling out the holes below since they are anyways hidden
-- behind an unprovable statement.
module _ ( : Level) (unprovable : IsCategory (RawCat )) where
private
Cat : Category (lsuc ( )) ( )
Cat = Cat unprovable
2018-03-08 10:54:13 +00:00
module _ ( 𝔻 : Category ) where
module CatExp = CatExponential 𝔻
_⊗_ = CatProduct.object
-- Filling the hole causes Agda to loop indefinitely.
eval : Functor (CatExp.object ) 𝔻
eval = {!CatExp.eval!}
isExponential : IsExponential Cat 𝔻 CatExp.object eval
isExponential = {!CatExp.isExponential!}
exponent : Exponential Cat 𝔻
exponent = record
{ obj = CatExp.object
; eval = eval
; isExponential = isExponential
}
2018-02-23 09:44:23 +00:00
hasExponentials : HasExponentials Cat
hasExponentials = record { exponent = exponent }