Generic Trace Semantics via Coinduction

Trace semantics has been defined for various kinds of state-based systems, notably with different forms of branching such as non-determinism vs. probability. In this paper we claim to identify one underlying mathematical structure behind these"trace semantics,"namely coinduction in a Kleisli category. This claim is based on our technical result that, under a suitably order-enriched setting, a final coalgebra in a Kleisli category is given by an initial algebra in the category Sets. Formerly the theory of coalgebras has been employed mostly in Sets where coinduction yields a finer process semantics of bisimilarity. Therefore this paper extends the application field of coalgebras, providing a new instance of the principle"process semantics via coinduction."


Introduction
Trace semantics is a commonly used semantic relation for reasoning about state-based systems.Trace semantics for labeled transition systems is found on the coarsest edge of the linear time-branching time spectrum [57].Moreover, trace semantics is defined for a variety of systems, among which are probabilistic systems [49].
In this paper we claim that these various forms of "trace semantics" are instances of a general construction, namely coinduction in a Kleisli category.Our point of view here is categorical, coalgebraic in particular.Hence this paper demonstrates the abstraction power of categorical/coalgebraic methods in computer science, uncovering basic mathematical structures underlying various concrete examples.
1.1."Trace semantics" in various contexts.First we motivate our contribution through examples of various forms of "trace semantics."Think of the following three state-based, branching systems.
a[ 1  3 ] A context-free grammar (for Peano Arithmetic) Terminal symbols: 0, s Non-terminal symbol: T Generation rules: • The first one is a non-deterministic system with a special state denoting successful termination.To its state x we can assign its trace set: tr(x) = {a, ab, abb, . . .} = ab * , ( that is, the set of the possible linear-time behavior (namely words) that can arise through an execution of the system. 1 In this case the trace set tr(x) is also called the accepted language; formally it is defined (co)recursively by the following equations.For an arbitrary state x, ∈ tr(x) ⇐⇒ x → a • σ ∈ tr(x) ⇐⇒ ∃y. ( x a → y ∧ σ ∈ tr(y) ) (1.3)Here denotes the empty word; σ = a 1 a 2 . . .a n is a word.• The second system has a different type of branching, namely probabilistic branching.
Here x ′ a [1/3]  −→ y ′ denotes: at the state x ′ , a transition to y ′ outputting a occurs with probability 1/3.Now, to the state x ′ , we can assign its trace distribution: that is, the probability distribution over the set of linear-time behavior. 2Its formal (corecursive) definition is as follows.
where Pr(. . . ) denotes the probability of a transition.• The third example can be thought of as a state-based system, with non-terminal symbols as states.It is non-deterministic because a state T has two possible transitions.It is natural to call the following set of parse-trees its "trace semantics." The infinite trace ab ω is out of our scope here: we will elaborate this point later in Section 4.2.
2 Here again, we do not consider the infinite trace a ω → 1/3.
It is again a set of "linear-time behavior" as in the first example, although the notion of linear-time behavior is different here.Linear-time behavior-that is, what we observe after we have resolved all the non-deterministic branchings in the system-is now a parsetree instead of a word.
1.2.Coalgebras and coinduction.In recent years the theory of coalgebras has emerged as the "mathematics of state-based systems" [25,26,47].In the categorical theory of coalgebras, an important definition/reasoning principle is coinduction: a system (identified with a coalgebra c : X → F X) is assigned a unique morphism beh c into the final coalgebra.
The success of coalgebras is largely due to the fact that, when Sets is taken as the base category, the final coalgebra semantics is fully abstract with respect to the conventional notion of bisimilarity: for states x and y of coalgebras X This is the case for a wide variety of systems (i.e. for a variety of functors F ), hence coinduction in Sets captures bisimilarity.However, there is not so much work so far that captures other behavioral equivalences (coarser than bisimilarity) by the categorical principle of coinduction.The current workcapturing trace semantics by coinduction in a Kleisli category-therefore extends the application field of the theory of coalgebras.
1.3.Our contributions.Our technical contributions are summarized as follows.Assume that T is a monad on Sets which has a suitable order structure; we shall denote its Kleisli category by Kℓ(T ).
• Trace semantics via coinduction in a Kleisli category.Commutativity of the coinduction diagram in Kℓ(T ), the Kleisli category for T (1.6) is shown to be equivalent to the conventional recursive definition of trace semantics such as (1.3) and (1.5).This is true for both trace set semantics (for non-deterministic systems) and trace distribution semantics (for probabilistic systems).The induced arrow tr c thus gives (conventional) trace semantics for a system c.• Identification of the final coalgebra in a Kleisli category.We show that an initial algebra in Sets coincides with a final coalgebra in Kℓ(T ).
In particular, the final coalgebra in Rel is the initial algebra in Sets, because the category Rel of sets and relations is a Kleisli category for a suitable monad.This coincidence happens in the following two steps: -the initial algebra in Sets lifts to a Kleisli category, due to a suitable adjunction-lifting result; -in a Kleisli category we have initial algebra-final coalgebra coincidence.Here we use the classical result by Smyth and Plotkin [51], namely limit-colimit coincidence which is applicable in a suitably order-enriched category.Note the presence of two parameters in (1.6): a monad T and an endofunctor F , both on Sets.The monad T specifies the branching type of systems.We have three leading examples: 3• the powerset monad P modeling non-deterministic or possibilistic branching; modeling probabilistic branching; and • the lift monad L = 1+( ) modeling system with exception (or deadlock, non-termination).The functor F specifies the transition type of systems: our understanding of "transition type" shall be clarified by the following examples.
• In labeled transition systems (LTSs) with explicit termination-no matter if they are non-deterministic or even probabilistic-a state either -terminates (x → ), or -outputs one symbol and moves to another state (x a → x ′ ), in one transition.This "transition type" is expressed by the functor F X = 1 + Σ × X, where Σ is the output alphabet and 1 = { }.
• In context-free grammars (CFGs) as state-based systems, a state evolves into a sequence of terminal and non-terminal symbols in a transition.The functor with Σ being the set of terminal symbols, expresses this transition type.Clear separation of branching and transition types is important in our generic treatment of trace semantics.The transition type F determines the set of linear-time behavior (which is in fact given by the initial F -algebra in Sets).We model a system by a coalgebra X c → F X in the Kleisli category Kℓ(T )-see (1.6)-where F is a suitable lifting of F in Kℓ(T ).By the definition of a Kleisli category we will easily see the following bijective correspondence.
Hence our system-a function of the type X → T F X-first resolves a branching of type T and then makes a transition of type F .Many branching systems allow such representation so that our generic coalgebraic trace semantics applies to them.1.4.Generic theory of traces and simulations.In the study of coalgebras as 'categorical presentation of state-based systems', there are three ingredients playing crucial roles: coalgebras as systems; coinduction yielding process semantics; and morphisms of coalgebras as behavior-preserving maps.In this paper we study the first two in a Kleisli category.What about morphisms of coalgebras?
In [14] this question is answered by identifying lax/oplax morphisms of coalgebras in a Kleisli category as forward/backward simulations.Use of traces and simulations is a common technique in formal verification of systems (see e.g.[41]): a desirable property is expressed in terms of traces; and then a system is shown to satisfy the property by finding a suitable simulation.Therefore this paper, together with [14], forms an essential part of developing a "generic theory of traces and simulations" using coalgebras in a Kleisli category.The categorical genericity-especially the fact that we can treat non-deterministic and probabilistic branching in a uniform manner-is exploited in [19] to obtain a simulationbased proof method for a probabilistic notion of anonymity for network protocols.Currently we are investigating how much more applicational impact can be brought about by our generic theory of traces and simulations.
1.5.Testing and trace semantics.Since the emergence of the theory of coalgebras, the significance of modal logics as specification languages has been noticed by many authors.This is exemplified by the slogan in [36]: 'modal logic is to coalgebras what equational logic is to algebras'.Inspired by coalgebras on Stone spaces and the corresponding modal logic, recent developments [5,6,31,32,34,37,45] have identified the following situation as the essential mathematical structure underlying modal logics for coalgebras.

C op
In fact, it is noticed in [45] that such a situation not only hosts a modal logic but also a more general notion of testing (in the sense of [53,57], also called testing scenarios).Therefore we shall call the above situation a testing situation.
In the last technical section of the paper we investigate coalgebraic trace semantics for the special case T = P (modeling non-determinism) from this testing point of view.First, we present some basic facts on testing situations, especially on the relationship between the induced testing equivalence and the final coalgebra semantics.These two process equivalences are categorically presented as kernel pairs, which enables a fairly simple presentation of the theory of coalgebraic testing.In addition, we observe that the coinduction scheme in the Kleisli category Kℓ(P) gives rise to a canonical testing situation, in which the set of tests is given by an initial F -algebra.
The material on testing in the last section has not been presented in the earlier versions [16,17] of this paper.1.6.Organization of the paper.In Section 2 we observe that a coalgebra in a Kleisli category is an appropriate "denotation" of a branching system, when we focus on trace semantics.In Section 3 we present our main technical result that an initial algebra in Sets yields a final coalgebra in Kℓ(T ).The relationship to axiomatic domain theory-which employs similar mathematical arguments-is also discussed here.Section 4 presents some examples of the use of coinduction in Kℓ(T ) and argues that the coinduction principle is a general form of trace semantics.In Section 5 we review the preceding material from the testing point of view.

Coalgebras in a Kleisli category
In the study of coalgebras as "categorical presentations of state-based systems," the category Sets of sets and functions has been traditionally taken as a base category (see e.g.[25,47]).An important fact in such a setting is that bisimilarity is often captured by coinduction. 4 However, bisimilarity is not the only process equivalence.In some applications one would like coarser equivalences, for example in order to abstract away internal branching structures.One of such coarser semantics, which has been extensively studied, is trace equivalence.For example, the process algebra CSP [21] has trace semantics as its operational model.Trace equivalence is coarser than bisimilarity, as the following classic example of "trace-equivalent but not bisimilar" systems illustrates.
It is first noticed in [46] that the Kleisli category for the powerset monad is an appropriate base category for trace semantics for non-deterministic systems.This observation is pursued further in [16,17,24].In [15] it is recognized that the same is true for the subdistribution monad for probabilistic systems.The current paper provides a unified framework which yields those preceding results, in terms of Cppo-enrichment of a Kleisli category; see Section 2.3.In this section we first aim to justify the use of coalgebras in a Kleisli category.

Monads and Kleisli categories.
Here we recall the relevant facts about monads and Kleisli categories.For simplicity we exclusively consider monads on Sets.
A monad on Sets is a categorical construct.It consists of • an endofunctor T on Sets; • a unit natural transformation η : id ⇒ T , that is, a function X η X → T X for each set X satisfying a suitable naturality condition; and • a multiplication natural transformation µ : T 2 ⇒ T , consisting of functions T 2 X µ X → T X with X ranging over sets.The unit and multiplication are required to satisfy the following compatibility conditions.
See [3,42] for the details. 4 Non-examples include LTSs with unbounded branching degree.They are modeled as coalgebras for F X = P(Σ × X).Lambek's Lemma readily shows that this choice of F does not have a final coalgebra in Sets, because it would imply an isomorphism Z ∼ = → P(Σ × Z) which is impossible for cardinality reasons.
The monad structures play a crucial role in modeling "branching."Intuitively, the unit η embeds a non-branching behavior as a trivial branching (with only one possibility to choose).The multiplication µ "flattens" two successive branchings into one branching, abstracting away internal branchings: The following examples will illustrate how this flattening phenomenon is a crucial feature of trace semantics.
In this paper we concentrate on the three monads mentioned in the introduction: L, P and D.
• The lift monad L = 1 + ( )-where we denote 1 = {⊥} with ⊥ meaning deadlock -has a standard monad structure induced by a coproduct.For example, the multiplication µ L X : 1 + 1 + X → 1 + X carries x ∈ X to itself and both ⊥'s to ⊥. • The powerset monad P has a unit given by singletons and a multiplication given by unions.The monad P models non-deterministic branching: the "flattening" in (2.1) corresponds to the following application of the multiplication of P.
The monad P's action on arrows (as a functor) is given by direct images: for f : X → Y , the function Pf : PX → PY carries a subset u ⊆ X to the subset {f (x) | x ∈ u} ⊆ Y .• The subdistribution monad D has a unit given by the Dirac distributions.
Its multiplication is given by multiplying the probabilities along the way.That is, which models "flattening" of the following kind. x The monad D's action on arrows (as a functor) is given as a suitable adaptation of "direct images."Namely, for f : X → Y , the function Df : Given any monad T , its Kleisli category Kℓ(T ) is defined as follows.Its objects are the objects of the base category, hence sets in our consideration.An arrow X → Y in Kℓ(T ) is the same thing as an arrow X → T Y in the base category, here Sets.
Identities and composition of arrows are defined using the unit and the multiplication of T .Moreover, there is a canonical adjunction . See [3,42] for details.The relevance in this paper is that a Kleisli category can be thought of as a category where the branching is implicit.For example, an arrow X → Y in the Kleisli category Kℓ(P) is a function X → PY hence a "non-deterministic function."When T = D, then by writing X → Y in the Kleisli category we mean a function with probabilistic branching.Moreover, composition of arrows in Kℓ(T ) is given by that is, making one transition (by g) after another (by f ), and then flattening (by µ Z ).For example, this general definition instantiates as follows when T Remark 2.1.Our use of the sub-distribution monad instead of the distribution monad needs some justification.Looking at the trace distribution (1.4), one sees that the probabilities add up only to 2/3 and not to 1; this is because the infinite trace (namely a ω → 1/3) are not present.Therefore in this example, although the state-based system can be modeled as a coalgebra in the category Kℓ(D =1 ), its trace semantics can only be expressed as an arrow in Kℓ(D).
When a system is modeled as a coalgebra in Kℓ(D), a state may have a (sub)distribution over possible transitions which adds up to less than 1.In that case the missing probability can be understood as the probability for deadlock.
Technically, we use the monad D instead of D =1 because we need the minimum element (a bottom) so that the Kleisli category becomes Cppo-enriched (Theorem 3.3).A bottom is available for D as the zero distribution [x → 0], but not for D =1 .

2.2.
Lifting functors by distributive laws.In this paper a state-based system is presented as a coalgebra X → F X in Kℓ(T ), where F : Kℓ(T ) → Kℓ(T ) is a lifting of F : Sets → Sets.This lifting F → F is equivalent to a distributive law F T ⇒ T F .The rest of this section elaborates on this point.
Various kinds of state-based, branching systems are expressed as a function of the form X c → T F X with T a monad (for branching type) and F a functor (for transition type).
The following examples are already hinted at in the introduction.
• For T = P and F = 1 + Σ × , a function X c → T F X is an LTS with explicit termination.For example, consider the following system where is the element of 1. 5 Then the state x can make three possible transitions, namely: x → (successful termination), x → x 2 , when written in a conventional way.
• By replacing T = P by D, but keeping F the same, we obtain a probabilistic system such as the one in the middle of (1.1).For example, • For T = P and F = (Σ + ) * , a function X c → T F X is a CFG with Σ the terminal alphabet (but without finiteness conditions e.g. on the state space).See [16] for more details.All these systems are modeled by a function X c → T F X, hence an arrow X c → F X in Kℓ(T ).Our question here is: is c a coalgebra in Kℓ(T )?In other words: is the functor F on Sets also a functor on Kℓ(T )?
Hence, to develop a generic theory of traces in Kℓ(T ), we need to lift F to a functor F on Kℓ(T ).A functor F is said to be a lifting of F if the following diagram commutes.Here J is the left adjoint in (2.2).
The intuition is as follows.On the one hand, when an execution hits successful termination , it yields its history of observations as its trace.On the other hand, when an execution hits deadlock ⊥ then it yields no trace no matter what is the history before hitting ⊥.This distinction will be made formal in Example 4.3.
A distributive law λ induces a lifting F as follows.On objects: F X = F X. Given f : X → Y in Kℓ(T ), we need an arrow F f : F X → F Y in Kℓ(T ).Recall that f is a function X → T Y in Sets; one takes F f to be the arrow which corresponds to the function A distributive law specifies how a transition (of type F ) "distributes" over a branching (of type T ).Let us look at an example.For T = P and F = 1 + Σ × (the combination for LTSs with explicit termination), we have the following distributive law.
where waving arrows denote branchings.Throughout the paper we need the global assumption that a functor F has a lifting F on Kℓ(T ), or equivalently, that there is a distributive law λ : F T ⇒ T F .Now we present some sufficient conditions for existence of λ.In most examples one of these conditions holds.
First, take T = P, in which case we have Kℓ(P) ∼ = Rel, the category of sets and binary relations.We can provide the following condition that uses relation liftings, whose definition is found [24].
Lemma 2.3 (From [24]).Let F : Sets → Sets be a functor that preserves weak pullbacks.Then there exists a distributive law λ : F P ⇒ PF given by In fact, the functor F : Rel → Rel induced by this distributive law carries an arrow Now let us consider a monad T which is not P.When a monad T is commutative and a functor F is shapely, we can provide a canonical distributive law.The class of such monads and functors is wide and all the examples in this paper are contained.
• A commutative monad [33] is intuitively a monad whose corresponding algebraic theory has only commutative operators.We exploit the fact that a commutative monad is equipped with an arrow called double strength for any sets X and Y ; the double strength must be compatible with the monad structure of T in an obvious way.
Our three examples of monads are all commutative, with the following double strengths. (2.5) • The family of shapely functors [27] 6 on Sets is defined inductively by the following BNF notation: where Σ denotes the constant functor into an arbitrary set Σ. Notice that taking infinite product is not allowed, nor exponentiation to the power of an infinite set.This is in order to ensure that we find an initial F -algebra as a suitable ω-colimit-see Proposition A.1.
Lemma 2.4.Let T : Sets → Sets be a commutative monad, and F : Sets → Sets a shapely functor.Then there is a distributive law λ : F T ⇒ T F .
Proof.The construction of a distributive law is done inductively on the construction of shapely F .
• If F is the identity functor, then the λ is the identity natural transformation T ⇒ T .
to form the composite: • If F is a coproduct i∈I F i then we use laws λ It is straightforward to check that such λ is natural and compatible with the monad structure.
We have provided some sufficient conditions for a distributive law to exist, that is, for a functor F to be lifted to Kℓ(T ).This does not mean the results in the sequel hold exclusively for commutative monads and shapely functors.

2.3.
Order-enriched structures of Kleisli categories.The notion of branching naturally involves a partial order: one branching is bigger than another if the former offers "more possibilities" than the latter.Formally, this order appears as the Cppo-enriched structure of a Kleisli category.It plays an important role in the initial algebra-final coalgebra coincidence in Section 3.1.
A Cppo-enriched category C is a category where: 6 Shapely functors here are called polynomial functors by some authors, although other authors allow infinite powers or the powerset construction.
which makes C(X, Y ) an ω-cpo with a bottom.This means: -for an increasing ω-chain of arrows from X to Y , there exists its join n<ω f n : X → Y ; -for any X and Y there exists a bottom arrow ⊥ This means that the following joins are preserved: Note that composition need not preserve bottoms (i.e. it is not necessarily strict).This is in fact an instance of a more general notion of V-enriched categories where V is the category Cppo of pointed (i.e. with ⊥) cpo's and continuous (but not necessarily strict) functions.See [7,28,38] for more details on enriched category theory, and [1] on cpo's and domain theory.The cpo structure of a homset Kℓ(T )(X, Y ) comes from that of T Y in a pointwise manner: It is laborious but straightforward to show that composition in Kℓ(T ) is continuous and left-strict.
We are concerned with coalgebras X → F X in the category Kℓ(T ), which we assume is Cppo-enriched.Hence it comes natural to require that functor F is somehow compatible with the Cppo-enriched structure of Kℓ(T ).The obvious choice is to require that F is a Cppo-enriched functor (see e.g.[7]), i.e.F is locally continuous.It means that for an increasing ω-chain f n : X → Y , we have This is indeed the assumption chosen in axiomatic domain theory.We will come back to this point later in Section 3.3.However, for our later purpose, we only need the weaker condition of local monotonicity: For a monad T = {L, P, D} and a shapely functor F (recall Lemma 2.4), the lifted F is indeed locally continuous.We emphasize again that this does not mean our results in Section 3 hold exclusively for shapely functors.
Proof.By induction on the construction of shapely functors.
• F = id, the identity functor.Then F = id which satisfies the condition.
• F = Σ, a constant functor.Then F maps every arrow to the identity map on Σ in Kℓ(T ).This is obviously locally continuous.
, we obtain F f as the following composite in Sets.
Because the order in Kℓ(T )(F X, F Y ) is pointwise, it suffices to show the following: dst : ) is a continuous map between cpo's.It is easy to check that this is indeed the case.See (2.5).
Since the order on the homset is pointwise, it suffices to show that each T κ j : T F j Y → T ( j∈J F j Y ) is continuous.This is easy.

