Compositionality of Rewriting Rules with Conditions

We extend the notion of compositional associative rewriting as recently studied in the rule algebra framework literature to the setting of rewriting rules with conditions. Our methodology is category-theoretical in nature, where the definition of rule composition operations is encoding the non-deterministic sequential concurrent application of rules in Double-Pushout (DPO) and Sesqui-Pushout (SqPO) rewriting with application conditions based upon $\mathcal{M}$-adhesive categories. We uncover an intricate interplay between the category-theoretical concepts of conditions on rules and morphisms, the compositionality and compatibility of certain shift and transport constructions for conditions, and thirdly the property of associativity of the composition of rules without conditions.

denote molecular complexes. As formal methods are expending in the molecular biology community, it is expected that large models describing signaling pathways and self-assembling processes occurring in the cell will be commonplace in a near future.
While the algorithmic aspects of graph rewriting are a well-studied, programming language approaches to modeling with graphs are to date still a comparatively underdeveloped topic. Contrary to classical term rewriting, the notion of a match of a graph rewriting rule and its e ects on a term (a graph) is subject to various de nitions, allowing more of less control over possible rewrites. In addition, the mere nature of the graphs that are being rewritten impacts both the algorithmic design and expressiveness of graph rewriting.
Category theory is a practical toolkit for equipping graphs with well-de ned operational semantics. Double pushout (DPO) rewriting [20] is a popular technique, partly because it relies on a simple de nition, and does not yield side e ects when rules are applied (which makes it amenable to static analysis for instance). However, when a graph rewriting rule entails node deletion, DPO semantics will not allow a match of such rule to trigger if the node that is deleted is connected outside the domain of the match (which would yield a so called "side e ect"). This has limited the practicality of DPO in the context of biological modeling, where more permissive techniques have been employed.
Sesqui-pushout (SqPO) rewriting [19] in particular is the technique that is used to rewrite Kappa graphs [21], one of the main graph rewriting formalisms for biological models.
Quite orthogonal to the issue of de ning rule matches and e ects, having access to a ne-grained control over rule triggering is a key issue when graph rewriting is used as a modeling language. To this aim, graph rewriting rules have been equipped with application conditions [33,27], which can be seen as constraints that need to be checked "on the y" when a rewrite rule is applied.
The main objective of this paper consists in providing a rst-of-its kind compositional variant of DPO and SqPO-type rewriting for rewriting rules with conditions in a very general category-theoretical setting. From a mathematical perspective, while the framework of both types of rewriting developed here relies upon the original de nitions of DPO-rewriting (see e.g. [27]) and of SqPO-rewriting [19], new developments are necessary in order to obtain the desired compositionality properties. For rules without conditions, one of the core technical obstacles has proved to be establishing a compositional associativity property for sequential compositions of rewriting rules, which for the DPO-type case has been achieved in [10,11,7], and for the SqPO-type case in [6]. The latter work also established a compositional concurrency property for SqPO-type rewriting theories that was hitherto unknown. Lifting these results to the settings of rules with application conditions is the core contribution of this work.
The main motivation for our search for compositional rewriting theories is two-fold: in the setting of rewriting without conditions, the notion of rule algebras [7,9,10,6] has been developed as a new mathematical framework to encode the concurrent and combinatorial interactions of rewriting rules, which in particular allows one to develop a principled and novel analysis techniques for stochastic rewriting systems [7,10,8]. Especially the recent results of [8] hint at the intimate interplay of design choices in constructing rewriting systems with regards to their dynamical properties, and at the potential of greatly improving the tractability of the analysis of such systems via judiciously chosen constraints on objects and rewriting rules (such as implemented in the form of rigidity constraints in the Kappa formalism [22]).
Our second main motivation originates from the desire to analyze rewriting systems statically, rather than via simulation-based techniques. While the traditional rewriting theory generally approaches this problem from the viewpoint of so-called derivation traces (i.e. sequences of rule applications to a given input graph), we posit that a viable alternative approach may consist in focusing instead on sequential rule compositions, which in particular when combined with application conditions is anticipated to yield a powerful framework to study the causality of rewriting systems. For certain specialized applications of DPO-type graph rewriting, namely those in the well-established eld of socalled chemical graph rewriting [12,5,1], such types of analyses have already proven very fruitful [4,3,30,2], and we believe that our compositional re nements as described in the present paper can provide a signi cant contribution to future algorithms and re nements thereof.

A motivating example: rewriting simple graphs
Since our main constructions will be somewhat technical, let us start with a simple example in order to provide the readers with some intuitive picture of the concepts. To this end, consider the task of de ning a sound notion of rewriting undirected simple graphs, a type of graphs where at most one undirected edge may exist between any two given vertices of the graph, as opposed to multigraphs. Following the rewriting theory paradigms, one may envision manipulating such graphs by virtue of graph rewriting rules. Intuitively, specifying a rewriting rule amounts to providing the following data: • An Input pattern I, which implement the manipulations of adding a new edge between two vertices (e + ) and deleting an edge between two vertices (e − ). However, in the setting of rewriting of simple graphs, the above tentative de nition for the rewriting of graphs is as of yet incomplete. For example, given the graph below (where the indices are just used to be able to specify the possible matches, but where the graph is in fact considered unlabeled) Therefore, in order to ensure that our transformations via application of rules keep the constraint of graphs to be simple intact, we need to endow the rules with so-called application conditions. While this approach is in fact very wellknown in the rewriting literature, we will demonstrate that via a careful reimplementation of the traditional framework some interesting mathematical structures may be uncovered: rules with conditions are endowed with a structure of composition operation that permits to synthesize sequences of causally sound rewriting steps without reference to a host object, and this operation is demonstrated to be associative. Contact with the traditional techniques of rewriting is then made in the form of a suitable adaption of the so-called concurrency theorem, whereby a sequence of rule application to an initial object may always be equivalently described by the application of a sequential composite of the rules to that object. The most non-trivial part of our results then concerns a certain compositional associativity property, which reasons about structures in triple sequential compositions of rules.
To conclude the example at hand, we will not only be able to express a constraint that the edge creation rule can only be applied to a graph if its input is matched to two vertices that are not already linked, but we will also be able to compute causal information such as e.g. that applying the edge creation rule e + followed by applying the edge deletion rule e − (in a fashion such as to delete the previously created edge) will lead to a rule that, when applied to a given graph, can also only be applied at two not yet linked vertices (transforming the graph identically).

