<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Distributing Commas, and the Monad of Anchored Spans</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Michael Johnson Departments of Mathematics and Computing, Macquarie University Robert Rosebrugh Department of Mathematics and Computer Science Mount Allison University</institution>
        </aff>
      </contrib-group>
      <fpage>31</fpage>
      <lpage>42</lpage>
      <abstract>
        <p>Spans are pairs of arrows with a common domain. Despite their symmetry, spans are frequently viewed as oriented transitions from one of the codomains to the other codomain. The transition along an oriented span might be thought of as transitioning backwards along the first arrow (sometimes called 'leftwards') and then, having reached the common domain, forwards along the second arrow (sometimes called 'rightwards'). Rightwards transitions and their compositions are wellunderstood. Similarly, leftwards transitions and their compositions can be studied in detail. And then, with a little hand-waving, a span is 'just' the composite of two well-understood transitions - the first leftwards, and the second rightwards. In this paper we note that careful treatment of the sources, targets and compositions of leftwards transitions can be usefully captured as a monad L built using a comma category construction. Similarly the sources, targets and compositions of rightwards transitions form a monad R, also built using a comma category construction. Our main result is the development of a distributive law, in the sense of Beck [3] but only up to isomorphism, distributing L over R. Such a distributive law makes RL a monad, the monad of anchored spans, thus removing the hand-waving referred to above, and establishing a precise calculus for span-based transitions. As an illustration of the applicability of this analysis we use the new monad RL to recast and strengthen a result in the study of databases and the use of lenses for view updates.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>1.1</p>
    </sec>
    <sec id="sec-2">
      <title>Introduction</title>
      <sec id="sec-2-1">
        <title>Set-based bidirectional transformations</title>
        <p>There is an important distinction among extant bidirectional transformations between those that are “set-based”
and those that are “category-based” (the latter are sometimes also called “delta-based”). This paper analyses
the origins of that distinction and lays the mathematical foundations for a calculus integrating both points of
view along with an often implicit point of view in which deltas sometimes have a “preferred” direction.</p>
        <p>So, what are these set-based and category-based transformations, and how did the distinction arise?</p>
        <p>To quote from the Call for Papers: “Bidirectional transformations (Bx) are a mechanism for maintaining the
consistency of at least two related sources of information. Such sources can be relational databases, software
models and code, or any other document following standard or ad-hoc formats.”</p>
        <p>A fundamental question in bidirectional transformations is: What are the state spaces of the sources among
which consistency needs to be maintained? After all, consistency only needs to be worked on when one source
changes state, so a careful analysis of permissible state changes is important.</p>
        <p>This analysis will be important whatever the nature of the sources, but for ease of explication we will focus
at first on an example. Let us consider relational databases. Recall that state spaces of systems are most often
represented by graphs whose nodes are states and whose arrows represent transitions among the states.</p>
        <p>Consider the state space of a relational database. Nodes in the state space, states, are just snapshots of the
database at a moment in time — all of the data, stored in the database, in its structured form, at that moment.</p>
        <p>Typically, with a database, one can transition (update the database) from any snapshot to any other. So, the
state space could be all possible snapshots with an arrow between every pair of snapshots. (This kind of state
space is sometimes called a “chaotic” or “co-discrete” category. A co-discrete category is a category with exactly
one arrow between each ordered pair of objects.)</p>
        <p>This kind of state-space, a co-discrete state-space, is a perfectly reasonable analysis of database updating. It
comes naturally from focusing on the states, and from noticing that there is always an update that will lead from
any state S to any other state S0. After all, when one can transition between any two states, why keep track
of arrows that tell you that you can do that? All that one needs to know is what the new state S0 is. And, no
matter what the current state S might be, the database can transition to that new state S0.</p>
        <p>So, it is natural to do away with the arrows, consider simply the set of states, and plan one’s Bx assuming
that any state S might be changed to any other state S0.</p>
        <p>This is the foundation of set-based bidirectional transformations.</p>
        <p>Important, pioneering work on set-based bidirectional transformations was carried out in this community by
Hoffmann, Pierce et al, and by Stevens et al, among others.
1.2</p>
      </sec>
      <sec id="sec-2-2">
        <title>Category-based bidirectional transformations</title>
        <p>Other workers chose to analyse the state spaces differently.</p>
        <p>
          Pioneering work by Diskin [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ] et al noted that while the states are vitally important (and on one analysis,
that of the database user, they are all that really matters) one might expect very different side-effects when one
updates from S to S0 in very different ways, and so it might be important to distinguish different updates leading
from S to S0.
        </p>
        <p>For example, S0 might be obtainable from S by inserting a single row in a single table. Let’s call that transition