Final coalgebra in a Kleisli category
In this section we shall prove our main technical result: the initial F -algebra in Sets yields the final F -coalgebra in Kℓ(T ).It happens in the following two steps: first, the initial algebra in Sets is lifted to the initial algebra in Kℓ(T ); second we have the initial algebra-final coalgebra coincidence in Kℓ(T ).For the latter we use the classical result [51] of limit-colimit coincidence.This is where the Cppo-enriched structure of Kℓ(T ) plays a role.
In the proof we use two standard constructions: initial/final sequences [2] and limitcolimit coincidence [51].The reader who is not familiar with these constructions is invited to look at Appendices A.1 and A.2 where we briefly recall them.
Remark 3.1.The proof of our main theorem (Theorem 3.3) can be simplified if we suitably strengthen the assumptions.First, if we assume local continuity of the lifted functor F (instead of local monotonicity that is assumed in our main theorem), then the initial algebrafinal coalgebra coincidence follows from a standard result in axiomatic domain theory; see Section 3.3.Furthermore, for the special case T = P in which case Kℓ(P) ∼ = Rel, the initial algebra-final coalgebra coincidence is almost obvious due to the duality Rel ∼ = Rel op ; see Section 3.2.
3.1.The initial algebra in Sets is the final coalgebra in Kℓ(T ).First, it is standard that an initial algebra in Sets is lifted to an initial algebra in Kℓ(T ).Such a phenomenon is studied for instance in [11,44] in the context of combining datatypes (modeled by an initial algebra) and effectful computations (modeled by a Kleisli category).For this result we do not need an order structure.Proposition 3.2.Let T be a monad and F be a endofunctor, both on a category C. Assume that we have a distributive law F T ⇒ T F -or equivalently, we have a lifting F on Kℓ(T ).If F has an initial algebra α : is an initial F -algebra.Here J is the canonical Kleisli left adjoint as in (2.2).
We will use an instance of this result for C = Sets.
Proof.It follows from [20, Theorem 2.14] that a distributive law lifts the canonical Kleisli adjunction to an adjunction between the categories Alg(F ) and Alg(F ) of algebras.
Second, we use the initial algebra-final coalgebra coincidence in Kℓ(T )-which holds in a suitable order-enriched setting-to identify the final coalgebra in Kℓ(T ).This is our main theorem.

