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-09 11:09:59 +00:00
|
|
|
|
open import Cubical
|
2018-02-16 10:36:44 +00:00
|
|
|
|
open import Cubical.NType.Properties using ( propIsEquiv )
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-02-19 10:25:16 +00:00
|
|
|
|
open import Cat.Wishlist
|
|
|
|
|
|
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-20 15:22:38 +00:00
|
|
|
|
record RawCategory (ℓa ℓb : Level) : Set (lsuc (ℓa ⊔ ℓb)) where
|
2018-02-05 10:43:38 +00:00
|
|
|
|
no-eta-equality
|
|
|
|
|
field
|
2018-02-20 15:22:38 +00:00
|
|
|
|
Object : Set ℓa
|
|
|
|
|
Arrow : Object → Object → Set ℓb
|
|
|
|
|
𝟙 : {A : Object} → Arrow A A
|
2018-02-05 10:43:38 +00:00
|
|
|
|
_∘_ : {A B C : Object} → Arrow B C → Arrow A B → Arrow A C
|
2018-02-20 15:22:38 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
infixl 10 _∘_
|
2018-02-20 15:22:38 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
domain : { a b : Object } → Arrow a b → Object
|
|
|
|
|
domain {a = a} _ = a
|
2018-02-20 15:22:38 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
codomain : { a b : Object } → Arrow a b → Object
|
|
|
|
|
codomain {b = b} _ = b
|
|
|
|
|
|
2018-02-20 15:22:38 +00:00
|
|
|
|
IsAssociative : Set (ℓa ⊔ ℓb)
|
|
|
|
|
IsAssociative = ∀ {A B C D} {f : Arrow A B} {g : Arrow B C} {h : Arrow C D}
|
|
|
|
|
→ h ∘ (g ∘ f) ≡ (h ∘ g) ∘ f
|
|
|
|
|
|
|
|
|
|
IsIdentity : ({A : Object} → Arrow A A) → Set (ℓa ⊔ ℓb)
|
|
|
|
|
IsIdentity id = {A B : Object} {f : Arrow A B}
|
|
|
|
|
→ f ∘ id ≡ f × id ∘ f ≡ f
|
|
|
|
|
|
|
|
|
|
IsInverseOf : ∀ {A B} → (Arrow A B) → (Arrow B A) → Set ℓb
|
|
|
|
|
IsInverseOf = λ f g → g ∘ f ≡ 𝟙 × f ∘ g ≡ 𝟙
|
|
|
|
|
|
|
|
|
|
Isomorphism : ∀ {A B} → (f : Arrow A B) → Set ℓb
|
|
|
|
|
Isomorphism {A} {B} f = Σ[ g ∈ Arrow B A ] IsInverseOf f g
|
|
|
|
|
|
|
|
|
|
_≅_ : (A B : Object) → Set ℓb
|
|
|
|
|
_≅_ A B = Σ[ f ∈ Arrow A B ] (Isomorphism f)
|
|
|
|
|
|
|
|
|
|
module _ {A B : Object} where
|
|
|
|
|
Epimorphism : {X : Object } → (f : Arrow A B) → Set ℓb
|
|
|
|
|
Epimorphism {X} f = ( g₀ g₁ : Arrow B X ) → g₀ ∘ f ≡ g₁ ∘ f → g₀ ≡ g₁
|
|
|
|
|
|
|
|
|
|
Monomorphism : {X : Object} → (f : Arrow A B) → Set ℓb
|
|
|
|
|
Monomorphism {X} f = ( g₀ g₁ : Arrow X A ) → f ∘ g₀ ≡ f ∘ g₁ → g₀ ≡ g₁
|
|
|
|
|
|
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
|
2018-02-19 14:46:19 +00:00
|
|
|
|
assoc : IsAssociative
|
|
|
|
|
ident : IsIdentity 𝟙
|
2018-02-09 11:09:59 +00:00
|
|
|
|
arrowIsSet : ∀ {A B : Object} → isSet (Arrow A B)
|
2018-02-01 14:20:20 +00:00
|
|
|
|
|
2018-02-19 14:46:19 +00:00
|
|
|
|
propIsAssociative : isProp IsAssociative
|
|
|
|
|
propIsAssociative x y i = arrowIsSet _ _ x y i
|
|
|
|
|
|
|
|
|
|
propIsIdentity : ∀ {f : ∀ {A} → Arrow A A} → isProp (IsIdentity f)
|
|
|
|
|
propIsIdentity a b i
|
|
|
|
|
= arrowIsSet _ _ (fst a) (fst b) i
|
|
|
|
|
, arrowIsSet _ _ (snd a) (snd b) i
|
|
|
|
|
|
|
|
|
|
propArrowIsSet : isProp (∀ {A B} → isSet (Arrow A B))
|
|
|
|
|
propArrowIsSet a b i = isSetIsProp a b i
|
|
|
|
|
|
|
|
|
|
propIsInverseOf : ∀ {A B f g} → isProp (IsInverseOf {A} {B} f g)
|
|
|
|
|
propIsInverseOf x y = λ i →
|
|
|
|
|
let
|
|
|
|
|
h : fst x ≡ fst y
|
|
|
|
|
h = arrowIsSet _ _ (fst x) (fst y)
|
|
|
|
|
hh : snd x ≡ snd y
|
|
|
|
|
hh = arrowIsSet _ _ (snd x) (snd y)
|
|
|
|
|
in h i , hh i
|
|
|
|
|
|
2018-02-01 14:20:20 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2018-02-20 13:08:47 +00:00
|
|
|
|
-- TODO: might want to implement isEquiv
|
|
|
|
|
-- differently, there are 3
|
2018-02-01 14:20:20 +00:00
|
|
|
|
-- 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-19 14:46:19 +00:00
|
|
|
|
module _ {A B : Object} {f : Arrow A B} where
|
|
|
|
|
isoIsProp : isProp (Isomorphism f)
|
|
|
|
|
isoIsProp a@(g , η , ε) a'@(g' , η' , ε') =
|
|
|
|
|
lemSig (λ g → propIsInverseOf) a a' geq
|
|
|
|
|
where
|
|
|
|
|
open Cubical.NType.Properties
|
|
|
|
|
geq : g ≡ g'
|
|
|
|
|
geq = begin
|
|
|
|
|
g ≡⟨ sym (fst ident) ⟩
|
|
|
|
|
g ∘ 𝟙 ≡⟨ cong (λ φ → g ∘ φ) (sym ε') ⟩
|
|
|
|
|
g ∘ (f ∘ g') ≡⟨ assoc ⟩
|
|
|
|
|
(g ∘ f) ∘ g' ≡⟨ cong (λ φ → φ ∘ g') η ⟩
|
|
|
|
|
𝟙 ∘ g' ≡⟨ snd ident ⟩
|
|
|
|
|
g' ∎
|
|
|
|
|
|
|
|
|
|
module _ {ℓa ℓb : Level} {C : RawCategory ℓa ℓb} {ℂ : IsCategory C} where
|
|
|
|
|
open IsCategory ℂ
|
|
|
|
|
open import Cubical.NType
|
|
|
|
|
open import Cubical.NType.Properties
|
|
|
|
|
|
|
|
|
|
propUnivalent : isProp Univalent
|
|
|
|
|
propUnivalent a b i = propPi (λ iso → propHasLevel ⟨-2⟩) a b i
|
|
|
|
|
|
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-19 14:46:19 +00:00
|
|
|
|
-- Why choose `x`'s `propIsAssociative`?
|
|
|
|
|
-- Well, probably it could be pulled out of the record.
|
|
|
|
|
{ assoc = x.propIsAssociative x.assoc y.assoc i
|
2018-02-20 13:08:47 +00:00
|
|
|
|
; ident = ident' i
|
2018-02-19 14:46:19 +00:00
|
|
|
|
; arrowIsSet = x.propArrowIsSet x.arrowIsSet y.arrowIsSet i
|
|
|
|
|
; univalent = eqUni i
|
2018-02-05 09:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
module x = IsCategory x
|
|
|
|
|
module y = IsCategory y
|
2018-02-20 13:08:47 +00:00
|
|
|
|
ident' = x.propIsIdentity x.ident y.ident
|
|
|
|
|
ident'' = ident' i
|
2018-02-07 19:19:17 +00:00
|
|
|
|
xuni : x.Univalent
|
|
|
|
|
xuni = x.univalent
|
|
|
|
|
yuni : y.Univalent
|
|
|
|
|
yuni = y.univalent
|
|
|
|
|
open RawCategory ℂ
|
2018-02-20 13:08:47 +00:00
|
|
|
|
Pp : (x.ident ≡ y.ident) → I → Set (ℓa ⊔ ℓb)
|
|
|
|
|
Pp eqIdent i = {A B : Object} →
|
2018-02-20 15:22:38 +00:00
|
|
|
|
isEquiv (A ≡ B) (A ≅ B)
|
2018-02-07 19:19:17 +00:00
|
|
|
|
(λ A≡B →
|
|
|
|
|
transp
|
|
|
|
|
(λ j →
|
|
|
|
|
Σ-syntax (Arrow A (A≡B j))
|
|
|
|
|
(λ f → Σ-syntax (Arrow (A≡B j) A) (λ g → g ∘ f ≡ 𝟙 × f ∘ g ≡ 𝟙)))
|
|
|
|
|
( 𝟙
|
|
|
|
|
, 𝟙
|
2018-02-20 13:08:47 +00:00
|
|
|
|
, ident' i
|
2018-02-07 19:19:17 +00:00
|
|
|
|
)
|
|
|
|
|
)
|
2018-02-20 13:08:47 +00:00
|
|
|
|
T : I → Set (ℓa ⊔ ℓb)
|
|
|
|
|
T = Pp {!ident'!}
|
2018-02-19 14:46:19 +00:00
|
|
|
|
open Cubical.NType.Properties
|
|
|
|
|
test : (λ _ → x.Univalent) [ xuni ≡ xuni ]
|
|
|
|
|
test = refl
|
|
|
|
|
t = {!!}
|
|
|
|
|
P : (uni : x.Univalent) → xuni ≡ uni → Set (ℓa ⊔ ℓb)
|
|
|
|
|
P = {!!}
|
2018-02-20 13:08:47 +00:00
|
|
|
|
-- T i0 ≡ x.Univalent
|
|
|
|
|
-- T i1 ≡ y.Univalent
|
2018-02-07 19:19:17 +00:00
|
|
|
|
eqUni : T [ xuni ≡ yuni ]
|
2018-02-20 13:08:47 +00:00
|
|
|
|
eqUni = {!!}
|
2018-02-07 19:19:17 +00:00
|
|
|
|
|
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-20 15:22:38 +00:00
|
|
|
|
-- What happens if we just open this up to the public?
|
2018-02-05 11:21:39 +00:00
|
|
|
|
private
|
|
|
|
|
module ℂ = RawCategory raw
|
|
|
|
|
|
2018-02-20 15:22:38 +00:00
|
|
|
|
open RawCategory raw public using ( Isomorphism ; Epimorphism ; Monomorphism )
|
|
|
|
|
|
2018-02-05 11:21:39 +00:00
|
|
|
|
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
|