equational theories for real-time coalgebraic state machineschomsky-talk-st... · 2018-10-15 ·...

30
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

Upload: others

Post on 26-Apr-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Equational Theories for Real-Time

Coalgebraic State Machines

Sergey Goncharova Stefan Miliusa Alexandra Silvab

ICTAC 2018, October 15-19, Stellenbosch

aFriedrich-Alexander-Universitat Erlangen-NurnbergbUniversity College London

Page 2: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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

Page 3: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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

Page 4: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Prelude: Coalgebraic Powerset

Construction

Page 5: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

T-automata and Generalized Powerset Construction

For a monad T and a T-algebra am : TB Ñ B, we dub a triple of maps

om : X Ñ B, tm : X ˆ AÑ TX , am : TB Ñ B

a T-automaton. Equivalently, it is a coalgebra m : X Ñ B ˆ pTX qA

X TX BA‹

B ˆ pTX qA B ˆ pBA‹qA

m

ηpm7

m7out

idˆppm7qA

Factorization m “ m 7η is unique and we define JxKm “ JηpxqKm7 P BA‹ ,

meaning that the formal power series JxKm : A‹ Ñ B is the semantics

of m in state x

3/15

Page 6: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

T-automata and Generalized Powerset Construction

For a monad T and a T-algebra am : TB Ñ B, we dub a triple of maps

om : X Ñ B, tm : X ˆ AÑ TX , am : TB Ñ B

a T-automaton. Equivalently, it is a coalgebra m : X Ñ B ˆ pTX qA

X PX PA‹

2ˆ pPX qA 2ˆ pPA‹qA

m

ηpm7

m7out

idˆppm7qA

Factorization m “ m 7η is unique and we define JxKm “ JηpxqKm7 P BA‹ ,

meaning that the formal power series JxKm : A‹ Ñ B is the semantics

of m in state x

3/15

Page 7: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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

Page 8: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Equational Theories for Effects

Page 9: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Monads for Effects

Mac Lane: A monad T is just a monoid in the category of endofunctors

Any monad T supports inclusion of a value into a computation

η : X Ñ TX and a Kleisli lifting pf : X Ñ TY q ÞÑ pf ‹ : TX Ñ TY q

Examples:

• (finitary) nondeterminism: TX “ PωX ; “nondeterministic

functions” AÑ PωB are relations

• probabilistic nondeterminism: TX “

ρ : X Ñ r0, 1s |ř

