module Cat.Diagram.Monad.Relative where
Relative extension systemsπ
By definition, monads must be endofunctors. For most applications, this is sufficient, and the theory of monads is quite rich. However, this restriction can become problematic. As an example, let be a monad on interpreted as an algebraic theory, where each fibre is interpreted as the syntax of with variables. In this situation, the unit interprets a variable as a term, and the multiplication performs substitution.
However, we might wish to give a more refined treatment of variables1, then we immediately run into issues: We want to restrict domain away from being an endofunctor but we canβt make it into an endofunctor on either! In all but the most trivial situations, the collection of syntax trees on even a single variable is infinite.
So, if we want to work in a scenario like this, we will need to generalise the notion of monad. The fundamental impediment is that we can not take iterated composites of a functor so the unit-and-multiplication presentation of monads will not do. However, we can consider an alternative starting point: extension systems, where the problematic multiplication is replaced with an extension operation, written
Since the type of the extension operation does not mention iterated composites of we have cleared the main obstruction. It remains to see that we can actually achieve something. Following (Altenkirch, Chapman, and Uustalu 2015), we define a relative extension system, over a functor as:
A mapping of objects, and
A family of unit morphisms, and
An extension operation,
Like their non-relative counterparts, we do not require any functoriality or naturality.
module _ {oj βj oc βc} {J : Precategory oj βj} {C : Precategory oc βc} (F : Functor J C) where private module J = Cat.Reasoning J module C = Cat.Reasoning C module F = Cat.Functor.Reasoning F
record Relative-extension-system : Type (oj β oc β βc) where no-eta-equality field Mβ : J.Ob β C.Ob unit : β {x} β C.Hom (F.β x) (Mβ x) bind : β {x y} β C.Hom (F.β x) (Mβ y) β C.Hom (Mβ x) (Mβ y)
The equations for a relative extension system are similar to the non-relative case.
bind-unit-id : β {x} β bind (unit {x}) β‘ C.id bind-unit-β : β {x y} (f : C.Hom (F.β x) (Mβ y)) β bind f C.β unit β‘ f bind-β : β {x y z} β (f : C.Hom (F.β y) (Mβ z)) (g : C.Hom (F.β x) (Mβ y)) β bind f C.β bind g β‘ bind (bind f C.β g)
The functorial action of on can be recovered by extending
Mβ : β {x y} β J.Hom x y β C.Hom (Mβ x) (Mβ y) Mβ f = bind (unit C.β F.β f)
Furthermore, the latter two equations ensure naturality of the unit and extension, respectively.
unit-natural : β {x y} (f : J.Hom x y) β unit C.β F.β f β‘ Mβ f C.β unit unit-natural f = unit C.β F.β f β‘Λβ¨ bind-unit-β (unit C.β F.β f) β©β‘Λ bind (unit C.β F.β f) C.β unit β bind-naturall : β {x y z} (f : J.Hom y z) (g : C.Hom (F.β x) (Mβ y)) β Mβ f C.β bind g β‘ bind (Mβ f C.β g) bind-naturall f g = bind (unit C.β F.β f) C.β bind g β‘β¨ bind-β (unit C.β (F.β f)) g β©β‘ bind (bind (unit C.β F.β f) C.β g) β bind-naturalr : β {x y z} (f : C.Hom (F.β y) (Mβ z)) (g : J.Hom x y) β bind f C.β Mβ g β‘ bind (f C.β F.β g) bind-naturalr f g = bind f C.β bind (unit C.β F.β g) β‘β¨ bind-β f (unit C.β F.β g) β©β‘ bind (bind f C.β unit C.β (F.β g)) β‘β¨ ap bind (C.pulll (bind-unit-β f)) β©β‘ bind (f C.β F.β g) β
Functoriality also follows.
M-id : β {x} β Mβ (J.id {x}) β‘ C.id M-id = bind (unit C.β F.β J.id) β‘β¨ ap bind (C.elimr F.F-id) β©β‘ bind unit β‘β¨ bind-unit-id β©β‘ C.id β M-β : β {x y z} β (f : J.Hom y z) (g : J.Hom x y) β Mβ (f J.β g) β‘ Mβ f C.β Mβ g M-β f g = bind (unit C.β F.β (f J.β g)) β‘β¨ ap bind (F.shufflel (unit-natural f)) β©β‘ bind (Mβ f C.β unit C.β F.β g) β‘Λβ¨ bind-β (unit C.β F.β f) (unit C.β F.β g) β©β‘Λ Mβ f C.β Mβ g β
However, note that we do not have a multiplication operation, as we cannot iterate
module _ {oj βj oc βc} {J : Precategory oj βj} {C : Precategory oc βc} {F : Functor J C} {E E' : Relative-extension-system F} where private module J = Cat.Reasoning J module C = Cat.Reasoning C module F = Cat.Functor.Reasoning F module E = Relative-extension-system E module E' = Relative-extension-system E' open Relative-extension-system Relative-extension-system-path : (p0 : β x β E.Mβ x β‘ E'.Mβ x) β (β x β PathP (Ξ» i β C.Hom (F.β x) (p0 x i)) E.unit E'.unit) β (β {x y} (f : β i β C.Hom (F.β x) (p0 y i)) β PathP (Ξ» i β C.Hom (p0 x i) (p0 y i)) (E.bind (f i0)) (E'.bind (f i1))) β E β‘ E' Relative-extension-system-path p0 punit pbind = sys where coe-pbind : β i β {x y : J.Ob} β (f : C.Hom (F.β x) (p0 y i)) β C.Hom (p0 x i) (p0 y i) coe-pbind i {x} {y} f = pbind (Ξ» j β coe (Ξ» i β C.Hom (F.β x) (p0 y i)) i j f) i sys : E β‘ E' sys i .Mβ x = p0 x i sys i .unit {x} = punit x i sys i .bind f = coe-pbind i f sys i .bind-unit-id {x} = is-propβpathp (Ξ» i β C.Hom-set (p0 x i) (p0 x i) (coe-pbind i (punit x i)) C.id) E.bind-unit-id E'.bind-unit-id i sys i .bind-unit-β {x} {y} f = hcomp (β i) Ξ» where j (i = i0) β C.Hom-set _ _ _ _ base (E.bind-unit-β f) j j (i = i1) β C.Hom-set _ _ _ _ base (E'.bind-unit-β f) j j (j = i0) β base where base = coe0βi (Ξ» i β (f : C.Hom (F.β x) (p0 y i)) β coe-pbind i f C.β punit x i β‘ f) i (Ξ» f β E.bind-unit-β {x} {y} f) f sys i .bind-β {x} {y} {z} f g = hcomp (β i) Ξ» where j (i = i0) β C.Hom-set _ _ _ _ base (E.bind-β f g) j j (i = i1) β C.Hom-set _ _ _ _ base (E'.bind-β f g) j j (j = i0) β base where base = coe0βi (Ξ» i β (f : C.Hom (F.β y) (p0 z i)) (g : C.Hom (F.β x) (p0 y i)) β coe-pbind i f C.β coe-pbind i g β‘ coe-pbind i (coe-pbind i f C.β g)) i (Ξ» f g β E.bind-β {x} {y} f g) f g
Algebras over a relative extension systemπ
A relative extension algebra over is the relative extension system analog of an algebra over a monad. Following the general theme of extension operations, a relative extension algebra on is given by an operation Intuitively, this operation lets us βevaluateβ any so long as the codomain of the evaluation is
module _ {oj βj oc βc} {J : Precategory oj βj} {C : Precategory oc βc} {F : Functor J C} (E : Relative-extension-system F) where private module J = Cat.Reasoning J module C = Cat.Reasoning C module F = Cat.Functor.Reasoning F open Relative-extension-system E
record Relative-algebra-on (x : C.Ob) : Type (oj β βc) where no-eta-equality field Ξ½ : β {a} (f : C.Hom (F.β a) x) β C.Hom (Mβ a) x
This operation must satisfy a pair of equations:
For every we must have
For every and we must have
Ξ½-unit : β {a} (f : C.Hom (F.β a) x) β Ξ½ f C.β unit β‘ f Ξ½-bind : β {a b} (f : C.Hom (F.β b) x) (g : C.Hom (F.β a) (Mβ b)) β Ξ½ f C.β bind g β‘ Ξ½ (Ξ½ f C.β g)
From these, we can deduce a sort of naturality principle for
Ξ½-natural : β {a b} (f : C.Hom (F.β b) x) (g : J.Hom a b) β Ξ½ f C.β Mβ g β‘ Ξ½ (f C.β F.β g) Ξ½-natural f g = Ξ½ f C.β bind (unit C.β F.β g) β‘β¨ Ξ½-bind f (unit C.β F.β g) β©β‘ Ξ½ (Ξ½ f C.β unit C.β F.β g) β‘β¨ ap Ξ½ (C.pulll (Ξ½-unit f)) β©β‘ Ξ½ (f C.β F.β g) β
module _ {oj βj oc βc} {J : Precategory oj βj} {C : Precategory oc βc} {F : Functor J C} {E : Relative-extension-system F} where private module J = Cat.Reasoning J module C = Cat.Reasoning C module F = Cat.Functor.Reasoning F open Relative-extension-system E open Relative-algebra-on Relative-algebra-on-pathp : β {x y} β (p : x β‘ y) β {Ξ± : Relative-algebra-on E x} β {Ξ² : Relative-algebra-on E y} β (β {a} β (f : β i β C.Hom (F.β a) (p i)) β PathP (Ξ» i β C.Hom (Mβ a) (p i)) (Ξ± .Ξ½ (f i0)) (Ξ² .Ξ½ (f i1))) β PathP (Ξ» i β Relative-algebra-on E (p i)) Ξ± Ξ² Relative-algebra-on-pathp {x} {y} p {Ξ±} {Ξ²} pΞ½ = sys where coe-Ξ½ : β i β {a : J.Ob} β (f : C.Hom (F.β a) (p i)) β C.Hom (Mβ a) (p i) coe-Ξ½ i {a} f = pΞ½ (Ξ» j β coe (Ξ» i β C.Hom (F.β a) (p i)) i j f) i sys : PathP (Ξ» i β Relative-algebra-on E (p i)) Ξ± Ξ² sys i .Ξ½ f = coe-Ξ½ i f sys i .Ξ½-unit {a} f = hcomp (β i) Ξ» where j (i = i0) β C.Hom-set _ _ _ _ base (Ξ± .Ξ½-unit f) j j (i = i1) β C.Hom-set _ _ _ _ base (Ξ² .Ξ½-unit f) j j (j = i0) β base where base = coe0βi (Ξ» i β (f : C.Hom (F.β a) (p i)) β coe-Ξ½ i f C.β unit β‘ f) i (Ξ± .Ξ½-unit) f sys i .Ξ½-bind {a} {b} f g = hcomp (β i) Ξ» where j (i = i0) β C.Hom-set _ _ _ _ base (Ξ± .Ξ½-bind f g) j j (i = i1) β C.Hom-set _ _ _ _ base (Ξ² .Ξ½-bind f g) j j (j = i0) β base where base = coe0βi (Ξ» i β (f : C.Hom (F.β b) (p i)) β coe-Ξ½ i f C.β bind g β‘ coe-Ξ½ i (coe-Ξ½ i f C.β g)) i (Ξ» f β Ξ± .Ξ½-bind f g) f
The relative Eilenberg-Moore categoryπ
We can also relativize the Eilenberg-Moore category to obtain the relative Eilenberg-Moore category.
module _ {oj βj oc βc} {J : Precategory oj βj} {C : Precategory oc βc} {F : Functor J C} (E : Relative-extension-system F) where private module J = Cat.Reasoning J module C = Cat.Reasoning C module F = Cat.Functor.Reasoning F open Relative-extension-system E open Relative-algebra-on open Displayed
Relative-Eilenberg-Moore : Displayed C (oj β βc) (oj β βc)
Objects over are given by relative extension algebras over and maps over between algebras and are relative extension algebra morphisms when, for every we have
Relative-Eilenberg-Moore .Ob[_] = Relative-algebra-on E Relative-Eilenberg-Moore .Hom[_] {x} {y} f Ξ± Ξ² = β {a} (g : C.Hom (F.β a) x) β f C.β Ξ± .Ξ½ g β‘ Ξ² .Ξ½ (f C.β g)
It is straightforward to show that relative extension algebra morphisms are closed under identities and composites.
Relative-Eilenberg-Moore .id' {x = Ξ±} g = C.id C.β Ξ± .Ξ½ g β‘β¨ C.idl _ β©β‘ Ξ± .Ξ½ g β‘Λβ¨ ap (Ξ± .Ξ½) (C.idl _) β©β‘Λ Ξ± .Ξ½ (C.id C.β g) β Relative-Eilenberg-Moore ._β'_ {x = Ξ±} {y = Ξ²} {z = Ξ³} {f = f} {g = g} p q h = (f C.β g) C.β Ξ± .Ξ½ h β‘β¨ C.pullr (q h) β©β‘ f C.β Ξ² .Ξ½ (g C.β h) β‘β¨ p (g C.β h) β©β‘ Ξ³ .Ξ½ (f C.β g C.β h) β‘β¨ ap (Ξ³ .Ξ½) (C.assoc _ _ _) β©β‘ Ξ³ .Ξ½ ((f C.β g) C.β h) β
All of the equations are trivial.
Relative-Eilenberg-Moore .Hom[_]-set _ _ _ = hlevel 2 Relative-Eilenberg-Moore .idr' _ = prop! Relative-Eilenberg-Moore .idl' _ = prop! Relative-Eilenberg-Moore .assoc' _ _ _ = prop!
For instance, if we want to model a syntax where terms can only have finitely many variables.β©οΈ
References
- Altenkirch, Thosten, James Chapman, and Tarmo Uustalu. 2015. βMonads Need Not Be Endofunctors.β Logical Methods in Computer Science Volume 11, Issue 1 (March): 928. https://doi.org/10.2168/LMCS-11(1:3)2015.