Theorem 3.3 (Main theorem). Assume the following:
(1) A monad T on Sets is such that its Kleisli category Kℓ(T ) is Cppo-enriched and composition in Kℓ(T ) is left-strict.(2) For an endofunctor F on Sets, we have a distributive law λ : F T ⇒ T F .Equivalently, F has a lifting F on Kℓ(T ).Moreover, the lifting F is locally monotone.(3) The functor F preserves ω-colimits in Sets, hence has an initial algebra via the initial sequence (see Proposition A.1).
Then the initial F -algebra α : We first present the main line of the proof.Some details are provided in the form of subsequent lemmas.Note that the assumptions are satisfied by T ∈ {L, P, D} and shapely F ; see Lemmas 2.5 and 2.4.
Proof.By the assumption (3) we obtain the initial algebra via the initial sequence in Sets.
In Sets A (colimit) Here 0 = ∅ ∈ Sets is initial and ¡ : 0 → X is the unique arrow from 0 to an arbitrary X.We apply the functor J : Sets → Kℓ(T ) to the whole diagram.Since J is a left adjoint it preserves colimits: hence the two cocones in the following diagram are both colimits again.
In Kℓ(T ) A (colimit) The ω-chain in this diagram is in fact the initial sequence for the functor F (Lemma 3.4) because, for example, a left adjoint J preserves initial objects.Moreover the lower cone is the image of the upper cone under F ; see the diagram (2.3).Hence the diagram (3.2) is equal to the following one.Recall that F X = F X on objects.
In Kℓ(T ) A (colimit) → A is an initial F -algebra.This can be seen as a more concrete proof of Proposition 3.2.Now we show the initial algebra-final coalgebra coincidence in Kℓ(T ).This is done by reversing all the arrows in (3.3) and transforming the diagram into the one of the final sequence and its limits.
We notice (Lemma 3.6) that each arrow F n ¡ in the initial sequence is an embedding (Definition A.4). Hence the limit-colimit coincidence Theorem A.8 says that every arrow in the diagram is an embedding.Note that Jα and Jα −1 , inverse to each other, form an embedding-projection pair.By taking the corresponding projections-they are uniquely determined (Lemma A.5) and are denoted by ( ) P -we obtain the next diagram.The limit-colimit coincidence Theorem A.8 says that the two resulting cones are both limits.It is also obvious that the whole diagram commutes.
In Kℓ(T ) A (limit) The ω op -chain here is indeed a final sequence: Lemma 3.5 shows-using the assumption (1) on left-strictness-that 0 is also final in Kℓ(T ), and according to Lemma 3.6 we have (F n ¡ ) P = F n !where !: X → 0 is the unique arrow to the final object 0 in Kℓ(T ).As to the lower cone we have F Jα n P = F (Jα n ) P by Lemma 3.7.
Hence the diagram (3.4) is equal to the following one, showing the final sequence for F , its limit (the upper one) and that limit mapped by F (the lower one) which is again a limit.
In Kℓ(T ) A (limit) By Proposition A.2 we conclude that Jα −1 is a final F -coalgebra.
In the remainder of this section the lemmas used in the above proof are presented.We rely on the same assumptions as in Theorem 3.3.
Lemma 3.4.The ω-chain in the diagram (3.2) is indeed the initial sequence for F .That is, we have for each n < ω, where ¡ Sets : 0 → F 0 in Sets and ¡ Kℓ(T ) : 0 → F 0 in Kℓ(T ) denote the unique maps.
Proof.By induction on n.For n = 0 the two maps are equal due to the initiality of J0 = 0 in Kℓ(T ).For the step case we use the commutativity JF = F J of (2.3).
Lemma 3.5.The empty set 0 is both an initial and a final object in Kℓ(T ).
In particular, this implies that the object T 0 is final in Sets.
Proof.The functor J : Sets → Kℓ(T ) preserves initial objects since it is a left adjoint.Therefore 0 = J0 is initial in Kℓ(T ).Finality follows essentially from the left-strictness assumption: for each set X there exists at least one arrow X → 0 in Kℓ(T ), for example ⊥ X,0 .To show the uniqueness of such an arrow, take an arbitrary arrow f : X → 0 in Kℓ(T ).Recalling that the bottom map ⊥ 0,0 : 0 → 0 is also the identity arrow in Kℓ(T ) because of initiality, we obtain where the compositions are taken in Kℓ(T ) and the equality marked by ( * ) holds by leftstrictness of composition.
Lemma 3.6.Each arrow F n ¡ in the initial sequence for F , as in the diagram (3.3), is an embedding.Its corresponding projection is given by Proof.We show that (F n ¡ , F n ! ) is an embedding-projection pair for all n < ω.We have For the other half we have F is locally monotone.
Lemma 3.7.We have F Jα n P = F (Jα n ) P .Hence the lower cone in the diagram (3.4) is the image of the upper cone under F .
Proof.It is easy to check that F Jα n , F (Jα n ) P indeed form an embedding-projection pair.Therein we use the monotonicity of F 's action on arrows.This is because of the following bijective correspondence between functions Recalling Kℓ(P) ∼ = Rel, this mapping f → f ∨ corresponds to taking the opposite relation.Due to this "global" duality Kℓ(P) ∼ = Kℓ(P) op , the proof of Theorem 3.3 is drastically simplified for T = P.It essentially relies on the lifted self duality Alg(F where the latter is isomorphic to (Coalg(F )) op .We do not need here an order structure of Kℓ(P) nor local monotonicity of F .
Theorem 3.8.Let F : Sets → Sets be a functor which preserves weak pullbacks, and F : Kℓ(P) → Kℓ(P) be its lifting induced by relation lifting (Lemma 2.3).Then the initial F -algebra in Sets yields the final F -coalgebra in Kℓ(P).
Proof.We have the following situation because of the self-duality of Kℓ(P).
The adjunction J ⊣ K and the isomorphism Op : Kℓ(P) op ∼ = → Kℓ(P) lift to those between the categories of algebras.

