A coalgebraic take on regular and $\omega$-regular behaviours

We present a general coalgebraic setting in which we define finite and infinite behaviour with B\"uchi acceptance condition for systems whose type is a monad. The first part of the paper is devoted to presenting a construction of a monad suitable for modelling (in)finite behaviour. The second part of the paper focuses on presenting the concepts of a (coalgebraic) automaton and its ($\omega$-) behaviour. We end the paper with coalgebraic Kleene-type theorems for ($\omega$-) regular input. The framework is instantiated on non-deterministic (B\"uchi) automata, tree automata and probabilistic automata.

Automata theory is one of the core branches of theoretical computer science and formal language theory. One of the most fundamental state-based structures considered in the literature is a non-deterministic automaton and its relation with languages. Non-deterministic automata with a finite state-space are known to accept regular languages. These languages are characterized as subsets of words over a fixed finite alphabet that can be obtained from simple languages via a finite number of applications of three types of operations: union, concatenation and the Kleene star operation [HMRU00,Kle56]. This result is known under the name of R ::= ∅ | a, a ∈ Σ ε | R + R | R · R | R *

Figure 1: Regular expression grammar
Kleene theorem for regular languages and readily generalizes to other types of finite input (see e.g. [PP04]). On the other hand, non-deterministic automata have a natural infinite semantics which is given in terms of infinite input satisfying the so-called Büchi acceptance condition (or BAC in short). The condition takes into account the terminal states of the automaton and requires them to be visited infinitely often. It is a common practise to use the term Büchi automata in order to refer to automata whenever their infinite semantics is taken into consideration.
input type Kleene theorem where  Although the standard type of infinite input of a Büchi automaton is the set of infinite words over a given alphabet, other types (e.g. trees) are also commonly studied [PP04]. The class of languages of infinite words accepted by Büchi automata can also be characterized akin to the characterization of regular languages. This result is known under the name of Kleene theorem for ω-regular languages and its variants hold for many input types (see e.g. [KN01,Büc90,GTW02,PP04]). Roughly speaking, any language recognized by a Büchi automaton can be represented in terms of regular languages and the infinite iteration operator (−) ω . This begs the question whether these systems can be placed in a unifying framework and reasoned about on a more abstract level so that the analogues of Kleene theorems for (ω-)regular input are derived. The recent developments in the theory of coalgebra [CV12,SW13,USH16,Rut00] show that the coalgebraic framework may turn out to be suitable to achieve this goal.
A coalgebra X → F X is an abstract (categorical) representation of a computation of a process [Rut00,Gum99]. The coalgebraic setting has already proved itself useful in modelling finite behaviour via least fixpoints (e.g. [HJS07,SW13,Bre15]) and infinite behaviour via greatest fixpoints of suitable mappings [Jac04,Cîr10,UH15]. The infinite behaviour with BAC can be modelled by a combination of the two [USH16,Par81].
We plan to revisit the coalgebraic framework of (in)finite behaviour from the perspective of systems whose type functor is a monad. In the coalgebraic literature [Bre14,Bre15,BP16,BMP15,Bre18,BP19] these systems are often referred to by the name of systems with internal moves. This name is motivated by the research on a unifying theory of finite behaviour for systems with internal steps [SW13,Bre14,Bre15,BMSZ15,BP16,BMP15]. They arise in a natural manner in many branches of theoretical computer science, among which are process calculi [Mil89] (labelled transition systems and their weak bisimulation) or automata theory (automata with ε-moves), to name only two. Intuitively, these systems have a special computation branch that is silent. This special branch, usually labelled by the letter τ or ε, is allowed to take several steps and is, in some, a neutral part of the process. As thoroughly discussed in [Bre15], the nature of this type of transition suggests it is in fact (part of) the unit of a monad. Hence, from our point of view the following terms become synonymous: coalgebras with internal moves = coalgebras whose type is a monad. equivalences which take silent steps into account [BMP15,BP16,Bre15]. If the type T of a coalgebra α : X → T X is a monad then the map α becomes an endomorphism α : X−→ • • X in the Kleisli category for T : a natural and simple setting to study composition and fixpoints. For instance, if T is taken to be the monad modelling labelled transition systems [Bre15] then Milner's weak bisimulation [Mil89] of an LTS given by α is a strong bisimulation on its saturation α * , i.e. the smallest LTS over the same state space s.t. α ≤ α * , id ≤ α * and α * · α * ≤ α * (where the composition and the order are given in the Kleisli category for the LTS monad) [Bre15]. Hence, intuitively, α * is the reflexive and transitive closure of α and is formally defined as the least fixpoint µx.(id ∨ x · α). The fact that labelled transition systems' weak bisimulation can be modelled via saturation of endomorphisms of a given Kleisli category allows for a generalization of the setting to other systems (e.g. probabilistic [Bre15,BMP15]). The only requirement is that type functor is a monad whose Kleisli category satisfies suitable conditions for the definition of (−) * to be meaningful. The reflexive and transitive closure α → α * is understood as an accumulation of a finite number of compositions of the structure with itself. Hence, the concept of coalgebraic saturation is intrinsically related to finite behaviour of systems with a monadic type. A similar treatment of infinite behaviour (and their combination used to model Büchi acceptance condition) in the context of coalgebras whose type is a monad has not been considered so far. The closest to this goal would be [UH15,USH16], where (in)finite trace semantics is given in the setting of T F -coalgebras for a monad T and an endofunctor F . We take this treatment one step further and embed T F into a monad T F ∞ which is tailored to modelling (in)finite behaviours and their combinations. The new setting allows us to present clear definitions of coalgebraic (in)finite semantics and reason about them. In particular, it allows us to state Kleene theorems for regular and ω-regular behaviours which would be challenging without the monadic types.
1.1. Motivations. Our purpose is to build a single coalgebraic setting that allows us to easily present definitions of (in)finite behaviours and reason about them aiming at their algebraic characterization. By finding a suitable monad T describing the type of systems taken into consideration we are able to state generic Kleene theorems connecting syntax and semantics of languages: the former imposed by the canonical algebraic nature of T and the latter given by T -automata and their behaviours.
By presenting a recipe to extend a functor to a suitable monad, we automatically encompass systems with invisible steps. However, this should not be viewed as our primary goal. Instead, from our point of view, it should be perceived as a by-product.
1.2. The aim of the paper. We plan to: (A) revisit non-deterministic (tree) automata and their behaviour in the coalgebraic context of systems whose type is a monad, (B) provide a type monad suitable for modelling (in)finite behaviour of general systems, (C) present a setting for defining (in)finite behaviour for abstract automata whose type is a monad, (D) state and prove coalgebraic Kleene theorems for (ω-)regular behaviour, (E) put probabilistic automata into the framework. The first point is achieved in Section 3 by describing non-deterministic (tree) automata and their finite and infinite behaviour in terms of different coalgebraic (categorical) fixpoint constructions calculated in the Kleisli category for a suitable monad. Section 3 serves as a motivation for the framework presented later in Section 4 and Section 5.
Originally [Has06,SW13], coalgebras with internal moves were considered as systems X → T F ε X for a monad T and an endofunctor F , where F ε F + Id. Under some conditions the functor T F ε can be embedded into the monad T F * , where F * is the free monad over F [Bre15]. The monad T F * is sufficient to model systems with internal moves and their finite behaviour [BMSZ15,Bre15,BMP15]. However, it will prove itself useless in the context of infinite behaviour. Hence, by revisiting and tweaking the construction of T F * from [Bre15], Section 4 gives a general description of the monad T F ∞ , the type functor T F (or T F ε ) embeds into, which is used in the remaining part of the paper to model the combination of finite and infinite behaviour. The reason why we find the expressive power of T F ∞ suitable is the following: the object F ∞ X is defined for any X as the carrier of the coproduct of the free algebra F * X over X and the algebra F ω obtained by inversing the final coalgebra map. Hence, by slighty abusing the notation, we can write F ∞ = F * ⊕ F ω .
Item (C) in the above list is achieved by using two fixpoint operators: the saturation operator (−) * and a new operator (−) ω defined in the Kleisli category for a given monad. The combination of (−) * and (−) ω allows us to define infinite behaviour with BAC. Kleene-type theorems of (D) are a direct consequence of the definitions of finite and infinite behaviour with BAC using (−) * and (−) ω .
Finally, in Section 6 we put probabilistic automata into the framework of (in)finite behaviour for systems whose type is a monad.
This paper is an extended version of [Bre18] with all missing proofs and additional Section 6 where probabilistic automata are considered.

