---
title: Graded Quantitative Rewriting Theory
url: https://www.emergentmind.com/topics/graded-quantitative-rewriting
type: topic
---

# Graded Quantitative Rewriting Theory

Graded quantitative rewriting is a theory of rewriting in which reduction steps carry quantitative information—such as distance, cost, degree, or resource usage—valued in a quantale, and in which contexts act on these quantities through an explicit graded structure, typically given by quantale homomorphisms or change-of-base endomorphisms. In its contemporary form, the subject combines several strands: quantale-enriched abstract rewriting and term rewriting, graded context sensitivity and balanced substitution, coalgebraic graded semantics via graded monads, and quantitative narrowing for solving equations modulo graded rewrite theories. The resulting framework refines classical rewriting theory by replacing reachability, convertibility, and confluence with quantitative analogues, while also supporting modal, coeffectful, and trace-based interpretations of computation [2206.13610] [2507.19630] [2306.01487].

## 1. Quantitative foundations

The underlying quantitative domain is a quantale. One standard presentation writes a quantale as
\[
\mathbb{V} = (V,\le,k,\otimes),
\]
where \((V,\le)\) is a complete lattice, \((V,\otimes,k)\) is a commutative monoid, and \(\otimes\) distributes over arbitrary joins. A closely related notation uses
\[
\mathbb{\Omega} = (\Omega,\leq,\otimes,\kappa),
\]
with the same structural requirements. The graded rewriting literature concentrates on commutative, integral, cointegral, non-trivial quantales, often called Lawvereian; the guiding example is the Lawvere quantale
\[
L = \big([0,\infty],\ \ge,\ 0,\ +\big),
\]
where the order is reversed so that smaller metric distances correspond to larger elements [2206.13610] [2507.19630].

A quantitative relation is a quantale-valued relation. In one formulation, a \(\mathbb{V}\)-relation \(R:A\multimap B\) is a map
\[
R:A\times B\to V,
\]
with relational composition
\[
(R;S)(a,c)=\bigvee_{b\in B} R(a,b)\otimes S(b,c).
\]
In another, equivalent ternary presentation, one works with \(R\subseteq A\times \Omega\times B\), where the middle component records the degree of the step. The diagonal relation
\[
\Delta_A(a,a)=k,\qquad \Delta_A(a,b)=\bot\ (a\neq b)
\]
or
\[
\Delta_{\mathbb{\Omega},A}=\{(a,\kappa,a)\mid a\in A\}
\]
acts as identity. Reflexivity, symmetry, and transitivity then generalize the usual metric or preorder axioms. In the Lawvere case, equivalence \(\mathbb{V}\)-relations are exactly pseudometrics [2206.13610].

A quantitative abstract rewriting system is therefore a pair \((A,R)\) with \(R:A\multimap A\). Its closures are defined by the standard relational operations:
\[
R^0=\Delta_A,\qquad R^{n+1}=R;R^n,\qquad R^*=\bigvee_{n\ge 0}R^n.
\]
The symmetric and convertibility closures yield quantitative analogues of bidirectional rewriting. For a path
\[
a = a_0 \xrightarrow{w_1} a_1 \xrightarrow{w_2} \cdots \xrightarrow{w_n} a_n = b,
\]
the induced degree is bounded by \(w_1\otimes\cdots\otimes w_n\); in the Lawvere quantale this is \(w_1+\cdots+w_n\). Quantitative rewriting thus treats the distance between objects as a closure of one-step reductions rather than as a separate semantic layer [2206.13610].

## 2. Grades, contexts, and the structure of term rewriting

The specifically graded component is introduced through quantale endomorphisms. A change-of-base endomorphism \(h:\mathbb{\Omega}\to\mathbb{\Omega}\) preserves unit, tensor, and arbitrary joins:
\[
h(\kappa)=\kappa,\quad
h(\varepsilon\otimes\delta)=h(\varepsilon)\otimes h(\delta),\quad
h\Big(\bigvee_i\varepsilon_i\Big)=\bigvee_i h(\varepsilon_i).
\]
These endomorphisms, called CBEs, form a structure
\[
(\Phi,\precsim,\circ,1,\otimes,\kappa^\star),
\]
closed under composition and pointwise tensor. They describe how a context amplifies a degree [2507.19630].

