Electronic Notes in Theoretical Computer Science 44 No. 3 (2003) URL: http://www.elsevier.nl/locate/entcs/volume44.html 19 pages

Some algebraic laws for spans (and their connections with multirelations)1

Roberto Bruni and Fabio Gadducci

Dipartimento di Informática, Université di Pisa {bruni,gadducci}@di.unipi.it

Abstract

This paper investigates some key algebraic properties of the categories of spans and cospans (up to isomorphic supports) over the category Set of (small) sets and functions, analyzing the monoidal structures induced over both spans and cospans by cartesian product and disjoint union of sets. Our results find analogous counterparts in (and are partly inspired by) the theory of relational algebras, thus our paper also sheds some light on the relationship between (co)spans and the categories of (multi)relations and of equivalence relations. And, since (co)spans yield an intuitive presentation of dynamical systems with input and output interfaces, our results introduce an expressive, two-fold algebra that can serve as a specification formalism for rewriting systems and for composing software modules.

Key words: spans, relations, monoidal categories, modular

specification

Introduction

The use of spans [1,6] (and of the dual notion of cospans) have been quite ubiquitous in recent years. They have been used as a syntactical device for system specification [4,18,19]; as a foundational tool for graphs and graph rewriting [14,15]; or as a semantical domain for the study of partial and multi-algebras [9,26], and of predicate transformers [17].

Their presentation is deceptively simple: given a category C with pullbacks, the associated category Span(C) has the same objects as C, and as a generic arrow from a to b a span, i.e., an object c G C (called the support) together with two arrows f: c ^ a and g: c ^ b in C (called legs) having c as common source. Intuitively, a span can be viewed as a sort of input/output system, where each system module c is equipped with two "views" [19], which can be

1 Research partly supported by the EC TMR Network getgrats and by the Italian MURST Project tosca.

©2003 Published by Elsevier Science B. V.

used to simulate system interaction, i.e., through which different modules may be interfaced.

Despite being straightforward, the span construction presents some subtleties. First of all, for a given category C, the resulting Span(C) would be better described as a (bi)category, since composition is not really associative (if not up-to isomorphism); and, moreover, an intuitive notion of morphism between spans is easily given, making the resulting structure a 2-category at least. Second, various restriction on the class of admissible spans may heavily restrict the class of derived arrows (e.g., requiring that at least one of the leg is a mono, see [26]) and the resulting structure may greatly vary, from the point of view of the algebraic properties.

The goal of this paper is rather modest: we consider the category Set of (small) sets and functions, and study some algebraic properties of Span (Set) (and of the dual CoSpan(Set)). More precisely, we investigate the key features of the monoidal structures induced on these categories by lifting the cartesian product and the disjoint union in Set, obtaining a preliminary taxonomy for these properties. The relevance of such a taxonomy lies in the uses of (co)spans as a general-purpose framework. In fact, from one side it offers an abstract view of programs with interfaces (respectively the support and the legs of the span) and therefore the algebraic laws of the category express the way of composing programs by connecting their interfaces; from the other side, having an algebra of spans yields an abstract data type that can be used in rewriting systems for modeling distributed system via interconnected modules that can change dynamically.