Basic notions
We assume the reader is familiar with basic category theory concepts like a category, a functor, an adjunction. For a thorough introduction to category theory the reader is referred to [ML78]. See also e.g. [Bre14,Bre15,BMP15] for an extensive list of notions needed here.
2.1. Non-deterministic automata. The purpose of this subsection and the next one is to recall basic definitions and properties of non-deterministic automata and their tree counterparts: an automaton, its (ω-)language and Kleene theorems for regular and ω-regular languages. Note that the aim of this paper is to take these notions and statements and generalize them to the categorical setting.
Classically, a non-deterministic automaton, or simply automaton, is a tuple Q = (Q, Σ, δ, q 0 , F), where Q is a finite set of states, Σ is a finite set called alphabet, δ : Q × Σ → P(Q) a transition function and F ⊆ Q set of accepting states. We write q 1 a → q 2 if q 2 ∈ δ(q 1 , a). There are two standard types of semantics of automata: finite and infinite. The finite semantics of Q is defined as the set of all finite words a 1 . . . a n ∈ Σ * for which there is a sequence of transitions q 0 a 1 → q 1 a 2 → q 2 . . . q n−1 an → q n which ends in an accepting state q n ∈ F [HMRU00]. The infinite semantics, also known as the ω-language of Q, is the set of infinite words a 1 a 2 . . . ∈ Σ ω for which there is a run r = q 0 → q 3 . . . for which the set of indices {i | q i ∈ F} is infinite, or in other words, the run r visits the set of final states F infinitely often. Often in the literature, in order to emphasize that the infinite semantics is taken into consideration the automata are referred to as Büchi automata [PP04]. In our work we consider (Büchi) automata without the initial state specified and define the (ω-)language in an automaton for any given state (see Section 3 for details).
2.1.1. Kleene theorems. Finite and infinite semantics of non-deterministic automata can be characterized in terms of two Kleene theorems (see e.g. [HMRU00,PP04]). The first statement is the following. A language L ⊆ Σ * is a language of finite words of an automaton Q (a.k.a. regular language) if and only if it is a rational language, i.e. it can be obtained from languages of the form ∅ and {a} for any a ∈ Σ by a sequence of applications of finite union, concatenation and Kleene star operation with the latter two given respectively by: R * {w 1 . . . w n | w i ∈ R and n = 0, 1, . . .}, The second Kleene theorem focuses on ω-languages. A language L ω ⊆ Σ ω is an ωlanguage (a.k.a. ω-regular language) of an automaton Q if and only if it is ω-rational, i.e. it can be written as a finite union where L i , R i are regular languages, the language R ω i ⊆ Σ ω is given by 1 : 2.2. Tree automata. There are several other variants of input for non-deterministic Büchi automata known in the literature [PP04,GTW02]. Here, we focus on non-deterministic (Büchi) tree automaton, i.e. a tuple (Q, Σ, δ, F), where δ : Q × Σ → P(Q × Q) and the rest is as in the case of standard non-deterministic automata. The infinite semantics of this machine is given by a set of infinite binary trees with labels in Σ for which there is a run whose every branch visits F infinitely often [PP04,GTW02]. We recall these notions here below (with minor modifications to suit our language) and refer the reader to e.g. [PP04] for more details.
2.2.1. Trees. Formally, a binary tree or simply tree with nodes in A is a function t : P → A, where P is a non-empty prefix closed subset of {l, r} * . The set P ⊆ {l, r} * is called the domain of t and is denoted by dom(t) P . Elements of P are called nodes. For a node w ∈ P any node of the form wx for x ∈ {l, r} is called a child of w. A tree is called complete if all nodes have either two children or no children. The height of a tree t is max{|w| | w ∈ dom(t)}.
Elements of fr(t) are called leaves. Nodes from dom(t) \ fr(t) are called inner nodes. The outer frontier of t is defined by fr + (t) {wl, wr | w ∈ dom(t)} \ dom(t). I.e. it consists of all the words wi / ∈ dom(t) such that w ∈ dom(t) and i ∈ {l, r}. Finally, set dom + (t) dom(t) ∪ fr + (t).
Let T Σ X denote the set of all complete trees t : P → Σ+X with inner nodes taking values in Σ and which have a finite number of leaves, all from the set X. Note that trees from T Σ X of height 0 can be thought of as elements of X. Hence, we may write X ⊆ T Σ X. Moreover, trees of height 1 can be viewed as elements from Σ × X × X. Thus, which assigns to t ∈ T Σ X the tree obtained from t by replacing any occurrence of a leaf x ∈ X with f (x) ∈ Y . This turns T Σ (−) into a Set-endofunctor. For two functions f : X → T Σ Y and g : Y → T Σ Z we may naturally define g · f : X → T Σ Z for which (g · f )(x) is a tree obtained from f (x) with every occurence of a variable y ∈ Y replaced with the tree g(y) ∈ T Σ Z. It is a simple exercise to prove that · is associative. Moreover, if we denote the function X → T Σ X; x → x by id then id · f = f · id.
1 Our definition of R ω i and the one presented in e.g. [PP04] differ slightly on Ri with ε ∈ Ri. Indeed, in loc. cit., R ω i = {w1w2 . . . | wi ∈ Ri and wi = ε}. This small difference does not change the formulation of the Kleene theorem. We choose our definition of (−) ω because it can be viewed as the greatest fixpoint of a certain assignment. See the following sections for details. This follows from the fact that T Σ is a monad and g · f is, in fact, the Kleisli composition for T Σ (see Example 4.9 for details). Finally, T * Σ X ⊆ T Σ X and T ω Σ X ⊆ T Σ X are sets of finite and infinite trees from T Σ X respectively. Note that trees in T ω Σ X have no leaves, hence T ω Σ X = T ω Σ ∅ for any set X.