A graded signature assigns such grades to argument positions. If \(f\) is \(n\)-ary, its modal arity is a tuple
\[
f:(\phi_1,\dots,\phi_n),\qquad \phi_i\in\Phi.
\]
The grade of a position \(p\) in a term \(t\) is defined compositionally:
\[
\partial_\lambda(t):=1,\qquad
\partial_{i.p'}(t):=\phi_i\circ\partial_{p'}(t_i)
\]
when \(t=f(t_1,\dots,t_n)\). The grade of a variable \(x\) in \(t\) is then
\[
\partial_x(t):=
\begin{cases}
\kappa^\star & \text{if } x\notin V(t),\\[.3em]
\displaystyle\bigotimes_{\{p\mid t|_p=x\}} \partial_p(t) & \text{otherwise.}
\end{cases}
\]
An equivalent notation in the earlier formulation writes these quantities as \(g_p(t)\) and \(g_x(t)\) [2206.13610] [2507.19630].

A graded quantitative term rewriting system is a pair \(R=(F,\mapsto_R)\), or in the earlier notation \(R=(\Sigma,\to_R)\), where rewrite rules have degrees and are closed under graded contexts. The one-step rewrite relation is generated by
\[
\frac{\varepsilon\Vdash l\mapsto_R r}
{\partial_p(s)(\varepsilon)\Vdash s[l\sigma]_p\to_R s[r\sigma]_p},
\]
so the step degree is the rule degree \(\varepsilon\) amplified by the grade of the redex position. In the context-hole formulation, the contextual rule is
\[
\infer{g_C(w)\Vdash C[t^\sigma]\to_R C[s^\sigma]}
      {w\Vdash t\to_R s},
\]
where \(g_C\) is the grade of the hole in \(C[-]\). The non-expansive case is recovered by taking all grades to be the identity, so that contexts do not amplify distances [2206.13610] [2507.19630].

Balancedness is the central well-formedness condition for graded rules. A rule \(l\xrightarrow{w}r\) is balanced if, for every variable \(x\),
\[
g_x(l)=g_x(r).
\]
This prevents rules from creating or deleting graded uses of variables and is crucial for graded substitution lemmas and confluence arguments [2206.13610].

The shift from non-expansive to graded rewriting is motivated by distance trivialization. In the non-expansive framework, allowing non-linear duplication under a constructor treated as non-expansive can force the induced convertibility distance to collapse to the degenerate values \(0\) or \(\infty\). Grading repairs this by making duplication explicit and quantitatively accountable: contexts no longer preserve degrees automatically, but transform them according to their declared sensitivities [2206.13610].

## 3. Quantitative metatheory

Classical metatheorems of rewriting admit quantale-valued analogues. For quantitative abstract rewriting systems, confluence, local confluence, commutation, and Church–Rosser are stated as relational inequalities. For example, if \(R,S:A\multimap A\), then \(R\) commutes with \(S\) when
\[
\overline{R};S \le S;\overline{R},
\]
and \(R\) is confluent when \(R^*\) has the diamond property. The quantitative Church–Rosser theorem states:
\[
\text{confluent}\quad\Longleftrightarrow\quad
\overline{R}=R^*;\overline{R^*}.
\]
This says that convertibility distances can be computed through convergent valleys, not merely through arbitrary zig-zags [2206.13610].

Termination is refined through strong normalization and induction over quantale-valued predicates. An element is a normal form if \(\bigvee_b R(a,b)=\bot\), and \(R\) is strongly normalising if every reduction sequence terminates. Quantitative induction is expressed by the condition
\[
\bigvee_a R(a,b)\otimes p(a)\le p(b),
\]
and one has
\[
SN(R)\wedge \text{locally confluent}\Rightarrow \text{confluent},
\]
which is the quantitative form of Newman’s Lemma. Hindley–Rosen modularity also lifts: if \(R^*\) commutes with \(S^*\) and both subsystems are confluent, then \(R\vee S\) is confluent [2206.13610].

