key: cord-0046332-u9lh101s authors: Kurth, Winfried title: Multiscale Graph Grammars Can Generate Cayley Graphs of Groups and Monoids date: 2020-05-31 journal: Graph Transformation DOI: 10.1007/978-3-030-51372-6_18 sha: 7475788f2205a1218c90bdfe6510a3870148959a doc_id: 46332 cord_uid: u9lh101s A graph grammar with parallel replacement of subgraphs, based on the single-pushout approach in graph rewriting, was designed which constructs Cayley graphs of monoids of transformations of a finite set, with permutation groups as a special case. As input, graph-based representations of a finite number of generating transformations have to be specified; they will then correspond to the edge types of the Cayley graph which is the final result of the rewriting process. The grammar has [Formula: see text] rules, where d is the number of generators, and operates at two scale levels. The fine-scale level is the level of elements on which the transformations act and where their composition is calculated by parallel subgraph replacement. The coarse-scale level corresponds to the transformations themselves which are organized in the Cayley graph in a sequential rule application process. Both scale levels are represented in a single graph. The graph grammar was implemented in the programming language XL on the software platform GroIMP, a graph rewriting tool which was originally designed for simulating the growth of plants. Cayley graphs have been used for a long time to visualize the structure of discrete groups (see, e.g., [2] ). They can be generalized to other algebraic structures [1, 8] . Particularly, for a monoid M (i.e., semigroup with neutral element), the Cayley graph of M w.r.t. a set of generators G has the node set M , and for each node n ∈ M and each generator g ∈ G there is a directed edge (n, n • g). In this small study we will demonstrate that the construction of the Cayley graph of a monoid which is defined by a generating set G of transformations of a finite set can be conceived as an application of a graph rewriting system. See [6] for an introduction to finite transformation semigroups. Permutation groups, which have been intensively studied for long time [3] , and their Cayley graphs emerge as a special case when all members of G are bijective. As our graph grammar formalism, we used the "relational growth grammars" (RGGs) which enable a parallel replacement of subgraphs and are based on the single-pushout approach [4] . "Parallel replacement" means here that in every discrete time step all subgraphs which are instances of a left-hand side of a grammar rule are replaced by the graph given on the respective right-hand side. (For a discussion of the advantages of the single-pushout approach see [9] , p. 104.) RGGs are supported by the programming language XL and are available on the platform GroIMP [9, 10] . They can be seen as generalizations of Lindenmayer systems from strings to graphs and were primarily used to simulate the 3-dimensional architecture and development of plants (see, e.g., [14] ). The software GroIMP contains also a powerful graph-drawing algorithm combining an energy-based layout with a tree layout [5] . Furthermore, XL was recently extended to support rewriting at several scale-levels simultaneously [12, 13] . These were our main reasons for choosing the RGG approach and GroIMP for our purpose. We think other graph-grammar formalisms and software tools with a suitable expressive power could solve our task as well. It was not our intention to create yet another calculation tool for transformation semigroups or permutation groups. Several such tools, devoted to this special field of application, exist already (see, e.g., [11] ). We rather wanted to show that an existing graph rewriting approach, originally introduced for a quite different purpose, can solve our construction task. Our method is not optimized in terms of computation time or memory efficiency. In the following, we will specify our used graph model and all the rules of our grammar. The description of the rules will also contain the proof that they indeed build the Cayley graph defined by the generating transformations given as input. Finally we will discuss some weaknesses of our method and also the graph layout provided for the final results by GroIMP. The graphs supported by the language XL are finite, connected, directed, rooted graphs with attributed, typed nodes with inheritance and with typed edges [9] . That means, each node belongs to a node type, with a class hierarchy among the types like in object-oriented programming, and each node can optionally have parameters (attributes), their number depending on the node type. In our case, all parameters will be integers. There is always a single node of the distinguished type "Root". Edges belong to one of a finite number of edge types (without hierarchy). There are no loops and no multiple edges of the same type and direction. XL provides three standard edge types called successor (s), ramification (r) and decomposition (d) which were taken from a graph model designed for multiscale descriptions of plant architecture in [7] . Beyond that, additional edge types can be defined by the user. The concept of multiple scales within a graph has been introduced to represent several levels of spatial resolution in vegetation models [12] . Although there is no geometry and hence no "spatial" scaling in our application here, we retain the concept of scale-level by denoting the transformations (i.e., the elements of our monoid; node type T ) as "coarse-scale" and the n elements on which they operate (node type E), which form a finite set S, as "fine-scale". Without loss of generality, we can assume S = {1, 2, . . . , n}. At the coarse-scale level we will additionally need intermediate nodes (type I) of indegree 1 and outdegree 1 between any connected pair of T nodes-this is particularly necessary in the case that the Cayley graph has loops, because our graph model does not permit loops, and by inserting an intermediate node each loop will be expanded to a cycle of length 2 -, and connector nodes (type C) which will provide the linkage to the fine-scale level. The T nodes will have an index parameter which will help to control the step-by-step buildup of the Cayley graph. The I nodes will have a parameter i, initially 0, which indicates if the target T node of the corresponding edge was already used for constructing a subgraph at fine-scale level representing the transformation for which this T node stands (i = 1) and if this transformation was already compared, in a subsequent step, with all previously generated transformations (i = 2). The E nodes will have a parameter k between 1 and 2n indicating which element of S they represent, either as a preimage (1 ≤ k ≤ n) or as an image element (n + 1 ≤ k ≤ 2n) with respect to the transformation under consideration. As edge types, we utilize the standard types s, r and d as well as one edge type g i for each generator (1 ≤ i ≤ d), and additionally two edge types x and y which will be used at the fine-scale level to calculate the composition of two transformations. In our graph, a transformation f : S → S will be represented by a subgraph consisting of 2n nodes of type E, with edges of type x between nodes E k and E f (k)+n where the subscript denotes the parameter of the node. Each element of S is thus represented twice. We could have used a single set of n nodes instead, with edges between E k and E f (k) , but because our graph rewriting mechanism does not allow non-injective embeddings of the left-hand side of a rule into the host graph, this would have made the calculation of the composition of two transformations more complicated. Rule 1 (Initialization): From the start node (in XL called Axiom) a graph is created which corresponds to the identical transformation id, shown in Fig. 1 . The nodes I, T and C represent the coarse-scale level. The C node is connected by decomposition edges with the E nodes at fine-scale level. The interconnections of the E nodes by edges of type x form the pattern of id on an n-element set. In XL, the initialization rule is coded as follows: where "+>" stands for a type r edge, a blank for a type s edge, "/>" for a type d edge, and "-x->" for a type x edge. The parenthesized part in the third line is iterated n − 1 times. The syntax "c:" in the first line introduces an identifier for the particular instance of a node of type C generated at this place and allows to refer to this instance by using the label "c" in the rest of the rule. To build up the Cayley graph, the transformations which exist already in the graph have to be multiplied with the d generators. In the first step, we simply make d copies of a transformation which is already represented in our graph. (This rule will then be applied iteratively to all nodes of type T .) The mapping pattern at fine-scale level of a copied transformation is still identical with that of the original, i.e., the generators have not yet been applied (Fig. 2) . This copy rule application is controlled by a global variable m, initially 0, which is incremented by 1 in each application. For the sake of simplicity, we display here only the code for the case d = 2, with generators g and h. The generalization to the general case, using the remainder of m mod d, is straightforward. On the right-hand side of the rule, the XL method cloneSubgraph(c) is used which creates a copy of the whole subgraph accessible from the node marked with label c: Fig. 1 , with an additional gi edge (thick unbroken arrow). For each generator g i , there is a rule which adds a third layer of type E nodes to the existing two layers. The new nodes are parameterized with n + 1, n + 2, ..., 2n like the nodes of the second layer (cf. bottom part of Fig. 1 ). Connections are established between the second and the third layer using edges of type y which mimic the application of the transformation g i on S. These connection patterns are the input of our algorithm. The code of each of these d rules thus depends on the action of the corresponding generator. As an example, we show the rule code for the permutation g = (3 4) on a two-element set. It makes use of a context condition, enclosed in starred parentheses, which ensures that the rule is only applied to T nodes with an incoming path consisting of a type g edge followed by a type s edge. The additional condition "i.used == 0" ensures that this insertion rule is applied only once to each transformation node in the Cayley graph: Note that in the third line the order of the parameters of the type E nodes, 4 and 3, has switched according to the represented transposition g which exchanges 3 and 4. Like the insertion rules, the two composition rules work exclusively at fine-scale level. They perform the composition of the two transformations represented between the first and the second layer and between the second and third layer of type E nodes, respectively. At the end, the subgraph where they have been applied has again only two layers of nodes, and the type y edges have disappeared (Fig. 3) . Rule 4 is the proper composition rule. Rule 5 serves to remove unused E nodes of the second layer after rule 4 has already been applied. Rule 5 is superfluous in the case that all transformations are permutations, because then all layer-2 nodes will be consumed by the applications of rule 4. In the XL code we have to ensure that rule 5 is only applied when all possible applications of rule 4 have already been done. To this purpose, XL provides the method call "derive()" enforcing to carry out all preceding parallel rule applications listed before: Rule 6 (Redirect): After copying the subgraph representing an already existing transformation f , inserting the connection pattern for generator g i at fine scale level and calculating the composition f • g i at this level, we have to check if this newly determined transformation occurs already in our graph. In this case, the corresponding type g i edge at coarse-scale level which led to the T node under consideration has to be redirected to the existing T node (which has the identical pattern at fine-scale level below it), and the new T node, together with the attached subgraph below it, has to be deleted (Fig. 4) . The search for identical subgraphs has to be done systematically, so in the XL code the rule application is embedded into a control structure with graph queries (syntactically marked by starred parentheses). The flag "used" guarantees that the redirect rule is applied only once to a transformation node. 4 . The redirect rule (rule 6). The italicized numbers in parentheses show the values of the parameter "used" of the type I nodes, which ensure that the rule is applied only once to each newly created type T node (here: the T node below the I node with value 1). The rule is applied only if the condition (u = u ) is valid for the indicated subgraphs. Edge signatures as in Fig. 1. Global control. After the growing Cayley graph was (possibly) modified by the redirect rule, the rule application process starts again with the copy rule. The indexing of the type T nodes and the application condition in the copy rule ensure that each transformation is processed only as often as there are generators (i.e., d times). In XL, the correct order of rule applications is specified by a control structure where the rule blocks are called by their respective names ("compose" stands for rules 4 and 5): for (int i = 1; i <= d; i++) { copy(); derive(); insert_gi(); derive(); compose(); derive(); redirect(); derive(); } The execution of this loop of rule applications has itself to be iterated until there are no more applicable rules (i.e., all transformations have been processed). The result is then a graph consisting of the Cayley graph of the monoid generated by g 1 , ..., g d at coarse-scale level (however, including insertion and connector nodes) and with all generated transformation patterns at fine-scale level. As an example, Fig. 5 shows the generated graph in the case of the Klein four-group Z 2 × Z 2 . To obtain the proper Cayley graph, we can first get rid of the fine-scale level by applying the rule C ==>>; which deletes all connector nodes. Since in the single-pushout approach, all "dangling edges" are deleted after removing a part of the host graph by rule application, this disconnects all type E nodes from the root and thus, because of the requirement of connectedness, deletes them, too. Only the coarse-level part of the generated graph (without the C nodes) will be retained after this (parallel) rule application. Finally, we can simplify the two-edge paths between two transformation nodes by merging them into one edge: t:T -gi-> I u:T ==>> t -gi-> u; for all generators, i = 1, ..., d. This last step should only be done if the Cayley graph has no loops (which is always the case for groups). The presented graph-rewriting method follows closely the way how one would construct the Cayley graph of a given transformation monoid manually. To this end, a combination of parallel subgraph replacement rule applications and procedural control structures (for ensuring the systematic, sequential visiting of all type T nodes during the construction process, and for comparing their transformations with all previously generated ones) turned out to be useful. The language XL provides an appropriate environment for combining these programming paradigms. However, some steps still required workarounds. Particularly, for testing the identity of two (graphically-encoded) transformations we had to write our own method "equalTransf" for using it in rule 6. The copying method "cloneSubgraph", used in rule 2, was already provided by XL, but, as for equality checking, a more intuitive and short-hand notation would have made the rules even more transparent. In terms of calculation time, our method is far from being optimized. Particularly the search pattern in the insertion rule family tends to produce a lot of mismatches which are then sorted out during testing the additional parameter conditions, especially for larger values of n. A more intelligent pattern matching strategy for the transformation-encoding subgraphs would probably be possible. On the other hand, our calculation of the composition of transformations by parallel graph-grammar rule application (rule 4) is potentially very efficient. To make use of this parallelism, however, requires a splitting of the execution into several threads and their processing by properly parallel devices (e.g., on the GPU). Cayley graphs are used to display an algebraic structure graphically and thereby to visualize its symmetries (see, e.g., [2] for groups). This requires an appropriate graph layout algorithm which is able to map abstract symmetries into geometrical ones. GroIMP provides already a "standard" graph layout which is a combination of an energy-based layout (using simulated annealing for optimization) and a classical tree layout [5] . When applied to the full graph (before simplification), it has the advantage to automatically separate the fine-scale from the coarse-scale level. From the examples of final Cayley graphs (after simplification) which we tested with our algorithm, we could see that this layout tends to produce already quite appropriate results in the case of groups, whereas in the more general case of monoids the existing patterns of similarity in the Cayley graphs are often not fully reflected in the layouts. It will be a special challenge in graph drawing to provide an improved graph layout algorithm for Cayley graphs of finite monoids which could then be used in combination with our graph-rewriting approach. "Multiscale functional-structural plant modelling at the example of apple trees", funded by DFG under grant number KU 847/11-1. All support is gratefully acknowledged. On Cayley graphs of basic algebraic structures Generators and Relations for Discrete Groups Permutation Groups Algebraic approaches to graph transformation II: single pushout approach and comparison with double pushout approach General-purpose graph drawing algorithm for GroIMP. Internship work presentation Classical Finite Transformation Semigroups: An Introduction A multiscale model of plant topological structures On transitive Cayley graphs of groups and semigroups Design and implementation of a graph grammar based language for functional-structural plant modelling Relational growth grammars -a graph rewriting approach to dynamical systems with a dynamical structure Computing transformation semigroups Multi-scale rule-based graph transformation using the programming language XL An approach to multiscale modelling with graph grammars Parallel graph grammars with instantiation rules allow efficient structural factorization of virtual vegetation Acknowledgments. I thank Ole Kniemeyer and Octave Etard for their ingenious programming work. Some prerequisites of this study were developed in the project