2.2.2.
Büchi tree automata and their languages. Let Q = (Q, Σ, δ, F) be a tree automaton. A run of the automaton Q on a finite tree t ∈ T Σ 1 starting at the state s ∈ Q is a map r : dom + (t) → Q such that r(ε) = s and for any x ∈ dom(t) \ fr(t) we have (r(xl), r(xr)) ∈ δ(r(x), t(x)).
We say that the run r is successful if r(w) ∈ F for any w ∈ fr + (t) for the tree t. The set of finite trees recognized by a state s in Q is defined as the set of finite trees t ∈ T * Σ 1 for which there is a run in Q starting at s which accepts the tree t.
Finally, let t ∈ T ω Σ ∅ be an infinite tree with nodes in Σ. An infinite run for t starting at s ∈ Q is a map r : {l, r} * → Q such that r(ε) = s and: (r(xl), r(xr)) ∈ δ(r(x), t(x)) for all x ∈ {l, r} * . The tree t is said to be recognized by the state s in Q if there is a run r for t which start at s and for each path in t some final state occurs infinitely often [PP04].
2.2.3. Rational tree languages. Rational tree languages are analogues of rational languages for non-deterministic automata. Akin to the standard case, they are defined as sets of trees obtained from trees of height ≤ 1 by a sequence of applications of: finite union, composition and Kleene star closure. However, the non-sequential nature of trees requires us to consider composition of rational trees with more than one variable.
Formally, for any subset T ⊆ X → T Σ X we define T * by T * n T n , where T 0 = {id} and T n = T n−1 ∪ {t · t | t ∈ T n−1 and t ∈ T }. For any natural number n ∈ {0, 1, . . .} we slightly abuse the notation and put n {1, . . . , n} and define Rat(1, n) to be the smallest family of subsets of T Σ n which satisfies: where t is of height less than or equal to 1, • if T ∈ Rat(1, n) and T 1 , . . . , T m ∈ Rat(1, m) then: • if T ∈ Rat(1, n) then for any i ∈ n: It is easy to check that if we extend the definition of Rat and put Rat(m, n) m → Rat(1, n) then the last item in the above list implies that for any T ∈ Rat(n, n) we have T * ∈ Rat(n, n). Now for T ⊆ n → T * Σ n we define T ω as the subset of n → T ω Σ ∅ consisting of common extensions of functions in T k for any k. Finally, the ω-rational subset of trees is defined by [PP04]: ωRat {T ω · T | T ∈ Rat(n, n) and T ∈ Rat(1, n)}, where T · T {t · t | t ∈ T, t ∈ T }. 2.2.4. Kleene theorems. Let Reg be the set of subsets of trees from T * Σ 1 for which there is an automaton accepting the given set of trees. Similarly, we define the set ωReg of infinite trees accepted by the tree automata. In this case the Kleene theorems for regular and ω-regular input are respectively given by [PP04]: Reg = Rat(1, 1) and ωReg = ωRat.
In Section 3 we will show that Kleene theorems for non-deterministic automata and tree automata are instances of a generic pair of theorems formulated on a categorical level.
2.3. Algebras and coalgebras. Let F : C → C be a functor. An F -coalgebra (F -algebra) is a morphism α : A → F A (resp. a : F A → A). The object A is called a carrier of the underlying F -(co)algebra. Given two coalgebras α : A → F A and β : The category of all F -coalgebras (F -algebras) and homomorphisms between them is denoted by CoAlg(F ) (resp. Alg(F )). We say that a coalgebra ζ : Example 2.1. Let Σ be a set of labels. Labelled transition systems (see e.g. [San11]) can be viewed as coalgebras of the type P(Σ × Id) : Set → Set [Rut00]. Here, P : Set → Set is the powerset functor which maps any X to the set PX = {A | A ⊆ X} and any f : Non-deterministic automata as defined in Subsection 2.1 are modelled as coalgebras of the type P(Σ × Id + 1), where 1 = { } (e.g. [HJS07]). Indeed, any non-deterministic automaton (Q, Σ, δ, F) is modelled by α : Q → P(Σ × Q + 1) where: In a similar manner, we can model tree automata coalgebraically, i.e. as coalgebras of the type Q → P(Σ × Q × Q + 1).
Example 2.2. Fully probabilistic processes [BH97] sometimes referred to as fully probabilistic systems [Sok11] are modelled as D(Σ × Id)-coalgebras [Sok11]. Here, D denotes the subdistribution functor assigning to any set X the set {µ : X → [0, 1] | x µ(x) ≤ 1} of subdistributions with countable support and to any map f : 2.4. Monads. For a general introduction to the theory of monads the reader is referred to e.g. [BW02,ML78]. A monad on C is a triple (T, µ, η), where T : C → C is an endofunctor and µ : T 2 =⇒ T , η : Id =⇒ T are two natural transformations for which the following diagrams commute: The transformation µ is called multiplication and the transformation η is called unit. For any monad (T : C → C, µ, η) we define the Kleisli category Kl(T ) for T has whose class of objects is the class of objects of C and for two objects X, Y in Kl(T ) we put Kl(T )(X, Y ) = C(X, T Y ) with the composition · in Kl(T ) defined between two morphisms f : X → T Y and g : Y → T Z by g · f := µ Z • T (g) • f . Since most of the time we work with two categories at once, namely C and Kl(T ), morphisms in C will be denoted using standard arrows →, whereas for morphisms in Kl(T ) we will use the symbol −→ • • . Hence, f : X−→ • • Y = X → T Y and the composition is given by We define a functor : C → Kl(T ) which sends each object X ∈ C to itself and each morphism f : of the form f for some f : X → Y ∈ C are referred to as base morphisms.
Every monad (T, µ, η) on a category C arises from the composition of a left and a right adjoint: C Kl(T ), where the left adjoint is : C → Kl(T ) and the right adjoint U T : Kl(T ) → C is defined as follows: for any object X ∈ Kl(T ) (i.e. X ∈ C) the object U T X is given by U T X := T X and for any morphism f : We say that a functor F : C → C lifts to a functor F : Kl(T ) → Kl(T ) provided that the following diagram commutes: There is a one-to-one correspondence between liftings F and distributive laws λ : F T =⇒ T F between the functor F and the monad T 2 . Indeed, any lifting F : Kl(T ) → Kl(T ) induces the transformation λ whose X-component λ X : and any distributive law λ : F T =⇒ T F gives rise to a lifting F : Kl(T ) → Kl(T ) given by: A monad (T, µ, η) on a category C with finite products is called strong if there is a natural transformation t X,Y : X × T Y → T (X × Y ) called tensorial strength satisfying the strength laws listed in e.g. [Koc72]. Existence of strength guarantees that for any object Σ the functor Σ × Id : C → C admits a lifting Σ : Kl(T ) → Kl(T ) defined as follows. For any X ∈ Kl(T ) we put ΣX := Σ × X, and for any f : Existence of the transformation t is not a strong requirement. For instance all monads on Set are strong.
2 A distributive law between a functor F and a monad T is a natural transformation F T =⇒ T F which additionally satisfies extra conditions listed in e.g. [JSS12,Mul93]. Example 2.3. The powerset endofunctor P : Set → Set, used in the definition of labelled transition systems, non-deterministic automata and tree automata, carries a monadic structure (P, , {−}) for which the multiplication and the unit are given by: The Kleisli category Kl(P) consists of sets as objects and morphisms given by the maps The identity morphisms id : The Kleisli category for P is isomorphic to Rel -the category of sets as objects, and relations as morphisms. The X-component of the distributive law λ : Σ × PX → P(Σ × X) induced by strength of P is: and η X : X → DX assigns to any x the Dirac delta distribution δ x : X → [0, 1].
Example 2.5. For any monoid (M, ·, 1) the Set-functor M × Id carries a monadic structure From the perspective of this paper, the most imporant instance of the family of monads from Example 2.5 is the monad (Σ * × Id, m, e), where (Σ * , ·, ε) is the free monoid over Σ. The reason is that Σ * × Id is the free monad over the functor Σ × Id and hence, since Σ × Id lifts to the Kleisli category for any Set-based monad T (since all Set-based monads are strong), then so does Σ * × Id whose lifting is the free monad over the lifting of Σ × Id [Bre15]. In practice, this yields a monadic structure on T (Σ * × Id) for any monad T on the category of sets [Bre15].
Example 2.6. If T = P then the Kleisli category for P(Σ * × Id) has the composition given as follows [Bre15]. For two morphisms f : The identity morphisms in this category are id : In a similar manner, using the remark above, we show that D(Σ * × Id) carries a monadic structure. 2.5. Coalgebras with internal moves. Coalgebras with internal moves were first introduced in the context of coalgebraic trace semantics as coalgebras of the type T F ε for a monad T and an endofunctor F on C with F ε defined by In [Bre15] we showed that given certain assumptions on T and F we may embed the functor T F ε into the monad T F * , where F * is the free monad over F . In particular, if we apply this construction to T = P and F = Σ × Id we obtain the monad P(Σ * × Id) from Example 2.6. The construction of T F * is revisited in this paper in Section 4. The trick of modelling the invisible steps via a monadic structure allows us not to specify the internal moves explicitly. Instead of considering T F ε -coalgebras we consider T -coalgebras for a monad T on an arbitrary category. The strategy of finding a suitable monad (for modelling the behaviour taken into consideration) will also be applied in this paper. Unfortunately, from the point of view of the infinite behaviour of coalgebras, considering systems of the type T F * is not sufficient (see Section 3 for a discussion). Hence, in Section 4 we show how to obtain a monad suitable for modelling infinite behaviour. Intuitively, the new monad extends T F * by adding an ingredient associated with the terminal F -coalgebra ζ : F ω → F F ω . The construction presented in Section 4 yields the monad T F ∞ = T (F * ⊕ F ω ) suitable to capture both: finite and infinite behaviour of systems. Below we give two examples of such monad.
Example 2.7. Although the monad P(Σ * × Id) from Example 2.6 proves to be sufficient to model finite behaviours of non-deterministic automata (see [Bre15,BMP15]), it will not be suitable to model their infinite behaviour (see Section 3 for details). Hence, we extend P(Σ * × Id) and consider the following. Let Σ ω be the set of all infinite sequences of elements from Σ. As it will be shown in sections to come, the functor P(Σ * × Id + Σ ω ) carries a monadic structure whose Kleisli composition is as follows. For f : In the above we write The identity morphisms in this category are the same as in the Kleisli category for the monad P(Σ * × Id). The monadic structure of P(Σ * × Id + Σ ω ) arises as a consequence of a general construction of monads modelling (in)finite behaviour described in detail in Section 4.
Example 2.8. If we move from non-deterministic automata towards tree automata we have to find a suitable monadic setting to talk about their (in)finite behaviour. It turns out that a good candidate for this monad can be built from the ingredients already presented in this paper. Indeed, if we take the powerset monad and the monad T Σ from Subsection 2.2.1, then their composition PT Σ carries a monadic structure 3 . The formula for the composition in the Kleisli category for the monad PT Σ is given for f : being a set of trees obtained from trees in f (x) ⊆ T Σ Y by replacing any occurence of the leaf y ∈ Y with a tree from g(y) ⊆ T Σ Z. As will be witnessed in Section 4, this monad and the monad P(Σ * × Id + Σ ω ) arise from the same categorical construction. 3 The proof of this claim can be found in Section 4. See Example 4.9 for details.

