BASES AS COALGEBRAS

. The free algebra adjunction, between the category of algebras of a monad and the underlying category, induces a comonad on the category of algebras. The coalgebras of this comonad are the topic of study in this paper (following earlier work). It is illustrated how such coalgebras-on-algebras can be understood as bases, decomposing each element x into primitives elements from which x can be reconstructed via the operations of the algebra. This holds in particular for the free vector space monad, but also for other monads, like powerset or distribution. For instance, continuous dcpos or stably continuous frames, where each element is the join of the elements way below it, can be described as such coalgebras. Further, it is shown how these coalgebras-on-algebras give rise to a comonoid structure for copy and delete, and thus to diagonalisation of endomaps like in linear algebra.


Introduction
The concept of basis in mathematics is best known for a vector space.It involves a way of writing an arbitrary vector v as finite linear combination v = i v i e i , using special base vectors e i , which are mutually independent.In the current paper this phenomenon will be studied at a more general level, using algebras and coalgebras.A vector space is an algebra -to be precise, an Eilenberg-Moore algebra of a particular monad -and the decompositions can be described as a coalgebra v → i v i e i .The fact that bases are coalgebras is the main, novel observation.It applies to other structures than vector spaces, like directed complete partial orders and convex sets.
In general, algebras are used for composition and coalgebras for decomposition.An algebra a : T (X) → X, for a functor or a monad T , can be used to produce elements in X from ingredients structured by T .Conversely, a coalgebra c : X → T (X) allows one to decompose an element in X into its ingredients with structure according to T .This is the fundamental difference between algebraic and coalgebraic data structures.

B. JACOBS
Assume an arbitrary category A, carrying a monad T , as in the lower left corner of the next diagram. CoAlg(−) The category Alg(T ) of algebras of the monad T comes with a standard adjunction Alg(T ) ⇄ A. This adjunction induces a comonad T on Alg(T ), see Section 2 for details.Then we can form the category CoAlg(T ) of coalgebras of the comonad T , with standard adjunction CoAlg(T ) ⇆ Alg(T ), inducing a monad T on CoAlg(T ).This process can be continued, and gives rise to an alternating sequence of monads and comonads.
This situation (1.1) has been studied by various authors, see e.g.[4,30,14,23].One obvious question is: does the sequence (1.1) stabilise?Stabilisation after 2 steps is proven in [4] for monads on Sets.Here we prove stabilisation in 3 steps for special monads (of so-called Kock-Zöberlein type) on PoSets, see below.
But more importantly, here it is proposed that a T -coalgebra on a T -algebra can be seen as a basis for this algebra, see Section 2. In particular, in Section 3 it will be shown that the concept of basis in linear algebra gives rise to such a coalgebra X → M(X) for the multiset monad M; this coalgebra decomposes an element x of a vector space X into a formal sum i x i e i ∈ M(X) given by its coefficients x i for a Hamel basis (e i ), see Theorem 3.2 for more details.In the same vein, the operation that sends an element of a convex set to a formal convex sum of extreme elements is an instance of such a coalgebra.
Other examples arise in an order-theoretic setting, see Section 4.Here one uses the notion of monad of Kock-Zöberlein type -where T (η X ) ≤ η T X , see [23,10].We describe how such monads fit in the present setting (with continuous dcpos as coalgebras), and add a new result (Theorem 4.5) about algebras-on-coalgebras-on-algebras, see Section 4. This builds on rather old (little noticed) work of the author [14].
The first two steps of the sequence (1.1) are also relevant in the semantics of effectful programming based on monads.In [24] it is shown that the exception monad transformer is a monad itself-so it can play the role of T in (1.1)-and that its algebras provide a syntax for raising exceptions, whereas the associated coalgebra/basis takes care of exception handling.These results are intriguing and need to be tested and investigated further, but that is beyond the scope of this paper.We mention them only briefly in Section 5.
In recent work [8] in the categorical foundations of quantum mechanics it is shown that orthonormal bases in finite-dimensional Hilbert spaces are equivalent to comonoids structures (in fact, Frobenius algebras).These comonoids are used for copying and deleting elements.In Section 6 it is shown how bases as coalgebras (capturing bases-as-decomposition) also give rise to such comonoids (capturing bases-as-copier-and-deleter).These comonoids can be used to formulate in general terms what it means for an endomap to be diagonalised.This is illustrated for a.o. the Pauli functions.