Kℓ(P)
Op op ∼ = Kℓ(P) op Indeed, J ⊣ K lifts due to Proposition 3.2; the lifted isomorphism Op ′ : Alg(F ) is because of the following commutativity: which is because: F R = Rel F (R) (see (2.4)); and taking relation liftings is compatible with opposite relations (i.e.Rel F (R op ) = (Rel F R) op , see [22]).Moreover the category Alg(F op ) is obviously isomorphic to (Coalg(F )) op .Therefore the initial object in Alg(F ) is carried to that in (Coalg(F )) op , hence the final object in Coalg(F ).
For monads such as T = D a "global" self-duality Kℓ(T ) ∼ = Kℓ(T ) op is not available.Instead, in the proof of Theorem 3.3, we exploit the "partial" duality which holds between the colimit/limit of the initial/final sequence.

Related work: axiomatic domain theory.
The initial algebra-final coalgebra coincidence is heavily exploited in the field of axiomatic domain theory, e.g. in [9,12,13,50].There, categories which have coinciding initial algebra and final coalgebra for each endofunctor are called algebraically compact categories.They draw special attention as suitable "categories of domains" for denotational semantics of datatype construction.The relevance comes as follows.
Let C be a "category of domains."We think of an object of the category C as a type.A "recursive" datatype constructor-a prototypical example is (X, Y ) → Y X -is presented as a bifunctor G : C op × C → C. Note the presence of both covariance and contravariance.We expect that such a category C has a canonical fixed point Fix G such that which models the recursive type determined by the datatype constructor G. Freyd [12] showed that if C is algebraically compact, then we can construct such a fixed point as a suitable initial algebra; moreover this fixed point is shown by Fiore [9] to be a canonical one in a suitable sense.The rough idea here is that the covariant part of G is taken care of by an initial algebra; the contravariant part is by a final coalgebra; the initial algebra-final coalgebra coincidence yields a fixed point of overall G.
Typical examples of algebraically compact categories are enriched over Cppo or one of its variants.This conforms the traditional use of the word "domain" for certain cpo's (e.g. in [1]).
Although we utilize the initial algebra-final coalgebra coincidence result in Kℓ(T ), we are not so much interested in algebraic compactness of Kℓ(T ).This is because our motivation is different from that of axiomatic domain theory.In studying trace semantics for coalgebras, we need not deal with every endofunctor on Kℓ(T ), but only such an endofunctor F which is a lifting of F : Sets → Sets.
In a different context of functional programming, the work [44] also studies initial algebras and final coalgebras in a Kleisli category.The motivation there is to combine data types and effects.More specifically, an initial algebra and a final coalgebra support the fold and the unfold operators, respectively, used in recursive programs over datatypes.A computational effect is presented as a monad, and its Kleisli category is the category of effectful computations.
The difference between [44] and the current work is as follows.In [44], the original category of pure functions is already algebraically compact; the paper studies the conditions for the algebraic compactness to be carried over to Kleisli categories.In contrast, in the current work, it is a monad-with a suitable order structure, embodying the essence of "branching"-which yields the initial algebra-final coalgebra coincidence on a Kleisli category; the coincidence is not present in the original category Sets.