T. Brengos
Vol. 17:4 The list of examples of monads used in the paper will be extended in the upcoming sections.
2.6. Categorical order enrichment. Our main ingredients for defining (in)finite behaviours of automata will turn out to be two fixpoint operators: (−) * and (−) ω . In order to establish them on a categorical level we require the category under consideration to be suitably order enriched. A category is said to be order enriched, or simply ordered, if each hom-set is a poset with the order preserved by the composition. It is ∨-ordered if all hom-posets admit arbitrary finite (possibly empty) suprema. Note that, given such suprema exist, the composition in C does not have to distribute over them in general. We call a category left distributive (or LD in short) if it is ∨-ordered and g · ( i∈I f i ) = i∈I g · f i for any finite set I. We define right distributivity analogously. In this paper we come across many left distributive categories that do not necessarily satisfy right distributivity. Still, however, all examples of Kleisli categories taken into consideration satisfy its weaker form.
To be more precise, we say that the Kleisli category and any finite set I. We say that an order enriched category is ωCpo-enriched if any countable ascending chain of morphisms f 1 ≤ f 2 ≤ . . . with common domain and codomain admits a supremum which is preserved by the morphism composition. Finally, in an ordered category with finite coproducts we say that cotupling preserves order Remark 2.9. Right distributivity w.r.t. the base morphisms and cotupling order preservation are properties we often get as a consequence of other general assumptions. Indeed, any Set-based monad T whose order enrichment of the Kleisli category is given by where T Y is a poset for any Y 4 , satisfies these conditions. Note that, in this case, the Kleisli composition over any suprema or infima that exist is right distributive w.r.t. morphisms of the form j = η Y • j : X−→ • • Y = X → T Y for any set map j : X → Y . A similar argument applies to cotupling order preservation.
Example 2.10. The next section of this paper focuses on three categories, namely: Kl(P(Σ * × Id)), Kl(P(Σ * × Id + Σ ω )) and Kl(PT Σ ). These categories are order-enriched with the hom-set ordering given by for any x. The base morphisms of the first two examples are of the form for a set map j : X → Y . The base morphisms of the third example are given by X → PT Σ Y ; x → {j(x)}. We leave it as an exercise to the reader to verify that all these examples satisfy the following conditions: the order enrichment is pointwise induced; they are ωCpoenriched; their hom-sets are complete lattices; they are left distributive 5 . These conditions play a central role in defining (in)finite behaviours on a coalgebraic level. We will elaborate more on them in Section 5. 2.7. Lawvere theories. The primary interest of the theory of automata and formal languages focuses on automata over a finite state space. Hence, since we are interested in systems with internal moves (i.e. coalgebras X → T X for a monad T ), without loss of generality we may focus our attention on coalgebras of the form n → T n, where n = {1, . . . , n} with n = 0, 1, . . .. These morphisms are endomorphisms in a full subcategory of the Kleisli category for T , we will later refer to as (Lawvere) theory. Restricting the scope to this category instead of considering the whole Kleisli category for a given monad plays an important role in Kleene theorems characterizing regular and ω-regular behaviour (see e.g. [HMRU00,PP04]). Formally, a Lawvere theory, or simply theory, is a category whose objects are natural numbers n ≥ 0 such that each n is an n-fold coproduct of 1. The definition used here is dual to the classical notion [Law63] and can be found in e.g. [ÉK11,ÉK13,EH09]. The reason why we use our version of the definition is the following: we want the connection between Lawvere theories and Kleisli categories for Set-based monads to be as direct as possible. Indeed, in our case, any monad T on Set induces a theory T associated with it by restricting the Kleisli category Kl(T ) to objects n for any n ≥ 0. Conversely, for any theory T there is a Set based monad the theory is associated with (see e.g. [HP07] for details). This remark also motivates us to use the notation introduced before and denote morphisms from a theory by −→ • • .
For any element i ∈ n let i n : 1−→ • • n denote the i-th coproduct injection in the diagram on the right. The coprojection morphism n i −→ • • n 1 + · · · + n k into the i-th component of the coproduct will be denoted by in n i n 1 +···+n k . Any morphism k−→ • • n of the form [(i 1 ) n , . . . , (i k ) n ] : k−→ • • n for i j ∈ n is called base morphism or base map. If T is associated with a monad T then the base morphisms in T are exactly given by f : m−→ • • n = m → T n for Set-maps f : m → n. Finally, let ! : n−→ • • 1 be defined by ! [1 1 , 1 1 , . . . , 1 1 ]. We say that a theory T is a subtheory of T if there is a faithful functor T → T which maps any object n onto itself.

Non-deterministic automata, coalgebraically
The purpose of this section is to give motivations for the abstract theory presented in the remainder of the paper. In the first part of this section we focus on finite non-deterministic (Büchi) automata and their (in)finite behaviour from the perspective of the categories Kl(P(Σ * × Id)) and Kl(P(Σ * × Id + Σ ω )). Afterwards, we deal with tree automata and their behaviour. Finally, we give a categorical perspective on Kleene theorems for automata taken into consideration.
3.1. Non-deterministic automata. Without any loss of generality we may only consider automata over the state space n = {1, . . . , n} for some natural number n. As mentioned in Example 2.1 any non-deterministic automaton (n, Σ, δ, F) may be modelled as a P(Σ × Id + 1)−coalgebra n → P(Σ × n + 1) [Rut00]. However, as it has been already noted in [USH16], from the point of view of infinite behaviour with BAC it is more useful to extract the information about the final states of the automaton and not to encode it into the transition 24:14