Comonads on categories of algebras
In this preliminary section we investigate the situation of a monad and the induced comonad on its category of algebras.We shall see that coalgebras of this comonad capture the notion of basis, in a very general sense.This will be illustrated later in several situations see in particular Subsection 3.2.
For an arbitrary monad T : A → A, with unit η : id ⇒ T and multiplication µ : T 2 ⇒ T , there is a category Alg(T ) of (Eilenberg-Moore) algebras, together with a left adjoint F (for free algebra functor) to the forgetful functor U : Alg(T ) → A. This adjunction Alg(T ) ⇆ A induces a comonad on the category Alg(T ), which we shall write as T = F U in: For an algebra (T X a → X) ∈ Alg(T ) there are counit ε : T ⇒ id and comultiplication δ : T ⇒ T maps in Alg(T ) given by: Definition 2.1.Consider a monad T : A → A together with the comonad T : Alg(T ) → Alg(T ) induced by T , as in (2.1).A basis for a T -algebra (T X a → X) ∈ Alg(T ) is a Tcoalgebra on this algebra, given by a map of algebras b of the form: y y As we shall see a basis as described above may be understood as providing a decomposition of each element x of an algebra into a collection b(x) of basic elements that together form x.
The actual basic elements X b X involved can be obtained as the indecomposable ones, via the following equaliser in the underlying category.
One can then ask in which cases the map of algebras T (X b ) → X, induced by the equaliser e : X b → U (T X → X), is an isomorphism.This is (almost always) the case for monads namely given by T (η X ).This gives a situation: Proof It is easy to check that T (η X ) is a morphism in Alg(T ) and a T -coalgebra: The object X b of basic elements, as in (2.3), in the situation of this lemma is the original set X in case the monad T satisfies the so-called equaliser requirement [27], which says precisely that η X : X → T X is the equaliser of T (η X ), η T X : T X ⇒ T 2 X.This requirement does not hold, for instance, for the powerset monad.
There is some redundancy in the data described in Definition 2.1.This is implicitly used in the description of syntax for exception in [31] (with only 'handle' as coalgebra and no 'raise' algebra, see also [24] and Section 5).
Lemma 2.3.Assume a monad T : A → A, with induced comonad T : Alg(T ) → Alg(T ).Having: is the same as having: • a map c : X → T (X) in A which forms an equaliser diagram in A: Proof Assuming an algebra and coalgebra (a, b) as above, it is easy to check that b : X → T (X) is the equaliser of T (b) and T (η).
The other direction is a bit more work: assume we have c : X → T (X) forming an equaliser of T (c) and T (η).Consider the map a defined in the diagram: Using the equaliser property one checks that a is a T -algebra, and that c : X → T (X) satisfies the T -coalgebra requirements from Definition 2.1.
The comonad T : Alg(T ) → Alg(T ) from (2.1) gives rise to a category of coalgebras CoAlg(T ) → Alg(T ), where this forgetful functor has a right adjoint, which maps an algebra T Y → Y to the diagonal coalgebra δ : µ Y → µ T Y as in (2.2).Thus we obtain a monad on the category CoAlg(T ), written as T , like in the sequence (1.1).On a basis c : a → T (a), for an algebra a : T X → X, there is a unit η c = c : c → δ and multiplication µ c = T (c) : δ → δ in CoAlg(T ).
By iterating this construction as in (1.1) one obtains alternating monads and comonads.Such iterations are studied for instance in [4,30,14,23].In special cases it is known that the iterations stop after a number of cycles.This happens after 2 iterations for monads on sets, as we shall see next, and after 3 iterations for Kock-Zöberlein monads in Section 4. This stabilisation means that in presence of sufficiently many iterated (co)algebraic operations, the algebraic structure that we start from becomes free -typically on some atoms or basic elements.

Set-theoretic examples
It turns out that for monads on the category Sets only free algebras have bases.This result goes back to [4].We repeat it in the present context, with a sketch of proof.Subsequently we describe the situation for the powerset monad (from [14]), the free vector space monad, and the distribution monad.Proposition 3.1.For a monad T on Sets, if an algebra T X a → X has a basis X b → T X with non-empty equaliser X b X ⇒ T X as in (2.3), then the induced map T (X b ) → X is an isomorphism of algebras and coalgebras.In particular, in the set-theoretic case any algebra with a non-empty basis is free.Proof Let's consider the equaliser X b X of b, η : X ⇒ T (X) from (2.3) in Sets.It is a so-called coreflexive equaliser, because there is a map T X → X, namely the algebra a, satisfying a • b = id = a • η.It is well-known-see e.g.[26,Lemma 6.5] or the dual result in [5, Volume I, Example 2.10.3.a]-that if X b = ∅ such coreflexive equalisers in Sets are split, and thus absolute.The latter means that they are preserved under any functor application.In particular, by applying T we obtain a new equaliser in Sets, of the form: The resulting map b ′ is the inverse to the adjoint transpose a • T (e) : T (X b ) → X, since: • the other equation follows because T (e) is equaliser, and thus mono: = T (e) • id.

