Coalgebras for Bisimulation of Weighted Automata over Semirings

Weighted automata are a generalization of nondeterministic automata that associate a weight drawn from a semiring $K$ with every transition and every state. Their behaviours can be formalized either as weighted language equivalence or weighted bisimulation. In this paper we explore the properties of weighted automata in the framework of coalgebras over (i) the category $\mathsf{SMod}$ of semimodules over a semiring $K$ and $K$-linear maps, and (ii) the category $\mathsf{Set}$ of sets and maps. We show that the behavioural equivalences defined by the corresponding final coalgebras in these two cases characterize weighted language equivalence and weighted bisimulation, respectively. These results extend earlier work by Bonchi et al. using the category $\mathsf{Vect}$ of vector spaces and linear maps as the underlying model for weighted automata with weights drawn from a field $K$. The key step in our work is generalizing the notions of linear relation and linear bisimulation of Boreale from vector spaces to semimodules using the concept of the kernel of a $K$-linear map in the sense of universal algebra. We also provide an abstract procedure for forward partition refinement for computing weighted language equivalence. Since for weighted automata defined over semirings the problem is undecidable in general, it is guaranteed to halt only in special cases. We provide sufficient conditions for the termination of our procedure. Although the results are similar to those of Bonchi et al., many of our proofs are new, especially those about the coalgebra in $\mathsf{SMod}$ characterizing weighted language equivalence.


Introduction
Bisimulation was introduced by Park and Milner [Par81,Mil89] for characterizing the equivalence of two processes specified by transition systems or process algebra terms.Over the years the notion has had an enduring impact on the study of the behaviour of systems, with ramifications in concurrency, automata theory, modal logic, coalgebras, games and formal verification.The basic notion of bisimulation for discrete systems has been extended to probabilistic, quantitative and even continuous systems.
Coalgebras are a category theoretic concept that enable a study of state transition systems and their behaviours in a unified setting [Rut00,Jac16].The idea behind a coalgebraic theory of systems is the following.Given an endofunctor F : C → C on a concrete category C, a coalgebra f : X → FX represents a transition system on the set of states X possibly with additional structure.For example, in Set, the category of sets and maps, a coalgebra for the endofunctor F d X = 2 × X A represents a deterministic automaton with states X and alphabet A. This is because a coalgebra for F d can be seen as a map o, δ : X → 2 × X A where o : X → 2 is the output map indicating whether a given state is accepting and δ : X → X A is the transition map where δ(x)(a) is the next state on reading the letter a in state x.Here 2 = {0, 1} is the set of truth values.Similarly a coalgebra for the endofunctor F n (X) = 2 × (P ω X) A on Set, where P ω X is the finite powerset of X, represents a nondeterministic automaton.Homomorphisms between coalgebras can be seen as behaviour-preserving maps.A final coalgebra for the functor F : C → C, if it exists, is the universe of all possible F-behaviours.The unique arrow from any coalgebra to the final coalgebra maps a state to its behaviour.The final coalgebra for the functor F naturally induces a notion of F-behavioural equivalence, denoted by ≈ F .Two states are behaviourally equivalent if they are mapped to the same element in the final coalgebra by the unique arrow.For example, for deterministic automata, the behaviour of a state is the language accepted by the automaton starting from that state; two states x and y satisfy x ≈ F d if and only if they are language equivalent.For nondeterministic automata, two states are F n -behaviourally equivalent for the functor F n on Set defined above if and only if they are bisimilar.However, if we consider the category Rel of sets and relations, the behavioural equivalence for a suitable functor coincides with language equivalence [HJS07] of nondeterministic automata.Thus the notion of behavioural equivalence for the same computational object is relative to the underlying category and the associated endofunctor.
In this paper we focus on bisimulation for weighted automata [Buc08].Weighted automata were introduced by Shützenburger [Sch61] and have found renewed interest in the last two decades [DKV09] as they arise in various contexts where quantitative modelling is involved.Intuitively, weighted automata generalize the notion of nondeterministic automata where each state and each transition has an associated weight valued in some semiring.Such a weight could represent a cost, reward or probability, or any other measure of interest.Like nondeterministic automata, the behaviour of weighted automata have two different characterizations, in terms of weighted language equivalence and weighted bisimulation.
In [BBB + 12] Bonchi et al. have given a comprehensive account of both weighted-language equivalence and bisimilarity of weighted automata in terms of coalgebras of an endofunctor L on Vect (the category of vector spaces and linear maps) and an endofunctor W on Set, respectively.The characterization of weighted language equivalence, is based on an elegant notion of linear bisimulation given by Boreale [Bor09].The idea here is that a weighted automaton is a vector space (of states) over a field K, with two linear maps: the output map from states to observations valued in K and an A-indexed family of transition maps from states to states, where A is the set of actions.Then, a linear relation over states is a set of pairs whose differences form a subspace of the vector space and a linear bisimulation is a linear relation that preserves the output map and (the corresponding subspace) is invariant under the transition maps.Boreale showed that this notion of linear bisimulation coincides with weighted language equivalence.Bonchi et al. [BBB + 12] gave a coalgebraic formulation of these results using an endofunctor L on Vect.
Weighted automata were originally defined over semirings and not fields.Therefore, it is desirable that the results of Boreale [Bor09] and Bonchi et al. [BBB + 12] related to linear bisimulation and language equivalence be generalized to semimodules over semirings.This is exactly what we accomplish in this paper, starting with the assumption that K is a semiring.Bonchi et al. had identified in their work the results which could be extended to semirings in a straightforward way, and the ones which could not, because the latter involve Boreale Our work

