---
title: Graph Extension Grammars (GEGs)
url: https://www.emergentmind.com/topics/graph-extension-grammars-gegs
type: topic
---

# Graph Extension Grammars (GEGs)

Graph Extension Grammars (GEGs) are a formalism introduced to address the expressive and computational requirements of generating and parsing languages of directed, node- and edge-labelled graphs, particularly supporting non-structural reentrancies as found in semantic representations such as Abstract Meaning Representation (AMR). A GEG consists of an algebra over graphs—incorporating specific graph operations—and a regular tree grammar that generates expressions over these operations. The resulting framework allows specification of sets of graphs with both rich structural constraints and tractable polynomial-time parsing [2105.02033].

## 1. Formal Structure of Graph Extension Grammars

A GEG is fundamentally composed of two interlocked components: (i) a graph-extension algebra specifying operations over families of typed, labelled graphs, and (ii) a regular tree grammar generating terms over those operations. The graph domains are defined as follows:

Let $\Sigma_n$ be a finite set of node-labels and $\Sigma_e$ a finite set of edge-labels. For each nonnegative integer $\tau$, $\mathbb{G}_\tau$ is the set of all finite, directed, node- & edge-labelled graphs $G = (V, E, \ell, port)$ with $|port| = \tau$, where:
- $V$ is a finite set of nodes,
- $E \subseteq V \times \Sigma_e \times V$,
- $\ell \colon V \to \Sigma_n$,
- $port \in V^\tau$ is a sequence of $\tau$ (possibly repeating) nodes called the ports.

The union $\mathbb{G} = \bigcup_{\tau \geq 0} \mathbb{G}_\tau$ collects all such graphs, parameterized by type $\tau$.

### Operations in the Signature

The signature $\mathcal{F}$ comprises two key forms:
- **Binary union** operations $\,\#_{\tau,\tau'} \colon \mathbb{G}_\tau \times \mathbb{G}_{\tau'} \to \mathbb{G}_{\tau + \tau'}\,$, which yield disjoint unions (up to renaming) and concatenate ports.
- **Unary extension** operations $f$ specified by tuples
  $$(V_f, E_f, \ell_f, port_f, dock_f, C_f),$$
  where $V_f, E_f, \ell_f, port_f$ is a graph of type $|port_f|$; $dock_f \in V_f^\tau$ is a sequence of $\tau$ dock-nodes; $C_f \subseteq V_f \setminus (port_f \cup dock_f)$ is the set of "clonable" context nodes. These are subject to:
  - (R1) All edge sources in $E_f$ are from $NEW_f := port_f \setminus dock_f$,
  - (R2) Every non-port node in $V_f$ is a target of some edge in $E_f$.

Extension $f$ is of type $\tau \to \tau'$ where $\tau = |dock_f|$, $\tau' = |port_f|$. The operation $f$ acts nondeterministically by attaching new structure and enabling node-fusion as described below.

The algebra is completed by including the constant operator for the empty graph $\{\lambda\}$ of type 0.

#### Algebraic Semantics

A graph-extension algebra is a many-sorted algebra
$$
A = \left( (_\tau)_{\tau \geq 0},\, (op_A)_{op \in \mathcal{F} \cup \{\}\ } \right)
$$
with $_\tau = \mathcal{P}(\mathbb{G}_\tau)$ and the above-specified operations, producing sets of graphs. Reachability is enforced: every node of every generated graph is reachable from some port-node.

## 2. Regular Tree Grammar Mechanism

A GEG employs a regular, many-sorted tree grammar $g = (N, \mathcal{F}, P, S)$ with finitely many nonterminals $N$, each assigned a type $\sigma(A) = \tau_A$. Productions are of the form
$$
A \to op(A_1, \ldots, A_k),
$$
where $op \in \mathcal{F}$ has type $\tau_{A_1} \ldots \tau_{A_k} \to \tau_A$. The generated tree language $L(g)$ encodes valid sequences of operations.

A full GEG is then
$$
\Gamma = (g, A)
$$
with associated graph language
$$
L(\Gamma) = \bigcup_{t \in L(g)} A-\mathrm{eval}(t)
$$
obtained by recursively mapping derivation trees to their semantic value in the algebra.