B. JACOBS
Hence the homomorphism of algebras a • T (e), from F (X b ) = µ X b to a is an isomorphism.In particular, b ′ : X → T (X b ) in (3.1) is a map of algebras, as inverse of an isomorphism of algebras.It is not hard to see that it is also an isomorphism between the coalgebras b : X → T (X) and T (η) : 3.1.Complete lattices.Consider the powerset monad P on Sets, with the category CL = Alg(P) of complete lattices and join-preserving maps as its category of algebras.
The induced comonad P : CL → CL as in (2.1) sends a complete lattice (L, ≤) to the lattice (P(L), ⊆) of subsets, ignoring the original order ≤.The counit ε : P(L) → L sends a subset U ∈ P(L) to its join ε(U ) = U ; the comultiplication δ : P(L) → P 2 (L) sends Thus, such a coalgebra of the comonad P, if it exists, is uniquely determined and gives a decomposition of lattice elements into the atoms below it.The atoms in the lattice thus form a basis.
(Recall: the complete lattice L is atomic when each element is the join of the atoms below it.And an atom a ∈ L is a non-zero element with no non-zero elements below it, satisfying: a ≤ U implies a ≤ x for some x ∈ U .) The equaliser (2.3) for the basic elements in this situation, for an atomic complete lattice L, is the set of atoms:

Vector spaces.
For a semiring S one can define the multiset monad M S on Sets by M S (X) = {ϕ : X → S | supp(ϕ) is finite}.Such an element ϕ can be identified with a formal finite sum i s i x i with multiplicities s i ∈ S for elements x i ∈ X.The unit of this monad η : X → M S (X) is given by singleton multisets: , where • is the multiplication of the semiring S.
The category of algebras Alg(M S ) of the multiset monad M S is the category of Mod S of modules over S: commutative monoids with S-scalar multiplication, see e.g.[9] for more information.The induced comonad M S : Mod S → Mod S from (2.1) sends such a module X = (X, +, 0, •) to the free module M S (X) of finite multisets (formal sums) on the underlying set X, ignoring the existing module structure on X.The counit and comultiplication are given by: The formal sum (multiset) in the middle is mapped by the counit ε to an actual sum in X, namely to its interpretation.The comultiplication δ maps this formal sum to a multiset of multisets, with the inner multisets given by singletons 1x j = η(x j ).
The following is a novel observation, motivating the view of coalgebras on algebras as bases.
Theorem 3.2.Let X be a vector space, say over S = R or S = C. Coalgebras X → M S (X) correspond to (Hamel) bases on X.
Proof Suppose we have a basis B ⊆ X for the vector space X.Then we can define a coalgebra b : X → M S (X) via (finite) formal sums b(x) = j s j a j , where Conversely, given a coalgebra b : be expressed as sum of such basic elements.
A basis for complete lattices in Subsection 3.1, if it exists, is uniquely determined.In the context of vector spaces bases are unique up to isomorphism.
Our next example involves convex sets, where extreme points play the role of base vectors.Via the language of coalgebras we can make the similarity with vector spaces explicit.
Algebras of the distribution monad can be identified with "convex sets" (see e.g.[16]), where convex sums exist: the mapping D(X) → X sends a formal convex combination to an actual convex sum.A typical example is the unit interval [0, 1].Notice that it does not have arbitrary sums; but convex sums exist in [0, 1].An algebra homomorphism preserves such convex sums.Such a map is usually called 'affine'.We write Conv for this category Alg(D) of convex sets and affine maps.
A point x ∈ X in a convex set X is called extreme if it does not occur as non-trivial convex combination: if x = i r i x i , then r j = 1 and x j = x, for some j, and thus r i = 0 for i = j.One usually writes ∂X ⊆ X for the subset of extreme points.In a free convex set D(Y ), for a set Y , the extreme points are the singletons η(y) = 1y, for y ∈ Y .Thus ∂D(X) ∼ = X.Now assume we have a coalgebra b : X → D(X) for the induced comonad D : Conv → Conv.We form the subset X b = {x ∈ X | b(x) = 1x} as in (2.3), and claim X b = ∂X, that is, these basic elements in X b are precisely the extreme points.
It is easy to see that there is an inclusion ∂X ⊆ X b : if x is extreme, and b(x) is a formal sum i r i x i , then x equals the actual sum i r i x i ∈ X.But then r j = 1 and x = x j , for some j -and r i = 0 for i = j.Hence b(x) = 1x j = 1x.

