{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module ALMA.SecondPass.Cosmos where
open import Agda.Primitive using (Level; _⊔_)
open import Agda.Builtin.Equality using (_≡_; refl)
open import Agda.Builtin.Sigma using (_,_)
open import Relation.Binary.PropositionalEquality.Core using (sym; trans; cong; subst)
open import Relation.Binary.PropositionalEquality.Properties using (setoid)
open import Function.Bundles using (Func)
open import Data.Unit.Polymorphic.Base using (⊤; tt)
open import Data.Product.Base using (proj₁; proj₂)
open import Categories.Category.Core using (Category)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Category.Instance.Sets using (Sets)
open import Categories.Category.Instance.One using (One)
open import Categories.Functor.Core using (Functor)
open import Categories.Functor using (id; _∘F_)
open import ALMA.Cosmos.ContCategory using (≈sr-refl; ContCat)
open import ALMA.Cosmos.ContCategoryLemmas using (ShapeOf; PosOf; actSOf; actPOf)
open import ALMA.Cosmos.ContCatEquiv using (ShapeCat)
open import ALMA.SecondPass.Unfolding using (Unfolding; module UnfoldingSetoid)
open import ALMA.SecondPass.MorphismObject using (MorphismObject; idMorphismObject; compMorphismObject)
open import ALMA.SecondPass.MorphismMorphism
using (MorphismMorphism; idMorphismMorphism; actP-from-S; compMorphismMorphism)
record Cosmos {o h e s p : Level}
(C : Category o h e)
(FC : Functor C (ContCat s p))
: Set (o ⊔ h ⊔ e ⊔ s ⊔ p) where
coinductive
field
out : Unfolding FC (Cosmos C FC)
open Cosmos public
mutual
record _⇒ℱ[_]_ {o h e s p : Level} {C : Category o h e} {FC : Functor C (ContCat s p)}
(F : Cosmos C FC)
(S : Functor (ShapeCat C FC) (ShapeCat C FC))
(G : Cosmos C FC)
: Set (o ⊔ h ⊔ s ⊔ p) where
coinductive
field
out : ⇒ℱLayer[ S ] F G
record ⇒ℱLayer[_] {o h e s p : Level} {C : Category o h e} {FC : Functor C (ContCat s p)}
(S : Functor (ShapeCat C FC) (ShapeCat C FC))
(F G : Cosmos C FC)
: Set (o ⊔ h ⊔ s ⊔ p) where
inductive
private
module C = Category C
module S = Functor S
UF = out F
UG = out G
field
shapeTrans : ∀ {A} {s : ShapeOf FC A}
→ PosOf FC s
→ ShapeOf FC (Functor.₀ (Unfolding.unfoldFunctor UG) (S.₀ (A , s)))
morphismObj : MorphismObject UF UG S shapeTrans
morphismMor : MorphismMorphism UF UG S shapeTrans morphismObj
onunfold-next : ∀ {A} (s : ShapeOf FC A)
→ Unfolding.unfold-next UF s ⇒ℱ[ S ]
Unfolding.unfold-next UG (proj₂ (S.₀ (A , s)))
open _⇒ℱ[_]_ public
open ⇒ℱLayer[_] public
_⇒ℱ_ : ∀ {o h e s p} {C : Category o h e} {FC : Functor C (ContCat s p)}
→ Cosmos C FC → Cosmos C FC → Set (o ⊔ h ⊔ s ⊔ p)
_⇒ℱ_ {C = C} {FC = FC} F G = F ⇒ℱ[ id ] G
id⇒ℱ : ∀ {o h e s p} {C : Category o h e} {FC : Functor C (ContCat s p)}
→ {F : Cosmos C FC} → F ⇒ℱ F
id⇒ℱ {F = F} .out = record
{ shapeTrans = λ p → Unfolding.pos-to-shape UF _ p
; morphismObj = idMorphismObject UF
; morphismMor = idMorphismMorphism UF
; onunfold-next = λ _ → id⇒ℱ
}
where UF = out F
comp⇒ℱ : ∀ {o h e s p} {C : Category o h e} {FC : Functor C (ContCat s p)}
{S₁ S₂ : Functor (ShapeCat C FC) (ShapeCat C FC)}
{F G H : Cosmos C FC}
→ G ⇒ℱ[ S₂ ] H → F ⇒ℱ[ S₁ ] G → F ⇒ℱ[ S₂ ∘F S₁ ] H
comp⇒ℱ {S₁ = S₁} {S₂ = S₂} {F = F} {G = G} {H = H} g f .out = record
{ shapeTrans = λ p → shapeTrans (g .out) (onPos moF p)
; morphismObj = compMorphismObject UF UG UH S₁ S₂ stF stG moF moG
; morphismMor = compMorphismMorphism UF UG UH S₁ S₂ stF stG mmF mmG
; onunfold-next = λ {A} s′ →
let A′ = proj₁ (S₁.₀ (A , s′))
s″ = proj₂ (S₁.₀ (A , s′))
in comp⇒ℱ (onunfold-next (g .out) {A = A′} s″)
(onunfold-next (f .out) s′)
}
where
open MorphismObject
module S₁ = Functor S₁
UF = out F
UG = out G
UH = out H
stF = shapeTrans (f .out)
stG = shapeTrans (g .out)
moF = morphismObj (f .out)
moG = morphismObj (g .out)
mmF = morphismMor (f .out)
mmG = morphismMor (g .out)
_∘⇒ℱ_ : ∀ {o h e s p} {C : Category o h e} {FC : Functor C (ContCat s p)}
{F G H : Cosmos C FC}
→ G ⇒ℱ H → F ⇒ℱ G → F ⇒ℱ H
_∘⇒ℱ_ {C = C} {FC = FC} {F = F} {G = G} {H = H} g f .out = record
{ shapeTrans = λ p → shapeTrans (g .out) (onPos moF p)
; morphismObj = record
{ onPos = λ p → onPos moG (onPos moF p)
; pts-compat = λ p → pts-compat moG (onPos moF p)
}
; morphismMor = record { onActP = coh }
; onunfold-next = λ s → (onunfold-next (g .out) s) ∘⇒ℱ (onunfold-next (f .out) s)
}
where
open MorphismObject
open MorphismMorphism
UF = out F
UG = out G
UH = out H
moF = morphismObj (f .out)
moG = morphismObj (g .out)
mmF = morphismMor (f .out)
mmG = morphismMor (g .out)
coh : ∀ {A B} (f′ : Category._⇒_ C A B) {s : ShapeOf FC A} {t : ShapeOf FC B}
→ (p : actSOf FC f′ s ≡ t) (q : PosOf FC t)
→ onPos moG (onPos moF (actPOf FC f′ s (subst (PosOf FC) (sym p) q)))
≡ actP-from-S FC FC id f′ p (onPos moG (onPos moF q))
coh f′ p q = trans (cong (onPos moG) (onActP mmF f′ p q))
(onActP mmG f′ p (onPos moF q))
UnitCat : ∀ {ℓ} → Category ℓ ℓ ℓ
UnitCat {ℓ} = One
UnitContainerFunctor : ∀ {ℓ} → Functor (UnitCat {ℓ}) (ContCat ℓ ℓ)
UnitContainerFunctor = record
{ F₀ = λ _ → record { Shape = ⊤; Position = λ _ → ⊤ }
; F₁ = λ _ → record { shape = λ _ → tt; position = λ _ → tt }
; identity = ≈sr-refl
; homomorphism = ≈sr-refl
; F-resp-≈ = λ _ → ≈sr-refl
}
UnitCosmos : ∀ {ℓ} → Cosmos (UnitCat {ℓ}) UnitContainerFunctor
UnitCosmos .out = record
{ unfoldFunctor = record
{ F₀ = proj₁
; F₁ = proj₁
; identity = Category.Equiv.refl UnitCat
; homomorphism = Category.Equiv.refl UnitCat
; F-resp-≈ = λ p → p
}
; unfold-next = λ _ → UnitCosmos
; pos-to-shape = λ _ _ → tt
; pos-actS-compat = λ _ _ _ → refl
}
module CosmosFFunctor {o h e s p : Level}
{C : Category o h e}
{FC : Functor C (ContCat s p)} where
private
module US = UnfoldingSetoid
{o = o} {h = h} {e = e} {s = s} {p = p} {C = C} {F = FC}
toStdFunc : {u : Level} {X Y : Set u} → (X → Y) → Func (setoid X) (setoid Y)
toStdFunc f = record { to = f ; cong = cong f }
cosmosFFunctor : (u : Level)
→ Functor (Sets u)
(Setoids (o ⊔ h ⊔ e ⊔ s ⊔ p ⊔ u)
(o ⊔ s ⊔ p ⊔ u))
cosmosFFunctor u = record
{ F₀ = λ X → US.unfoldingSetoid (setoid X)
; F₁ = λ f → US.mapUnfolding-resp (toStdFunc f)
; identity = λ {X} → US.≈U-refl {X = setoid X}
; homomorphism = λ {X Y Z} {f g} → US.≈U-refl {X = setoid Z}
; F-resp-≈ = λ {X Y} {f g} f≈g {c} →
US.mapUnfolding-resp-≈ X Y f g (λ {x} → f≈g x) US.≈U-refl
}