α. But there are many other ways to transition from S to S0. To take an extreme example, let’s call it β, one
might in a single update delete all of the contents of the database state S, and then insert into the resultant
empty database all of the contents of the database state S0. Both α and β are transitions from S to S0, so if
one wishes to distinguish them, then a set-based, or indeed a co-discrete category based, description of the state
space will not suffice. While the states themselves remain pre-eminently important, the transitions need to be
tracked in detail, along with their compositions (one transition followed by another) and the state space becomes
a category (we assume that the reader is familiar not just with set theory, but also with category theory).</p>
        <p>Incidentally, much of the former controversy surrounding put-put laws arises from the different analyses of
set-based and category-based bidirectional transformations. If a state space does not distinguish α from β then
the result of maintaining consistency with α (a single row insert) has to be the same as the result of maintaining
consistency with β and the latter could, on breaking down the update result in synchronising with the empty
database state, and then synchronising with the update from that state to S0. On that analysis the put-put
law (which says that an update can be synchronized only at the end, or at any intermediate step and then
resynchronized at the end, with the same outcome in either case) is a very strong, probably unreasonably strong,
requirement. Alternatively, if α and β are different updates then the put-put law says nothing a priori about
their synchronizations and is a much less stringent requirement.
1.3</p>
      </sec>
      <sec id="sec-2-3">
        <title>Information-order-based bidirectional transformations</title>
        <p>There is yet another way in which one might analyse the state space of a relational database.</p>
        <p>A basic transition might be inserting one or more new rows in some table(s). So we might consider a
statespace with the same snapshots as before, but with an arrow S / S0 just when S0 is obtained from S by inserting
rows. This is in fact the “information order” — the arrow S / S0 can be thought of as the inclusion of the
snapshot S in the bigger (more information stored) snapshot S0.</p>
        <p>Notice that this state space has arrows corresponding to inserts, and we will below call the inserts “rightwards”
transitions. But those very same arrows correspond to deletes if we transition them “leftwards”, backwards, along
the arrow (one can move from S0 to S by deleting the relevant rows).</p>
        <p>The information order provides yet another potential state space for a relational database, and is
wellunderstood by database theorists. It has the added complication that arrows can be transitioned in both
directions. But it has the advantage of separating out two distinct kinds of transition, the rightwards, insert,
transitions, and leftwards, delete, transitions, and these can be analysed separately.</p>
        <p>It is of great convenience that transitions of the same kind — all leftwards or all rightwards — have very good
properties: For example, an insert followed by another insert is definitely just an insert, and the corresponding
“monotonic” (rightwards) put-put law for a Bx using multiple inserts has never been controversial. Similarly for
multiple leftwards transitions.</p>
        <p>Of course an arbitrary update can involve some mixture of leftwards and rightwards transitions, and the main
technical content of this paper is the development of a detailed calculus for mixed transitions.
1.4</p>
      </sec>
      <sec id="sec-2-4">
        <title>Bx state spaces</title>
        <p>We have seen that there are (at least) three fundamental approaches to state spaces for relational databases.
These approaches apply more generally to various sources for bidirectional transformations.
1. In many systems we can concentrate on the states, assume that we can transition from any state S to any
other state S0, and view the state space either as a set over which we might build a set-based Bx (for example
a well-behaved lens), or equivalently as a co-discrete category (which explicitly says that there is a single
arrow S / S0 for any two states S and S0).
2. Alternatively, we can attempt to distinguish among different ways of updating S / S0, different “deltas”,
and view the state space as a category over which we might build a category-based Bx (for example, a
delta-lens).
3. And very often among the categories of state spaces there is a “preferred direction” for arrows that can
be identified in which case the state space as a category can be simplified by showing only the preferred
direction, with arbitrary transitions recovered as composites of rightwards (normal direction along an arrow)
and leftwards (backwards along an arrow) transitions.</p>
        <p>Naturally, if a particular application lends itself well to set-based analysis then a set-based Bx will suffice.</p>
        <p>Frequently however, knowledge of the deltas, when available, is sufficiently advantageous for us to want to build
a category-based Bx. One advantage of the co-discrete representation of set-based bidirectional transformations
is that set-based results can be derived from category-based results since co-discrete categories are merely a
special case of categories.</p>
        <p>Furthermore, if the application presents a natural “preferred” order of transition then the third approach
might be used. Such information order and related situations are so common that this approach has been used
implicitly for some time. The main goal of this paper is to develop the machinery that mathematically underlies
this approach, and to show how it incorporates the other two approaches so that ordinary category-based, or
indeed, via co-discrete categories, ordinary set-based bidirectional transformations, can be recovered as special
cases.
1.5</p>
      </sec>
      <sec id="sec-2-5">
        <title>Lenses as algebras for monads</title>
        <p>
          In earlier work [
          <xref ref-type="bibr" rid="ref13 ref14 ref9">13, 14, 9</xref>
          ] the authors, sometimes with their colleague Wood, have shown that asymmetric