B. JACOBS
For the reverse inclusion X b ⊆ ∂X, assume x ∈ X satisfies b(x) = 1x, and x = i r i x i , where r i = 0 and i r i = 1.Since b is an algebra homomorphism, it preserves convex sums: and so x i = x for each i.Hence x = i r i x i is a singleton sum, making x extreme.
We thus see that a D-coalgebra b : X → D(X) determines a coalgebra b ′ : X → D(∂X), as in (3.1), that describes each element as convex sum of extreme points.As we have seen, this map b ′ is an isomorphism X ∼ = −→ D(∂X) describing each convex set with a basis as a free convex set on its extreme points.This is the essence of the equivalence of categories CoAlg(D) ≃ Sets.
The situation is reminiscent of the Krein-Milman theorem, which states that a convex and compact subset S of a locally convex space is equal to the closed convex hull of its extreme points: S = D(∂S), where (−) is the closure operation.What we have here is a non-topological version of such a result.

Order-theoretic examples
Assume A is a poset-enriched category.This means that all homsets A(X, Y ) are posets, and that pre-and post-composition are monotone.In this context maps f : X → Y and g : Y → X in opposite direction form an adjunction f ⊣ g (or Galois connection) if there are inequalities id X ≤ g • f and f • g ≤ id Y , corresponding to unit and counit of the adjunction.In such a situation the adjoints f, g determine each other.
A monad T = (T, η, µ) on such a poset-enriched category A is said to be of Kock-Zöberlein type or just a Kock-Zöberlein monad if T : A(X, Y ) → A(T X, T Y ) is monotone and T (η X ) ≤ η T X holds in the homset A T (X), T 2 (X) .This notion is introduced in [23] in proper 2-categorical form.Here we shall use the special 'poset' instance-like in [10] where the dual form occurs.The following result goes back to [23]; for convenience we include the proof.Theorem 4.1.Let T be a Kock-Zöberlein monad on a poset-enriched category A. For a map a : T (X) → X in A the following statements are equivalent.
(1) a : T (X) → X is an (Eilenberg-Moore) algebra of the monad T ; (2) a : T (X) → X is a left-adjoint-left-inverse of the unit η : X → T (X); this means that a ⊣ η X is a reflection.
Proof First assume a : T (X) → X is an algebra, i.e. satisfies a • η = id and a • µ = a • T (a).It suffices to prove id ≤ η • a, corresponding to the unit of the reflection, since the equation a • η = id is the counit (isomorphism).This is easy, by naturality: In the other direction, assume a : T (X) → X is left-adjoint-left-inverse of the unit η : X → T (X), so that a • η = id and id ≤ η • a.We have to prove a • µ = a • T (a).In one direction, we have: since µ ≤ µ • T (η • a) = T (a), and thus a • µ ≤ a • T (a).For the reverse inequality we use: In a next step we consider the induced comonad T on the category Alg(T ) of algebra of a Kock-Zöberlein monad T , as in (1.1).A first, trivial but important, observation is that the category Alg(T ) is also poset enriched.It is not hard to see that the comonad T is also of Kock-Zöberlein type, in the sense that for each algebra (T X a → X) we have: by (4.1).Thus one may expect a result similar to Theorem 4.1 for coalgebras of this comonad T .It is formulated in [23,Thm. 4.2] (and attributed to the present author).We repeat the poset version in the current context.Theorem 4.2.Let T be a Kock-Zöberlein monad on a poset-enriched category A, with induced comonad T on the category of algebras Alg(T ).Assume an algebra a : T (X) → X.For a map c : X → T (X), forming a map of algebras in, the following statements are equivalent.
(1) c : a → T (a) is an (Eilenberg-Moore) coalgebra of the comonad T ; (2) c : a → T (a) is a left-adjoint-right-inverse of the counit a : T (a) → a; this means that c ⊣ a is a coreflection.
We have to prove c • a ≤ id, which is obtained in: Conversely, assume a coreflection c ⊣ a, so that a • c = id and c • a ≤ id.We have to prove , and thus In the other direction, we use: One can iterate the (−) construction, as in (1.1).Below we show that for Kock-Zöberlein monads the iteration stops after 3 steps.First we need another characterisation.The proof is as before.The next result shows how such series of adjunctions can arise.Lemma 4.4.Assume an algebra a : T (X) → X of a Kock-Zöberlein monad.The free algebra T (X) then carries multiple (co)reflections (algebras and coalgebras) in a situation: This lemma describes the only form that such structures can have.This is the main (new) result of this section.Proof Assume b ⊣ c ⊣ a ⊣ η X on X, and consider the equaliser (2.3) in: We use the letter 'k' because the elements in X c will turn out to be compact elements, in the examples later on.The first thing we note is: Next we observe that the object X c carries a T -algebra structure a c inherited from a : T (X) → X, as in: It is an algebra indeed, since: The other algebra equation is left to the reader.Next we show that the transpose a • T (e) : T (X c ) → X of the equaliser e : X c X is an isomorphism of algebras µ Xc ∼ = a.The inverse is We continue to check that the assumed chain of adjunctions b ⊣ c ⊣ a ⊣ η X is related to the chain T (a c ) ⊣ T (η) ⊣ µ ⊣ η in (4.3) via these isomorphisms.In particular we still need to check that the following two square commute.
These square commute We still have to check that the functor T : Alg(T ) → Alg(T ) is an equivalence.In the reverse direction, given a coalgebra c : T (b) → b on X, we take the induced algebra T (X c ) → X c on the equaliser (4.4).Then T (X c ) → X is an isomorphism of T -algebras, as we have seen.For the isomorphism in the other direction, assume we start from an algebra a : T (X) → X, obtain the T -algebra T (a) described in the chain T (a) ⊣ T (η) ⊣ µ ⊣ η in (4.3), and then form the equaliser (4.4); it now looks as follows.
This is the equaliser requirement [27], which holds since X carries an algebra structure.Clearly, η • η = T (η) • η by naturality.And if a map f : In the remainder of this section we review some examples.4.1.Dcpos over Posets.The main example from [14] involves the ideal monad Idl on the category PoSets of partially ordered sets with monotone functions between them.In the light of Theorems 4.1 and 4.2 we briefly review the essentials.
For a poset X = (X, ≤) let Idl(X) be the set of directed downsets in X, ordered by inclusion.This Idl is in fact a monad on PoSets with unit X → Idl(X) given by principal downset x → ↓x and multiplication Idl 2 (X) → Idl(X) by union.This monad is of Kock-Zöberlein type since for U ∈ Idl(X) we have: Applying Theorem 4.1 to the ideal monad yields the (folklore) equivalence of the following points.
(1) X is a directed complete partial order (dcpo): each directed subset U ⊆ X has a join U in X; (2) The unit ↓ : X → Idl(X) has a left adjoint-which is the join; (3) X carries a (necessarily unique) algebra structure Idl(X) → X, which is also the join.Additionally, algebra maps are precisely the continuous functions.Thus we may use as category Dcpo = Alg(Idl).
The monad Idl on PoSets induces a comonad on Dcpo, written Idl, with counit ε = : Idl(X) → X and comultiplication δ = Idl(↓) : Idl(X) → Idl 2 (X), so that δ(U ) = ↓{↓x | x ∈ U }.In order to characterise coalgebras of this comonad Idl we need the following.In a dcpo X, the way below relation ≪ is defined as: for x, y ∈ X, A continuous poset is then a dcpo in which for each element x ∈ X the set ↓ ↓ x = {y ∈ X | y ≪ x} is directed and has x as join.These elements way-below x may be seen as a (local) basis.
For a dcpo X, the following statements are equivalent.(1) X is a continuous poset; (2) The counit : Idl(X) → X of the comonad Idl on Dcpo has a left adjoint (in Dcpo); it is x → ↓ ↓ x. (3) X carries a (necessarily unique) Idl-coalgebra structure X → Idl(X), which is also ↓ ↓ (−).Theorem 4.5 says that another iteration Idl yields nothing new.

