Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov a Stefan Milius a Alexandra Silva b ICTAC 2018, October 15-19, Stellenbosch a Friedrich-Alexander-Universit¨ at Erlangen-N¨ urnberg b University College London
Some Related Work • Deterministic automata as coalgebras [Rutten, 1998] • Generalized regular expressions and Kleene theorem for Kripke-polynomial functors [Silva, 2010] • Generalized powerset construction [Silva, Bonchi, Bonsangue, and Rutten, 2010] • Regular expressions for equationally presented functors and monads [Myers, 2013] • Context-free languages, coalgebraically [Winter, Bonsangue, and Rutten, 2013] This talk is based on • Goncharov, Milius, and Silva 2014, Towards a Coalgebraic Chomsky Hierarchy (TCS 2014) • Goncharov, Milius, and Silva 2018, Towards a Uniform Theory of Effectful State Machines (ArXiv preprint) 1/15
Overview What’s in here: • A theory of effectful real-time state machines and expressions • Semantics over the space of formal power series • Equational theories for effects • Kleene theorem What isn’t here: • Results on the equational theory of fixpoint expressions, e.g. completeness • Non-linear semantics (e.g. with trees instead of words) • Infinite trace semantics • Unguarded expressions/non-real-time machines (but see the paper) 2/15
Prelude: Coalgebraic Powerset Construction
T -automata and Generalized Powerset Construction For a monad T and a T -algebra a m : TB Ñ B , we dub a triple of maps o m : X Ñ B , t m : X ˆ A Ñ TX , a m : TB Ñ B a T -automaton. Equivalently, it is a coalgebra m : X Ñ B ˆ p TX q A m 7 p B A ‹ η X TX m 7 out m m 7 q A id ˆp p B ˆ p B A ‹ q A B ˆ p TX q A Factorization m “ m 7 η is unique and we define � x � m “ � η p x q � m 7 P B A ‹ , meaning that the formal power series � x � m : A ‹ Ñ B is the semantics of m in state x 3/15
T -automata and Generalized Powerset Construction For a monad T and a T -algebra a m : TB Ñ B , we dub a triple of maps o m : X Ñ B , t m : X ˆ A Ñ TX , a m : TB Ñ B a T -automaton. Equivalently, it is a coalgebra m : X Ñ B ˆ p TX q A m 7 p η P A ‹ P X X m 7 m out m 7 q A id ˆp p 2 ˆ p P A ‹ q A 2 ˆ p P X q A Factorization m “ m 7 η is unique and we define � x � m “ � η p x q � m 7 P B A ‹ , meaning that the formal power series � x � m : A ‹ Ñ B is the semantics of m in state x 3/15
Towards Kleene Theorem • We seek a syntactic counterpart of the generalized powerset construction • Hence, we need a syntax for the corresponding fixpoint expressions, corresponding to the classical regular expressions • Such expressions must include • reactive constructs for actions from A and final outputs from B (Think of prefixing a . - - and 0 , 1 of Kleene algebra) • effectful constructs for representing side-effecting transitions of the corresponding T -automaton (Think of nondeterministic ` and 0 ) 4/15
Equational Theories for Effects
Monads for Effects Mac Lane: A monad T is just a monoid in the category of endofunctors 5/15
Monads for Effects Mac Lane: A monad T is just a monoid in the category of endofunctors Moggi: A monad T is a (generalized) computational effect 5/15
Monads for Effects Moggi: A monad T is a (generalized) computational effect Any monad T supports inclusion of a value into a computation η : X Ñ TX and a Kleisli lifting p f : X Ñ TY q ÞÑ p f ‹ : TX Ñ TY q Examples: • (finitary) nondeterminism: TX “ P ω X ; “nondeterministic functions” A Ñ P ω B are relations � ( ρ : X Ñ r 0 , 1 s | ř ρ “ 1 • probabilistic nondeterminism: TX “ ; “probabilistic functions” A Ñ TB are “probabilistic relations” • (finite) background store: TX “ p X ˆ S q S ; side-effecting functions A Ñ TB are functions A ˆ S Ñ B ˆ S 5/15
Algebraic Theories Moggi: A monad is a (generalized) computational effect 6/15
Algebraic Theories Moggi: A monad is a (generalized) computational effect Plotkin & Power: A monad is a (generalized) algebraic theory 6/15
Algebraic Theories Plotkin & Power: A monad is a (generalized) algebraic theory An algebraic theory E can be presented by a signature Σ and a set of equations. Any E defines a monad: • T E X “ ‘set of Σ-terms over X modulo E ’ • η coerces a variable to a term • σ ‹ p t q applies substitution σ : X Ñ T E Y to t : T E X Example: Finite powerset monad P ω ð ñ join semilattices with bottom ð ñ idempotent commutative monoids Example: Finite probability distributions D ω ð ñ barycentric algebras; Σ “ t` p | p P r 0 , 1 su , satisfying e.g. “biased associativity”: p x ` p y q ` q z “ x ` p {p p ` q ´ pq q p y ` p ` q ´ pq z q 6/15
Stack Monad The store monad TX “ p Γ ‹ ˆ X q Γ ‹ with Γ “ t γ 1 , . . . , γ n u could be regarded as a monad for stack transformations. But it contains too much! Definition: The stack monad is the submonad T stk of the store monad - ˆ Γ ‹ q Γ ‹ formed by x r : Γ ‹ Ñ X , t : Γ ‹ Ñ Γ ‹ y , which satisfy restriction: p - D k . w P Γ k . @ u P Γ ‹ . r p wu q “ r p w q ^ t p wu q “ t p w q u Intuitively, this ensures that the underlying stack may only be finitely read. E.g. nonexample: empty “ x λ - - . ‹ , λ - - . ǫ y R T stk 1 The stack signature consists of unary push i ( i ď n ) and ( n ` 1)-ary pop : � push i � p p P T stk X qp w q “ p p γ i w q � pop � p p 1 P T stk X , . . . , p n P T stk X , q P T stk X qp γ i w q “ p i p w q � pop � p p 1 P T stk X , . . . , p n P T stk X , q P T stk X qp ǫ q “ p i p ǫ q 7/15
Stack Theory Theorem: The following stack theory is complete w.r.t. the stack monad push i p pop p x 1 , . . . , x n , y qq “ x i pop p push 1 p x q , . . . , push n p x q , x q “ x pop p x 1 , . . . , x n , pop p y 1 , . . . , y n , z qq “ pop p x 1 , . . . , x n , z q Moreover, each T stk X is the free algebra of the stack theory over X Proof: Interpreting the axioms as a rewriting system (it is strongly normalizing, no non-trivial critical pairs) and identifying each T stk X with the set of normal forms 8/15
Adding Nondeterminism Store-like effects can be sensibly combined by tensoring 1 : a tensor product of two theories E 1 and E 2 is obtaining by joining signatures and equations and adding the tensor laws: for all f P E 1 , g P E 2 f p g p x 1 1 , . . . , x 1 k q , . . . g p x n 1 , . . . , x n k qq “ g p f p x 1 1 , . . . , x n 1 q , . . . f p x n k , . . . , x n k qq Theorem [Freyd] : Tensor product of any theory with a semiring-module theory is again a semiring-module theory This yields a complete axiomatization of P ω b T stk : u i o i “ 1 u i o j “ 0 u i e “ 0 o 1 u 1 ` . . . ` o n u n ` e “ 1 eo i “ 0 ee “ e p i ‰ j q where e p x q “ pop p ∅ , . . . , ∅ , x q o i p x q “ pop p ∅ , . . . , x , . . . , ∅ q p i p x q “ push p x q 1 Freyd 1966, Algebra valued functors in general and tensor products in particular 9/15
(Turing) Tape Monad The tape monad T tp is analogously defined as a submonad of - ˆ Z ˆ Γ Z q Z ˆ Γ Z ( Z “ integer numbers) p - Signature: rd ( n -ary), wr i (unary, 1 ď i ď n ), mv 1 , mv - 1 (unary) Equations: mv - 1 p mv 1 p x qq “ x rd p wr 1 p x q , . . . , wr n p x qq “ x mv 1 p mv - 1 p x qq “ x wr i p rd p x 1 , . . . , x n qq “ wr i p x i q wr i p wr j p x qq “ wr j p x q wr i p mv k p wr j p mv - k p x qqqq “ mv k p wr j p mv - k p wr i p x qqqq p k ‰ 0 q Proposition: Tape theory is not finitely axiomatizable 10/15
Combining Effects with Reactivity
Reactive Expressions: Syntax Reactive expressions E Σ , B 0 are closed δ -expressions generated by the grammar for a given signature Σ and generators B 0 of a Σ-algebra B : δ :: “ x | γ | f p δ, . . . , δ q p x P X , f P Σ q γ :: “ µ x . p a 1 .δ & ¨ ¨ ¨ & a k .δ & β q p x P X , a i P A q β :: “ b | f p β, . . . , β q p b P B 0 , f P Σ q Example (Nondeterministic Automata) (using 1 ` 1 “ 1 from B ): δ :: “ x | γ | ∅ | δ ` δ γ :: “ µ x . p a 1 .δ & ¨ ¨ ¨ & a k .δ & 1 q Example (Deterministic PDA) (using push i p 1 q “ 0 from B ): δ :: “ x | γ | push i p δ q | pop p δ, . . . , δ q γ :: “ µ x . p a 1 .δ & ¨ ¨ ¨ & a k .δ & β q β :: “ 0 | 1 | pop p β, . . . , β q 11/15
Reactive Expressions: Semantics For e P E Σ , B 0 , we define • Brzozowski derivatives B a p e q P E Σ , B 0 by induction, most notably ` ˘ B a i µ x . p a 1 . t 1 & ¨ ¨ ¨ & a k . t k & r q “ t i r e { x s and by further induction, B ǫ p e q “ e , B aw p e q “ B a B w p e q • final outputs o p e q P B , again by induction, specifically ` ˘ o µ x . p a 1 . t 1 & ¨ ¨ ¨ & a k . t k & r q “ r 12/15
Reactive Expressions: Semantics For e P E Σ , B 0 , we define • Brzozowski derivatives B a p e q P E Σ , B 0 by induction, most notably ` ˘ B a i µ x . p a 1 . t 1 & ¨ ¨ ¨ & a k . t k & r q “ t i r e { x s and by further induction, B ǫ p e q “ e , B aw p e q “ B a B w p e q • final outputs o p e q P B , again by induction, specifically ` ˘ o µ x . p a 1 . t 1 & ¨ ¨ ¨ & a k . t k & r q “ r This induces the semantics � e � : A ‹ Ñ B , by putting � e � p w q “ o pB w p e qq 12/15
Recommend
More recommend