Domain of weights
Table 1.Correspondence between previous work and ours the minus operator in fields.These are the the results of Boreale on linear bisimulation and their coalgebraic formulation which make essential use of the properties of fields and vector spaces.We show that there is an elegant characterization of these concepts in the semiring-semimodule setting, by leveraging the concept of kernel of a K-linear map in the universal algebraic sense, i.e., ker(f } and its universal properties.We show that in the special case that K is a field, our results are identical to those of [Bor09] and [BBB + 12].Our coalgebraic characterization of linear bisimulation proceeds as follows.We define a K-linear relation on a semimodule V over the semiring K as the kernel of a K-linear map f : V → W with domain V .Clearly, this is an equivalence relation which is a congruence.In fact any relation R on V can be turned into a K-linear relation by considering the smallest congruence R containing R and taking f to the be canonical map V → V /R that sends each element to its congruence class.A K-linear bisimulation on a weighted automaton is then defined as a K-linear relation which preserves the output map of the weighted automaton and is invariant under the transition map as in [BBB + 12].We show that this approach leads to all the results of [BBB + 12] regarding the functor L and weighted language equivalence although the proofs are new as we cannot assume the field properties of K, in particular the existence of the additive inverse.Table 1 is a summary of the correspondence between the key concepts in [Bor09, BBB + 12] and the present work. We briefly summarize our work highlighting the contributions.After introducing the basic definitions and notation we recall the notion of a K-weighted automaton (Section 2.4) and K-weighted bisimulation (Section 2.5).We use the definition of Bonchi et al. [BBB + 12] but assume that the underlying set of weights is a semiring K.We use the terms Kweighted automaton and K-weighted bisimulation to distinguish our setting from that of [BBB + 12].The fact that K-weighted automata are W-coalgebras for an endofunctor W on Set follows, and so does the correspondence between K-weighted bisimulations and kernels of W-homomorphims (Section 2.6).This result uses our definition of kernels, so there is some novelty here.The proof that K-weighted bisimilarity ∼ w coincides with W-behavioural equivalence ≈ W is the one in [BBB + 12] presented in a different way.
The main focus of our work is on the coalgebras of the functor L on SMod, the category of semimodules over the semiring K.We start by defining the functor L and proceed to define the notions of K-linear automata as coalgebras for the functor L. We define their behaviour in terms of weighted languages and present the final L-coalgebra (Section 3.1).This part is more or less similar to the treatment in [BBB + 12] as it does not rely on any vector space property not enjoyed by a semimodule.The point of departure in our work from that of [BBB + 12] is the definition of K-linear relations and K-linear bisimulations (Section 3.2) based on the kernel (in the universal algebraic sense) of K-linear maps as mentioned above.We prove the correspondence between K-linear bisimulations and kernels of L-homomorphisms and establish the coincidence of the behavioural equivalence ≈ L and weighted language equivalence ∼ l (Section 3.2).Although these results mirror those of [BBB + 12], the proofs, other than the one for the coincidence of ≈ L and ∼ l , are new and more general -they truly extend the results from the vector space setting to the semimodule setting in a non-trivial way.This is where the main contribution of this paper lies.
One desideratum is the existence of a partition refinement algorithm for computing the weighted language equivalence ∼ l for finitely generated semimodules.Unfortunately, the results from Bonchi et al. [BBB + 12] do not carry over to our semimodule setting.First, even finitely generated semimodules do not have the descending chain property: they can have an infinite descending chain of submodules.Also, weighted language equivalence is known to be undecidable for finite-state weighted automata over the tropical semiring [Kro94,ABK20].Instead, we offer an abstract procedure via the final sequence whose limit exists in SMod.The limit of the final sequence is shown to be isomorphic to the final coalgebra for the functor L, essentially following the reasoning in [BBB + 12].It is well-known that if the final sequence stabilizes at an object that object is isomorphic to the final coalgebra.For any K-linear weighted automaton there is a cone to the final sequence such that the kernel of the arrows in the cone constitute a sequence of K-linear relations.We show that these K-linear relations converge to L-bisimilarity, i.e., language equivalence, in a finite number of steps in case the state space of the automaton is a finitely generated Artinian semimodule (those satisfying the descending chain property) as well as when a weaker condition holds (Section 4.1).Unfortunately, this does not give us an algorithm for computing the bisimilarity relation in general, as this involves solving K-linear equations.Although this is possible for specific semirings, such as R, Z and N, the problem is known to be undecidable for certain semirings [Nar96].We conclude the paper by comparing our work with the only existing coalgebraic formulation of partition refinement for weighted automata over semirings, that of König and Küpper [KK18] (Section 4.2).