4.2.
Frames over semi-lattices.For a poset X, the set of its downsets: is a frame (or complete Heyting algebra, or locale), see [20].If the poset X has finite meets ⊤, ∧, then the downset map ↓ : X → Dwn(X) preserves meets: ↓⊤ = X and ↓(x ∧ y) = ↓x∩↓y.Hence it is a morphism in the category MSL of meet semi-lattices.It is not hard to see that Dwn is a monad on MSL that is of Kock-Zöberlein type.For a (meet) semi-lattice X = (X, ⊤, ∧) the following are equivalent.
(1) X is a frame: X has arbitrary joins and its finite meets distribute over these joins: x ∧ i y i = i (x ∧ y i ); (2) The unit ↓ : X → Dwn(X) has a left adjoint in MSL-which is the join; (3) X carries a (necessarily unique) algebra structure Dwn(X) → X in MSL, which is also the join.Moreover, the algebra maps are precisely the frame maps, preserving arbitrary joins and finite meets; thus Frm = Alg(Dwn).
In a next step, for a frame X, the following statements are equivalent.(1) X is a stably continuous frame, i.e. a frame that is continuous as a dcpo, in which ⊤ ≪ ⊤, and also x ≪ y and x ≪ z implies x ≪ y ∧ z; (2) The counit Dwn(X) → X of the comonad Dwn on Frm has a left adjoint in Frm; it is x → ↓ ↓ x. (3) X carries a (necessarily unique) Dwn-coalgebra structure X → Dwn(X), which is also ↓ ↓ (−).
One can show that coalgebra homomorphisms are the proper frame homomorphisms (from [3]) that preserve ≪.We recall from [20,VII,4.5]that for a sober topological space X, its opens Ω(X) form a continuous lattice iff X is a locally compact space.Further, the stably continuous frames are precisely the retracts of frames of the form Dwn(X), for X a meet semi-lattice-here via the coreflection ↓ ↓ ⊣ .