lenses of various kinds are simply algebras for certain well-understood monads. This gives a strong, unified, and
algebraic treatment of lenses, and brings to bear a wide-range of highly-developed mathematical tools.
        </p>
        <p>The monads involved are all in some sense state space dependent.</p>
        <p>For asymmetric lenses we will call the state spaces of the two systems S and V, and suppose given a Get
function or functor G : S / V.</p>
        <p>In the set-based case the monad, ΔΣ, captures completely the notion that all that is needed for a Put operation
is a given state S ∈ S and a new state V 0 ∈ V with no necessary relationship between GS and V 0.</p>
        <p>In the category-based case the monad (−, 1V ) (which we will rename here as R because it will be used to
model the rightwards transitions), captures completely the notion that a Put operation depends on a given state
S ∈ S and an arrow of the state space V of the form GS / V 0.</p>
        <p>In this paper we will show how to construct analogously a monad L which models the leftwards transitions,
and which has as algebras lenses for the backwards (in database terms, delete) updates. A Put operation for
leftwards transitions depends on a given state S ∈ S and an arrow of the state space V of the form V 0 / GS.
(Notice that the update from GS to V 0 transitions leftwards along the arrow to reach V 0.)</p>
        <p>
          Most importantly in this paper we exhibit a distributive law, in the sense of Beck [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ], which relates R and
L and provides a new monad RL which captures completely the notion that for the general third case a Put
operation should depend on a given state S ∈ S and an arbitrary composition of leftwards and rightwards arrows
starting from GS and ending, after zig-zagging, at some V 0 ∈ V. This is our main technical result.
        </p>
        <p>Algebras for the new monad RL are lenses that synchronise with arbitrary strings of leftwards and rightwards
transitions in V.
1.6</p>
      </sec>
      <sec id="sec-2-6">
        <title>Plan of this paper’s technical content</title>
        <p>
          The paper shows that the category theoretic structure of arrows rightwards from GS can be captured as a
monad R. Similarly, the category theoretic structure of arrows leftwards from GS can be captured as a monad
L. There are some important new technical advantages in this, and some important new implications for the
lens community, but the basic ideas of these two monads are not new (first appearing in the paper of Street [
          <xref ref-type="bibr" rid="ref17">17</xref>
          ]).
        </p>
        <p>Database theorists often work with the information order. But an arbitrary database transition involves
inserts and deletes — a mixing of L and R transitions in the information order. Until now this has been done
with handwaving — the R monad tells us all about inserts, the L monad tells us all about deletes, so we mix
transitions together doing say a delete followed by an insert as a general transition which could be drawn as a
“span” S o S0 / S00 (get from S to S00 by deleting some rows from S to get to S0, and then inserting some
rows into S0 to get to S00). And of course we want to distinguish this from other ways of getting from S to S00,
perhaps S o T / S00 where T may be very different from S0. But we’ve moved from the monads that tell us
everything we need to know about rightwards transitions and their interactions, and leftwards transitions and
their interactions, to a vague idea of mixing such transitions together.</p>
        <p>The main point of the paper is the discovery of a previously unobserved distributive law between L and R
which, like all distributive laws, gives a new monad RL, and this composite monad precisely captures the calculus
of these spans (“calculus” meaning we can calculate with it using routine procedures (various versions of μ and
η below) determining algorithmically how all possible mixings, zigzags, etc, interact, which ones are equivalent
to one another, and so on).</p>
        <p>
          It should perhaps be noted here that the spans in this paper are mathematically the same as, but largely
semantically otherwise unrelated to, the authors’ use of equivalence classes of spans to describe symmetric lenses
of various kinds in [
          <xref ref-type="bibr" rid="ref10 ref11">10, 11</xref>
          ].
        </p>
        <p>The plan of this paper is fairly straightforward. In Section 2 we introduce in detail the two monads R and
L. In Section 3 we develop the distributive law, slightly generalising the work of Beck as it is in fact a
pseudodistributive-law. (Recall that in category theory, when an axiom is weakened by requiring only a coherent
isomorphism rather than an equality, the resulting notion is given the prefix “pseudo-”. The coherency of the
isomorphisms involved can be daunting, but in this paper the isomorphisms arise from universal properties and
thus coherency is automatic and we will say no more about it.) In addition in Section 3 we display explicitly
the basic operations of the new monad RL. In Section 4 we study the algebras for such monads, noting that
these algebras are (generalised) lenses. And how useful might all this be? Well, Proposition 3 in Section 4 is an
example of a strong new result that couldn’t even be stated without the new monad RL.</p>
        <p>We hope that having these things in mind might be some help in seeing through the technical details in the
mathematics that follows.
1.7</p>
      </sec>
      <sec id="sec-2-7">
        <title>Summarising the introduction</title>
        <p>State spaces with reversible transitions have been the source of a number of confusions. The fact that every state
