Presenting Distributive Laws

Distributive laws of a monad T over a functor F are categorical tools for specifying algebra-coalgebra interaction. They proved to be important for solving systems of corecursive equations, for the specification of well-behaved structural operational semantics and, more recently, also for enhancements of the bisimulation proof method. If T is a free monad, then such distributive laws correspond to simple natural transformations. However, when T is not free it can be rather difficult to prove the defining axioms of a distributive law. In this paper we describe how to obtain a distributive law for a monad with an equational presentation from a distributive law for the underlying free monad. We apply this result to show the equivalence between two different representations of context-free languages.


Introduction
The combination of algebraic structure and observable behaviour is fundamental in computer science.Examples include the operational models of structural operational semantics [3], denotational models of programming languages [37], finite stream circuits [24], linear and context-free systems of behavioural differential equations [30,38], and many types of automata such as nondeterministic and weighted automata [32].
In the categorical treatment of these examples, the algebraic structure is encoded by a monad T = T, η, µ , and the system behaviour by coalgebras for a functor F .Often it is desirable that the algebraic and coalgebraic structure are compatible in some way.A general approach to specifying such algebra-coalgebra interaction is via a distributive law.There are several advantages of this structured approach.A distributive law λ of the monad T over F induces a T -algebra on the final F -coalgebra of behaviours, yields solutions to corecursive equations φ : X → F T X [7], and ensures that bisimulation is a congruence [34].Moreover, it yields the soundness of techniques such as bisimulation-up-to-context [7] and extensions thereof [27,29].
Describing a distributive law explicitly and proving that it is one can, however, be rather complicated.Therefore, general methods for constructing distributive laws from simpler ingredients are very useful.An important example of this is given by abstract GSOS [34,7,21] where distributive laws of a free monad T over a (copointed) functor F are shown to correspond to plain natural transformations, called abstract GSOS-rules as they can be seen as specification formats.In [12] it was shown how an abstract GSOS-rule for a free monad T and functor F can be lifted to one for the functor F (−) A which describes F -systems with input in A. Another method which works for all monads T , but only for certain polynomial behaviour functors F , produces a distributive law inducing a "pointwise lifting" of T -algebra structure to F -behaviours, cf.[13,14,32].
But many examples do not fit into the abovementioned settings.An important motivating example for this paper is that of context-free grammars, where sequential composition is not a pointwise operation and whose formal semantics satisfies the axioms of idempotent semirings, i.e., the algebraic structure is not free.More generally, one may be interested in a monad arising from a free one by adding equations which one knows to hold in the final coalgebra.
The main contribution of this paper is to give a general approach for constructing a distributive law λ ′ for a monad T ′ with an equational presentation, from a distributive law λ for the underlying free monad T .We have no constraints on the behaviour functor F .This λ ′ is obtained as a certain quotient of λ by the equations E of T ′ , hence we say that λ ′ is presented by a λ for the free monad and the equations E. We show that such quotients exist precisely when the distributive law preserves the equations E, which roughly means that congruences generated by the equations are bisimulations.We also discuss how these quotients of distributive laws give rise to quotients of bialgebras, thereby giving a concrete operational interpretation, and a correspondence between solutions to corecursive equations with and without equations.As an illustration and application of our theory, we show the existence of a distributive law of the monad for idempotent semirings over the deterministic automata functor.This result yields the equivalence betweeen the Greibach normal form representation of context-free languages and the coalgebraic representation via context-free expressions given in [38].
Outline.In Section 2, we recall the notions of monads and algebras, and give a concrete description of monad quotients.In Section 3, we recall distributive laws and their application to solving systems of equations.Then, in Section 4, we prove our main results on quotients of distributive laws.In Section 5, we show that such quotients give rise to quotients of bialgebras.Finally, in Section 6, we discuss related work, and provide some directions for future work.
This paper is an extended version of [9].It contains all proofs and generalises the main results of [9] from monads on the category of Set to monads on arbitrary categories (with the appropriate structure in the category of algebras).Furthermore, this paper includes the treatment of distributive laws of a monad over a comonad, allowing more general specification formats that involve look-ahead in the premises.
Acknowledgements.We thank Neil Ghani, Bart Jacobs, Jan Rutten, Jiří Velebil and Joost Winter for helpful discussions and suggestions.We are indebted to the referees for their constructive comments, which greatly helped us improving the paper.