Local continuity vs. local monotonicity.
In axiomatic domain theory, Cppo-enriched categories are said to be algebraically compact because, "in a 2-category setting" [13], every endofunctor has an initial algebra and a final coalgebra.Concretely this means: "every locally continuous functor." In this spirit, we could have made a stronger assumption of F 's local continuity in Theorem 3.3 instead of local monotonicity.If we do so, in fact, the proof of Theorem 3.3 becomes much simpler: the following proposition (Lemma in [13, p.98]) immediately yields the initial algebra-final coalgebra coincidence for a locally continuous F .Proposition 3.9 ( [13]).Let D be a Cppo-enriched category whose composition is leftstrict, and G : D → D be a locally continuous endofunctor.An initial algebra β : GB Hence it has the least fixed point n<ω Φ n (⊥); this proves existence of a morphism from Now we shall show its uniqueness.Assume that g : Y → B is a morphism of coalgebras as above, that is, Φ(g) = g.Similarly to Φ, we define a function Ψ : D(B, B) → D(B, B) as the one which carries h : Here ( * ) holds because n Ψ n (⊥), being a fixed point for Ψ, is the unique morphism of algebras from β to β.This shows that the morphism g must be the least fixed point of Φ.
For our main Theorem 3.3 we can do with only local monotonicity of the lifted functor F , by taking a closer look at the initial/final sequences.However at this stage it is not clear how much we gain from this generality: up to now we have not found an example where the functor F is only locally monotone (and not locally continuous).

Finite trace semantics via coinduction
In this section we shall further illustrate the observation that the principle of coinduction, when employed in Kℓ(T ), captures trace semantics of state-based systems.As we have shown in the previous section, an initial algebra in Sets constitutes the semantic domain, i.e. is a final coalgebra in Kℓ(T ).Viewing an initial algebra as the set of well-founded terms (such as finite words or finite-depth parse trees), this fact means that the "trace semantics" induced by coinduction is inevitably finite, in the sense that it captures only finite behavior.Here we will elaborate on this finiteness issue as well.
with one of the above choices, then the commutativity of the diagram is equivalent to the corresponding (conventional) definition of trace semantics in Section 1.1.Therefore we claim that the diagram (4.1) is the mathematical principle underlying various "trace semantics," no matter if it is "trace set" (non-deterministic) or "trace distribution" (probabilistic).As further illustration we give details for the choice of parameters T = P and F = 1 + Σ × .This is the suitable choice to deal with the first system in (1.1).Now the coinduction diagram looks as follows.Recall that an initial F -algebra is carried by the set Σ * of finite words.
It assigns, to a system c, a function tr c : X → P(Σ * ) which carries a state x ∈ X to the set of finite words on Σ which can possibly arise as an execution "trace" of c starting from x.The commutativity states equality of two arrows X ⇉ 1 + Σ × Σ * in Kℓ(P), that is, functions X ⇉ P(1 + Σ × Σ * ).Let us denote these functions by For each x ∈ X, the following conditions-derived straightforwardly by definition of composition of Kℓ(P), lifting of the functor 1 + Σ × , etc.-specify u and v's value at x, as a subset of 1 Commutativity of (4.2) amounts to u = v; this gives the condition (1.3).
From a different point of view we can also express that as follows: finality of the coalgebra Σ * ∼ = → 1 + Σ × Σ * in (4.2) ensures that the conventional recursive definition (1.3) uniquely determines a function tr c : X → P(Σ * ).Hence tr c is well-defined.
An easy consequence of the recursive definition (1.3) is Therefore every trace a 1 . . .a n ∈ tr c (x) has termination implicit at its tail.In particular, the set tr c (x) is not necessarily prefix-closed:  By examining trace semantics for such systems, we shall formally put the difference between the computational meanings of the two elements, ⊥ and .
The coinduction diagram (4.1) instantiates to the same diagram as (4.2), but now in the category Kℓ(L).Easy calculation shows that its commutativity amounts to the following condition.The function Here σ ∈ Σ * is a word in Σ.
For the systems under consideration, we can think of three different kinds of possible executions.
• An execution eventually hitting , that is, x 3) it yields a word tr c (x) = a 1 . . .a n as its trace.
• An execution eventually hitting ⊥, that is, x It properly reflects our intuition that a state x that eventually goes into deadlock does not yield a finite (or terminating) trace.
• An execution not hitting nor ⊥, that is, x In this case, the only possible solution of the "recursive equation" (4.3) is tr c (x) = tr c (x 1 ) = • • • = ⊥.The intuition here is: a state leading to livelock does not yield a finite trace.4.2.Infinite traces.The trace semantics obtained via coinduction (Corollary 4.1) assigns, to each state x ∈ X, "a set of" (if T = P) or "a distribution over" (if T = D) elements of the initial algebra A. Elements of A are thought of as possible linear behavior of the system determined by the transition type (i.e. the functor F ). Now the intuition is that an initial F -algebra A consists of the well-founded (or finitedepth) terms and a final F -coalgebra Z consists of the possibly non-well-founded (or infinitedepth) terms.For example, • for F = 1 + Σ × , A = Σ * consists of all the finite words, and Z = Σ ∞ = Σ * + Σ ω is augmented with streams, i.e. infinite words; • for F = (Σ + ) * , A is the set of finite-depth skeletal parse trees (see [16]), and Z additionally contains infinite-depth ones; • for F = Σ × which models LTSs without explicit termination, A = 0 and Z = Σ ω .Therefore our trace semantics X → T A only takes account of finite, well-founded lineartime behavior but not infinite ones.This is why the trace set (1.2) does not contain ab ω ; and also why we have been talking about LTSs with explicit termination-otherwise the finite trace semantics is always empty.
Designing a coalgebraic framework to capture possibly infinite trace semantics is the main aim of [24].The work is done exclusively in a non-deterministic setting and the main result reads as follows.
Theorem 4.4 (Possibly infinite trace semantics for coalgebras, [24]).Let F be a shapely functor on Sets, and ζ : Z ∼ = → F Z be a final coalgebra in Sets.The coalgebra is weakly final: that is, given a coalgebra c : X → F X, there is a morphism from c to Jζ but the morphism is not necessarily unique.
Still there is a canonical choice tr ∞ c among such morphisms, namely the one which is maximal with respect to the inclusion order.We shall call the function tr ∞ c : X → PZ the possibly-infinite trace semantics for c.
Note here that, when we take F = 1 + Σ × and T = P (the choice for LTSs with termination), commutativity of (4.4) boils down to exactly the same conditions as (1.3): )) means the following.The recursive definition (4.5)-although it looks valid at the first sight-does not uniquely determine the infinite trace map tr ∞ c : X → P(Σ ∞ ).Instead, the map tr ∞ c is the maximal one among those which satisfy (4.5).
As an example take the first system in (1.1).We expect its possibly-infinite trace map X → P(Σ ∞ ) to be such that x → ab * + ab ω and y → b * + b ω .Indeed this satisfies (4.5) and is moreover the maximal.However, the function x → ab * and y → b * -this is actually the finite trace X → P(Σ * ) embedded along Σ * ֒→ Σ ∞ -also satisfies (4.5).In fact, [16,Section 5] shows a general fact that such an embedding of the finite trace map is the minimal one among those morphisms which make the diagram (4.4) commute.
The coalgebraic characterization (Theorem 4.4) of possibly-infinite trace semantics is not yet fully developed.In particular the current proof of Theorem 4.4 (in [24]) is fairly concrete and a categorical principle behind it is less clear than the one behind finite traces.Consequently the result's applicability is limited: we do not know whether the result holds in a probabilistic setting; or whether it holds for any weak-pullback-preserving functor F .

