Martin Escardo 7th November 2018. (Strong) 'Monad' structure on π. Again the proofs are simplified by the use of SIP. We prove the laws for the various notions of equality because different ones are more convenient in different situations, and because they requires different assumptions (function extensionality or univalence). \begin{code} {-# OPTIONS --without-K --exact-split --safe --auto-inline #-} open import MLTT.Spartan module Lifting.Monad (π£ : Universe) where open import UF.Base open import UF.Subsingletons open import UF.Subsingletons-FunExt open import UF.Equiv open import UF.EquivalenceExamples open import UF.FunExt open import UF.Univalence open import UF.UA-FunExt open import Lifting.Lifting π£ open import Lifting.IdentityViaSIP π£ \end{code} Constructions: \begin{code} πΜ : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π X β π Y πΜ f (P , Ο , i) = P , f β Ο , i _β― : {X : π€ Μ } {Y : π₯ Μ } β (X β π Y) β (π X β π Y) _β― f (P , Ο , i) = (Ξ£ p κ P , is-defined (f (Ο p))) , (Ξ» Ο β value (f (Ο (prβ Ο))) (prβ Ο)) , Ξ£-is-prop i (Ξ» p β being-defined-is-prop (f (Ο p))) ΞΌ : {X : π€ Μ } β π (π X) β π X ΞΌ = id β― \end{code} We now give the monad laws. Functoriality holds definitionally: \begin{code} πΜ-id : {X : π€ Μ } β πΜ id οΌ id πΜ-id {π€} {X} = refl {π€ β (π£ βΊ)} {π X β π X} πΜ-β : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ } (f : X β Y) (g : Y β Z) β πΜ (g β f) οΌ πΜ g β πΜ f πΜ-β f g = refl \end{code} And so do the naturality laws if we use appropriate notions of equality in each case. The second is of course equivalent to identity, but not definitionally. \begin{code} Ξ·-natural : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β Ξ· β f οΌ πΜ f β Ξ· Ξ·-natural f = refl Ξ·-naturalβΌ : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β Ξ· β f βΌ πΜ f β Ξ· Ξ·-naturalβΌ f _ = refl ΞΌ-naturalβΌ : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β πΜ f β ΞΌ βΌ ΞΌ β πΜ (πΜ f) ΞΌ-naturalβΌ f _ = refl ΞΌ-natural : funext (π£ βΊ β π€) (π£ βΊ β π₯) β {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β πΜ f β ΞΌ οΌ ΞΌ β πΜ (πΜ f) ΞΌ-natural fe f = dfunext fe (ΞΌ-naturalβΌ f) \end{code} We unit laws amount to the laws P Γ π β P and π Γ P β P: \begin{code} π-unit-rightβ : {X : π€ Μ } (l : π X) β ΞΌ (πΜ Ξ· l) β l π-unit-rightβ (P , Ο , i) = e , refl where e : P Γ π β P e = π-rneutral π-unit-leftβ : {X : π€ Μ } (l : π X) β ΞΌ (Ξ· l) β l π-unit-leftβ (P , Ο) = e , refl where e : π Γ P β P e = π-lneutral π-unit-rightβΌ : is-univalent π£ β {X : π€ Μ } β ΞΌ β πΜ Ξ· βΌ id π-unit-rightβΌ {π€} ua {X} l = β-gives-οΌ ua (π-unit-rightβ {π€} {X} l) π-unit-leftβΌ : is-univalent π£ β {X : π€ Μ } β ΞΌ β Ξ· βΌ id π-unit-leftβΌ {π€} ua {X} l = β-gives-οΌ ua (π-unit-leftβ {π€} {X} l) \end{code} The associativity of multiplication amounts to the associativity of Ξ£: \begin{code} π-assocβ : {X : π€ Μ } (l : π (π (π X))) β ΞΌ (ΞΌ l) β ΞΌ (πΜ ΞΌ l) π-assocβ (P , Ο) = Ξ£-assoc , refl π-assocβΌ : is-univalent π£ β {X : π€ Μ } β ΞΌ β ΞΌ βΌ ΞΌ β πΜ ΞΌ π-assocβΌ {π€} ua {X} l = β-gives-οΌ ua (π-assocβ {π€} {X} l) \end{code} Strengths: \begin{code} π-Ο : {X : π€ Μ } {Y : π₯ Μ } β X Γ π Y β π (X Γ Y) π-Ο (x , m) = πΜ (Ξ» y β (x , y)) m π-Ο : {X : π€ Μ } {Y : π₯ Μ } β π X Γ Y β π (X Γ Y) π-Ο (l , y) = πΜ (Ξ» x β (x , y)) l \end{code} The monad is commutative, with its commutativity amounting to that of _Γ_: \begin{code} π-comm : {X : π€ Μ } {Y : π₯ Μ } {l : π X Γ π Y} β ΞΌ (πΜ π-Ο (π-Ο l)) βΒ· ΞΌ (πΜ π-Ο (π-Ο l)) π-comm = Γ-comm , (Ξ» z β refl) π-m : {X : π€ Μ } {Y : π₯ Μ } β π X Γ π Y β π (X Γ Y) π-m (l , m) = ((Ξ» x β curry π-Ο x m)β―) l \end{code} TODO. Write down and prove the strength laws. Or we can use the Kleisli-triple presentation of the monad, but the proofs / constructions are essentially the same: \begin{code} Kleisli-Lawβ : {X : π€ Μ } (l : π X) β (Ξ· β―) l β l Kleisli-Lawβ (P , Ο) = π-rneutral , refl Kleisli-Lawβ : {X : π€ Μ } {Y : π₯ Μ } (f : X β π Y) (x : X) β (f β―) (Ξ· x) β f x Kleisli-Lawβ f x = π-lneutral , refl Kleisli-Lawβ : {X : π₯ Μ } {Y : π¦ Μ } {Z : π£ Μ } (f : X β π Y) (g : Y β π Z) (l : π X) β (g β― β f β―) l β ((g β― β f)β―) l Kleisli-Lawβ f g l = Ξ£-assoc , refl πΜ' : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π X β π Y πΜ' f = (Ξ· β f)β― πΜ-agreement : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) (l : π X) β πΜ' f l βΒ· πΜ f l πΜ-agreement {π€} {π₯} {X} {Y} f (P , Ο , i) = π-rneutral , Ξ» _ β refl \end{code}