T. Brengos
Vol. 17:4 map as above. Instead, given an automaton (n, Σ, δ, F) we encode it as a pair (α, F) where α : n → P(Σ × n) is defined by α(i) = {(a, j) | j ∈ δ(a, i)} and consider the map: Note that by extending the codomain of α and f F both maps can be viewed as endomorphisms in LTS and LTS ω . The purpose of f F is to encode the set of accepting states with an endomorphism in the same Kleisli category in which the transition α is an endomorphism. Now, we have all the necessary ingredients to revisit finite and infinite behaviour (with BAC) of non-deterministic automata from the perspective of the theories LTS and LTS ω .
where the order is as in Example 2.11. We have [Bre15]: Let us observe that the theory morphism ! : n−→ • • 1 is explicitly given in the case of theories LTS and LTS ω by Since P(Σ * × 1) ∼ = P(Σ * ), the set ! · f F · α * (i) represents the set of all finite words accepted by the state i in the automaton (n, Σ, δ, F).
3.1.2. Infinite behaviour. Note that the hom-posets of theories LTS and LTS ω are complete lattices and, hence (by the Tarski-Knaster theorem), come equipped with an operator which assigns to any endomorphism β : n−→ • • n the morphism β ω : n−→ • • 0 defined as the greatest fixpoint of the assignment x → x · β. Now, if α is given as in the previous subsections and considered as an endomorphism in the theory LTS then the map α ω : n−→ • • 0 = n → P(Σ * ×∅) in LTS satifies α ω (i) = ∅. However, if we consider α to be an endomorphism in LTS ω and compute α ω : n−→ • • 0 = n → P(Σ * × ∅ + Σ ω ) = n → P(Σ ω ) in LTS ω the result will be different. Indeed, we have the following.
Proposition 3.1. Let β : n → P(Σ * × n) and, since P(Σ * × n) ⊆ P(Σ * × n + Σ ω ), it can be considered as an endomorphism in LTS ω . In this case, the explicit formula for the greatest fixpoint β ω : n−→ • • 0 = n → P(Σ ω ) of the assignment x → x · β calculated in LTS ω is given by: where | − | : (Σ * ) ω → P(Σ ω ) assigns to any sequence σ 1 , σ 2 , . . . of words over Σ the set Proof. At first let us note that we may assume β = β * · β. This is a consequence of the fact that β ω = (β * · β) ω6 . Restated, this condition means that for any i, j, k ∈ n we have: be a map whose value β o (i) is given in terms of the right hand side of the equality 3.1. Observe that this map satisfies β o = β o · β in LTS ω . This follows directly from the definition of β o and the formula for the composition in Kl(P(Σ * × Id + Σ ω )).
Hence, in particular, this means that there is an infinite sequence of transitions i If it was otherwise, then by 3.2 we would have an infinite sequence i . By inductively repeating this argument we get a sequence i Thus, by the definition of β o we also get v ∈ β o (i) which is a contradiction.
The above statement suggests a general approach towards modelling (ω-)behaviours of abstract (coalgebraic) automata which we will develop in the sections to come. 3.2. Tree automata. Let us now focus our attention on tree automata and their behaviour. Just like in the previous subsection we may consider automata over the state space n. Moreover, as before, we also encode any tree automaton (n, Σ, δ, F) as a pair (α : n → P(Σ × n × n), F). Since P(Σ × n × n) ⊆ PT Σ n, the transition map α can be viewed as α : n → PT Σ n (i.e. as an endomorphism in the Kleisli category for the monad PT Σ or, equivalently, as an endomorphism in the theory TTS ω ). The hom-sets of the Kleisli category for PT Σ and its full subcategory TTS ω admit ordering in which we can define β * , β + and β ω for any β : n−→ • • n as in the previous subsection. Not surpisingly, if we now compute ! · f F · α * and (f F · α + ) ω in TTS ω we exactly get the following 7 .
Proposition 3.2. For any i ∈ n we have: ! · f F · α * (i) = the set of finite trees recognized by i in (n, Σ, δ, F), 3.3. Kleene theorems, categorically. The purpose of this subsection is to restate classical Kleene theorems from Subsection 2.1 on the categorical level for LTS ω and TTS ω . Before we do this let us elaborate more on why we choose our setting to be systems whose type is a monad.

Remark 3.3.
As the examples of non-deterministic (tree) automata studied in the previous subsection do not admit silent moves, the reader may get an impression that the need for categorical modelling of infinite behaviour for systems with silent steps is not sufficiently justified. To add to this, although ε-moves are a standard feature of automata whenever it comes to their finitary languages, invisible moves rarely occur in practice in the classical literature on the infinite behaviour (with BAC) (see e.g. [PP04]). However, as already mentioned in the introduction, incorporation of silent moves should be viewed as a byproduct of our paper's framework, not its main purpose. The main aim is to build a simple bridge between syntax and semantics of regular and ω-regular behaviours in the form of generic Kleene theorems. Once we embed our systems into systems whose type is a monad T , the syntax arises from the algebraicity of T and the semantics is provided by automata whose transition maps are certain T -coalgebras. This also allows us to abstract away from several "unnecessary" details and focus on core properties.
As witnessed in Subsection 2.1, Kleene theorems for tree automata were slightly more involved than their classical counterparts for non-deterministic automata. The reason for this is simple: non-deterministic automata accept sequential data types. Whenever we deal 7 The proof of Proposition 3.2 is intensionally omitted as it goes along the lines of the series of statements made in Subsection 3.1 for non-deterministic automata. with non-sequential data, e.g. trees, the set of (ω-)regular languages is expected to be closed under a more complex type of composition, i.e. the composition of regular languages with multiple variables [GTW02,PP04]. Hence, if we aim at categorical statements generalizing theory from Subsection 2.1 then we should expect a slightly more involved formulation to be our point of reference. Hence, we start with presenting a categorical perspective of Kleene theorems for tree automata first.
3.3.1. Tree automata. The Kleene theorems for regular and ω-regular input from Subsection 2.2.4 are equivalent to the following proposition. Then the hom-set Rat(1, 1) of the theory Rat equals to Reg. Moreover, the set ωReg of ω-regular languages for tree automata satisfies {r ω · s | r ∈ Rat(n, n), s ∈ Rat(1, n)} = ωReg.

3.3.2.
Non-deterministic automata. The formulation of Proposition 3.4 allows us to instantiate it for non-deterministic automata. A simple verification proves that the following holds.
Then the hom-set Rat(1, 1) of the theory Rat equals to: Additionally, the set ωReg {r : 1−→ • • 0 = 1 → P(Σ ω ) | r(1) is ω-regular} satisfies: 3.4. Beyond tree automata. There are variants of non-deterministic (Büchi) automata that accept other types of input (e.g. arbitrary finitely-branching trees, see e.g. [USH16]). In general, given a functor F : Set → Set we define a non-deterministic (Büchi) F -automaton as a pair (α, F), where α : n → PF n and F ⊆ n. A natural question that arises is the following: are we able to build a general categorical setting in which we can reason about the (in)finite behaviour of systems for arbitrary non-deterministic Büchi F -automata (or even more generally, for systems of the type T F for a monad T )? If so, then is it possible to generalize the Kleene theorem for (ω−)regular languages to a coalgebraic level? We will answer these questions positively in the next sections.