Trace semantics as testing equivalence
In this section we will observe that, in a non-deterministic setting, the coalgebraic finite trace semantics (i.e.coinduction in Kℓ(P)) gives rise to a canonical testing situation in which a test is an element of the initial F -algebra A in Sets.Here F specifies the transition type, just as before.The notion of testing situations (Definition 5.1) and its variants have attracted many authors' attention in the context of coalgebraic modal logic; our aim here is to demonstrate genericity and pervasiveness of the notion of testing situations by presenting an example which is not much like modal logic (that is, propositional logic plus modality).
In Section 5.1 we introduce the notion of testing situations and investigate some of their general properties.Our main concern there is the comparison between two process equivalences, namely testing equivalence and equivalence modulo final coalgebra semantics.
We present the equivalences categorically as suitable kernel pairs; this makes the arguments simple and clean.In Section 5.2 we present the canonical testing situation for trace semantics.Moreover we show that it is expressive: the testing captures final coalgebra semantics, which is now trace semantics.5.1.Testing situations.Recent studies [5,6,32,35,37,45] on coalgebra and modal logic have identified (variants of) the following categorical situation as the essential underlying structure.Following [45], we prefer using a more general term "testing": it subsumes "modal logic" in the following sense.We learn properties of a system through pass or failure of tests; modal logic constitutes a special case where tests are modal formulas.Definition 5.1.A testing situation is the following situation of a contravariant adjunction S op ⊣ P and two endofunctors F, M C op (5.1) plus a "denotation" natural transformation δ : M P ⇒ P F op : C op → A, which consists of arrows M P X Note that the denotation δ is a parameter: the same "syntax for tests" M : A → A can have different interpretations with different δ.
The requirements in Definition 5.1 are the same as in [32,45].They are what we need to compare two process semantics, namely testing equivalence-which arises naturally from the concept of testing-and final coalgebra semantics. 8We shall explain each ingredient's role, using the well-established terminology of modal logic.
• The endofunctor F : C → C makes Coalg(F ) the category of "systems," or "Kripke models" in modal logic.• The category A-typical examples being Bool of Boolean algebras or Heyt of Heyting algebras-is that of "propositional logic."The functor M specifies "modality": modal operators and axioms.Then Alg(M ) is the category of "modal algebras"; the initial → L is a "modal logic" consisting of modal formulas, modulo logical equivalence.
• The denotation δ specifies how the modality M is interpreted via transitions of type F .This allows to give "Kripke semantics" for the modal logic: given a coalgebra (or a "Kripke model") c : X → F X, interpretation c of modal formulas therein is given by the following induction.
(5.2) 8 In fact we can be even more liberal: existence of a denotation δ can be replaced by existence of a lifting P : Coalg(F ) op → Alg(M ) of P .The results in this section nevertheless hold in that case.The latter condition (there is a lifting P ) is strictly weaker than the former (there is a natural transformation δ): obviously δ induces P but not the other way round.Let C = ω op , A = ω, P = id, F = (1 + ) op and M = 2 + .Then both Coalg(F ) and Alg(M ) are the empty category hence P has the trivial lifting.However there is no natural transformation M P X → P F op X.
• Why a right adjoint S of P op ?It allows us, via transposition, to assign a modal "theory" to each state of a Kripke model.
The theory th c (x) associated with a state x contains precisely the modal formulas that hold at x.Following the above intuition, we define the categorical notion of testing equivalence-two states are testing-equivalent if they have the same modal theory.Definition 5.2.Assume that we have a testing situation (5.1), and that C has finite limits.On a coalgebra X c → F X, the testing equivalence TestEq c is the kernel pair of the theory map th c defined by (5.2) and (5.3).Equivalently, is an equalizer.
Similarly, we introduce the categorical notion of "equivalence modulo final coalgebra semantics"; we shall call it FCS-equivalence for short.Definition 5.3.Assume that there is a final F -coalgebra ζ : Z ∼ = → F Z, and that C has finite limits.On a coalgebra X c → F X, the FCS-equivalence FCSEq c is the kernel pair of the unique map beh c : X → Z induced by finality.Equivalently, is an equalizer.
It is easily seen that the two "relations" TestEq c and FCSEq c on X are equivalence relations in the sense of [23,Section 1.3].That is, they satisfy the reflexivity, symmetry, and transitivity conditions when the conditions are suitably formulated in categorical terms.Now our concern is the comparison between two process semantics TestEq c and FCSEq c , as subobjects of X × X.The following lemma is crucial for our investigation; in fact it is important for coalgebraic modal logic in general and appears e.g. as [32,Theorem 3.3].
Lemma 5.4.A morphism of F -coalgebras preserves theory maps.That is, Proof.The following induction diagram proves P f • d = c .Naturality of δ plays an important role there.
Then the claim follows from naturality of the transposition (5.3).
We show that in a testing situation like (5.1), tests respect final coalgebra semantics.That is, testing does not distinguish two FCS-equivalent states.Proof.It suffices to show that the arrow q 1 , q 2 in (5.5) equates the parallel arrows in (5.4); then the claim follows from universality of an equalizer.
Here ( * ) is an instance of Lemma 5.4: beh c is a morphism of coalgebras from c to the final ζ.
The converse TestEq c ≤ FCSEq c does not hold in general.For a fixed type of systems (i.e. for fixed F : C → C), we can think of logics with varying degree of expressive power; this results in process equivalences with varying granularity.This view is systematically presented by van Glabbeek in [57] as the linear time-branching time spectrum-a categorical version of which we consider as an important direction of future work.
It is when we have FCSEq c → TestEq c that a modal logic (considered as a testing situation) is said to be expressive.Recall that FCSEq c usually coincides with bisimilarity if C is Sets: in this case an expressive logic captures bisimilarity.
The following proposition states a (rather trivial) equivalent condition for a testing situation to be expressive.For more ingenious sufficient conditions-which essentially rely on the transpose of δ being monic-see e.g.[32].We have beh c • p 1 = beh c • p 2 since th ζ is a mono.
To prove the "only if" direction, first we observe that the FCS-equivalence on the final coalgebra ζ : Remark 5.7.The literature [5,6] considers more restricted settings than the testing situations in Definition 5.1.There an adjunction S op ⊣ P is replaced by a dual equivalence of categories, and a denotation δ is required to be a natural isomorphism.These additional restrictions allow one to say more about the situations: logics are always expressive; the main concern of [6] is how to present an abstract modal logic M : A → A by concrete syntax.However, for our purpose in Section 5.2 the greater generality of our notion of testing situations is needed.