is accessible from every other state in the same connected component, has sometimes led to researchers ignoring
transitions (the set-based state spaces referred to above). Conversely, if instead of ignoring transitions all the
transitions are explicitly included in the state space, then in many applications we are failing to distinguish two
different types of transition, the “rightwards” and the “leftwards”. The resulting plethora of transitions of mixed
types can seriously complicate any analysis.</p>
        <p>With the two monads L and R, state spaces with reversible transitions can be managed effectively. Rather
than constructing state spaces in which transitions come in pairs S / S0 and S0 / S, we include only one of
each pair (there is usually a “preferred” direction which can be the one included). Then the monad R is used for
analyses and constructions using the categorical structure of the preferred transitions. Similarly the monad L
can be used for analyses and constructions using the reverse transitions. And arbitrary composites of transitions
can be broken down into “zig-zags” of L and R transitions, and in many cases into spans, L transitions followed
by R transitions.</p>
        <p>However, at this point we have come to the “hand-waving”. What does it really mean mathematically to
deal with zig-zags of L and R transitions? What does it mean to deal with an L transition followed by an R
transition? And what is the calculus of mixed L and R transitions?</p>
        <p>
          The main point of this paper is to show how under a modest hypothesis (the existence of pullbacks in the state
space category V) there is, up to isomorphism, a distributive law [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ] between the two comma category monads R
and L. In the presence of such a distributive law, the composite RL becomes a monad — the monad of anchored
spans. The monad of anchored spans, including its relationship to L and R and the calculus it generates, answers
all the questions in the preceding paragraph in a precise way. It eliminates the “hand-waving” and replaces it
with a proper mathematical treatment of the interactions of R and L.
2
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Two comma category monads</title>
      <p>
        For basic category theoretic notions readers are referred to any of the standard texts, including for example [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]
and [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ]. At present the mathematical parts of this paper have been written succinctly, frequently assuming that
readers have well-developed category theoretic backgrounds.
      </p>
      <p>G /Vo H</p>
      <p>Given two functors with common codomain V, say S T, the comma category (G, H) was introduced
in the thesis of F.W. Lawvere. It has as objects triples (s, t, a) where s is an object of S, t is an object of T, and
a : Gs / Ht is an arrow of V. The arrows of the comma category are, as one would expect, given by an arrow
p : s / s0 of S and an arrow q : t / t0 of T which make the corresponding square in V commute (so for an
arrow (p, q) from (s, t, a) to (s0, t0, a0) we have (Hq)a = a0(Gp) in V) .</p>
      <p>The comma category has evident projections to S and T shown in the figure below.</p>
      <p>We denote the comma category and its projections as follows:</p>
      <p>S w</p>
      <p>LGH</p>
      <p>G
(G, H)</p>
      <p>γ
−→
' V w</p>
      <p>RHG
H
' T</p>
      <p>Where possible we will suppress the subscripts on projections. This is especially desirable if the subscript is
itself an identity functor, and this situation arises frequently since the comma categories we will consider below
will usually have the identity functor on V for one of either G or H.</p>
      <p>The central arrow, γ in the figure, is included because the comma category has not just projections LH and
RG, but also a natural transformation γ : G(LH) / H(RG) (because each object (s, t, a) of (G, H) is in natural
correspondence with an appropriate arrow, a itself, of V). Indeed, the comma category is a kind of 2-categorical
limit — it is universal among spans from S to T with an inscribed natural transformation.</p>
      <p>Explicitly, the universality of the comma category is given by the following. Each functor F : X / (G, H)
corresponds bijectively with a triple (K, L, ϕ) where K : X / S, L : X / T and ϕ : GK / HL (with the
correspondence given by composing each of LH, RG and γ with F ).</p>
      <p>Using this universal propertly we establish some further notation. Write ηG for the functor corresponding to
the triple (1V, G, 1G) : S</p>
      <p>/ (G, 1V) as in</p>
      <sec id="sec-3-1">
        <title>We denote the iterated comma category and projections</title>
        <p>between these two monads and consequently, the composite RL is a monad.
LR
λ / RL</p>
      </sec>
      <sec id="sec-3-2">
        <title>We begin by describing the composites LR and RL.</title>
        <p>If G : S / V then the domain of the functor RG is the comma category (G, 1V) and so has as objects arrows
from V indexed by objects of S of the form Gs a / v. The important projection RG (important because it is
the one which shows us the effect on G of the monad functor R) gives RG(Gs a / v) = v. The projection RG
is also important because when we apply L to RG, L will build on the projected value v. Thus applying the
functor L to RG gives a functor LRG : (1V, RG) / V whose domain has objects of the form Gs
that is cospans (a, b) from Gs to v0. Moreover LR(G)(a, b) = v0.
a / v o b</p>
        <p>v0,
