{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module ALMA.Base.MCorrSetoidCoalg where
open import Agda.Primitive using (Level; lsuc; _⊔_)
open import Agda.Builtin.Sigma using (_,_)
open import Agda.Builtin.Equality using (_≡_; refl)
open import Relation.Binary.PropositionalEquality.Core using (cong; sym; trans)
open import Categories.Category.Core using (Category)
open import ALMA.Base.MCorr using (M)
open import ALMA.Base.MCorrSetoid using
(SysEq; EqOn; _≈Mˢ_; ≈Mˢ-refl; ≈Mˢ-sym; ≈Mˢ-trans; idAdjˢ)
open _≈Mˢ_ public
module _ {i a b ℓa ℓe : Level} (X : SysEq i a b ℓa ℓe) where
open SysEq X
Mˣ : I → Set (i ⊔ a ⊔ b)
Mˣ = M A E
≈ˣ : ∀ {x : I} → Mˣ x → Mˣ x → Set (i ⊔ a ⊔ b ⊔ ℓa ⊔ ℓe)
≈ˣ {x = x} = _≈Mˢ_ ≈A ≈E {x = x}
≈ˣ-refl : ∀ {x : I} (t : Mˣ x) → ≈ˣ t t
≈ˣ-refl = ≈Mˢ-refl ≈A ≈E
≈ˣ-sym : ∀ {x : I} {t s : Mˣ x} → ≈ˣ t s → ≈ˣ s t
≈ˣ-sym = ≈Mˢ-sym ≈A ≈E
≈ˣ-trans : ∀ {x : I} {t m s : Mˣ x} → ≈ˣ t m → ≈ˣ m s → ≈ˣ t s
≈ˣ-trans = ≈Mˢ-trans ≈A ≈E
record Coalgebra (u : Level) (Xst : I → Set u)
: Set (i ⊔ u ⊔ a ⊔ b) where
field
label : (xᵢ : I) → Xst xᵢ → A xᵢ
child : (xᵢ : I) (x : Xst xᵢ) (y : I)
(e : E xᵢ (label xᵢ x) y) → Xst y
open Coalgebra public
ana : ∀ {u : Level} {Xst : I → Set u}
(γ : Coalgebra u Xst)
→ (xᵢ : I) (x : Xst xᵢ) → Mˣ xᵢ
ana γ xᵢ x .M.here = label γ xᵢ x
ana γ xᵢ x .M.below y e = ana γ y (child γ xᵢ x y e)
unfold-coalgebra : Coalgebra (i ⊔ a ⊔ b) Mˣ
unfold-coalgebra .label xᵢ t = M.here t
unfold-coalgebra .child xᵢ t y e = M.below t y e
mutual
ana-unfold : ∀ {xᵢ : I} (t : Mˣ xᵢ)
→ ≈ˣ (ana unfold-coalgebra xᵢ t) t
ana-unfold {xᵢ = xᵢ} t .here-eq = EqOn.refl (≈A xᵢ)
ana-unfold {xᵢ = xᵢ} t .below-eq y =
idAdjˢ (≈E xᵢ (M.here t) y)
, ( (λ e → ana-unfold (M.below t y e))
, (λ e → ana-unfold˘ (M.below t y e)) )
ana-unfold˘ : ∀ {xᵢ : I} (t : Mˣ xᵢ)
→ ≈ˣ t (ana unfold-coalgebra xᵢ t)
ana-unfold˘ {xᵢ = xᵢ} t .here-eq = EqOn.refl (≈A xᵢ)
ana-unfold˘ {xᵢ = xᵢ} t .below-eq y =
idAdjˢ (≈E xᵢ (M.here t) y)
, ( (λ e → ana-unfold˘ (M.below t y e))
, (λ e → ana-unfold (M.below t y e)) )
private
u0 = i ⊔ a ⊔ b
ℓh = i ⊔ a ⊔ b ⊔ ℓa ⊔ ℓe
ℓo = lsuc ℓh
ℓeq = i ⊔ a ⊔ b
record CoalgObj : Set ℓo where
constructor mkCoalg
field
Xst : I → Set u0
γ : Coalgebra u0 Xst
open CoalgObj public
record Coalg⇒ (Y Z : CoalgObj) : Set ℓh where
field
map : ∀ xᵢ → Xst Y xᵢ → Xst Z xᵢ
comm : ∀ xᵢ (x : Xst Y xᵢ)
→ ≈ˣ (ana (γ Z) xᵢ (map xᵢ x)) (ana (γ Y) xᵢ x)
open Coalg⇒ public
idCoalg : ∀ (Y : CoalgObj) → Coalg⇒ Y Y
idCoalg Y .map _ x = x
idCoalg Y .comm xᵢ x = ≈ˣ-refl (ana (γ Y) xᵢ x)
compCoalg : ∀ {Y Z W : CoalgObj}
→ Coalg⇒ Z W → Coalg⇒ Y Z → Coalg⇒ Y W
compCoalg g f .map xᵢ x = map g xᵢ (map f xᵢ x)
compCoalg g f .comm xᵢ x =
≈ˣ-trans (comm g xᵢ (map f xᵢ x)) (comm f xᵢ x)
_≈Coalg_ : ∀ {Y Z : CoalgObj} → Coalg⇒ Y Z → Coalg⇒ Y Z → Set ℓeq
_≈Coalg_ f g = ∀ xᵢ x → map f xᵢ x ≡ map g xᵢ x
CoalgCatˣ : Category ℓo ℓh ℓeq
CoalgCatˣ = record
{ Obj = CoalgObj
; _⇒_ = Coalg⇒
; _≈_ = _≈Coalg_
; id = λ {Y} → idCoalg Y
; _∘_ = λ {Y Z W} g f → compCoalg {Y = Y} {Z = Z} {W = W} g f
; assoc = λ {_ _ _ _} {_ _ _} xᵢ x → refl
; sym-assoc = λ {_ _ _ _} {_ _ _} xᵢ x → refl
; identityˡ = λ {_ _} {f} xᵢ x → refl
; identityʳ = λ {_ _} {f} xᵢ x → refl
; identity² = λ {_} xᵢ x → refl
; equiv = record
{ refl = λ {_} xᵢ x → refl
; sym = λ {_ _} e xᵢ x → sym (e xᵢ x)
; trans = λ {_ _ _} e₁ e₂ xᵢ x → trans (e₁ xᵢ x) (e₂ xᵢ x)
}
; ∘-resp-≈ = λ {_ _ _} {f} {k} {g} {j} f≈ g≈ xᵢ x →
trans (cong (map f xᵢ) (g≈ xᵢ x)) (f≈ xᵢ (map j xᵢ x))
}
terminal-coalgebra : CoalgObj
terminal-coalgebra = mkCoalg Mˣ unfold-coalgebra
! : ∀ (Y : CoalgObj) → Coalg⇒ Y terminal-coalgebra
! Y .map xᵢ x = ana (γ Y) xᵢ x
! Y .comm xᵢ x = ana-unfold (ana (γ Y) xᵢ x)
!-unique : ∀ (Y : CoalgObj)
(f : Coalg⇒ Y terminal-coalgebra)
(xᵢ : I) (x : Xst Y xᵢ)
→ ≈ˣ (map f xᵢ x) (ana (γ Y) xᵢ x)
!-unique Y f xᵢ x =
≈ˣ-trans (ana-unfold˘ (map f xᵢ x)) (comm f xᵢ x)
record IsTerminalUpToBisim : Set ℓo where
field
bang : ∀ (Y : CoalgObj) → Coalg⇒ Y terminal-coalgebra
bang-unique : ∀ (Y : CoalgObj) (f : Coalg⇒ Y terminal-coalgebra)
(xᵢ : I) (x : Xst Y xᵢ)
→ ≈ˣ (map f xᵢ x) (ana (γ Y) xᵢ x)
terminalUpToBisim : IsTerminalUpToBisim
terminalUpToBisim = record
{ bang = !
; bang-unique = !-unique
}
lambek-in∘out : ∀ {xᵢ : I} (t : Mˣ xᵢ)
→ ≈ˣ (ana unfold-coalgebra xᵢ t) t
lambek-in∘out = ana-unfold
lambek-out∘in : ∀ {xᵢ : I} (t : Mˣ xᵢ)
→ ≈ˣ t (ana unfold-coalgebra xᵢ t)
lambek-out∘in = ana-unfold˘