5.2.
Canonical testing for trace semantics in Kℓ(P).In this section we shall present a canonical testing situation for coalgebras in Kℓ(P).We shall also show that the testing is "expressive," in the sense that the testing captures final coalgebra semantics.The intuition is as follows.
Trace semantics for non-deterministic systems assigns to each system c its "(finite) trace set" map tr c : X → PA, where A carries an initial algebra in Sets.This suggests a natural testing framework where: an element t of A is a test; a state x ∈ X of a system passes a test t if and only if the trace set of x includes t (i.e.x |= t ⇐⇒ t ∈ tr c (x)).An important point here is that A, carrying an initial algebra in Sets, usually gives a well-founded syntax for tests. 9 We focus on a non-deterministic setting (i.e.T = P) in this section and leave a probabilistic one as future work.Although the above intuition is true in probabilistic settings 9 Recall the construction of an initial algebra in Sets via the initial sequence (Proposition A.1).The set A is the colimit (union in Sets) of the initial sequence 0 → F 0 → F 2 0 → • • • .Each F n 0 can be thought of as the set of terms with depth ≤ n.
as well-where the 2-valued (pass/failure) observation scheme is replaced by the refined [0, 1]-valued one-we do not know yet how to extend the current material to probabilistic settings.The difficulty is that the category Kℓ(D) is not self-dual, as opposed to Kℓ(P); see (5.6) below.
The canonical testing situation which captures finite trace semantics is the following one.Here J ⊣ K is the canonical Kleisli adjunction.Recall the self duality Op : Kℓ(P) op ∼ = → Kℓ(P) from Section 3.2.The denotation is given by (the components of) the distributive law λ : F P ⇒ PF .The following lemma establishes naturality of the denotation.Lemma 5.8.Let F : Sets → Sets be a functor which preserves weak pullbacks, and F be its lifting induced by the relation lifting (Lemma 2.3).Then the components F PX λ X → PF X of the corresponding distributive law λ also form a natural transformation

Kℓ(P) op
Proof.The desired natural transformation is obtained from another natural transformation Here the equality ( * ) is the one in (3.6).Now we describe the natural transformation λ ′ .Its components are given by those of λ; naturality of λ ′ is an easy consequence of λ's being a distributive law.Indeed, given an arrow f : X → Y in Kℓ(P), the following shows that the naturality square commutes.
The previous lemma establishes that the situation (5.6) is indeed a testing situation as defined in Definition 5.1.
In the previous Section 5.1, the use of testing situations is demonstrated through comparing testing equivalence and final coalgebra semantics, both described as suitable kernel By the definition of composition in Kℓ(P), it reads as follows in Sets.
We use this equality in showing that Op(tr c ) makes the diagram (5.2) commute.