Examples in effectful programming
Since [28] it is standard to describe the semantics of (sequential) programs in the Kleisli category of a (strong) monad T .The monad captures the computational effect involved, such as partial computation via the lift monad, non-deterministic computation via powerset P, probabilistic computation via distribution D, exceptions via E + (−), etc.The combination of such effects has also been studied, in terms of monad transformers, see e.g.[25,19].
Probably the most well-known monad transformer is T → T (E +−), which sends a monad T capturing some computational effect to the monad T (E+−) which additionally incorporates exceptions (via a fixed exception object E).It has been observed before that this monad transformer E, given by E(T ) = T (E + −), is a monad itself, on the category of monads.Hence we can proceed as in Section 2, study its category Alg(E) of E-algebras, with induced comonad E : Alg(E) → Alg(E), and with category of coalgebras CoAlg(E).This has been done in [24], resulting in an intruiguing description of the 'raise' and 'handle' operations associated with exceptions.Here we briefly recall these main points, simply because the approach fits very well in the setting of the current paper.We do not add any new material.The situation is analogous to previous examples if one sees the algebra as the relevant introduction rule and the coalgebra as the associated elimination rule (for a new language construct).
Assume a distributive category A, that is, a category with finite products (×, 1) and coproducts (+, 0) such that products distribute over coproducts, via (canonical) isomorphisms (X × Y ) + (X × Z) We write StMnd(A) for the category of strong monads on A, with monad maps commuting with strength as morphisms.Strength st : T (X)×Y → T (X ×Y ) is standardly assumed in the theory of monadic computation (see [28]), where it is used to handle computations in contexts.
Theorem 5.1.In the setting described above, (1) the mapping E(T ) = T (E + −) is a monad on the category StMnd(A) of strong monads on A, giving rise to a situation: (2) an E-algebra corresponds to a "throw" map E → T (0); (3) a E-coalgebra corresponds to a 'handle' (or 'catch') family of maps T (X) → T (X + E), satisfying the equations for exception handling, see [24].
The second point involves a bijective correspondence: This works as follows.
• Given σ, take: • And given r : E → T (0), define r : T (E + −) ⇒ T with components: The coalgebra T (X) → T (X + E) in the third point indeed does a catch, since after this coalgebra one can combine a cotuple of a normal computation f : X → T (Y ) with an exception handler g : We refer to [24] (and also [31]) for more information.