For term rewriting, critical-pair analysis persists but requires linearity or graded balance hypotheses. In the non-expansive setting, the paper proves: if a linear \(\mathbb{V}\)-TRS is locally confluent on all critical pairs, then it is locally confluent; hence any linear, terminating \(\mathbb{V}\)-TRS that is locally confluent on critical pairs is confluent. In the graded setting, the corresponding statement is strengthened to left-linear, balanced systems that are strongly closed on critical pairs. Orthogonality—left-linearity plus absence of critical pairs—again implies confluence, now for the graded multi-step relation \(\mathring{R}\) [2206.13610].

The graded substitution lemma is one of the technically decisive results:
\[
\mathring{R}(t,s)\ \otimes\ \bigotimes_i [g_{x_i}(t)]\mathring{R}(u_i,v_i)
\;\le\;
\mathring{R}(t[\vec{u}/\vec{x}],s[\vec{v}/\vec{x}]).
\]
It states that substitution scales argument distances by the variable grades of the term into which the substitution is performed. This is the exact graded replacement for the non-expansive substitution principle [2206.13610].

A canonical example is the graded combinatory system \(W\), where a constructor \(!^n\) has grade “multiply by \(n\)” and controlled duplication is implemented by rules such as
\[
W_{n,m}\cdot x\cdot !^{n+m}y \xrightarrow{0}_W x\cdot !^n y\cdot !^m y.
\]
The system is orthogonal, and therefore confluent. This example exhibits the point of graded quantitative rewriting in concentrated form: non-linearity is admitted, but only through grades that record exactly how duplication affects quantitative structure [2206.13610].

## 4. Narrowing and quantitative unification

Quantitative narrowing extends graded rewriting by replacing matching with unification. A narrowing step uses a fresh variant of a rewrite rule, a renaming making the rule variables fresh with respect to the subject term, and an mgu of the redex subterm with the left-hand side. Formally, the graded narrowing relation is generated by
\[
\frac{\varepsilon\Vdash l\mapsto_R r}
     {\partial_p(s)(\varepsilon)\Vdash s \leadsto_R (s[r\rho]_p)\sigma},
\]
where \(\rho\) is a renaming and \(\sigma\) is an mgu of \(s|_p\) and \(l\rho\). Iterated narrowing composes substitutions by composition and degrees by tensor:
\[
\sigma_1\sigma_2=\sigma,\qquad \varepsilon_1\otimes\varepsilon_2=\varepsilon.
\]
On ground terms, this reduces to graded rewriting, because unification collapses to matching [2507.19630].

The semantic target is a graded equational theory \(E=(F,=_E)\). Its rules include reflexivity, symmetry, transitivity,
\[
\frac{\varepsilon\Vdash t=_E s\qquad \delta\Vdash s=_E r}
     {\varepsilon\otimes\delta\Vdash t=_E r},
\]
and the graded amplification rule
\[
\frac{
\varepsilon_1\Vdash t_1=_E s_1\quad\cdots\quad \varepsilon_n\Vdash t_n=_E s_n\quad
f:(\phi_1,\dots,\phi_n)}
{
\phi_1(\varepsilon_1)\otimes\cdots\otimes\phi_n(\varepsilon_n)
\Vdash f(t_1,\dots,t_n)=_E f(s_1,\dots,s_n)
}.
\]
The graded context lemma refines this to arbitrary positions:
\[
\frac{\varepsilon\Vdash u=_E v}
{\partial_p(t)(\varepsilon)\Vdash t[u]_p =_E t[v]_p }.
\]
Thus the same contextual sensitivity that governs rewriting also governs equational reasoning [2507.19630].

Operationally, narrowing is organized by the \(\mathcal N\)-calculus on configurations
\[
e;C;\sigma;\delta,
\]
where \(e\) is a term, \(C\) a set of constraints, \(\sigma\) a substitution, and \(\delta\) the accumulated degree. The main inference rules are lazy paramodulation, syntactic unification, clash, and constrain. Successful derivations have the form
\[
t =^? s;\emptyset;Id;\kappa \Longrightarrow_\varepsilon^* {}; \emptyset;\sigma;\varepsilon,
\]
and yield quantitative unifiers \(\sigma\) of degree \(\varepsilon\) [2507.19630].

