near distributive laws
play

Near Distributive Laws E. Manes 1 . Mulry 2 P 1 Department of - PowerPoint PPT Presentation

Near Distributive Laws E. Manes 1 . Mulry 2 P 1 Department of Mathematics and Statistics University of Massachusetts at Amherst 2 Department of Computer Science Colgate University FMCS 2018 Preliminaries H = ( H , , ) a monad in C , K = (


  1. Near Distributive Laws E. Manes 1 . Mulry 2 P 1 Department of Mathematics and Statistics University of Massachusetts at Amherst 2 Department of Computer Science Colgate University FMCS 2018

  2. Preliminaries H = ( H , µ, η ) a monad in C , K = ( K , ν, ρ ) a monad in D C H for the Kleisli category of H D K for the Eilenberg-Moore category of K algebras A Kleisli lifting of functor F : C → D is F : C H → D K F ✲ C H D K ✻ ✻ ι H ι K ✲ C D F Kleisli liftings are classified exactly by natural transformations λ : FH → KF satisfying certain axioms. F ( f : A → HB ) = λ ◦ ( F f )

  3. Introduction Likewise An Eilenberg-Moore lifting of functor F : C → D is F ⋆ : C H → D K F ⋆ ✲ C H D K ✻ ✻ U H U K ✲ C D F E-M liftings are classified exactly by natural transformations σ : KF → FH again satisfying certain axioms. λ and σ are denoted lifting transformation and their axioms guarantee that F and F ⋆ are functorial.

  4. Introduction Well known question: How to compose two monads? The composition of ( H , µ, η ) and K , ν, ρ ) should have form ( KH , τ, ρη ) . The problem is that there is no obvious τ . The solution is to provide a natural transformation λ : HK → KH which allows τ to be defined as τ = KHKH K λ H µν − − → KKHH − − → KH The axioms on λ which enable ( KH , τ, ρη ) to be a monad(i.e. that λ is a distributive law ) were first discovered by Beck.

  5. Introduction λ : HK → KH a distributive law of H over K if H ρ ✲ ✛ H ν H HK HKK ❩❩❩❩❩❩❩❩ λ K ❄ ( DL A ) ( DL B ) KHK λ ρ H K λ ❄ ❄ ❩ ⑦ ✛ KH KKH ν H η K µ K ✲ ✛ K HK HHK ❩❩❩❩❩❩❩❩ H λ ❄ ( DL C ) ( DL D ) HKH λ K η λ H ❄ ❄ ❩ ⑦ ✛ KH KHH K µ

  6. Introduction Prior slide: The two diagrams are the axioms for the lifting transformations λ : HK → KH (where λ is both a Kleisli and an E-M lifting transformation for H and K ⋆ respectively) of the monads H and K . Difficulties in composing monads generally arise from the axioms as opposed to the naturality requirement. While composition of monads can be achieved for many monads in programming, it often comes at a cost in terms of the definition of λ One approach is to only require (DL C, DL D) to hold in which case we say λ is a near distributive law . We present two approaches to building near distributive laws via free monads and pre-monads .

  7. Free Monads Our most relaxed model of a monad is a functor H : V → V . If it exists, the free monad generated by H is ( H @ , µ, η ; ι ) where H @ = ( H @ , µ, η ) is a monad in V and ι : H → H @ is a natural transformation, subject to the universal property ι ✲ ( H @ , µ, η ) H @ H ❅ ❅ α ❅ ψ ψ ❅ ❅ ❘ ❅ ❄ ❄ ( K , ν, ρ ) K that if ( K , ν, ρ ) is a monad in V and α : H → K is a natural transformation then there exists a unique monad map ψ as shown with ψι = α .

  8. Free Monads Example Assume that V has finite powers. For a finite ordinal i ≥ 1, let H i : V → V be the functor H i X = X i , the usual i -product functor. When V = Set , the data type H @ i X is the set of all i -ary trees in which every node is either an element of X , denoted L i x (a leaf) or has i subtrees beneath it, denoted B i t 1 · · · t i ∈ H @ i X . The natural transformation η X : X → H @ i X maps x to L i x while µ X : H @ i H @ i X → H @ i maps L i t to t and B i tt 1 . . . tt i to B i ( µ X tt 1 ) . . . ( µ X tt i ) . For now we consider only H for which H @ exists. Theorem V H is isomorphic over V to the category of Eilenberg-Moore algebras V H @ . The isomorphism Φ : V H @ → V H is given by ι X ξ ξ Φ( X , H @ X → H @ X − − → X ) = ( X , HX − − − − → X )

  9. Free Monads Definition Let H : V → V generate a free monad H @ and let K : V → V be a functor. Let K ⋆ : V H @ → V H @ be a functorial lift of K with lifting natural transformation λ @ : H @ K → KH @ . We say K ⋆ is a flat functorial lift if there exists a natural transformation λ : HK → KH such that the following square commutes. ι K ✲ H @ K HK λ @ ( 3 ) λ ❄ ❄ ✲ KH @ KH K ι We then say that λ generates K ⋆ , or λ generates λ @ , and when K is a monad that λ @ is a flat near-distributive law .

  10. Free Monads Theorem Given H , K : V → V such that H @ exists, every natural transformation λ : HK → KH generates a flat functorial lift of K through H @ . Proof. Given λ , define K † : V H → V H over V by λ X K δ K † ( X , δ ) = ( KX , HKX − − − − → KHX − − − − → KX ) If f : ( X , δ ) → ( Y , ǫ ) is an H -homomorphism, the diagram λ X ✲ K δ ✲ HKX KHX KX HKf KHf Kf ❄ ❄ ❄ ✲ ✲ HKY KHY KY λ Y K ǫ

  11. Free Monads shows that Kf : K † ( X , δ ) → K † ( Y , ǫ ) is again an H -homomorphism. We then have the functorial lift K † Φ − 1 K ⋆ = V H @ Φ → V H @ → V H → V H − − − − − − − − − − − − Corollary Given H , K : V → V where K is a monad and H @ exists, then every natural transformation λ : HK → KH generates a flat near distributive law λ @ : H @ K → KH @ .

  12. Near Distributive Laws for Free Monads Definition For functor F : V → V , a pre-strength on F is a pair ( F , Γ F ) where Γ F is a natural transformation Γ F V 1 ··· V n : FV 1 × · · · × FV n → F ( V 1 × · · · × V n ) A morphism α : ( F , Γ F ) → ( G , Γ G ) is a natural transformation α : F → G such that the following square commutes. α V 1 × · · · × α Vn ✲ FV 1 × · · · × FV n GV 1 × · · · × GV n Γ F Γ G V 1 ··· Vn V 1 ··· Vn ❄ ❄ ✲ F ( V 1 × · · · × V n ) G ( V 1 × · · · × V n ) α V 1 ×···× Vn This forms a category of prestrengths of order n

  13. Near Distributive Laws for Free Monads Lemma For any monad K = ( K , ν, ρ ) in Set there exists a generic prestrength Γ n : KA 1 × ... KA n → K ( A 1 × ... A n ) of dimension n ≥ 1 . Γ 1 = id X Γ 2 formed using the Kock prestrength construction. For m 1 , m 2 ∈ KX define Γ 2 ( m 1 , m 2 ) = m 1 >> = λ a → ( m 2 >> = λ b → ρ ( a , b )) where for f : X → KY , ( m >> = f ) = f # m Straightforward application of monad laws shows K ( f × g ) ◦ Γ 2 ( m 1 , m 2 ) = Γ 2 ◦ ( Kf × Kg )( m 1 , m 2 ) and so Γ 2 is natural.

  14. Near Distributive Laws for Free Monads Proceeding inductively, if Γ i : ( KX ) i → KX i is natural, we obtain a natural transformation Γ id X × Γ i XXi KX × ( KX ) i → KX × KX i → K ( X i + 1 ) − − − − − − − − − − Lemma Γ 2 : KA × KB → K ( A × B ) is also associative, namely Γ 2 ◦ (Γ 2 × 1 )( m 1 , m 2 , m 3 ) = Γ ◦ ( 1 × Γ)( m 1 , m 2 , m 3 ) .

  15. Amenable Monads Difficult to find nontrivial monads which admit a distributive law with every monad. Definition A monad H in V is amenable if for every monad K in V , K has a functorial lift through V H . Proposition The monads H @ i in Set of Example 1 are amenable. Proof. Let K = ( K , ν, ρ ) be a monad in Set . By previous lemma there exists a generic natural transformation Γ i : H i K → KH i for every i ≥ 1. By letting λ = Γ 2 = Γ XX in flat near-distributive result, we are done.

  16. Amenable Monads Theorem The list monad is amenable. For any semigroup ( X , · ) , define the binary operation on K ∗ ( X , · ) as ( KX , ·· ) where k 1 · · k 2 = ( K · ) ◦ Γ 2 ( k 1 , k 2 ) . If f : ( X , · ) → ( Y , · ) is a semigroup morphism then so is K ∗ f since ( Kf )( k 1 · · X k 2 ) = ( Kf ) ◦ ( K · X ) ◦ Γ KX , KX ( k 1 , k 2 ) = ( K · Y ) ◦ K ( f × f ) ◦ Γ KX , KX ( k 1 , k 2 ) ( f a semigp hom) = ( K · Y ) ◦ Γ KY , KY ◦ ( Kf × Kf )( k 1 , k 2 ) ( Γ natural) = ( Kfk 1 ) · · Y ( Kfk 2 ) The result easily extends to empty lists by defining K ∗ ( X , · , e X ) as ( KX , ·· , ρ ( e X )) .

  17. Amenable Monads Example We apply K ∗ ( X , · ) == ( KX , ·· ) . When K is: the exception monad KX = X + 1 , then ( X + 1 , ·· ) is the obvious semigroup defined by a 1 · · a 2 = a 1 · a 2 when a 1 , a 2 are in X, ∗ otherwise. the reader monad KX = C × X for commutative monoid ( C , ∗ ) , ( c 1 , x 1 ) · · ( c 2 , x 2 ) = ( c 1 ∗ c 2 , x 1 · x 2 ) . the writer monad KX = A → X, and t i in KX, t 1 · · t 2 = λ x → t 1 x · t 2 x. the state monad KX = S → X × S, and t i in KX, t 1 ·· t 2 = λ s → let ( x 1 , s 1 ) = t 1 s in let ( x 2 , s 2 ) = t 2 s 1 in ( x 1 · x 2 , s 2 ) .

  18. Amenable Monads Example For K the reader monad KX = C × X , λ = Γ 2 : H 2 K → KH 2 becomes Γ 2 (( c 1 , x 1 ) , ( c 2 , x 2 )) = ( c 1 ∗ c 2 , ( x 1 , x 2 )) . Acting on a binary tree t of type H @ 2 KX , λ @ ( t ) = ( p , t ∗ ) where p is the product of the c i ’s found in the leaves and t ∗ is the corresponding tree in H @ 2 X consisting only of the elements of X . Example When K is H @ j , we can give a recursive construction of the functorial lift of lifting K through Set H @ i defining the near-distributive law λ : H @ i H @ j → H @ j H @ i in cases. For i , j ≥ 1: λ ( L i L j a ) = L j L i a λ L i ( B j t 1 · · · t j ) = B j ( λ L i t 1 ) · · · ( λ L i t j ) ( H @ λ B i ( tt 1 · · · tt i ) = j B i )Γ i ( λ tt 1 ) · · · ( λ tt i ) @ H j @ where tt i has type H i

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend