### Graph transformation in minIR

←Return to chapter

## 3.4. Graph transformation in minIR

As discussed in section 3.2, computation graphs with linear values, such as minIR, must adopt strict graph transformation semantics to ensure that linear constraints are satisfied at all times. In this section, we use the minIR graph category presented in the previous section to define transformation semantics that lean on the double pushout (DPO) Ehrig, 1976Hartmut Ehrig and Hans-Jörg Kreowski. 1976. Parallelism of manipulations in multidimensional information structures and sesqui-pushout (SqPO) Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 semantics in adhesive categories Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028.

#### Adhesivity of hypergraph categories #

The natural place to start this section is by studying which of the categories defined in section 3.3 are adhesive. From adhesivity follows that transforming graphs using DPO and SqPO constructions is well-defined and unique, at least in the regimes of interest to us.

A category is said to be adhesive if it has all pullbacks and pushouts along monos, as well as some compatibility conditions between them, the so-called “Van Kampen squares”. We refer to the literature (e.g. Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028) for a complete definition. For our purposes, the following two results are sufficient:

- Every presheaf topos [C, S e t][\mathbb C, \mathrm{Set}][C, Set] is adhesive (Corollary 3.6 in Lack, 2005Stephen Lack and Pawel Sobocinski. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028);
- Every full subcategory D⊆C\mathbb D \subseteq \mathbb CD⊆C of an adhesive category is adhesive if the pullbacks and pushouts in C\mathbb CC of objects in D\mathbb DD are again in D\mathbb DD (a simple result; if the Van Kampen squares commute in C\mathbb CC, they must commute in D\mathbb DD).

A first result immediately follows from the first result:

Proposition 3.1Adhesivity of directed hypergraphs
The category H\mathbb HH of directed hypergraphs is adhesive.

It is a presheaf.

This does not immediately generalise to lin-H\textrm{lin-}\mathbb Hlin-H, as unlike H\mathbb HH, Definition 3.2 imposes that E E E be a coproduct. However, the result still holds:

Proposition 3.2Adhesivity of hypergraphs with linearity constraints
The categories lin-H\textrm{lin-}\mathbb Hlin-H and lin-H type\textrm{lin-}\mathbb H_\textrm{type}lin-H type​ are adhesive.

lin-H\textrm{lin-}\mathbb Hlin-H is a full subcategory of the adhesive category [lin-C, S e t][\textrm{lin-}\mathbb C, \mathrm{Set}][lin-C, Set]. We must show the existence of pullbacks and pushouts along monos in lin-H\textrm{lin-}\mathbb Hlin-H.

Pullbacks. Consider a pullback A←p a P→p b A \xleftarrow{p_a} P \xrightarrow{p_b}A p a​
​P p b​
​ of A→a C←b B A \xrightarrow{a} C \xleftarrow{b} BA a
​C b
​B in [lin-C, S e t][\textrm{lin-}\mathbb C, \mathrm{Set}][lin-C, Set], with A, B, C∈lin-H A, B, C \in \textrm{lin-}\mathbb HA, B, C∈lin-H. We must show that P P P is in lin-H\textrm{lin-}\mathbb Hlin-H. Colimits are computed pointwise in presheaves, so we know that P(E)P(E)P(E) is the pullback of A(E)→C(E)←B(E)A(E) \to C(E) \leftarrow B(E)A(E)→C(E)←B(E) in Set\textrm{Set}Set. If we can show that P(E)P(E)P(E) is the coproduct of P(E s t)P(E_{st})P(E st​) for s, t∈N s, t \in \mathbb{N}s, t∈N, then we are done.