As a suitable example, we illustrate a quite straightforward application for our framework as a semantic domain for Petri nets [24], a well-known specification mechanism for representing program schemata and distributed systems, which are built out of connecting, e.g., software modules and architecture components (i.e., the transitions of the net). In our paper we tackle contextual nets [23], i.e., nets offering read-only arcs (also called positive contexts, which allow to model multiple concurrent readings of the same resource), and we show how modeling each net computation as a suitable cospan, which is able to recover causal dependencies between fetched and produced resources (i.e., the tokens of the net), so that our result may seem to recast the well-known correspondence result for processes of ordinary nets [22]. Furthermore, we show that by modeling, instead, each net computation as a span, we can recover information about the persistence of resources in a computation, namely, those tokens which are may have been read but have not been consumed. In this setting, system reconfiguration can be viewed as a rule-driven reduction system that allows for simplifying program schemata and software architectures, and therefore, one can prototype automated normalizations of processes by using languages based on rewrite rules (e.g., Maude and ELAN, cfr. the documentation available at the URL's http://maude.csl.sri.com and http://elan.loria.fr) on the underlying span algebra.

The restriction to Set is limiting, and we leave as future work the task of lifting our taxonomy to other categories. Nevertheless, Span(Set) represents an important instance of the paradigm, which might be generalized to e.g. complete or regular categories. Furthermore, it better drives our intuition, since its correspondence with (multi)relations allows us to cast our properties against analogous results already presented in e.g. the theory of relational algebras [2]. In fact, even if the overall justification for the study of the categories of spans have been their connections with relations [5,6] (and it was already clear since [3] the one-to-one correspondence between unitary pretabular allegories [13] and cartesian bicategories), a careful analysis of these connections may result in a few surprises.

In Section 2 we make the correspondence precise by exploiting the notion of multirelation. As a suitable introduction, the relationship is fully worked out, even if it could be considered as an established fact in the literature, after Lawvere's work [21] (but see [29] for an up-to date presentation of the connection between categories of matrices and relations). What seems to be original, to the best of our knowledge, is the negative result in Proposition 2.2, stating the non-existence of object-preserving functors between the category of relations and Span (Set).

In Section 3 we provide the relevant results of the paper, analyzing the equational properties of the monoidal structures induced on Span (Set) by cartesian product and disjoint union in Set. As we will see, the resulting ax-iomatizations fully coincide with two different proposals present in the flowno-mial calculus on the one side, and in cartesian bicategories on the other.

In Section 4 we consider the "opposite" of the category of spans, namely, the category CoSpan(Set) = Span(Setop) of sets and cospans. We sketch the correspondence between cospans and equivalence relations, analyzing the equational properties of the structures induced on CoSpan(Set) by cartesian product and disjoint union in Set: While the latter category shares many of the properties of the monoidal category induced on spans by the cartesian product, the former fails to be monoidal, yielding a pre-monoidal category [25]. These correspondence results are, to the best of our knowledge, new.

Finally, in Section 5 we illustrate an application of spans to the modeling of Petri nets. We consider in particular contextual nets, an extension of the classical model including read-only arcs, and we prove that both categories of spans and cospans can be used to recover information about the causal dependencies between resources, as well as their persistence, in a computation.

1 Preliminaries

We introduce now the terminology and the notation that will be used in the rest of the paper, assuming the reader familiar with the basic concepts of category theory.

Abusing the notation we will often denote the identity arrow ida by the

object name a itself. Sequential composition of f: a ^ b and g: b ^ c is written f; g: a ^ c, i.e., the symbol _; _ composes in the diagrammatic order.

We shall refer to the opposite category Cop of a category C as the category having the same objects as C, but where the direction of the arrows is reversed. For two categories C and D we let Cx D denote their cartesian product in Cat, the category of (small) categories and functors.

1.1 Monoidal Categories

As standard in functorial semantics, we restrict to categories strictly preserving the additional structure; and, in particular, to monoidal structures where the tensor product is strictly associative and with unit, instead of being so only up to a canonical isomorphism. This allows us to focus on the overall presentation of the monoidal structure itself as a suitable data type, at the same time easing the notation, even if all the relevant structure is indeed preserved only up to iso on concrete categories such as Set. We refer the reader for details to the recent [9].

Definition 1.1 A (strict) monoidal category (mc) is a triple (C, ®,e), where C is the underlying category, the tensor product Cx C ^ C is a functor satisfying the associative law (ii ® t2) ® t3 = t1 ® (t2 ® t3), and the unit e is an object of C satisfying the identity law t1 ® e = t1 = e ® t1, for all arrows t1, i2 and i3.

A symmetric monoidal category (smc) is a 4-tuple (C, ®,e, 7), where (C, e) is a mc, and 7: ^ ® _2 ^ _2 ® ^ is a natural transformation satisfying the coherence axioms 7a06;C = (a ® 76,c); (7a>c ® b) and 7^; 7b,a = a ® b, for all a, b, c.

As a matter of terminology, given two functors F, G: C ^ D, we use the term transformation (from F to G) to denote a family n of arrows in D indexed by the objects of C, such that na: F(a) ^ G(a) for all objects a in C. It is a natural transformation if F(f); nb = na G(f) for any arrow f: a ^ b in C. For example, the naturality of symmetries in a smc (C, e, 7) amounts to say that for all f: a ^ b, g: c ^ d we have (f ® g); 7b,d = Ya,c; (g ® f).

Additional structures may live in smc's, and suitable arrows such as duplicators and dischargers (and also their co-versions) do play significant roles. In particular, cartesian categories are monoidal categories such that duplicators and dischargers automatically exist, and are uniquely determined by the universal property of terminal object and products. A duplicator V is a transformation from the identity on C to the functor D; ® = ^ ® ^ obtained by precomposing the tensor by the diagonal functor D: C ^ C x C (with D(f) = (f, f) for all f G C). A discharger ! is a transformation between the identity on C and the constant functor that sends everything into the unit e.

Moreover, the following coherence axioms must be satisfied:

Va®6 = (Va ®V6);(a ® Ya,b ® b) !a®6 =!a®!b Ve = !e = ide

Va; (Va ® a) = Va; (a ® Va) Va; Ya,a = Va Va; (!a ® a) = a

This situation is sometimes referred to in the literature by saying that each object is equipped with a comonoid structure [12], while, after [7], we denote such a structured category as gs-monoidal. If V and ! are natural (i.e., if they satisfy f; Vb = Va; (f ® f) and f; !b =!a for all f: a ^ b), then the category is cartesian.

Similarly, co-duplicators Aa: a ® a ^ a and co-dischargers ¡a: e ^ a must satisfy dual coherence axioms, and we denote the resulting category as cogs-monoidal; when naturality is also satisfied, it yields co-cartesianity. There are various ways for the gs-monoidal and the cogs-monoidal structures to interact. In particular, the following laws have been pointed out in the literature (see,

e.g., [6,10]).

(1) V0 ;An = a (5) ¡0;!0 = e

(2) Aa; Va = (Va ®V„);(a ® la,a ® a); (Aa ® Aa) (6) !a; ¡a = a

(3) Aa; Va = (Va ® a); (a ® Aa) (7) ¡a; Va = ia ® ¡a

(4) Aa; Va = (a ®Va);(Aa ® a) (8) Aa;!a = !a®!a

As a set, these laws are of course redundant. For example, laws (3) and (4) are equivalent, and they subsume law (2). At the same time, they are linked with naturality: The law (2) is e.g. satisfied when the monoidal product is both cartesian and co-cartesian, i.e., if the underlying category has biproducts.

Several subsets of the eight laws listed above have been studied in the literature, usually as a model for various algebras of systems. Case studies range from the flownomials calculus proposed by Cazanescu and §tefanescu [10,28], to the bicategories of relations introduced by Carboni and Walters [5,6]. As stated in the Introduction, we plan to show which algebraic laws are satisfied by (co)span categories over Set, thus offering a taxonomy for those laws.

1.2 On spans (and cospans)

Definition 1.2 [Span] Given a category C, a span on C is an ordered pair of

arrows with common source f: a ^ b and g: a ^ c in C, and it is denoted by

(f,g): b ^ a ^ c.

The object a is called the support of the span, while f and g are called respectively the left and the right leg of the span.

Two spans (fi, gi): b ^ ai ^ c and (f2, g2): b ^ a2 ^ c are equivalent if an isomorphism 0: a1 ^ a2 GC exists such that 0; f2 = f1 and 0; g2 = g1. Other choices of equivalence are available, but this is enforced by our understanding of spans as abstract modules of a distributed system: The arrows represent the

d-T* e

Figure 1. Sequential composition of spans.

interfaces offered for connecting to other components, and the support implements the functionality of the module. Morphisms between supports could be considered as refinement operations, as in [18]; thus, our equivalence modulo isomorphism abstracts away from the choice of the support, without altering its internal structure. At the same time, the equivalence allows for an associative operation of sequential composition: A span (/, g) is seen as an arrow from the target of / to the target of g.

Definition 1.3 [Composition of spans] Given any two composable spans (/, g): b ^ a ^ c and (h, k): c ^ d ^ e, their sequential composition (/, g); (h, k) is the span (pi; /,p2; k), where p1 and p2 are the projections associated with the pullback of g and h in C, if it exists (see Figure 1).

Since pullbacks are unique only up to isomorphism, it is essential to work on equivalence classes of spans; otherwise, either a choice of pullbacks would be required, or suitable bicategories of spans [1] should be considered. Summarizing, by slightly abusing the notation we use the terminology "spans" to denote equivalence classes rather than concrete diagrams.

Similarly, we will ignore the obvious 2-categorical enrichment [1,20]: Each hom-set has a natural pre-order, where (/1 ,g1): b ^ a1 ^ c < (/2,g2): b ^ a2 ^ c if there exists a function 0: a1 ^ a2 such that 0; /2 = /1 and 0; g2 = g1. As we argued before, this enrichment falls outside the scope of the paper, which is interested only in a preliminary analysis of the equational properties of the framework.

Definition 1.4 [Identities] For each object a G C, we let ida = (ida,ida).

Definition 1.5 [Category of spans on C] Given a category C with all pullbacks, the category Span(C) has the objects of C as objects and the spans on C as arrows. Arrow composition and identities are defined as in Definition 1.3 and Definition 1.4.

We focus on the structure of categories Span(Set) and Span(Setop) = CoSpan(Set). In the latter case, objects are sets A, B, C,... and arrows are cospans [/, g]: B ^ A ^ C, with identities idA = [idA,idA], and composition of cospans is computed via pushout in Set.

2 Spans and relations

In this section we focus on the category Rel of (small) sets and relations, highlightening its relationship with the category Span(Set). While a functor

g x0 h

R: Span(Set) ^ Rel is easily defined (see Section 2.1), a straightforward definition for an inverse mapping from Rel to Span (Set) fails to be functorial, because spans retain more information about the multiplicity of components. Moreover, under reasonable assumptions no such functor exists, while a more precise correspondence can be drawn between Span(Set) and the category MRel of multiset relations.

2.1 Spans are more concrete than relations

There is an obvious full functor R : Span (Set) ^ Rel: It is the identity on objects and maps each span (f, g): B ^ A ^ C to the relation

R((f, g)) = {(b, c) G B x C |3a G A.f (a) = b A g(a) = c}.

It can be easily verified that R preserves identities and composition, e.g., that R((f, g); (h, k)) = R((f,g)); R((h,k)) for spans as in Figure 1.

Remark 2.1 We recall that in Set the pullback of g and h can be defined as the triple (g x0 h, p1,p2), where g x0 h = {(a, d) G A x D | g(a) = h(d)}, with p1 and p2 the obvious projections.

Let us consider the function S from Rel to Span(Set) that is the identity on objects and maps a relation r C B x C to the span (q1,q2): B ^ r ^ C, with qi the obvious restriction, to the subset r, of the projection n4xC from B x C to the ith component (B if i = 1, C if i = 2), later denoted n4xC|r.

The mapping S models the intuitive way of regarding a relation as a span, but can it be extended to a functor? It preserves identities, because A is isomorphic to the set {(a, a) | a G A}. To check if S preserves composition, we must show that for any relations r: B ^ C and s: C ^ E, then S(r; s) is equivalent to S(r); S(s). But this is not the case, because S(r); S(s) =

/_BxC BxC \. / CxE _CxE \ (n1 |r,n2 |r); (n1 |s,n2 |s)

= (nBxCxCxE|t,n4^xCxCxE|t), where t = {(b,c,c,e) | (b, c) G r A (c, e) G s}. Since r; s = {(b, e) |3c G C.(b, c) G r A (c, e) G s}, it follows that S(r; s) = S(r); S(s) holds only if t and r; s are isomorphic. This happens if for all b G B and e G E, at most one c G C exists, with (b, c) G r and (c, e) G s; otherwise the cardinality of t is greater than that of r; s. Thus, the obvious lluf (i.e., bijective on objects) functor from Rel to Span (Set) does not work. Also the "dual" solution (i.e., saturating the span with infinite multiplicities for each pair in the relation by letting S(r) = (p1 ,p2): B ^ r x N ^ C and taking advantage of the fact that N x N is iso to N) fails, since the induced functor would preserve composition, but not identities.

Proposition 2.2 No lluf functor S: Rel ^ Span(Set) exists s.t. S; R = 1.

Proof Let A = {a} and B = {b1,b2}. It is straightforward that the identity relation on A coincides with r; s, for r = {(a, b1), (a, b2)} and s = {(b1, a), (b2, a)}. Thus, let S(r) = (f,g): A ^ X ^ B and S(s) = (h, k): B ^ Y ^ A for suitable X and Y. Since we expect that R((f, g)) = r,

the set X must contain at least two elements x1 and x2 that are mapped by g in different elements of B, and similarly for Y. Thus, the pullback object g x0 h also contains two elements (at least) and therefore S(r); S(s) cannot be equivalent to the identity span on the singleton A. □

2.2 Spans define multirelations

We denote by Nw the semiring (N, +, ■) extended with the top element T and the obvious infinitary operations (assuming that 0 ■ T = 0).

Definition 2.3 [Multirelations] Let A and B be sets. A multiset relation (multirelation) on A and B is a multiset M: A x B — Nw, where M(a, b) defines the multiplicity of the pair (a, b) G A x B .As for relations, a multirelation M: A x B — Nw can be viewed as an arrow M: A — B.

Definition 2.4 Given two multirelations M: A — B and N: B — C, their composition is the multirelation M; N such that

(M; N)(a, c) = £ M(a, b) ■ N(b, c)

for any (a, c) G A x C, assuming the sum being T for B countable. Sets and multirelations form a category, denoted MRel.

With the previous definition, MRel results the Kleisli category of the monad induced by the functor _ x Nw from Set to itself.

Given a multirelation M, its underlying relation rM is such that (a, b) G rM iff M(a, b) > 0. It is immediate to note that a relation is just a multirelation M: A x B —^ {0,1}, however Rel, the category of sets and relations, is not a subcategory of MRel, as it follows from the results in the previous section. Instead, it is then possible to define a functor from Span (Set) to MRel. The function M is the identity on objects and maps each span (/, g): B ^ A — C to the multirelation M((/, g)) such that for all b G B and c G C we have

M((/, g))(b, c) = |{a G A | /(a) = b A g(a) = c}|

Proposition 2.5 The function M can be extended to a functor.

The functor P: MRel — Span(Set), inverse to M, can be defined as follows: P is the identity on objects and maps any multirelation M: B — C to the span (p1,p2): B ^ M — C, where M = {(b, c, i) G B x C x N | 0 < i < M(b, c)} and p1 and p2 are the obvious projections. For identities, the set A = {(a, a, 1) | a G A} is of course isomorphic to the set A. Moreover, given any two multirelations M: B — C and N: C — E, then P(M; N) = P(M); P(N).

It is easy to verify that P; M is the identity functor on MRel, since

M(P(M))(b, c) = |{(b, c, i) | 0 < i < M(b, c)}| = M(b, c). Taken a generic span (/, g): B ^ A — C, then:

P(M((/,g))) = (P1,P2): B ^ A — C,

where A = {(f(a),g(a),i) | 0 < i < M((f,g))(f(a),g(a))}, and P1 and P2 are the obvious projections. Then, any isomorphism between A and A that maps a into (f (a), g(a), ia) for suitable index ia proves the equivalence between P(M((f,g))) and (f,g).

Proposition 2.6 The categories Span(Set) and MRel are equivalent. 2.3 Partial functions, minimal spans and relations

A further abstraction has to be required on spans, in order to discard multiplicities, but "syntactical" restrictions on span components do not suffice. For example, requesting left legs to be mono is a property closed under composition (pullbacks preserve monos) and thus yields a category, but in Span (Set) this just captures partial functions [26]. In fact if in (f, g), f: A ^ B is mono, then at most one pair (b, g(a)) can be assigned to b G B with f (a) = b. For the converse correspondence, given a partial function k: B ^ C we just take the span kp given by (in,k|dom(k)): B ^ dom(k) ^ C, with in:dom(k) ^ B the obvious inclusion. Indeed, given a second partial function h: C ^ E, then the composition kp; hp has as pullback object the domain of k; h, as expected.

Similarly, the restriction to mono right legs still yields a subcategory (dual to the previous one), while no category exists if restricting to jointly mono spans, because they are not closed under composition. Nevertheless, Rel can be recovered either redefining the composition for the category of jointly mono spans (namely, considering a suitable epi-mono decomposition component of the resulting span), or equivalently by collapsing spans whose supports are related by a surjective function (an epimorphism in Set.)

Definition 2.7 Two spans (f1,g1): B ^ A1 ^ C and (f2, g2): B ^ A2 ^ C are kernel ordered, written (f1,g1) (f2, g2), if there is an epi e: A2 ^ A1 such that f2; e = f1 and g2; e = g1.

Composition of spans is monotonic with respect to such an ordering, and thus induces a partial order over Span(Set). We denote by =e the symmetric closure of and by Spane(Set) the category of spans modulo the equivalence =e. Each =e-equivalence class has a minimal element (unique up to iso) that gives the minimal representation of the underlying relation.

Proposition 2.8 The categories Spane(Set) and Rel are isomorphic. 3 Two monoidal structures for spans

In this section we study the equational properties of the two different monoidal structures over Span (Set), induced by product and disjoint union in Set. While both structures result gs-monoidal and cogs-monoidal (since they are self-dual), the laws satisfied by the interaction of their respective operators are quite different.

3.1 Spans and product

We first analyze the case in which the tensor product is induced by the cartesian product in Set, denoting the resulting structure as (Span(Set), ®). Given two objects A1 and A2, their tensor product is the set A1 x A2, and given two spans (/1 ,g1): B1 ^ A1 — C1 and (/2,g2): B2 ^ A2 — C2, their product is the span (/1 x /2,g1 x g2): B1 x B2 ^ A1 x A2 — C1 x C2. The unit for the tensor product is the singleton 1 = {•} (e.g., we assume A x 1 = A = 1 x A for all sets A).

The symmetry at A and B is the span (idA x idB, XA B): A x B ^ A x B — B x A, where XA B(a, b) = (b, a) for all a G A and b G B. Note that the symmetry could have been defined as well as being the span (XB A, idB x idA), which is in fact equivalent to the previous one. We denote (idA x idB, XA,B) by the symbol 70 B. Coherence and naturality of 70 B rely on the properties of XA, B in Set.

The duplicator at A is given by V0 = (idA, VA): A ^ A — A x A, where the function VA: A — A x A is defined as VA(a) = (a, a) for all a G A. Although the duplicator V is natural in Set, in general the duplicator V0 is not natural in (Span(Set), ®).

Proposition 3.1 Given a span (/, g): B ^ A — C, the compositions (/, g); V0 and V0; (/ x /, g x g) are equivalent iff / is mono.

This result is in fact pivotal in the characterization of spans as partial functions (see e.g. [26], and the recent [9] for a general discussion on gs-monoidal categories and varieties of partial algebras).

The discharger at A is given by !0 = (idA, !A): A ^ A — 1, where !a: A — 1 is the unique constant function with !A(a) = • for all a G A. Although the discharger ! is natural in Set, the discharger !0 is not natural in (Span(Set), ®).

Proposition 3.2 Given a span (/, g): B ^ A — C, the composition (/, g); !0 is equivalent to !0 iff / is iso.

Hence, this amounts to say that the discharger in (Span(Set), ®) is not natural because 1 is not terminal. In fact, for each set A there are infinitely many arrows to 1, which are differentiated by their left component. The coherence axioms can be easily verified due to the particular nature of the spans 70, V0 and !0 that have an iso as the left leg, and due to the fact that this property is preserved by span composition. Thus all coherence axioms trivially reduce to the analogous ones in Set, which are of course valid.

The self-dual nature of Span (Set) allows for a straightforward definition of the dual of duplicators and dischargers. Hence, we have the co-duplicator A0 = (VA,idA): A x A ^ A — A, and the co-discharger ¡0 = (U,id^): 1 ^ A — A. It is obvious that co-duplicators and co-dischargers are not natural and satisfy the coherence axioms. The interesting question concerns the validity of laws (1)-(8).

Proposition 3.3 The category (Span(Set), ®) satisfies the laws (1)-(4).

The other laws are a different matter. For example, by composing dischargers with co-dischargers in (Span(Set), ®) in general we get ¡®; = (!A, !A) = id1 and !®; i® = (nj4xA,n;AxA) = idA. In the first case, the equality holds iff A is either iso to 1, or to 0; in the second case, iff A is iso to 1.

Likewise, the composition of duplicators and co-dischargers usually yields ¡®; V® = (!a, Va) = ¡® x i® and A®;!® = (Va, !a) = x !®. Also in these cases, the equalities hold iff A is either iso to 1, or to 0.

Note that the same set of equations holds for relations. Thus, considering Spane(Set), and denoting by (Spane(Set), ®) the monoidal category induced by the cartesian product of sets, we can state the following result.

Proposition 3.4 The category (Spane(Set), ®) satisfies the laws (1)-(4). 3.2 Spans and disjoint union

The disjoint union in Set induces a different gs-monoidal structure on Span(Set), denoted by (Span(Set), ©). Given two sets A and B, their tensor product is the disjoint union A ll B = {(0,a) | a G A}U{(1,b) | b G B}, with the empty set 0 as unit. Given two spans (f1, g1) and (f2, g2), their tensor is (f1 l f2,g1 l g2), where

,iM v , ( (0, f (a)) if x = (0, a) (f l g)(x) = <

[ (1, g(b)) if x = (1, b)

The symmetry at A and B is 7®,4 = (idA ll idB, xA,B): A ll B ^ A l±l B ^ B ll A, where xA,B(i, x) = (i + 1 mod 2, x) (for x G A U B). The duplicator at A is given by V® = (ta, idA^A): A ^ A l A ^ A l A, where ta: A l A ^ A is defined as TA(i, a) = a for all i G [0,1] and a G A, and it is natural. The discharger at A is defined by !® = (0A,id$): A ^0^0, where 0A: 0 ^ A is the unique arrow from the initial object of Set to the set A, and it is also natural. Since also the coherence axioms are satisfied by 7®, V® and !®, we can conclude the following result.

Proposition 3.5 Disjoint union makes Span(Set) a cartesian category.

Dually, the natural co-duplicator is A® = (idAwA, ta): A ll A ^ A ll A ^ A and the natural co-discharger is i® = (id$, 0A): 0^0^ A.

Proposition 3.6 Disjoint union makes Span (Set) a co-cartesian category.

However, the interplay between the two dual structures in (Span(Set), ©) satisfies only laws (2), (5), (7) and (8), whereas the other laws are trivially satisfied iff A is empty. Instead, relations satisfy one more law: We can summarize the situation with a result analogous to Proposition 3.3 and Proposition 3.4.

Proposition 3.7 The category (Span(Set), ®) satisfies the laws (2), (5), (7) and (8); whereas the category (Spane(Set), ©) additionally satisfies law (1).

4 Cospans

Many analogies can be drawn between the categories Span (Set) and CoSpan(Set). In particular, equivalence relations play for cospans the role played by relations for spans: In a cospan [f, g]: B ^ A ^ C all the elements of B and C that are mapped to the same element a G A are viewed as belonging to the same equivalence class. It is worth remarking that more information is stored in cospans, if the two arrows f, g are not jointly epi. Differently from Span(Set), CoSpan(Set) possesses only one monoidal structure, obtained by lifting disjoint union. The structure resulting from the lifting of product is just pre-monoidal: One of the few "natural" examples of such categories, to the best of our knowledge.

4.1 Cospans and equivalence relations

We try now to establish similar results between cospans and equivalence relations, as those holding between spans and relations. We first give the explicit definition of ERel, the category of sets and equivalence relations.

Definition 4.1 [Equivalence relations] Let A and B be sets. An equivalence relation (also, partition) e from A to B is a reflexive, transitive and symmetric relation over A ll B. A redundant partition ep from A to B is a pair (e, ne), for partition e: A ^ B and ne G . Given partitions E: A ^ B and F : B ^ C, their composition is given by the pair ((e; f )*, ne+nf+nB), where (e; f )* is the restriction to A ll C of the transitive closure of e; f, and nB is the cardinality of the family of equivalence classes in (e; f )* containing only elements in B.

Sets and (redundant) equivalence relations form a category, denoted by ERel (respectively RERel).

There is an obvious full functor P that maps each cospan [f, g]: B ^ A ^ C to the partition P = P([f,g]), such that P = {Pi, ...,P„ | n = |f (B) U g(C )|} and d G Pj iff, given a total ordering x1, ...,xn,... over f (B ) U g(C ), then either d G B and f (B) = Xj, or d G C and g(C) = Xj. In the other direction, there is a lluf functor from RERel to CoSpan(Set). In addition, ERel can be identified with a suitable quotient category of CoSpan(Set).

Definition 4.2 Two cospans [f1,g1]: B ^ A1 ^ C and [f2,g2]: B ^ A2 ^ C are image ordered, written (f1,g1 ) (f2,g2), if there is a mono m: A2 ^ A1 such that f2; e = f1 and g2; e = g1.

Composition of cospans is monotonic with respect to such an ordering, and thus induces a partial order over CoSpan(Set). We denote by =m the symmetric closure of and by CoSpanm(Set) the category of spans modulo the equivalence =m. Each =m-equivalence class has a minimal element (unique up to iso) that gives the minimal representation of the underlying relation.

Proposition 4.3 The categories CoSpan(Set) (CoSpanm(Set)) and RERel

(respectively ERel) are equivalent (isomorphic).

4.2 Cospans and disjoint union

A monoidal structure of CoSpan(Set) is given by taking as tensor product of A and B their disjoint union A ll B: We denote the resulting structure as (CoSpan(Set), ©). Given two cospans [/i,gi] and [/2,g2], their tensorial product is [/1 ll /2, g1 ll g2] and the unit is the empty set 0.

The symmetry at A and B is 7® ,B = [idA ll idB ,%B, A]: A l±l B ^ A l±l B ^ B ll A, and satisfies the naturality axiom for symmetries. The duplicator at A is defined by V® = [idA,TA]: A ^ A ^ A ll A; the discharger at A is !A = [idA,0A]: A ^ A ^ 0. In general, duplicators and dischargers are not natural.

Proposition 4.4 Given [/, g]: B ^ A ^ C, then [/, g]; V® = VB; [/1 /, g l g] iff / is surjective; whereas [/, g]; = T® iff / is iso.

It is straightforward that the coherence axioms are satisfied by 7®, V® and The co-duplicator and co-discharger at A are A® = [ta, idA]: A ll A ^ A ^ A and iA = [0A,idA]: 0 ^ A ^ A, respectively. The interplay between the two dual structures yields a monoidal structure very similar to the one of (Span(Set), ®).

Proposition 4.5 The category (CoSpan(Set), ©) satisfies the laws (1)-(4).

This analogy is partly supported by looking at laws (5)-(8): They are satisfied iff A is empty, as summarized in Table 1.

4.3 Cospans and products

As we already claimed, lifting the cartesian product of Set to CoSpan(Set) does not result into a monoidal category. A simple counterexample is given by considering the discharger !A and the co-discharger iA of the monoidal structure induced by the disjoint union, and showing that the functoriality of product does not hold, namely, (!A; iA) ® (!A; iA) = (TA ® !A); (iA ® iA). In fact, the structure (CoSpan(Set), ®) forms a pre-monoidal category: A relevant structure, albeit it lies ouside of the scope of the present paper, and its analysis is left for future work.

5 Spans, cospans and Petri nets

A Petri net N is a graph whose nodes are taken in the free commutative monoid S® generated by a set of places and whose arcs are called transitions. We let a, b,... range over S and t, s,... range over the set of transitions T. The elements u, v,... of S® are called markings. We let u U v, u Ç v, and

v \ u denote respectively multiset union, multiset inclusion (of u into v) and multiset difference (defined if u C v). Each marking u = ©aeSna ■ a defines a configuration of the system, i.e. a multiset of resources (tokens) typed over the places S; a transition t: ut ^ vt is enabled at u if ut C u, and its execution (firing) leads to (u \ ut) U vt; a multiset of transitions t = {n1 ■ t1,..., nk ■ tk} with ti: ui ^ vi for i G [1, k], is (concurrently) enabled at u if |Jie[1 k] ni ■ ui C u and their firing leads to (u \ Uie[1>fe] n ' ui) U Uie[1,fc] ni' vi.

Nets with read arcs (or positive contexts) differ from ordinary Petri nets by distinguishing for a transition t: u ^ v a multiset w of 'read but not consumed' resources, with the obvious requirement that u D w C v. As a consequence, the concurrent firing of a multiset of transitions is allowed whenever they are concurrently enabled for what concerns their 'fetched' resources, but where 'contexts' can be instead shared, so that one 'contextual' token can enable more transitions at the same time. Let us now make some precise definition, restricting our attention, for the sake of simplicity, to nets where each arc has weight 1.

Definition 5.1 [contextual net] A contextual net N (also c-net) is a five-tuple (SN, TN, preN, postN, ctxN) such that SN and TN are finite sets of places and transitions, respectively; and preN, postN, ctxN : TN ^ SN are jointly injective functions.

We plan to further restrict the class of nets under analysis. To this end, we need some additional definitions, concerning possible sequences of transitions.

Definition 5.2 [computations] Let N be a net and u a marking. A computation a, starting from u, is a sequence of transition t1,... ,tn, such that for each i G [1, n], the transition ti is enabled in ui (i.e., preN(ti) U ctxN(ti) C ui), with u1 = u and ui+1 = ui \ preN (ti) U postN (ti). The markings ui are said to be reachable from u.

Spans can interpret computations in such a way that the information about non-consuming readings is maintained. For the sake of simplicity we illustrate the mapping for the class of safe nets, just sketching its extension to all nets.

Definition 5.3 [safeness] Given an initial marking uN C SN, the net N is safe (for uN) if all the markings which can be reached starting from uN are also just sets.

The notion of enabling for multisets of transitions can be easily given for safe contextual nets: simply, the tokens in the preset of each single transition are disjointly united, while those in the contexts are simply united.

It is possible to interpret each computation (eventually composed by a sequence of multisets of transitions) of a safe net N in (Span(Set), ©), by assigning to each transition t the span

(ft, gi): pren(t) U ctxn(t) ^ ctxn(t) ^ postn(t) U ctxn(t), where ft and gt are the obvious injections.

The firing of t at marking u D preN (t) U ctxN (t) is then interpreted as the tensor product (in (Span(Set), ©)) of (ft, gt) with the identity of u\ (preN(t) U ctx N (t)); i.e., as (ft,gt) © id«\(preN (t)ucix N (t)): u ^ u \ pre n (t) ^ (u \ pre n (t)) U postN(t). In fact, the support contains those resources which are only read by the transition (namely, ctxN(t)) and those which are not checked at all in the transition itself (namely, (u \ ctxN(t)) \ preN(t)).

Finally, the span associated with a computation a = t1, ...,tn is given by sequentially composing the spans associated with the n firings of the ti's (at their respective ui's, see Definition 5.2). Thus, to each computation a span is associated inductively, and the following claim may be safely stated.

Claim 5.4 Let : u ^ w ^ v be the span associated with a computation a. The elements a G u which are in the image of the support w are those resources which are eventually read, but never consumed, in the computation. Moreover, for each element a G w, its images through the left and right legs of the span represent the same (idle or read) resource of the computation a.

A more intriguing characterization may be obtained interpreting computations in (CoSpan(Set), ©), by assigning to each transition t the cospan

[ft, gt]: pren(t) U ctxn(t) ^ {t} U ctxn(t) ^ postn(t) U ctxn(t),

where ft and gt are the identities on ctxN (t), and the constant functions on preN(t) and postN(t) (sending everything to the element t of the support). Thus, the support contains, in addition to those resources which are only read (namely, ctxN(t)), also a token simulating the occurrence of a causal dependency among the other resources. Or, more appropriately, a relation of necessary consumption between them. While, to some extent, fetched and produced resources belong to the same thread (the element t in the support), read resources have associated one side-thread each.

This could be better understood by introducing two types in the support: T and C, where C < T, with typing assignments t(t) = T and t(a) = C for all a G ctxN (t). When cospans are sequentially composed, the types of the elements in the resulting support is given by the sup of the types of the elements in their counterimages, i.e., when composing [f, g] with [h, k] via the pushout (D, q1: B ^ D, q2: C ^ D) of g: A ^ C and h: A ^ B, then the type

t(d) of any element d G D is given by t(d) = U6Sq1-1(d) t(b) u Uceq2-1(d) t(c).

This reflects the intuition that a token read by the first step of a computation and then consumed in the second step becomes a consumed token (similarly for tokens that are first produced and then read). Of course, to each computation a cospan is associated inductively as before, and the following claim may be safely stated.

Claim 5.5 Let n<r: u ^ w ^ v be the cospan associated with a computation a. Given a G u and b G v, if they are mapped by the legs of the span to the same element, say c, of the support, then in the computation the resource a has been fetched for producing the resource b. Moreover, if t(c) = C, then a and b would correspond to the same contextual (or idle) token.

It is by no chance that cospans may intuitively allow for a discussion on causal dependencies among the different threads, so to say, of a computation. In fact, the causal and concurrent semantics of a net N is usually expressed by means of so-called deterministic processes, a particular kind of acyclic safe nets, each one of them modeling a computation of N. In this case, the possible simultaneous execution of two transitions sharing the same resource has its counterpart in the causal independence between their representation as processes.

In [11] it has been shown that the deterministic processes of a generic net N form the arrows of a suitable symmetric monoidal category (symmetries have the task of eventually rearranging multiple tokens in the same place, whenever this is needed for composing processes), and in [16], the relationship has been extended to a fairly sophisticate embedding of processes of a contextual nets into match-share categories. These categories are essentially symmetric monoidal categories equipped with duplicators and coduplicators satisfying laws (1) and (3), and consequently, also laws (2) and (4). Reading without consuming is in fact modeled by first duplicating the contextual resources, then executing the transition with an idle copy of the original resources in parallel, finally matching (via a coduplicator) the idle copy with the corresponding resources in the postset of the step.

Thus, since CoSpan(Set) is a model of the match-share category generated by N, each contextual process of N can be interpreted in that category, by first defining the image of transitions (as we have illustrated above) and then exploiting the features of initial model semantics to lift the mapping to all the processes via the unique strict match-share functor that extends the interpretation of transitions.

In non-safe nets, markings can involve several tokens in the same place. Correspondingly, when composing computations, it is crucial not to mix up those tokens, as they can carry different causal (and persistence) information. Though the token types (i.e., the place where they belong) get lost in the interpretation, the correct typing would be preserved by the functorial interpretation of processes.

Remark 5.6 Alternatively, typed (co)spans could be employed. Formally, a span (f, g): A ^ C ^ B is typed over S when it is equipped with two functions fS: A ^ S and gS: B ^ S; moreover, it is composable with a span (h, k): B ^ E ^ D typed over S by hS and kS, if gS = hS (composition is defined as usual, with resulting typings given by fS and kS). Likewise, for typed cospans.

Concluding Remarks

The aim of our paper was to investigate some algebraic properties satisfied by the categories Span(Set) and CoSpan(Set). In particular, we analyzed the monoidal structures over those two categories, induced by cartesian product and disjoint union in Set: Our results are summarized in Table 1. Each row is

(1) (2) (3) (4) (5) (6) (7) (8) nat. dup. nat. dis.

Span (Set), ® + + + + I A |< 1 I A |< 1 A ~ 1 A ~ 1 f mono f iso

Span (Set), ® A = 0 + A = 0 A = 0 + A = 0 + + + +

CoSpan (Set), ® + + + + A = 0 A = 0 A = 0 A = 0 f epi f iso

Rel, ® + + + + I A |< 1 I A |< 1 A ~ 1 A ~ 1 f mono f iso

Rel, ® + + A = 0 A = 0 + A = 0 + + + +

ERel, ® + + + + A = 0 A = 0 A = 0 A = 0 f epi f iso

Table 1

Summary of results for (co)spans and (equivalence) relations.

dedicated to a particular symmetric monoidal category; each column is associated with a particular property (laws (1)-(8), naturality of (co)duplicators and (co)dischargers). Each entry describes whether the property holds in the category: The symbol + states that the axiom is valid, while the other entries describe the sufficient and necessary condition under which the axiom is satisfied. As for the naturality axioms, conditions refer to a generic span (/, g) or cospan [/, g] with support A.

In particular, the table displays the similarity between Span(Set) with products and CoSpan(Set) with unions: Not too surprising, given the duality in their definition; more striking is the different behaviour over the alternative structures, which we were not able to pinpoint in a formal way. In fact, our results are still preliminary. As an example, we did not tackle at all the issue of the intuitive ordering over (co)spans, except in defining the categories Spane(Set) and CoSpanm(Set). This is a relevant topic, both semantically, as shown e.g. in the predicate transformer construction in [17]; and syntactically, since it would allow us to take further the connection between our work and e.g. the notion of direct product [2] in relational algebras, which is for now forbidden by our restriction with respect to the 2-dimensional aspects of the formalism. Nevertheless, the flat view we pursued in this paper seems to be enough for recasting and extending several other properties used in relational approaches (e.g., thanks to the correspondence we sketched in Section 4.1, one can easily generalize the notion of difunctionality [27] which is then preserved by composition, yielding a subcategory).

Moreover, we also plan to investigate if, and how, our taxonomy can be extended and generalized to (either complete or regular) categories other than Set. We are thinking in particular of Graph, given the importance of the resulting categories in the modeling of the operational behaviour of rewriting systems and of automata, as pointed out in [8,15] and [18,19], respectively.

References

[1] J. Benabou. Introduction to bicategories. In Midwest Category Seminar, volume 47 of Lectures Notes in Mathematics, pages 1-77. Springer Verlag, 1967.

[2] R. Berghammer, A. Haeberer, G. Schmidt, and P. Veloso. Comparing two different approaches to products in abstract relational algebra. In M. Nivat,

Ch. Rattray, T. Rus, and G. Scollo, editors, Algebraic Methodology and Software Technology, Workshops in Computing, pages 167-176. Springer Verlag, 1994.

[3] C. Brown and A. Jeffrey. Allegories of circuits. In A. Nerode and Y. Matiyasevich, editors, Logic Foundations of Computer Science, volume 813 of Lect. Notes in Comp. Science, pages 56-68. Springer Verlag, 1994.

[4] R. Bruni, F. Gadducci, and U. Montanari. Normal forms for partitions and relations. In J.L. Fiadeiro, editor, Recent Trends in Algebraic Development Techniques, volume 1589 of Lect. Notes in Comp. Science, pages 31-47. Springer Verlag, 1999.

[5] A. Carboni, S. Kasangian, and R.H. Street. Bicategories of spans and relations. Journal of Pure and Applied Algebra, 33:259-267, 1984.

[6] A. Carboni and R.F.C. Walters. Cartesian bicategories I. Journal of Pure and Applied Algebra, 49:11-32, 1987.

[7] A. Corradini and F. Gadducci. An algebraic presentation of term graphs, via gs-monoidal categories. Applied Categorical Structures, 7:299-331, 1999.

[8] A. Corradini and F. Gadducci. Rewriting on cyclic structures: Equivalence between the operational and the categorical description. Informatique Théorique et Applications/Theoretical Informatics and Applications, 33:467493, 1999.

[9] A. Corradini and F. Gadducci. A functorial semantics for multi-algebras and partial algebras, with applications to syntax. Theoret. Comput. Sci., 2001. To appear. Available at http://www.di.unipi.it/~gadducci/papers.

[10] V.-E. Cazanescu and Gh. Stefanescu. Classes of finite relations as initial abstract data types I. Discrete Mathematics, 90:233-265, 1991.

[11] P. Degano, J. Meseguer, and U. Montanari. Axiomatizing the algebra of net computations and processes. Acta Informatica, 33:641-667, 1996.

[12] T. Fox. Coalgebras and cartesian categories. Communications in Algebra, 4:665-667, 1976.

[13] P. Freyd and A. Scedrov. Categories, Allegories. North-Holland, 1990.

[14] F. Gadducci and R. Heckel. An inductive view of graph transformation. In F. Parisi-Presicce, editor, Recent Trends in Algebraic Development Techniques, volume 1376 of Lect. Notes in Comp. Science, pages 219-233. Springer Verlag, 1998.

[15] F. Gadducci, R. Heckel, and M. Llabrés. A bi-categorical axiomatisation of concurrent graph rewriting. In M. Hofmann, D. Pavlovic, and G. Rosolini, editors, Category Theory and Computer Science, volume 29 of Electronic Notes in Theoretical Computer Science. Elsevier Sciences, 1999. Available at http://www.elsevier.nl/locate/entcs/volume29.html/.

[16] F. Gadducci and U. Montanari. Axioms for contextual net processes. In K.G. Larsen, S. Skyum, and G. Winskel, editors, Automata, Languages and Programming, volume 1443 of Lect. Notes in Comp. Science, pages 296-308. Springer Verlag, 1998.

[17] P. Gardiner, C. Martin, and O. de Moor. An algebraic construction of predicate trasformers. In R.S. Bird, C.C. Morgan, and Woodcock J.C.P., editors, Mathematics of Program Construction, volume 669 of Lect. Notes in Comp. Science. Springer Verlag, 1992.

[18] P. Katis, N. Sabadini, and R.F.C. Walters. Bicategories of processes. Journal of Pure and Applied Algebra, 115:141-178, 1997.

[19] P. Katis, N. Sabadini, and R.F.C. Walters. SPAN(Graph): A categorical algebra of transition systems. In M. Johnson, editor, Algebraic Methodology and Software Technology, volume 1349 of Lect. Notes in Comp. Science, pages 307-321. Springer Verlag, 1997.

[20] G.M. Kelly and R.H. Street. Review of the elements of 2-categories. In G.M. Kelly, editor, Sydney Category Seminar, volume 420 of Lecture Notes in Mathematics, pages 75-103. Springer Verlag, 1974.

[21] F.W. Lawvere. Metric spaces, generalized logic, and closed categories. Rendiconti del Seminario Matematico e Fisico di Milano, 43:135-166, 1973.

[22] J. Meseguer and U. Montanari. Petri nets are monoids. Information and Computation, 88:105-155, 1990.

[23] U. Montanari and F. Rossi. Contextual nets. Acta Informatica, 32:545-596, 1995.

[24] C.A. Petri. Kommunikation mit Automaten. PhD thesis, Institut für Instrumentelle Matematik, Bonn, 1962.

[25] J. Power and E. Robinson. Premonoidal categories and notions of computation. Mathematical Structures in Computer Science, 7:453-468, 1998.

[26] E. Robinson and G. Rosolini. Categories of partial maps. Information and Computation, 79:95-130, 1988.

[27] G. Schmidt and T. Strohlein. Relations and Graphs, Discrete Mathematics for Computer Scientists. EATCS-Monographs on Theoretical Computer Science. Springer Verlag, 1993.

[28] Gh. Stefanescu. Network Algebra. Springer Verlag, 2000.

[29] M. Winter. A pseudo representation theorem for various categories of relations. Theory and Application of Categories, 7:23-37, 2000. Available at http://www.tac.mta.ca/tac/.