Comonoids from bases
A recent insight, see [8], is that orthonormal bases in finite-dimensional Hilbert spaces can be described via so-called Frobenius algebras.Orthonormal bases are very important in quantum theory because they provide a 'perspective' for a measurement on a system.The algebraic re-description of bases in terms of Frobenius algebras is influential because it gives rise to a diagrammatic calculus for quantum protocols, see e.g.[6].In the present section we show how the coalgebra-as-basis perspective gives rise to comonoidal structure for copy and delete -and thus to the essential part of a Frobenius algebra structure.
In general, such a Frobenius algebra consists of an object carrying both a monoid and a comonoid structure that interact appropriately.In the self-dual category of Hilbert spaces, it suffices to have either a monoid or a comonoid, since the dual is induced by the dagger / adjoint transpose (−) † .In this section we show that the kind of coalgebras (on algebras) considered in this paper also give rise to comonoids, assuming that the category of algebras has monoidal (tensor) structure.
In a (symmetric) monoidal category A a comonoid is the dual of a monoid, given by maps I u ← X d → X ⊗ X satisfying the duals of the monoid equations.Such comonoids are used for copying and deletion, in linear and quantum logic.If ⊗ is cartesian product ×, each object carries a unique comonoid structure 1 !← X ∆ → X × X.The no-cloning theorem in quantum mechanics (due to Dieks, Wootters and Zurek) says that copying arbitrary states is impossible.But copying wrt. a basis is allowed, see [29,8,1].
If a monad T on a symmetric monoidal category A is a commutative (aka.symmetric monoidal) monad, and the category Alg(T ) has enough coequalisers, then it is also symmetric monoidal, and the free functor F : A → Alg(T ) preserves this monoidal structure B. JACOBS (via the isomorphism used below).This classical result goes back to [22,21].We shall use it for the special case where the monoidal structure on the base category A is cartesian.Proposition 6.1.In the setting described above, assume the category of algebras Alg(T ) is symmetric monoidal, for a commutative monad T on a cartesian category A. Each Tcoalgebra / basis b : X → T (X), say on algebra a : T (X) → X, gives rise to a commutative comonoid in Alg(T ) by: where we use the underlying comonoid structure Proof It is not hard to see that these d b and u b are maps of algebras: The verification of the comonoid properties involves lengthy calculations, which are basically straightforward.We just show that u is neutral element for d, using the equations from Definition 2.1.
Example 6.2.To make the comonoid construction (6.1) more concrete, let V be a vector space, say over the complex numbers C, with a Hamel basis, described as a coalgebra b : V → M C (V ) like in Theorem 3.2, with basic elements (e j ), satisfying b(e j ) = 1e j .The counit u b = M C (!) • b : V → C from (6.1) first represents a vector wrt.this basis, and then adds the (finitely many) coefficients: Similarly, the comultiplication d b : V → V ⊗ V as in (6.1) is the composite: v −→ j v j e j −→ j v j (e j ⊗ e j ), like in [8].
(For Hilbert spaces one uses orthonormal bases instead of Hamel bases; the counit u of the comonoid then exists only in the finite-dimensional case.The comultiplication d seems more relevant, see also below, and may thus also be studied on its own, like in [2], without finiteness restriction.) Another example is the ideal monad Idl : PoSets → PoSets from Subsection 4.1.It preserves finite products, and as a result, the induced monoidal structure on the category of algebras Alg(Idl) = Dcpo is cartesian.Hence the comonoid structure (6.1) is given by actual diagonals and (unique) maps to the final object.For instance, when ⊗ = × on algebras: In general, given a comonoid I u ← X d → X ⊗ X, an endomap f : X → X may be called diagonalised-wrt.this comonoid, or actually, comultiplication d-if there is a "map of eigenvalues" v : X → I such that f equals the composite: In case the diagonal d is part of a comonoid, with a counit u : X → I, then this eigenvalue map v equals u • f .In the special case where the comonoid comes from a coalgebra (basis) b : X → T (X), like in (6.1), an endomap of algebras f : X → X, say on a : T (X) → X, is diagonalised if there is a map of algebras v : X → I = T (1) such that f is: where st is a strength map of the form T (X) × Y → T (X × Y ), which exists because the monad T is assumed to be commutative.
Example 6.3.Recall the multiset monad M S from Subsection 3.2, where S is a semiring.
In [18] it is used to defined a dagger category BifMRel S of "bifinite multirelations".Objects are sets X, and maps X → Y in BifMRel S are multirelations r : X × Y → S which factor both as X → M S (Y ) and as Y → M S (X).This means that for each x there are finitely many y with r(x, y) = 0, and similarly, for each y there are finitely many x with r(x, y) = 0. Composition of r : X → Y and s : Y → Z is done via matrix multiplication: (s • r)(x, z) = y s(y, z) • r(x, y).The identity id : X → X is the given by id(x, x) = 1 and id(x, x ′ ) = 0 if x = x ′ .
Here we don't need the dagger (−) † on BifMRel S , but for completeness we briefly mention how it arises, assuming that S carries an involution (−) : S → S, like conjugation on the complex numbers.For a map r : X → Y there is an associated map r † : Y → X in the reverse direction, obtained by swapping arguments and involution: r † (y, x) = r(x, y), like in a conjugate transpose.This makes BifMRel S a dagger category.The situation that we have is similar to what one finds in categorical models of linear logic, where the exponential !A, giving arbitrarily many copies of A, is interpreted via a comonad !carrying a comonoid structure !A ← !A⊗!A → I for weakening and contraction.In the current situation we have a basis as a coalgebra A → !A, so that we get a comonoid structure on A, instead of on !A.
The next result can be interpreted informally as: base vectors are copyable.
Proposition 6.5.Assume an algebra T (X) a → X with an 'element' I x → X in Alg(T ) that is in the basis of a coalgebra b : X → T (X), as in the equaliser diagram (2.3): This x is then copyable, in the sense that the following diagram commutes where d is the comultiplication associated with b as in (6.1).
Proof Since I = T (1) is a free algebra, the map of algebras x : I → X can be written as x = a • T (x ′ ), for the element x ′ = x • η : 1 → X in the underlying category.Then: Now we use that ξ is a monoidal isomorphism in: T (1) ⊗ T (1) in order to prove that x is copyable:

