Recent from talks
Nothing was collected or created yet.
Graph rewriting
View on WikipediaIn computer science, graph transformation, or graph rewriting, concerns the technique of creating a new graph out of an original graph algorithmically. It has numerous applications, ranging from software engineering (software construction and also software verification) to layout algorithms and picture generation.
Graph transformations can be used as a computation abstraction. The basic idea is that if the state of a computation can be represented as a graph, further steps in that computation can then be represented as transformation rules on that graph. Such rules consist of an original graph, which is to be matched to a subgraph in the complete state, and a replacing graph, which will replace the matched subgraph.
Formally, a graph rewriting system usually consists of a set of graph rewrite rules of the form , with being called pattern graph (or left-hand side) and being called replacement graph (or right-hand side of the rule). A graph rewrite rule is applied to the host graph by searching for an occurrence of the pattern graph (pattern matching, thus solving the subgraph isomorphism problem) and by replacing the found occurrence by an instance of the replacement graph. Rewrite rules can be further regulated in the case of labeled graphs, such as in string-regulated graph grammars.
Sometimes graph grammar is used as a synonym for graph rewriting system, especially in the context of formal languages; the different wording is used to emphasize the goal of constructions, like the enumeration of all graphs from some starting graph, i.e. the generation of a graph language – instead of simply transforming a given state (host graph) into a new state.
Graph rewriting approaches
[edit]
Algebraic approach
[edit]The algebraic approach to graph rewriting is based upon category theory. The algebraic approach is further divided into sub-approaches, the most common of which are the double-pushout (DPO) approach and the single-pushout (SPO) approach. Other sub-approaches include the sesqui-pushout and the pullback approach.
From the perspective of the DPO approach a graph rewriting rule is a pair of morphisms in the category of graphs and graph homomorphisms between them: , also written , where is injective. The graph K is called invariant or sometimes the gluing graph. A rewriting step or application of a rule r to a host graph G is defined by two pushout diagrams both originating in the same morphism , where D is a context graph (this is where the name double-pushout comes from). Another graph morphism models an occurrence of L in G and is called a match. Practical understanding of this is that is a subgraph that is matched from (see subgraph isomorphism problem), and after a match is found, is replaced with in host graph where serves as an interface, containing the nodes and edges which are preserved when applying the rule. The graph is needed to attach the pattern being matched to its context: if it is empty, the match can only designate a whole connected component of the graph .
In contrast a graph rewriting rule of the SPO approach is a single morphism in the category of labeled multigraphs and partial mappings that preserve the multigraph structure: . Thus a rewriting step is defined by a single pushout diagram. Practical understanding of this is similar to the DPO approach. The difference is, that there is no interface between the host graph G and the graph G' being the result of the rewriting step.
From the practical perspective, the key distinction between DPO and SPO is how they deal with the deletion of nodes with adjacent edges, in particular, how they avoid that such deletions may leave behind "dangling edges". The DPO approach only deletes a node when the rule specifies the deletion of all adjacent edges as well (this dangling condition can be checked for a given match), whereas the SPO approach simply disposes the adjacent edges, without requiring an explicit specification.
There is also another algebraic-like approach to graph rewriting, based mainly on Boolean algebra and an algebra of matrices, called matrix graph grammars.[1]
Determinate graph rewriting
[edit]Yet another approach to graph rewriting, known as determinate graph rewriting, came out of logic and database theory.[2] In this approach, graphs are treated as database instances, and rewriting operations as a mechanism for defining queries and views; therefore, all rewriting is required to yield unique results (up to isomorphism), and this is achieved by applying any rewriting rule concurrently throughout the graph, wherever it applies, in such a way that the result is indeed uniquely defined.
Term graph rewriting
[edit]Another approach to graph rewriting is term graph rewriting, which involves the processing or transformation of term graphs (also known as abstract semantic graphs) by a set of syntactic rewrite rules.
Term graphs are a prominent topic in programming language research since term graph rewriting rules are capable of formally expressing a compiler's operational semantics. Term graphs are also used as abstract machines capable of modelling chemical and biological computations as well as graphical calculi such as concurrency models. Term graphs can perform automated verification and logical programming since they are well-suited to representing quantified statements in first order logic. Symbolic programming software is another application for term graphs, which are capable of representing and performing computation with abstract algebraic structures such as groups, fields and rings.
The TERMGRAPH conference[3] focuses entirely on research into term graph rewriting and its applications.
Classes of graph grammar and graph rewriting system
[edit]Graph rewriting systems naturally group into classes according to the kind of representation of graphs that are used and how the rewrites are expressed. The term graph grammar, otherwise equivalent to graph rewriting system or graph replacement system, is most often used in classifications. Some common types are:
- Attributed graph grammars, typically formalised using either the single-pushout approach or the double-pushout approach to characterising replacements, mentioned in the above section on the algebraic approach to graph rewriting.
- Hypergraph grammars, including as more restrictive subclasses port graph grammars, linear graph grammars and interaction nets.
Implementations and applications
[edit]Graphs are an expressive, visual and mathematically precise formalism for modelling of objects (entities) linked by relations; objects are represented by nodes and relations between them by edges. Nodes and edges are commonly typed and attributed. Computations are described in this model by changes in the relations between the entities or by attribute changes of the graph elements. They are encoded in graph rewrite/graph transformation rules and executed by graph rewrite systems/graph transformation tools.
- Tools that are application domain neutral:
- AGG, the attributed graph grammar system (Java).
- GP 2 is a visual rule-based graph programming language designed to facilitate formal reasoning over graph programs.
- GMTE Archived 2018-03-13 at the Wayback Machine, the Graph Matching and Transformation Engine for graph matching and transformation. It is an implementation of an extension of Messmer’s algorithm using C++.
- GrGen.NET, the graph rewrite generator, a graph transformation tool emitting C#-code or .NET-assemblies.
- GROOVE, a Java-based tool set for editing graphs and graph transformation rules, exploring the state spaces of graph grammars, and model checking those state spaces; can also be used as a graph transformation engine.
- Verigraph, a software specification and verification system based on graph rewriting (Haskell).
- Tools that solve software engineering tasks (mainly MDA) with graph rewriting:
- eMoflon, an EMF-compliant model-transformation tool with support for Story-Driven Modeling and Triple Graph Grammars.
- EMorF a graph rewriting system based on EMF, supporting in-place and model-to-model transformation.
- Fujaba uses Story driven modelling, a graph rewrite language based on PROGRES.
- Graph databases often support dynamic rewriting of graphs.
- GReAT.
- Gremlin, a graph-based programming language (see Graph Rewriting).
- Henshin, a graph rewriting system based on EMF, supporting in-place and model-to-model transformation, critical pair analysis, and model checking.
- PROGRES, an integrated environment and very high level language for PROgrammed Graph REwriting Systems.
- VIATRA.
- Mechanical engineering tools
- GraphSynth is an interpreter and UI environment for creating unrestricted graph grammars as well as testing and searching the resultant language variant. It saves graphs and graph grammar rules as XML files and is written in C#.
- Soley Studio, is an integrated development environment for graph transformation systems. Its main application focus is data analytics in the field of engineering.
- Biology applications
- Functional-structural plant modeling with a graph grammar based language
- Multicellular development modeling with string-regulated graph grammars
- Kappa is a rule-based language for modeling systems of interacting agents, primarily motivated by molecular systems biology.
- Artificial Intelligence/Natural Language Processing
- OpenCog provides a basic pattern matcher (on hypergraphs) which is used to implement various AI algorithms.
- RelEx is an English-language parser that employs graph re-writing to convert a link parse into a dependency parse.
- Computer programming language
- The Clean programming language is implemented using graph rewriting.
See also
[edit]- Graph theory
- Shape grammar
- Formal grammar
- Abstract rewriting — a generalization of graph rewriting
References
[edit]Citations
[edit]- ^ Perez 2009 covers this approach in detail.
- ^ "A Graph-Oriented Object Model for Database End-User Interfaces" (PDF).
- ^ "TERMGRAPH".
Sources
[edit]- Rozenberg, Grzegorz (1997), Handbook of Graph Grammars and Computing by Graph Transformations, vol. 1–3, World Scientific Publishing, ISBN 9810228848, archived from the original on 2013-10-04, retrieved 2012-07-11.
- Perez, P.P. (2009), Matrix Graph Grammars: An Algebraic Approach to Graph Dynamics, VDM Verlag, ISBN 978-3-639-21255-6.
- Heckel, R. (2006). Graph transformation in a nutshell. Electronic Notes in Theoretical Computer Science 148 (1 SPEC. ISS.), pp. 187–198.
- König, Barbara (2004). Analysis and Verification of Systems with Dynamically Evolving Structure. Habilitation thesis, Universität Stuttgart Archived 2007-06-25 at the Wayback Machine, pp. 65–180.
- Lobo, Daniel; Vico, Francisco J.; Dassow, Jürgen (2011-10-01). "Graph grammars with string-regulated rewriting". Theoretical Computer Science. 412 (43): 6101–6111. doi:10.1016/j.tcs.2011.07.004. hdl:10630/6716. ISSN 0304-3975.
- Grzegorz Rozenberg, ed. (Feb 1997). Foundations. Handbook of Graph Grammars and Computing by Graph Transformation. Vol. 1. World Scientific. doi:10.1142/3303. ISBN 978-981-02-2884-2.
- Hartmut Ehrig; Gregor Engels; Hans-Jörg Kreowski; Grzegorz Rozenberg, eds. (Oct 1999). Applications, Languages and Tools. Handbook of Graph Grammars and Computing by Graph Transformation. Vol. 2. World Scientific. doi:10.1142/4180. ISBN 978-981-02-4020-2.
- Hartmut Ehrig; Hans-Jörg Kreowski; Ugo Montanari; Grzegorz Rozenberg, eds. (Aug 1999). Concurrency, Parallelism, and Distribution. Handbook of Graph Grammars and Computing by Graph Transformation. Vol. 3. World Scientific. doi:10.1142/4181. ISBN 978-981-02-4021-9.
Graph rewriting
View on GrokipediaFundamentals
Definition and Principles
Graph rewriting is a computational paradigm for transforming graphs by applying production rules that match a subgraph in a host graph and replace it with another subgraph, thereby preserving or modifying the overall structure according to specified conditions.[5] This process enables the modeling and evolution of complex relational structures in fields such as formal language theory and software engineering.[6] At its core, graph rewriting operates on a host graph, which serves as the initial structure subject to transformations, and relies on production rules of the form , where is the left-hand side (a pattern to match) and is the right-hand side (the replacement structure).[5] The application of a rule involves matching, which identifies an occurrence of as a subgraph in the host graph via an injective mapping, and embedding, which integrates into the host graph by reconnecting preserved elements and removing or adding components as needed.[6] This can introduce non-determinism, as multiple matches may exist for the same rule in a given host graph.[5] The standard model for graph rewriting employs directed labeled graphs, consisting of vertices (nodes) and directed arcs (edges), where both carry labels drawn from finite alphabets to encode types or attributes.[7] Vertices represent entities, while arcs denote relations between them, allowing for hierarchical or networked representations.[6] Some formalisms extend this to hypergraphs, where hyperedges connect multiple vertices, but the binary directed case remains foundational.[8] A simple illustrative rule might replace a single node labeled "A" (as ) with a chain of two nodes labeled "B" and "C" connected by a directed edge (as ), with incoming and outgoing edges from the original node reattached to the new chain's endpoints.[6] For instance, in an arithmetic expression graph, a rule could transform , where denotes successor, matching the left side and embedding the right to simplify the structure, potentially with multiple possible matches for and .[6] Unlike string rewriting, which operates on linear sequences and corresponds to tree structures without sharing or cycles, graph rewriting accommodates cycles, multiple edges between nodes (sharing), and hyperedges, facilitating the representation of intricate dependencies and non-linear relations.[6] Algebraic approaches extend these principles to handle partial matches via more flexible morphisms.[7]Historical Development
The origins of graph rewriting trace back to the late 1960s, when Azriel Rosenfeld and John L. Pfaltz introduced web grammars as a formal mechanism for generating and recognizing picture languages represented as directed graphs with labeled vertices.[9] This work extended string-based formal language theory to two-dimensional structures, laying foundational ideas for pattern recognition and image processing applications. Early precursors included L-systems for biological modeling introduced by Aristid Lindenmayer in 1968.[1] In the 1970s, Hans-Jörg Kreowski advanced the field through contributions to graph grammars, including work on derivation sequences and formal systems. In the 1990s, Kreowski and Grzegorz Rozenberg developed structured graph grammars, emphasizing canonical derivations and pumping lemmas for context-free graph languages to analyze generative power and complexity. The algebraic formalisms were pioneered by Hartmut Ehrig, Manfred Pfender, and Hans-Jürgen Schneider in 1973, introducing pushout constructions as a categorical framework for graph transformation.[10] This approach provided rigorous semantics for rule-based rewriting, influencing subsequent developments in software specification and concurrency. Concurrently, term graph rewriting emerged in the late 1980s and 1990s as an efficient implementation strategy for term rewriting systems, allowing sharing of subterms in graph representations to optimize computations in lambda calculus and functional programming. In the 1990s, graph rewriting integrated with concurrency theory, particularly through Grzegorz Rozenberg's efforts to unify graph grammars with Petri nets for modeling distributed systems and transformations.[11] This period also saw the establishment of key publication venues, including the International Workshops on Graph Grammars and Their Application to Computer Science, starting in 1978, which fostered collaborative advancements.[12] The culmination was the "Handbook of Graph Grammars and Computing by Graph Transformation" edited by Rozenberg in 1997, compiling foundational theories and applications across volumes.[13] Post-2000 developments expanded graph rewriting into model-driven engineering, where Ehrig and collaborators applied transformation rules to automate software design and verification processes.[14] More recently, in the 2020s, explorations in quantum computing have leveraged graph rewriting for manipulating quantum graph states, as seen in analyses of transformation complexity to Bell pairs using local operations.[15] These advancements highlight graph rewriting's evolving role in bridging classical and emerging computational paradigms.Formal Foundations
Graphs and Morphisms
In graph rewriting, graphs serve as the fundamental structures being transformed, typically formalized to support precise rule matching and application. A directed edge-labeled graph is defined as a tuple , where is a finite set of vertices, is a finite set of edges, and are the source and target functions specifying the endpoints of each edge, and is a labeling function that assigns labels from a fixed alphabet to edges, allowing representation of typed relations or attributes.[16] This structure accommodates parallel edges (multiple edges between the same pair of vertices) but assumes no self-loops unless specified. Unlabeled graphs omit the labeling function , treating all edges as indistinguishable beyond their connectivity, while node-labeled variants extend the definition with an additional function for vertex labels.[3] Undirected graphs can be modeled within this framework by enforcing symmetry (e.g., for each edge from to , adding a reverse edge from to ) or by using symmetric relations instead of directed edges. Hypergraphs generalize further, where edges (hyperedges) connect arbitrary finite sets of vertices rather than exactly two; formally, a hypergraph replaces and with an attachment function mapping each hyperedge to a nonempty finite subset of vertices, enabling the representation of n-ary relations in rewriting systems.[3] Graph morphisms provide the means to embed or map one graph into another while preserving structure, essential for identifying subgraphs during rewriting. A morphism between graphs and consists of functions and such that , , and for all edges , ensuring compatibility of sources, targets, and labels. For hypergraphs, the condition generalizes to . Morphisms compose componentwise: if , then , with identity morphisms being inclusions on vertices and edges.[16] In the context of rewriting, injective morphisms—where both and are injective—are particularly important, as they enable exact, non-overlapping matches of rule patterns into host graphs without identifying distinct elements. An isomorphism is a bijective morphism (with bijective and ), along with its inverse, establishing structural equivalence between graphs; two graphs are isomorphic if such a morphism exists.[17] From a categorical perspective, the collection of all graphs (of a fixed type, e.g., directed edge-labeled) forms the category Graph, with graphs as objects and morphisms as arrows; this category has componentwise composition, identity morphisms, and supports limits and colimits constructed set-theoretically on vertices and edges. Colimits, such as pushouts, facilitate "gluing" graphs along shared subgraphs via parallel morphisms, providing a formal basis for constructing transformed graphs in rewriting processes.[17] A representative example in graph rewriting involves an injective morphism from the left-hand side of a rewrite rule to a host graph , which embeds L as a subgraph in G such that all edges in L correspond to edges in G via m, allowing for possible additional contextual edges in G between the matched vertices, initially preventing dangling edges that could arise from partial matches.[16]Rewrite Rules
In graph rewriting, a rewrite rule is formally defined as a span , where is the left-hand side graph representing the pattern to be matched, is the interface graph specifying the preserved gluing context shared between the left- and right-hand sides, and is the right-hand side graph indicating the replacement structure. The morphisms and are graph homomorphisms that identify corresponding elements in the interface, ensuring that elements in remain unchanged during rewriting while allowing modifications outside this context.[13] This structure enables precise control over which parts of a graph are deleted, preserved, or added, forming the basis for local transformations in larger host graphs.[18] To apply a rule to a host graph , one first identifies a match, which is a graph morphism injecting the left-hand side into such that the image of embeds as a subgraph. The resulting graph is then constructed by removing the image under m of the elements in from , preserving the context outside this matched subgraph, and gluing in the elements of along the image of under the composed morphisms.[13] This process operationalizes the rule by transforming only the matched portion while maintaining the overall connectivity and structure of the host graph through the interface.[18] Contexts in graph rewriting refer to the subgraph of excluding the matched portion, which is preserved intact during the application of ; the interface acts as the boundary ensuring seamless integration of the replacement without disrupting external connections. For instance, dangling edges or nodes adjacent to the matched subgraph but outside remain attached to their counterparts in via the preserved elements in .[13] Rule application is inherently non-deterministic, as multiple matches may exist for a given rule in , or several rules from a set may apply simultaneously to overlapping or disjoint subgraphs, leading to branching derivation paths. This non-determinism reflects the generative power of graph rewriting systems, where choices in matching or rule selection can produce diverse outcomes from the same initial graph.[18] Derivations in graph rewriting can proceed sequentially, forming a chain where each step applies one rule to obtain the next graph, or in parallel, applying multiple compatible rules (on disjoint matches) in a single step to yield a combined transformation.[13] Sequential derivations emphasize step-by-step evolution, while parallel ones accelerate computation by exploiting independence of non-overlapping rewrites, both generating languages of reachable graphs from an initial . As a representative example, consider an initial graph consisting of a central node with an attached edge to another node, with a rule where is a single edge (two nodes and one edge), is one node (the interface, the attached node), and is a cycle of three nodes sharing the interface node. Matching identifies the edge, removes it while preserving the interface node, and glues in the cycle, yielding as a triangle where the interface node is part of the cycle and attached to the central node in the unmatched context of ; further sequential applications of similar rules can extend this to larger polygonal structures attached to the central node.[18]Rewriting Approaches
Algebraic Approaches
Algebraic approaches to graph rewriting formalize the transformation process using category theory, particularly through constructions like pushouts in categories of graphs and graph morphisms. These methods provide a precise semantic foundation for rule application, treating graphs as objects and rewrite rules as spans of morphisms, thereby enabling rigorous analysis of properties such as confluence and termination.[19] The double-pushout (DPO) semantics is a cornerstone of these algebraic approaches, where a rewrite rule is applied to a graph via a match in two successive pushout constructions. The first pushout deletes elements from corresponding to , yielding an intermediate graph , while the second pushout adds elements from to , resulting in the output graph . This ensures the absence of dangling edges or vertices by requiring the existence of pushout complements, which glues the constructions soundly.[20] Formally, given a match , the DPO construction proceeds as follows: first, form the pushout square with morphisms and (inclusion), yielding and , where is the deletion result isomorphic to . Then, construct the second pushout square with and , yielding and , so is isomorphic to . This is visualized as two adjacent pushout squares sharing the morphism from : The first pushout square: The second pushout square: [20] A more recent algebraic variant is the sesqui-pushout (SqPO) rewriting, introduced by Corradini et al. in 2006. SqPO—"sesqui" meaning "one and a half" in Latin—extends DPO to arbitrary categories using a construction that combines elements of single- and double-pushout approaches. It provides a deterministic and conservative generalization of DPO, particularly effective for handling deletions in unknown contexts and identifications, while maintaining efficiency and applicability in adhesive categories. SqPO rewriting facilitates transformations in settings where traditional DPO or SPO may fail due to strictness requirements, and it supports advanced features like negative application conditions in a more flexible manner.[2] In contrast, the single-pushout (SPO) semantics simplifies the process to a single pushout along a partial morphism from to , where undefined parts of the morphism indicate deletions. This approach permits dangling edges under specified deletion policies, such as inheriting or removing them, making it more permissive than DPO while still grounded in category theory. SPO generalizes DPO derivations, as every valid DPO step corresponds to an SPO step, but SPO allows transformations that DPO would reject due to partiality.[21] Algebraic approaches offer key advantages, including the ability to handle negative application conditions (NACs) via graph morphisms that forbid certain substructures during matching, and support for confluence analysis through critical pair analysis. Critical pairs arise from minimal overlaps of rules and are resolved by checking joinability, ensuring systematic verification of transformation behavior.[22] The Church-Rosser theorem is adapted to DPO and SPO contexts, stating that local confluence—where any two parallel derivations from a common graph can be joined—implies global confluence under conditions like the existence of pushout complements and strictness of the category. This parallel independence theorem underpins the theoretical soundness of these semantics for ensuring unique normal forms in terminating systems.[23] As an example, consider a DPO rule for node deletion where is a graph with a node and its incident edges, is the empty graph (full deletion), and is empty. Matching identifies in ; the first pushout deletes and edges, yielding , and the second pushout (trivial since ) gives . The pushout complement ensures no isolated edges remain, preserving graph integrity.[20]Term Graph Rewriting
Term graph rewriting specializes graph rewriting techniques to directed acyclic graphs (DAGs) that represent terms from term rewrite systems or lambda calculus, where nodes denote function symbols or variables and edges indicate arguments, allowing multiple references to the same subterm via sharing. This structure sharing, often implemented through pointers or multiple incoming edges to a node, enables efficient representation of terms with common subexpressions, such as repeated variables or subterms in functional expressions. Unlike plain term trees, which duplicate subterms and lead to exponential growth during reductions, term graphs maintain compactness by reusing nodes, making them particularly suitable for implementing functional programming languages and abstract reduction systems.[24] In term graph rewriting, rules are defined as graph transformations that match a left-hand side (lhs) subgraph to a redex and replace it with a right-hand side (rhs) subgraph, while preserving existing sharing to avoid unnecessary duplication and term explosion. The rewriting process injects the rhs into the host graph at the redex position, potentially connecting shared nodes across the rule and host to maintain structural efficiency; garbage collection is integrated to remove unreachable nodes post-rewrite, ensuring the graph remains compact and garbage-free. Strategies guide rule application: normal-order (leftmost-outermost) prioritizes outermost redexes for lazy evaluation, while applicative-order evaluates arguments first for eager computation, both adapted to graph traversal to respect sharing. Term graphs extend abstract reduction systems by handling cyclic structures through constructs like letrec or μ-operators, simulating recursive lambda terms without infinite unfolding.[24][25] The efficiency of term graph rewriting stems from constant-time (O(1)) operations for duplicating or referencing shared nodes, contrasting with the exponential cost of copying subtrees in traditional term rewriting, which is critical for large-scale reductions in lambda calculus or higher-order functions. For instance, algebraic gluing mechanisms can underlie the connection of lhs and rhs subgraphs during matching. A representative example is beta-reduction in lambda terms: consider the application , represented as a term graph with a lambda node pointing to a sum node whose arguments both reference the variable , and the application node linking the lambda and the constant 2. After rewriting, the graph becomes a let-bindinglet x = 2 in x + x, where the two sum arguments share a single pointer to the substituted 2 node, avoiding duplication and preserving the O(1) sharing benefit.[24][25]
Before (simplified graph):
- App node: args = [Lambda(x, Sum(x, x)), Const(2)]
After beta-reduction (with sharing):
- Let node: var=x, val=Const(2), body=Sum(x, x) [both x point to same node]
Before (simplified graph):
- App node: args = [Lambda(x, Sum(x, x)), Const(2)]
After beta-reduction (with sharing):
- Let node: var=x, val=Const(2), body=Sum(x, x) [both x point to same node]
