---
abstract: 'In this extended abstract, we present a simple approach to convergence on term graphs that allows us to unify term graph rewriting and infinitary term rewriting. This approach is based on a partial order and a metric on term graphs. These structures arise as straightforward generalisations of the corresponding structures used in infinitary term rewriting. We compare our simple approach to a more complicated approach that we developed earlier and show that this new approach is superior in many ways. The only unfavourable property that we were able to identify, viz. failure of full correspondence between weak metric and partial order convergence, is rectified by adopting a strong convergence discipline.'
author:
- Patrick Bahr
bibliography:
- 'compact.bib'
title: 'Convergence in Infinitary Term Graph Rewriting Systems is Simple (Extended Abstract)[^1]'
---

Introduction {#sec:introduction}
============

In *infinitary term rewriting* [@kennaway03book] we study infinite terms and infinite rewrite sequences. Typically, this extension to infinite structures is formalised by an ultrametric on terms, which yields infinite terms by metric completion and provides a notion of convergence to give meaning to infinite rewrite sequences. In this paper we extend infinitary term rewriting to term graphs. In addition to the metric approach, we also consider the partial order approach to infinitary term rewriting [@bahr10rta2] and generalise it to the setting of term graphs.

One of the motivations for studying infinitary term rewriting is its relation to *non-strict evaluation*, which is used in programming languages such as Haskell [@marlow10haskell]. Non-strict evaluation defers the evaluation of an expression until it is “needed” and thereby allows us to deal with conceptually infinite data structures and computations. For example, the function `from` defined below constructs for each number $n$ the infinite list of consecutive numbers starting from $n$:

    from(n) = n :: from(s(n))

This construction is only conceptual and only results in a terminating computation if it is used in a context where only finitely many elements of the list are “needed”. Infinitary term rewriting provides us with an explicit limit construction to witness the outcome of an infinite computation as it is, for example, induced by `from`. After translating the above function definition to a term rewrite rule $\mathit{from}(x) \to x \cons \mathit{from}(s(x))$, we may derive an infinite rewrite sequence $$\mathit{from}(0) \to 0 \cons \mathit{from}(s(0)) \to 0 \cons s(0)
\cons \mathit{from}(s(s(0))) \to \dots$$ which converges to the infinite term $0 \cons s(0) \cons s(s(0)) \cons
\dots$, which represents the infinite list of numbers $0, 1, 2, \dots$ – as intuitively expected.

Non-strict evaluation is rarely found in isolation, though. Usually, it is implemented as lazy evaluation [@henderson76popl], which complements a non-strict evaluation strategy with *sharing*. The latter avoids duplication of subexpressions by using pointers instead of copying. For example, the function `from` above duplicates its argument `n` – it occurs twice on the right-hand side of the defining equation. A lazy evaluator simulates this duplication by inserting two pointers pointing to the actual argument.

While infinitary term rewriting is used to model the non-strictness of lazy evaluation, term graph rewriting models the sharing part of it. By endowing term graph rewriting with a notion of convergence like in infinitary term rewriting, we aim to unify the two formalisms into one calculus, thus allowing us to model both aspects within the same calculus.

#### Contributions & Outline {#sec:contributions}

At first we recall the basic notions of infinitary term rewriting (Section \[sec:infin-term-rewr\]). Afterwards, we construct a metric and a partial order on term graphs and show that both are suitable as a basis for notions of convergence in term graph rewriting (Section \[sec:graphs-term-graphs\]). Based on these structures we introduce notions of convergence (weak and strong variants) for term graph rewriting and show correspondences between metric-based and partial order-based convergence (Section \[sec:weak-convergence\] and \[sec:strong-convergence\]). We then present soundness and completeness properties of the resulting infinitary term graph rewriting calculi w.r.t. infinitary term rewriting (Section \[sec:soundness\]). Lastly, we compare our calculi with previous approaches (Section \[sec:concluding-remarks\]).

Infinitary Term Rewriting {#sec:infin-term-rewr}
=========================

Before starting with the development of infinitary *term graph* rewriting, we recall the basic notions of infinitary *term* rewriting. Rewrite sequences in infinitary rewriting, also called *reductions*, are sequences of the form $(\phi_\iota)_{\iota<\alpha}$, where each $\phi_\iota$ is a rewrite step from a term $t_\iota$ to $t_{\iota+1}$ in a term rewriting system (TRS) $\calR$, denoted $\phi_\iota\fcolon t_\iota \to[\calR]
t_{\iota+1}$. The length $\alpha$ of such a sequence can be an arbitrary ordinal. For example, the infinite reduction indicated in Section \[sec:introduction\] is the sequence $(\phi^\mathrm{f}_i\fcolon t^\mathrm{f}_i \to[\calR^\mathrm{f}]
t^\mathrm{f}_{i+1})_{i<\omega}$, where $t^\mathrm{f}_i = 0 \cons \dots
\cons s^{i-1}(0) \cons \mathit{from}(s^i(0))$ for all $i<\omega$ and $\calR^\mathrm{f}$ is the TRS consisting of the single rule $\mathit{from}(x)
\to x \cons \mathit{from}(s(x))$.

Metric Convergence {#sec:metric-convergence}
------------------

The above definition of reductions ensures that consecutive rewrite steps are “compatible”, i.e. the result term of the $\iota$-th step, viz. $t_{\iota+1}$, is the start term of the $(\iota+1)$-st step. However, this definition does not relate the start terms of steps at limit ordinal positions to the terms that preceded it. For example, we can extend the abovementioned reduction $(\phi^\mathrm{f}_i)_{i<\omega}$ of length $\omega$, to a reduction $(\phi^\mathrm{f}_i)_{i<\omega+1}$ of length $\omega +1$ using any reduction step $\phi^\mathrm{f}_\omega$, e.g. $\phi^\mathrm{f}_\omega\fcolon \mathit{from}(0) \to 0 \cons
\mathit{from}(s(0))$. In our informal notation this reduction $(\phi^\mathrm{f}_i)_{i<\omega+1}$ reads as follows: $$\mathit{from}(0) \to 0 \cons \mathit{from}(s(0)) \to 0 \cons s(0) \cons \mathit{from}(s(s(0)))
\to \quad \dots\quad \mathit{from}(0) \to 0 \cons \mathit{from}(s(0))$$ Intuitively, this does not make sense since the sequence of terms that precedes the last step intuitively converge to the term $0 \cons s(0)
\cons s(s(0)) \cons \dots$, but not $\mathit{from}(0)$.

In infinitary term rewriting such reductions are ruled out by a notion of convergence and a notion of continuity that follows from it. Typically, this notion of convergence is derived from a metric $\dd$ on the set of (finite and infinite) terms $\iterms$: $\dd(s,t) =
0$ if $s = t$, and $\dd(s,t) = 2^{-d}$ otherwise, where $d$ is the minimal depth at which $s$ and $t$ differ. Using this metric, we may also construct the set of (finite and infinite) terms $\iterms$ by *metric completion* of the metric space $(\terms,\dd)$ of finite terms.

The mode of convergence in the metric space $(\iterms,\dd)$ is the basis for the notion of *weak $\mrs$-convergence* of reductions: a reduction $S = (\phi_\iota\fcolon t_\iota \to[\calR]
t_{\iota+1})_{\iota<\alpha}$ is *weakly $\mrs$-continuous* if $\lim_{\iota\limto\lambda} t_\iota = t_\lambda$ for all limit ordinals $\lambda < \alpha$; it *weakly $\mrs$-converges* to a term $t$, denoted $S\fcolon t_0 \wmato[\calR] t$, if it is weakly $\mrs$-continuous and $\lim_{\iota\limto\wsuc\alpha} t_\iota = t$, where $\wsuc\alpha$ is the length of the underlying sequence of terms $(t_\iota)_{\iota<\wsuc\alpha}$. For example, the reduction $(\phi^\mathrm{f}_i)_{i<\omega}$ weakly $\mrs$-converges to the term $0 \cons s(0) \cons s(s(0)) \cons \dots$; but the sequence $(\phi^\mathrm{f}_i)_{i<\omega+1}$ does not weakly $\mrs$-converge, it is not even weakly $\mrs$-continuous as $\lim_{\iota\limto\omega}t^\mathrm{f}_\iota$ is not $\mathit{from}(0)$.

Weak $\mrs$-convergence is quite a general notion of convergence. For example, given a rewrite rule $a \to a$, we may derive the reduction $a \to a \to \dots$, which weakly $\mrs$-converges to $a$ even though the rule $a \to a$ is applied again and again at the same position. This generality causes many desired properties to break, such as unique normal form properties and compression [@kennaway95ic]. That is why Kennaway et al. [@kennaway95ic] introduced *strong $\mrs$-convergence*, which in addition requires that the depth at which rewrite steps take place tends to infinity as one approaches a limit ordinal: Let $S =
(\phi_\iota\fcolon t_\iota \to[\pi_\iota] t_{\iota+1})_{\iota<\alpha}$ be a reduction, where each $\pi_\iota$ indicates the position at which the step $\phi_\iota$ takes place and $\len{\pi_\iota}$ denotes the length of the position $\pi_\iota$. The reduction $S$ is said to be *strongly $\mrs$-continuous* (resp. *strongly $\mrs$-converge* to $t$, denoted $S\fcolon t_0 \mato t$) if it is weakly $\mrs$-continuous (resp. weakly $\mrs$-converges to $t$) and if $(\len{\pi_\iota})_{\iota<\lambda}$ tends to infinity for all limit ordinals $\lambda < \alpha$ (resp. $\lambda \le \alpha$). For example, the reduction $(\phi^\mathrm{f}_i)_{i<\omega}$ also strongly $\mrs$-converges to the term $0 \cons s(0) \cons s(s(0)) \cons
\dots$. On the other hand, the reduction $a \to a \to \dots$ indicated above weakly $\mrs$-converges to $a$, but it does not strongly $\mrs$-converge to $a$.

Partial Order Convergence {#sec:part-order-conv}
-------------------------

Alternatively to the metric approach illustrated in Section \[sec:metric-convergence\], convergence can also be formalised using a partial order $\lebot$ on terms. The idea to use this partial order for infinitary rewriting goes back to Corradini [@corradini93tapsoft]. The signature $\Sigma$ is extended to the signature $\Sigma_\bot$ by adding a fresh constant symbol $\bot$. When dealing with terms in $\ipterms$, we call terms that do not contain the symbol $\bot$, i.e. terms that are contained in $\iterms$, *total*. We define $s \lebot t$ iff $s$ can be obtained from $t$ by replacing some subterm occurrences in $t$ by $\bot$. Interpreting the term $\bot$ as denoting “undefined”, $\lebot$ can be read as “is less defined than”. The pair $(\ipterms,\lebot)$ is known to form a *complete semilattice* [@goguen77jacm], i.e. it has a least element $\bot$, each directed set $D$ in $(\ipterms,\lebot)$ has a *least upper bound* (*lub*) $\Lub D$, and every *non-empty* set $B$ in $(\ipterms,\lebot)$ has *greatest lower bound* (*glb*) $\Glb
B$. In particular, this means that for any sequence $(t_\iota)_{\iota<\alpha}$ in $(\ipterms,\lebot)$, its *limit inferior*, defined by $\liminf_{\iota \limto \alpha}t_\iota =
\Lub_{\beta<\alpha} \left(\Glb_{\beta \le \iota < \alpha}
  t_\iota\right)$, exists.

In the same way that the limit in the metric space gives rise to weak $\mrs$-continuity/-convergence, the limit inferior gives rise to *weak $\prs$-continuity* and *weak $\prs$-convergence*; simply replace $\lim$ by $\liminf$. We write $S\fcolon t_0 \wpato t$ if a reduction $S$ starting with term $t_0$ weakly $\prs$-converges to $t$. The defining difference between the two approaches is that $\prs$-continuous reductions always $\prs$-converge. The reason for that lies in the complete semilattice structure of $(\ipterms,\lebot)$, which guarantees that the limit inferior always exists (in contrast to the limit in a metric space).

The definition of the strong variant of $\prs$-convergence is a bit different from the one of $\mrs$-convergence, but it follows the same idea: a reduction $(\phi_i\fcolon t_i\to[\pi_i] t_{i+1})_{i<\omega}$ weakly $\mrs$-converges iff the minimal depth $d_i$ at which two consecutive terms $t_i, t_{i+1}$ differ tends to infinity. The strong variant of $\mrs$-convergence is a conservative approximation of this condition; it requires $\len{\pi_i}$ to tend to infinity. This approximation is conservative since $\len{\pi_i} \le d_i$; differences between consecutive terms can only occur below the position at which a rewrite rule was applied.

In the partial order approach we can make this approximation more precise since we have the whole term structure at our disposal instead of only the measure provided by the metric $\dd$. In the case of $\mrs$-convergence, we replaced the actual depth of a minimal difference $d_i$ with its conservative under-approximation $\len{\pi_i}$. For $\prs$-convergence, we replace the glb $t_i \glb
t_{i+1}$, which intuitively represents the common information shared by $t_i$ and $t_{i+1}$, with the conservative under-approximation $\substAtPos{t_i}{\pi_i}{\bot}$, which replaces the redex at position $\pi_i$ in $t_i$ with $\bot$. This term $\substAtPos{t_i}{\pi_i}{\bot}$ – called the *reduction context* of the step $\phi_i\fcolon t_i \to t_{i+1}$ – is a lower bound of $t_i$ and $t_{i+1}$ w.r.t. $\lebot$ and is, thus, also smaller than $t_i \glb t_{i+1}$. The definition of strong $\prs$-convergence is obtained from the definition of weak $\prs$-convergence by replacing $\liminf_{\iota\limto\lambda} t_\iota$ with $\liminf_{\iota\limto\lambda} \substAtPos{t_\iota}{\pi_\iota}{\bot}$.

A reduction $S = (\phi_\iota\fcolon t_\iota \to[\pi_\iota]
t_{\iota+1})_{\iota<\alpha}$ is called *strongly $\prs$-continuous* if $\liminf_{\iota\limto\lambda}
\substAtPos{t_i}{\pi_i}{\bot} = t_\lambda$ for all limit ordinals $\lambda < \alpha$; it *strongly $\prs$-converges* to $t$, denoted $S\fcolon t_0 \pato t$, if it is strongly $\prs$-continuous and either $\liminf_{\iota\limto\alpha} \substAtPos{t_i}{\pi_i}{\bot}
= t$ in case $\alpha$ is a limit ordinal, or $t = t_{\alpha+1}$ otherwise.

The previously mentioned reduction $(\phi^\mathrm{f}_i)_{i<\omega}$ both strongly and weakly $\prs$-converges to the infinite term $0
  \cons s(0) \cons s(s(0)) \cons \dots$ – like in the metric approach. However, while the reduction $a \to a \to \dots$ does not strongly $\mrs$-converge, it strongly $\prs$-converges to the term $\bot$.

The partial order approach has some advantages over the metric approach. As explained above, every $\prs$-continuous reduction is also $\prs$-convergent. Moreover, strong $\prs$-convergence has some properties such as infinitary normalisation and infinitary confluence of orthogonal systems [@bahr10rta2] that are not enjoyed by strong $\mrs$-convergence.

Interestingly, however, the partial order-based notions of convergence are merely conservative extensions of the metric-based ones:

\[thr:strongExt\] For every reduction $S$ in a TRS, the following equivalences hold:

$S\fcolon s \wmato t$ iff $S\fcolon s \wpato t$ in $\iterms$.\[item:strongExtI\]

$S\fcolon s \mato t$ iff $S\fcolon s \pato t$ in $\iterms$.\[item:strongExtII\]

The phrase “in $\iterms$” means that all terms in $S$ are total (including $t$). That is, if restricted to total terms, $\mrs$- and $\prs$-convergence coincide.

Graphs and Term Graphs {#sec:graphs-term-graphs}
======================

In this section, we present our notion of term graphs and generalise the metric $\dd$ and the partial order $\lebot$ from terms to term graphs.

Our notion of graphs and term graphs is largely taken from Barendregt et al. [@barendregt87parle].

\[def:graph\] A *graph* over signature $\Sigma$ is a triple $g =
  (N,\glab,\gsuc)$ consisting of a set $N$ (of *nodes*), a *labelling function* $\glab\fcolon N \funto \Sigma$, and a *successor function* $\gsuc\fcolon N \funto N^*$ such that $\len{\gsuc(n)} = \srank{\glab(n)}$ for each node $n\in N$, i.e. a node labelled with a $k$-ary symbol has precisely $k$ successors. If $\gsuc(n) = \seq{n_0,\dots,n_{k-1}}$, then we write $\gsuc_{i}(n)$ for $n_i$.

The successor function $\gsuc$ defines, for each node $n$, directed edges from $n$ to $\gsuc_i(n)$. A path from a node $m$ to a node $n$ is a finite sequence $\seq{e_0,\dots,e_l}$ of numbers such that $n=\gsuc_{e_l}(\dots \gsuc_{e_0}(m))$, i.e. $n$ is reached from $m$ by taking the $e_0$-th edge, then the $e_1$-th edge etc.

\[def:tgraph\] A *term graph* $g$ over $\Sigma$ is a tuple $(N,\glab,\gsuc,r)$ consisting of an *underlying* graph $(N,\glab,\gsuc)$ over $\Sigma$ whose nodes are all reachable from the *root node* $r\in N$. The class of all term graphs over $\Sigma$ is denoted $\itgraphs$. A *position* of $n \in N$ in $g$ is a path in the underlying graph of $g$ from $r$ to $n$. The set of all positions of $n$ in $g$ is denoted $\nodePos{g}{n}$. The *depth* of $n$ in $g$, denoted $\depth{g}{n}$, is the minimum of the lengths of the positions of $n$ in $g$, i.e. $\depth{g}{n} = \min
  \setcom{\len{\pi}}{\pi \in \nodePos{g}{n}}$. The term graph $g$ is called a *term tree* if each node in $g$ has exactly one position. We use the notation $N^{g}$, $\glab^{g}$, $\gsuc^{g}$ and $r^{g}$ to refer to the respective components $N$,$\glab$, $\gsuc$ and $r$ of $g$. Given a graph or a term graph $h$ and a node $n$ in $h$, we write $\subgraph{h}{n}$ to denote the sub-term graph of $h$ rooted in $n$.

The notion of homomorphisms is crucial for dealing with term graphs. For greater flexibility, we will parametrise this notion by a set of constant symbols $\Delta$ for which the homomorphism condition is suspended. This will allow us to deal with variables and partiality appropriately.

\[def:D-hom\] Let $\Sigma$ be a signature, $\Delta\subseteq \Sigma^{(0)}$, and $g,h \in \itgraphs$. A *$\Delta$-homomorphism* $\phi$ from $g$ to $h$, denoted $\phi\fcolon g \homto_\Delta h$, is a function $\phi\fcolon N^g \funto N^h$ with $\phi(r^g) = r^h$ that satisfies the following equations for all for all $n \in N^g$ with $\glab^g(n)
  \nin \Delta$: $$\begin{aligned}
    \glab^g(n) &= \glab^h(\phi(n))
    \tag{labelling}\\
    \phi(\gsuc^g_i(n)) &= \gsuc^h_i(\phi(n)) \quad \text{ for all } 0 \le i <
    \srank{\glab^g(n)} \tag{successor}
  \end{aligned}$$

Note that, for $\Delta = \emptyset$, we get the usual notion of homomorphisms on term graphs (e.g. Barendsen [@barendsen03book]) and from that the notion of isomorphisms. The nodes labelled with symbols in $\Delta$ can be thought of as holes in the term graphs that can be filled with other term graphs.

We do not want to distinguish between isomorphic term graphs. Therefore, we use a well-known trick [@plump99hggcbgt] to obtain canonical representatives of isomorphism classes of term graphs.

\[def:canTgraph\] A term graph $g$ is called *canonical* if $n = \nodePos{g}{n}$ holds for each $n \in N^g$. That is, each node is the set of its positions in the term graph. The set of all (finite) canonical term graphs over $\Sigma$ is denoted $\ictgraphs$ (resp. $\ctgraphs$). For each term graph $h \in \ictgraphs$, its *canonical representative* $\canon{h}$ is obtained from $h$ by replacing each node $n$ in $h$ by $\nodePos{h}{n}$.

This construction indeed yields a canonical representation of isomorphism classes. More precisely: $g \isom \canon g$ for all $g\in\itgraphs$, and $g \isom h$ iff $\canon g = \canon h$ for all $g,h \in \itgraphs$.

We consider the set of terms $\iterms$ as the subset of canonical term trees of $\ictgraphs$. With this correspondence in mind, we can define the *unravelling* of a term graph $g$ as the unique term $\unrav g$ such that there is a homomorphism $\phi\fcolon \unrav g
\homto g$. For example, $g_0$ from Figure \[fig:convWeird\] is the unravelling of $g_1$, and $h_0$ and $g_\omega$ from Figure \[fig:fixedPointComb\] both unravel to the infinite term $@(f,@(f,\dots))$. Term graphs that unravel to the same term are called *bisimilar*.

A Simple Partial Order on Term Graphs {#sec:simple-partial-order}
-------------------------------------

In this section, we want to establish a partial order suitable for formalising convergence of sequences of canonical term graphs similarly to weak $\prs$-convergence on terms.

Weak $\prs$-convergence on term rewriting systems is based on the partial order $\lebot$ on $\ipterms$, which instantiates occurrences of $\bot$ from left to right, i.e. $s \lebot t$ iff $t$ is obtained by replacing occurrences of $\bot$ in $s$ by arbitrary terms in $\ipterms$. Analogously, we consider the class of *partial term graphs* simply as term graphs over the signature $\Sigma_\bot =
\Sigma \uplus \set{\bot}$. In order to generalise the partial order $\lebot$ to term graphs, we need to formalise the instantiation of occurrences of $\bot$ in term graphs. For this purpose, we shall use $\Delta$-homomorphisms with $\Delta=\set\bot$, or $\bot$-homomorphisms for short. A $\bot$-homomorphism $\phi\colon g \to_\bot h$ maps each node in $g$ to a node in $h$ while “preserving its structure”. Except for nodes labelled $\bot$ this also includes preserving the labelling. This exception to the homomorphism condition allows the $\bot$-homomorphism $\phi$ to instantiate each $\bot$-node in $g$ with an arbitrary node in $h$. Using $\bot$-homomorphisms, we arrive at the following definition for our simple partial order $\lebots$ on term graphs:

For each $g,h \in \ipctgraphs$, define $g \lebots h$ iff there is some $\phi\fcolon g \homto_\bot h$.

One can verify that $\lebots$ indeed generalises the partial order $\lebot$ on terms. Considering terms as canonical term trees, we obtain the following characterisation of $\lebot$ on terms $s,t\in
\ipterms$: $$s \lebot t \iff \text{ there is a $\bot$-homomorphism } \phi\fcolon s
\homto_\bot t.$$

The first important result for $\lebots$ is that the semilattice structure that we already had for $\lebot$ is preserved by this generalisation:

\[thr:complSemilattice\] The partially ordered set $(\ipctgraphs,\lebots)$ forms a complete semilattice.

For terms, we already know that the set of (potentially infinite) terms can be constructed by forming the *ideal completion* of the partially ordered set $(\pterms,\lebot)$ of finite terms [@berry77popl]. More precisely, the ideal completion of $(\pterms,\lebot)$ is order isomorphic to $(\ipterms,\lebot)$.

An analogous result can be shown for term graphs:

\[thr:idealCompletion\] The ideal completion of $(\pctgraphs, \lebots)$ is order isomorphic to $(\ipctgraphs,\lebots)$.

A Simple Metric on Term Graphs {#sec:simple-metric-term}
------------------------------

Next, we shall generalise the metric $\dd$ from terms to term graphs. To achieve this, we need to formalise what it means for two term graphs to coincide up to a certain depth, so that we can reformulate the definition of the metric $\dd$ for term graphs. To this end, we follow the same idea that the original definition of $\dd$ on terms from Arnold and Nivat [@arnold80fi] was based on. In particular, we introduce a truncation construction that cuts off nodes below a certain depth:

\[def:trunca\] Let $g \in \iptgraphs$ and $d \le \omega$. The *simple truncation* $\truncs{g}{d}$ of $g$ at $d$ is the term graph defined as follows: $$\begin{aligned}
    N^{\truncs{g}{d}} &= \setcom{n \in N^g}{\depth{g}{n} \le d}
    & r^{\truncs{g}{d}} &= r^g
    \\
    \glab^{\truncs{g}{d}}(n) &= 
    \begin{cases}
      \glab^g(n) &\text{if } \depth{g}{n} < d \\
      \bot  &\text{if } \depth{g}{n} = d
    \end{cases} &
    \gsuc^{\truncs{g}{d}}(n) &=
    \begin{cases}
      \gsuc^g(n) &\text{ if }\depth{g}{n} < d\\
      \emptyseq &\text{ if }\depth{g}{n} = d
    \end{cases}
  \end{aligned}$$

The definition of the simple metric $\dds$ follows straightforwardly:

The *simple distance* $\dds\fcolon \ictgraphs \times \ictgraphs
  \to \realsnn$ is defined as follows: $$\begin{gathered}
    \dds(g,h) =
    \begin{cases}
      0&\text{if } g = h\\      2^{-d}&\text{if } g \neq h \text{ and } d
      =\max\setcom{e<\omega}{\truncs{g}{e}\isom\truncs{h}{e}}
    \end{cases}
  \end{gathered}$$

Again, we can verify that $\dds$ generalises $\dd$. In particular, we can show that our notion of truncation coincides with that of Arnold and Nivat [@arnold80fi] if restricted to terms.

As desired, this generalisation retains the complete ultrametric space structure:

\[thr:smetricComplete\] The pair $(\ictgraphs,\dds)$ forms a complete ultrametric space.

The metric space analogue to ideal completion is metric completion. On terms, we already know that we can construct the set of (potentially infinite) terms $\iterms$ by metric completion of the metric space $(\terms,\dd)$ of finite terms [@barr93tcs]. More precisely, the metric completion of $(\terms,\dd)$ is the metric space $(\iterms,\dd)$. This property generalises to term graphs as well:

\[thr:metricCompletion\] The metric completion of $(\ctgraphs,\dds)$ is the metric space $(\ictgraphs,\dds)$.

(r1) [$f$]{} child[ node (n1) [$c$]{} ]{} child[ node (n2) [$c$]{} ]{}; (r2) [$f$]{} child [ node (n2) [$c$]{} edge from parent\[transparent\] ]{}; (r2) edge \[bend right=25\] (n2) edge \[bend left=25\] (n2); (r1) – (r2); (r3) [$f$]{} child[ node (n1) [$c$]{} ]{} child[ node (n2) [$c$]{} ]{}; (r2) – (r3); (r4) [$f$]{} child [ node (n2) [$c$]{} edge from parent\[transparent\] ]{}; (r4) edge \[bend right=25\] (n2) edge \[bend left=25\] (n2); (r3) – (r4);

(r5) [$f$]{} child[ node (n1) [$c$]{} ]{} child[ node (n2) [$c$]{} ]{}; (r4) – (r5);

; ; ; ; ;

Infinitary Term Graph Rewriting {#sec:infin-term-graph}
===============================

In this paper, we adopt the term graph rewriting framework of Barendregt et al. [@barendregt87parle]. In order to represent placeholders in rewrite rules, we use variables – in a manner much similar to term rewrite rules. To this end, we consider a signature $\Sigma_\calV = \Sigma\uplus\calV$ that extends the signature $\Sigma$ with a set $\calV$ of nullary variable symbols.

Given a signature $\Sigma$, a *term graph rule* $\rho$ over $\Sigma$ is a triple $(g,l,r)$ where $g$ is a graph over $\Sigma_\calV$ and $l,r \in N^g$ such that all nodes in $g$ are reachable from $l$ or $r$. We write $\lhs\rho$ resp. $\rhs\rho$ to denote the left- resp. right-hand side of $\rho$, i.e. the term graph $\subgraph{g}{l}$ resp. $\subgraph{g}{r}$. Additionally, we require that for each variable $v\in\calV$ there is at most one node $n$ in $g$ labelled $v$, and we have that $n \neq l$ and that $n$ is reachable from $l$ in $g$. A *term graph rewriting system (GRS)* $\calR$ is a pair $(\Sigma,R)$ with $\Sigma$ a signature and $R$ a set of term graph rules over $\Sigma$.

The notion of unravelling straightforwardly extends to term graph rules: the *unravelling* of a term graph rule $\rho$, denoted $\unrav{\rho}$, is the term rule $\unrav{\rho_l} \to
\unrav{\rho_r}$. The unravelling of a GRS $\calR=(\Sigma,R)$, denoted $\unrav{\calR}$, is the TRS $(\Sigma,\setcom{\unrav{\rho}}{\rho\in
  R})$.

\[ex:fixedPointCombRules\] Figure \[fig:fixedPointCombA\] shows two term graph rules which both unravel to the term rule $\rho\fcolon @(Y, x) \to @(x,@(Y,x))$ that defines the fixed point combinator $Y$. Note that sharing of nodes is used both to refer to variables in the left-hand side from the right-hand side and in order to simulate duplication.

Without going into all details of the construction, we describe the application of a rewrite rule $\rho$ with root nodes $l$ and $r$ to a term graph $g$ in four steps: at first a suitable sub-term graph of $g$ rooted in some node $n$ of $g$ is *matched* against the left-hand side of $\rho$. This matching amounts to finding a $\calV$-homomorphism $\phi$ from the left-hand side $\lhs\rho$ to $\subgraph{g}{n}$, the *redex*. The $\calV$-homomorphism $\phi$ allows us to instantiate variables in the rule with sub-term graphs of the redex. In the second step, nodes and edges in $\rho$ that are not in $\lhs\rho$ are copied into $g$, such that each edge pointing to a node $m$ in $\lhs\rho$ is redirected to $\phi(m)$. In the next step, all edges pointing to the root $n$ of the redex are redirected to the root $n'$ of the *contractum*, which is either $r$ or $\phi(r)$, depending on whether $r$ has been copied into $g$ or not (because it is reachable from $l$ in $\rho$). Finally, all nodes not reachable from the root of (the now modified version of) $g$ are removed. With $h$ the result of the above construction, we obtain a *pre-reduction step* $\psi\fcolon g \preto[n] h$ from $g$ to $h$.

The definition of term graph rewriting in the form of pre-reduction steps is very operational. While this style is beneficial for implementing a rewriting system, it is problematic for reasoning on term graphs modulo isomorphism, which is necessary for introducing notions of convergence. However, one can easily see that the construction of the result term graph of a pre-reduction step is invariant under isomorphism, which justifies the following definition of reduction steps:

Let $\calR = (\Sigma,R)$ be GRS, $\rho \in R$ and $g,h \in
  \ictgraphs$ with $n \in N^g$ and $m\in N^h$. A tuple $\phi =
  (g,n,h)$ is called a *reduction step*, written $\phi\fcolon g
  \to[n] h$, if there is a pre-reduction step $\phi'\fcolon g'
  \preto[n'] h'$ with $\canon{g'} = g$, $\canon{h'} = h$, and $n =
  \nodePos{g'}{n'}$. We also write $\phi\fcolon g \to[\calR] h$ to indicate $\calR$.

In other words, a reduction step is a canonicalised pre-reduction step. Figure \[fig:fixedPointCombB\] and Figure \[fig:fixedPointCombC\] illustrate some (pre-)reduction steps induced by the rules $\rho_1$ respectively $\rho_2$ shown in Figure \[fig:fixedPointCombA\].

Weak Convergence {#sec:weak-convergence}
----------------

In analogy to infinitary term rewriting, we employ the partial order $\lebots$ and the metric $\dds$ for the purpose of defining convergence of transfinite term graph reductions.

Let $\calR = (\Sigma,R)$ be a GRS.

(i) Let $S = (g_\iota \to_\calR g_{\iota+1})_{\iota < \alpha}$ be a reduction in $\calR$. $S$ is *weakly $\mrs$-continuous* in $\calR$ if $\lim_{\iota\limto\lambda} g_\iota = g_\lambda$ for each limit ordinal $\lambda < \alpha$. $S$ *weakly $\mrs$-converges* to $g \in \ictgraphs$ in $\calR$, written $S\fcolon g_0 \wmato[\calR] g$, if it is weakly $\mrs$-continuous and $\lim_{\iota\limto\wsuc\alpha} g_\iota = g$.

(ii) Let $\calR_\bot$ be the GRS $(\Sigma_\bot, R)$ over the extended signature $\Sigma_\bot$ and $S = (g_\iota \to[\calR_\bot]
        g_{\iota+1})_{\iota < \alpha}$ a reduction in $\calR_\bot$. $S$ is *weakly $\prs$-continuous* in $\calR$ if $\liminf_{\iota<\lambda} g_i = g_\lambda$ for each limit ordinal $\lambda < \alpha$. $S$ *weakly $\prs$-converges* to $g\in\ipctgraphs$ in $\calR$, written $S\fcolon g_0 \wpato[\calR]
        g$, if it is weakly $\prs$-continuous and $\liminf_{\iota<\wsuc\alpha} g_i = g$.

\[ex:fixedPointCombWeak\] Figure \[fig:fixedPointCombC\] illustrates an infinite reduction derived from the rule $\rho_1$ in Figure \[fig:fixedPointCombA\]. Since $\truncs{g_i}{(i+1)} \isom \truncs{g_\omega}{(i+1)}$ for all $i < \omega$, we have that $\lim_{i \limto \omega} g_i = g_\omega$, which means that the reduction weakly $\mrs$-converges to the term graph $g_\omega$. Moreover, since each node in $g_\omega$ eventually appears in a term graph in $(g_i)_{i<\omega}$ and remains stable afterwards, we have $\liminf_{i\limto\omega}g_\iota =
  g_\omega$. Consequently, the reduction also weakly $\prs$-converges to $g_\omega$.

Recall that weak $\prs$-convergence for TRSs is a conservative extension of weak $\mrs$-convergence (cf.Theorem \[thr:strongExt\]). The key property that makes this possible is that for each sequence $(t_\iota)_{\iota<\alpha}$ in $\iterms$, we have that $\lim_{\iota\limto\alpha} t_\iota =
\liminf_{\iota\limto\alpha} t_\iota$ whenever $(t_\iota)_{\iota<\alpha}$ converges, or $\liminf_{\iota\limto\alpha}
t_\iota$ is a total term. Sadly, this is not the case for the metric space and the partial order on term graphs: the sequence of term graphs depicted in Figure \[fig:convWeird\] has a total term graph as its limit inferior, viz. $g_\omega$, although it does not converge in the metric space. In fact, since the sequence in Figure \[fig:convWeird\] alternates between two distinct term graphs, it does not converge in any Hausdorff space, i.e. in particular, it does not converge in any metric space.

This example shows that we cannot hope to generalise the compatibility property that we have for terms: even if a sequence of total term graphs has a total term graph as its limit inferior, it might not converge. However, the converse direction of the correspondence does hold true:

\[thr:limLiminf\] If $(g_\iota)_{\iota<\alpha}$ converges, then $\lim_{\iota\limto\alpha} g_\iota = \liminf_{\iota\limto\alpha}
  g_\iota$.

From this property, we obtain the following relation between weak $\mrs$- and $\prs$-convergence:

Let $S$ be a reduction in a GRS $\calR$. $\text{If}\quad S\fcolon g \wmato[\calR] h \qquad \text{then} \qquad
  S\fcolon g \wpato[\calR] h.$

As indicated above, weak $\mrs$-convergence is not the total fragment of weak $\prs$-convergence as it is the case for TRSs, i.e. the converse of the above implication does not hold in general:

\[ex:rulesWeird\] There is a GRS that yields the reduction shown in Figure \[fig:convWeird\], which weakly $\prs$-converges to $g_\omega$ but is not weakly $\mrs$-convergent. This reduction can be produced by alternately applying the rules $\rho_1,\rho_2$, where the left hand side of both rules and the right-hand side of $\rho_1$ is $g_0$, and the right-hand side of $\rho_2$ is $g_1$.

Strong Convergence {#sec:strong-convergence}
------------------

The idea of strong convergence is to conservatively approximate the convergence behaviour somewhat independently from the actual rewrite rules that are applied. Strong $\mrs$-convergence in TRSs requires that the depth of the redexes tends to infinity thereby assuming that anything at the depth of the redex or below is potentially affected by a reduction step. Strong $\prs$-convergence, on the other hand, uses a better approximation that only assumes that the redex is affected by a reduction step – not however other subterms at the same depth. To this end strong $\prs$-convergence uses a notion of reduction contexts – essentially the term minus the redex – for the formation of limits. The following definition provides the construction for the notion of reduction contexts that we shall use for term graph rewriting:

\[def:truncl\] Let $g \in \iptgraphs$ and $n \in N^g$. The *local truncation* of $g$ at $n$, denoted $\truncl{g}{n}$, is obtained from $g$ by labelling $n$ with $\bot$ and removing all outgoing edges from $n$ as well as all nodes that thus become unreachable from the root.

\[prop:stepContext\] Given a reduction step $g \to[n] h$, we have $\truncl{g}{n} \lebots g, h$.

This means that the local truncation at the root of the redex is preserved by reduction steps and is therefore an adequate notion of reduction context for strong $\prs$-convergence [@bahr10rta]. Using this construction we can define strong $\prs$-convergence on term graphs analogously to strong $\prs$-convergence on terms. For strong $\mrs$-convergence, we simply take the same notion of depth that we already used for the definition of the simple truncation $\truncs{g}{d}$ and thus the simple metric $\dds$.

Let $\calR = (\Sigma,R)$ be a GRS.

(i) The *reduction context* $c$ of a graph reduction step $\phi\fcolon g \to[n] h$ is the term graph $\canon{\truncl{g}{n}}$. We write $\phi\fcolon g \to[c] h$ to indicate the reduction context of a graph reduction step.

(ii) Let $S = (g_\iota \to[n_\iota] g_{\iota+1})_{\iota<\alpha}$ be a reduction in $\calR$. $S$ is *strongly $\mrs$-continuous* in $\calR$ if $\lim_{\iota \limto \lambda} g_\iota = g_\lambda$ and $(\depth{g_\iota}{n_\iota})_{\iota<\lambda}$ tends to infinity for each limit ordinal $\lambda < \alpha$. $S$ *strongly $\mrs$-converges* to $g$ in $\calR$, denoted $S\fcolon g_0
        \mato[\calR] g$, if it is strongly $\mrs$-continuous and either $S$ is closed with $g = g_\alpha$ or $S$ is open with $g =
        \lim_{\iota \limto \alpha} g_\iota$ and $(\depth{g_\iota}{n_\iota})_{\iota<\alpha}$ tending to infinity.

(iii) Let $S = (g_\iota \to[c_\iota] g_{\iota+1})_{\iota<\alpha}$ be a reduction in $\calR_\bot=(\Sigma_\bot,R)$. $S$ is *strongly $\prs$-continuous* in $\calR$ if $\liminf_{\iota \limto \lambda}
        c_\iota = g_\lambda$ for each limit ordinal $\lambda <
        \alpha$. $S$ *strongly $\prs$-converges* to $g$ in $\calR$, denoted $S\fcolon g_0 \pato[\calR] g$, if it is strongly $\prs$-continuous and either $S$ is closed with $g = g_\alpha$ or $S$ is open with $g = \liminf_{\iota \limto \alpha} c_\iota$.

As explained in Example \[ex:fixedPointCombWeak\], the reduction in Figure \[fig:fixedPointCombC\] both weakly $\mrs$- and $\prs$-converges to $g_\omega$. Because contraction takes place at increasingly large depth, the reduction also strongly $\mrs$-converges to $g_\omega$. Moreover, since each node in $g_\omega$ eventually appears also in the sequence of reduction contexts $(c_i)_{i<\omega}$ of the reduction and remains stable afterwards, we have that $\liminf_{i\limto\omega}c_i =
  g_\omega$. Consequently, the reduction also strongly $\prs$-converges to $g_\omega$.

Remarkably, one of the advantages of the strong variant of convergence is that we regain the correspondence between $\mrs$- and $\prs$-convergence that we know from infinitary term rewriting:

\[thr:graphExt\] Let $\calR$ be a GRS and $S$ a reduction in $\calR_\bot$. We then have that

$S\fcolon g \mato[\calR] h$ $S\fcolon g
    \pato[\calR] h$ in $\ictgraphs$.

In particular, the GRS given in Example \[ex:rulesWeird\] that induces the reduction depicted in Figure \[fig:convWeird\] does not provide a counterexample for the “if” direction of the above equivalence – in contrast to weak convergence. The reduction in Figure \[fig:convWeird\] does not strongly $\mrs$-converge but it does strongly $\prs$-converge to the term graph $\bot$, which is in accordance with Theorem \[thr:graphExt\] above.

Soundness and Completeness {#sec:soundness}
--------------------------

In order to assess the value of the modes of convergence on term graphs that we introduced in this paper, we need to compare them to the well-established counterparts on terms. Ideally, we would like to see a strong connection between converging reductions in a GRS $\calR$ and converging reductions in the TRS $\unrav{\calR}$ in the form of soundness and completeness properties. For example, for $\mrs$-convergence we want to see that $g \wmato[\calR] h$ implies $\unrav g \wmato[\unrav{\calR}] \unrav h$ – i.e. soundness – and vice versa that $\unrav g \wmato[\unrav{\calR}] t$ implies $g
\wmato[\calR] h$ with $\unrav h = t$ – i.e. completeness.

Completeness is already an issue for finitary rewriting [@kennaway94toplas]: a single term graph redex may correspond to several term redexes due to sharing. Hence, contracting a term graph redex may correspond to several term rewriting steps, which may be performed independently.

In the context of weak convergence, also soundness becomes an issue. The underlying reason for this issue is similar to the phenomenon explained above: a single term graph rewrite step may represent several term rewriting steps, i.e. $g \to[\calR] h$ implies $\unrav g \fto+[\unrav\calR]\unrav h$.[^2] When we have a converging term graph reduction $(\phi_\iota\fcolon
g_\iota \to g_{\iota+1})_{\iota<\alpha}$, we know that the underlying sequence of term graphs $(g_\iota)_{\iota<\wsuc\alpha}$ converges. However, the corresponding term reduction does not necessarily produce the sequence $(\unrav{g_\iota})_{\iota<\wsuc\alpha}$ but may intersperse the sequence $(\unrav{g_\iota})_{\iota<\wsuc\alpha}$ with additional intermediate terms, which might change the convergence behaviour.

While we cannot prove soundness for weak convergence due to the abovementioned problems, we can show that the underlying modes of convergence are sound in the sense that convergence is preserved under unravelling.

\[thr:unravLim\]

(i) $\lim_{\iota\limto\alpha} g_\iota = g$ implies $\lim_{\iota\limto\alpha} \unrav{g_\iota} = \unrav g$ for every sequence $(g_\iota)_{\iota<\alpha}$ in $(\ictgraphs,\dds)$.

(ii) $\unrav{\liminf_{\iota\limto\alpha}g_\iota} =
        \liminf_{\iota\limto\alpha}\unrav{g_\iota}$ for every sequence $(g_\iota)_{\iota<\alpha}$ in $(\ipctgraphs,\lebots)$.

Note that the above theorem in fact implies soundness of the modes of convergence on term graphs with the modes of convergence on terms since both $\dds$ and $\lebots$ specialise to $\dd$ respectively $\lebot$ if restricted to term trees.

However, we can observe that strong convergence is more well-behaved than weak convergence. It is possible to prove soundness and completeness properties for strong $\prs$-convergence:

\[thr:pConvSoundCompl\] Let $\calR$ be a left-finite GRS.

(i) If $\calR$ is left-linear and $g \pato[\calR] h$, then $\unrav{g} \pato[\unrav{\calR}] \unrav{h}$.

(ii) If $\calR$ is orthogonal and $\unrav{g} \pato[\unrav\calR] t$, then there are reductions $g \pato[\calR] h$ and $t
        \pato[\unrav\calR] \unrav{h}$.

Note that the above completeness property is not the one that one would initially expect, namely $\unrav g \pato[\unrav{\calR}] t$ implies $g \pato[\calR] h$ with $\unrav h = t$. But this general completeness property is known to already fail for finitary term graph rewriting [@kennaway94toplas].

The soundness and completeness properties above have an important practical implication: GRSs that only differ in their sharing, i.e.they unravel to the same TRS, will produce the same results, i.e. the same normal forms up to bisimilarity. GRSs with more sharing may, however, reach a result with fewer steps. This can be observed in Figure \[fig:fixedPointComb\], which depicts two rules $\rho_1,
\rho_2$ that unravel to the same term rule. Rule $\rho_1$ reaches $g_\omega$ in $\omega$ steps whereas $\rho_2$ reaches a term graph $h_0$, which is bisimilar to $g_\omega$, in one step.

The situation for strong $\mrs$-convergence is not the same as for strong $\prs$-convergence. While we do have soundness under the same preconditions, i.e. $g \mato[\calR] h$ implies $\unrav{g}
\mato[\unrav{\calR}] \unrav{h}$, the completeness property we have seen in Theorem \[thr:pConvSoundCompl\] fails. This behaviour was already recognised by Kennaway et al. [@kennaway94toplas]. Nevertheless, we can find a weaker form of completeness that is restricted to normalising reductions:

Given an orthogonal, left-finite GRS $\calR$ that is normalising w.r.t. strongly $\mrs$-converging reductions, we find for each normalising reduction $\unrav{g} \mato[\unrav\calR] t$ a reduction $g \mato[\calR] h$ such that $t = \unrav{h}$.

Concluding Remarks {#sec:concluding-remarks}
==================

We have devised two independently defined but closely related infinitary calculi of term graph rewriting. This is not the first proposal for infinitary term graph rewriting calculi; in previous work [@bahr12lmcs] we presented a so-called *rigid* approach based on a metric and a partial order different from the structures presented here.

There are several arguments why the simple approach presented in this paper is superior to the rigid approach. First of all it is simpler. The rigid metric and partial order have been carefully crafted in order to obtain a correspondence result in the style of Theorem \[thr:strongExt\] for weak convergence on term graphs. This correspondence result of the rigid approach is not fully matched by the simple approach that we presented here, but we do regain the full correspondence by moving to strong convergence.

Secondly, the rigid approach is very restrictive, disallowing many reductions that are intuitively convergent. For example, in the rigid approach the reduction depicted in Figure \[fig:fixedPointCombC\], would not $\prs$-converge (weakly or strongly) to the term graph $g_\omega$ as intuitively expected but instead to the term graph obtained from $g_\omega$ by replacing $f$ with $\bot$. Moreover, this sequence would not $\mrs$-converge (weakly or strongly) at all.

Lastly, as a consequence of the restrictive nature of the rigid approach, the completion constructions of the underlying metric and partial order do not yield the full set of term graphs – in contrast to our findings here in Theorem \[thr:idealCompletion\] and \[thr:metricCompletion\].

Unfortunately, we do not have solid soundness or completeness results for weak convergence apart from the preservation of convergence under unravelling and the metric/ideal completion construction of the set of term graphs. However, as we have shown, this shortcoming is again addressed by moving to strong convergence.

[^1]: The full version of this paper will appear in Mathematical Structures in Computer Science [@bahr13mscs].

[^2]: If the term graph $g$ is cyclic, the corresponding term reduction may even be infinite.
