On a Monadic Encoding of Continuous Behaviour Renato Neves joint work with: Luís Barbosa, Manuel Martins, Dirk Hofmann INESC TEC (HASLab) & Universidade do Minho October 1, 2015 1 / 27
The main goal A coalgebraic calculus of hybrid components. 2 / 27
Motivation & Context Hybrid systems possess both discrete and continuous behaviour. A discrete evolution A continuous evolution 4 3 2 1 4 3 2 1 1 2 3 4 5 6 Time 1 2 3 4 5 6 Time They are often complex but can be seen as the composition of (simpler) components. 3 / 27
Motivation & Context Hybrid systems possess both discrete and continuous behaviour. A discrete evolution A continuous evolution 4 3 2 1 4 3 2 1 1 2 3 4 5 6 Time 1 2 3 4 5 6 Time They are often complex but can be seen as the composition of (simpler) components. 3 / 27
Motivation & Context Hybrid systems possess both discrete and continuous behaviour. A discrete evolution A continuous evolution 4 3 2 1 4 3 2 1 1 2 3 4 5 6 Time 1 2 3 4 5 6 Time They are often complex but can be seen as the composition of (simpler) components. 3 / 27
Thermostat 22 A possible behaviour (c 10) 20 18 y 16 14 12 10 0 2 4 6 8 10 x 4 / 27
Water level regulator 25 A possible behaviour (d 0) 20 15 y 10 5 0 0 10 20 30 40 50 60 x 5 / 27
Hybrid components (coalgebraically) Arrows of type S I S HO where S I S defines the internal (discrete) transitions and S I HO the observable (continuous) behaviour. This favours a coalgebraic perspective! 6 / 27
Hybrid components (coalgebraically) Arrows of type S I S HO where S I S defines the internal (discrete) transitions and S I HO the observable (continuous) behaviour. This favours a coalgebraic perspective! 6 / 27
Coalgebras & Hybrid systems (related work) Object oriented hybrid systems of coalgebras plus monoid actions [Jacobs, 2000]. A coalgebra for the (discrete) assignments, a monoid for the (continuous) evolutions. Notions of bisimulation for hybrid systems (resort to open maps) [Haghverdi et al., 2005]. 7 / 27
Coalgebras & Hybrid systems (related work) Object oriented hybrid systems of coalgebras plus monoid actions [Jacobs, 2000]. A coalgebra for the (discrete) assignments, a monoid for the (continuous) evolutions. Notions of bisimulation for hybrid systems (resort to open maps) [Haghverdi et al., 2005]. 7 / 27
Components as coalgebras We view a component as s S, c : S I B(S O) where B is a (strong) monad that captures a specific type of behaviour [Barbosa, 2001]. [Barbosa, 2001] shows how to generate a rich component algebra from a strong monad. 8 / 27
Motivation & Context Different monads capture different types of behaviour...... and thus different kinds of component Maybe monad (M) faulty components Powerset monad (P) non deterministic components Distribution monad (D) probabilistic components Hybrid monad (H) hybrid components 9 / 27
Motivation & Context Different monads capture different types of behaviour...... and thus different kinds of component Maybe monad (M) faulty components Powerset monad (P) non deterministic components Distribution monad (D) probabilistic components Hybrid monad (H) hybrid components 9 / 27
Motivation & Context Different monads capture different types of behaviour...... and thus different kinds of component Maybe monad (M) faulty components Powerset monad (P) non deterministic components Distribution monad (D) probabilistic components Hybrid monad (H) hybrid components 9 / 27
Motivation & Context Different monads capture different types of behaviour...... and thus different kinds of component Maybe monad (M) faulty components Powerset monad (P) non deterministic components Distribution monad (D) probabilistic components Hybrid monad (H) hybrid components 9 / 27
Motivation & Context Different monads capture different types of behaviour...... and thus different kinds of component Maybe monad (M) faulty components Powerset monad (P) non deterministic components Distribution monad (D) probabilistic components Hybrid monad (H) hybrid components 9 / 27
Monad H It is defined in such a way that c : S I S HO c : S I S (O T D) unfold H where T = R 0 and D = [0, ]. Kleisli composition allows the transfer of evolution control between components. Technically, this amounts to concatenation of evolutions. 10 / 27
Monad H It is defined in such a way that c : S I S HO c : S I S (O T D) unfold H where T = R 0 and D = [0, ]. Kleisli composition allows the transfer of evolution control between components. Technically, this amounts to concatenation of evolutions. 10 / 27
Kleisli composition (thermostat revisited) c 1 i = ( λt.(i + t), 10 ), c 2 i = ( λt.(i + sin t), ) 25 c 2 c 1 10 20 y 15 10 0 5 10 15 20 25 30 x 11 / 27
Kleisli composition (thermostat revisited) c 1 i = ( λt.(i + t), 10 ), c 2 i = ( λt.(i + sin t), ) 25 c 2 c 1 10 20 y 15 10 0 5 10 15 20 25 30 x 11 / 27
Monad H and Höfner s Algebra Kleisli composition of Monad H corresponds to concatenation of evolutions in An algebra of hybrid systems [Höfner, 2009] Concatenation of evolutions 3 2 1 1 2 3 4 5 6 Time 12 / 27
Assembly of monad H (underlying functor) Based upon the category of topological spaces Top. Definition Given a space X Top, HX = { (f, d) X T D f d = f } where d = id d d. Definition Given a continuous function g : X Y, Hg : HX HY, Hg = g T id Intuitively, Hg alters evolutions pointwise (but keeps durations). 13 / 27
Assembly of monad H (underlying functor) Based upon the category of topological spaces Top. Definition Given a space X Top, HX = { (f, d) X T D f d = f } where d = id d d. Definition Given a continuous function g : X Y, Hg : HX HY, Hg = g T id Intuitively, Hg alters evolutions pointwise (but keeps durations). 13 / 27
Assembly of monad H (underlying functor) Based upon the category of topological spaces Top. Definition Given a space X Top, HX = { (f, d) X T D f d = f } where d = id d d. Definition Given a continuous function g : X Y, Hg : HX HY, Hg = g T id Intuitively, Hg alters evolutions pointwise (but keeps durations). 13 / 27
Assembly of monad H (underlying functor) An interesting algebra HX θ X θ (f, d) = f 0 14 / 27
Assembly of Monad H (monad operations) Id HH η H µ Definition Given a space X Top, η X x = (x, 0) Defines the simplest continuous system of type X HX. 15 / 27
Assembly of Monad H (monad operations) Id HH η H µ Definition Given a space X Top,... µ X (f, d) = (θ f, d) ++ (f d) 16 / 27
Assembly of Monad H (monad operations) Let us reason HHX (HX) T D (HX) T (X T D) T = (X T ) T D T (X T ) T = X T T 17 / 27
Kleisli category Top H (An environment to study the effects of continuity over composition) Top H = Top, for any objects I, O Top H, Top H (I, O) = Top(I, HO) the identity of I is η I, and given two arrows c 1 : I HK, c 2 : K HO their (sequential) composition, is equal to c 2 c 1 : I HO µ Hc 2 c 1 18 / 27
Kleisli composition (of Top H ) I c 1 HK Hc 2 HHO µ HO 4 c1 0 y 3 2 Hc 2 1 0 0 0.5 1 1.5 2 2.5 3 x 19 / 27
Other forms of composition (in Top H ) Choice (coproduct) c 1 : I 1 HO, c 2 : I 2 HO [c 1, c 2 ] : I 1 + I 2 HO (+) Parallelism (pullback) c 1 : I HO 1, c 2 : I HO 2 c 1, c 2 : I H(O 1 O 2 ) ( ) These operators are (co)limits, hence a number of useful laws come for free! 20 / 27
Other forms of composition (in Top H ) Choice (coproduct) c 1 : I 1 HO, c 2 : I 2 HO [c 1, c 2 ] : I 1 + I 2 HO (+) Parallelism (pullback) c 1 : I HO 1, c 2 : I HO 2 c 1, c 2 : I H(O 1 O 2 ) ( ) These operators are (co)limits, hence a number of useful laws come for free! 20 / 27
Other forms of composition (in Top H ) Choice (coproduct) c 1 : I 1 HO, c 2 : I 2 HO [c 1, c 2 ] : I 1 + I 2 HO (+) Parallelism (pullback) c 1 : I HO 1, c 2 : I HO 2 c 1, c 2 : I H(O 1 O 2 ) ( ) These operators are (co)limits, hence a number of useful laws come for free! 20 / 27
Other forms of composition (in Top H ) Synchronised parallelism c 1 : I HO 1, c 2 : I HO 2 c 1, c 2 : I H(O 1 O 2 ) (s) Feedback c : I HI νc : I HI (ν) 21 / 27
Other forms of composition (in Top H ) Synchronised parallelism c 1 : I HO 1, c 2 : I HO 2 c 1, c 2 : I H(O 1 O 2 ) (s) Feedback c : I HI νc : I HI (ν) 21 / 27
Top H (Parallelism) c 1 x = (λt. x + (sin t), 20 ) c 2 x = (λt. x + (sin(3 t)), 20 ) c 1, c 2 0 2 y 0 2 0 5 10 15 20 x 22 / 27
Top H (Parallelism) c 1 x = (λt. x + (sin t), 20 ) c 2 x = (λt. x + (sin(3 t)), 20 ) c 1, c 2 0 2 y 0 2 0 5 10 15 20 x 22 / 27
Top H (Parallelism) c 3 (x, y) = (λt. x + y, 0) c 3 c 1, c 2 0 2 y 0 2 0 5 10 15 20 x 23 / 27
Top H (Parallelism) c 3 (x, y) = (λt. x + y, 0) c 3 c 1, c 2 0 2 y 0 2 0 5 10 15 20 x 23 / 27
Conclusions Our goal is a coalgebraic calculus of hybrid components and monad H seems to be a promising approach for this. But mind Simulink, widely used in industry, and Hybrid automata, the standard formalism for the specification of hybrid systems. The former is highly expressive, but lacks a clear semantics. The latter is very intuitive, but does not have composition mechanisms as rich as Simulink. 24 / 27
Conclusions Our goal is a coalgebraic calculus of hybrid components and monad H seems to be a promising approach for this. But mind Simulink, widely used in industry, and Hybrid automata, the standard formalism for the specification of hybrid systems. The former is highly expressive, but lacks a clear semantics. The latter is very intuitive, but does not have composition mechanisms as rich as Simulink. 24 / 27
Conclusions Our goal is a coalgebraic calculus of hybrid components and monad H seems to be a promising approach for this. But mind Simulink, widely used in industry, and Hybrid automata, the standard formalism for the specification of hybrid systems. The former is highly expressive, but lacks a clear semantics. The latter is very intuitive, but does not have composition mechanisms as rich as Simulink. 24 / 27
Future work Introduction of non determinism. Development of a calculus bisimulation based. Try to answer the question: Which kind of logics does monad H gives rise to? 25 / 27
Future work Introduction of non determinism. Development of a calculus bisimulation based. Try to answer the question: Which kind of logics does monad H gives rise to? 25 / 27
Future work Introduction of non determinism. Development of a calculus bisimulation based. Try to answer the question: Which kind of logics does monad H gives rise to? 25 / 27
References I Barbosa, L. S. (2001). Components as coalgebras. PhD thesis, DI, Minho University. Haghverdi, E., Tabuada, P., and Pappas, G. J. (2005). Bisimulation relations for dynamical, control, and hybrid systems. Theoretical Computer Science, 342(2 3):229 261. Höfner, P. (2009). Algebraic calculi for hybrid systems. PhD thesis, University of Augsburg. 26 / 27
References II Jacobs, B. (2000). Object-oriented hybrid systems of coalgebras plus monoid actions. Theoretical Computer Science, 239(1):41 95. 27 / 27