Let v∈P(E)v \in P(E)v∈P(E). Because A(E)A(E)A(E) and B(E)B(E)B(E) are coproducts in Set, i.e. a disjoint union, there must be s, t, s′,t′∈N s, t, s', t' \in \mathbb{N}s, t, s′,t′∈N such that p a(v)∈A(E s t)p_a(v) \in A(E_{st})p a​(v)∈A(E st​) and p b(v)∈B(E s t′)p_b(v) \in B(E_{st'})p b​(v)∈B(E st′​). By naturality of a aa and b bb, it follows that a(p a(v))∈C(E s t)a(p_a(v)) \in C(E_{st})a(p a​(v))∈C(E st​) and b(p b(v))∈B(E s′t′)b(p_b(v)) \in B(E_{s't'})b(p b​(v))∈B(E s′t′​). But by commutativity of the pullback diagram, a(p a(v))=b(p b(v))a(p_a(v)) = b(p_b(v))a(p a​(v))=b(p b​(v)), and thus s=s′s = s's=s′ and t=t′t = t't=t′. We conclude by unicity of the pullback that v∈P(E s t)v \in P(E_{st})v∈P(E st​) and thus P(E)=⨆s t P(E s t)P(E) = \bigsqcup_{st} P(E_{st})P(E)=⨆st​P(E st​).

Pushouts. The same argument as for pullbacks also applies to pushouts: given a pushout P P P of A→a C←b B A \xrightarrow{a} C \xleftarrow{b} BA a
​C b
​B in [lin-C, S e t][\textrm{lin-}\mathbb C, \mathrm{Set}][lin-C, Set] with A, B, C∈lin-H A, B, C \in \textrm{lin-}\mathbb HA, B, C∈lin-H, an element v∈P(E)v \in P(E)v∈P(E) that makes the pushout square commute must have preimages in A(E s t),B(E s t)A(E_{st}), B(E_{st})A(E st​),B(E st​) and C(E s t)C(E_{st})C(E st​) for some s, t∈N s, t \in \mathbb{N}s, t∈N. Thus the pushout distributes over the coproduct, and we can conclude that P(E)P(E)P(E) is the coproduct of pushouts.

The same argument also applies to lin-H type\textrm{lin-}\mathbb H_\textrm{type}lin-H type​1.

Now to the spicy stuff:

Proposition 3.3Non-adhesivity of hierarchical hypergraphs
Whilst hier-lin-H type\textrm{hier-lin-}\mathbb H_\textrm{type}hier-lin-H type​ is adhesive, the category hier-lin-H\textrm{hier-lin-}\mathbb Hhier-lin-H is NOT adhesive.

hier-lin-H type\textrm{hier-lin-}\mathbb H_\textrm{type}hier-lin-H type​ is a presheaf – hence adhesive.

The following pushout square shows that hier-lin-H\textrm{hier-lin-}\mathbb Hhier-lin-H cannot be adhesive: the pushout square is valid in [hier-lin-C, S e t][\textrm{hier-lin-}\mathbb C, \mathrm{Set}][hier-lin-C, Set], but the pushout at the bottom right is not in hier-lin-H\textrm{hier-lin-}\mathbb Hhier-lin-H, because the child regions cannot each be assigned a unique parent.

#### Double pushout semantics #

From Proposition 3.3, it follows that minIR graph transformations can be performed through the double pushout (DPO) construction Ehrig, 1976Hartmut Ehrig and Hans-Jörg Kreowski. 1976. Parallelism of manipulations in multidimensional information structures in the [hier-lin-C, S e t][\textrm{hier-lin-}\mathbb C, \mathrm{Set}][hier-lin-C, Set] category.

Definition 3.6Double pushout (DPO) transformation

A transformation rule p pp in an adhesive category A\mathbb AA is a span L←I→R L \leftarrow I \rightarrow RL←I→R. For objects G, H∈A G, H \in \mathbb AG, H∈A, we then write G⇒(p, m)H G \xRightarrow{(p,m)} HG(p,m)
​H or G⇒p H G \xRightarrow{p} HG p
​H if there is a matching morphism m: L→G m: L \to Gm: L→G and a context object C C C along with morphisms G←C→H G \leftarrow C \to HG←C→H and I→C I \to C I→C such that the following diagram commutes and both squares are pushouts:

If the DPO transformation G⇒(p, m)H G \xRightarrow{(p,m)} HG(p,m)
​H exists for some rule p pp and match m mm, then we say G⇒H G \Rightarrow HG⇒H is a valid DPO rewrite.

To ensure that a DPO rewrite is valid in minIR, we must impose certain conditions. Let G GG be an IO-free minIR graph, i.e. G∈hier-lin-H G \in \textrm{hier-lin-}\mathbb HG∈hier-lin-H, there is a morphism G→Σ G \to \SigmaG→Σ in hier-lin-H type\textrm{hier-lin-}\mathbb H_\textrm{type}hier-lin-H type​ for some type system Σ\SigmaΣ and I=O=∅I = O = \varnothing I=O=∅.

A DPO rewrite G⇒H G \Rightarrow HG⇒H is a valid minIR DPO rewrite if there is a transformation G⇒p H G \xRightarrow{p} HG p
​H in [hier-lin-C, S e t][\textrm{hier-lin-}\mathbb C, \mathrm{Set}][hier-lin-C, Set] and

1. p pp is left-mono, i.e. the morphism I→L I \to L I→L is mono,2
2. the pushout complement C C C and pushout H H H also exist in the slice category hier-lin-H type↘Σ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigmahier-lin-H type​↘Σ,
3. H H H satisfies the hierarchy condition of Definition 3.3,
4. H H H is IO-free.

Proposition 3.4
If G GG is a minIR graph and G⇒H G \Rightarrow HG⇒H is a valid minIR DPO rewrite, then H H H is a valid minIR graph.

We know by construction that H∈[hier-lin-C, S e t]H \in [\textrm{hier-lin-}\mathbb C, \mathrm{Set}]H∈[hier-lin-C, Set]. We must show that H H H further satisfies the constraints to be an object in the full subcategory of minIR graphs.

The first condition is standard in DPO and guarantees that C C C and D D D are unique if they exist.

The third condition we impose on H H H corresponds directly to the constraint that defines hierarchical graphs in hier-lin-H\textrm{hier-lin-}\mathbb Hhier-lin-H. The fourth condition ensures that valid minIR DPO rewrites map IO-free graphs to IO-free graphs.

Finally, the second condition is imposed to ensure well-typedness of H H H. The functor hier-lin-H→hier-lin-H type\textrm{hier-lin-}\mathbb H \to \textrm{hier-lin-}\mathbb H_\textrm{type}hier-lin-H→hier-lin-H type​ that forgets the def\textit{def}def and use\textit{use}use morphisms is a left adjoint (it possesses a right Kan extension defined pointwise), and thus preserves colimits. The images of C C C and H H H thus form pushout squares in hier-lin-H type\textrm{hier-lin-}\mathbb H_\textrm{type}hier-lin-H type​, and by unicity, must match the pushout squares in hier-lin-H type↘Σ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigmahier-lin-H type​↘Σ. Hence H H H is well-typed.

The restriction to rewrites of IO-free graphs is not a restriction of generality: if we are interested in rewriting computations with inputs and outputs, we can always express them as IO-free graphs by adding `input` and `output` ops with the values in I I I as outputs, respectively O O O as inputs. We assign them dedicated types distinct from all other operations; these operations will never be matched by transformation rules and can be removed at the end of rewriting.

#### Generalising to sesqui-pushouts #

We restricted minIR rewrites to DPO transformations obtained form left-mono rules, to ensure that the construction is unique. This excludes rules that may identify two values in G GG but split them into two different values in H H H. Such rules allow for cloning values, which is a useful transformation in minIR for non-linear values. An example of a transformation rule that we would like to allow in minIR:

For this example we added a `2x` operation that multiplies an angle value passed as input by two. The transformation rule replaces a rotation of angle 2 α 2\alpha2 α by two rotations of angle α\alpha α by cloning the input angle.

Such semantics are possible using the sesqui-pushout construction (SqPO) by Corradini et al. Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4. We can reuse the same ⇒(p, m)\xRightarrow{(p,m)}(p,m)
​ notation: when DPO is restricted to left-mono rules as we have done, SqPO is a generalisation of DPO (i.e. the construction coincides whenever the DPO exists).

Definition 3.7Sesqui-pushout (SqPO) transformation

A transformation rule p pp in an adhesive category A\mathbb AA is a span L←I→R L \leftarrow I \rightarrow RL←I→R. For objects G, H∈A G, H \in \mathbb AG, H∈A, we then write G⇒(p, m)H G \xRightarrow{(p,m)} HG(p,m)
​H or G⇒p H G \xRightarrow{p} HG p
​H if there is a matching morphism m: L→G m: L \to Gm: L→G and a context object C C C along with morphisms G←C→H G \leftarrow C \to HG←C→H and I→C I \to C I→C such that C C C is the final pullback complement of I→L→m G I \to L \xrightarrow{m} G I→L m
​G and the right square is a pushout:

If the SqPO transformation G⇒(p, m)H G \xRightarrow{(p,m)} HG(p,m)
​H exists for some rule p pp and match m mm, then we say G⇒H G \Rightarrow HG⇒H is a valid (SqPO) rewrite.

The left square is redundant in the diagram above, as it follows from the requirement that C C C be the final pullback complement (FPC). It is kept to highlight the similarities to DPO. As the commuting diagram indicates, the final pullback complement (FPC) construction forms a pullback square. Furthermore, unlike pushout complements, the FPC is defined by a universality property that ensures uniqueness if it exists. We refer to Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 for the exact FPC construction.

With SqPO, we can define the set of valid minIR rewrites as given by the SqPO transformations G⇒p H G \xRightarrow{p} HG p
​H in [hier-lin-C, S e t][\textrm{hier-lin-}\mathbb C, \mathrm{Set}][hier-lin-C, Set] satisfying the relaxed set of conditions

1. the pushout complement C C C and pushout H H H also exist in the slice category hier-lin-H type↘Σ\textrm{hier-lin-}\mathbb H_\textrm{type} \searrow \Sigmahier-lin-H type​↘Σ,
2. H H H satisfies the hierarchy condition of Definition 3.3,
3. H H H is IO-free.

We conclude this section with a discussion of some of the properties of minIR transformations using SqPO (referring again to Corradini Corrad., 2006Andrea Corradini, Tobias Heindel, Frank Hermann and Barbara König. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 or König, 2018Barbara König, Dennis Nolte, Julia Padberg and Arend Rensink. 2018. A Tutorial on Graph Transformation. In Graph Transformation, Specifications, and Nets - In Memory of Hartmut Ehrig. Springer, 83--104. doi: 10.1007/978-3-319-75396-6_5 for a more detailed explanation of the concepts discussed):

Deletion in unknown context.A key difference between DPO and SqPO transformations is that SqPO transformations on graphs will delete edges attached to a vertex v d v_d v d​ that is deleted by the transformation rule (i.e. v d∈L v_d \in L v d​∈L but v d∉R v_d \not\in R v d​∈R of the rule). The DPO transformation on the other hand is only well-defined when all edges incident to v d v_d v d​ are in the image of m mm and thus explicitly deleted (this is known as the dangling condition).

As minIR rewrites follow SqPO semantics, transformation rules such as the following are allowed:

Here ×\times× denotes the multiplication of angles and const(0)\textsf{const(0)}const(0) the zero angle. Any operation that would be connected to the starred value on the left would be deleted by this rule. However such an implicit operation deletion only yields valid minIR graphs if all incident values are non-linear and none of the target values of the deleted operation are used.

Non-left-mono rules.As discussed in the introduction to SqPO, the cloning of values is allowed in minIR rewrites. However, linear values may never be cloned (the FPC or pushout will not exist in these cases). Thus any minIR transformation rule will be left-mono on linear values. It must further be left-linear on all (linear and non-linear) values in I I I that are mapped to outputs in R R R: if a value w w w is produced by `op` applied to v v v, then cloning v v v and `'op` will result in two definitions of w w w.

Non-right-mono rules.Non-right-mono rules are allowed in both DPO and SqPO. They result in vertex merges. In minIR, the situation for right-mono is symmetric to left-mono: the map must be mono on linear values (otherwise the same value will have multiple uses or definitions) and it must be mono on all values in I I I that are mapped to inputs in L LL (otherwise a value in the rewritten minIR graph will have more than one value definition).

1. In fact, a much simpler argument applies: the category lin-H type\textrm{lin-}\mathbb H_\textrm{type}lin-H type​ is isomorphic to the presheaf category [lin-C~type, S e t][\textrm{lin-}\tilde{\mathbb C}_\textrm{type}, \mathrm{Set}][lin-C~type​,Set], where lin-C~type\textrm{lin-}\tilde{\mathbb C}_\textrm{type}lin-C~type​ is obtained from lin-C type\textrm{lin-}\mathbb C_\textrm{type}lin-C type​ by removing the object E E E. Adhesivity follows. ↩︎

2. This is often called left-linear in the literature. We avoid this term in this thesis to avoid confusion with the linearity property of values in minIR. ↩︎

←Return to chapter