K-Weighted Automata and K-Weighted Bisimulation
This section is a mild generalization of the coalgebraic characterization of weighted automata and weighted bisimulation in Bonchi et al. [BBB + 12] from the setting of vector spaces to semimodules.We start by fixing the notation and recalling the basic notions of semimodules and coalgebras.Then we show how weighted automata over a semiring K can be seen as a coalgebra over a functor W : Set → Set and characterize weighted bisimilarity ∼ w as the behavioural equivalence ≈ W for the functor W. The results and proofs are essentially identical to those in [BBB + 12], as they do not use the additional properties satisfied by vector spaces.We include them for the sake of completeness.The only exception to this is the correspondence between K-weighted bisimulation and kernels of W-homomorphisms in Section 2.6, which uses our definition of kernel and is therefore new.
2.1.Notation and Preliminaries.We denote sets by capital letters X, Y, Z, . . .and maps (i.e., functions) by small letters f, g, h, . ... We denote the identity map on a set X by id X .Given two maps f : X → Y and g : Y → Z, their composition is denoted g • f : X → Z.The product of two sets is denoted X×Y with the projections π 1 : X×Y → X and π 2 : X×Y → Y .The product of two maps f 1 : ).Given maps f : X → Y and g : X → Z, f, g : X → Y × Z is the pairing map defined by f, g (x) = (f (x), g(x)).We use N for the set of natural numbers, Z for the integers, R for the set of reals and R + for the set of non-negative reals.
The disjoint union of sets X 1 and X 2 is X 1 + X 2 with the injections ι 1 : The set of all finite subsets of X is denoted by P ω (X).For a finite set of letters A, A * denotes the set of all finite words over A. We denote by the empty word, and by w 1 w 2 the concatenation of words w 1 , w 2 ∈ A * .The length of a word w is denoted by |w|.
If R is an equivalence relation on a set X we denote the set of equivalence classes of R by X/R and the equivalence class of an element x ∈ X by 2.2.Semirings and Semimodules.Semirings and semimodules generalize the notions of fields and vector spaces, respectively.A semiring (K, +, ., 0, 1) consists of a commutative monoid (K, +, 0) and a monoid (K, ., 1) such that the product distributes over the sum on both sides and k.0 = 0.k = 0 for all k ∈ K.We will refer to the semiring K when the operations are understood.A semiring module, or simply a semimodule V over a semiring K is a commutative monoid (V, +, 0) together with an action .: An equivalence relation R on a semimodule V is called a congruence if all the semimodule operations are compatible with R, i.e., for all k ∈ K and It is easy to verify that the quotient V /R has a semimodule structure given by the operations k.
The fact that these are well-defined, i.e., independent of the choice of representative of an equivalence class, is a consequence of R being a congruence.
For a K-linear map f : It can be shown that ker(f ) is a congruence.It follows that V /ker(f ) is a semimodule.Further, every K-linear map f has a unique (up to isomorphism) factorization into two K-linear maps, a surjection ε f : V → V /ker(f ) followed by an injection In the following, when we refer to the kernel of a K-linear map f , we mean the kernel of f as defined above and not the set {u | f (u) = 0}.This usage is common in universal algebra [BS81].
Let V be a K-semimodule.A nonempty subset U of V is called a subsemimodule of V if U is closed under addition and scalar multiplication.The intersection i∈I U i of any family {U i } i∈I of subsemimodules of V is clearly a subsemimodule of V .If U is any nonempty subset of V then the intersection of all subsemimodules of V containing U is called the subsemimodule generated by U , and is denoted by span(U ).It is easy to check that span(U ) is the set of finite linear combinations of elements of U Semimodules over a semiring K and K-linear maps form the category SMod.SMod has products V × W , and the set of all maps V A from a set A to a semimodule V has a natural semimodule structure defined pointwise: for f, g For a set X, the set of all maps f : X → K with finite support, i.e., the set {x | f (x) = 0} is finite, is denoted K(X).Its elements are conveniently represented as formal sums x∈X k x .xby writing k x = f (x).In other words, K(X) = span(X), where we identify an element x ∈ X with the map η X (x) = δ x : X → K where δ x is the Kronecker delta that maps x to 1 and everything else to 0. Note that only a finite number of k x are non-zero in the formal sum.K(X) is called the free semimodule generated by X over K and satisfies the following universal property.Given any map f : X → V from a set X to a semimodule V there exists a unique K-linear map f : K(X) → V which extends f .The map f is just the linear extension of f i.e., f In many categories the pair (X, f ) represents a transition system such as a deterministic, nondeterministic or probabilistic automaton [Rut00].A morphism of F-coalgebras, or an F-homomorphism, between coalgebras (X, f ) and (Y, g) is a C-arrow h : X → Y such that the following diagram commutes. (2.5) Figure 1.Bisimulation quotient of weighted automata over different semirings x 0 x 2 x 1 x 3 1 The final coalgebra represents the universe of all possible F-behaviours and the arrow F X maps every element (or state) of a coalgebra X to its behaviour [Rut00].Two states x 1 , x 2 ∈ X are said to be F-behaviourally equivalent, denoted 2.4.K-Weighted Automata.A weighted automaton [DKV09] is a generalization of a nondeterministic finite automaton where each transition and each state is assigned a weight in a semiring K.We follow the definition in [BBB + 12].Formally, for a semiring K, a K-weighted automaton (K-WA in short) with input alphabet A is a pair (X, o, t ) where X is a set of states, o : X → K is a output map and t : X → (K X ) A is the transition map.The state x can make a transition to state y on input a ∈ A with weight k ∈ K iff t(x)(a)(y) = k.A weight of zero means there is no transition.Note that the set of states X may be infinite in general.We often use X to refer to the K-WA (X, o, t ) when the output and transition maps are clear from the context.2.5.K-Weighted Bisimulation.The notion of weighted bisimulation [Buc08] generalizes the well-known notion from ordinary transition systems [Mil89] to finite-state weighted automata.We follow the definition in [BBB + 12] which applies to infinite state spaces, but with finite branching: for all x ∈ X, a ∈ A, t(x)(a)(y) = 0 for only finitely many y.In the following we assume the finite branching condition for weighted automata without stating it explicitly.
Definition 2.1.Let M = (X, o, t ) be a K-weighted automaton.An equivalence relation R on X is a K-weighted bisimulation on M if the following two conditions hold for all x 1 , x 2 ∈ X: (1) o(x 1 ) = o(x 2 ), and (2) for all a ∈ A and y ∈ X, y ∈ The largest K-weighted bisimulation relation on M is called K-weighted bisimilarity, and is denoted by ∼ w .It exists because an arbitrary union of K-weighted bisimulation relations is a K-weighted bisimulation.
Example 2.2.This example illustrates bisimulation between weighted automata for different semirings, and is adapted from [Buc08]. Figure 1(A) shows a K-weighted automaton M = (X A , o A , t A ) over the alphabet A = {a, b} and the semiring K = (R + , +, •, 0, 1).It has the set of states X M = {x 0 , x 1 , x 2 , x 3 , x 4 , x 5 }, the output map (shown in the figure as labels of the states when they are non-zero) o A given by {x 0 → 0, x 1 → 0, x 2 → 0, x 3 → 1, x 4 → 1, x 5 → 1} and the transition map t shown in the figure by the edges with their labels.For example, t(x 0 )(a)(x 1 ) = 1 3 .All missing transitions have weight zero.Let R be the smallest equivalence relation on X M containing the pairs {(x 1 , x 2 ), (x 3 , x 5 ), (x 4 , x 5 )}.R is shown in the figure as the dashed lines, which join states in the same equivalence class.It is easily checked that R is a bisimulation relation on M , and is in fact the largest such.The automaton N in Figure 1(B) is the one obtained from M by quotienting by R, where the quotient operation is defined in Section 2.6.Here the set of states is {y 0 , y 1 , y 2 } and the output map is given by {y 0 → 0, y 1 → 0, y 2 → 1}.Now consider a different semiring K = ([0, 1], max, •, 0, 1) and consider M , the automaton on the left, as a K -weighted automaton.The relation R above is again the largest bisimulation on M , but the quotient automaton P has different weights on transitions, and is shown in Figure 1(C).Here the set of states is {z 0 , z 1 , z 2 } and the output map is given by {z 0 → 0, z 1 → 0, z 2 → 1}.Notice the difference in the weights on the edges (y 0 , y 1 ) and (z 0 , z 1 ).The former is obtained by addition whereas the latter by the max operation on the pair ( 1 3 , 1 3 ).
2.6.Coalgebraic Model for K-Weighted Automata and K-Weighted Bisimulation.Following [BBB + 12], we now exhibit a functor W : Set → Set such that a W-coalgebra is just a K-weighted automaton and ≈ W is exactly K-weighted bisimilarity.
Definition 2.3.For a semiring K the valuation functor K( ) : Set → Set is defined by the mappings X → K(X) on sets X and → K(Y ) on maps, where K(h) Recall that for a given set C, the functor C × : Set → Set sends a set X to C × X and a map f : X → Y to the map id C × f .The functor W : Set → Set is defined by W = K × (K( )) A where ( ) A is the exponential functor defined earlier.Thus a Wcoalgebra f : X → WX on a set X constitutes a pair of maps o, t where o : X → K and t : X → K(X) A .In other words, a W-coalgebra is identical to a K-weighted automaton (X, o, t ) and vice versa under the assumption of finite branching, since K(X) is the set of maps G : X → K with finite support, which means t satisfies the finite branching property.
It is shown in Bonchi et al. [BBB + 12] that the functor W, being bounded, has a final coalgebra (Ω, ω).Moreover, the behavioural equivalence ≈ W coincides with K-weighted bisimilarity ∼ w .It is also shown that K-weighted bisimilarity is strictly included in weighted language inclusion.For completeness we recall the proof by Bonchi et al. of the coincidence of the two relations ≈ W and ∼ w .
Recall that a map h : X → Y is a W-homomorphism between weighted automata, i.e., W-coalgebras, (X, o X , t X ) and (Y, o Y , t Y ) when the following diagram commutes.
) and For any and for all a ∈ A, for all y ∈ Y which in turn implies that for all x ∈ X (x ,x )∈ker(h) Conversely, every K-weighted bisimulation R on (X, o X , t X ) induces a coalgebra structure (X/R, o X/R , t X/R ) on the quotient set X/R where o X/R : X/R → K and t X/R : X/R → (X/R) A are defined by As R is a K-weighted bisimulation, both o X/R : X/R → K and t X/R : X/R → (X/R) A are well-defined, i.e., independent of the choice of representative of an equivalence class.Now, the map ε R : X → X/R which sends x to its equivalence class [x] R is a W-homomorphism.Therefore we have the following commuting diagram, where the dashed arrows constitute the unique W-homomorphisms to the final coalgebra (Ω, ω).
Theorem 2.4.Let (X o, t ) be a weighted automaton.Then for Proof.The equality of the two relations ∼ w and ≈ W follows by diagram chasing.By definition, ≈ W = ker( W X ) and this is is a K-weighted bisimulation since W X is a Whomomorphism as witnessed by the curved and dashed arrows in the diagram, which implies ≈ W ⊆∼ w .In the other direction, We now define K-weighted language equivalence ∼ l for K-weighted automata and show that K-weighted bisimilarity is a refinement of K-weighted language equivalence.The proof is from [BBB + 12].
A K-weighted language over an alphabet A and semiring K is a map σ : A * → K that assigns to each word w ∈ A * a weight in K.For a K-WA (X, o, t ) the map σ l : X → K A * assigns to each state x ∈ X the K-weighted language recognized by x and is defined by induction on w as follows.
Proof.We prove by induction on the length of w that if R is a K-weighted bisimulation on X then for all x 1 , x 2 ∈ X and all w ∈ A * , (x 1 , x 2 ) ∈ R implies σ l (x 1 )(w) = σ l (x 2 )(w).For the base case w = , we have σ l (x 1 )(w) = o(x 1 ) and σ l (x 2 )(w) = o(x 2 ) and o(x 1 ) = o(x 2 ) since R is a K-weighted bisimulation.For the inductive case, if w = aw then ).σ l (x )(w )) since by the induction hypothesis for all x ∈ [x ] R , σ l (x )(w ) = σ l (x )(w ) and by grouping the states w) by an argument similar to the first two lines above.
Example 2.6.Figure 3 is an adaptation of a familiar example from the process algebra literature that shows that K-weighted bisimilarity strictly refines K-weighted language equivalence.Here K = (R + , +, •, 0, 1).The states x 0 and y 0 are language equivalent, since Figure 3. Weighted language equivalence and weighted bisimulation 2 and σ l (x 0 )(ac) = σ l (y 0 )(ac) = 1 2 and σ l (x 0 )(w) = σ l (y 0 )(w) = 0 for all other words w.But it is easily checked that x 0 and y 0 are not bisimilar.