/ V has objects of the form w
/ V whose domain has
c / Gs in V and</p>
        <p>On the other hand, the domain of the functor LG : (1V, G)
LG(w</p>
        <p>c / Gs) = w. Applying the functor R to LG gives a functor RL(G) : (LG, 1V)
objects of the form Gs o c w d / w0, that is spans (c, d) from Gs to w0, and RL(G)(c, d) = w0.</p>
        <p>Now we can define the G’th component of λ. It is the (pseudo-)functor (over V) λG : (1V, RG)
a / v o b
defined at an object Gs v0 of the domain of LRG by taking the pullback in V (and on arrows using
the induced maps). Thus λG(a, b) is a span in V from Gs to v0. The value of the functor LR(G) at (a, b) is v0
and the value of RL(G) at the pullback of the cospan (a, b) is also v0. Thus, RL(G)(λG(a, b)) = LR(G)(a, b) on
the nose.</p>
        <p>To see that λ is natural, suppose that G0 : S0 / V and the functor F : S / S0 defines an arrow from G
to G0 in cat/V, that is G0F = G. We need to show that λG0 LR(F ) = RL(F )λG. Thus the following square of
functors must commute (over V):
/ (LG, 1V)
(1V, RG)
LR(F )
(1V, RG0)
/ (LG, 1V)
/ (LG0, 1V)</p>
        <p>RL(F )
λG
λG0
L
λ
R
λ
where LR(F ) is the functor (1V, R(F )) which defines a morphism LRG
/ LRG0. The square does commute,
up to isomorphism, since the effect of LR(F ) on a cospan Gs
a / v o b
v0 (an object of (1V, RG)) is actually
the same cospan G0F s = Gs</p>
        <p>a / v o b v0 and λG0 computes a pullback span, G0F s o c w d / v0. On the other
hand RL(F )λG applied to the (same) cospan (a, b) computes a pullback span, Gs o c0
applies RL(F ) which likewise leaves the span unchanged, and so isomorphic to (c, d).</p>
        <p>
          Next we consider the distributive law equations [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ]. One equation involving the units is:
w0 d0 / v0, and then
the result is the cospan v
        </p>
        <p>a / Gs o 1
v o 1 v a / Gs. On the other hand ηRL applied to v</p>
        <p>The other unit equation is:</p>
        <p>Gs. Application of λG gives a pullback span which we can choose to be
a / Gs is exactly the same span v o 1 v a / Gs.</p>
        <p>At a functor G, the left hand side of the triangle LηR applies to an object v
a / Gs of the domain of LG and
At a functor G, the left hand side ηLR applies to an object Gs b / v of the domain of RG and the result is the
cospan Gs b / v o 1 v. Application of λG gives a pullback span which we choose to be Gs o 1
Gs b / v. Again,
this is the same as the effect of RηL on Gs
b / v.</p>
        <p>LηR</p>
        <p>ηRL
ηLR</p>
        <p>RηL
LR w
LR w
'/ RL
/' RL
is:</p>
        <p>We consider only one of the equations involving multiplications; the other is similar. The equation we consider</p>
        <p>LRR
LμR</p>
        <p>LR
λR
/ RLR</p>
        <p>Rλ
λ
/ RRL
/ RL
μRL
Again, we look at the equation in the domain and at an object G. A typical object of the domain of LRR(G) is
an extended cospan of the form Gs a / v a0 / v0 o b w. Since μR(a, a0) is simply the composite Gs a0a / v0,
we see that λG(LμR(G))(a, a0, b) is a pullback span Gs o c u d / w of b along a0a. On the other hand, λGR(G)
applied to (a, a0, b) computes a pullback span of b along a0 with result Gs
computes a pullback of c0 along a with result Gs o c00 u00 d00 / u0
giving the span Gs o c00 u00 d00d0 / w which is isomorphic to Gs o c</p>
        <p>The preceding considerations give:
u
d / w.</p>
        <p>Proposition 1 The transformation LR
λ / RL is a (pseudo-)distributive law.</p>
        <p>a / v o c0</p>
        <p>u0 d0 / w. Applying RGλG
d0 / w. Applying μRGLG composes d00 and d0</p>
        <p>
          Using this proposition, and with minor modifications of the work of Beck [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ] to take account of the
isomorphisms in the pseudo-naturality squares and in the equations involving multiplications, we obtain:
Proposition 2 The composite functor RL on cat/V is a monad, the monad of spans, with μRL = μRL · RRμL ·
RλL and ηRL = ηRL · ηL.
        </p>
        <p>It is convenient for later work to introduce some notation and use it to describe the unit and multiplication
for the composed monad RL.</p>
        <p>As noted above, for G : S / V, the domain of RLG is a comma category whose objects are certain spans in
