Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discrete categories #638

Merged
merged 4 commits into from
Nov 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Cubical/Categories/Instances/Discrete.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Discrete category over a type A
-- A must be an h-groupoid for the homs to be sets
{-# OPTIONS --safe #-}

module Cubical.Categories.Instances.Discrete where

open import Cubical.Categories.Category.Base
open import Cubical.Categories.Functor.Base
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Transport

private
variable
ℓ ℓC ℓC' : Level

open Category

-- Discrete category
DiscreteCategory : hGroupoid ℓ → Category ℓ ℓ
DiscreteCategory A .ob = A .fst
DiscreteCategory A .Hom[_,_] a a' = a ≡ a'
DiscreteCategory A .id = refl
DiscreteCategory A ._⋆_ = _∙_
DiscreteCategory A .⋆IdL f = sym (lUnit f)
DiscreteCategory A .⋆IdR f = sym (rUnit f)
DiscreteCategory A .⋆Assoc f g h = sym (assoc f g h)
DiscreteCategory A .isSetHom {x} {y} = A .snd x y


module _ {A : hGroupoid ℓ}
{C : Category ℓC ℓC'} where
open Functor

-- Functions f: A → ob C give functors F: DiscreteCategory A → C
DiscFunc : (fst A → ob C) → Functor (DiscreteCategory A) C
DiscFunc f .F-ob = f
DiscFunc f .F-hom {x} p = subst (λ z → C [ f x , f z ]) p (id C)
DiscFunc f .F-id {x} = substRefl {B = λ z → C [ f x , f z ]} (id C)

-- Preserves composition
DiscFunc f .F-seq {x} {y} p q =
let open Category C using () renaming (_⋆_ to _●_) in

let Hom[fx,f—] = (λ (w : A .fst) → C [ f x , f w ]) in
let Hom[fy,f—] = (λ (w : A .fst) → C [ f y , f w ]) in
let id-fx = id C {f x} in
let id-fy = id C {f y} in
let Fp = (subst Hom[fx,f—] (p) id-fx) in

subst Hom[fx,f—] (p ∙ q) id-fx ≡⟨ substComposite Hom[fx,f—] _ _ _ ⟩
subst Hom[fx,f—] (q) (Fp) ≡⟨ cong (subst _ q) (sym (⋆IdR C _)) ⟩
subst Hom[fx,f—] (q) (Fp ● id-fy) ≡⟨ substCommSlice _ _ (λ _ → Fp ●_) q _ ⟩
Fp ● (subst Hom[fy,f—] (q) id-fy) ∎