Monads, Algebras and Equations
We start by recalling some basic definitions on monads, algebras, term equations and congruences (see, e.g., [6,5] for a detailed introduction).We will then proceed to give a concrete description of the quotient monad arising from a free monad and a set of equations.
Let C be a category.A monad is a triple T = T, η, µ where T is an endofunctor on C, and η : Id ⇒ T and µ : T T ⇒ T are natural transformations such that µ Given any T -algebra A, α and any arrow f : X → A, there is a unique algebra homomorphism f ♯ : T X → A such that f ♯ • η X = f , given by f ♯ = α • T f .We denote the category of T -algebras and their homomorphisms by Alg(T ), and the associated forgetful functor by U : Alg(T ) → C.
Let T, η, µ and K, θ, ν be monads.A morphism of monads is a natural transformation σ : T ⇒ K such that the following diagram commutes: where Assume we are given a monad T = T, η, µ on some category C. We define T -equations as a 3-tuple E = E, l, r where E is an endofunctor on C and l, r : E ⇒ T are natural transformations.The intuition is that E models the arity of the equations, and l and r give the left and right-hand side, respectively.This is illustrated below by an example.
Example 2.1.Consider the Set functor ΣX = X × X + 1, modelling a binary operation and a constant, which we call + and 0 respectively.The (underlying functor of the) free monad T Σ for Σ sends a set X to the terms over X built from + and 0. The equations x + 0 = x, x + y = y + x and (x + y) + z = x + (y + z) can be modelled as follows.The functor E is defined as EX = X + (X × X) + (X × X × X).The natural transformations l, r : E ⇒ T Σ are given by l X (x) = x + 0 and r X (x) = x for all x ∈ X; l X (x, y) = x + y and r X (x, y) = y + x for all (x, y) ∈ X × X; l X (x, y, z) = x + (y + z) and r X (x, y, z) = (x + y) + z for all (x, y, z) ∈ X × X × X.
Throughout this paper we will need assumptions on C, T , and E. For this section we only need the following.Assumption 2.2.We assume that T is a monad on C, and E : C → C is a functor such that: (1) Alg(T ) has coequalizers.
(2) U and T U map regular epis in Alg(T ) to epis in C.
(3) EU maps regular epis in Alg(T ) to epis in C.
The first condition is needed to construct quotients of free algebras modulo equations.
The second condition relates quotients of algebras (regular epis) with quotients in the base category (epis).It is satisfied if either U preserves regular epis or if U preserves epis.Finally, the last condition is satisfied if E preserves epimorphisms in C.
(1) If C = Set the conditions are satisfied for any monad T and endofunctor E.
(2) If C is the category Pos of posets with monotone maps the second condition may fail, see Example 6 in [8], which can be adapted to show that the monad induced by the adjunction ¾ × (−) ⊣ (−) ¾ : Pos → Pos does map some regular epis to non-epis.
(3) If C is abelian groups and T is the identity, the well-known fact that torsion-free abelian groups are not monadic over Set [10] can be adapted to give an example of equations E that fail condition 3. Let Z n denote the group of integers with addition modulo n.Define E : C → C as the coproduct of abelian groups E(A) = n∈N C(Z n , A) and define l, r : E(A) → A by l(g) = g(1) and r(g) = 0. Note that there is g : 'has torsion'.The equations then force the quotient of A to be torsion-free (i.e., no element different than 0 has torsion).Since E(Z) = 1 and E(Z 2 ) is infinite, the epi Z → Z 2 is not preserved.Alg(T, E) is the category of torsion-free abelian groups.
Let A = A, α be a T -algebra.We denote by s A the coequalizer of l ♯ A • α and r ♯ A • α in Alg(T ) depicted in the following diagram (we suppress the forgetful functor and denote by the same symbol both an algebra morphism and its underlying C-arrow) In the case C = Set, this entails that ker(s A ) is the congruence generated by the set E A = {(α(l A (e)), α(r A (e)) | e ∈ EA}, i.e., by the least equivalence relation on A that includes E A and is a subalgebra of A, α × A, α .In this sense, the kernel pair of a morphism always yields a congruence, and conversely, every congruence relation on an algebra A, α is the kernel of the corresponding quotient homomorphism.In general, the coequaliser (2.2) in Alg(T ) differs from the one obtained by applying the forgetful functor U and then computing the coequaliser of α • l ♯ A and α • r ♯ A in Set.The coequalisers in Alg(T ) and Set coincide if the equations are reflexive in the sense that the two parallel arrows α • l A and α • r A from EA to A have a common section, and the forgetful functor U preserves reflexive coequalisers.If T is finitary, then U preserves reflexive coequalisers.Moreover, we note that if U preserves reflexive coequalisers then T preserves them too, but not every Setfunctor preserves reflexive coequalisers, cf.[4,Example 4.3].
A T -algebra A = A, α is said to satisfy E if the following diagram commutes: By Alg(T , E) we denote the full subcategory of T -algebras that satisfy E. As coequalisers are unique only up to isomorphism, we will choose s such that for all A ∈ Alg(T , E), s A = id A .
Lemma 2.4.The inclusion V : Alg(T , E) → Alg(T ) has a left-adjoint H : Alg(T ) → Alg(T , E) with unit η A = s A : A, α → A/E, α E for all A ∈ Alg(T ), and counit ǫ A = id A the identity for all A ∈ Alg(T , E).In particular, Alg(T , E) is a full, reflective subcategory of Alg(T ).
Proof.We first show that for any A = A, α in Alg(T ), A/E, α E is an object in Alg(T , E).
Consider the following diagram: The right-hand square commutes by the definition of s A , cf. (2.2).The left squares (for l and r respectively) commute by naturality of l and r.The upper two paths from T EA to A/E commute by definition of s A .From the above diagram we obtain It remains to show that for B = B, β in Alg(T , E) and an algebra morphism f : A → B there is a unique algebra morphism g : The situation is illustrated here: We have shown that s A,α : A, α → A/E, α E is an Alg(T , E)-reflection arrow for A, α .By defining H : Alg(T ) → Alg(T , E) as H A, α = A/E, α E , then H is left adjoint to V , and the unit of the adjunction is η = q.Now, since the unit and counit must satisfy By composition of adjoints, the functor U V : Alg(T , E) → Alg(T ) → C has a left adjoint given by X → T X/E, (µ X ) E .In what follows, we will write T ′ X for T X/E.This allows the following definition.Definition 2.5 (Quotient monad).Given a monad T = T, η, µ on C and T -equations E, we define the quotient monad T ′ = T ′ , η ′ , µ ′ as the monad on C arising from the composition of the adjunction H, V, η = s, ǫ = id of Lemma 2.4 and the Eilenberg-Moore adjunction G, U, η, ǫ of T : We define q : T ⇒ T ′ as the family of underlying C-arrows of reflection arrows for free algebras, i.e., Naturality of q is clear, since s is natural.Next, we show that q is a monad morphism from T to T ′ .One way of doing so is to show that q is a coequaliser in the category of monads and monad morphisms.Kelly studied colimits in categories of monads, and proved their existence in the context of some adjunction [17,Proposition 26.4]; with a bit of effort one can instantiate this to the adjunction constructed above.For a self-contained presentation in this section, we do not invoke Kelly's results but instead prove directly the part that shows the existence of a monad morphism.This is instantiated below to the adjunction of the quotient monad.
Lemma 2.6.Let A be any subcategory of Alg(T ), and suppose the forgetful functor U : A → C has a left adjoint F , with unit and counit denoted by η ′ and ǫ ′ respectively.Then (1) F induces a natural transformation κ : Proof.The functor F sends any C-object X to a T -algebra structure on U F X; we define κ X to be that algebra structure.Naturality of κ is immediate since F f is a T -algebra homomorphism for any C-arrow f .To see that κ • T η ′ is a monad morphism, consider: The top left square commutes by naturality and the middle square since any component of κ is an T -algebra.For the right square we have where the first equality follows from the triangle identity id U F = U ǫ ′ F • η ′ U F (and functoriality), and the second from the fact that ǫ ′ F X is a T -algebra homomorphism from κ U F X to κ X .The bottom left square commutes by naturality, and the triangle since κ is an T -algebra.
For (2), we first note that the composite functor under consideration maps any where the first equality is a triangle identity and the second is the fact that ǫ ′ A,α is an algebra morphism.
Proof.By Lemma 2.6, we only need to show that q coincides with κ • T η ′ , where η ′ is the unit of the quotient monad.To this end consider the following diagram: Commutativity of the triangle follows from the definition of the quotient monad.For the square, notice that the components of κ are simply the quotient algebras as constructed in the proof of Lemma 2.4, and q is an algebra morphism by construction.
The above construction yields a monad T ′ given a set of operations and equations.Intuitively, any monad which is isomorphic to T ′ is presented by these same operations and equations; this is captured by the following definition.Definition 2.10.Let Σ be an endofunctor on C, T Σ the free monad over Σ, and T ′ the quotient monad of T Σ with respect to some The idempotent semiring monad is defined by the functor mapping a set X to the set P ω (X * ) of finite languages over X and, for morphisms Furthermore, η X : X → P ω (X * ) and µ X : P ω (P ω (X * ) * ) → P ω (X * ) are given by The idempotent semiring monad is presented by two constants 0 and 1, two binary operations + and •, and the idempotent semiring axioms.The witnessing isomorphism can easily be given based on the observation that every semiring term is equivalent with respect to the idempotent semiring equations to a sum of products of variables.⊳ Finally, we discuss conditions under which Alg(T , E) is isomorphic to Alg(T ′ ).In general this need not be the case due to the fact that despite both Alg(T , E) → Alg(T ) and Alg(T ) → C being monadic, their composition need not be monadic.This situation occurs in Example 2.3 (3), where Alg(T , E) is torsion-free abelian groups but Alg(T ′ ) = Alg(T ) is abelian groups [10].
A general remark in this situation is that, due to Beck's theorem, But we can do better in a situation of special interest.
We say that C is a finitary variety if C is the category of algebras for a finitary signature and equations, or, equivalently, if C is the category of algebras for a finitary monad on Set.
In particular, we have an adjoint situation F C ⊣ U C : C → Set.A signature is a functor N → Set, assigning to each 'arity' n a set of operation symbols.An endofunctor on C is said to be generated by a signature S : (Note that we cannot use such endofunctors to imitate Example 2.3(3) which relies on the Z n not being free algebras of the form F C n.) Proposition 2.12.If in the situation described in Definition 2.10 the category C is a finitary variety, and Σ and E are endofunctors on C generated by signatures, then Alg(T , E) is isomorphic to Alg(T ′ ).
Proof.This is an instance of Theorem 4.4 of [35].

Distributive Laws and Bialgebras
We briefly recall the basic definitions of distributive laws and bialgebras; for a more thorough introduction we refer to [19,7,34].
3.1.Basic Definitions.Let T = T, η, µ be a monad on a category C, and F an endofunctor on C. A distributive law λ of the monad T over the functor F is a natural transformation λ : T F ⇒ F T which is compatible with the monad structure, meaning that λ , for all X the following diagrams commute: We recall that every distributive law λ : T F ⇒ F T corresponds to a lifting F λ of F to the category of T -algebras (see, e.g., [16,19]), defined as Note that the compatibility of λ X with µ X means precisely that λ X is a T -algebra homomorphism from T F X, µ F X to F λ T X, µ X .An F -coalgebra is a pair X, c where X is a C-object and c : The following results are well known (see, e.g., [34,7,19]).If Z, ζ is a final Fcoalgebra, then a distributive law λ : T F ⇒ F T yields a final λ-bialgebra Z, α, ζ where α : T Z → Z is defined by coinduction from the F -coalgebra T Z, λ Z • T ζ .
We will need the notion of distributive laws of monads over copointed functors.A copointed functor is a pair F, ǫ where F is an endofunctor and ǫ : F ⇒ Id a natural transformation.A distributive law of T over F, ǫ is a distributive law of T over F additionally satisfying ǫ T • λ = T ǫ.For any endofunctor F on a category C with products, the cofree copointed functor generated by F is the pair Id×F, π 1 : Id×F → Id where π 1 is the natural left-projection.
When T = T Σ is the free monad generated by a (signature) functor Σ, then distributive laws involving T can be reduced to "plain" natural transformations using recursion, namely, there is a 1-1 correspondence between distributive laws λ : T Σ F ⇒ F T Σ of T Σ over F and natural transformations ρ : ΣF ⇒ F T Σ (cf.[34,7]).Such a ρ corresponds to a specification format of operational rules, and is sometimes referred to as a simple SOS specification.Similarly, for cofree copointed functors, if T Σ is freely generated by Σ, then there is a 1-1 correspondence between distributive laws λ : [21,13]).Such a natural transformation ρ is also referred to as an abstract GSOS specification since it generalises the GSOS-format for labelled transition systems where F = (P ω (−)) A , cf. [7,34].In what follows, we will generally omit Σ-subscripts on free monads in order to keep notation uncluttered.

