layer by layer combining monads
play

Layer by Layer: combining monads Fredrik Dahlqvist, Alexandra Silva, - PowerPoint PPT Presentation

Layer by Layer: combining monads Fredrik Dahlqvist, Alexandra Silva, Louis Parlant October 16, 2018 1/22 Motivation: ProbNetKAT 2/22 Motivation: ProbNetKAT S 2 A simple network: S 1 S 4 S 3 2/22 Motivation: ProbNetKAT S 2 A simple network:


  1. Layer by Layer: combining monads Fredrik Dahlqvist, Alexandra Silva, Louis Parlant October 16, 2018 1/22

  2. Motivation: ProbNetKAT 2/22

  3. Motivation: ProbNetKAT S 2 A simple network: S 1 S 4 S 3 2/22

  4. Motivation: ProbNetKAT S 2 A simple network: S 1 S 4 S 3 Topology: t =( sw = S 1 ; pt = 2 ; ( sw ← S 2 ; pt ← 1 ) ⊕ . 9 drop ) & ( sw = S 1 ; pt = 3 ; sw ← S 3 ; p ← 1 ) & ( sw = S 2 ; pt = 4 ; sw ← S 4 ; p ← 2 ) & ( sw = S 3 ; pt = 4 ; sw ← S 4 ; p ← 3 ) 2/22

  5. Motivation: ProbNetKAT S 2 A simple network: S 1 S 4 S 3 Topology: t =( sw = S 1 ; pt = 2 ; ( sw ← S 2 ; pt ← 1 ) ⊕ . 9 drop ) & ( sw = S 1 ; pt = 3 ; sw ← S 3 ; p ← 1 ) & ( sw = S 2 ; pt = 4 ; sw ← S 4 ; p ← 2 ) & ( sw = S 3 ; pt = 4 ; sw ← S 4 ; p ← 3 ) Forwarding policy: p = ( sw = S 1 ; pt ← 2 ) & ( sw = S 2 ; pt ← 4 ) 2/22

  6. Motivation: ProbNetKAT S 2 A simple network: S 1 S 4 S 3 Topology: t =( sw = S 1 ; pt = 2 ; ( sw ← S 2 ; pt ← 1 ) ⊕ . 9 drop ) & ( sw = S 1 ; pt = 3 ; sw ← S 3 ; p ← 1 ) & ( sw = S 2 ; pt = 4 ; sw ← S 4 ; p ← 2 ) & ( sw = S 3 ; pt = 4 ; sw ← S 4 ; p ← 3 ) Forwarding policy: p = ( sw = S 1 ; pt ← 2 ) & ( sw = S 2 ; pt ← 4 ) A packet reaches S 4 : ( t ; p ) ∗ ; ( sw = S 4 ) 2/22

  7. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ 3/22

  8. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ BUT! The denotation of the operator & is odd... 3/22

  9. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ BUT! The denotation of the operator & is odd... & isn’t idempotent. 3/22

  10. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ BUT! The denotation of the operator & is odd... & isn’t idempotent. ; does not distribute over & 3/22

  11. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ BUT! The denotation of the operator & is odd... & isn’t idempotent. ; does not distribute over & Why? What’s going on? 3/22

  12. Motivation: ProbNetKAT Syntactically, ProbNetKAT is a kind of Kleene algebra with probabilistic choice ⊕ λ BUT! The denotation of the operator & is odd... & isn’t idempotent. ; does not distribute over & Why? What’s going on? General question: How can we add features in a principled and controllable manner? 3/22

  13. Building languages layer by layer: shopping list 4/22

  14. Building languages layer by layer: shopping list First layer: p ::= skip | p ; p | a ∈ At p ; skip = skip ; p = p , . . . Monad: (−) ∗ 4/22

  15. Building languages layer by layer: shopping list Second layer: p ::= abort | p + p | a ∈ At p + abort = abort + p = p , p + q = q + p , p + p = p , . . . Monad: P First layer: p ::= skip | p ; p | a ∈ At p ; skip = skip ; p = p , . . . Monad: (−) ∗ 4/22

  16. Building languages layer by layer: shopping list Topping: p ::= p ⊕ r p | a ∈ At p ⊕ r q = q ⊕ 1 − r p , . . . Monad: D Second layer: p ::= abort | p + p | a ∈ At p + abort = abort + p = p , p + q = q + p , p + p = p , . . . Monad: P First layer: p ::= skip | p ; p | a ∈ At p ; skip = skip ; p = p , . . . Monad: (−) ∗ 4/22

  17. Combining the layers: things can go wrong! 5/22

  18. Combining the layers: things can go wrong! The composition of two monads is not necessarily a monad 5/22

  19. Combining the layers: things can go wrong! The composition of two monads is not necessarily a monad Combine monads S , T via distributive law λ : ST → TS 5/22

  20. Combining the layers: things can go wrong! The composition of two monads is not necessarily a monad Combine monads S , T via distributive law λ : ST → TS No distributive law PD → DP 5/22

  21. Combining the layers: things can go wrong! The composition of two monads is not necessarily a monad Combine monads S , T via distributive law λ : ST → TS No distributive law PD → DP But there exists a distributive law (−) ∗ P → P (−) ∗ 5/22

  22. Combining the layers: things can go wrong! The composition of two monads is not necessarily a monad Combine monads S , T via distributive law λ : ST → TS No distributive law PD → DP But there exists a distributive law (−) ∗ P → P (−) ∗ How do we deal with this systematically? 5/22

  23. This paper A general and modular approach for determining : (a) if a monad combination by distributive law is possible; (b) if it is not possible, exactly which features are broken by the extension; and (c) suggests a way to fix the composition by modifying one of the monads. 6/22

  24. Monads Monads: a categorical way to encode computational effects: 7/22

  25. Monads Monads: a categorical way to encode computational effects: Non-determinism, probabilities, side-effects . . . 7/22

  26. Monads Monads: a categorical way to encode computational effects: Non-determinism, probabilities, side-effects . . . Applications of monads include programming language semantics, automata theory, etc. It is convenient to compositionally combine several effects. 7/22

  27. Definitions Definition A Monad ( T , η , µ ) on a category C is: An endofunctor T : C → C A natural transformation η : 1 → T A natural transformation µ : TT → T (Verifying some structural properties) We will consider monads on Set. 8/22

  28. Examples P ( A ) = { B | B ⊆ A , B finite } Finite Powerset A ∗ = { w 1 . . . w n | n ∈ N , w i ∈ A } Free Monoid (List) D ( A ) = { f | f probability distribution on A , Distributions and Supp ( f ) finite } 9/22

  29. Algebras Definition An algebra for the monad T is an object A together with a morphism α : TA → A . (Verifying some structural properties involving η and µ ) 10/22

  30. Algebras Definition An algebra for the monad T is an object A together with a morphism α : TA → A . (Verifying some structural properties involving η and µ ) Definition For a signature Σ and a set of equations E we can define a monad T such that EM ( T ) ≃ Alg ( Σ , E ) 10/22

  31. Examples Σ E P 0, + x+0=0+x=x x+y=y+x (x+y)+z=x+(y+z) x+x=x (join-semilattice) (−) ∗ 1, ; x;1=1;x=x (x;y);z=x;(y;z) (monoid) 11/22

  32. S , T monads, EM ( T ) ≃ Alg ( Σ T , E T ) , EM ( S ) ≃ Alg ( Σ S , E S ) Definition A distributive law of T over S is a natural transformation λ : ST → TS (verifying structural properties) 12/22

  33. � � S , T monads, EM ( T ) ≃ Alg ( Σ T , E T ) , EM ( S ) ≃ Alg ( Σ S , E S ) Definition A distributive law of T over S is a natural transformation λ : ST → TS (verifying structural properties) If T distributes over S , then: TS is a monad η T η S µ S S µ T S λ TX � X � TX � STX TTX � STTX X � STX X TX STSTX SSTTX u m Operations in Σ S distribute over those of Σ T We call S the inner layer , T the outer layer . 12/22

  34. Remarks and questions: Distributive laws are one of the go-to methods to compose monads Implements a one-way distributivity of algebraic operations For two given monads, how to know whether there exists a distributive law? How to build it? 13/22

  35. Remarks and questions: Distributive laws are one of the go-to methods to compose monads Implements a one-way distributivity of algebraic operations For two given monads, how to know whether there exists a distributive law? How to build it? Theorem Let T be a monoidal monad, then for any finitary signature Σ , there exists a distributive law λ Σ : H Σ T → TH Σ of the polynomial functor associated with Σ over T . 13/22

  36. Remarks and questions: Distributive laws are one of the go-to methods to compose monads Implements a one-way distributivity of algebraic operations For two given monads, how to know whether there exists a distributive law? How to build it? Theorem Let T be a monoidal monad, then for any finitary signature Σ , there exists a distributive law λ Σ : H Σ T → TH Σ of the polynomial functor associated with Σ over T . Monoidal helps with lifting operations but not equations. 13/22

  37. The procedure: 1. Build ‘candidate’ λ : ST → TS 14/22

  38. The procedure: 1. Build ‘candidate’ λ : ST → TS S always given by signature Σ and equations E 14/22

  39. The procedure: 1. Build ‘candidate’ λ : ST → TS S always given by signature Σ and equations E Use monoidal ‘tensor’ ⊗ − , − : T (−) × T (−) → T (− × −) 14/22

  40. The procedure: 1. Build ‘candidate’ λ : ST → TS S always given by signature Σ and equations E Use monoidal ‘tensor’ ⊗ − , − : T (−) × T (−) → T (− × −) Define a lifting � T of T on Σ -algebras ( A , σ : A ar ( σ ) → A ) σ ∈ Σ → ( TA , T σ ◦ ⊗ ar ( σ ) : ( TA ) ar ( σ ) → TA ) σ ∈ Σ 14/22

  41. The procedure: 1. Build ‘candidate’ λ : ST → TS S always given by signature Σ and equations E Use monoidal ‘tensor’ ⊗ − , − : T (−) × T (−) → T (− × −) Define a lifting � T of T on Σ -algebras ( A , σ : A ar ( σ ) → A ) σ ∈ Σ → ( TA , T σ ◦ ⊗ ar ( σ ) : ( TA ) ar ( σ ) → TA ) σ ∈ Σ ; : ( P ( At ) ∗ ) 2 → P ( At ∗ ) , ( U , V ) �→ { u ; v | u ∈ U , v ∈ V } , � ˆ skip = { ǫ } 14/22

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