V. Let us denote them</p>
      </sec>
      <sec id="sec-3-3">
        <title>Objects of the domain of LRG are depicted:</title>
      </sec>
      <sec id="sec-3-4">
        <title>An object of the domain of RLRLG is a “zig-zag”:</title>
        <p>a GCs
v
b</p>
        <p>v0
Gs c
w0</p>
        <p>C
w d
a GCs
b
c Cv0
v
v00
d</p>
        <p>v000
The effect of the multiplication for RL on the zig-zag is to first form the span:
1 GCs
Gs
1</p>
        <p>Gs
where w is a pullback of b and c, and then to compose each of the legs using the multiplication μL for the top
leg (which is an instance of LLG), and the multiplication μR for the bottom leg (which is by then an instance
of RRLG).</p>
        <p>The unit for RL simply forms spans of identity arrows, so each object s of S yields a span
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Algebras</title>
      <p>
        To illustrate the benefits of the distributive law and the resultant monad RL we present here a significantly
stronger version, made possible by the use of RL, of a result from [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. That paper was a study of two kinds
of generalised lenses, one for preferred transitions and one for their reverses. It showed that the two lenses are
respectively an R-algebra and an L-algebra and conversely. The main interest was how they should interact via
a “mixed put-put law” called condition (*) below. The new result shows that having two such lenses satisfying
condition (*) is equivalent to having an RL-algebra. In other words, if we can update inserts (R transitions)
and deletes (L transitions) and those updates satisfy condition (*), then we can update spans — arbitrary
compositions of R and L transitions.
      </p>
      <p>We first describe a condition that is essentially the Beck-Chevalley condition for our purposes. (It does not
matter if the reader is not familiar with other instances of the Beck-Chevalley condition.)</p>
      <sec id="sec-4-1">
        <title>Suppose that S</title>
        <p>G / V and that RG
r / G and LG
l / G are R- and L-algebra structures. If Gs
k / w is
an object of (G, 1V), we denote its image under r by r(s, k). Similarly if v i / Gs is an object of (1V, G), we
denote its image under l by l(i, s). Since r and l are arrows in cat/V, G(r(s, k)) = w and G(l(i, s)) = v. We say
that condition (*) is satisfied if
for any object s in S and any pullback (in V)
it is the case that r(l(i, s), j) ∼= l(m, r(s, k)).</p>
        <p>v
i
j
k</p>
        <p>? w
m
G?s
v0
/ G (on objects) by ξ(Gs o i
v
j
/ v0) = r(l(i, s), j). Then ξ
ξ
Proposition 3 If RLG</p>
        <p>/ G is an RL-algebra, then r = ξRηLG and l = ξηRLG define R- and L-algebras,
respectively, that satisfy condition (*). Conversely, suppose RG
r / G and LG
l / G are R- and L-algebra
structures satisfying (*). Define ξ : RLG
determines an RL-algebra structure on G.</p>
        <p>ξ
Proof. Suppose RLG</p>
        <p>/G is an RL-algebra, r and l are defined as in the statement, and the square in condition
(*) is a pullback in V. The definitions of r and l amount, on objects, to r(Gs
and l(v
a / Gs) = ξ(Gs o a</p>
        <p>v 1 / v). For clarity we will sometimes suppress the objects of V, (v, Gs, etc), in
what follows. Then, using the notation from the pullback square and noting that G(ξ( o 1
k / )) = w,
a / v) = ξ(Gs o 1</p>
        <p>Gs
a / v)
l(m, r(s, k))
=
=
=
=
=
=
=
=
l(m, ξ( o 1
ξ(G(ξ( o 1
ξ · RL(ξ)( o 1
ξμG( o 1
o i</p>
        <p>j
ξ( o 1
ξ( o i
r(ξ( o i
r(l(i, s), j)
k / o m
j</p>
        <p>/
/ )
1 / ), j)
k / ))
k / )) o m
k / o m
1 / )</p>
        <p>1 / )
1 / )
1 / )
(where the fourth equality uses the associative law for the RL-algebra ξ) which proves condition (*).</p>
        <p>To check that r and l satisfy the algebra axioms for R and L respectively is routine.</p>
        <p>Conversely, suppose that r and l are R- and L-algebras respectively, and that they satisfy condition (*).
Suppose that ξ is defined on objects as in the statement. Notice that it is straightforward to extend the
definition of ξ to arrows of (the domain of) RLG.</p>
        <p>For the RL-algebra associative law we need to verify that for a “zig-zag” W = Gs o x
y
starting from Gs, say, that ξRLξ(W ) = ξμG(W ). Now RL(ξ) applies ξ to o x / (while carrying along z
and w) giving an object G-over the codomain of z, and ξ applies to this result along with z and w. So using the
definition of ξ above, and writing o a b / for the pullback of y / o z ,
w /
y / o z
ξRL(ξ)(W )</p>
        <p>w / )