Solutions to Corecursive
Equations.An important application of distributive laws is in solving corecursive equations which are arrows of the type φ : X → F T X where F is a functor and T is (the functor component of) a monad.These include many interesting and useful structures such as linear and context-free systems of behavioural differential equations [30,38], as well as linear, nondeterministic and weighted automata cf.[13,32].These are all instances of T -automata [13] (where T is a monad on Set) which have the type X → B × (T X) A where A is a set and B carries a T -algebra β : T B → B, i.e., in particular, F = B × (−) A whose final coalgebra carrier is B A * .
In the presence of a distributive law λ : T F ⇒ F T one obtains a λ-coinduction principle [7] which provides unique solutions in the final λ-bialgebra Z, α, ζ to corecursive equations of the form φ : X → F T X. Ordinary coinduction is the special case where T is the identity monad.Formally, a solution to φ : X → F T X in a λ-bialgebra A, α, β is an arrow f : X → A such that commutes.More precisely, λ-coinduction is coinduction in the category of λ-bialgebras, and we have the following fact.
A "pointwise distributive law" λ for T -automata can be obtained (cf.[13,14]) by taking λ X = (β × st) • T π 1 , T π 2 where st : T • (−) A ⇒ (−) A • T is the strength natural transformation.This λ is called "pointwise", since the algebra structure induced on the carrier B A * of the final B × (−) A -coalgebra is the pointwise extension of β : T B → B. In the context-free and streams examples below, however, the desired algebraic structure on B A * uses the convolution product which is not the pointwise extension of the semiring product of B. So for these examples a different λ must be given.