Soundness is straightforwardly aligned with the generated equational theory: if the \(\mathcal N\)-calculus derives
\[
t =^? s;\emptyset;Id;\kappa \Longrightarrow_\varepsilon^* {}; \emptyset;\sigma;\varepsilon,
\]
then \(\sigma\) is an \((R,\varepsilon)\)-unifier of \(t\) and \(s\). More generally, every successful narrowing derivation yields a derivation in the graded equational theory generated by the TRS [2507.19630].

Completeness is subtler than in the classical setting. Even a weak completeness property fails in general: there are examples over \(\mathbb L\) in which a natural unifier exists at degree \(3\), but narrowing systematically finds only a degree-\(4\) solution. The obstruction comes from repeated variables, non-linearity, and the fact that grading introduces an optimization dimension absent from ordinary narrowing. Positive results are recovered under structural restrictions. If \(R\) is right-linear, the problem term is linear, and \(t\tau \to_{R,\varepsilon}^* s\), then there exists a narrowing derivation \(t\leadsto^*_{R,\sigma,\delta}s'\) with \(s'\leqq s\) and \(\delta\succsim\varepsilon\). If, additionally, the quantale order is total, \(R\) is confluent and right-linear, and the equation \(t=^?s\) is linear, then the \(\mathcal N\)-calculus is weakly complete in the sense of Corollary 5.7. For basic narrowing, completeness is established for right-ground TRSs and linear problems, while the right-linear balanced case is conjectured rather than proved [2507.19630].

## 5. Coalgebraic semantics, behavioural metrics, and modal logic

A coalgebraic account places graded quantitative rewriting inside the broader theory of graded semantics. A graded monad on a category \(C\), usually \(Met\) or a quantale-enriched metric category, is a family
\[
\mathbb M=(M_n,\eta,\mu^{n,k})_{n,k\in\mathbb N}
\]
with unit \(\eta:Id\to M_0\) and multiplications \(\mu^{n,k}:M_nM_k\to M_{n+k}\) satisfying graded monad laws. Given a system functor \(G\) and a natural transformation
\[
\alpha:G\to M_1,
\]
one obtains, for each \(G\)-coalgebra \((X,\gamma)\), the depth-\(n\) behaviour maps
\[
\gamma^{(0)}=M_0!\circ\eta,\qquad
\gamma^{(n+1)}=\mu^{1,n}\circ M_1\gamma^{(n)}\circ \alpha_X\circ \gamma.
\]
The associated graded behavioural distance in the metric-space setting is
\[
d^\alpha(x,y)=\bigvee_{n\in\mathbb N} d_{M_n1}\big(\gamma^{(n)}(x),\gamma^{(n)}(y)\big).
\]
This supplies a depth-indexed quantitative semantics for rewrite systems viewed as coalgebras of one-step rewrites [2306.01487].

Trace-style examples are especially close to rewriting. With the finite powerset monad one gets
\[
M_nX=P(A^n\times X),
\]
whose elements are sets of traces of length \(n\); with the distribution monad,
\[
M_nX=D(A^{\boxplus n}\boxplus X),
\]
giving distributions over length-\(n\) traces; with the fuzzy finite powerset,
\[
M_nX=F_\omega(A^n\times X),
\]
giving fuzzy sets of traces. These constructions induce metric trace distance, probabilistic metric trace distance, and fuzzy trace distance, respectively. The graded-monad framework is designed to cover a spectrum of behavioural metrics analogous to the linear-time/branching-time spectrum of equivalences, including branching-depth semantics \(M_n=G^n\) and trace-style semantics from distributive laws [2306.01487].

This perspective is significant for graded quantitative rewriting because it makes precise the distinction between branching-style rewrite metrics, trace-style rewrite metrics, and intermediate semantics such as readiness or failures. A plausible implication is that graded rewrite systems can be organized by the same kind of semantic spectrum: rewrite trees up to depth \(n\), rewrite traces of length \(n\), or observational structures lying between those extremes [2306.01487].