=
=
=
=
=
=
=
ξ(G(r(l(x, s), y)) o z
r(l(z, r(l(x, s), y)), w)
r(r(l(a, l(x, s)), b), w)
r(r(l(xa, s), b), w)
r(l(xa, s), wb)
ξ( o xa
ξ(μG(W ))
wb / )
in which the third equation is an application of property (*) and the fourth and fifth equations use the associative
laws of the L-algebra and the R-algebra respectively.</p>
        <p>The RL-algebra identity law for ξ is straightforward noting the definition of ηRL in terms of ηR and ηL.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Related work</title>
      <p>
        In the development of a 2-categorical treatment of the Yoneda Lemma, Ross Street [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ] studied monads equivalent
to L and R, and also a ‘composite’ monad M , not equivalent to the composite studied here. The present authors,
and their colleague Wood, introduced L and R as part of an on-going study of the use of monads in the study
of generalised lenses [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ]. That work, like much of the earlier work of Johnson and Rosebrugh starting from [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ],
studied inserts and deletes in isolation, and depended upon the presumption that these could then be reintegrated
as spans. A theoretical 2-categorical analysis of spans of models was carried out in [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], but it has had little
practical application to date. More recently, a search for a ‘mixed put-put law’ [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] led the authors to the discovery
of the distributive law reported here, and hence to the new composite monad RL and the corresponding calculus
of mixed transitions.
      </p>
      <p>
        In the realm of database state spaces it seems that most authors have taken the set-based state space approach.
We have argued elsewhere [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] that view updating has been limited unnecessarily to constant complement updating
[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] because of the failure to treat transitions as first class citizens. One notable exception is the insightful work
of Hegner [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] which introduced an information order on the set of states. This order corresponds precisely to
choosing to include insert transitions in the state space, but to leave delete transitions out (to be recovered as
reversed insert transitions as described in Section 1 above).
      </p>
      <p>Spans have a wide variety of applications, and so have long been studied category theoretically. Given a
category C with pullbacks there is a bicategory spanC with the same objects as C, with spans of arrows from C
as arrows, and with composition given by pullback, and most treatments take this point of view. Such spans are
oriented, despite their symmetry, by definition, since they are arrows of a bicategory. To the authors’ knowledge,
the monad of anchored spans presented here, including its relationship to the comma category monads L and
R, is entirely new. In addition it has noteworthy and desirable differences from earlier treatments because the
orientation of spans comes from the fibering over V, and because, in the manner of comma categories, spans
appear as objects rather than as arrows.</p>
      <p>
        Meanwhile spans have also had a wide range of applications among researches into bidirectional
transformations. In particular the graph transformation community has used spans for many years and the recent paper
of Orejas et al [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ] makes use of spans of updates in a manner closely related to the current paper. We leave to
future work the exploration of the possible applications of our developments in those areas.
6
      </p>
    </sec>
    <sec id="sec-6">
      <title>Conclusions</title>
      <p>The main findings from this paper are
1. By explicitly working on cat/V the two comma categories (G, 1V) and (1V, G) can be fibred over V and so
sources and targets can be tracked, resulting in monads R and L respectively. Those monads capture the
category theoretic structure of arrows out of images of G and into images of G respectively, and, being built
from those comma categories, they lift arrows of V to objects of RG and LG (fibred over V).
2. There is a pseudo-distributive law between R and L, and so RL is itself a monad, the monad of anchored
spans. Furthermore the tracking of sources and targets, provided by the fibring, orients the spans as spans
from images of G (the “anchoring”). The monad RL captures the category theoretic structure of spans from
images of G, and, being built from iterated comma categories, lifts spans in V from images of G to objects
of RLG (fibred over V).
3. Having an RL-algebra is equivalent to having a pair of algebras (one R and one L) satisfying condition (*).</p>
      <p>The first finding shows that we have found the right context in which to work with comma categories for
a variety of state space based applications. The second finding solves the long standing problem of making
mathematically precise the composition of preferred and reversed transitions (eliminating the “hand-waving”).
The third finding neatly illustrates the extra power available when spans of transitions can be dealt with as
single objects.
7</p>
    </sec>
    <sec id="sec-7">
      <title>Acknowledgements</title>
      <p>The authors are grateful for the support of the Australian Research Council and NSERC Canada, and for
insightful suggestions from anonymous referees.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Bancilhon</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Spyratos</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          (
          <year>1981</year>
          )
          <article-title>Update Semantics of Relational Views</article-title>
          ,
          <source>ACM Trans. Database Syst</source>
          .
          <volume>6</volume>
          ,
          <fpage>557</fpage>
          -
          <lpage>575</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Barr</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Wells</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          (
          <year>1995</year>
          )
          <article-title>Category Theory for Computing Science</article-title>
          . Prentice-Hall.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Beck</surname>
            ,
            <given-names>J. M.</given-names>
          </string-name>
          (
          <year>1969</year>
          )
          <article-title>Distributive Laws</article-title>
          .
          <source>Seminar on Triples and Categorical Homology Theory Lecture Notes in Math. 80</source>
          ,
          <fpage>95</fpage>
          -
          <lpage>112</lpage>
          . Available in Reprints in
          <source>Theory Appl. Categ</source>
          .
          <volume>18</volume>
          (
          <year>2008</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Zinovy</given-names>
            <surname>Diskin</surname>
          </string-name>
          , Yingfei Xiong, Krzysztof
          <string-name>
            <surname>Czarnecki</surname>
          </string-name>
          (
          <year>2011</year>
          ), From State- to
          <source>Delta-Based Bidirectional Model Transformations: the Asymmetric Case, Journal of Object Technology</source>
          <volume>10</volume>
          ,
          <issue>6</issue>
          :
          <fpage>1</fpage>
          -
          <lpage>25</lpage>
          , doi:10.5381/jot.
          <year>2011</year>
          .
          <volume>10</volume>
          .1.a6
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Hegner</surname>
            ,
            <given-names>S. J.</given-names>
          </string-name>
          (
          <year>2004</year>
          )
          <article-title>An Order-Based Theory of Updates for Closed Database Views</article-title>
          . Ann. Math. Artif. Intell.
          <volume>40</volume>
          ,
          <fpage>63</fpage>
          -
          <lpage>125</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2001</year>
          )
          <article-title>View Updatability Based on the Models of a Formal Specification</article-title>
          .
          <source>Proceedings of Formal Methods Europe</source>
          <year>2001</year>
          , Lecture Notes in Comp. Sci.
          <year>2021</year>
          ,
          <fpage>534</fpage>
          -
          <lpage>549</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2007</year>
          )
          <article-title>Fibrations and Universal View Updatability</article-title>
          .
          <source>Theoret. Comput. Sci</source>
          .
          <volume>388</volume>
          ,
          <fpage>109</fpage>
          -
          <lpage>129</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>Lens Put-Put Laws: Monotonic and Mixed</article-title>
          .
          <source>Electronic Communications of the EASST</source>
          ,
          <volume>49</volume>
          ,
          <year>13pp</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2013</year>
          )
          <article-title>Delta Lenses and Fibrations</article-title>
          .
          <source>Electronic Communications of the EASST</source>
          ,
          <volume>57</volume>
          ,
          <year>18pp</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2014</year>
          )
          <article-title>Spans of Lenses</article-title>
          .
          <source>CEUR Proceedings</source>
          ,
          <volume>1133</volume>
          ,
          <fpage>112</fpage>
          -
          <lpage>118</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2015</year>
          )
          <article-title>Spans of Delta Lenses</article-title>
          . To appear
          <source>CEUR Proceedings.</source>
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Wood</surname>
            ,
            <given-names>R. J.</given-names>
          </string-name>
          (
          <year>2002</year>
          )
          <article-title>Entity-Relationship-Attribute Designs and Sketches</article-title>
          .
          <source>Theory Appl. Categ</source>
          .
          <volume>10</volume>
          ,
          <fpage>94</fpage>
          -
          <lpage>112</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Wood</surname>
            ,
            <given-names>R. J.</given-names>
          </string-name>
          (
          <year>2010</year>
          )
          <article-title>Algebras</article-title>
          and
          <string-name>
            <given-names>Update</given-names>
            <surname>Strategies</surname>
          </string-name>
          .
          <source>J.UCS</source>
          <volume>16</volume>
          ,
          <fpage>729</fpage>
          -
          <lpage>748</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>Johnson</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosebrugh</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Wood</surname>
            ,
            <given-names>R. J.</given-names>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>Lenses</article-title>
          , Fibrations, and Universal Translations. Math. Structures in Comp. Sci.
          <volume>22</volume>
          ,
          <fpage>25</fpage>
          -
          <lpage>42</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Orejas</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Boronat</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ehrig</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          , Hermann,
          <string-name>
            <surname>F.</surname>
          </string-name>
          , and Sch¨olzel, H. (
          <year>2013</year>
          )
          <article-title>On Propagation-Based Concurrent Model Synchronization</article-title>
          .
          <source>Electronic Communications of the EASST</source>
          <volume>57</volume>
          ,
          <year>19pp</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>Pierce</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          (
          <year>1991</year>
          )
          <article-title>Basic Category Theory for Computer Scientists</article-title>
          . MIT Press.
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Street</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>1974</year>
          )
          <article-title>Fibrations and Yoneda's Lemma in a 2-category</article-title>
          . Lecture Notes in Math.
          <volume>420</volume>
          ,
          <fpage>104</fpage>
          -
          <lpage>133</lpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>