Quotients of Distributive Laws
In Section 2 we saw how equations give rise to quotients of algebras, and we gave a construction of the resulting quotient monad.In this section, we investigate conditions under which distributive laws and equations give rise to quotients of distributive laws.
As before, let Σ be a functor generating the free monad T = T, η, µ , and let E = E, l, r be T -equations with the associated quotient monad T ′ = T ′ , η ′ , µ ′ .4.1.Distributive Laws over Plain Behaviour Functors.In this subsection, we assume that λ : T F ⇒ F T is a distributive law of a monad T over a plain behaviour functor F .We will provide a condition on λ and the equations E that ensures that we get a distributive law λ ′ : T ′ F ⇒ F T ′ for the quotient monad.To this end, it is convenient to use the notion of a morphism of distributive laws from [26,36].Definition 4.1.Let T, η, µ and K, θ, ν be monads, and let λ : T F ⇒ F T and κ : KF ⇒ F K be distributive laws.A natural transformation τ : T ⇒ K is a morphism of distributive laws from λ to κ (notation τ : λ ⇒ κ) if τ is a monad morphism and the following square commutes:

⊳
We note that there are generalisations of the above definition that allow natural transformations between behaviour functors, cf.[36].For our purposes, we do not need to change the behaviour type.Definition 4.2.We say that λ : T F ⇒ F T preserves (equations in) E if for all X in C: commutes.⊳ In Set, preservation of equations can be conveniently formulated in terms of relation lifting.The F -lifting of a relation R ⊆ Y × Y is defined as For any set X, we denote by ≡ X the congruence ker(q X ) on T X generated by the equations.If the lifting F preserves inverse images, then it preserves kernel relations. 1This means that F (≡ X ) = ker(F q X ), and hence equation (4.2) is satisfied if for every set X and every b ∈ EF X: λ 3) We now come to our main result.On the one hand, item (2) of Theorem 4.3 below gives us a distributive law for the quotient monad and the useful consequences that follow from it such as, e.g., the solution of recursive equations as discussed in Sections 3.2 and 5.
On the other hand, condition (1) in the form of (4.2) is amenable to explicit calculations as shown in Examples 4.7, 4.9, and 4.11.
(2) There is a (unique) distributive law λ ′ : T ′ F ⇒ F T ′ such that q : T ⇒ T ′ is a morphism of distributive laws from λ to λ ′ .
Proof.We first show that (4.2) extends to the following: To obtain (4.4) it suffices to show that F q X • λ X is a T -algebra homomorphism, since then respectively.Since these latter two are equal due to (4.2), and homomorphic extensions are unique, we then get (4.4).
We now show that F q X • λ X is a T -algebra homomorphism.Let F λ be the lifting of F to the category of T -algebras, and recall that λ X is a T -algebra homomorphism from T F X, µ F X to F λ T X, µ X (cf.Section 3.1).Since also T X, µ X q X − − → T ′ X, µ ′ X •q T ′ X is a T -algebra homomorphism, by applying the lifting F λ we obtain a T -algebra homomorphism This proves that (4.4) commutes.Now, by the universal property of the coequalizer q F X there is a (unique) algebra homomorphism λ ′ X : The naturality of λ ′ follows from (4.5), and the naturality of λ and q.Due to the commutativity of the square in (4.5), q is a morphism of distributive laws from λ to λ ′ once we show that λ ′ is, in fact, a distributive law.The unit law for λ ′ holds due to the unit law for λ and (4.5): Multiplication law for λ ′ : The small upper-left square commutes by naturality of q.The small lower-left square commutes by applying T ′ to (4.5).The outer crescents commute since q is a monad morphism, and the outermost part does due to (4.5).Finally, use that by naturality of q, T ′ q F X • q T F X = q T ′ F X • T q F X , which by Assumption 2.2 is an epi, and hence can be right-cancelled to yield commutativity of the lower rectangle as desired.
The implication from 2 to 1 follows from the fact that (4.5) implies (4.2).
Remark 4.4.Street [33] investigates the 2-category where monads are objects and distributive laws λ : SF ⇒ F T , called monad functors, are the 1-cells (λ, F ) : T → S. Given a monad T , the right Kan-extension Ran F F T of F T along F is again a monad.Morever, distributive laws SF ⇒ F T are in 1-1 correspondence to monad morphisms S ⇒ Ran F F T , cf. [33,Theorem 5].
In this setting, if the free monad T E over E exists, then the equations can be expressed more abstractly as a parallel pair of monad morphisms T E G G G G T , and the distributive law λ : T F ⇒ F T satisfies the equations iff its transpose T ⇒ Ran F F T does, that is, iff Since T ′ is a coequaliser of monads, this induces a monad morphism T ′ ⇒ Ran F F T ′ , which, after transposing, gives a distributive law λ ′ : T ′ F ⇒ F T ′ .We thank Neil Ghani for this conceptually elegant argument of the equivalence stated in Theorem 4.3.We note that the above elementary proof does not require the existence of the free monad over E, and moreover, it avoids introducing more abstract definitions.As a corollary we obtain the analogue of Theorem 4.3 for monads presented by operations and equations.
Corollary 4.6.Suppose K = K, θ, ν is presented by operations Σ and equations E with natural isomorphism i : T ′ ⇒ K, and suppose we have a distributive law λ : T F ⇒ F T of T over F .Then there exists a unique distributive law κ : KF ⇒ F K of K over F such that i • q : λ ⇒ κ is a morphism of distributive laws.
Proof.The distributive law κ : KF ⇒ KF is defined as κ = F i • λ • i −1 .The proof proceeds by checking that κ indeed satisfies the defining axioms of a distributive law, which is an easy but tedious exercise.Theorem 4.3 says that if λ preserves the equations E, then we can present λ ′ as "λ modulo equations".We illustrate this with an example.
Example 4.7 (Stream calculus).Behavioural differential equations are used extensively in [30,31] to define streams and stream operations.Here, the behaviour functor is F X = R×X whose final coalgebra R ω , ζ consists of streams over the real numbers together with the map ζ(σ) = σ(0), σ ′ which maps a stream σ to its initial value σ(0) and derivative σ ′ .Consider the following system of behavioural differential equations where [a], X, σ and τ denote streams over the real numbers. [a](0 The behavioural differential equations in (4.8) define the constant streams [a] = (a, 0, 0, . ..) for all a ∈ R, X = (0, 1, 0, 0, . ..), pointwise addition and convolution product of streams.Note that the convolution product is here defined differently than in [30,31].We explain this choice at the end of the example.
Since we are defining R many streams [a], one constant stream X and two binary operations (+ and ×), the signature functor is Σ(X) = R + 1 + (X × X) + (X × X), and (4.8) corresponds to a natural transformation ρ : ΣF ⇒ F T where T is the functor part of the free monad T over Σ (that is, T X is the set of all Σ-terms over variables in X).The components of ρ are given by: As described at the end of section 3.1, such a ρ is a simple SOS specification, and it uniquely induces a distributive law λ : T F ⇒ F T .This λ is essentially the inductive extension of ρ from terms of depth 1 to arbitrary terms.Let E be given by the following axioms where V = {v, u, w} and a, b ∈ R (see Example 2.1 for an explanation of how this corresponds to a functor with two natural transformations): E consists of the commutative semiring axioms together with axioms stating the inclusion of the underlying semiring of the reals.We would like to apply Theorem 4.3 to obtain a distributive law λ ′ for the quotient monad T ′ arising from T and E. We show that λ preserves E. Let a, x , b, y , c, z ∈ F X for some set X. First note that for It is straightforward to check preservation of the axioms that only concern addition, as well as of [1] We check that λ preserves the distribution axiom: Similarly, preservation of ×-associativity can be verified, and it uses the axiom [a We have thus shown that λ preserves E, and it follows, in particular, that R ω , +, ×, [0], [1] is a commutative semiring.This was shown directly in [31], but the proof uses bisimulation-up-to as well as the fundamental theorem of stream calculus, which cannot be added as an equation.In our approach we construct a distributive law, and obtain not only this result but also the soundness of the bisimulation-up-to technique [29], and the existence of unique solutions to corecursive equations φ : X → F T ′ X (see Section 3.2).
The derivative of the convolution product is usually (cf.[30,31]) specified as: which corresponds to a stream GSOS-rule Σ(Id × R × Id) ⇒ R × T (−), and thus to a distributive law over the cofree copointed functor.However, with this definition, we could not show that the commutativity of × is preserved although all other axioms remain preserved.Hence a given λ does not necessarily satisfy all equations that are valid on the final F -coalgebra. ⊳ In the above example the monad under consideration is defined by operations and equations.In Example 4.11 below we will see an example of a monad that has an independent definition, but where a presentation by operations and equations simplifies the construction of a distributive law considerably.
Remark 4.8.The concrete proof method for preservation of equations bears a close resemblance to bisimulation up to congruence [29], in that one must show that for every pair in the (image of the) equations, its derivatives are related by the least congruence ≡ X instead of just the equivalence relation induced by the equations.Example 4.9.As we discussed at the end of Example 4.7 (regarding the definition of the convolution product), it is not always possible to show that a given λ preserves all equations that hold in the final coalgebra.Now we give another concrete example of this fact.This example again concerns stream systems, i.e., coalgebras for the functor F X = R × X.We define the constant stream of zeros by three different constants n 1 , n 2 and n 3 by the following behavioural differential equations: The corresponding signature functor is thus ΣX = 1 + 1 + 1, and the above specification gives rise to a distributive law λ : T F ⇒ F T where T is (the functorial component of) the free monad over Σ.Now consider the equation n 1 = n 2 ; this clearly holds when interpreted in the final coalgebra.However, this equation is not preserved by λ.To see this, notice that λ(n 1 ) = 0, n 1 and λ(n 2 ) = 0, n 3 , but n 1 ≡ X n 3 , so λ(n 1 ) and λ(n 2 ) are not related by F (≡ X ).⊳ 4.2.Distributive Laws over Copointed Functors.We now show that our main results hold as well for distributive laws of monads over copointed functors.This extends our method to deal with operations specified in the abstract GSOS format, such as language concatenation.
Proposition 4.10.Theorem 4.3 and Corollary 4.6 hold as well for any distributive law of a monad over a copointed functor.
Proof.Let H, ǫ be a copointed functor and λ : T H ⇒ HT a distributive law of T over H, ǫ .Suppose λ preserves equations E. By Theorem 4.3 then there is a distributive law λ ′ of T ′ over H such that q : T ⇒ T ′ is a morphism of distributive laws.In order to show that λ ′ is a distributive law of T ′ over H, ǫ we only need to prove that λ ′ satisfies the additional axiom, i.e., that the right crescent in the following diagram commutes: The outermost part commutes by naturality of q, the two squares commute by naturality of λ and ǫ, and the left crescent commutes by the fact that λ is a distributive law of T over H, ǫ .Consequently we have ǫ T ′ X • λ ′ X • q HX = T ′ ǫ X • q HX , and since q HX is an epi we obtain ǫ T ′ X • λ ′ X = T ′ ǫ X as desired.For Corollary 4.6 one needs to add to its proof a check that the distributive law satisfies the additional axiom as well, which is again rather easy to do.Example 4.11 (Context-free languages).A context free grammar (in Greibach normal form) consists of a finite set A of terminal symbols, a (finite) set X of non-terminal symbols, and a map o, t : X → 2 × P ω (X * ) A , i.e., it is a coalgebra for the behavior functor F (X) = 2 × X A composed with the idempotent semiring monad P ω ((−) * ) from Example 2.11.Intuitively, o(x) = 1 means that the variable x can generate the empty word, whereas w ∈ t(x)(a) if and only if x can generate aw, cf.[38].
It is a rather difficult task to describe concretely a distributive law of T ′ = P ω ((−) * ) over F (or Id×F ) defining the sum + and sequential composition • of context-free grammars.
More conveniently, since we have seen in Example 2.11 that the monad P ω ((−) * ) can be presented by the operations and axioms of idempotent semirings, we proceed by defining a distributive law λ of the free monad T Σ generated by the semiring signature functor Σ(X) = 1 + 1 + (X × X) + (X × X) over the cofree copointed functor Id × F, π 1 , and show that λ preserves the semiring axioms.We define λ as the distributive law that corresponds to the natural transformation ρ : Σ(Id × F ) ⇒ F T whose components are given by: We proceed to show that λ preserves the defining equations of idempotent semirings.We treat here only the case of distributivity, i.e., u To this end, let X be arbitrary and suppose x, o, d , y, p, e , z, q, f ∈ X × F X. Notice that either o = 0 or o = 1; we treat both cases separately: In a similar way one can show that λ preserves the other idempotent semiring equations.Thus, from Proposition 4.10 and Corollary 4.6 we obtain a distributive law κ of P ω ((−) * ) over Id × F such that i • q : λ ⇒ κ is a morphism of distributive laws, i.e., κ is presented by λ and the equations of idempotent semirings.⊳ 4.3.Distributive Laws over Comonads.A further type of distributive law, which generalizes all of the above, is that of a distributive law of a monad over a comonad.These arise from GSOS laws as well as from coGSOS laws, which allow to model operational rules which involve look-ahead in the premises.We refer to [19] for technical details and an example of a coGSOS format on streams.In this subsection, we prove for future reference that when constructing the quotient distributive law as above for a distributive law over a comonad, the axioms are preserved, i.e., the quotient is again a distributive law over the comonad.
Proposition 4.12.Theorem 4.3 and Corollary 4.6 hold as well for any distributive law of a monad over a comonad.
Proof.Let D, ǫ, δ be a comonad and λ : T D ⇒ DT a distributive law of the monad T, η, µ over the comonad D, ǫ, δ .Suppose λ preserves equations E. By Proposition 4.10 there is a distributive law λ ′ of T ′ over the copointed functor D, ǫ .To show that λ ′ is a distributive law over the comonad D, ǫ, δ , we need to check that the corresponding axiom holds.
The outermost part and the right square both commute by the fact that q is a morphism of distributive laws.The outer crescents commute since q and δ are natural.The small rectangles commute since q is a morphism from λ to λ ′ .The upper rectangle commutes by the assumption that λ is a distributive law over the comonad.Checking that the lower rectangle commutes, which is what we need to prove, is now an easy diagram chase, using that q D is epic.

Morphisms and Solutions
In this section, we show that morphisms of distributive laws commute with solving corecursive equations.In the case of monads with equations, this means that first solving equations φ with respect to T and then forming the quotient of the solution bialgebra is the same as first forming the quotient of T and solving with respect to the quotient monad T ′ .We first describe some functors that link the relevant categories of bialgebras and corecursive equations.Throughout this Section, we let T = T, η, µ and K = K, θ, ν be monads; and λ : T F ⇒ F T and κ : KF ⇒ F K be distributive laws of T and K over F , respectively.
If τ : λ ⇒ κ is a morphism of distributive laws, then precomposing with τ yields a functor: It follows from the naturality of τ and F τ • λ = κ • τ F that I takes a κ-bialgebra to a λ-bialgebra.Similarly, postcomposing with F τ yields a functor between corecursive equations: Recall from Section 3.2, that given a distributive law λ : T F ⇒ F T , the solutions of a corecursive equation φ : X → F T X are characterised by morphisms from the λ-bialgebra T X, µ X , φ λ whose F -coalgebra structure given by It follows that the unique λ-bialgebra morphism g : T X, µ X , φ λ → Z, α, ζ into the final λ-bialgebra Z, α, ζ factors as g = g ′ • τ X , where g ′ is the final λ-bialgebra morphism from IG κ Q(φ), as shown here: Hence by Proposition 3.1, every solution of φ in the final λ-bialgebra yields a solution of Qφ, and vice versa.When τ : λ ⇒ κ arises from a set of preserved equations E as in Section 4 (with κ = λ ′ ), then Proposition 5.1 says that IG κ Q(φ) is a quotient of the "free" λ-bialgebra T X, µ X , φ λ , and in particular, the congruence ≡ X is an F -behavioural equivalence.In this case, Qφ is the corecursive equation obtained by reading the right-hand side of φ modulo equations in E. In other words, forming the quotient of the solution of the equation φ is the same as solving the quotiented equation Qφ.
Example 5.2.Recall from Example 4.11 that i•q : T ⇒ P ω (X * ) is a morphism of distributive laws.By Proposition 5.1 we have the following commuting diagram for any corecursive equation φ : (5.9) Notice that a context-free grammar o, t : X → 2 × P ω (X * ) A can be represented by a φ : X → 2 × (T X) A such that Qφ = o, t , since i • q is surjective.This gives the expected correspondence between two of the three different coalgebraic approaches to context-free languages introduced in [38] (the third approach is about fixed-point expressions and as such is outside the scope of this paper).⊳ Similarly, the algebraic structure induced by λ on the final F -coalgebra factors uniquely through the algebraic structure induced by κ.
The upper left square commutes by naturality of τ , whereas the lower left square commutes since τ is a morphism of distributive laws.The two rectangles commute by definition of α and α ′ (see Section 3).Thus α ′ • τ Z and α are both coalgebra homomorphisms from T Z, λ Z • T ζ to Z, ζ and consequently α ′ • τ Z = α by finality.
Example 5.4.Continuing Example 5.2, it follows from Proposition 5.3 that the algebra α : T P(A * ) → P(A * ) induced by the distributive law for T can be decomposed as i • q • α ′ , where α ′ is the algebra on P(A * ) induced by the distributive law for P ω (Id * ).It can be shown by induction that α is the algebra on languages given by union and concatenation product.Now α ′ : P ω (P(A * ) * ) → P(A * ) can be given by selecting a representative term and applying α, and it follows that α

Discussion and Conclusion
We have presented a preservation condition that is necessary and sufficient for the existence of a distributive law λ ′ for a monad with equations given a distributive law λ for the underlying free monad.This condition consists of checking that the base equations are preserved by λ.Example 4.11 shows that presenting a monad by operations and equations and then checking that λ preserves the equations can be much easier than describing and verifying the distributive law requirements directly.We demonstrated our method by applying it to obtain distributive laws for stream calculus over commutative semirings, and for context-free grammars which use the monad of idempotent semirings.
In [36] the notion of morphisms of distributive laws is studied as a general approach to translations between operational semantics.In this paper we investigate in detail the case of quotients of distributive laws.Distributive laws for monad quotients and equations are also studied in [21,23].The setting and motivation of [23] is different as they study distributive laws of one monad over another with the aim to compose these monads.We study distributive laws of a monad over a plain functor, a copointed functor or a comonad.The approach in [21] differs from ours in that the desired distributive law is contingent on two given distributive laws and the existence of the coequaliser (in the category of monads) which encodes equations.We have given a more direct analysis for monads in Set and a practical proof principle, which covers many known examples.We leave as future work to find out precisely how their Theorem 31 relates to our Theorem 4.3.In [1] effects with equations are added to the syntax generated by a free monad T , using as semantic domain a suitable final B-coalgebra in the Kleisli category of T (assumed to be enriched over ωcomplete pointed partial-orders).To prove adequacy of the semantics with respect to a given operational model, the authors use a result similar to our Theorem 4.3.Their result, however, is limited to coalgebras for the functor BX = V + X.Moreover, since we work in Eilenberg-Moore categories of algebras rather than Kleisli categories of free algebras, we do not need to require the monad (and the quotient map) to be strong.
While in this work we have focused on adding equations which already hold in the final bialgebra, it is often useful to use equations to induce behaviour, next to a behavioural specification in terms of a distributive law.In process theory this idea is captured by the notion of structural congruences [25].At the more general level of distributive laws there is work on adding recursive equations [18].A study of structural congruences for distributive laws on free monads was given recently in [28].While that work focuses only on free monads, we believe that it can possibly be combined with the present work to give a more general account of equations and structural congruences for different monads.
In the case of GSOS on labelled transition systems, proving equations to hold at the level of a specification was considered in [2], based on rule-matching bisimulations, a refinement of De Simone's notion of FH-bisimulation.Rule-matching bisimulations are based on the syntactic notion of ruloids, while our technique is based on preservation of equations at the level of distributive laws.It is currently not clear what the precise relation between these two approaches is; one difference is that preserving equations naturally incorporates reasoning up to congruence.
More technically, it remains an open problem whether a converse of Proposition 5.1 holds.We intend to investigate this matter in future work.
) Precomposing the functor Alg(U F ) → Alg(T ) induced by this monad morphism with the comparison functor A → Alg(U F ) yields the inclusion A → Alg(T ).

Remark 4 . 5 .
Using that distributive laws correspond to functor liftings on T -algebras (cf.(3.1)), the distributive law λ ′ in Theorem 4.3 exists if and only if the functor F λ restricts to T ′ -algebras.A similar statement for the case when F is a monad is made in[23, Corollary 3.4.2].