Quantitative graded logics provide the logical counterpart. If \(\mathcal L\) is a graded logic for \((\alpha,\mathbb M)\), then every uniform-depth formula has nonexpansive evaluation with respect to the behavioural distance, so logical distance is bounded by behavioural distance. Under the abstract separation criterion of Theorem 5.3, one gets full expressiveness:
\[
d^{\mathcal L}=d^\alpha.
\]
A notable positive case is fuzzy trace distance, for which the logic \(\mathcal L^{ftrace}\) is expressive. A notable negative case is probabilistic metric trace distance with non-discrete labels: no quantitative coalgebraic modal logic with unary modalities whose semantics is defined compositionally on the coalgebra can characterize that distance. This limitation transfers directly to probabilistic graded quantitative rewriting with non-discrete rule metrics: unary compositional modalities may be insufficient, and higher-arity or non-compositional devices may be necessary [2306.01487].

The Eilenberg–Moore variant of graded semantics broadens this picture from metric spaces to quantale-valued truth spaces. Given a monad \(T\), a functor \(F\), and an EM distributive law \(\zeta:TF\Rightarrow FT\), one obtains a depth-1 graded monad
\[
M_n=F^nT.
\]
Its behavioural distance is quantale-valued:
\[
d^b(x,y)=\bigwedge_{n\in\mathbb N} d_{M_n1}\bigl(c^{(n)}(x),c^{(n)}(y)\bigr),
\]
and graded modal logics evaluated on the original state space are invariant, and expressive when depth-0 and depth-1 separation hold. This quantale-parametrized account covers both Boolean and quantitative settings uniformly, and it suggests a semantic discipline for rewrite transformations: rules may be required to preserve or decrease behavioural distance grade by grade [2307.14826].

## 6. Related graded calculi, examples, and open directions

Graded quantitative rewriting is closely connected to modal and coeffectful calculi. In graded modal dependent type theory, terms and types share a syntax, typing judgments carry grade vectors for subject and type usage,
\[
(\Delta \mid \sigma_s \mid \sigma_r)\odot \Gamma \vdash t : A,
\]
and the operational semantics has a small-step reduction relation \(t\leadsto t'\) with type preservation and strong normalization for a fragment. Function application, tensor elimination, and box elimination all propagate grades by semiring addition and scalar multiplication. This suggests a typed instance of graded quantitative rewriting in which rewrite steps are constrained by graded usage information rather than by quantale-valued rule degrees alone [2010.13163].

Examples across the literature show the range of the framework. The system \(W\) provides confluent graded combinatory logic with controlled duplication. Quantitative approximate arithmetic uses rules
\[
0\Vdash x+Z\mapsto x,\qquad
0\Vdash x+S(y)\mapsto S(x+y),\qquad
1\Vdash S(x)\mapsto x
\]
to solve approximate equations by narrowing, with the cumulative degree measuring how far a solution is from exact algebraic equality. Security and information-flow interpretations arise when the grading algebra is a lattice rather than a numerical semiring. Coalgebraic examples include nondeterministic, probabilistic, and fuzzy trace semantics; these are not rewrite systems in the narrow syntactic sense, but they instantiate the same graded quantitative discipline at the level of observable behaviour [2206.13610] [2507.19630] [2010.13163] [2307.14826].

Several open directions recur across the papers. One is completeness of basic quantitative narrowing for right-linear balanced systems, which is conjectured but not proved. Another is the design of strategies and optimal strategy problems for metric word problems in graded systems. Completion procedures for quantitative and graded TRSs, and the effect of completion on distances, are also explicitly proposed. On the semantic side, richer grades than \(\mathbb N\), such as cost-aware or resource-aware monoids, are a natural extension of the current depth-indexed coalgebraic theory. Infinite-depth semantics, game-based characterizations of graded metrics, and logics beyond unary modalities are likewise identified as important next steps. Taken together, these directions indicate that graded quantitative rewriting is not merely a weighted variant of rewriting theory; it is a general framework for quantitative operational semantics in which syntax, context sensitivity, metrics, and logical observability are treated in a single graded architecture [2507.19630] [2206.13610] [2306.01487].

Source: https://www.emergentmind.com/topics/graded-quantitative-rewriting