---
title: Pattern Graph Rewrite Systems
url: https://www.emergentmind.com/topics/pattern-graph-rewrite-systems
type: topic
---

# Pattern Graph Rewrite Systems

Pattern graph rewrite systems are graph-rewriting formalisms that extend string graph rewriting with a compact syntax for expressing infinite families of graph rewrite rules. In the canonical formulation, certain marked subgraphs, called !-boxes or bang boxes, may be copied any number of times or removed, so a single schematic rule can stand for infinitely many concrete string graph rules. This places pattern graph rewriting at the intersection of diagrammatic reasoning, algebraic graph transformation, and automated reasoning for string diagrams, with especially strong connections to categorical quantum mechanics, tensor-network style reasoning, and graph-based proof tools such as Quantomatic [1204.6695]. Subsequent work broadened this perspective by introducing context-free grammar presentations of rule families, stronger categorical control over matching and embedding, and strategy-controlled and domain-specific graph rewriting frameworks [1504.02716] [2203.01032].

## 1. Origins in string graph rewriting

The immediate precursor of pattern graph rewrite systems is string graph rewriting. String diagrams are useful for reasoning about physical processes, logic circuits, tensor networks, and many other compositional structures, but as topological objects they are awkward for computation. String graphs were introduced as a discrete representation amenable to double-pushout rewriting, thereby turning diagrammatic equational reasoning into a graph transformation problem [1204.6695].

The key motivation for pattern graphs is that many diagrammatic laws are not naturally finite. The spider law in categorical quantum mechanics is the standard example: one schematic equation covers all arities of connected spiders. In ordinary informal notation, such laws are often written with ellipses. Pattern graphs replace that informal ellipsis with explicit graph structure. A plausible implication is that the formalism was designed not merely to compress notation, but to make infinitary rule families machine-readable and mechanically applicable without leaving the algebraic graph-transformation setting [1204.6695].

This origin also fixes the intended semantic level. Pattern graph rewrite systems do not begin as arbitrary graph grammars; they begin as an extension of a specific graph language for string diagrams. Their basic purpose is to preserve the combinatorial discipline of string graphs while enriching the rule language so that families of equations can be represented directly rather than by external schemas or metasyntactic conventions [1204.6695].

## 2. Pattern graphs and !-box structure

A pattern graph is a string graph equipped with special vertices representing marked subgraphs called !-boxes. Formally, the underlying typing structure is extended by adding a third vertex type, a !-vertex, to a typegraph \(\mathcal G_3\). Instead of drawing explicit edges from a !-vertex to everything inside it, the !-vertex is drawn as a box around the enclosed subgraph [1204.6695].

The formal constraints on a pattern graph \(G\) are specific. The subgraph on node-vertices and wire-vertices, denoted \(\Sigma(G)\), must be a string graph. The subgraph on !-vertices, denoted \(\beta(G)\), must be posetal. For each !-vertex \(b\), the associated box \(B(b)\) must be an open subgraph. If \(b' \in B(b)\), then \(B(b') \subseteq B(b)\), which supports nesting of !-boxes [1204.6695].

The definition of \(B(b)\) is also structural rather than decorative. For a !-vertex \(b\), \(B(b)\) is the full subgraph generated by its successors, and the parent graph \(B^\uparrow(b)\) is the full subgraph generated by its predecessors. The openness requirement is essential because removing an open subgraph does not create new boundaries. This ensures that copying the contents of a !-box preserves the string-graph property, especially the requirement that wires do not branch [1204.6695].

Two structural relations among !-boxes are especially important. Nested boxes are represented by a directed edge from one !-vertex to another, meaning that one box is inside another. Overlapping boxes intersect but neither contains the other. The distinction is semantically significant because copying an outer box copies the nested boxes as well, whereas overlapping boxes permit families that are not reducible to simple hierarchical replication. The examples with trees and path-counting rules show that nesting strictly increases expressiveness: with nesting one can represent arbitrary trees of height up to \(2\), whereas without nesting one only gets balanced trees [1204.6695].

## 3. Instantiation and rewrite semantics