Monads for (in)finite behaviour
Given a monad T and an endofunctor F on a common category, the purpose of this section is to provide a construction of a monad T F ∞ which extends the functor T F . The monad T F ∞ will prove itself sufficient to model the combination of finite and infinite behaviour (akin to the monad P(Σ * × Id + Σ ω ) for the functor P(Σ × Id), or PT Σ for P(Σ × Id 2 )).
At first we list all assumptions required in the remainder of this section. Later, in Subsection 4.2, we revisit the construction of the monad T F * from [Bre15]. Finally, we give a description of T F ∞ .
Assumption 4.1. Let C be a category which admits binary coproducts. We denote the coproduct operator by + and the coprojection into the first and the second component of a coproduct by inl and inr respectively. Moreover, let F : C → C be a functor. In what follows, in this section we additionally assume: (i) (T, µ, η) is a monad on C and F : C → C lifts to Kl(T ) via a distributive law λ : F T =⇒ T F , (ii) there is an initial F (−) + X-algebra for any object X and a terminal F -coalgebra ζ : F ω → F F ω , (iii) the category Alg(F ) of F -algebras admits binary coproducts (with the coproduct operator denoted by ⊕).

4.1.
Preliminaries. The initial F (−) + X-algebra i X : F F * X + X → F * X yields the free F -algebra over X given by i X • inl : F F * X → F * X. Hence, by our assumptions we have an adjoint situation C Alg(F ), where the left adjoint is the free algebra functor which assigns to any object X the free algebra i X • inl over it. The right adjoint is the forgetful functor which assigns to any F -algebra its carrier and is the identity on morphisms. The adjunction yields the monad F * : C → C which assigns to any object X the carrier of the free F -algebra over X.
Example 4.2. For any set Σ and X the initial Σ × Id + X-algebra is given by the morphism i X : Σ × Σ * × X + X → Σ * × X, where i X (a, (σ, x)) = (aσ, x) and i X (x) = (ε, x). 4.1.1. Bloom algebras. The purpose of this subsection is to recall basic definitions and properties of Bloom F -algebras [AHM14] whose free algebras yield a monad F ∞ on C which extends the functor F . This will allow us to embed systems of the type X → T F X to systems of the type X → T F ∞ X and discuss their (in)finite behaviour in the latter context.
A pair (a : F A → A, (−) † ) is called a Bloom F -algebra provided that any F -coalgebra e : X → F X yields the map e † : X → A which satisfies: ] : X → F ω between e and ζ, is an initial object in Alg B (F ). Moreover, the F -algebra coproduct is the free Bloom algebra over X.
Remark 4.4. Let F ∞ : C → C be defined as the composition of the left and right adjoints C Alg B (F ), where the left adjoint is the free Bloom algebra functor and the right adjoint is the forgetful functor. The functor F ∞ carries a monadic structure which extends F * . Indeed, by Theorem 4.3, the monad F * is a submonad of F ∞ (via the transformation induced by the coprojection into the first component of i X • inl ⊕ ζ −1 in Alg(F )). The formula for the free Bloom algebra from the above theorem indicates that F ∞ is a natural extension of F * encompassing infinite behaviours of the final F -coalgebra. By abusing the notation slightly, we can write The functor F ε is a subfunctor of F * [Bre15, Lemma 4.12] and hence, by the above, also of F ∞ . In the following sections this will let us turn any coalgebra X → T F X or X → T F ε X into a system X → T F ∞ X and, by doing so, allow us to model their (in)finite behaviour.
The above theorem together with the assumption of existence of an arbitrary free F -algebra in Alg(F ) leads to a pair of adjoint situations captured by the diagram on the right. Since the composition of adjunctions is an adjunction this yields a monadic structure on the functor T F * : C → C.
Example 4.7. An example of this phenomenon is given by the monad P(Σ * × Id) from Example 2.6 where in the above we set T = P and F = Σ × Id. This monad has already been described e.g. in [Bre15], but it arose as a consequence of the composition of a different pair of adjunctions.

Monads on Bloom algebras.
Above we gave a recipe for a general construction of a monadic structure on the functor T F * . As witnessed in [Bre15,BMSZ15], this monad is suitable to model coalgebras and their weak bisimulations and weak finite trace semantics (i.e. their finite behaviour). Our primary interest is in modelling infinite behaviour and this monad proves itself insufficient. The purpose of this subsection is to show how to tweak the middle category from the pair of adjunctions in pictured in the diagram above so that the monad obtained from the composition of two adjunctions is suitable for our needs. Let  adjunctions impose a monadic structure on the functor T F ∞ : C → C. The monad P(Σ * × Id + Σ ω ) from Example 2.7 arises from the composition of the above adjoint situations (see also Example 4.5).
Example 4.9. Let F = Σ×Id 2 . This functor lifts to Kl(P) [HJS07] and, up to isomorphism, F ∞ = T Σ is a functor which assigns to any set X the set of complete binary trees (i.e. every node has either two children or no children) with inner nodes taking values in Σ and finitely many leaves, all taken from X [AHM14] (see Subsection 2.1). This yields a monadic structure on PF ∞ = PT Σ defined in Example 2.8.

Vol. 17:4 A COALGEBRAIC TAKE ON REGULARAND ω-REGULAR BEHAVIOURS 24:21
The above example can be easily generalized. Indeed, if T is a commutative Set-based monad then any polynomial functor 8 F : Set → Set lifts to Kl(T ) [HJS07]. If it admits all free F -algebras and the final F -coalgebra then Assumption 4.1 holds for T and F yielding the monad T F ∞ .

Abstract automata and their behaviour
The purpose of this section is to generalize the concepts from Section 3 to an arbitrary Kleisli category with a suitable ordering. In other words, given a Set-monad T , we define a T -automaton, its finite behaviour, its infinite behaviour with BAC and provide generic Kleene theorems for T .
Let (T, µ, η) be a Set-based monad. Since we will often consider the Lawvere theory T associated with it, recall that its objects are sets given by n = {1, . . . , n} for n = 0, 1, . . .. We start with the definition of a T -automaton.
Definition 5.1. A T -automaton or simply automaton is a pair (α, F), where α : X−→ • • X = X → T X is a T -coalgebra called transition morphism and F ⊆ X.
Assumption 5.2. In order to define finite and infinite behaviour of (α, F) and reason about it we require the Kleisli category for T to satisfy more assumptions. In this section we assume that: (A) Kl(T ) is order enriched with a pointwise induced order, (B) it is ωCpo-enriched, (C) it is left distributive, (D) its hom-sets are complete lattices.
At first let us note that, in the light of Remark 2.9, by (A) we get: • right distributivity w.r.t. the base morphisms and • cotupling order preservation. Additionally, since the Kleisli category for T is left distributive we have: • the bottoms ⊥ X,Y ∈ Kl(T )(X, Y ) satisfy g· ⊥ X,Y =⊥ X,Z for any g : Y −→ • • Z. The axioms (A)-(C) guarantee that the saturation α → α * is computable in ω-steps and is expressive enough. For a given α : X−→ • • X = X → T X we can define maps α * , α + : and α + α * · α. The operator α → α * was thoroughly studied in [Bre14,Bre15,BMP15,BP16] in the context of coalgebraic weak bisimulation. Its definition does not require a complete lattice order. See loc. cit. for a discussion.
Assumption (D) allows us to define the greatest fixpoint of the map x → x · α. Indeed for any α : X−→ • • X = X → T X put α ω : X−→ • • 0 = X → T 0 to be: where : X−→ • • 0 = X → T 0 is the greatest element of Kl(T )(X, 0) and is defined in terms of the transfinite induction by for a successor ordinal κ + 1 and the ordinary map composition operator •, and (x → x · α) κ λ<κ (x → x · α) λ for a limit ordinal κ. By the Tarski-Knaster theorem, the map α ω : X−→ • • 0 = X → T 0 is the greatest fixpoint of the assignment x → x · α.
Example 5.3. The Kleisli categories for the monads from Example 2.10 satisfy (A)-(D). Section 6 presents one more example of a Kleisli category that fits the setting in the context of probabilistic automata.
Before we present the definition of finite and infinite behaviour of automata we need one more technical result.

