Resourceful Traces for Commuting Processes
Abstract
We show that, when the actions of a Mazurkiewicz trace are considered not merely as atomic but as transformations from a specified type of inputs to a specified type of outputs, we obtain a novel notion of presentation for effectful categories (also known as generalized Freyd categories), a well-known algebraic structure in the semantics of side-effecting computation. Like the usual representation of traces as graphs, our notion of presentation gives rise to a graphical representation of morphisms in effectful categories. We use our presentations to give a construction of the commuting tensor product of free effectful categories, capturing the combination of systems in which the actions of each must commute with one another, while still permitting exchange of resources.
Keywords and phrases:
Mazurkiewicz traces, premonoidal categories, monoidal categories, effectful categoriesFunding:
Matthew Earnshaw: Estonian Research Council grant PRG1210 and PRG2764.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Concurrency ; Theory of computation Categorical semanticsAcknowledgements:
The authors thank Niels Voorneveld for discussions, and the anonymous reviewers for their detailed comments and suggestions on the manuscript.Editors:
Stefano Guerrini and Barbara KönigSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Mazurkiewicz traces [5, 17] provide a simple but powerful model of concurrent systems. Traces are a generalization of words, in which specified pairs of symbols (thought of as actions) can commute. Commuting actions and are independent: their possible concurrent execution is observationally indistinguishable from .
Just as free monoids are the algebraic structure formed by words, free partially commutative monoids [8] or trace monoids [17, 25] are the algebraic structure formed by (Mazurkiewicz) traces. Traces therefore permit an algebraic approach to the analysis of concurrent systems, by analogy with the use of algebraic methods in automata theory.
Mazurkiewicz states that intuitively, “actions are state transformations of some resources of a system” and that “actions are independent if they act on disjoint sets of resources” [16]. We contend that this view conflates two notions of resource that might be present in a concurrent system, and it is the remit of this paper to show that by teasing them apart, we obtain a richer algebraic structure.
On the one hand are shared resources corresponding to definite noun phrases, such as “the database”, “the memory location”, or “the printer”. These indeed give rise to relations of (in)dependence between actions. In this paper, we shall refer to such resources as devices. On the other hand are the kinds of resources and their transformations axiomatized by monoidal categories, as in Coecke, Fritz and Spekkens [4]. These are resources which act like types, and generally correspond to indefinite noun phrases such as “a database query”, “an integer”, or “a message”. Given any two such resources, we can always consider their conjunction “in parallel”, and they do not necessarily lead to relations of (in)dependence between actions. In what follows, we shall refer to these simply as resources.
For example, consider Figure 1, which introduces a running example, in our graphical notation. The left-hand side of the figure corresponds to our analogue of the alphabet of actions underlying a trace: we call this an effectful signature. In our example, the effectful signature contains a process corresponding to the action of emitting a document, with a single output string, and two processes corresponding to the action of printing received data on two distinct printers. Note that these actions are no longer atomic: they have strings corresponding to resources (depicted as solid strings, in general annotated with particular resources), that here indicate the data to be printed. Crucially, the two printing actions are annotated by distinct devices, depicted as patterned strings. Intuitively, a resourceful trace is a string diagram (directed from a left to a right boundary) built by plugging generators together, while only allowing each device string to appear at most once in each vertical section.
If we only admit one printer in our system, printing actions must occur in a specific order, and this is captured by the topology of the trace, as in the center of Figure 1. However, if we admit both printers, printing can occur concurrently, and this is again captured by the topology of the traces, such as on the right of Figure 1, where the printing actions may slide past one another or interchange. We shall see in Section 5 that this example in fact arises by a canonical combination of the “theory of a printer” with itself, called the commuting tensor product, generalizing the commuting tensor product of algebraic theories [9].
The collection of all resourceful traces over an effectful signature assembles into an effectful category [23], also known as generalized Freyd categories [10, 21], a well-known algebraic structure in the semantics of effectful computation. Indeed, one of the results of this paper is that resourceful traces are the morphisms in free effectful categories. That is, we show that there is an adjunction between effectful signatures and effectful categories, generalizing the classic maximal cliques construction for Mazurkiewicz traces.
Related work
That Mazurkiewicz traces can be seen as morphisms in certain free monoidal categories was elaborated by Sobociński and the first author [7]. By moving to effectful categories, we sharpen this viewpoint, recovering Mazurkiewicz traces precisely as the morphisms in free effectful categories with no resources (qua “indefinite noun phrases”). The construction of free effectful categories over effectful signatures with a single device was given by the third author, following Jeffrey [13, 22, 23]. The construction of the commuting tensor product of effectful categories appeared in [6], in terms of string diagrams, covering the case of morphisms supported by a finite number of devices. The central results of this paper are new, namely the existence of an adjunction between effectful signatures and effectful categories (Corollary 42), and Theorem 47 on the commuting tensor product of free effectful categories.
Outline
Section 2 recalls the notion of Mazurkiewicz trace, and their graphical representation. Section 3 introduces effectful signatures and effectful categories, via their underlying device signatures and monoidal signatures, generalizing the notion of distribution of an alphabet of actions. We give a construction of the free effectful category over an effectful signature, whose morphisms are resourceful traces. In Section 4, we show how the cliques construction from the theory of traces generalizes to effectful categories, and exhibits the free construction as a left adjoint. Finally, Section 5 gives a construction of the commuting tensor product of free effectful categories, capturing the combination of systems in which the morphisms of each are forced to commute with one another, even while they may exchange resources.
2 Mazurkiewicz traces
In this section, we recall the basic definitions of trace theory, including the graphical presentation of traces. For more details, we refer to Mazurkiewicz, Hoogeboom and Rozenberg [5]. For this section, we fix a set of actions , and denote by the monoid of words over .
Definition 1.
A dependency relation, , is a reflexive, symmetric relation. Dependency relations form a preorder, , with order the inclusion of relations.
Intuitively, a dependency relation specifies actions which should not occur concurrently, because they have some kind of dependency on each other, or the potential to interfere, such as writing to the same location in memory.
Definition 2.
Given a dependency relation , let be the least congruence on such that for every pair of actions , implies . The free partially commutative monoid or trace monoid generated by is the quotient monoid . An element of the trace monoid is a Mazurkiewicz trace (or simply trace) over .
A trace is thus an equivalence class of words up to commutation of independent actions. Another construction of traces starts from distributions of the set of actions:
Definition 3.
A distribution of is a function for some . Distributions form a preorder with if and only if for all ,
Classically, is known as the set of locations of . In line with the terminology introduced in the following, we call the set of devices of . In terms of concurrency, we might consider to be the set of shared resources on which depends, such as memory locations, execution threads, runtimes or peripherals.
We can represent a distribution graphically by introducing nodes (depicted as boxes) corresponding to actions in , with interfaces (depicted as patterned strings) corresponding to the devices assigned to the action, as for example in Figure 2.
Traces are the diagrams that we can build by plugging these components together, subject to the restriction that each device string occurs exactly once in each vertical slice of the diagram, such as in Figure 3. This is formalized by the algebra of (pre)monoidal categories, as we shall see in the next section. The collection of all such diagrams also forms a monoid, isomorphic to the trace monoid. More details can be found in the work of Sobociński and the first author [7], which builds on earlier work on the representation of traces as graphs [5].
A classical construction lets us move between dependency relations and distributions: devices correspond to (non-trivial) maximal cliques in the graph of the dependency relation. For example, the dependency relation depicted in Figure 4 gives rise to the distribution in Figure 2. In Section 4, we shall apply a similar construction to effectful categories.
Definition 4.
The graph of a dependency relation has vertices the elements of and an edge for every .
Proposition 5.
([7, §4.1]) Every dependency relation on gives rise to a distribution of by taking a bijection of with the non-trivial maximal cliques of the graph of , with sending an action to the subset of such cliques to which it belongs. This extends to a (contravariant) Galois insertion, .
Finally, we remark that any monoid has an underlying distribution, which can be found using the maximal cliques construction. A monoid has a dependency relation on its elements defined by just when and do not commute in , and taking non-trivial maximal cliques in the graph of this dependency relation defines a distribution of . We shall extend this idea to effectful categories in Section 4.
3 Resourceful traces and free effectful categories
In traces, actions are merely atomic names, equipped with a set of devices. In this section, we enrich the language of traces by allowing actions to additionally have input and output types, which we think of as resources that may be shared between actions. Actions therefore become morphisms, with a designated source and target.
In Section 3.1, we introduce the resourceful analogue of the distribution of a set of actions, which we call an effectful signature. In an effectful signature, in addition to a set of devices, every action is equipped with input and output types of resources. In Section 3.3, we show that just as a distribution generates a free partially commutative monoid, effectful signatures generate free effectful categories [23], also known as generalized Freyd categories [10, 21].
3.1 Effectful signatures
Effectful signatures refine distributions: not only by equipping actions with input and output types, but additionally by designating some central or pure actions, with only the impure actions being potentially able to interfere. In programming language theory, this is the division between values and computations [19, 15].
One reason for this can be seen already at the level of trace monoids. Morphisms of trace monoids are, a priori, simply morphisms of monoids, but these need not preserve centrality of actions. That is, if an action commutes with all actions in a trace monoid (i.e., is central in ), then its image under a monoid homomorphism need not commute with all actions of . Thus, certain actions that we might consider to be pure might change their role under a translation of systems. However, restricting the notion of morphism to require preservation of centrality is too strong, since it is possible for computations to be incidentally central: an example may be found in Staton and Levy [24, §5.2].
To overcome this, we explicitly designate which actions we want to consider as pure, and ask that centrality of just these actions is preserved. The chosen set of pure actions is specified by a monoidal signature:
Definition 6.
A monoidal signature consists of a set of objects, ; a set of arrows, ; and a pair of functions assigning source and target lists of objects to each arrow. We can equivalently present a monoidal signature by a set of objects , and sets of arrows for each pair of lists of objects: we shall find both perspectives useful.
We can picture a monoidal signature as on the left of Figure 5, where boxes depict the arrows, and their associated strings designate the sources and targets. We use solid strings for the objects of a monoidal signature.
Definition 7.
A morphism of monoidal signatures comprises two functions and commuting with and , that is, .
Equivalently, a morphism is specified by a function on objects, and functions
It is easy to check that morphisms of monoidal signatures compose, the composite given by composing their underlying actions on arrows and objects, and that we have identities. Denote by the category of monoidal signatures and their morphisms.
The set of morphisms that may be equipped with devices, specifying dependencies between morphisms, is given by a device signature, which is simply a monoidal signature together with extra data associating a set of devices to each morphism:
Definition 8.
A device signature comprises
-
a monoidal signature ,
-
a set of devices, and
-
a function assigning each arrow in to a subset of the devices. We shall simply write when the device signature is clear from context.
When a generator has a finite subset of devices, we can depict a device signature as on the right of Figure 5. Patterned strings denote devices (with arbitrary order of appearance). In contrast to resource strings, device strings must thread through the process: this enforces a definite ordering of dependent processes.
Example 9.
A device signature in which the underlying monoidal signature has an empty set of objects and set of arrows is precisely a distribution of in the sense of Definition 3, although we allow the set of devices to be infinite. In practice, a finite set of devices often suffices. For example, if the device signature has a finite number of arrows, then an infinite number of devices can be shown to be redundant.
Definition 10.
Morphisms and in a device signature are said to be orthogonal, denoted just when they share no devices, . Note that any with no devices is orthogonal to every . We write when is clear from context, and when and are not orthogonal.
A morphism of device signatures must preserve orthogonality, that is
Definition 11.
A morphism of device signatures, , comprises
-
a morphism of underlying monoidal signatures, ,
-
such that for all arrows , if then .
Composition of these morphisms is given by composition of their underlying morphisms of monoidal signatures. It is easily checked that preservation of orthogonality is satisfied by a composite, and so device signatures and their morphisms form a category .
We now have the ingredients required to define effectful signatures.
Definition 12.
An effectful signature comprises
-
a monoidal signature ,
-
a device signature over the same set of objects as ,
-
an identity-on-objects morphism of monoidal signatures ,
-
such that for all arrows in .
We usually think of in terms of its image in , and thus when we speak of a morphism in an effectful signature, we are referring to the arrows of the device signature .
Example 13.
In the effectful signature in Figure 1, the monoidal signature comprises solely the “document” generator, while the device signature includes all three generators, with the morphism of monoidal signatures simply including the “document” generator.
Definition 14.
A morphism of effectful signatures comprises
-
a morphism of monoidal signatures , and
-
a morphism of device signatures ,
-
such that the square of morphisms of monoidal signatures commutes, .
Since both and are categories, it follows easily that
Proposition 15.
Effectful signatures and their morphisms form a category .
Note that effectful signatures generalize the effectful polygraphs of Sobociński and the third author [23], precisely by allowing each action to have a different set of devices, rather than all actions having a single, global device. The construction of effectful categories in the next section also refines that from effectful polygraphs [23], in that it builds in extra independence equations between processes.
3.2 Effectful categories
Effectful signatures generate effectful categories. An effectful category comprises a monoidal category , a premonoidal category , and an identity-on-objects premonoidal functor . In this paper, we work with strict versions of these notions, since not only are the free such structures strict, but coherence theorems exist which state that any (pre)monoidal category is equivalent to a strict one [20].
Just as with effectful signatures, the idea is that is a category of pure actions (generated by a monoidal signature), is a category of effectful actions (generated by a device signature), and the functor is thought of as an inclusion of into . Let us build up to their definition.
Definition 16.
A strict monoidal category is a category equipped with
-
a functor , called the monoidal product,
-
a distinguished object , called the monoidal unit,
-
such that and ,
-
and such that the following equations hold for all morphisms :
Premonoidal categories refine monoidal categories by only requiring the monoidal product to be functorial separately in each variable: in particular, there is no operation combining arbitrary morphisms in parallel.
Definition 17.
A strict premonoidal category is a category, , equipped with functors (the “left-whiskering” by A) and (the “right-whiskering” by A), for every object of , and a distinguished object (the “monoidal unit”), such that,
-
, allowing us to denote this object as ,
-
and ,
-
and such that the following equations hold, stating coherence of left- and right-whiskering with each other and with the monoid structure
Note that every monoidal category is a premonoidal category in which partial applications of the monoidal product define the left- and right- whiskerings. The key equations that hold for every pair of morphisms in a monoidal category, but not generally in a given premonoidal category, are those expressing interchange (i.e., commutation) of morphisms:
Definition 18.
For morphisms and in a premonoidal category ,
-
we write in case ,
-
we say that and interchange in case and ,
-
we say that and interfere, written , in case they do not interchange,
-
we say that is central in case it interchanges with every morphism of .
Graphically, interchange of morphisms is precisely the sliding of morphisms past one another, as discussed for example in Figure 3.
Definition 19.
Let and be strict premonoidal categories. A strict premonoidal functor is a functor that
-
maps objects as a monoid homomorphism, and ,
-
and preserves whiskerings, and .
When and are moreover strict monoidal categories, we call this a strict monoidal functor.
Strict monoidal categories and strict premonoidal categories, along with strict functors form categories, and . Finally, we reach the definition of effectful categories:
Definition 20.
A (strict) effectful category comprises
-
a strict monoidal category ,
-
a strict premonoidal category with the same objects as , ,
-
an identity-on-objects strict premonoidal functor ,
-
such that the image of is central.
Definition 21.
A morphism of (strict) effectful categories, , comprises a strict monoidal functor and a strict premonoidal functor such that in (eliding the inclusion of ).
From the fact that and are categories, it follows easily that:
Proposition 22.
Effectful categories and their morphisms form a category .
3.3 Free effectful category over an effectful signature
Our goal now is to define a functor . We will see in the next section that this functor has a right adjoint, and so constructs the free effectful category on an effectful signature. We begin with the free premonoidal category over a device signature.
Definition 23.
For a device signature , we construct a premonoidal category on as follows. The underlying category has,
-
set of objects , the free monoid on , whose elements are lists. We shall denote by the concatenation of lists.
-
set of morphisms , where is the set inductively defined by rules for identities, the whiskering of generating arrows, and composition,
-
and is the least congruence for generated by
whenever these are well typed, along with equations allowing (whiskerings of) orthogonal generating arrows to interchange, i.e. for every pair, and , of arrows in that are orthogonal, , and each triple of objects in ,
It is immediate that this data forms a category. For the premonoidal structure, we define to be the empty list, left and right whiskerings act on objects by list concatenation (denoted ), and their action on morphisms is defined inductively by
It is easily verified that these mappings are well-defined, functorial, and satisfy the required coherence equations of Definition 17.
The morphisms of are resourceful traces over , and can be depicted intuitively as “string diagrams” (from an input boundary to an output boundary), built by combining whiskered generators of via the operations of premonoidal categories. Generators correspond to boxes as in Figure 5, identity morphisms correspond to strings, composition is given by joining resource strings and any matching device strings, leading to a morphism with the union of the two sets of devices, and whiskering by juxtaposing strings with boxes. Whiskering by the empty list is simply depicted by drawing no whiskering string. We illustrate this in Figure 6. The requirement that every device string appear at most once in every vertical slice through the diagram, as in Section 2, is enforced by the fact that we have no operation for combining morphisms in parallel. The following lemma shows that interchange of generating arrows extends to the morphisms of via the device assignment described above.
Definition 24.
Device assignment extends inductively from a device signature to a well-defined function on the morphisms of (Definition 23) as follows
Lemma 25.
Let be two morphisms of . If and are orthogonal, , then and .
Proof.
See Appendix A.
Example 26.
As noted in Example 9, a device signature with empty set of objects is precisely a distribution of an alphabet. In this case, has a single object, the empty list, and hence is a monoid (with trivial whiskerings). This monoid is isomorphic to the trace monoid over the corresponding distribution.
Lemma 27.
Each morphism of device signatures, , induces a strict premonoidal functor, , defined as follows. The action on objects is the lifting of to lists, . The action on morphisms is given by
and this action is well-defined.
Proof.
Well-definedness follows from the fact and are categories and that preserves orthogonality by definition. The action on objects is a morphism of monoids, so to see that is a strict premonoidal functor, it remains to check that it preserves whiskerings: this follows by a straightforward induction on .
It is clear that the mapping preserves composition and identities, and thus
Proposition 28.
The assignments of Definition 23 and Lemma 27 define a functor .
To define the free effectful category over an effectful signature, we simply combine the construction of the free monoidal category on a monoidal signature (Construction 48) with the construction of the free premonoidal category on a device signature (Definition 23), as follows.
Definition 29.
Let be an effectful signature. This generates the following effectful category , which Proposition 30 checks is well-defined.
-
The monoidal category is the free monoidal category on the monoidal signature ,
-
the premonoidal category is the free premonoidal category on the device signature ,
-
is taken to be identity-on-objects, and is defined by structural induction on its arguments, following Construction 48. The interesting case is, for , ,
For this equality to hold, we must have that and are orthogonal for all and in , since then we can conclude from Lemma 25 that they interchange. It suffices to show that has no devices for all in , which follows by structural induction (c.f. Construction 48).
Proposition 30.
Definition 29 has the structure of an effectful category.
Proof.
By the definitions of device signature, free monoidal category and free premonoidal category, we have that . We must check that is a strict premonoidal functor with central image. is identity-on-objects and so a monoid homomorphism. Furthermore it preserves left-whiskering since
using the equations of strict premonoidal categories, and preserves right-whiskerings in a similar fashion. It follows from Lemma 25 that the image of is central since the definition of device signature asks that for all , and so by Definition 24, for all .
Proposition 31.
Let be a morphism of effectful signatures. This generates a morphism of effectful categories defined as follows:
-
the underlying strict monoidal functor is ,
-
the underlying strict premonoidal functor is that given by Lemma 27,
-
and the required square commutes by functoriality.
It is easily checked that this assignment on morphisms preserves identities and composition.
Proposition 32.
The assignments of Proposition 30 and Proposition 31 extend to a functor .
4 Interference: from effectful categories to effectful signatures
In this section we show that every effectful category has an underlying effectful signature, given by a generalization of the clique construction of Proposition 5. Rather than taking the elements of a monoid as the vertices, we take the vertices to be the morphisms of a premonoidal category.
Definition 33.
The interference graph of a premonoidal category , denoted by , is the graph whose vertices are the arrows of , with an edge if and only if and interfere in (denoted ): that is, they do not interchange.
Definition 34.
Let be a strict premonoidal category. We define its underlying device signature as follows:
-
For the underlying monoidal signature we take , and for every pair of lists and of objects of , we take a set of arrows
That is, there is an arrow in for every morphism in . Since each and is an object of , whose set of objects already forms a monoid with operation denoted , a morphism is included both in and . The complete set of arrows is the coproduct of all such sets, over every pair of lists of objects in .
-
The set of devices, , is given by the set of non-trivial maximal cliques in the interference graph, . A clique is trivial just when it is a singleton. A clique is maximal just in case any morphism that interferes with every other morphism of the clique is in the clique. The device assignment, , assigns an arrow to the subset of non-trivial maximal cliques to which it belongs.
Lemma 35.
For a strict premonoidal functor, we have that implies (interchange is preserved), and that implies (interference is reflected).
Proof.
Immediate.
Proposition 36.
For every strict premonoidal functor , there is a morphism of device signatures given by the action of .
Proof.
That this defines a morphism of the underlying monoidal signatures follows from the fact that a functor preserves sources and targets. We show that orthogonality of morphisms is preserved by proving the contrapositive, . Suppose that for some . Then and , and we have . Then Lemma 35 gives , which means for some , in which case , that is, , which is what we wanted to show.
Lemma 37.
The assignments of Definitions 34 and 36 extend to a functor .
We can now define a functor . We begin with the action on effectful categories.
Proposition 38.
Let be an effectful category. Then is the effectful signature with
-
monoidal signature , the underlying monoidal signature of (Definition 50),
-
device signature ,
-
morphism of monoidal signatures defined to be identity-on-objects, and on arrows.
Proof.
To see that this is well-defined, first note that by definition, has the same set of objects as . It remains to show that for all arrows in . By definition of , we have . Also, by definition has central image, and so must constitute a trivial clique in .
It follows straightforwardly by combining Definition 50 and Proposition 38, that every morphism of effectful categories has an underlying morphism of effectful signatures, and furthermore that these assignments extend to a functor:
Proposition 39.
Let and be effectful categories and a morphism of effectful categories. Then, there is an underlying morphism of effectful signatures, , where is the underlying morphism of monoidal signatures.
Proposition 40.
The assignments of Propositions 38 and 39 extend to a functor
Finally, we show that our free and forgetful functors form an adjunction. Proofs can be found in Appendix A.
Theorem 41.
The free construction of premonoidal categories over a device signature (Definition 23) is left adjoint to forming the underlying device signature of a premonoidal category (Definition 34). That is,
Corollary 42.
The adjunction of Theorem 41 extends to an adjunction between effectful signatures and effectful categories. That is,
5 Commuting tensor product of free effectful categories
In their abstract investigation of the notion of commutativity, Garner and López Franco deduce the existence of a commuting tensor product of effectful categories [10, §9.4]. In this section, we show how our construction of free effectful categories from effectful signatures gives rise to a simple, concrete construction of this commuting tensor product.
Roughly speaking, given two free effectful categories generated by effectful signatures over the same monoidal signature of chosen pure actions, their commuting tensor product is given by taking the free effectful category over a sort of “disjoint union” of the two underlying effectful signatures. In particular, the set of devices is a disjoint union, and so actions from one graph are forced to interchange with those from the other. However, the set of resources is left unchanged, and so the actions from each graph may share resources when they are composed into resourceful traces, as in Figure 1 (see also Example 44, below).
Construction 43.
Given effectful signatures and over the same monoidal signature , we construct their commuting tensor product as follows. The monoidal signature of pure morphisms is simply . The device signature has,
-
objects ,
-
arrows , i.e., the following pushout of sets,
-
devices ,
-
device assignment the unique map induced by the universal property of the pushout via the assignments and ,
-
is identity-on-objects and on arrows.
Example 44.
A simple example is given by our printer example from Section 1, reproduced in Figure 7 (left), with the chosen monoidal signature of pure actions made explicit: in this case, it comprises the only pure action, namely the “document” generator. The commuting tensor product of this effectful signature with itself is the effectful signature in Figure 7 (right), in which we have two distinct printers.
Our next goal is to show that the free effectful category over a commuting tensor product of effectful signatures is isomorphic to the commuting tensor product of the free effectful categories over those graphs. First, we recall the definition of commuting tensor product of effectful categories given by Garner and López Franco [10, §9.4], see also [6, Proposition 4.6.4]. The definition builds on the auxiliary notion of commuting cospan.
Definition 45 (Commuting cospan).
A cospan of effectful categories
over the same monoidal category , is said to be commuting when, for every in and in , we have , i.e. and interchange in
Definition 46.
Let and be effectful categories over a monoidal category . The commuting tensor product of and , denoted , is defined to be the apex of the initial commuting cospan of effectful categories over . Explicitly, for any other commuting cospan, of effectful categories over , there exists a unique morphism of effectful categories such that:
Theorem 47.
Given effectful signatures and over the same monoidal signature , .
Proof.
It suffices to show that is the apex of the initial commuting cospan of effectful categories over the free monoidal category on . In particular, we will show that:
is an initial commuting cospan, where is the morphism of effectful signatures that is identity on objects and pure generators, and given by the left pushout injection on generators (Construction 43), and similarly for . This cospan is commuting because of the way in which is constructed using the universal property of the pushout given by and . In particular, we have by construction that for any and , . It follows that for any morphisms in and in , from which it follows in turn that the cospan in question is commuting.
To see that it is initial, suppose that we have another commuting cospan of effectful categories over , call it We obtain a function by the universal property of the pushout, where denotes inclusion of generators,
This mapping on generators of the device signatures defines a morphism of effectful signatures , where the fact that and are a commuting cospan ensures that . Using the bijection of hom-sets given by Corollary 42, we obtain a morphism of such that
Any other such morphism, transported back across the adjunction, induces another filler for our pushout diagram, and must therefore be equal to .
6 Conclusion and further work
We have shown how morphisms in free effectful categories can be seen as generalizations of Mazurkiewicz traces, by introducing a new notion of generating data for effectful categories, namely effectful signatures. This point of view also leads to a simple presentation of the commuting tensor product of free effectful categories. In this paper, we have not given a treatment of presentations involving equations but this would be a natural next step, and would allow us to express richer descriptions of concurrent systems, such as commuting tensor products of global state [23].
Prior work has generalized Mazurkiewicz traces along different lines, such as to contextual traces [2] or semicommutations [3], so these might be investigated in light of this paper. For example, semicommutations generalize Mazurkiewicz traces by allowing commutations to be directed, and this may correspond to a notion of order-enriched effectful category.
Since effectful categories are equivalent to strong promonads [22, 10], recasting our concepts from that point of view would bring our work adjacent to the literature on combining monads [12], whose relation to the commuting tensor product should be investigated. This may also suggest appropriate generalizations. For example, we might be able to see device information as corresponding to a grading of a strong promonad.
String diagrams bearing some resemblance to resourceful traces have been used informally by Melliès in a treatment of the local state monad [18]. The local state monad arises as a combination of global state monads, linked by a theory of allocation: connections to our commuting tensor product should be investigated. Similarly, Barrett, Heijltjes, and McCusker [1] have made informal use of string diagrams bearing resemblance to resourceful traces, in which devices stand for distinct effects in an effectful -calculus. These instances suggest that it would be worthwhile to formalize the diagrammatic point of view. Sobociński and the third author [23] proved that string diagrams over effectful signatures with a single global device do indeed give free premonoidal categories. However, since it is possible to construct effectful categories whose interference graphs contain an infinite number of maximal cliques, making the string-diagrammatic construction formal in our setting would require restricting to an appropriate subcategory of finitary effectful signatures. With this restriction, we see no reason why string diagrams for effectful categories should not extend to our setting.
References
- [1] Chris Barrett, Willem Heijltjes, and Guy McCusker. The Functional Machine Calculus II: Semantics. In Bartek Klin and Elaine Pimentel, editors, 31st EACSL Annual Conference on Computer Science Logic (CSL 2023), volume 252 of Leibniz International Proceedings in Informatics (LIPIcs), pages 10:1–10:18, Dagstuhl, Germany, 2023. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.CSL.2023.10.
- [2] Christian Choffrut and Robert Mercas. Contextual partial commutations. Discrete Mathematics & Theoretical Computer Science, 12, 2010.
- [3] Mireille Clerbout and Michel Latteux. Semi-commutations. Information and computation, 73(1):59–74, 1987. doi:10.1016/0890-5401(87)90040-X.
- [4] Bob Coecke, Tobias Fritz, and Robert W Spekkens. A mathematical theory of resources. Information and Computation, 250:59–86, 2016. doi:10.1016/J.IC.2016.02.008.
- [5] Volker Diekert and Grzegorz Rozenberg. The Book of Traces. World Scientific, 1995. doi:10.1142/2563.
- [6] Matthew Earnshaw. Languages of String Diagrams. PhD thesis, Tallinn University of Technology, 2025. doi:10.23658/TALTECH.2/2025.
- [7] Matthew Earnshaw and Pawel Sobociński. String Diagrammatic Trace Theory. In MFCS, volume 272, 2023. doi:10.4230/LIPIcs.MFCS.2023.43.
- [8] Dominique Foata and Pierre Cartier. Problèmes combinatoires de commutation et réarrangements. Lecture notes in mathematics, 85, 1969.
- [9] P. Freyd. Algebra valued functors in general and tensor products in particular. Colloquium Mathematicum, 14(1):89–106, 1966. doi:10.4064/cm-14-1-89-106.
- [10] Richard Garner and Ignacio López Franco. Commutativity. Journal of Pure and Applied Algebra, 220(5):1707–1751, 2016.
- [11] Philip Hackney and Marcy Robertson. On the category of props. Applied Categorical Structures, 23(4):543–573, August 2015. doi:10.1007/s10485-014-9369-4.
- [12] Martin Hyland, Gordon Plotkin, and John Power. Combining effects: Sum and tensor. Theoretical computer science, 357(1-3):70–99, 2006. doi:10.1016/J.TCS.2006.03.013.
- [13] Alan Jeffrey. Premonoidal categories and a graphical view of programs. Preprint, 1997.
- [14] André Joyal and Ross Street. The geometry of tensor calculus, I. Advances in Mathematics, 88(1):55–112, 1991. doi:10.1016/0001-8708(91)90003-P.
- [15] Paul Blain Levy, John Power, and Hayo Thielecke. Modelling environments in call-by-value programming languages. Information and Computation, 185(2):182–210, 2003. doi:10.1016/S0890-5401(03)00088-9.
- [16] Antoni Mazurkiewicz. Concurrent program schemes and their interpretations. DAIMI Report Series, 6(78), July 1977. doi:10.7146/dpb.v6i78.7691.
- [17] Antoni Mazurkiewicz. Basic notions of trace theory. In J. W. de Bakker, W. P. de Roever, and G. Rozenberg, editors, Linear Time, Branching Time and Partial Order in Logics and Models for Concurrency, pages 285–363, Berlin, Heidelberg, 2005. Springer Berlin Heidelberg.
- [18] Paul-André Melliès. Local states in string diagrams. In Rewriting and Typed Lambda Calculi: Joint International Conference, pages 334–348. Springer, 2014. doi:10.1007/978-3-319-08918-8_23.
- [19] John Power. Premonoidal categories as categories with algebraic structure. Theoretical Computer Science, 278(1):303–321, 2002. Mathematical Foundations of Programming Semantics 1996. doi:10.1016/S0304-3975(00)00340-6.
- [20] John Power and Edmund Robinson. Premonoidal categories and notions of computation. Math. Struct. Comput. Sci., 7(5):453–468, 1997. doi:10.1017/S0960129597002375.
- [21] John Power and Hayo Thielecke. Closed freyd- and -categories. In Jirí Wiedermann, Peter van Emde Boas, and Mogens Nielsen, editors, Automata, Languages and Programming, pages 625–634, Berlin, Heidelberg, 1999. Springer Berlin Heidelberg.
- [22] Mario Román. Promonads and string diagrams for effectful categories. In Applied Category Theory, volume 380 of Electronic Proceedings in Theoretical Computer Science, pages 344–361. Open Publishing Association, 2023. doi:10.4204/EPTCS.380.20.
- [23] Mario Román and Paweł Sobociński. String diagrams for premonoidal categories. Logical Methods in Computer Science, Volume 21, Issue 2, April 2025. doi:10.46298/lmcs-21(2:9)2025.
- [24] Sam Staton and Paul Blain Levy. Universal properties of impure programming languages. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, pages 179–192, New York, NY, USA, 2013. Association for Computing Machinery. doi:10.1145/2429069.2429091.
- [25] Wieslaw Zielonka. Notes on finite asynchronous automata. RAIRO - Theoretical Informatics and Applications - Informatique Théorique et Applications, 21(2):99–135, 1987. doi:10.1051/ITA/1987210200991.
Appendix A Omitted details
Lemma 25. [Restated, see original statement.]
Let be two morphisms of . If and are orthogonal, , then and .
Proof.
By structural induction on and . The cases where one of and are an identity or both morphisms are whiskered generators are straightforward by the equations of premonoidal categories, or by the imposed interchange equations for whiskered generators. Let , then by assumption we obtain , and by hypothesis and . Say . We need to show . By the functoriality of and associativity of , the left-hand side is equal to . Using the two induction hypotheses, this becomes which is finally equal to the right-hand side by the functoriality of . The argument for is symmetric, as well as the case when is a composite.
The following tautological construction of the free strict monoidal category on a monoidal signature is standard (see e.g. [11, Appendix A]).
Construction 48 (Free strict monoidal category).
For a monoidal signature , we construct a strict monoidal category on as follows. The underlying category of has:
-
set of objects , the free monoid on ,
-
set of morphisms constructed according to the following rules:
subject to the equations,
-
composition and identities are given by the corresponding inference rules.
The first two equations ensure that this data forms a category and the remaining equations ensure that the evident monoidal product is functorial.
Similarly, the free strict monoidal functor on a morphism of monoidal signatures is given by the evident inductive extension.
Proposition 49.
The construction of defines a functor .
Definition 50.
The underlying monoidal signature of a monoidal category is defined to have set of objects the set of objects of , and set of arrows,
with the obvious assignments of sources and targets of arrows. For a strict monoidal functor , its underlying morphism of monoidal signatures is given by the action of on objects and arrows.
Proposition 51.
Definition 50 defines a functor .
Proposition 52.
There is an adjunction .
Proof.
A left adjoint to is constructed via string diagrams by Joyal and Street [14].
Theorem 41. [Restated, see original statement.]
The free construction of premonoidal categories over a device signature (Definition 23) is left adjoint to forming the underlying device signature of a premonoidal category (Definition 34). That is,
Proof.
We begin constructing the unit, . A component acts on objects by inclusion as a singleton list, which we again denote simply as ,
On arrows, recall that by definition,
where is list concatenation. Let be elements of , and a morphism in . Let us denote the coproduct injection into the component of by . Then we define,
where denotes the primitive left-right whiskering of by the empty list, as in Definition 23. It is easy to check that this is a morphism of the underlying monoidal signatures. For the preservation of orthogonality, if then by definition and in . Therefore, and are not connected in the interference graph of . Now, two maps in will be orthogonal as long as they do not have a device in common, but were they to share a device, they would belong to a common maximal clique and thus be connected. This is a contradiction, so they must be orthogonal, .
It remains to show that is natural. We must show that for any in we have:
We proceed by showing that the two above composite device signature morphisms have equal object mappings, and equal arrow mappings. First note by definition, so we have,
for all , as required. For the arrows, recall that by Lemma 27, , which gives:
establishing the naturality of .
We now turn our attention to the counit , where has action on objects , where is the monoidal operation on objects that exists in a premonoidal category. The action on morphisms is defined by structural recursion as follows:
where denotes a coproduct injection. It is straightforward to check that this is well-defined, is a monoid morphism on objects, and preserves whiskerings. It remains to show that is natural. We must show that for any in we have:
We proceed by showing that the two composite functors have equal object mappings and equal arrow mappings. For the mapping on objects we have,
For the arrow mappings, we proceed by induction on . The interesting case is when , for an arrow of ,
The other cases follow directly from the inductive hypothesis together with the fact that each composite is a strict premonoidal functor. It follows that is natural.
Finally, to obtain an adjunction we must show the triangle identities:
For the first triangle, we have:
from which we may conclude that the triangle in question commutes. For the second triangle, we proceed by induction on . The interesting case is when is a whiskered generating arrow, ,
where for , we denote by the list . The case where is follows from the (easily checked) fact that the claim holds for the object mapping, and the case of composition follows directly from the inductive hypothesis together with the fact that the composite is a strict premonoidal functor.
Corollary 42. [Restated, see original statement.]
The adjunction of Theorem 41 extends to an adjunction between effectful signatures and effectful categories. That is,
Proof.
We shall make use of the adjunction of Theorem 41 and the adjunction between monoidal signatures and monoidal categories ([14]). Let be an effectful signature. We first define the components of the unit, namely a morphism of effectful signatures
by letting the morphism between the monoidal signatures be the unit of the adjunction between monoidal signatures and monoidal categories, , and the morphism between the device signatures be given by the unit of the adjunction constructed in Theorem 41. It is straightforward to verify that the required square commutes.
Let be an effectful category. For the components of the counit, we define a morphism of effectful categories,
by letting the component between the monoidal categories be given by the counit of the adjunction between monoidal signatures and monoidal categories, , and the morphism between premonoidal categories be given by the counit of the adjunction constructed in Theorem 41.
It remains to show that the unit and counit satisfy the triangle identities, which follows simply from the triangle identities of the two adjunctions involved.
