2018-02-02 14:33:54 +00:00
|
|
|
|
{-# OPTIONS --allow-unsolved-metas --cubical #-}
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-01-08 21:48:59 +00:00
|
|
|
|
module Cat.Category where
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
open import Agda.Primitive
|
|
|
|
|
open import Data.Unit.Base
|
2018-01-20 23:21:25 +00:00
|
|
|
|
open import Data.Product renaming
|
|
|
|
|
( proj₁ to fst
|
|
|
|
|
; proj₂ to snd
|
|
|
|
|
; ∃! to ∃!≈
|
|
|
|
|
)
|
2017-11-15 21:56:04 +00:00
|
|
|
|
open import Data.Empty
|
2018-01-30 18:19:16 +00:00
|
|
|
|
import Function
|
2018-02-06 09:34:43 +00:00
|
|
|
|
open import Cubical hiding (isSet)
|
2018-02-05 09:24:57 +00:00
|
|
|
|
open import Cubical.GradLemma using ( propIsEquiv )
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-01-20 23:21:25 +00:00
|
|
|
|
∃! : ∀ {a b} {A : Set a}
|
|
|
|
|
→ (A → Set b) → Set (a ⊔ b)
|
|
|
|
|
∃! = ∃!≈ _≡_
|
|
|
|
|
|
|
|
|
|
∃!-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
|
|
|
|
|
∃!-syntax = ∃
|
|
|
|
|
|
|
|
|
|
syntax ∃!-syntax (λ x → B) = ∃![ x ] B
|
|
|
|
|
|
2018-02-06 09:34:43 +00:00
|
|
|
|
IsSet : {ℓ : Level} (A : Set ℓ) → Set ℓ
|
|
|
|
|
IsSet A = {x y : A} → (p q : x ≡ y) → p ≡ q
|
|
|
|
|
|
2018-02-07 19:19:17 +00:00
|
|
|
|
-- This follows from [HoTT-book: §7.1.10]
|
|
|
|
|
-- Andrea says the proof is in `cubical` but I can't find it.
|
|
|
|
|
postulate isSetIsProp : {ℓ : Level} → {A : Set ℓ} → isProp (IsSet A)
|
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
record RawCategory (ℓ ℓ' : Level) : Set (lsuc (ℓ' ⊔ ℓ)) where
|
|
|
|
|
-- adding no-eta-equality can speed up type-checking.
|
|
|
|
|
-- ONLY IF you define your categories with copatterns though.
|
|
|
|
|
no-eta-equality
|
|
|
|
|
field
|
|
|
|
|
-- Need something like:
|
|
|
|
|
-- Object : Σ (Set ℓ) isGroupoid
|
|
|
|
|
Object : Set ℓ
|
|
|
|
|
-- And:
|
|
|
|
|
-- Arrow : Object → Object → Σ (Set ℓ') isSet
|
|
|
|
|
Arrow : Object → Object → Set ℓ'
|
|
|
|
|
𝟙 : {o : Object} → Arrow o o
|
|
|
|
|
_∘_ : {A B C : Object} → Arrow B C → Arrow A B → Arrow A C
|
|
|
|
|
infixl 10 _∘_
|
|
|
|
|
domain : { a b : Object } → Arrow a b → Object
|
|
|
|
|
domain {a = a} _ = a
|
|
|
|
|
codomain : { a b : Object } → Arrow a b → Object
|
|
|
|
|
codomain {b = b} _ = b
|
|
|
|
|
|
2018-02-02 14:33:54 +00:00
|
|
|
|
-- Thierry: All projections must be `isProp`'s
|
2018-02-01 14:20:20 +00:00
|
|
|
|
|
|
|
|
|
-- According to definitions 9.1.1 and 9.1.6 in the HoTT book the
|
|
|
|
|
-- arrows of a category form a set (arrow-is-set), and there is an
|
|
|
|
|
-- equivalence between the equality of objects and isomorphisms
|
|
|
|
|
-- (univalent).
|
2018-02-05 10:43:38 +00:00
|
|
|
|
record IsCategory {ℓa ℓb : Level} (ℂ : RawCategory ℓa ℓb) : Set (lsuc (ℓa ⊔ ℓb)) where
|
|
|
|
|
open RawCategory ℂ
|
2018-02-07 19:19:17 +00:00
|
|
|
|
module Raw = RawCategory ℂ
|
2018-01-21 13:31:37 +00:00
|
|
|
|
field
|
|
|
|
|
assoc : {A B C D : Object} { f : Arrow A B } { g : Arrow B C } { h : Arrow C D }
|
2018-02-02 14:33:54 +00:00
|
|
|
|
→ h ∘ (g ∘ f) ≡ (h ∘ g) ∘ f
|
2018-01-21 13:31:37 +00:00
|
|
|
|
ident : {A B : Object} {f : Arrow A B}
|
2018-02-02 14:33:54 +00:00
|
|
|
|
→ f ∘ 𝟙 ≡ f × 𝟙 ∘ f ≡ f
|
2018-02-06 09:34:43 +00:00
|
|
|
|
arrowIsSet : ∀ {A B : Object} → IsSet (Arrow A B)
|
2018-02-01 14:20:20 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
Isomorphism : ∀ {A B} → (f : Arrow A B) → Set ℓb
|
2018-02-02 14:33:54 +00:00
|
|
|
|
Isomorphism {A} {B} f = Σ[ g ∈ Arrow B A ] g ∘ f ≡ 𝟙 × f ∘ g ≡ 𝟙
|
2018-02-01 14:20:20 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
_≅_ : (A B : Object) → Set ℓb
|
2018-02-01 14:20:20 +00:00
|
|
|
|
_≅_ A B = Σ[ f ∈ Arrow A B ] (Isomorphism f)
|
|
|
|
|
|
|
|
|
|
idIso : (A : Object) → A ≅ A
|
|
|
|
|
idIso A = 𝟙 , (𝟙 , ident)
|
|
|
|
|
|
|
|
|
|
id-to-iso : (A B : Object) → A ≡ B → A ≅ B
|
|
|
|
|
id-to-iso A B eq = transp (\ i → A ≅ eq i) (idIso A)
|
|
|
|
|
|
|
|
|
|
-- TODO: might want to implement isEquiv differently, there are 3
|
|
|
|
|
-- equivalent formulations in the book.
|
2018-02-05 15:35:33 +00:00
|
|
|
|
Univalent : Set (ℓa ⊔ ℓb)
|
|
|
|
|
Univalent = {A B : Object} → isEquiv (A ≡ B) (A ≅ B) (id-to-iso A B)
|
2018-02-01 14:20:20 +00:00
|
|
|
|
field
|
2018-02-05 15:35:33 +00:00
|
|
|
|
univalent : Univalent
|
2018-02-01 14:20:20 +00:00
|
|
|
|
|
2018-02-02 14:33:54 +00:00
|
|
|
|
module _ {A B : Object} where
|
2018-02-05 10:43:38 +00:00
|
|
|
|
Epimorphism : {X : Object } → (f : Arrow A B) → Set ℓb
|
2018-02-02 14:33:54 +00:00
|
|
|
|
Epimorphism {X} f = ( g₀ g₁ : Arrow B X ) → g₀ ∘ f ≡ g₁ ∘ f → g₀ ≡ g₁
|
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
Monomorphism : {X : Object} → (f : Arrow A B) → Set ℓb
|
2018-02-02 14:33:54 +00:00
|
|
|
|
Monomorphism {X} f = ( g₀ g₁ : Arrow X A ) → f ∘ g₀ ≡ f ∘ g₁ → g₀ ≡ g₁
|
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
module _ {ℓa} {ℓb} {ℂ : RawCategory ℓa ℓb} where
|
2018-02-05 09:24:57 +00:00
|
|
|
|
-- TODO, provable by using arrow-is-set and that isProp (isEquiv _ _ _)
|
2018-02-01 14:20:20 +00:00
|
|
|
|
-- This lemma will be useful to prove the equality of two categories.
|
2018-02-05 10:43:38 +00:00
|
|
|
|
IsCategory-is-prop : isProp (IsCategory ℂ)
|
2018-02-05 09:24:57 +00:00
|
|
|
|
IsCategory-is-prop x y i = record
|
2018-02-07 19:19:17 +00:00
|
|
|
|
-- Why choose `x`'s `arrowIsSet`?
|
2018-02-06 09:34:43 +00:00
|
|
|
|
{ assoc = x.arrowIsSet x.assoc y.assoc i
|
2018-02-05 09:24:57 +00:00
|
|
|
|
; ident =
|
2018-02-06 09:34:43 +00:00
|
|
|
|
( x.arrowIsSet (fst x.ident) (fst y.ident) i
|
|
|
|
|
, x.arrowIsSet (snd x.ident) (snd y.ident) i
|
2018-02-05 09:24:57 +00:00
|
|
|
|
)
|
2018-02-07 19:19:17 +00:00
|
|
|
|
; arrowIsSet = isSetIsProp x.arrowIsSet y.arrowIsSet i
|
|
|
|
|
; univalent = {!!}
|
2018-02-05 09:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
module x = IsCategory x
|
|
|
|
|
module y = IsCategory y
|
2018-02-07 19:19:17 +00:00
|
|
|
|
xuni : x.Univalent
|
|
|
|
|
xuni = x.univalent
|
|
|
|
|
yuni : y.Univalent
|
|
|
|
|
yuni = y.univalent
|
|
|
|
|
open RawCategory ℂ
|
|
|
|
|
T : I → Set (ℓa ⊔ ℓb)
|
|
|
|
|
T i = {A B : Object} →
|
|
|
|
|
isEquiv (A ≡ B) (A x.≅ B)
|
|
|
|
|
(λ A≡B →
|
|
|
|
|
transp
|
|
|
|
|
(λ j →
|
|
|
|
|
Σ-syntax (Arrow A (A≡B j))
|
|
|
|
|
(λ f → Σ-syntax (Arrow (A≡B j) A) (λ g → g ∘ f ≡ 𝟙 × f ∘ g ≡ 𝟙)))
|
|
|
|
|
( 𝟙
|
|
|
|
|
, 𝟙
|
|
|
|
|
, x.arrowIsSet (fst x.ident) (fst y.ident) i
|
|
|
|
|
, x.arrowIsSet (snd x.ident) (snd y.ident) i
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
eqUni : T [ xuni ≡ yuni ]
|
|
|
|
|
eqUni = {!!}
|
|
|
|
|
|
2018-01-21 13:31:37 +00:00
|
|
|
|
|
2018-02-05 13:47:15 +00:00
|
|
|
|
record Category (ℓa ℓb : Level) : Set (lsuc (ℓa ⊔ ℓb)) where
|
|
|
|
|
field
|
|
|
|
|
raw : RawCategory ℓa ℓb
|
|
|
|
|
{{isCategory}} : IsCategory raw
|
2018-02-05 10:43:38 +00:00
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
private
|
|
|
|
|
module ℂ = RawCategory raw
|
|
|
|
|
|
|
|
|
|
Object : Set ℓa
|
|
|
|
|
Object = ℂ.Object
|
|
|
|
|
|
|
|
|
|
Arrow = ℂ.Arrow
|
|
|
|
|
|
|
|
|
|
𝟙 = ℂ.𝟙
|
|
|
|
|
|
|
|
|
|
_∘_ = ℂ._∘_
|
2018-02-05 10:43:38 +00:00
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
_[_,_] : (A : Object) → (B : Object) → Set ℓb
|
|
|
|
|
_[_,_] = ℂ.Arrow
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
_[_∘_] : {A B C : Object} → (g : ℂ.Arrow B C) → (f : ℂ.Arrow A B) → ℂ.Arrow A C
|
|
|
|
|
_[_∘_] = ℂ._∘_
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-01-30 17:26:11 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
module _ {ℓa ℓb : Level} (ℂ : Category ℓa ℓb) where
|
|
|
|
|
private
|
|
|
|
|
open Category ℂ
|
2018-02-05 13:47:15 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
OpRaw : RawCategory ℓa ℓb
|
2018-02-05 13:47:15 +00:00
|
|
|
|
RawCategory.Object OpRaw = Object
|
|
|
|
|
RawCategory.Arrow OpRaw = Function.flip Arrow
|
|
|
|
|
RawCategory.𝟙 OpRaw = 𝟙
|
|
|
|
|
RawCategory._∘_ OpRaw = Function.flip _∘_
|
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
open IsCategory isCategory
|
2018-02-05 13:47:15 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
OpIsCategory : IsCategory OpRaw
|
2018-02-05 13:47:15 +00:00
|
|
|
|
IsCategory.assoc OpIsCategory = sym assoc
|
|
|
|
|
IsCategory.ident OpIsCategory = swap ident
|
2018-02-06 09:34:43 +00:00
|
|
|
|
IsCategory.arrowIsSet OpIsCategory = arrowIsSet
|
2018-02-05 13:47:15 +00:00
|
|
|
|
IsCategory.univalent OpIsCategory = {!!}
|
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
Opposite : Category ℓa ℓb
|
2018-02-05 13:47:15 +00:00
|
|
|
|
raw Opposite = OpRaw
|
|
|
|
|
Category.isCategory Opposite = OpIsCategory
|
|
|
|
|
|
|
|
|
|
-- As demonstrated here a side-effect of having no-eta-equality on constructors
|
|
|
|
|
-- means that we need to pick things apart to show that things are indeed
|
|
|
|
|
-- definitionally equal. I.e; a thing that would normally be provable in one
|
|
|
|
|
-- line now takes more than 20!!
|
|
|
|
|
module _ {ℓa ℓb : Level} {ℂ : Category ℓa ℓb} where
|
|
|
|
|
private
|
|
|
|
|
open RawCategory
|
|
|
|
|
module C = Category ℂ
|
|
|
|
|
rawOp : Category.raw (Opposite (Opposite ℂ)) ≡ Category.raw ℂ
|
|
|
|
|
Object (rawOp _) = C.Object
|
|
|
|
|
Arrow (rawOp _) = C.Arrow
|
|
|
|
|
𝟙 (rawOp _) = C.𝟙
|
|
|
|
|
_∘_ (rawOp _) = C._∘_
|
|
|
|
|
open Category
|
|
|
|
|
open IsCategory
|
|
|
|
|
module IsCat = IsCategory (ℂ .isCategory)
|
|
|
|
|
rawIsCat : (i : I) → IsCategory (rawOp i)
|
|
|
|
|
assoc (rawIsCat i) = IsCat.assoc
|
|
|
|
|
ident (rawIsCat i) = IsCat.ident
|
2018-02-06 09:34:43 +00:00
|
|
|
|
arrowIsSet (rawIsCat i) = IsCat.arrowIsSet
|
2018-02-05 13:47:15 +00:00
|
|
|
|
univalent (rawIsCat i) = IsCat.univalent
|
|
|
|
|
|
|
|
|
|
Opposite-is-involution : Opposite (Opposite ℂ) ≡ ℂ
|
|
|
|
|
raw (Opposite-is-involution i) = rawOp i
|
|
|
|
|
isCategory (Opposite-is-involution i) = rawIsCat i
|
2018-01-20 23:21:25 +00:00
|
|
|
|
|
2018-02-02 13:47:33 +00:00
|
|
|
|
module _ {ℓa ℓb : Level} (ℂ : Category ℓa ℓb) where
|
2018-02-05 13:47:15 +00:00
|
|
|
|
open Category
|
2018-02-02 13:47:33 +00:00
|
|
|
|
unique = isContr
|
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
IsInitial : Object ℂ → Set (ℓa ⊔ ℓb)
|
|
|
|
|
IsInitial I = {X : Object ℂ} → unique (ℂ [ I , X ])
|
2018-02-02 13:47:33 +00:00
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
IsTerminal : Object ℂ → Set (ℓa ⊔ ℓb)
|
2018-02-02 13:47:33 +00:00
|
|
|
|
-- ∃![ ? ] ?
|
2018-02-05 11:21:39 +00:00
|
|
|
|
IsTerminal T = {X : Object ℂ} → unique (ℂ [ X , T ])
|
2018-02-02 13:47:33 +00:00
|
|
|
|
|
|
|
|
|
Initial : Set (ℓa ⊔ ℓb)
|
2018-02-05 11:21:39 +00:00
|
|
|
|
Initial = Σ (Object ℂ) IsInitial
|
2018-02-02 13:47:33 +00:00
|
|
|
|
|
|
|
|
|
Terminal : Set (ℓa ⊔ ℓb)
|
2018-02-05 11:21:39 +00:00
|
|
|
|
Terminal = Σ (Object ℂ) IsTerminal
|