K-Linear weighted automata as Coalgebras over Semimodules
The goal of this section is to show that there is a functor L : SMod → SMod for which behavioural equivalence ≈ L coincides with weighted language equivalence ∼ l of K-linear weighted automata, extending the results of Bonchi et al. [BBB + 12] to the category of semimodules.Although the functor L appears to be the same as in [BBB + 12] the underlying details are different.The latter are based on a generalization of the notion of a linear weighted automaton in [Bor09, BBB + 12] from the setting of vector spaces to semimodules.We propose definitions of a K-linear relation and a K-linear bisimulation that generalize the notions of a linear relation and a linear bisimulation from [Bor09].This is the central part of the paper where the definitions and proofs do not mirror those in [Bor09, BBB + 12].In particular the notion of subspace of a vector space is replaced by that of the kernel (in the universal algebraic sense) of a K-linear map.But it is remarkable that all proofs go through and we obtain a true generalization of the concepts from vector spaces to semimodules.
3.1.K-Linear Weighted Automata.The following definition is a generalization of a linear weighted automaton of [Bor09] from the setting of vector spaces and linear maps to that of semimodules over a semiring K and K-linear maps.Note that we use the term "K-linear weighted automaton" to distinguish it from the "linear weighted automaton" of [Bor09, BBB + 12].Definition 3.1.A K-linear weighted automaton (K-LWA in short) with input alphabet A over the semiring K is a coalgebra for the functor L = K × ( ) A : SMod → SMod.
A K-LWA can be presented as a pair (V, o, t ) where V is a semimodule over K whose elements are called states, o : V → K is a K-linear map assigning an output weight to every state and t : V → V A is a K-linear transition map that, given a current state v and input a, assigns a new state t(v)(a).We write v 1 a −→ v 2 for t(v 1 )(a) = v 2 .We often use V to refer to the K-LWA (V, o, t ) when the output and transition maps are clear from the context.The behaviour of K-LWA is described by weighted languages.The K-linear weighted language recognized by a state v ∈ V of a K-LWA (V, o, t ) is the map σ l (v) : A * → K defined by induction on words W by: for all w ∈ A * .Note that we overload the symbol σ l to denote weighted language equivalence for both K-weighted automata and K-linear weighted automata.The context disambiguates which concept the symbol denotes.Later in this section we show that σ l (v) = v L V , the image of v under the unique L-homomorphism from V into the final L-coalgebra.
Given a K-WA (X, o, t ) (see Section 2.4), we can construct a K-LWA (K(X), o , t ), where K(X) is the free semimodule generated by X and o and t are linear extensions of o and t.It can be shown that the above K-WA X and the K-LWA K(X) have equivalent language behaviour, i.e., the corresponding states x and η X (x) recognize the same weighted language for all x ∈ X.
Recall that a K-linear map h : For the special case when the K-LWA V = K(X) and W = K(Y ) for given K-WA X and Y as above, we have the following situation.For a map h : X → Y , the map Bonchi et al. [BBB + 12] showed that the final L-coalgebra is defined on the set of all weighted languages K A * as follows.Consider the structure (K A * , , d) with the output map and the transition map d where : K A * → K, called the empty map, is defined by (σ) = σ( ) and d : We first show that the map d is K-linear.If σ 1 and σ 2 are two weighted languages in as desired.The proof of K-linearity of is similar.Hence (K A * , , d) is a coalgebra in SMod.
We now recall the proof from [BBB + 12] that it is the final coalgebra in SMod.
Proof.It is easy to check that the map L V = σ l : V → K A * which maps every state v ∈ V to the weighted language σ l (v) is the only one that makes the following diagram commute in Set.
w) for all w ∈ A * by a routine induction on the length of the word w.
It follows that two states v 1 , v 2 ∈ V are L-behaviourally equivalent, i.e., v 1 ≈ L v 2 iff they recognize the same weighted language.
3.2.K-Linear Bisimulation.In this section we generalize the definition of Boreale's linear weighted bisimulation [Bor09] from a field to a semiring K.We show that the two notions coincide in the special case when K is a field, for example K = R, as in [Bor09].Starting with this section almost all the results are our contribution and involve new concepts and proofs.
Definition 3.3.A binary relation R on a K-semimodule V is K-linear if there exists a Ksemimodule W and a K-linear map f : Such a relation is denoted by R f for the given f .It is immediate that a K-linear relation on a K-semimodule V is an equivalence relation which, in addition, is a congruence.Moreover, there is a canonical way of turning any relation R on K(X) into a K-linear relation R as follows.Let R be the least congruence relation on V containing R. R is obtained by taking the intersection of all congruences on V that contain R and is well-defined since the universal relation is a congruence and the intersection of any family of congruences is a congruence.The quotient set V /R has a K-semimodule structure given by It is easy to check that f is a K-linear map and R = ker(f ) by construction.Hence R is a K-linear relation.The following lemma is an easy consequence of the definitions.Lemma 3.4.For any binary relation R on a K-module V , R is the smallest K-linear relation containing R.
Note that for a given K-linear relation R there may be two distinct K-linear maps f, g : V → W with the same codomain such that R = ker(f ) = ker(g).On the other hand, all such maps factor uniquely through the map ε f : V → V /kerf that sends v ∈ V to its equivalence class [v] in kerf .Also, note that for any injective map f : V → W , R f is the identity relation on V .For the zero map 0 V,W : V → W which maps every element in V to 0, R 0 V,W is the universal relation on V .4:17 final sequence (or terminal sequence).In general the construction takes steps indexed by ordinals that can go beyond ω, although for semimodules no more than ω steps are necessary as is shown below, the proof being identical to that of [BBB + 12].In special cases, such as for finite dimensional vector spaces, and the free semimodules Z(X) and N(X) for a finite set X, the construction terminates after a finite number of steps and the required operations can be performed effectively.In this case the procedure is the same as the forward algorithm of [Bor09, BBB + 12].We identify sufficient conditions for the termination of the final sequence construction.The construction terminates for Artinian semimodules as one would expect.But we also show that a weaker condition identified in [DK12, KK18] also suffices.Our presentation below has a lot in common with that of [BBB + 12], but also has major differences due to the less enriched setting of semimodules as compared to vector spaces.
4.1.The Partition Refinement Procedure.The final sequence of the functor L = K × ( ) A : SMod → SMod is the countable cochain {W i } i∈N shown below Here 1 is the terminal object {0} in the category SMod and !denotes the unique arrow from L(1) to 1. L i is simply the i-fold composition of L, with L 0 being the the identity functor.
Adámek and Koubek [AK95] showed that in a category C with limits of all ordinal indexed cochains if the final sequence of a functor T : T 2 (!) ← . . . .stabilizes at ordinal k, in the sense that the arrow T k (!) : T k+1 (1) → T k (1) in the final sequence is an isomorphism, then (T k (1), (T k (!)) −1 ) is a final T -coalgebra.Moreover, the existence of a final coalgebra is sufficient to ensure stabilization of the final sequence.Below we show that in SMod the final sequence for L stabilizes at or before the index ω by essentially repeating the proof for vector spaces in [BBB + 12].
The objects and arrows in the cochain can be described as follows.Following the steps in [BBB + 12] we can show that for each n ∈ N, L n (1) is isomorphic to K A * n , where A * n is the set of all words of length less than n.The proof is by induction on n.
1 by definition.By the induction hypothesis, we have that an element k, σ n can be seen as a function that maps to k and aw to σ(a)(w) for a ∈ A and w ∈ A * n .Similarly, it can be shown that the arrow L n (!) : L n+1 (1) → L n (1) maps a function σ ∈ K A * n+1 to its restriction σ A * n to the subset of words of length less than n.We denote σ A * n by σ n from now on.Moreover, the limit of this SMod-cochain is K A * together with the maps ζ n : K A * → L n (1) that send a weighted language σ : A * → K to its restriction σ n for each n.The limit cone is shown in the commuting diagram below.
On the other hand, any K-LWA (V, o, t ), where V is not necessarily an Artinian semimodule, defines a cone !n : V → L n (1) by induction as follows.The map !0 : V → 1 is It is easily verified that the unique arrow from the cone from V to the limit cone from K A * is the same as the unique L-coalgebra homomorphism L V from (V, o, t ) to the final coalgebra (K A * , , d).This is depicted in the following commuting diagram.
Recall from Theorem 3.8 and Corollary 3.9 that the L-behavioural equivalence relation ≈ L on an (V, o, t ) is the kernel of L V .An abstract procedure for computing the equivalence ≈ L would be to iteratively compute the kernel of the arrows !n and terminate (if ever) when ker(! n+1 ) = ker(!n ).This condition is equivalent to L n (!) : L n+1 (1) → L n (1) being an isomorphism.But first we prove two propositions that justify the abstract procedure.The second result requires V to be a finitely generated Artinian semimodule.
Proposition 4.1.Let (V, o, t ) be a K-LWA.Consider the sequence of relations over V defined inductively by Then for all n, R n is a linear relation satisfying R n = ker(!n+1 ).
Proof.We show that R n = ker(!n+1 ) for each n by induction.It follows that R n is a linear relation.For the basis, since ! 1 = o we have R 0 = ker(o) = ker(! 1 ).Suppose R n = ker(!n+1 ) for n ≥ 1.Then = ker( !n+2 ) from Equation 4.2 Here we use the following facts that can be easily checked.
However, even when the final sequence stabilizes after a finite number of steps, in general there is no effective procedure to compute the kernel of a K-linear map for a semiring K.This is because unlike in R, Z and N, for semirings in general we do not have a procedure for linear equation solving; the problem is undecidable for certain semirings [Nar96].We conclude this section by presenting a couple of examples from different semimodules to illustrate how our procedure works.
Example 4.4.Figure 5 shows a K-LWA (V, o, t ), adapted from [Sak16], over the alphabet A = {a}.The semiring K is the ring Z of integers.Here V = Z(X) where X = {x 0 , x 1 , x 2 , x 3 , x 4 }.In the example, the maps o and t are generated from their values shown against the nodes and edges, respectively, by linear extension.Missing values against nodes are assumed to be zero.Note that V is not Artinian but span(V * ) is indeed finitely generated.To see this, V 3 consists of the set containing the following maps from X to Z Now, it is easily seen that for all x ∈ X and n ≥ 2, σ l (x)(a n ) = 2 n−2 σ l (x)(aa).Therefore, span(V * ) is generated by V 3 .To apply the partition refinement procedure to this K-LWA, Figure 5.A K-linear weighted automaton over the semiring K = ([0, 1], max, ., 0, 1) we use Propositions 4.1 and 4.3.We have and as x 1 , x 3 and x 4 are the only states with nonzero weights and all of them have weight one.
In the next iteration, we have and as all the edges have weight one except the loops on x 1 and x 4 , which have weight two.It is clear that R 2 = R 1 , since we take the intersection with the same set in obtaining R 1 from R 0 as in obtaining R 2 from R 1 .Therefore, the K-linear bisimilarity relation, i.e., weighted language equivalence, is given by the set of all pairs (u, v) When V = Z(X) for a finite set X, it can be shown that the number of iterations of the loop computing R i+1 from R i is bounded by |X| and termination then follows from the decidability of linear integer arithmetic.A more efficient algorithm for deciding language equivalence between states in X (and not the entire V (X) as in our case) appears in [BLS05].In fact, this problem is decidable for any semiring that is a subsemiring of a field [Sak09].
The approach to partition refinement which has some similarity with ours is by König and Küpper [KK18].This section is a brief summary of their work followed by a comparison with the current paper.The paper generalizes the partition refinement algorithm to a coalgebraic setting, just as this paper.It proposes a generic procedure for language equivalence for transition systems, of which weighted automata over arbitrary semirings form an important special case.However, unlike the usual partition refinement approach, [KK18] does not provide a unique or canonical representative for the weighted language accepted, in general.The procedure based on the approach is not guaranteed to terminate in all cases, but does so for particular semirings, just as in our case.It is based on a notion of equivalence classes of arrows and involves solving linear equations for a given semiring.
In more detail, [KK18] uses M(K), the category of finite sets and matrices over the semiring K with matrix multiplication as composition, as the base category.This is just the Kleisli category of the free semimodule monad and is equivalent to the category of free semimodules over finite sets that we use.The endofunctor F over M(K) defining a weighted automaton is given by F X = 1 + A × X.This can be seen as being equivalent to our L, as the paper [KK18] uses matrices as arrows rather than maps.
The paper presents two generic procedures for partition refinement, where the second is just an optimized version of the first.The basic ingredient in the theory which is new is a preorder on objects and arrows of a concrete category C. For objects X and Y in C, this is defined by X ≤ Y if there is an arrow f : X → Y .The relation X ≡ Y holds when X ≤ Y and Y ≤ X.For arrows f : X → Y and g : X → Z with the same domain, f ≤ X g if there exists an arrow h : Y → Z such that g = h • f .Similarly, f ≡ X g if f ≤ X g and g ≤ X f .It is easy to check that ≤ and ≤ X are preorders and ≡ and ≡ X are equivalence relations.
Given a coalgebra α : X → F X in C and an arrow f : X → Y , f is called a postfixed point if f ≤ X F f • α.This is equivalent to the existence of a coalgebra β : Y → F Y with f an F -homomorphism by simply taking β as the mediating morphism that witnesses f ≤ X F f • α.The paper then shows that the largest postfixed point f : X → Y induces behavioural equivalence: x ≈ F y if and only if f (x) = f (y).
The first partition refinement procedure in [KK18], called Procedure A, uses the final sequence construction to find the largest postfixed point for general coalgebras.The second, called Procedure B, is an optimized version intended for weighted automata over a semiring.Both procedures take a coalgebra α : X → F X as input, and if they terminate, return a coalgebra β : Y → F Y along with an F -homomorphism f : X → Y from α to β that induces behavioural equivalence on X: x ≈ F y if and only if f (x) = f (y).Here x and y are elements of the underlying set of X.Note that β need not be the final coalgebra in general.
by induction as follows: !0 : X → 1 is the unique arrow to the terminal object and !n+1 = F (! n ) • α : X → F n+1 (1).What is novel here is the termination condition for Procedure A, namely !n ≤ X !n+1 , i.e., there is an arrow β : F n (1) → F n+1 (1) such that β•! n =! n+1 .This condition is equivalent to ! n ≡ X !n+1 , which is weaker than requiring that F n (!) is an isomorphism, i.e., the elements of the cochain stabilize at n, as is the case for our procedure.This can lead to earlier termination for Procedure A. When applied to weighted automata over a semiring K, the procedure yields for each n, !n+1 (x)(w) = σ l (x)(w) for w ∈ A * n , just as in our case; see Equation 4.2.The termination condition then reduces to checking whether the semimodule span({σ l ( )(w) | w ∈ A * n+1 }) equals span({σ l ( )(w) | w ∈ A * n }), the condition in Proposition 4.3, which can be done by solving linear equations in the semiring K.
Procedure B replaces !n for each n by any e n such that !n ≡ X e n , thus potentially reducing the search space.The termination depends on the semiring.In particular, termination is guaranteed when the semimodule K(X) is Artinian, as well as when the weaker condition mentioned in Proposition 4.3 holds.To summarize, although the termination condition for the procedures in [KK18] is different from ours and it can lead to more efficiency in principle, the underlying framework of the final chain is identical to ours.The question whether there are examples where Procedure A (or B) terminates and our procedure does not is still open.

Conclusion
In this paper we have continued the programme in Bonchi et al. [BBB + 12] of a coalgebraic theory of bisimulation of weighted automata.We have generalized the formal framework to one based on weighted automata on semirings rather than fields.As we have shown, almost all the results of [BBB + 12] continue to hold except for the partition refinement algorithm.The latter necessarily depends on the specific type of semiring involved.Hence we can only propose an abstract procedure for partition refinement that may not, in general, halt or lead to a solution even if it halts, because of the the lack of enough operations.We have provided sufficient conditions for the procedure to halt.We have also compared our work and Bonchi et al. [BBB + 12] to the terminal object 1, and! n = L(! n ) • o, t .More concretely, for all w ∈ A * , ! n+1 (v)(w) = o(v), if w = !n (t(v)(a)(w )) if w = aw .(4.2)Equation 4.2 says ! n (v)(w) = σ l (v)(w) for all w with |w| ≤ n, and !n (v)(w) = σ l (v)(w| n ) for all w with |w| > n, where w| n is the prefix of w of length n.

Figure 4 .
Figure 4.A K-linear weighted automaton over the ring Z