Additional remarks.
Our approach to defining semantics for coalgebras seems to diverge slightly from the established coalgebraic takes known from e.g. [HJS07,SW13,BMSZ15,USH16]. The purpose of this subsection is to compare our setting with the frameworks presented in the literature and try to justify the (slight) differences. Our approach builds on top of two fixpoint operators, namely (−) * and (−) ω . The choice of these two operators, and not other (e.g. the dagger operator from [ÉK11,BMSZ15]) follows from the premise that we wanted to make the connection with the classical results in regular and ω-regular languages as clear and as direct as possible. As we witness here, the classical Kleene star operation and (−) ω [PP04] prove to have their general categorical counterparts.
It may not be clear to the reader why the finite and ω-behaviour maps have different codomains, i.e. the former is a map X−→ • • 1 and the latter X−→ • • 0. Let us focus on the finite behaviour first. So far in the coalgebraic literature, finite behaviour of systems was introduced in terms of finite trace [SW13,BMSZ15,JSS12]. In the setting of systems X → T F X it is obtained in terms of the initial algebra-final coalgebra coincidence [HJS07,BMSZ15]. When translated to the setting of systems with internal moves, the finite trace is given by µx.x · α : X−→ • • 0 and is calculated in the Kleisli category for the monad T F * [Bre14,Bre15]. However, this holds for coalgebras whose type monad encodes accepting states. From the point of our setting, the accepting states are not part of the transition and are encoded in terms of F ⊆ X instead. The direct use of initial algebra-final coalgebra coincidence makes no sense here, as the initial algebra would simply be degenerate. Luckily, there is a simple formal argument showing that our approach from this paper and the aforementioned approach established in the coalgebraic literature coincide. For the monad T and a T -automaton (α, F) consider the monad T (Id + 1) 9 and the map X → T (X + 1) defined for any It is a simple exercise to prove that the least fixpoint µx.x · (α ∨ χ F ) : X−→ • • 0 = X → T (0 + 1) = X → T 1 calculated in Kl(T (Id+1)) is the same as the finite behaviour map ||α, F|| : X−→ • • 1 = X → T 1 calculated in Kl(T ). Therefore, our definition of finite behaviour via (−) * coincides with the coalgebraic finite trace semantics via µx.x · α.
The finite behaviour of a state of an automaton from Definition 5.5 is of type 1−→ • • 1. We argue that this map should be viewed as a generalization of a finitary language. Classically, 9 It can be easily verified that for any monad T the functor T (Id + 1) carries a monadic structure. It follows from the fact that the exception monad Id + E induces an exception monad transfomer T → T (Id + E).