Structure of the paper
As illustrated in Figure 1, in Section 2, we will present the category-theoretical prerequisites for the two variants of our framework for associative rewriting with conditions. In Section 3, the notion of conditions on objects and mor-

Category-theoretical preliminaries
Rewriting in its modern formulations is a concept that heavily relies on speci c types of category-theoretical structures. In this section, we collect all the necessary prerequisites that permit to formulate consistent frameworks of associative rewriting theories with conditions on objects and morphisms, in both the Double-Pushout (DPO) and the Sesqui-Pushout (SqPO) approaches.
While many of the mathematical details of these setups are by now standard in the literature, we will emphasize the specially designed additional prerequisites necessary to guarantee associativity (in the sense of [10]), and thus consequently also the compositionality of concurrent composition of rules with conditions.

M-adhesive categories
We begin by quoting a number of essential de nitions and results from the standard literature, where our main references will be [16,33,27] (see also [39,40] for some more recent works). Let us rst recall the notion of M-adhesive categories, which are the most general mathematical setting currently known that permit to de ne DPO-and SqPO-type rewriting theories, and which generalize adhesive categories [36].
(ii) C has pushouts and pullbacks along M morphisms, i.e. pushouts of spans and pullbacks of cospans where at least one of the two morphisms of the (co-) span is in M exist.
1 Note that the general theory of M-adhesive categories would not require the class M to be a class of monomorphisms, yet this more general setting will not be of interest to the constructions in this paper.
For certain applications, it is also of interest to consider a variant of the de nition called weak M-adhesive categories, which are categories in which all of the above axioms hold except for the M-VK property; the latter is modi ed to the weak M-VK property: (iv)' Pushouts along M-morphisms are weak M-van Kampen (M-VK) squares: given a commutative cube in C as shown in (5), where the bottom square is a pushout along an M-morphism m ∈ M, the back faces are both pullbacks, and then the top face is a pushout if and only if the two front faces are pullbacks.
Note that the decomposition property (ib) follows directly from closure under compositions and stability of M-morphisms under pullbacks.
M-adhesive categories enjoy a number of special properties (some of which referred to in the literature as high-level replacement (HLR) properties) that will be of key importance to our main constructions. We collect the (long) list of such properties in Appendix A.1.
As advocated in particular in the work of Ehrig [16], one of the most optimal compromises for a very general setting in which DPO (and, as we shall see, also SqPO) rewriting theories involving constraints on objects and morphisms may be formulated e ciently is provided by M-adhesive categories with certain additional special properties. A central role in this setup is played by the following concepts: De nition 2 (M-initial object; [16], De. 2.5) An object ∅ of an M-adhesive category C is de ned to be an M-initial object if for each object A ∈ obj(C) there exists a unique monomorphism i A : ∅ → A, which is moreover required to be in M. An Minitial object ∅ is said to be strict if for each object X ∈ obj(C), every morphism X → ∅ must be an isomorphism.

Lemma 1 ([16], Fact 2.6)
If an M-adhesive category possesses an M-initial object ∅ ∈ obj(C), the category has nite coproducts, and moreover the coproduct injections are in M. In particular, the coproduct A + B of two objects A, B ∈ obj(C) is then given as the pushout of the span (A if "A has nitely many M-subobjects"). C is nitary if all its objects are nite. The • (uGraph, M U ), the category of undirected multigraphs [10] and graph homomorphisms, with M U the class of all injective homomorphisms of uGraph and with M U -initial object ∅ U ∈ obj(uGraph) (the empty graph).
• (Graph, M G ), the M-adhesive category of directed multigraphs, with M G the class of all injective graph homomorphisms. This category possesses the empty graph G ∅ as an M G -initial object.
• (Graph T G , M T G ), the category of typed graphs and morphisms thereof (constructed as the slice category Graph T G := Graph \ T G for some xed type graph T G ∈ Graph), with M T G the class of all injective typed graph homomorphisms.
• More generally, the categories of Petri nets and of elementary Petri nets [16,Ex. 2.3 ] are M-adhesive and M-initial for certain classes of M.
All categories in the above list possess an epi-M-factorization, as do their nitary restrictions. For example, in Graph, every graph homomorphism can be factored into the a surjective composed with an injective graph homomorphism. Interestingly, for the well-known non-examples, which are certain categories of (typed or untyped) attributed graphs, these fail to possess an M-initial object and an epi-M-factorization.
There exist a number of functorial constructions that permit to construct nitary M-adhesive categories with the desired properties from known such categories. We refer the reader to [16,Sec. 5] for the precise details.
the morphism d is in M.
While we are not aware of a set of necessary conditions to ensure the above property, we can provide at least a set of su cient conditions that covers many cases of interest in practical applications. for all morphisms f ∈ mor(C), if f ∈ mono(C) and f ∈ epi(C), then f ∈ iso(C)). Then C possesses M-e ective unions.
In particular, since according to [36] (Lem. 4.9) all adhesive categories are balanced, realizations of the above conditions are given by e.g. the adhesive categories Graph of directed and uGraph of undirected multigraphs.

Additional prerequisites for the Sesqui-Pushout (SqPO) framework
Referring to [6] for a more extensive presentation, it su ces here to quote some necessary background materials, and to discuss the general M-adhesive setting.
De nition 6 (Final Pullback Complement (FPC); [19,37]) Given a commutative diagram of the form P is a pullback of (c, d), and (ii) for each collection of morphisms (x, y, z, w) as in (7), where (x, y) is pullback of (c, z) and where a•w = x, there exists a morphism w * with d•w * = z and w * •y = w that is unique (up to isomorphisms).

Summary: full set of necessary assumptions for DPO and SqPO rewriting
Combining all ndings of the previous two sections (together with some insights from the constructions presented in the following sections), the requirements for associative Double-Pushout (DPO) and Sesqui-Pushout (SqPO) rewriting that admit conditions on both objects and morphisms read as follows: Assumption 1 (Associative DPO rewriting with conditions) We assume that C is an M-adhesive category with epi-M-factorization, where M is required to be a class of monomorphisms. We also assume that C is balanced, possesses a strict M-initial object ∅ ∈ obj(C) and M-e ective unions. which however in e ect only rea rms the case of C being an adhesive category. In the general M-adhesive setting, M-stability under FPCs will have to be veri ed at a case-by-case level. Note that the guaranteed existence ofnal pullback complements in the con gurations encountered in SqPO rewriting will drastically simplify the framework, and is in fact necessary to guarantee associativity as discussed in [6].