ρ “ 1(

;

“probabilistic functions” AÑ TB are “probabilistic relations”

• (finite) background store: TX “ pX ˆ SqS ; side-effecting functions

AÑ TB are functions Aˆ S Ñ B ˆ S

5/15

Page 10: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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

Any monad T supports inclusion of a value into a computation

η : X Ñ TX and a Kleisli lifting pf : X Ñ TY q ÞÑ pf ‹ : TX Ñ TY q

Examples:

• (finitary) nondeterminism: TX “ PωX ; “nondeterministic

functions” AÑ PωB are relations

• probabilistic nondeterminism: TX “

ρ : X Ñ r0, 1s |ř

ρ “ 1(

;

“probabilistic functions” AÑ TB are “probabilistic relations”

• (finite) background store: TX “ pX ˆ SqS ; side-effecting functions

AÑ TB are functions Aˆ S Ñ B ˆ S

5/15

Page 11: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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 pf : X Ñ TY q ÞÑ pf ‹ : TX Ñ TY q

Examples:

• (finitary) nondeterminism: TX “ PωX ; “nondeterministic

functions” AÑ PωB are relations

• probabilistic nondeterminism: TX “

ρ : X Ñ r0, 1s |ř

ρ “ 1(

;

“probabilistic functions” AÑ TB are “probabilistic relations”

• (finite) background store: TX “ pX ˆ SqS ; side-effecting functions

AÑ TB are functions Aˆ S Ñ B ˆ S

5/15

Page 12: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Algebraic Theories

Moggi: A monad is a (generalized) computational effect

An algebraic theory E can be presented by a signature Σ and a set of

equations. Any E defines a monad:

• TEX “ ‘set of Σ-terms over X modulo E ’

• η coerces a variable to a term

• σ‹ptq applies substitution σ : X Ñ TEY to t : TEX

Example: Finite powerset monad Pω ðñ join semilattices with

bottom ðñ idempotent commutative monoids

Example: Finite probability distributions Dω ðñ barycentric algebras;

Σ “ t`p | p P r0, 1su, satisfying e.g. “biased associativity”:

px `p yq `q z “ x `p{pp`q´pqq py `p`q´pq zq

6/15

Page 13: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Algebraic Theories

Moggi: A monad is a (generalized) computational effect

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:

• TEX “ ‘set of Σ-terms over X modulo E ’

• η coerces a variable to a term

• σ‹ptq applies substitution σ : X Ñ TEY to t : TEX

Example: Finite powerset monad Pω ðñ join semilattices with

bottom ðñ idempotent commutative monoids

Example: Finite probability distributions Dω ðñ barycentric algebras;

Σ “ t`p | p P r0, 1su, satisfying e.g. “biased associativity”:

px `p yq `q z “ x `p{pp`q´pqq py `p`q´pq zq

6/15

Page 14: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

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:

• TEX “ ‘set of Σ-terms over X modulo E ’

• η coerces a variable to a term

• σ‹ptq applies substitution σ : X Ñ TEY to t : TEX

Example: Finite powerset monad Pω ðñ join semilattices with

bottom ðñ idempotent commutative monoids

Example: Finite probability distributions Dω ðñ barycentric algebras;

Σ “ t`p | p P r0, 1su, satisfying e.g. “biased associativity”:

px `p yq `q z “ x `p{pp`q´pqq py `p`q´pq zq

6/15

Page 15: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Stack Monad

The store monad TX “ pΓ‹ ˆ X qΓ‹

with Γ “ tγ1, . . . , γnu could be

regarded as a monad for stack transformations. But it contains too much!

Definition: The stack monad is the submonad Tstk of the store monad

p--ˆΓ‹qΓ‹

formed by xr : Γ‹ Ñ X , t : Γ‹ Ñ Γ‹y, which satisfy restriction:

Dk.w P Γk .@u P Γ‹. rpwuq “ rpwq ^ tpwuq “ tpwqu

Intuitively, this ensures that the underlying stack may only be finitely

read. E.g. nonexample: empty “ xλ -- . ‹, λ -- . εy R Tstk1

The stack signature consists of unary pushi (i ď n) and (n ` 1)-ary pop:

JpushiKpp P TstkX qpwq “ ppγiwq

JpopKpp1 P TstkX , . . . , pn P TstkX , q P TstkX qpγiwq “ pi pwq

JpopKpp1 P TstkX , . . . , pn P TstkX , q P TstkX qpεq “ pi pεq

7/15

Page 16: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Stack Theory

Theorem: The following stack theory is complete w.r.t. the stack monad

pushi ppoppx1, . . . , xn, yqq “ xi

popppush1pxq, . . . ,pushnpxq, xq “ x

poppx1, . . . , xn,poppy1, . . . , yn, zqq “ poppx1, . . . , xn, zq

Moreover, each TstkX 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 TstkX with

the set of normal forms

8/15

Page 17: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Adding Nondeterminism

Store-like effects can be sensibly combined by tensoring1: a tensor

product of two theories E1 and E2 is obtaining by joining signatures and

equations and adding the tensor laws: for all f P E1, g P E2

f pgpx11 , . . . , x

1k q, . . . gpx

n1 , . . . , x

nk qq “ gpf px1

1 , . . . , xn1 q, . . . f px

nk , . . . , x

nk 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 Tstk :

uioi “ 1 uioj “ 0 uie “ 0 o1u1 ` . . .` onun ` e “ 1 eoi “ 0 ee “ e pi ‰ jq

where

epxq “ popp∅, . . . , ∅, xq oi pxq “ popp∅, . . . , x , . . . , ∅q pi pxq “ pushpxq

1Freyd 1966, Algebra valued functors in general and tensor products in particular

9/15

Page 18: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

(Turing) Tape Monad

The tape monad Ttp is analogously defined as a submonad of

p--ˆZˆ ΓZqZˆΓZ(Z “ integer numbers)

Signature: rd (n-ary), wri (unary, 1 ď i ď n), mv1,mv-1 (unary)

Equations:

rdpwr1pxq, . . . ,wrnpxqq “ x

wri prdpx1, . . . , xnqq “ wri pxi q

mv-1pmv1pxqq “ x

mv1pmv-1pxqq “ x

wri pwrjpxqq “ wrjpxq

wri pmvkpwrjpmv-kpxqqqq “ mvkpwrjpmv-kpwri pxqqqq pk ‰ 0q

Proposition: Tape theory is not finitely axiomatizable

10/15

Page 19: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Combining Effects with

Reactivity

Page 20: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Reactive Expressions: Syntax

Reactive expressions EΣ,B0 are closed δ-expressions generated by the

grammar for a given signature Σ and generators B0 of a Σ-algebra B:

δ ::“ x | γ | f pδ, . . . , δq px P X , f P Σq

γ ::“ µx . pa1.δ& ¨ ¨ ¨&ak .δ&βq px P X , ai P Aq

β ::“ b | f pβ, . . . , βq pb P B0, f P Σq

Example (Nondeterministic Automata) (using 1` 1 “ 1 from B):

δ ::“ x | γ | ∅ | δ ` δ γ ::“ µx . pa1.δ& ¨ ¨ ¨&ak .δ&1q

Example (Deterministic PDA) (using pushi p1q “ 0 from B):

δ ::“ x | γ | pushi pδq | poppδ, . . . , δq

γ ::“ µx . pa1.δ& ¨ ¨ ¨&ak .δ&βq

β ::“ 0 | 1 | poppβ, . . . , βq

11/15

Page 21: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Reactive Expressions: Semantics

For e P EΣ,B0 , we define

• Brzozowski derivatives Bapeq P EΣ,B0 by induction, most notably

Bai

`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ ti re{xs

and by further induction, Bεpeq “ e, Baw peq “ BaBw peq

• final outputs opeq P B, again by induction, specifically

o`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ r

This induces the semantics JeK : A‹ Ñ B, by putting JeKpwq “ opBw peqq

Kleene Theorem: for any e P EΣ,B0 there is a T-automaton m over X

and a state x P X such that JeK “ JxKm and vice versa

12/15

Page 22: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Reactive Expressions: Semantics

For e P EΣ,B0 , we define

• Brzozowski derivatives Bapeq P EΣ,B0 by induction, most notably

Bai

`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ ti re{xs

and by further induction, Bεpeq “ e, Baw peq “ BaBw peq

• final outputs opeq P B, again by induction, specifically

o`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ r

This induces the semantics JeK : A‹ Ñ B, by putting JeKpwq “ opBw peqq

Kleene Theorem: for any e P EΣ,B0 there is a T-automaton m over X

and a state x P X such that JeK “ JxKm and vice versa

12/15

Page 23: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Reactive Expressions: Semantics

For e P EΣ,B0 , we define

• Brzozowski derivatives Bapeq P EΣ,B0 by induction, most notably

Bai

`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ ti re{xs

and by further induction, Bεpeq “ e, Baw peq “ BaBw peq

• final outputs opeq P B, again by induction, specifically

o`

µx . pa1.t1& ¨ ¨ ¨&ak .tk&rq˘

“ r

This induces the semantics JeK : A‹ Ñ B, by putting JeKpwq “ opBw peqq

Kleene Theorem: for any e P EΣ,B0 there is a T-automaton m over X

and a state x P X such that JeK “ JxKm and vice versa

12/15

Page 24: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Classes of Instances

• If B “ 2, e.g. for non-deterministic or alternating automata,

JeK P 2A‹ – PA‹ is the formal language of e

• For weighted automata, B is a semiring, T is the corresponding

B-module monad and we obtain standard semantics

• For PDA-like machines, JeK is not the ultimate semantics:

Theorem: if B is finite then JeK is regular regardless of the monad

We take B to be the quotient of Tstk2 by

pushi p0q “ pushi p1q “ 0,

equivalently, B consists of predicates Γ‹ Ñ 2 depending on a

bounded portion of stack, hence, JeK : Γ‹ Ñ PpA‹q• For valence automata, T “ Pω b p--ˆMq “ Pωp--ˆMq, B “ PωpMq

where M is a (polycyclic) monoid emulating storage mechanism

13/15

Page 25: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Expressivity of Stack Machines

Theorem: With m ranging over Tstk -automata, x0 over the respective

state spaces and γ0 over Γ, the sets!

w P A‹ | Jx0Km pwqpγ0q “ 1)

exhaustively cover all real-time deterministic context-free languages

Theorem: the classes of languages recognized by Pω b Tstk b . . .b Tstk ,

where m is the number of copies of Tstk , are as follows:

1. All context-free languages if m “ 1

2. All nondeterministic linear time languages if m ě 3

3. The case m “ 2 correspond to a language class properly between the

above two

Proof: Reduction to results on real-time machines from 60-s

14/15

Page 26: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Further Work

• Reactive expressions come with a canonical equational calculus,

which cannot always be complete (otherwise equivalence of PDA

would be decidable). Can one derive completeness from constraints

on the effect theory2?

• ε-elimination: for T-automata over a given B, can we obtain a useful

description of T1-automata over B 1 such that every original

non-real-time automaton is equivalent to a real-time automaton

w.r.t. T1 and B 1? In particular, when T “ T1 and B “ B 1? This is

very hard already for valence automata3

• Identifying further language and complexity classes. How to describe

the relation between the theory of effects and the complexity of

languages recognized?

2Bonsangue, Milius, and Silva 2013, Sound and Complete Axiomatizations of

Coalgebraic Language Equivalence3Zetzsche 2013, Silent Transitions in Automata with Storage

15/15

Page 27: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

Thank You for Your Attention!

Page 28: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

References I

References

Marcello M. Bonsangue, Stefan Milius, and Alexandra Silva. Sound and

complete axiomatizations of coalgebraic language equivalence. ACM

Trans. Comput. Log., 14(1):7:1–7:52, 2013.

Peter Freyd. Algebra valued functors in general and tensor products in

particular. Colloq. Math., 14:89–106, 1966.

Sergey Goncharov, Stefan Milius, and Alexandra Silva. Towards a

coalgebraic chomsky hierarchy. In TCS’14, volume 8705, pages

265–280. Springer, 2014.

Sergey Goncharov, Stefan Milius, and Alexandra Silva. Towards a

uniform theory of effectful state machines. CoRR, abs/1401.5277,

2018. URL http://arxiv.org/abs/1401.5277.

13/15

Page 29: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

References II

Robert Myers. Rational Coalgebraic Machines in Varieties: Languages,

Completeness and Automatic Proofs. PhD thesis, Imperial College

London, 2013.

Jan J. M. M. Rutten. Automata and coinduction (an exercise in

coalgebra). In Davide Sangiorgi and Robert de Simone, editors,

CONCUR, volume 1466 of Lecture Notes in Computer Science, pages

194–218. Springer, 1998.

Alexandra Silva. Kleene coalgebra. PhD thesis, Radboud Univ. Nijmegen,

2010.

Alexandra Silva, Filippo Bonchi, Marcello M. Bonsangue, and Jan J.

M. M. Rutten. Generalizing the powerset construction, coalgebraically.

In FSTTCS, volume 8 of LIPIcs, pages 272–283, 2010.

14/15

Page 30: Equational Theories for Real-Time Coalgebraic State Machineschomsky-talk-st... · 2018-10-15 · Equational Theories for Real-Time Coalgebraic State Machines Sergey Goncharov aStefan

References III

Joost Winter, Marcello M. Bonsangue, and Jan J. M. M. Rutten.

Coalgebraic characterizations of context-free languages. LMCS, 9(3),

2013.

Georg Zetzsche. Silent transitions in automata with storage. In Fedor V.

Fomin, Rusins Freivalds, Marta Z. Kwiatkowska, and David Peleg,

editors, Automata, Languages, and Programming - 40th International

Colloquium, ICALP 2013, Riga, Latvia, July 8-12, 2013, Proceedings,

Part II, volume 7966 of Lecture Notes in Computer Science, pages

434–445. Springer, 2013.

15/15