B. JACOBS
The converse of result is not true: for the ideal monad in Example 6.2 every element is copyable, but not every element is compact, i.e. in a basis, see Subsection 4.1.
Comonoids make tensors cartesian, see [11,7], so that they bring us into the classical world.This cartesian structure already exists for coalgebras, as the next result shows.Proposition 6.6.The comonoid structure (6.1) restricts to a comonoid in the category CoAlg(T ) of bases.Therefore, this category has finite products.Moreover, the restriction of the free functor F : A → Alg(T ) to F : A → CoAlg(T ), as in Lemma 2.2, preserves finite products.
Proof First one checks that the maps d, u in (6.1) are homomorphisms of coalgebras.Then one uses that the comonad T : Alg(T ) → Alg(T ) is monoidal, see [15,Prop. 5.7], so that the products of coalgebras can be defined as: where on the right-hand-side we use the map: in which ⊗ is the universal bi-homomorphism.

Conclusions
This paper elaborates the novel view that coalgebras-on-algebras are bases, in a very general sense.This applies to coalgebras of the comonad that is canonically induced on a category of algebras of a monad.Various set-theoretic and order-theoretic examples support this view.It remains to be investigated to what extent this view also applies in program semantics, beyond the example of the exception monad transformer.Also, the connection between bases and copying, that is so important in quantum mechanics, exists in the current abstract setting.

Lemma 4 . 3 .
Let be a Kock-Zöberlein monad on a poset-enriched category A, giving rise to comonad T on Alg(T ) and monad T on CoAlg(T ).Assume:• an algebra a : T (X) → X in Alg(T ); • a coalgebra c : X → T (X) on a in CoAlg(T ); • an algebra b : T (X) → X on c in Alg(T ), where: − b • c = id and b • T (b) = b • T (a), since b is a T -algebra; − a • T (b) = b • µ, since b is a map of algebras a → T (a) = µ; − c • b = T (b) • T (η),since b is a map of algebras δ = c → c.The following statements are then equivalent.(1) b : T (c) → c is an algebra of the monad T ; (2) b : T (c) → c is a left-adjoint-left-inverse of the unit c : c → T (c).

Theorem 4 . 5 .
If we have a reflection-coreflection-reflection chainb ⊣ c ⊣ a ⊣ η X on an object X, like in Lemma 4.3, then X is a free algebra.Thus: for a Kock-Zöberlein monad T , the functor T : Alg(T ) → Alg(T ) is an equivalence of categories.

. 5 )
This follows since e is a mono, and:e • k • e = b • η • e by construction of k = b • c • e since e is equaliser= e since b is a T -algebra and c is unit.
since e is equaliser of c and η = T (k) • T (e) = id by (4.5).