Graph rewriting

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.

being called replacement graph (or right-hand side of the rule).

The algebraic approach to graph rewriting is based upon category theory.

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

serves as an interface, containing the nodes and edges which are preserved when applying the rule.

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.

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.

[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 graphs are a prominent topic in programming language research since term graph rewriting rules are capable of formally expressing a compiler's operational semantics.

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.

Some common types are: 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.

Computations are described in this model by changes in the relations between the entities or by attribute changes of the graph elements.

Top: Example graph rewrite rule ( optimization from compiler construction: multiplication with 2 replaced by addition). Bottom: Application of the rule to optimize "y=x*2" into "y=x+x".