Evaluation of $t \in L(g)$ proceeds by induction:
- Base: If $t = S$, $A-\mathrm{eval}(t) \subseteq \mathcal{P}(\mathbb{G}_\tau)$.
- Union: If $t = \#_{\tau_1,\tau_2}[t_1, t_2]$, then $A-\mathrm{eval}(t) = \#_{\tau_1,\tau_2}(A-\mathrm{eval}(t_1), A-\mathrm{eval}(t_2))$.
- Extension: If $t = f[t']$ with $f$ of type $\tau \to \tau'$, then $A-\mathrm{eval}(t) = f(A-\mathrm{eval}(t'))$.

## 3. Non-Structural Reentrancy Modelling

GEGs natively support non-structural reentrancy, a key limitation of prior devices like hyperedge-replacement grammars where only context-free attachments are possible. Non-structural reentrancy refers to allowing nodes in a partially constructed graph to appear multiple times as targets of newly introduced edges, a necessity for capturing phenomena such as shared arguments or referents in AMR.

This is realized in the GEG formalism via the set $C_f$ of clonable context-nodes within each unary extension operation $f$. When $f$ is applied:
- Each $v \in C_f$ can be cloned an arbitrary number of times (non-deterministically).
- Each clone is injectively merged ("fused") to a distinct node of $G$ with the same node-label.
- This process enables one or several new outgoing edges from operations to point to the same node(s) in $G$, thus creating arbitrary non-structural reentrancies.

The use of $C_f$ thus controls and enables the expressive generativity over non-structural reentrancies—an essential feature missing from many prior graph grammar formalisms.

## 4. Parsing Algorithms and Complexity

The challenge of parsing a given graph $G^*$ with respect to a GEG $\Gamma = (g, A)$ is to decide whether $G^* \in L(\Gamma)$. This is determined via the existence of a derivation tree $t \in L(g)$ and an assignment of semantic values yielding exactly $G^*$. GEGs provide a polynomial-time parsing algorithm, summarized as follows:

- The principal recursive routine $Parse\_rec(A, p)$ tests whether the induced subgraph from port-sequence $p \in V^{\tau_A}$ in $G^*$ is derivable by nonterminal $A$.
- Results are memoized in a table $result[A, p]$.
- Union productions and extension rules are handled with explicit splitting or matching logic.
- Matching for extension rules involves fusing dock-nodes to the graph at $p$ and considering all ways context-clones may merge, while preserving labels and the "clone only clonable" constraint.

### Data Structures and Efficiency

Key data structures include:
- Profiles $profile_G(v) = \{ (i, \ell) \mid (p_i, \ell, v) \in E(G^*) \}$ for nodes in $G^*$,
- Likewise, $profile_f(u)$ for nodes in the operation's underlying graph,
to efficiently check compatibility during matching and merging.

### Complexity Summary

With $n = |V(G^*)| + |E(G^*)|$ and $c = \max_{A \in N} \tau_A$, the algorithm executes in time $O(n^{2c+1})$, primarily determined by the combinatorics of ports and clones. Under additional unambiguity constraints on profiles, complexity can be reduced to $O(n^{c+1})$ or even linear time, as per corollaries in the primary reference [2105.02033].

| Parsing Step               | Complexity    | Key Limitation/Optimization        |
|----------------------------|--------------|------------------------------------|
| Memo table computation     | $O(n^c)$     | |$p|$ combinations                  |
| Union production handling  | $O(1)$       | Constant number per nonterminal    |
| Extension handling (naive) | $O(n^{c+1})$ | Filters via profile comparison     |
| Overall (optimized)        | $O(n^{2c+1})$| Profile constraints                |

## 5. Representative Example: Reentrant Graph Generation

Consider a minimal GEG showcasing non-structural reentrancy:
- Node labels: $\Sigma_n = \{a, b\}$,
- Edge labels: $\Sigma_e = \{\alpha\}$,
- Extension op $f$ of type $1 \to 1$:
  - $V_f = \{u_1 \ (\mathrm{port}), u_2 \ (\mathrm{clonable})\}$,
  - $dock_f = [u_1]$, $port_f = [u_1]$, $C_f = \{u_2\}$,
  - $E_f = \{(u_1, \alpha, u_2)\}$,
  - $\ell_f(u_1) = b, \ell_f(u_2) = a$.
- The regular tree grammar uses nonterminals $S$ (type 1), $A$ (type 1), $B$ (type 0), with productions:
  - $S \to f[S]$
  - $S \to \#_{0,1}[B, S]$
  - $B \to \{\}$

In a derivation sequence, repeated applications of $f$ followed by union yield a graph $G^*$ (of type 1) with a "b"-node and two parallel $\alpha$-edges targeting a single "a"-node. Here, the arbitrary cloning and merging induced by $C_f = \{u_2\}$ enables this reentrancy structure, directly modeling the non-structural scenario within the formalism [2105.02033].

## 6. Position within Generative Graph Formalisms and Related Work

GEGs make several advances within the family of generative graph formalisms:
- In comparison to hyperedge-replacement grammars, GEGs transcend the context-free model by enabling arbitrary (non-structural) node-sharing.
- The extension mechanism is inspired in part by concepts such as adaptive star grammars (notably the "cloning" device) [2105.02033].
- The framework is directly motivated by requirements from natural language processing, particularly representations such as AMR, which routinely employ non-structural reentrancies.
- The computational tractability of parsing distinguishes GEGs among more expressive, but intractable, grammar variants.

Connections to prior work include foundational treatments in graph grammar theory [Courcelle & Engelfriet, 2012], as well as device comparisons with weighted DAG automata for semantic graphs [Chiang et al., 2018].

## 7. References

- Björklund, Henrik; Drewes, Frank; Jonsson, Peter: "Polynomial Graph Parsing with Non-Structural Reentrancies" [2105.02033]
- Courcelle, B.; Engelfriet, J.: Graph Structure and MSO Logic (2012).
- Drewes, F.; et al.: Adaptive Star Grammars (2010).
- Chiang, D.; et al.: Weighted DAG Automata for Semantic Graphs (2018).

Source: https://www.emergentmind.com/topics/graph-extension-grammars-gegs