Conditions on objects and morphisms
The central concepts of the framework of conditions are the following notions of constraints (i.e. conditions over objects), application conditions (i.e. conditions over morphisms) and the associated notions of satis ability. We quote the precise de nitions from [27], and also from [33], where some important clarifying details are given (on the notion of satis ability on objects and morphisms). (i) Trivial condition: for every object P ∈ obj(C), true is a condition over P .

Core definitions
(ii) "Transported" conditions: for every object P ∈ obj(C), for every 2 M-morphism (a : P → Q) ∈ mor(C) and for every condition c Q over Q, ∃(a : P → Q, c Q ) is a condition over P .
(iii) Derived conditions: given conditions c P and {c P i } i∈I (for some index set I) over an object P ∈ obj(C), ¬c P and ∧ i∈I c P i are conditions over P .
The precise meaning of the above de nitions is speci ed via the associated notions of satis ability, which are also de ned inductively. One rst needs to de ne satis ability of conditions on morphisms: (i) Every M-morphism p : P → P (for P, P ∈ obj(C)) satis es the trivial condition true over P .
(ii) Given M-morphisms p : P → P and a : P → Q as well as a condition ∃(a, c Q ) over P , the morphism p is de ned to satisfy the condition ∃(a, c Q ) if and only if 2 It is here that our restriction to M-morphisms in the formulation of conditions reflects our choice of framework, i.e. that of M-satisfiability (for M-morphisms). We refer the interested readers to [33] for the proof that this is in fact the most general framework available when working with M-morphisms in matches and rewriting rules only, i.e. generalizing morphisms in conditions of arbitrary morphisms in this setting does not lead to more expressivity.
there exists an M-morphism q : Q → P such that q • a = p and such that q satis es the condition c Q , (iii) Given a M-morphism p : P → P and an application condition c P over P , p satis es ¬c P if it does not satisfy c P . If {c P i } i∈I (for some indexing set I) is a family of application conditions over P , p satis es ∧ i∈I c P i if it satis es each of the application conditions c P i .
For a morphism p ∈ mor(C), we write p c to denote that p satis es the condition c. Finally, two application conditions c P , c P over some object P ∈ obj(C) are equivalent, denoted c P ≡ c P , if and only if for all M-morphisms p : P → H (for arbitrary H ∈ obj(C) with P as a M-subobject) we nd that p c P ⇔ p c P .
Then for objects, satis ability is de ned as follows [33]: (i) Every object P ∈ obj(C) satis es true.
(ii) Only conditions ∃(a, c C ) with a : ∅ → C an M-initial morphism from the Minitial object ∅ are meaningful to consider in the context of satis ability for objects. Then for such a condition ∃(i C : ∅ → C; c C ), an object P ∈ obj(C) is de ned to satisfy the condition if and only if the initial morphism i P : ∅ → P satis es the condition ∃(i C ; c C ) (in the sense of satis ability as de ned for morphisms): (iii) Given an object P ∈ obj(C) and a condition c P on P , P satis es ¬c P if it does not satisfy c P . If {c P i } i∈I (for some indexing set I) is a family of conditions on P , P satis es ∧ i∈I c P i if it satis es each of the conditions c P i .
For later convenience, we take the convention that the statement "c P is a condition on an object P ∈ obj(C)" shall always imply that c P is of the admissible form.
What renders this set of de nitions somewhat counter-intuitive is that properties over objects of the M-adhesive category C are seemingly freely mixed with properties related to morphisms of the category. It may thus be instructive to the readers to explicitly parse the de nition of conditions on objects as in the following example: Example 2 Given an object P ∈ obj(C), a condition of the form "P contains a M- since by virtue of the de nition of satis ability of conditions on objects, P ∃(i Q ) entails the existence of an M-morphism q : Next, consider the following example for illustration of the concept of nested application conditions. We will in practice be interested exclusively in nite nested application conditions, i.e. in sequences (or in general DAGs) of conditions that ultimately end in an instance of a condition of the form ∃(x, true). In this sense, the example below is su ciently generic.

Example 3
The application condition below (on undirected multigraphs) parses more explicitly into the diagram expressing the condition that a morphism p : 1 → G satis es the condition if G contains at least one other vertex 2 (which is the information encoded in the rst part of the condition), and such that 1 and 2 are linked by an edge. One may also observe that the M-morphism q in the above diagram automatically exists if the entire condition is satis ed. This is in fact a typical example of re nement (or M-coverability [33]), whereby the condition ∃(a, true) is re ned by the condition ∃(a, ∃(b, true)).

A refined notion of shift construction
One of the most central concepts in the theory of rewriting with conditions is the notion of shift construction, which is, in essence, a category-theoretical characterization of the interplay between conditions and extensions of their domains. We introduce here an optimized version of the classical shift construction presented in [33] (which itself is a development of the original construction as reviewed in [27]). Our optimization hinges on the assumed properties of the underlying M-adhesive categories according to Assumption 1. We believe this optimization will be of key importance in future developments of algorithms and software implementations of our framework. The following theorem is at the basis of our novel construction:

Theorem 3
Given an M-adhesive category C satisfying Assumption 1, consider a commutative diagram of the form below, where the square marked (1)  Then construct the commutative diagram presented in the left part of (16) as follows: form the two pullbacks , which by universality of pullbacks also induces morphisms B i → B i (for i = 1, 2); according to Lemma 13 of Appendix A.2, we may conclude that ; by universality of pullbacks, this implies the existence of morphisms A → X and X → X (and by decomposition of M-morphisms, the latter is in M). Since the square just constructed is a pullback, the bottom square a pushout along M-morphisms (and thus a pullback), and since, due which proves the claim that e = f • m ∈ epi(C).
"⇐" direction: Suppose that e ∈ epi(C) and that the exterior square in (15) is a pullback. Construct the commutative diagram depicted in the right part of (16) as follows: start by forming the pushout F = PO(B 1 ← X → B 2 ), which by universality of pushouts (recalling that the top square is by assumption also a pushout) entails the existence of morphisms (f : C → F ) and (m : By stability of M-morphisms under pushouts, the morphisms so is m . The top commutative cube thus precisely satis es the properties necessary to invoke the theorem in the "⇒" direction, in order to conclude that f ∈ epi(C). Since by assumption e ∈ epi(C), and since e = m • e , invoking decomposition of epimorphisms yields that m ∈ epi(C). On the other hand, since by assumption the bottom square is a pullback, invoking the property of M-e ective unions permits us to conclude that m ∈ M. As the underlying category is assumed to be balanced, and since M ⊆ mono(C), we conclude that m ∈ iso(C), i.e. F ∼ = E, which proves that the bottom square is a pushout (by uniqueness of pushouts, and since pushouts along M-morphisms are also pullbacks).

Theorem 4 (Shift construction; compare [33], Thm. 5 and Lem. 3) Given an
M-adhesive category C satisfying Assumption 1, there exists a shift construction, denoted Shift, such that for every condition c P over an object P ∈ obj(P ) and for every M-morphism p : P → Q, an M-morphism m = n • p (with n ∈ M) satis es the condition c P if and only if n satis es Shift(p, c P ), the shift of c P along p: Here, the application condition Shift(p, c P ) is constructed inductively as follows: (ii) Case c P = ∃(a, c A ) (for some a : P → A and c A an application condition over A ∈ obj(C)): construct the commutative diagram below, where the square marked PO is a pushout 3 : Here, each M-morphism x : P → X such that there exist M-morphisms p : (iii) Case c P = ¬c P : (iv) Case ∧ i∈I c i : Proof: Our starting point is the formulation of the Shift construction according to [33] (with the crucial construction called However, due to the de nition of satis ability, a morphism (h : in that case, we also have that h satis es the condition ∃(r ) = ∃(r : Q → E , true), . This demonstrates that each choice of representatives for the isomorphism classes (r, s) and the pushouts yields an equivalent condition Shift(p, c P ).
At this point, we may demonstrate a rst application of our re ned Shift construction, namely to a special situation for shifts that plays a role later on in the theory of compositions of rewriting rules:

Lemma 3 (Shift along coproduct injections)
Let C be an M-adhesive category satisfying Assumption 1. Let P, Q ∈ obj(C) be objects, and let ∃(a : P → A, c A ) be a condition over P . Then Shift(P → P + Q, ∃(a : P → A, c A )) may be computed via the following type of diagram: Proof: Consider the following specialization of the technical result stated in Lemma 16: starting from the diagram depicted in (15), any M-morphism f : , and analogously the morphism x : P → X decomposes into the pair of M-morphisms [g, h] : P +P → X P +X Q (with P +P ∼ = P ).
But since by commutativity of the diagram in (23) that P ∼ = P and P ∼ = ∅, which upon invoking Theorem 4 proves the claim.

Example 4
As an illustrative application of Lemma 3, consider the following explicit computation in the category uGraph of undirected multigraphs (which satis es Assumption 1, with ∅ the empty graph): The image demonstrates how the shift along the the embedding of the two-vertex graph with an edge (highlighted in orange) into a disjoint union with a "square" graph yields a condition over this disjoint union of graphs that tests for a disjoint pattern, but also (via the only other possible non-trivial overlap up to isomorphisms, along an additional disjoint vertex marked in blue) an alternative condition that tests for a nondisjoint pattern: Finally, we will require two additional technical lemmas of key importance to our framework of compositional rewriting. Both results rely on the denition of the notion of equivalences of conditions (see De nition 8 and equation (10)).

Lemma 4 (Units for Shift)
For every object P ∈ obj(C) and for every condition c P over P , we have that Proof: This follows directly from the de nition of Shift according to Theorem 4, by specializing (17) in the form Lemma 5 (Compositionality of Shift; compare [31], Fact 3.14) Let X ∈ obj(C) be an object, c X an application condition over X, and let f : X → Y and g : Y → Z be two morphisms of C. Then the following equivalence of conditions holds: Proof: The proof follows by a repeated application of Theorem 4. The equivalence holds if for all morphisms c : Z → H, we nd that Starting from the diagram below, we may calculate: Compositional associative Double-Pushout rewriting with conditions

DPO-rewriting in M-adhesive categories
Keeping the de nitions and results to the essential minimum (mainly following [10]), with the assumptions described in Assumption 1, we will be exclusively interested in studying so-called Double Pushout (DPO) rewriting for linear rules: De nition 9 (Linear rules) Let C be an M-adhesive category. We denote by Lin(C) the set of linear rules, de ned as the set of isomorphism classes 4 Here Here, the square marked POC must be constructible as a pushout complement, while if this square exists the square marked PO is always constructible as a pushout (cf. Assumption 1), whence the moniker Double-Pushout (DPO) rewriting is derived. In this case, we refer to r m (X) ∈ obj(C) as the rewrite of X via the rule r along the (admissible) match m. We introduce the notation M r (X) for the set of admissible matches for the application of the rule r to the object X: For compatibility with the standard DPO rewriting literature, we will sometimes also use the notation in order to explicitly reference the information contained in (33). Moreover, the morphism m * is referred to as the comatch of m (under the application of linear rule r to the object X).
In order to provide a quick intuitive illustration of the DPO rewriting concept, consider the edge creation rule described in the introduction: Here along the example match m (which sends the vertices A and B of I to the vertices 1 and 2 of X, respectively) is depicted below: is constructible, i.e. if the pushout complement marked POC exists, we de ne It is straightforward to verify that the transport construction is invariant un- The transport construction permits us to choose, without loss of generality, a "standard position" for the application conditions in a linear rule, where we x the following conventions: De nition 12 (Standard form for DPO-type linear rules with application conditions and for admissble matches) Let Lin(C) denote the set of linear rules of C.
Then Lin(C) denotes the set of linear rules with application conditions in standard form, where elements of R ∈ Lin(C) are of the form Consequently, we may introduce the notion of admissible matches for applications of rules with application conditions to objects as follows; let X ∈ obj(C) be an object, Equivalently, admissibility of m thus amounts to admissibility with respect to the linear rule without application conditions (i.e. in the sense of (34)) combined with satisfaction of the application condition, whence we may write the following compact formula for the set of admissible matches M R (X): For later convenience, we will employ the shorthand notation≡ to signify This also implies that c I≡ċI , thus motivating the notationċ I .
We conclude this subsection by stating a number of technical lemmas that are necessary in order to derive our novel associative compositional DPO rewriting 7 We choose to not make the linear rule with respect to which admissibility is required explicit in our notation≡, since it may be inferred uniquely from the structure of the conditions that are related in any given formula.
framework as presented in the following subsection, which concern certain important properties of the Trans construction and of the compatibility of the Shift and Trans constructions: Lemma 7 (Units for Trans) Let X ∈ obj(C) be an arbitrary object and c X a condi- Proof: The proof follows directly from the de nition of the Trans construction as provided in Lemma 6, whence one nds for arbitrary admissible matches Here, the pushout complement in the squares marked POC always exists by virtue of Lemma 12(i)a, and m * = m as well as r m (X) = Y follow due to stability of isomorphisms under pushouts.

Lemma 8 (Compositionality of Trans)
Given two composable spans of M-morphisms de ne their composition via pullback as which is due to stability of M-morphisms under pullbacks and compositions also a span of M-morphisms (and thus r, s, s • r ∈ Lin(C)). Let c E be a condition over E.
Then we nd that Trans(s, Trans(r, c E ))≡ Trans(s • r, c E ) .
Proof: The proof relies upon the de nition of the transport construction according to Lemma 6 as well as on the M-adhesivity of the underlying category C. We proceed by constructing the following commutative diagram in two di erent ways for the two directions of the proof: Trans(s, Trans(r, c E )) "⇒" direction: Suppose that m ∈ M r (X) and that the comatch m * of m satis es m * ∈ M s (X ) (with X = r m (X)). Then by de nition of the Trans construction, this implies that m * * c E ⇔ m * Trans(r, c E ) ⇔ m Trans(s, Trans(r, c E )) .
We have to demonstrate that m ∈ M s•r (X) as well as m Trans(s, Trans(r, c E )) ⇒ m Trans(s • r, c E ) .
Admissibility of m and m * entails that the squares formed in the back row of (53) (the ones drawn in black and blue) are constructible as pushouts and pushout complements, respectively. Construct the objects F and F as pullbacks, which we may write more compactly as Proof: Let us x an object X and some admissible match n ∈ M r (X). implies that n * Shift(p * , c O ), and since by assumption n ∈ M r (X), and since n * is the comatch of n, we may nally conclude that indeed n Trans(r , Shift(p * , c O )).
"⇐" direction: The proof is entirely analogous to the previous case (starting from the observation that n ∈ M r (X) together with the data provided in (56) entails that m ∈ M r (X)).

A refined notion of sequential compositions of DPO-type rules with conditions
The notion of E-concurrent rules as originally introduced in the work or Ehrig To this end, we follow the philosophy put forward e.g. in [14,36]

De nition 15
Let C be a category satisfying Assumption 1. Let R j ≡ (r j , c I j ) ∈ Lin(C) be two linear rules with application conditions (j = 1, 2), and let be a span of monomorphisms (i.e. m 1 , m 2 ∈ M). If the diagram below is constructible, and if c I 21 ≡ false, then we call µ 21 an admissible match for the rules with conditions R 2 and R 1 , denoted In this case, we introduce the notation R 2 µ 21 R 1 to denote the composite, The de nition of the composition operation . . . entails a number of highly non-trivial e ects in practical computations, which originate from the interplay of admissibility of matches for rules without application conditions and the requirements on the induced composite application conditions. One of the most striking such results well-known also from the traditional graph rewriting literature [27] is the following:

Lemma 10 (Trivial matches) By de nition of the notion of admissible matches, for
any two linear rules with application conditions R j ≡ (r j , c I j ) ∈ Lin(C), the trivial match is an admissible match µ ∅ ∈ M R 2 (R 1 ) if and only if the composite condition c I 21 does not evaluate to false.

Proof:
The proof follows directly from the de nition of the composition operation . . ., namely by construction of the following diagram: Trans Thus the claim follows, since the above condition may evaluate to false in general, such as in the case where c I 2 = ¬∃(I 2 → I 2 + O 1 , true).
Nevertheless, it is possible to exhibit one special rule for which µ ∅ is always an admissible match: (65) Thus for every linear rule r 2 with application condition c I 2 ≡ false, µ ∅ ∈ M R 2 (R ∅ ).
For the remaining case, consider that r 1 = (O 1 ← K 1 → I 1 ) is an arbitrary linear rule with application condition c I 1 ≡ false. Again, admissibility of µ ∅ as a match of the rules without conditions follows by a specialization of (63), so it remains to compute the composite condition c I 21 : c I 21 = Shift(p 1 :

Concurrency theorem for DPO-type rules with conditions
We will need the following concurrency theorem, which is a re nement of a result of [32]  Let C be an M-adhesive category satisfying Assumption 1, X 0 ∈ obj(C) an object, and R j ≡ (r j , c I j ) be two linear rules with application conditions (j = 1, 2). Then there exists the following bijection: (i) "Synthesis": For every sequence of rule applications there exist admissible matches µ 21 ∈ M R 2 (R 1 ) of the linear rule R 2 into R 1 and , r 21 = R 2 µ 21 R 1 , and an application condition c I 21 computed as where the morphisms and objects in this formula depend (uniquely up to isomorphism) on the input data, such that X 2 ∼ = R 21m 21 (X 0 ).
(ii) "Analysis": For every admissible match µ ∈ M R 2 (R 1 ) and for every rule application with m 21 ∈ M R 21 (X) and R 21 = R 2 µ 21 R 1 , there exists a pair of admissible matches such as in (67) which transform X 0 via X 1 into the same (up to isomorphism) object X 2 .
Proof: Referring the interested readers to [11] for the precise details, note rst that at the level of linear rules without application conditions, the concurrency theorem of [11] entails the parts of the above statements pertaining to the existence of the admissible matches of "plain" rules. The concrete technical construction of the proof provided in [11] It thus remains to verify the part of the claim pertaining to the relevant conditions of the rules.
"Analysis" part of the proof: Suppose that we are given admissible matches (m 1 : are pushouts, we nd in addition that Since according to De nition 15 R 21 = R 2 µ 21 R 1 = (r 21 , c I 21 ) with c I 21 as de ned in (68), we con rm that m 21 c I 21 , which concludes the proof of the "Analysis" part of the theorem.
. It thus remains to verify the claim that these matches satisfy the conditions c I 1 and c I 2 , respectively, which may be demonstrating by running the corresponding arguments of the "Analysis" part of the proof "in reverse".

Associativity of DPO-type composition of rules with conditions
We will now state one of the main results of this paper, in the form of an associativity property a orded by the DPO-type composition operation on rules with conditions. The case of DPO-type compositions of rules without conditions was studied in [7,10], and the following result is an extension to the setting of rules with conditions a orded by our re ned framework for conditions as introduced in Section 3 and the current section. In contrast to the DPO-type concurrency theorem (which, in a slightly di erent formulation, had been previously known in the literature), the associativity result presented below is to the best of our knowledge the rst of its kind.
Theorem 6 (DPO-type Associativity Theorem) Let R j ≡ (r j , c I j ) (j = 1, 2, 3) be three linear rules with application conditions. Then there exists a bijection between the pairs of admissible matches M A and M B de ned as with R i,j := (r i µ ij r j , c I ij ) (and c I ij de ned as in (61)) such that ∀(µ 21 , µ 3(21) ) ∈ M A : ∃!(µ 32 , µ (32)1 ) ∈ M B : and vice versa. In this particular sense, the operation . . . is associative.
Proof: Considering rst the case of compositions of "plain" rules r 1 , r 2 , r 3 ∈ Lin(C), i.e. of rules without application conditions, one may quote from [11] (Theorem 2.9) an isomorphism of pairs of admissible matches of the form The isomorphism entails that for each corresponding pair, equation (72a) is veri ed. Consider then two such isomorphic pairs (µ 21 , µ 3(21) ) ∈ M A and (µ 32 , µ (32)1 ) ∈ M B of admissible matches of "plain" rules. The isomorphism entails in particular that the following commutative diagram is uniquely constructible (where we also draw the positions of the various application conditions at play for later convenience): In order to verify the validity of (72b), it is su cient to utilize our various technical lemmas pertaining to the Shift and Trans constructions and to follow the "paths" in the diagram depicted in (74) along which the three conditions c I j for j = 1, 2, 3 have to be shifted and transported in order to form the conditions c I 3(21) and c I (32)1 , respectively.
(i) contribution of c I 1 : (ii) contribution of c I 2 : Here, in the last step, we have made use of the commutativity of the diagram (74), whereby (iii) contribution of c I 3 :

Compositional associative Sesqui-Pushout rewriting with conditions
While the previously discussed notion of compositional DPO-type rewriting may be seen as a re nement of pre-existing notions of DPO-rewriting from the literature (apart from the associativity theorem), the corresponding construction for a framework of SqPO-rewriting is almost entirely new. The rst framework for a compositional SqPO-rewriting framework for rules without conditions was introduced in [6]. The essential technical step in order to extend our framework from DPO-to SqPO-type consists in analyzing the interplay of nal pullback complements with application conditions and transformations thereof. We will rst provide a brief introduction to this type of rewriting, and then develop our new framework.

Definition of SqPO rule applications and rule compositions
De nition 16 (compare [19], Def. 4) Given an object X ∈ obj(C) and a linear rule r ∈ Lin(C), we denote the set of SqPO-admissible matches M sq r (X) as Let m ∈ M sq r (X). Then the diagram below is constructed by taking the nal pullback complement marked FPC followed by taking the pushout marked PO: We write r m (X) := X for the object "produced" by the above diagram. The process is called (SqPO)-derivation of X along rule r and admissible match m, and denoted Notably, SqPO-type rewriting thus di ers from DPO-type rewriting in the important aspect that nal pullback complements as well as pushouts are guaranteed to exist in our base category (cf. Assumption 2), whereas pushout complements may fail to exist in general. A typical example already mentioned in the introduction concerns the application of a rule that deletes a vertex to a graph that consists of two vertices linked by an edge: In DPO-type rewriting, the deletion rule is not applicable along the match presented, since the square ( * ) is not constructible as a pushout complement. In SqPO-type rewriting however, since the square ( * ) is constructible as a nal pullback complement as presented, the deletion rule is applicable, resulting in a graph with just a single vertex. This example demonstrates the distinguishing feature of SqPO-type rewriting over DPO-rewriting, in that the former admits so-called "deletion in unknown context" (here the implicit deletion of the edge via application of the vertex deletion rule).

The transport construction in the SqPO-type setting
The following theorem demonstrates that the construction Trans as introduced in De nition 11 is precisely the construction needed in order to implement "transporting" conditions over linear rules also in the SqPO-rewriting setting.
This quintessential result appears to be new.
it holds that We may then construct the commutative diagram below, with the following individual steps taken: (ii) An arrow n ∈ M that satis es the condition Trans(r, c B ).
What is somewhat hidden in this set of data is the fact that the square (K, K , X, I) is a pullback (where the M-morphism K → X is provided as the composition of the M-morphisms n : B → X and K → B, which are by assumption part of the above data). This statement may be veri ed by constructing the commutative cube below left: By virtue of Lemma 12(i)c, the right square is a pullback. Since the top square is a pushout and thus also a pullback, by pullback composition the square (K, K , X, I) (i.e. the composite of the top and right squares) is indeed a pullback.
We may then invoke the universal property of FPCs (compare De nition 6) in the form presented in the right part of (87), which entails that there exists a morphism K → K (that is unique up to isomorphism). Then by Mmorphism decomposition, as K → X and K → X are in M, so is the morphism In summary, if c B ≡ true, we have veri ed that n * c B , and thus that If c B is nested, we may prove the statement inductively in the evident fashion.
The detailed structure of the above proof permits to clarify that while the Trans construction in SqPO rewriting is identical to the Trans construction of the DPO rewriting setting insofar as the calculation of the transported conditions is concerned, it di ers in the precise reasons why it indeed furnishes a transport construction in the desired sense (i.e. why satisfaction of conditions is "transported" against the direction of SqPO linear rules as detailed above).
Moreover, since there does not exist a construction that would permit to transport conditions "with" the direction of the linear rules (i.e. in the direction of rule applications), in SqPO rewriting the only degree of freedom in describing linear rules with application conditions is to transport any conditions a rule might carry on its output to its input, motivating the following de nition: De nition 17 (Standard form for SqPO-type linear rules with applicaiton conditions and for admissble matches) . Let C be an M-adhesive category satisfying Assumption 2. Let Lin(C) denote the set of linear rules of C, and Lin(C) the set of linear rules with application conditions in standard form as introduced in De nition 12, whence elements of R ∈ Lin(C) are of the form We then introduce the notion of SqPO-admissible matches for applications of rules with application conditions to objects under SqPO-type semantics as follows: let X ∈ obj(C) be an object, R ∈ Lin(C) as above a rule with application conditions, and m : I → X an element of M. Since according to Assumption 2 FPCs of arbitrary pairs of composable M-morphisms exist, the diagram below is always constructible, the SqPO-admissibility of m hinges solely on whether the match satis es the condition c I of the rule R. We thus de ne the set of SqPO-admissible matches for the application of the rule R to the object X as (i) Units for Trans: Let X ∈ obj(C) be an arbitrary object and c X a condition over X.
the "identity rule on X", we nd that (ii) Compositionality of Trans: Given two composable spans of M-morphisms we nd that Trans(s, Trans(r, c E )) ≡ Trans(s • r, c E ) .
(iii) Compatibility of Shift and Trans: where (in close analogy to the DPO-type rewriting setting) and if c I 21 = false, then we call µ 21 an SqPO-admissible match for the rules with In this case, we introduce the notation R 2 µ 21 R 1 to denote the composite, As already noted in [6] for the case of SqPO-type rewriting for rules without conditions, it might appear surprising at rst sight that there is an asymmetry in the above de nition (in that the left part of the diagram consists of an FPC and a pushout, while the right part is formed by a pushout complement and a pushout, respectively), but the precise reason for this de nition will become apparent when considering the concurrency theorem for SqPO-type rules with conditions in the following subsection.

SqPO-type concurrency theorem for rules with conditions
To the best of our knowledge, the following key result is the rst of its kind in the SqPO-rewriting setting:

Theorem 9 (SqPO-type Concurrency Theorem, extended from [6], Thm. 2.9)
Let C be an M-adhesive category satisfying Assumption 2, and let R j ≡ (r j , c I j ) ∈ Lin(C) (j = 1, 2) be two linear rules with application conditions, and let X 0 ∈ ob(C) be an object.
• Synthesis: Given a two-step sequence of SqPO derivations with X 1 := r 1 M 1 (X 0 ) and X 2 := r 2 M 2 (X 1 ), there exists a SqPO-composite rule , and a unique SqPO-admissible match n ∈ M sq R (X), such that • Analysis: Given an SqPO-admissible match µ 21 ∈ M sq R 2 (R 1 ) of R 2 into R 1 and an SqPO-admissible match n ∈ M sq Proof: For the part of the proof pertaining to the concurrency of SqPO-type rules without application conditions, we will follow the strategy presented in [6] (where slightly stronger conditions than the ones required according to Assumption 2 were made, i.e. in [6] C was assumed to be adhesive).
"Synthesis" part of the proof: Suppose we are given rules with application conditions R 1 , R 2 ∈ Lin(C) and SqPO-admissible matches m 1 ∈ M sq R 1 (X 0 ) and m 2 ∈ M sq R 2 (X 1 ), with X 1 = R 1m 1 (X 0 ). This data is encoded in the blue part of the diagram in (70). Let us begin by constructing the orange parts of (70) as follows: take the pullback M 21 = PB(I 2 → X 1 ←O 1 ), and then the pushout N 21 = PO(I 2 ← M 21 →O 1 ); by universality of pushouts, this entails the existence of a morphism N 21 → X 1 , which is in M since C is assumed to possess Me ective unions according to Assumption 2. Next, form the pullbacks K i = PB(K i → X 1 ← N 21 ) (for i = 1, 2), which entails the existence of morphisms At this point, note that the bottom row of squares in the back of (70) has the shape of two consecutive SqPO rewriting steps. Since (m 1 : I 1 → X 0 ) c I 1 and (m 2 : I 2 → X 1 ) c I 2 by assumption, we may conclude that m 21 = (I 21 → X 0 ) satis es m 21 c 21 , with To complete this part of the proof, take the pullbacks which also induces a morphism K 21 → K 21 . By pullback-pullback decomposition (Lemma 12(iii)a), the induced square (K 21 , K 21 , K 1 , K 1 ) (i.e. the inner right "curvy" square) is a pullback, which entails by stability of M-morphisms under pullbacks that K 21 → K 21 is in M. Then by the M-van Kampen property, the square (K 21 , K 21 , K 2 , K 2 ) (i.e. the inner left "curvy" square) is a pushout.  21 to X 0 yields the orange parts of the diagram in (70). In order to prove the claim, we have to demonstrate the existence of two SqPO-admissible matches m 1 ∈ M sq R 1 (X 0 ) and m 2 ∈ M sq R 1 (X 1 ), with X 1 = R 1m 1 (X 0 ) and that X 2 ∼ = R 2m 2 (X 1 ) under these assumptions.
We begin by forming the FPC K 1 = FPC(K 1 → I 21 →X 0 ), which is guaranteed to exist and to yield two M-morphisms K 1 → K 1 and K 1 → X 0 according to Assumption 2. By the universal property of FPCs, there exists a morphism K 21 → K 1 , which by the M-morphism decomposition property is in M. Horizontal FPC decomposition (Lemma 12(iii)e) entails that the square (K 21 , K 21 , K 1 , K 1 ) (inner right "curvy" square) is an FPC. Next, we take the pushout X 1 = PO(M 21 ← K 1 →K 1 ), followed by forming the FPC Since the inner right "curvy" square (K 21 , K 21 , K 1 , K 1 ) is an FPC and the second from the right bottom back square in (70) a pushout, the composition of these two squares is an FPC and thus a pullback. Then by the universal property of FPCs, there exists a morphism K 21 → K 2 , which is by the Mmorphism decomposition property in M, and by the horizontal FPC decomposition property, the left inner "curvy" square is an FPC. Noting that the square (K 21 , K 2 , N 21 , K 1 ) is by assumption a pullback, by pullback-pullback decomposition so is (K 21 , K 2 , X 1 , K 1 ); thus by the M-van Kampen property, the left inner "curvy" square is an FPC. Noting that the square is in fact a pushout. The latter entails by the universal property of pushouts the existence of a morphism K 2 → X 2 , and then by pushout-pushout decomposition that the leftmost bottom back square in (70) is a pushout (and thus by stability of M-morphisms under pushouts that (K 2 → X 2 ) ∈ M).
To complete the proof, note that the rightmost and second from right bot- rewriting steps claimed to exist by the statement of the theorem, which concludes the proof.

Associativity of SqPO rewriting with conditions
Based upon the developments presented thus far and on the central result of [6] (the associativity theorem for SqPO rewriting without rules), we may now state another key result of this paper. Due to the structural similarities between the structure of the associativity proof in the DPO-and SqPO-type cases for rules without application conditions, the following statement is almost verbatim equivalent to the corresponding DPO-type statement.
Note that in [6] the assumption was made that C is an adhesive category, which amounts to a stronger assumption than Assumption 2, since [16] an with R i,j := (r i µ ij r j , c I ij ) (and c I ij de ned as in (61)) such that and vice versa. In this particular sense, the operation . . . is associative.
Proof: Referring the interested readers to [6] for the precise details of the proof for the part of the above statement pertaining to rules without application conditions, su ce it here to quote the result that the following diagram (where we have also indicated the relevant conditions on rules for later convenience) is constructible starting from either of the sets of assumptions, and thereby proves the bijection for the sets of matches of rules without conditions:

Conclusion and Outlook
This paper provides a self-contained account of a novel class of rewriting theories, which have the special property of compositionality. Based upon the rich theory of "traditional" Double-Pushout (DPO) [20,26,28,27] and Sesqui-Pushout (SqPO) [19,37] rewriting in the setting of nitary M-adhesive categories [36,29,16], we lift our earlier results on compositional concurrency and compositional associativity as developed in [7,10,6] into the realm of rewriting systems with conditions on objects and morphisms.
The technical structure of both the rewriting theory for rules without conditions, and the theory of application conditions on objects and morphisms [38,33,27,35,31], required us to reformulate traditional category-theoretical definitions, and to provide an in-detail veri cation (and in part establishment) of the compatibility of the constructions with the requirements of compositionality.
From a technical perspective (referring to Section 2 for full details), it has proved essential to analyze the requirements on the host categories for both types of rewriting, namely that it should be nitary, M-adhesive and Mextensive, with certain additional properties such as the existence of epi-Mfactorizations required as described in Assumptions 1 (DPO-case) and 2 (SqPOcase).
Our second main contribution consists in a re nement of the theory of conditions in M-adhesive categories as presented in Section 3. For categories satisfying either of the aforementioned assumptions, it is possible to re ne a central construction of the theory of conditions, the so-called shift construction, into a form that allows one to develop a novel set of results on the interplay of rewriting rules and conditions. In particular, the transport construction is shown to possess a compatibility property in interaction with the shift construction, which is required to ensure compositionality of rewriting with conditions. This paper thus contains the rst-of-their-kind results on compositional concurrency and associativity of rewriting with conditions in both the DPO (Section 4) and SqPO (Section 5) cases. Our proof strategy and techniques rely heavily on earlier developments in the setting of rewriting without conditions [10,6] in conjunction with the aforementioned results on the properties of the re ned shift and transport constructions. While admittedly a rather technical work, we believe that our results could serve as a starting point for a new generation of developments in the eld of rewriting, in particular in view of static analysis tasks. Indeed, in most applications of practical interest, idealized data structures such as multigraphs must be restricted to more rigid structures (such as e.g. site graphs in the Kappa framework [25,15]) in order to obtain tractable algorithms of su cient predictive power.First results in the elds of stochastic mechanics of continuous-time Markov chains based upon stochastic rewriting systems [7,10,6,8] hint at a great potential of the framework of compositional rewriting with conditions as presented here.

A.1 Collection of technical lemmata for M-adhesive categories
In many practical computations in the framework of M-adhesive categories, one may take advantage of a number of technical results, some of which elementary, some of which rather specialized (such as in particular the lemmata pertaining to nal pullback complements (FPCs)). For the readers' convenience, we provide here the full list of results used in the framework of this paper. The list is an adaptation of the list provided in [6] from the setting of adhesive to M-adhesive categories. Note also that while the category-theoretical constructions of objects and morphisms via pullbacks, pushouts, pushout complements and FPCs are by de nition unique only up to universal isomorphisms, we follow standard practice in simplifying our notations by employing a convention whereby e.g. the pushout of an isomorphism as in (104)(A) is denoted by "equality arrows" (rather than keeping a notation with generic labels and ∼ = decorations on arrows).

Lemma 12
Let C be a category. ii. if (3) + (4) is an FPC (i.e. if (x, v • w ) is FPC of (v • w, z)), and if (4) is a pullback, then (4) is an FPC (i.e. (x, v ) is FPC of (v, y)). 9 It is worthwhile emphasizing that in these FPC-related lemmas, the "orientation" of the diagrams plays an important role. Moreover, the precise identity of the pair of morphisms that plays the role of the final pullback complement in a given square may be inferred from the "orientation" specified in the condition part of each statement. A.3 Some useful consequences of (strict) M-initiality In the case that an M-adhesive category possesses a (strict) M-initial object, the following useful properties may be derived.

Lemma 14
Let C be an M-adhesive category with M-initial object ∅. Then the commutative diagram of M-morphisms below is both a pushout and a pullback: Proof: Consider the following commutative diagram: Since the outer square and the left square are pushouts, according to the pushoutpushout decomposition property stated in Lemma 12(iii)b, the right inner square is also a pushout (and thus a pullback).

Lemma 15
Let C be an M-adhesive category with a strict M-initial object ∅, and consider the commutative diagrams of M-morphisms below, Then if (1) is a pullback, A ∼ = B, and if (2) is a pullback, B ∼ = F .
Proof: Consider the following auxiliary commutative diagrams: The left diagram is formed by taking a pullback to obtain the bottom square,