Op(tr
Recall that M in (5.2) is now F ; P in (5.2) is now KOp.This concludes the proof.
The proposition establishes a connection between two semantics for F -coalgebras in Kℓ(P), namely: tr c via a final F -coalgebra, and th c via an initial F -algebra.One may well say that it is a "degenerate" case because, as we have shown in Section 3, coinduction in Kℓ(P) and induction in Sets are essentially the same principle.Our emphasis is more on the fact that the coincidence of induction and coinduction yields a rather uncommon example of testing situations.Testing situations are of interest in modal logic-where the underlying contravariant adjunction S op ⊣ P : A → C op in (5.1) is often the Stone duality or one of its variants.Our example Kℓ(P) op ⇆ Sets here does not look like one of those familiar examples.

Conclusions and future work
We have developed a mathematical principle underlying "trace semantics" for various kinds of branching systems, namely coinduction in a Kleisli category.This general view is supported by a technical result that a final coalgebra in a Kleisli category is induced by an initial algebra in Sets.
The possible instantiations of our generic framework include non-deterministic systems and probabilistic systems, but do not yet include systems with both non-deterministic and probabilistic branching.The importance of having both of these branchings in system verification has been claimed by many authors e.g.[48,60], with an intuition that probabilistic branching models the choices "made by the system, i.e. on our side," while (coarser) nondeterministic choices are "made by the (unknown) environment of the system, i.e. on the adversary's side."A typical example of such systems is given by probabilistic automata introduced by Segala [48].
In fact this combination of non-deterministic and probabilistic branching is a notoriously difficult one from a theoretical point of view [8,54,59]: many mathematical tools that are useful in a purely non-deterministic or probabilistic setting cease to work in the presence of both.For our framework of generic trace semantics, the problem is that we could not find a suitable monad T with an order structure.
We have used the order-enriched structure of a Kleisli category (expressing "more possibilities") to obtain the initial algebra-final coalgebra coincidence result.However, an order structure is not the only one that can yield such coincidence: other examples include metric, quasi-metric and quantale-enriched structures (in increasing generality).See e.g.[10,56] for the potential use of such enriched structures in a coalgebraic setting.The relation of the current work to such structures is yet to be investigated.
In the discipline of process algebra, a system is represented by an algebraic term (such as a.P a.Q) and a structural operational semantics (SOS) rule determines its dynamics, that is, its coalgebraic structure.This is where "algebra meets coalgebra" and the interaction is studied e.g. in [4,30,55].In our recent work [18] we claim the importance of the microcosm principle in this context and provide a "general compositionality theorem": under suitable assumptions, the final coalgebra semantics is compatible with the algebraic structure.The results of the current paper say that the final coalgebra semantics can be interpreted as finite trace semantics, hence the result in [18] also yields a general compositionality result for trace semantics.
In this paper we have included some material-on possibly-infinite traces and testing situations-which, unfortunately, we have worked out only in a non-deterministic setting.A fully general account on these topics is left as future work.
Finally, there are so many different process semantics for branching systems, between two edges of bisimilarity and trace equivalence in the linear time-branching time spectrum [57].How to capture them in a coalgebraic setting is, we believe, an important and challenging question.The dual of this construction yields a final F -coalgebra.Assume that the base category C has a terminal object 1.The final sequence of F is where !: X → 1 is the unique arrow.Assume that it has an ω op -limit (Z ζn −→ F n 1) n<ω , and also that F preserves that ω op -limit.We have the following situation.
Proof.Any F -coalgebra c : X → F X induces a cone (X βn −→ F n 1) n<ω over the final sequence in the following way.
Now we can prove the following: for an arrow f : X → Z, f is a morphism of coalgebras from c to ζ if and only if f is a mediating arrow from the cone (β n ) n<ω to the limit (ζ n ) n<ω .Hence such a morphism of coalgebras uniquely exists.
It is easy to see that every shapely functor in Sets preserves ω-colimits and ω op -limits.Hence we have the following.
Lemma A.3.A shapely functor F has both an initial algebra and a final coalgebra in Sets.
A.2. limit-colimit coincidence.We recall some relevant notions and results from [51].The idea is that in a suitable order-enriched setting, (co)limits are equivalently described as an order-theoretic notion of O-(co)limits.Due to the inherent coincidence between O-limits and O-colimits, we also obtain the so-called limit-colimit coincidence.This proposition justifies the notation e P for the projection corresponding to a given embedding e, and p E for the embedding corresponding to a given projection p.It is easy to check that (e • f ) P = f P • e P and (p • q) E = q E • p E .← • • • is an O-limit if: each γ n is a projection, and the sequence (γ E n • γ n : C → C) n<ω is increasing and its join is id C .The following proposition establishes the equivalence between (co)limits and O-(co)limits.For its full proof the reader is referred to [51].(3) Let (D τn → X n ) n<ω be a limit over the chain.Then each τ n is also a projection.Moreover (τ n ) n<ω is an O-limit.(4) Conversely, an O-limit (D τn → X n ) n<ω over the chain is a limit.
Proof.For later reference we present the proof of (4).Let (B βn → X n ) n<ω be an arbitrary cone over the chain X 0 p 0 ← X 1 p 1 ← • • • .First we prove the uniqueness of a mediating map We conclude the proof by showing that the sequence (τ E n • β n ) n<ω is increasing, hence such f indeed exists.
The last inequality holds because p E n • p n ⊑ id from the definition of embedding-projection pairs.Here we use the inherent coincidence of O-(co)limits: namely, the condition that (σ n ) n<ω is an O-colimit is exactly the same as that (σ P n ) n<ω is an O-limit.We use Proposition A.7 to conclude the proof.

c→
F X and Y d → F Y , beh c (x) = beh d (y) ⇐⇒x and y are bisimilar.

Lemma 2 . 5 .
For our three examples L, P and D of a monad T , the Kleisli category Kℓ(T ) is Cppo-enriched.Moreover, composition of arrows is left-strict: ⊥ • f = ⊥.The left-strictness of composition will be necessary later.Proof.Notice first that a set T Y for T ∈ {L, P, D} carries a cpo structure with ⊥.The set LY = {⊥} + Y carries the flat order with a bottom: y y ′ y ′′ • • • ⊥ embodying the idea that ⊥ denotes non-termination or deadlock -in contrast to for successful termination.The set PY carries an inclusion order; in DY we define d ⊑ e if d(y) ≤ e(y) for each y ∈ Y .The bottom element in DY is the zero distribution [y → 0]: this belongs to the set DY because D is the sub-distribution monad.

4. 1 .
Trace semantics by coinduction.As we have seen in Section 2.2 various types of state-based systems allow their presentation as coalgebras X → F X in a Kleisli category Kℓ(T ).For example, • LTSs with explicit termination, with T = P and F = 1 + Σ × ; • probabilistic LTSs (also called generative probabilistic transition systems in[52,58]) with explicit termination, with T = D and F = 1 + Σ × ; • context-free grammars with T = P and F = (Σ + ) * .The main observation underlying this work is the following.If we instantiate the parameters T for branching type and F for transition type in the coinduction diagram

Corollary 4 . 1 (
Trace semantics for coalgebras).Assume that T and F are such as in Theorem 3.3, and α : F A ∼ = → A is an initial F -algebra in Sets.Given a coalgebra c : X → T F X in Sets, we can assign a function tr c : X −→ T A in Sets which is, as an arrow X → A in Kℓ(T ), the unique one making the diagram (4.1) commute.We shall call this function tr c the (finite) trace semantics for the coalgebra c.Example 4.2.

Proposition 5 . 5 .
Consider such a testing situation and equivalence relations as in Definitions 5.2 and 5.3.For any coalgebra X c → F X we have an inclusion FCSEq c ≤ TestEq c of subobjects of X × X.

Proposition 5 . 6 . 4 =
Consider a testing situation as in Definitions 5.2 and 5.3.The testing is expressive, that is, for any coalgebra X c → F X we have TestEq c ∼ = → FCSEq c as subobjects of X × X, if and only if the theory map th ζ : Z → SL for the final coalgebra is a mono.Proof.We first prove the "if" direction.In view of Proposition 5.5, it suffices to show that p 1 , p 2 in (5.4) equalizes beh c • π 1 and beh c • π 2 (which proves TestEq c ≤ FCSEq c ). th ζ • beh c • p 1 = th c • p 1 by Lemma 5.th c • p 2 due to (5.4) = th ζ • beh c • p 2 by Lemma 5.4

.
This is because behζ = id : Z → Z. Now assume that th ζ • k = th ζ • l for k, l : Y ⇉ Z.Universality of an equalizerTestEq ζ induces a mediating arrow m in the following diagram.The whole diagram commutes since TestEq ζ ∼ = FCSEq ζ (by assumption) and FCSEq ζ ∼ = Z (by the above observation), both as subobjects of Z × Z.This proves k = l.

λ
′ : F K =⇒ KF : Kℓ(P) −→ Sets which we describe in a moment, by post-composing the functor Op.That is, the desired one is the composite

Proposition A. 1 .
The F -algebra α :F A ∼ = → A is initial.Proof.For future reference we prove the dual result: see Proposition A.2.
obvious coincidence O-colimit The notions of O-(co)limits are stated in terms of embedding-projection pairs which we can define in an order-enriched category.In the sequel we assume the Cppo-enriched structure.Definition A.4 (Embedding-projection pairs).Let C be a Cppo-enriched category.A pair of arrows X e p Y in C is said to be an embedding-projection pair if we have p • e = id and e • p ⊑ id.Diagrammatically presented, By p • e = id we automatically have that e is a mono and p is an epi.Both split.Proposition A.5.Let (e, p), (e ′ , p ′ ) : X ⇄ Y be two embedding-projection pairs with the same (co)domains.Then e ⊑ e ′ holds if and only if p ′ ⊑ p.As a consequence, one component of an embedding-projection pair determines the other.

Definition A. 6 ( 0 → X 1 f 1 →→ 0 ← Y 1 g 1
O-(co)limits).Let X 0 f • • • be an ω-chain in a Cppo-enriched C. A cocone (X n σn → C) n<ω over this chain is said to be an O-colimit if:• each σ n is an embedding;• the sequence of arrows ( Cσ P n X n σn C ) n<ω is increasing.Moreover its join taken in the cpo C(C, C) is id C .Y n ) n<ω over an ω op -chain Y 0 g

Proposition A. 7 ( 0 → X 1 e 1 → 0 ← X 1 p 1 ←
Propositions A, B, C, D in[51]).Let X 0 e • • • be an ω-chain where each e n is an embedding.(1)Let (X n σn → C) n<ω be the colimit over the chain.Then each σ n is also an embedding.Moreover, (σ n ) n<ω is an O-colimit.(2) Conversely, an O-colimit (X n σn → C) n<ω over the chain is a colimit.Dually, let X 0 p • • • be an ω op -chain where each p n is a projection.

Theorem A. 8 ( 0 → X 1 e 1 →
Limit-colimit coincidence).Let X 0 e • • • be an ω-chain where each e n is an embedding, and (X n σn → C) n<ω be the colimit over the chain.Then each σ n is an embedding, and the cone (C σ P n → X n ) n<ω is a limit over the ω op -chain X 0 limit of an ω op -chain of projections consists of projections.By taking the corresponding embeddings we obtain a colimit of an ω-chain of embeddings.Proof.We prove the first statement.By Proposition A.7 each σ n is an embedding, and moreover (σ n ) n<ω is an O-colimit.Now obviously (σ P n ) n<ω is a cone over X 0