Instantiation is defined by four primitive !-box operations. For a pattern graph \(G\) and a !-vertex \(b \in !(G)\), these are \(\COPY_b(G)\), \(\DROP_b(G)\), \(\KILL_b(G)\), and \(\MERGE_{b,b'}(G)\). Intuitively, \(\COPY\) duplicates box contents, \(\DROP\) removes the !-box annotation but keeps its contents, \(\KILL\) deletes the contents entirely, and \(\MERGE\) identifies compatible boxes. The paper proves an instantiation theorem stating that \(\COPY_b(G)\), \(\DROP_b(G)\), \(\KILL_b(G)\), and, when \(b\) and \(b'\) are mergable, \(\MERGE_{b,b'}(G)\), are all pattern graphs [1204.6695].

This gives a refinement preorder
\[
G \succeq H \quad\Longleftrightarrow\quad H \text{ can be obtained from } G \text{ by finitely many } \COPY,\DROP,\KILL,\MERGE \text{ operations}.
\]
If \(H\) is concrete, it is called an instance of \(G\). A pattern graph is therefore best understood as a generator of a family of concrete graphs rather than as a single graph with optional annotations [1204.6695].

Rewrite rules become rewrite patterns, given as spans
\[
L \xleftarrow{i_1} I \xrightarrow{i_2} R,
\]
with conditions ensuring compatibility with ordinary string graph rewriting. The required conditions are that \(\Sigma(I)\) is a point graph, that \(L\) and \(R\) share the same boundary, that \(\beta(i_1)\) and \(\beta(i_2)\) are isomorphisms, and that each !-box in \(I\) maps to corresponding boxes in \(L\) and \(R\) with matching preimages [1204.6695].

Matching is defined through instantiation. A pattern graph \(P\) matches a string graph \(H\) if some instance of \(P\) matches \(H\) in the usual string-graph sense: first choose an instantiation \(S\) of \(P\) to a concrete graph \(G\), then require a monomorphism \(m\) from \(G\) into \(H\). If a concrete instance of the left-hand side matches a host graph, the corresponding instantiated rewrite rule can be applied by the standard DPO technique. The formalism is closed under instantiation at the rule level as well: if \(L \rewritesto R\) is a rewrite pattern, then applying any of \(\COPY\), \(\DROP\), \(\KILL\), or \(\MERGE\) yields another rewrite pattern [1204.6695].

The spider law is the canonical example. A single pattern rewrite rule can express the infinite family of spider equations by allowing zero or more external wires around each spider and one or more wires connecting the two spiders. The same mechanism also captures families such as a path-counting rule that were not expressible in the older !-box formalism until edges could be repeated via wire-vertices inside !-boxes and boxes could nest and overlap [1204.6695].

## 4. From !-boxes to context-free rule families

A major generalization of the pattern-graph idea replaces !-boxes with synchronized graph grammars. In "Equational reasoning with context-free families of string diagrams," the underlying objects are still string graphs, but infinite rule families are represented by B-ESG grammars and B-ESG rewrite patterns rather than by !-box operations alone. A string graph here is a directed graph labelled by two disjoint sets of vertex labels, \(\mathcal N\) for node-vertices and \(\mathcal W\) for wire-vertices, with no edges directly connecting two node-vertices and with every wire-vertex having in-degree at most \(1\) and out-degree at most \(1\) [1504.02716].

Because wire subdivision is semantically irrelevant, rewriting is carried out modulo wire-homeomorphism. A string graph rewrite rule has the form \(L \leftarrow B \rightarrow R\), where \(B\) is the common boundary, and a rewrite uses a matching
\[
m : L \to \widetilde G \quad\text{with}\quad \widetilde G \sim G
\]
satisfying the no-dangling-wires condition. This preserves the DPO basis of the earlier formalism while changing the way infinite families are generated [1504.02716].

A B-ESG grammar is a pair \(B=(G,T)\), where \(G\) is a B-edNCE grammar and \(T\) is a decoding system. Encoded string graphs allow special encoding edges between node-vertices, and the decoding system replaces each encoding edge by a fixed connected string graph fragment. The grammar is constrained by conditions \(N1\), \(N2\), \(W1\), \(W2\), \(W3\), and \(W4\), all designed so that derivations cannot create illegal string-graph structure. The structural soundness theorem states that every graph in the language of a B-ESG grammar is a string graph. The paper also proves bounded wire length: for every B-ESG grammar \(B\), there exists \(n\) such that no graph in \(L(B)\) contains a wire longer than \(n\) [1504.02716].

A B-ESG rewrite pattern is a pair of B-ESG grammars \((B_1,B_2)\) with the same decoding system and a synchronized production structure. Corresponding productions must satisfy bijection conditions on non-terminal nodes and on inputs and outputs. A pattern instantiation is obtained by choosing identical derivation steps in the two grammars, so one schematic pair of grammars generates a family of concrete string graph rewrite rules. The central theorem is that every B-ESG pattern instantiation is a string graph rewrite rule [1504.02716].

This grammar-based view yields algorithmic results that the !-box presentation does not state in the same way. The membership problem for B-ESG grammars is decidable. Match-enumeration is also decidable for match-exhaustive B-ESG grammars. The paper further shows that a grammar itself can be transformed by string graph rewriting and that the induced B-ESG rewrite pattern is admissible. This suggests a second level of rewriting: not only can one rewrite concrete diagrams using instantiated family rules, one can also rewrite the grammar that generates the family [1504.02716].

The comparison with !-boxes is explicit. Both formalisms represent infinite families of rewrite rules and instantiate them to concrete DPO rules, but B-ESG grammars are more expressive in the kinds of graph families they can generate. Complete graphs of arbitrary size and nontrivial ZX-calculus schemas such as local complementation are presented as examples that motivate the grammar-based extension [1504.02716].

## 5. Matching, parallelism, and categorical control

Pattern graph rewrite systems are often presented through !-boxes or grammar synchronization, but the broader literature shows that the topic is inseparable from questions about matching discipline, concurrency, and compositional semantics.

One important axis is the underlying algebraic graph-transformation model. In chemically inspired graph transformation, the formal basis is a variant of the DPO approach in which a rewrite rule is a span
\[
p = (L \xleftarrow{l} K \xrightarrow{r} R),
\]
with \(l\) and \(r\) restricted to monomorphisms. A rule is applied to a graph \(G\) by a match morphism
\[
m : L \rightarrow G
\]
subject to the dangling and identification conditions, yielding a direct derivation \(G \xRightarrow{p,m} H\). The chemical setting forces an additional shift from single graphs to multisets of connected graphs, because a reaction frequently consumes and produces several molecules simultaneously. The formalism therefore requires proper derivations in which every connected component on the left-hand side is hit by the match, expressed by
\[
g_i \cap \operatorname{img}(m) \neq \emptyset \quad \forall\, 1 \le i \le n.
\]
This is a domain-specific but conceptually important extension of pattern-based rewriting beyond single connected hosts [1603.02481].

A second axis concerns simultaneous application of rules. "Parallel Graph Rewriting with Overlapping Rules" distinguishes disjoint from overlapping parallel rewriting and studies the latter by first rewriting to a pregraph and then quotienting to recover an actual graph. The quotienting construction is governed by the equivalence relations
\[
\merge^P = (\pp_H \bullet \pp_H)^*, \qquad
\merge^N = (\pn_H^- \bullet \merge^P \bullet \pn_H)^*.
\]
The key closure criterion is that \(\overline{H}\) is a graph iff \(H\) has no odd loop, and a syntactic sufficient condition forbids new port-port connections between two environment ports. The paper then defines two parallel rewrite relations, \(\fpr\) and \(\ar\), and proves determinism for \(\fpr\), and determinism for \(\ar\) under a symmetry condition on rules. This makes overlapping pattern application a first-class semantic issue rather than a side condition on sequential rewriting [1701.06790].

A third axis is categorical composition. "Categorical Abstract Rewriting Systems and Functoriality of Graph Transformation" defines a categorical rewriting system as a span of categories
\[
\mathcal{M}_L \xleftarrow{L} \mathcal{P} \xrightarrow{R} \mathcal{M}_R
\]
equipped with partial functions \(S_p\). The central property is functoriality, or vertical composition:
\[
S_p(\mathrm{id}_L)=\mathrm{id}_p,
\qquad
S_{p_1}(f_2)\circ S_p(f_1)=S_p(f_2\circ f_1).
\]
The paper shows that SPO, HPO, DPO, and SqPO graph transformation systems are functorial in this sense, while one form of garbage removal is not. For pattern graph rewrite systems, this gives an abstract criterion for when rewriting in stages agrees with rewriting by composed matches, which is closely aligned with the demand that schematic rule instantiation remain coherent under iteration [1101.3417].

A fourth axis is control over embedding. PBPO\(^+\) strengthens PBPO by introducing strong matching: a match \(m : L \to G_L\) and adherence morphism \(\alpha : G_L \to L'\) form a strong match if the square determined by \(m\), \(\alpha\), and \(t_L : L \to L'\) is a pullback. In Set-like settings this means the preimage of the typed image \(t_L(L)\) under \(\alpha\) is exactly the matched copy \(m(L)\). The practical effect is tighter control over which part of the host graph belongs to the embedded pattern and which part belongs to the surrounding context. In the quasitopos setting, PBPO\(^+\) is shown to define a strict superset of the rewrite relations definable by PBPO, AGREE, and DPO, and it is extended to labeled graphs via a lattice structure on the label set and order-preserving graph morphisms. This makes relabeling, sorts, and variables natural within the categorical rewrite machinery [2203.01032].

A common misconception is that pattern graph rewriting is exhausted by the original !-box syntax. The literature suggests a broader view: !-boxes, grammar-generated rule families, multiset DPO semantics, overlapping parallel rewriting, and strong categorical matching are all ways of specifying and controlling patterned subgraph replacement, but they differ sharply in the structure they permit, the concurrency they support, and the level at which they guarantee compositionality.

## 6. Strategic control, applications, and related directions

The operational side of pattern graph rewrite systems is dominated by strategy languages. Graph rewriting is inherently nondeterministic because multiple rules may apply and the same rule may match in multiple places. In the port-graph setting, this led to located graphs \(G[P]\), where \(P\) is a position subgraph that specifies where rewriting is allowed. A rule may apply only if the image of its left-hand side intersects \(P\), i.e.
\[
g(L) \cap P \neq \varnothing.
\]
The associated strategy languages include position transformations, applications, sequential composition, choice, iteration, and tests such as \(\mathit{PnotEmpty}\), together with traversal primitives like \(\mathit{AllSuc}\), \(\mathit{OneSuc}\), and \(\mathit{NextSuc}\). The formal semantics is given by rewrite rules on expressions of the form \(\langle S, G[P] \rangle\), and PORGY implements this model as an interactive environment for port graph transformation and visualization [1012.5560] [1102.2654].

A more elaborate version extends located graphs to \(G_P^Q\), where \(P\) is the position subgraph and \(Q\) is a banned subgraph. Located rewrite rules \(L_W R_M^N\) update both after rewriting:
\[
P'=(P \setminus g(L)) \cup g(M), \qquad Q'= Q \cup g(N).
\]
The small-step operational semantics is given over multisets of strategic graph programs, yielding an explicit derivation-tree semantics for strategic rewriting. This is especially important in modeling and analysis settings where rule application order, traversal, and exclusion zones are part of the intended semantics rather than implementation details [1407.7929].

Applications are correspondingly diverse. In categorical quantum mechanics and related diagrammatic algebraic theories, pattern graphs and their descendants provide finite presentations of arity-parametric laws such as spider fusion and local complementation [1204.6695] [1504.02716]. In chemistry, graph rewrite rules model reaction patterns, with graph grammars generating chemical universes and strategy languages controlling combinatorial explosion [1603.02481]. In biochemical systems, port graph rules and strategies are used to model signaling dynamics, with derivation trees, backtracking, and synchronized quantitative views available in PORGY [1102.2654].

Verification provides another extension point. A class of graph transformation systems with whole neighbourhood operations introduces universally quantified neighborhood conditions on the neighbourhood of nodes. A universally quantified rule \(\rho=(r,U)\) is applied through an instantiation \((\pi,\gamma)\) and a total injective match \(m:\overline{L}\to G\), but only if for every quantified node \(x\in qn(\rho)\), every edge incident to \(m(\pi(x))\) has a preimage in \(\overline{L}\). The paper emphasizes that this is stronger than ordinary negative application conditions and is intended for topology-sensitive distributed protocols such as Dining Philosophers on arbitrary network topologies [1407.4394].

More recent work shows that rewrite-system ideas have also migrated into graph query optimization. Geo models graph mining queries in a rewrite framework based on equality saturation, canonicalization of isomorphic patterns, and embedded reconstructability. Its rewrite language expresses pattern equivalences as rewrite rules and uses e-graphs to explore combinations of equivalences, yielding substantial cost reductions in approximate pattern matching and quasi-clique mining. Although this is not a graph transformation formalism in the original DPO or string-graph sense, it is a clear instance of rewrite-based reasoning over graph patterns rather than over host graphs themselves [2605.26291].

Taken together, these developments show that pattern graph rewrite systems form a family of related formalisms rather than a single technique. The common thread is the use of explicitly structured graph patterns to denote rewrite families, admissible embeddings, or controlled subgraph replacements. The main points of variation are the representation of infinite families, the semantics of matching, the treatment of concurrency and context, and the degree to which rewriting is exposed as a programmable or categorical object.

Source: https://www.emergentmind.com/topics/pattern-graph-rewrite-systems