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, 1976. 1976. Parallelism of manipulations in multidimensional information structures and sesqui-pushout (SqPO) Corrad., 2006. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 semantics in adhesive categories Lack, 2005. 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, 2005. 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 is adhesive (Corollary 3.6 in Lack, 2005. 2005. Adhesive and quasiadhesive categories. RAIRO - Theoretical Informatics and Applications 39, 3 (July 2005, 511--545). doi: 10.1051/ITA:2005028);
 - Every full subcategory of an adhesive category is adhesive if the pullbacks and pushouts in of objects in are again in (a simple result; if the Van Kampen squares commute in , they must commute in ).
 
A first result immediately follows from the first result:
Proof
It is a presheaf.
This does not immediately generalise to , as unlike , Definition 3.2 imposes that be a coproduct. However, the result still holds:
Proof
is a full subcategory of the adhesive category . We must show the existence of pullbacks and pushouts along monos in .
Pullbacks. Consider a pullback of in , with . We must show that is in . Colimits are computed pointwise in presheaves, so we know that is the pullback of in . If we can show that is the coproduct of for , then we are done.
Let . Because and are coproducts in Set, i.e. a disjoint union, there must be such that and . By naturality of and , it follows that and . But by commutativity of the pullback diagram, , and thus and . We conclude by unicity of the pullback that and thus .
Pushouts. The same argument as for pullbacks also applies to pushouts: given a pushout of in with , an element that makes the pushout square commute must have preimages in and for some . Thus the pushout distributes over the coproduct, and we can conclude that is the coproduct of pushouts.
The same argument also applies to 1.
Now to the spicy stuff:
Proof
is a presheaf – hence adhesive.
The following pushout square shows that cannot be adhesive: the pushout square is valid in , but the pushout at the bottom right is not in , 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, 1976. 1976. Parallelism of manipulations in multidimensional information structures in the category.
A transformation rule in an adhesive category is a span . For objects , we then write or if there is a matching morphism and a context object along with morphisms and such that the following diagram commutes and both squares are pushouts:
If the DPO transformation exists for some rule and match , then we say is a valid DPO rewrite.
To ensure that a DPO rewrite is valid in minIR, we must impose certain conditions. Let be an IO-free minIR graph, i.e. , there is a morphism in for some type system and .
A DPO rewrite is a valid minIR DPO rewrite if there is a transformation in and
- is left-mono, i.e. the morphism is mono,2
 - the pushout complement and pushout also exist in the slice category ,
 - satisfies the hierarchy condition of Definition 3.3,
 - is IO-free.
 
Proof
We know by construction that . We must show that 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 and are unique if they exist.
The third condition we impose on corresponds directly to the constraint that defines hierarchical graphs in . 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 . The functor that forgets the and morphisms is a left adjoint (it possesses a right Kan extension defined pointwise), and thus preserves colimits. The images of and thus form pushout squares in , and by unicity, must match the pushout squares in . Hence 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  as outputs, respectively  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 but split them into two different values in . 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 
by two rotations of angle  by cloning the input angle.
Such semantics are possible using the sesqui-pushout construction (SqPO) by Corradini et al. Corrad., 2006. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4. We can reuse the same 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).
A transformation rule in an adhesive category is a span . For objects , we then write or if there is a matching morphism and a context object along with morphisms and such that is the final pullback complement of and the right square is a pushout:
If the SqPO transformation exists for some rule and match , then we say is a valid (SqPO) rewrite.
The left square is redundant in the diagram above, as it follows from the requirement that 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., 2006. 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 in satisfying the relaxed set of conditions
- the pushout complement and pushout also exist in the slice category ,
 - satisfies the hierarchy condition of Definition 3.3,
 - 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., 2006. 2006. Sesqui-Pushout Rewriting. In Graph Transformations, Berlin, Heidelberg. Springer Berlin Heidelberg, 30--45. doi: 10.1007/11841883_4 or König, 2018. 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 that is deleted by the transformation rule (i.e. but of the rule). The DPO transformation on the other hand is only well-defined when all edges incident to are in the image of 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 denotes the multiplication of angles and 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  that are mapped to
outputs in : if a value  is produced by op applied to , then cloning
 and 'op will result in two definitions of .
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 that are mapped to inputs in (otherwise a value in the rewritten minIR graph will have more than one value definition).
In fact, a much simpler argument applies: the category is isomorphic to the presheaf category , where is obtained from by removing the object . Adhesivity follows. ↩︎
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. ↩︎