ArticleslgStudy

science

Graph rewriting

Graph rewriting is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Graph rewriting rather than just read about it. In short: In 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 rewriting — main illustration
Graph rewriting — illustration

Key takeaways

  • Graph rewriting belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Graph rewriting to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Graph rewriting from memory before moving on to harder problems.

Reference excerpt

In 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 L → R {\displaystyle L\rightarrow R} , with L {\displaystyle L} being called pattern graph (or left-hand side) and R {\displaystyle R} 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

Algebraic approach 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: r = ( L ← K → R ) {\displaystyle r=(L\leftarrow K\rightarrow R)} , also written L ⊇ K ⊆ R {\displaystyle L\supseteq K\subseteq R} , where K → L {\displaystyle K\rightarrow L} 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 k : K → D {\displaystyle k\colon K\rightarrow D} , where D is a context graph (this is where the name double-pushout comes from). Another graph morphism m : L → G {\displaystyle m\colon L\rightarrow G} models an occurrence of L in G and is called a match. Practical understanding of this is that L {\displaystyle L} is a subgraph that is matched from G {\displaystyle G} (see subgraph isomorphism problem), and after a match is found, L {\displaystyle L} is replaced with R {\displaystyle R} in host graph G {\displaystyle G} where K {\displaystyle K} serves as an interface, containing the nodes and edges which are preserved when applying the rule. The graph K {\displaystyle K} 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 G {\displaystyle G} . 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: r : L → R {\displaystyle r\colon L\rightarrow R} . 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.

Determinate graph rewriting Yet another approach to graph rewriting, known as determinate graph rewriting, came out of logic and database theory. 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.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Graph rewriting

Start with the simplest possible case. Write down what Graph rewriting claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Graph rewriting before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Graph rewriting ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Graph rewriting

In research
Graph rewriting appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Graph rewriting in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Graph rewriting is common in secondary-school and first-year university syllabi. It links to neighbouring topics Graph rewriting, so understanding it makes those chapters shorter.
In everyday life
Look for Graph rewriting outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Graph rewriting” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Graph rewriting in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Graph rewriting means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Graph rewriting out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Graph rewriting in simple terms?

In 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 pic…

Why does Graph rewriting matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Graph rewriting?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Graph rewriting.

Tags

  • Graph rewriting

Keep exploring