T. Brengos
Vol. 17:4 these languages have been considered in some algebraic context, e.g. with the familiar algebraic operations of concatenation, Kleene start closure and finite union. These operations considered on our abstract categorical level directly translate into morphism composition, saturation and finite joins of endomorphisms 1−→ • • 1 respectively. As far as the infinite behaviour is concerned, it should be noted here that our prototypical example of a monad is T F ∞ = T (F * ⊕ F ω ) from Section 4. By Theorem 4.3 the object (F * ⊕ F ω )(0) = F ω is the carrier of the terminal F -coalgebra ζ : F ω → F F ω making T F ∞ 0 = T F ω . This is exactly what we expect to have as a codomain of an infinite trace map (see also for comparison [USH16,Cîr10]).
Additionally, the type of the infinite behaviour of a state of an automaton is 1−→ • • 0 and it reflects the partial algebraic nature of (in)finitary languages. In particular, it makes sense to compose ( 5.3. Kleene theorems. The purpose of this part of the paper is to state and prove Kleene theorems akin to Proposition 3.4 and 3.5. These theorems require us to work with finite automata and their behaviour, so we will restrict the setting of this subsection to the Lawvere theory T associated with the monad T .
The set A plays a role of a set of admissible transition functions for automata taken into consideration. A T -automaton (α, F) whose transition α : n−→ • • n is an arrow in T is called A-automaton if α ∈ A.
Example 5.7. In the case of our leading examples of theories, namely LTS ω and TTS ω , the prototypical choice for A was given in condition (a) in Proposition 3.5 and 3.4 respectively.
Definition 5.8. The set of regular morphisms m−→ • • p ∈ T is defined by: The set of regular morphisms Reg(1, p) will be often referred to as the set of regular trees with variables in p. Note that Reg(1, 1) is exactly the set of finite behaviours of states in A-automata.
We list the statements without proofs which we later provide in Subsection 5.3.1.
Lemma 5.9. The identity maps in T are regular morphisms. Moreover, regular morphisms are closed under composition from T. The above lemma precisely says that the collection of objects n = 0, 1, . . . with morphisms Reg(m, n) forms a category with the composition taken from T. We denote this category by Reg(A). We have the following. Finally, we define Theorem 5.11 (Kleene theorem for ω-regular behaviour). We have ωRat(A) = ωReg(A).

5.3.1.
Proofs. The purpose of this subsection is to present the proofs of the statements above. Before we proceed we would like to make a remark concerning the material presented here and its originality. Several Kleene theorems (akin to Theorem 5.10) have been presented and proven in the literature on the level of iteration theories (see e.g. [Ési97, BE93, EH09, ÉK11, ÉK13]). According to our knowledge, due to minor differences in the formulation, the theorems presented in our paper do not fit directly into any existing setting. However, the classical proof techniques used in loc. cit. are still applicable here. These methods are based on using well know properties satisfied by a fixpoint operator. We recall them here and present detailed proofs of our statements. We additionally use string diagrams as a visual aid to help the reader understand the techniques better.
In order to proceed with the proofs we need to introduce some new notions and define a notation used below. We start off by defining [A] to be the set of morphisms from T obtained by (pre-and post-)composing maps from A with base morphisms with suitable domains and codomains: [A] {i · α · j | α : n−→ • • n ∈ A and i : n−→ • • p, j : m−→ • • n are base maps}.
Moreover, since the proofs presented below use the identity GSPI which requires an extended definition of the saturation operator, for any morphism α : n−→ • • n + p we define: Hence, if p = 0 then α ⊗ = α * for α : n−→ • • n + p.

24:26
T. Brengos Vol. 17:4 String diagram notation. Let us now develop a string diagram notation which will clarify the proofs considerably.
Remark 5.12. It is important to emphasize that the purpose of the new notation is to build a visual aid to the technical statements made below. The reader should note that all proofs presented here are written so that the knowledge of the string diagram calculus is not required. However, given the complexity of some of the (in)equalities used, we strongly believe that the diagrammatic notation improves their readability (conf. e.g. GSPI and its diagrammatic representation). Hence, we decide to proceed with its introduction.
We adopt the standard string diagram calculus for monoidal categories [Sel11,FS18] which will be tailored to our purposes. A morphism f : m−→ • • n is depicted by We will often drop the (co)domain types from the notation and depict f simply by f . If f : m−→ • • n + p and the coproduct codomain needs to be emphasized by the diagram notation then we depict f by f . This generalizes to m 1 + · · · + m k −→ • • n 1 + · · · + n l in an obvious manner. Whenever f : m−→ • • n and g : n−→ • • p then the composition g · f : m−→ • • p is f g . Given two maps f : m 1 −→ • • n 1 and g : m 2 −→ • • n 2 the coproduct f + g : Given any endomorphism α : n−→ • • n we depict the saturated map α * by α .
By slightly abusing the notation we extend it to the generalized saturation (−) ⊗ operator and for any α : n−→ • • n + p denote α ⊗ : n−→ • • n + p diagrammatically by: α n n p .
We will use a separate notation to denote special morphisms. The identity map id : n−→ • • n is depicted by , the maps ⊥ 0,m : 0−→ • • m and ⊥ m,0 : m−→ • • 0 by and respectively. Since by Assumption (C) we have ⊥ m,n =⊥ 0,n · ⊥ m,0 we depict ⊥ m,n by . Additionally, since the map in m m+n : m−→ • • m+n satisfies in m m+n = id m + ⊥ 0,n , its diagrammatic representation is . The cotuple string diagram notation has already been presented in Subsection 2.7. However, since the the cotuple We are now ready to list some basic observations and remarks about the diagram calculus introduced above. First of all note that by the properties of saturation the following diagram (in)equalities hold: Moreover, since ⊥ satisfies f · ⊥=⊥ (Assumption (C)) for any f , we have: which diagrammatically is represented in terms of the following identity: In the above, the right hand side of the equality, namely , is the composition of and .
This completes the proof of the lemma.
We are now ready to proceed with the proof of Theorem 5.11.
Proof. (Theorem 5.11) We have as it is enough to note that and take r = f F · α + · i n , r k = f F · α + · k n . Conversely, let r, r i ∈ Reg(1, m). Put s = [r 1 , . . . , r m ] and consider any regular morphism s ∈ Reg(m, m) such that r = s · 1 m . For sake of clarity of notation let m 1 m and m 2 m. Consider the map γ σ · (s + s), where σ : m + m−→ • • m + m injects the first component of the coproduct into the second one and is the identity everywhere else. The morphism γ is depicted below: s s Note that this map is a regular morphism, so the map γ ω · 1 m 1 +m 2 is ω-regular. Moreover, we get: This completes the proof.

Probabilistic automata
The main purpose of this section is to put probabilistic systems [BH97,SdVW09,Sok11,USH16,BG05,BGB12] into the framework of Section 5. Here, we focus our attention on probabilistic automata which are akin to fully probabilistic systems from Example 2.2[BH97, BMP15, BEMC00, Sok11].

T. Brengos
Vol. 17:4 6.1. Preliminaries. A probabilistic automaton is a tuple where X is a set of states, Σ an alphabet, P is a probability transition function, i.e. a function such that for any x ∈ X we have (a,y)∈Σ×X P (x, a, y) = 1, and F ⊆ X the set of accepting states.
For C ⊆ X we define P (x, a, C) y∈C P (x, a, y). An execution fragment is a finite sequence s = x 0 We define f irst(s) = x 0 , last(s) = x n , length(s) = n, trace(s) = a 0 . . . a n−1 and P (s) = i=0,...,n−1 P (x i , a i , x i+1 ). An execution is an infinite sequence p = x 0 . . a n−1 → x n and p n x n . For an execution fragment s of length n let s ↑ denote the set of all executions p such that p (n) = s.
Let Exec(x) denote the set of all executions p such that f irst(p) = x. Let Σ(x) be the smallest sigma field on Exec(x) which contains all sets s ↑ for any execution fragment s with f irst(s) = x. Finally, let Q x denote the unique probability measure on Σ(x) such that Q x (s ↑) = P (s) for any execution fragment s with f irst(s) = x. We will often drop the subscript and write Q instead of Q x if the measure can be deduced from the context.
→ . . . such that it satisfies 6.1 and for any n ∈ N there is i n ≥ n such that (x in , a in , x in+1 ) equals to (s i , 1, s 1 ). Similarily, AccExec(s 1 , F) is the set of all executions whose first state is s 1 which satisfy the same argument as above. It is easy to see that Q(AccExec(s 0 , F)) = Q(AccExec(s 1 , F)) = 1 12 .
The remaining part of this section will focus on finding a suitable setting in which we can model probabilistic automata and their (in)finite behaviour using the framework presented in the previous section.
The Kleisli category associated with the monad D(Σ * × Id + Σ ω ) 13 is order enriched with the hom-set ordering given for f, g : X → D(Σ * × Y + Σ ω ) by: Although the Kleisli category for this monad is ωCpo-enriched, its hom-posets do not admit arbitrary finite suprema [HJS07,BMP15]. In other words, the setting is incompatible with the setting from the previous section. Hence, the remaining part of this section is focused on solving this issue based on ideas given in [GP14,BMP15].
6.2. Choosing the right monad. Here, we introduce a monad which is a suitable replacement for D, i.e. it satisfies the desired properties to make it suitable for modeling (in)finite behaviours of probabilistic automata. Inspired by [GP14] we consider the continuous continuation monad parametrized by the set [0, 1] whose functorial part is defined for any set X by: where P → ω Q denotes the set of functions between two ωCpo's P and Q which preserve suprema of ω-chains. The identity maps and the composition in the Kliesli category for D 12 This follows by the fact that any execution p = x0 → . . . satisfying 6.1 that is not a member of AccExec(si, F) satisfies the following condition: there is a natural number n such that for all i ≥ n we have xi = s0 and ai = 0. Hence, the probability of the set of all such executions equals 0.
13 By applying the construction from Section 4 to T = D and F = Σ × Id we obtain a monadic structure on the aforementioned functor. are as follows: It is not hard to see that this turns the family {ν X : DX → DX} into a natural transformation ν : D =⇒ D which is a monad morphism between the monads D and D. Additionally, it is easy to see that there is a natural ordering of arrows in Kl(D) which share the same domain and codomain. Indeed, for f, g : X → DY we have: This turns the Kleisli category for the monad D into an order enriched category. Moreover, the following theorem is true. Proof. The fact that the partial order is a complete lattice order is a direct corollary from the definition of D. We will now prove that Kleisli category for D is ωCpo-enriched. Take any ascending chain {f i : X → DY } i<ω of morphisms and note that where the equality marked with ( †) follows from the fact that DX consists of functions (X → [0, 1]) → ω [0, 1] that preserve ω-chains. Note that the identities 6.3 and 6.4 hold more generally for an arbitrary family of morphisms {f i } i∈I : X → DY and g : Y → DZ. This shows left distributivity of the Kliesli category and ends the proof.
From the above it follows that Kl(D) satisfies (A) -(D) from Section 5.
6.2.1. The monad for probabilistic automata and their behaviours. By instantiating the construction from Section 4 for T = D and F = Σ × Id we obtain the monad D(Σ * × Id + Σ ω ). We explicitly spell out the formula for the identity maps and the composition in Kl(D(Σ * × Id + Σ ω )) as it will be used throughout the remaining part of this section. For any set X the identity map id is given by: Moreover, for f : where for d : Σ * × Z + Σ ω → [0, 1] and σ ∈ Σ * the map d |σ : The following statement is a direct consequence of the definition of the monad D(Σ * × Id + Σ ω ) and the properties of D from the previous subsection.
6.3. (In)finite behaviour. Let (α, F) be a pair as in Remark 6.2 and consider where ν is given by 6.2. We see that the map α can be viewed as an endomorphism in the Kleisli category for the monad D(Σ * × Id + Σ ω ).
The rest of this section is devoted to presenting some properties of || α, F|| and || α, F|| ω for the pair ( α, F). We show that the values || α, F||(x) and || α, F|| ω (x) of behaviour functions encode probabilities of certain events from Σ(x). The main results are summarized in Theorem 6.6 and 6.7. 6.3.1. Finite behaviour. At first let us focus on describing the finite behaviour map || α, F||. Before we do that (see Theorem 6.6 for details) we need to present some intermediate results first. The following lemma is a direct consequence of the definition of α * , α + and the composition in Kl(D(Σ * × Id + Σ ω )).
The following theorem gives us insight into what (some of) the values of the infinite behaviour function are. To be more precise, we show that for a state x and a subset Λ ⊆ Σ * , the value of the infinite behaviour of x calculated for the characteristic function of the set of all infinite sequences from Σ ω with prefixes in Λ equals to the probability of F-accepting executions starting at x whose trace prefix belongs to Λ.
If we now assume by induction that the statement holds for some n > 1 then G n · f F (y)(χ Σ ω ) = f F (y)((τ, z) → Q(A z n ) and v → 1) = Q(A y n ) y ∈ F 0 otherwise.