From 9fe4aadad5a046aaf44a789bfddefc10a0afaeef Mon Sep 17 00:00:00 2001 From: Jacques Comeaux Date: Fri, 14 Nov 2025 12:53:49 -0600 Subject: Generalize ListOf construction to arbitrary monoid --- Functor/Monoidal/Construction/FamilyOfMonoids.agda | 214 +++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 Functor/Monoidal/Construction/FamilyOfMonoids.agda (limited to 'Functor/Monoidal/Construction/FamilyOfMonoids.agda') diff --git a/Functor/Monoidal/Construction/FamilyOfMonoids.agda b/Functor/Monoidal/Construction/FamilyOfMonoids.agda new file mode 100644 index 0000000..377342a --- /dev/null +++ b/Functor/Monoidal/Construction/FamilyOfMonoids.agda @@ -0,0 +1,214 @@ +{-# OPTIONS --without-K --safe #-} + +open import Categories.Category using (Category) +open import Categories.Category.Cocartesian using (Cocartesian) +open import Categories.Category.Cocartesian.Bundle using (CocartesianCategory) +open import Categories.Category.Construction.Monoids using (Monoids) +open import Categories.Category.Monoidal.Bundle using (MonoidalCategory) +open import Categories.Functor using (Functor) renaming (_∘F_ to _βˆ™_) +open import Level using (Level; _βŠ”_) + +-- A functor from a cocartesian category π’ž to Monoids[S] +-- can be turned into a monoidal functor from π’ž to S + +module Functor.Monoidal.Construction.FamilyOfMonoids + {o oβ€² β„“ β„“β€² e eβ€² : Level} + {π’ž : Category o β„“ e} + (π’ž-+ : Cocartesian π’ž) + {S : MonoidalCategory oβ€² β„“β€² eβ€²} + (let module S = MonoidalCategory S) + (M : Functor π’ž (Monoids S.monoidal)) + where + +import Categories.Category.Monoidal.Reasoning as βŠ—-Reasoning +import Categories.Category.Monoidal.Utilities as βŠ—-Util +import Categories.Morphism.Reasoning as β‡’-Reasoning +import Categories.Object.Monoid as MonoidObject + +open import Categories.Category using (module Definitions) +open import Categories.Category.Cocartesian using (module CocartesianMonoidal) +open import Categories.Category.Product using (_⁂_) +open import Categories.Functor.Monoidal using (MonoidalFunctor; IsMonoidalFunctor) +open import Categories.Functor.Properties using ([_]-resp-square; [_]-resp-∘) +open import Categories.Morphism using (_β‰…_) +open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) +open import Data.Product using (_,_) +open import Functor.Forgetful.Instance.Monoid S using (Forget) + +private + + G : Functor π’ž S.U + G = Forget βˆ™ M + + module π’ž = CocartesianCategory (record { cocartesian = π’ž-+ }) + module π’ž-M = CocartesianMonoidal π’ž π’ž-+ + + π’ž-MC : MonoidalCategory o β„“ e + π’ž-MC = record { monoidal = π’ž-M.+-monoidal } + + module +-assoc {n} {m} {o} = _β‰…_ (π’ž.+-assoc {n} {m} {o}) + module +-Ξ» {n} = _β‰…_ (π’ž-M.βŠ₯+Aβ‰…A {n}) + module +-ρ {n} = _β‰…_ (π’ž-M.A+βŠ₯β‰…A {n}) + + module G = Functor G + module M = Functor M + + open MonoidObject S.monoidal using (Monoid; Monoidβ‡’) + open Monoid renaming (assoc to ΞΌ-assoc; identityΛ‘ toΒ ΞΌ-identityΛ‘; identityΚ³ to ΞΌ-identityΚ³) + open Monoidβ‡’ + + open π’ž using (-+-; _+_; _+₁_; i₁; iβ‚‚; inject₁; injectβ‚‚) + + module _ where + + open Category π’ž + open β‡’-Reasoning π’ž + open βŠ—-Reasoning π’ž-M.+-monoidal + + module _ {n m o : Obj} where + + private + + +-Ξ± : (n + m) + o π’ž.β‡’ n + (m + o) + +-Ξ± = +-assoc.to {n} {m} {o} + + +-α∘iβ‚‚ : +-Ξ± ∘ iβ‚‚ β‰ˆ iβ‚‚ ∘ iβ‚‚ + +-α∘iβ‚‚ = injectβ‚‚ + + +-α∘iβ‚βˆ˜i₁ : (+-Ξ± ∘ i₁) ∘ i₁ β‰ˆ i₁ + +-α∘iβ‚βˆ˜i₁ = inject₁ ⟩∘⟨refl β—‹ inject₁ + + +-α∘iβ‚βˆ˜iβ‚‚ : (+-Ξ± ∘ i₁) ∘ iβ‚‚ β‰ˆ iβ‚‚ ∘ i₁ + +-α∘iβ‚βˆ˜iβ‚‚ = inject₁ ⟩∘⟨refl β—‹ injectβ‚‚ + + module _ {n : Obj} where + + +-ρ∘i₁ : +-ρ.from {n} ∘ i₁ β‰ˆ id + +-ρ∘i₁ = inject₁ + + +-λ∘iβ‚‚ : +-Ξ».from {n} ∘ iβ‚‚ β‰ˆ id + +-λ∘iβ‚‚ = injectβ‚‚ + + open S + open β‡’-Reasoning U + open βŠ—-Reasoning monoidal + open βŠ—-Util.Shorthands monoidal + + ⊲ : {A : π’ž.Obj} β†’ G.β‚€ A βŠ—β‚€ G.β‚€ A β‡’ G.β‚€ A + ⊲ {A} = ΞΌ (M.β‚€ A) + + β‡’βŠ² : {A B : π’ž.Obj} (f : A π’ž.β‡’ B) β†’ G.₁ f ∘ ⊲ β‰ˆ ⊲ ∘ G.₁ f βŠ—β‚ G.₁ f + β‡’βŠ² f = preserves-ΞΌ (M.₁ f) + + Ξ΅ : {A : π’ž.Obj} β†’ unit β‡’ G.β‚€ A + Ξ΅ {A} = Ξ· (M.β‚€ A) + + β‡’Ξ΅ : {A B : π’ž.Obj} (f : A π’ž.β‡’ B) β†’ G.₁ f ∘ Ξ΅ β‰ˆ Ξ΅ + β‡’Ξ΅ f = preserves-Ξ· (M.₁ f) + + ⊲-βŠ— : {n m : π’ž.Obj} β†’ G.β‚€ n βŠ—β‚€ G.β‚€ m β‡’ G.β‚€ (n + m) + ⊲-βŠ— = ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚ + + module _ {n nβ€² m mβ€² : π’ž.Obj} (f : n π’ž.β‡’ nβ€²) (g : m π’ž.β‡’ mβ€²) where + + open Definitions S.U using (CommutativeSquare) + + left₁ : CommutativeSquare (G.₁ i₁) (G.₁ f) (G.₁ (f +₁ g)) (G.₁ i₁) + left₁ = [ G ]-resp-square inject₁ + + leftβ‚‚ : CommutativeSquare (G.₁ iβ‚‚) (G.₁ g) (G.₁ (f +₁ g)) (G.₁ iβ‚‚) + leftβ‚‚ = [ G ]-resp-square injectβ‚‚ + + right : CommutativeSquare ⊲ (G.₁ (f +₁ g) βŠ—β‚ G.₁ (f +₁ g)) (G.₁ (f +₁ g)) ⊲ + right = β‡’βŠ² (f +₁ g) + + ⊲-βŠ—-commute : + CommutativeSquare + (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) + (G.₁ f βŠ—β‚ G.₁ g) + (G.₁ (f +₁ g)) + (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) + ⊲-βŠ—-commute = glueβ€² right (parallel left₁ leftβ‚‚) + + ⊲-βŠ—-homo : NaturalTransformation (βŠ— βˆ™ (G ⁂ G)) (G βˆ™Β -+-) + ⊲-βŠ—-homo = ntHelper record + { Ξ· = Ξ» (n , m) β†’ ⊲-βŠ— {n} {m} + ; commute = Ξ» (f , g) β†’ Equiv.sym (⊲-βŠ—-commute f g) + } + + ⊲-βŠ—-Ξ± + : {n m o : π’ž.Obj} + β†’ G.₁ (+-assoc.to {n} {m} {o}) + ∘ (ΞΌ (M.β‚€ ((n + m) + o)) ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) + ∘ (ΞΌ (M.β‚€ (n + m)) ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ id + β‰ˆ (ΞΌ (M.β‚€ (n + m + o)) ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) + ∘ id βŠ—β‚ (ΞΌ (M.β‚€ (m + o)) ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) + ∘ Ξ±β‡’ + ⊲-βŠ—-Ξ± {n} {m} {o} = begin + G.₁ +-Ξ± ∘ (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ id β‰ˆβŸ¨ refl⟩∘⟨ pullΚ³ merge₁ʳ ⟩ + G.₁ +-Ξ± ∘ ⊲ ∘ (G.₁ i₁ ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ G.₁ iβ‚‚ β‰ˆβŸ¨ extendΚ³ (β‡’βŠ² +-Ξ±) ⟩ + ⊲ ∘ G.₁ +-Ξ± βŠ—β‚ G.₁ +-Ξ± ∘ (G.₁ i₁ ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ G.₁ iβ‚‚ β‰ˆβŸ¨ refl⟩∘⟨ βŠ—-distrib-over-∘ ⟨ + ⊲ ∘ (G.₁ +-Ξ± ∘ G.₁ i₁ ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ (G.₁ +-Ξ± ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ pullΛ‘ (Equiv.sym G.homomorphism) βŸ©βŠ—βŸ¨ [ G ]-resp-square +-α∘iβ‚‚ ⟩ + ⊲ ∘ (G.₁ (+-Ξ± π’ž.∘ i₁) ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ extendΚ³ (β‡’βŠ² (+-Ξ± π’ž.∘ i₁)) βŸ©βŠ—βŸ¨refl ⟩ + ⊲ ∘ (⊲ ∘ G.₁ (+-Ξ± π’ž.∘ i₁) βŠ—β‚ G.₁ (+-Ξ± π’ž.∘ i₁) ∘ _) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ (refl⟩∘⟨ βŠ—-distrib-over-∘) βŸ©βŠ—βŸ¨refl ⟨ + ⊲ ∘ (⊲ ∘ _ βŠ—β‚ (G.₁ (+-Ξ± π’ž.∘ i₁) ∘ G.₁ iβ‚‚)) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ (refl⟩∘⟨ [ G ]-resp-∘ +-α∘iβ‚βˆ˜i₁ βŸ©βŠ—βŸ¨ [ G ]-resp-square +-α∘iβ‚βˆ˜iβ‚‚) βŸ©βŠ—βŸ¨refl ⟩ + ⊲ ∘ (⊲ ∘ G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ i₁)) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ split₁ˑ ⟩ + ⊲ ∘ ⊲ βŠ—β‚ id ∘ (G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ i₁)) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ extendΚ³ (ΞΌ-assoc (M.β‚€ (n + (m + o)))) ⟩ + ⊲ ∘ (id βŠ—β‚ ⊲ ∘ Ξ±β‡’) ∘ (G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ i₁)) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ assoc ⟩ + ⊲ ∘ id βŠ—β‚ ⊲ ∘ Ξ±β‡’ ∘ (G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ i₁)) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚) β‰ˆβŸ¨ refl⟩∘⟨ refl⟩∘⟨ assoc-commute-from ⟩ + ⊲ ∘ id βŠ—β‚ ⊲ ∘ G.₁ i₁ βŠ—β‚ ((G.₁ iβ‚‚ ∘ G.₁ i₁) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚)) ∘ Ξ±β‡’ β‰ˆβŸ¨ refl⟩∘⟨ pullΛ‘ mergeβ‚‚Λ‘ ⟩ + ⊲ ∘ G.₁ i₁ βŠ—β‚ (⊲ ∘ (G.₁ iβ‚‚ ∘ G.₁ i₁) βŠ—β‚ (G.₁ iβ‚‚ ∘ G.₁ iβ‚‚)) ∘ Ξ±β‡’ β‰ˆβŸ¨ refl⟩∘⟨ reflβŸ©βŠ—βŸ¨ (refl⟩∘⟨ βŠ—-distrib-over-∘) ⟩∘⟨refl ⟩ + ⊲ ∘ G.₁ i₁ βŠ—β‚ (⊲ ∘ G.₁ iβ‚‚ βŠ—β‚ G.₁ iβ‚‚ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ Ξ±β‡’ β‰ˆβŸ¨ refl⟩∘⟨ reflβŸ©βŠ—βŸ¨ (extendΚ³ (β‡’βŠ² iβ‚‚)) ⟩∘⟨refl ⟨ + ⊲ ∘ G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ Ξ±β‡’ β‰ˆβŸ¨ pushΚ³ (pushΛ‘ splitβ‚‚Κ³) ⟩ + (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ id βŠ—β‚ (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ Ξ±β‡’ ∎ + where + +-Ξ± : (n + m) + o π’ž.β‡’ n + (m + o) + +-Ξ± = +-assoc.to {n} {m} {o} + + module _ {A B : π’ž.Obj} (f : AΒ π’ž.β‡’ B) where + + ⊲-Ξ΅Κ³ : ⊲ ∘ G.₁ f βŠ—β‚ Ξ΅ β‰ˆ G.₁ f ∘ ρ⇒ + ⊲-Ξ΅Κ³ = begin + ⊲ ∘ G.₁ f βŠ—β‚ Ξ΅ β‰ˆβŸ¨ refl⟩∘⟨ serialize₂₁ ⟩ + ⊲ ∘ id βŠ—β‚ Ξ΅ ∘ G.₁ f βŠ—β‚ id β‰ˆβŸ¨ pullΛ‘ (Equiv.sym (ΞΌ-identityΚ³Β (M.β‚€ B))) ⟩ + ρ⇒ ∘ G.₁ f βŠ—β‚ id β‰ˆβŸ¨ unitorΚ³-commute-from ⟩ + G.₁ f ∘ ρ⇒ ∎ + + ⊲-Ξ΅Λ‘ : ⊲ ∘ Ξ΅ βŠ—β‚ G.₁ f β‰ˆ G.₁ f ∘ Ξ»β‡’ + ⊲-Ξ΅Λ‘ = begin + ⊲ ∘ Ξ΅ βŠ—β‚ G.₁ f β‰ˆβŸ¨ refl⟩∘⟨ serialize₁₂ ⟩ + ⊲ ∘ Ξ΅ βŠ—β‚ id ∘ id βŠ—β‚ G.₁ f β‰ˆβŸ¨ pullΛ‘ (Equiv.sym (ΞΌ-identityΛ‘Β (M.β‚€ B))) ⟩ + Ξ»β‡’ ∘ id βŠ—β‚ G.₁ f β‰ˆβŸ¨ unitorΛ‘-commute-from ⟩ + G.₁ f ∘ Ξ»β‡’ ∎ + + module _ {n : π’ž.Obj} where + + ⊲-βŠ—-Ξ» : G.₁ (+-Ξ».from {n}) ∘ ⊲-βŠ— ∘ Ξ΅ βŠ—β‚ id β‰ˆ Ξ»β‡’ + ⊲-βŠ—-Ξ» = begin + G.₁ +-Ξ».from ∘ (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ Ξ΅ βŠ—β‚ id β‰ˆβŸ¨ refl⟩∘⟨ pullΚ³ merge₁ʳ ⟩ + G.₁ +-Ξ».from ∘ ⊲ ∘ (G.₁ i₁ ∘ Ξ΅) βŠ—β‚ G.₁ iβ‚‚ β‰ˆβŸ¨ refl⟩∘⟨ refl⟩∘⟨ β‡’Ξ΅ i₁ βŸ©βŠ—βŸ¨refl ⟩ + G.₁ +-Ξ».from ∘ ⊲ ∘ Ξ΅ βŠ—β‚ G.₁ iβ‚‚ β‰ˆβŸ¨ refl⟩∘⟨ ⊲-Ξ΅Λ‘ iβ‚‚ ⟩ + G.₁ +-Ξ».from ∘ G.₁ iβ‚‚ ∘ Ξ»β‡’ β‰ˆβŸ¨ cancelΛ‘ ([ G ]-resp-∘ +-λ∘iβ‚‚ β—‹ G.identity) ⟩ + Ξ»β‡’ ∎ + + ⊲-βŠ—-ρ : G.₁ (+-ρ.from {n}) ∘ ⊲-βŠ— ∘ id βŠ—β‚ Ξ΅ β‰ˆ ρ⇒ + ⊲-βŠ—-ρ = begin + G.₁ +-ρ.from ∘ (⊲ ∘ G.₁ i₁ βŠ—β‚ G.₁ iβ‚‚) ∘ id βŠ—β‚ Ξ΅ β‰ˆβŸ¨ refl⟩∘⟨ pullΚ³ mergeβ‚‚Κ³ ⟩ + G.₁ +-ρ.from ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ (G.₁ iβ‚‚ ∘ Ξ΅) β‰ˆβŸ¨ refl⟩∘⟨ refl⟩∘⟨ reflβŸ©βŠ—βŸ¨ β‡’Ξ΅ iβ‚‚ ⟩ + G.₁ +-ρ.from ∘ ⊲ ∘ G.₁ i₁ βŠ—β‚ Ξ΅ β‰ˆβŸ¨ refl⟩∘⟨ ⊲-Ξ΅Κ³ i₁ ⟩ + G.₁ +-ρ.from ∘ G.₁ i₁ ∘ ρ⇒ β‰ˆβŸ¨ cancelΛ‘ ([ G ]-resp-∘ +-ρ∘i₁ β—‹ G.identity) ⟩ + ρ⇒ Β  ∎ + +F,βŠ—,Ξ΅ : MonoidalFunctor π’ž-MC S +F,βŠ—,Ξ΅ = record + { F = G + ; isMonoidal = record + { Ξ΅ = Ξ΅ + ; βŠ—-homo = ⊲-βŠ—-homo + ; associativity = ⊲-βŠ—-Ξ± + ; unitaryΛ‘ = ⊲-βŠ—-Ξ» + ; unitaryΚ³ = ⊲-βŠ—-ρ  + } + } + +module F,βŠ—,Ξ΅ = MonoidalFunctor F,βŠ—,Ξ΅ -- cgit v1.2.3