{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module ALMA.Cosmos.ContCatEquiv where
open import Agda.Primitive using (Level; _⊔_)
open import Agda.Builtin.Equality using (refl)
open import Agda.Builtin.Sigma using (_,_)
open import Data.Container.Core using (Container; shape)
open import Data.Container.Morphism using (id; _∘_)
open import Relation.Binary.Bundles using (Setoid)
open import Categories.Category.Core using (Category)
open import Categories.Category.Construction.Functors using (Functors)
open import Categories.Category.Instance.Sets using (Sets)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Category.Construction.Elements using (Elements)
open import Categories.Functor.Core using (Functor)
open import Categories.Functor using (_∘F_)
open import Categories.Functor.Properties using ([_]-resp-≅)
open import Categories.NaturalTransformation.Core using (NaturalTransformation)
open import ALMA.Cosmos.ContCategory using
(_≈sr_; ≈sr-sym; ∘M-assoc; ∘M-identityʳ; ∘M-resp-≈ˡ; ∘M-resp-≈ʳ
; ContCat; module ≈sr-Reasoning)
open import ALMA.Cosmos.ContFunctor using (ContEmbedding; ⟦_⟧)
module _ {o h e s p : Level}
(C : Category o h e)
(containerFunctor : Functor C (ContCat s p)) where
record ContCatEquiv : Set where
private
module C = Category C
open Functor containerFunctor
open import Categories.Category.Construction.Core C using (Core)
CoreC = Core
open import Categories.Morphism (ContCat s p) renaming (_≅_ to ContIso)
open ContIso renaming (from to contFrom)
open import Categories.Morphism C using (_≅_) renaming (module ≅ to C≅)
open _≅_ using (from; to)
open import Categories.Morphism.IsoEquiv C using (_≃_; module _≃_)
Core→C : Functor CoreC C
Core→C = record
{ F₀ = λ X → X
; F₁ = _≅_.from
; identity = C.Equiv.refl
; homomorphism = λ {_ _ _ f g} → C.Equiv.refl
; F-resp-≈ = λ {_ _ f g} f≃g → _≃_.from-≈ f≃g
}
transportFunctor : Functor CoreC (ContCat s p)
transportFunctor = containerFunctor ∘F Core→C
private
module TF = Functor transportFunctor
transpIso : ∀ {A₁ A₂} → A₁ ≅ A₂ → ContIso (F₀ A₁) (F₀ A₂)
transpIso eq = [ containerFunctor ]-resp-≅ eq
transpCont-sym : ∀ {A B} (eq : A ≅ B) →
_≈sr_ {X = F₀ A} {Y = F₀ A}
(TF.F₁ (C≅.sym eq) ∘ TF.F₁ eq) (id (F₀ A))
transpCont-sym eq = ContIso.isoˡ (transpIso eq)
transportMorphism : ∀ {A₁ A₂ B₁ B₂} (eqA : A₁ ≅ A₂) (eqB : B₁ ≅ B₂)
→ (A₁ C.⇒ B₁) → (A₂ C.⇒ B₂)
transportMorphism eqA eqB f = from eqB C.∘ f C.∘ to eqA
module _ where
open ≈sr-Reasoning
act-natural : ∀ {A₁ A₂ B₁ B₂} (eqA : A₁ ≅ A₂) (eqB : B₁ ≅ B₂) (f : A₁ C.⇒ B₁)
→ _≈sr_ {X = F₀ A₁} {Y = F₀ B₂}
(contFrom (transpIso eqB) ∘ F₁ f)
(F₁ (transportMorphism eqA eqB f) ∘ contFrom (transpIso eqA))
act-natural {A₁} {A₂} {B₁} {B₂} eqA eqB f = ≈sr-sym R≈L
where
FtA = contFrom (transpIso eqA)
Ff = F₁ f
FtB = contFrom (transpIso eqB)
Ff∘to = F₁ (f C.∘ to eqA)
R≈L : _≈sr_ {X = F₀ A₁} {Y = F₀ B₂}
(F₁ (transportMorphism eqA eqB f) ∘ FtA) (FtB ∘ Ff)
R≈L = begin
F₁ (transportMorphism eqA eqB f) ∘ FtA
≈⟨ ∘M-resp-≈ˡ {f = FtA} (homomorphism {f = f C.∘ to eqA} {g = from eqB}) ⟩
(FtB ∘ Ff∘to) ∘ FtA
≈⟨ ∘M-assoc {f = FtA} {g = Ff∘to} {h = FtB} ⟩
FtB ∘ (Ff∘to ∘ FtA)
≈⟨ ∘M-resp-≈ʳ {g = FtB}
(∘M-resp-≈ˡ {f = FtA} (homomorphism {f = to eqA} {g = f})) ⟩
FtB ∘ ((Ff ∘ F₁ (to eqA)) ∘ FtA)
≈⟨ ∘M-resp-≈ʳ {g = FtB}
(∘M-assoc {f = FtA} {g = F₁ (to eqA)} {h = Ff}) ⟩
FtB ∘ (Ff ∘ (F₁ (to eqA) ∘ FtA))
≈⟨ ∘M-resp-≈ʳ {g = FtB}
(∘M-resp-≈ʳ {g = Ff} (transpCont-sym eqA)) ⟩
FtB ∘ (Ff ∘ id (F₀ _))
≈⟨ ∘M-resp-≈ʳ {g = FtB} (∘M-identityʳ {f = Ff}) ⟩
FtB ∘ Ff
∎
module ContCatEquivEmbedding {o h e s p} (ℓ′ : Level)
(C : Category o h e)
(F : Functor C (ContCat s p)) where
private
module CF = Functor F
CCE : ContCatEquiv C F
CCE = record {}
Tgt = Functors (Setoids (p ⊔ ℓ′) (p ⊔ ℓ′)) (Setoids (s ⊔ p ⊔ ℓ′) (s ⊔ p ⊔ ℓ′))
module TgtCat = Category Tgt
open TgtCat using (_≈_) renaming (_∘_ to _∙_; id to idF)
open ContCatEquiv CCE using (transportFunctor; transpCont-sym; CoreC)
open import Categories.Morphism C using (_≅_) renaming (module ≅ to C≅)
⟦_⟧′ : Container s p → Functor (Setoids (p ⊔ ℓ′) (p ⊔ ℓ′)) (Setoids (s ⊔ p ⊔ ℓ′) (s ⊔ p ⊔ ℓ′))
⟦_⟧′ = ⟦_⟧ {s = s} {p = p} {ℓ = ℓ′}
ContEmb = ContEmbedding {s = s} {p = p} {ℓ = ℓ′}
open Functor ContEmb
module TF = Functor transportFunctor
liftedTransport : Functor CoreC Tgt
liftedTransport = ContEmb ∘F transportFunctor
transpNat : ∀ {A B} (iso : A ≅ B) → NaturalTransformation ⟦ CF.F₀ A ⟧′ ⟦ CF.F₀ B ⟧′
transpNat = Functor.F₁ liftedTransport
transpNat-refl : ∀ {A} → transpNat (C≅.refl {A}) ≈ idF
transpNat-refl {A} {X} {x = (s , k)} =
Functor.identity liftedTransport {A} {X} {x = (s , k)}
transpNat-sym : ∀ {A B} (eq : A ≅ B) →
transpNat (C≅.sym eq) ∙ transpNat eq ≈ idF
transpNat-sym {A} {B} eq {X} {x} =
let
S = Functor.F₀ ⟦ CF.F₀ A ⟧′ X
h = homomorphism {f = TF.F₁ eq} {g = TF.F₁ (C≅.sym eq)} {X} {x}
r = F-resp-≈ (transpCont-sym eq) {X} {x}
i = identity {A = CF.F₀ A} {X} {x}
in
Setoid.trans S (Setoid.sym S h) (Setoid.trans S r i)
transpNat-trans : ∀ {A B C} (eq1 : A ≅ B) (eq2 : B ≅ C) →
transpNat (C≅.trans eq1 eq2) ≈ (transpNat eq2 ∙ transpNat eq1)
transpNat-trans eq1 eq2 {X} {x} =
Functor.homomorphism liftedTransport {f = eq1} {g = eq2} {X} {x}
module _ {o h e s p} (C : Category o h e) (F : Functor C (ContCat s p)) where
ShapeForget : Functor (ContCat s p) (Sets s)
ShapeForget = record
{ F₀ = λ Ctr → Data.Container.Core.Shape Ctr
; F₁ = λ f → shape f
; identity = λ _ → refl
; homomorphism = λ _ → refl
; F-resp-≈ = λ f≈g x → _≈sr_.shape-eq f≈g x
}
ShapeCat : Category (o ⊔ s) (h ⊔ s) e
ShapeCat = Elements (ShapeForget ∘F F)