---
title: Neural Rewriting System (NRS)
url: https://www.emergentmind.com/topics/neural-rewriting-system-nrs
type: topic
---

# Neural Rewriting System (NRS)

Neural Rewriting System (NRS) is a modular neural architecture for algorithmic formula simplification that is explicitly inspired by symbolic rewriting systems and designed to learn a general procedure for solving nested mathematical formulas by only relying on a minimal set of training examples [2402.17407]. Its central idea is to replace end-to-end prediction of a final answer with an iterative rewriting loop composed of three specialized modules—Selector, Solver, and Combiner—which respectively identify a reducible sub-expression, compute its value, and replace it in the original formula. In the literature summarized here, NRS occupies a specific position between classical rule-based rewriting and neural sequence modeling: earlier work asked whether symbolic rewriting could be learned as a sequence-to-sequence task [1911.04873], whereas NRS formulates the rewriting process itself as the organizing principle of the architecture [2402.17407].

## 1. Historical and conceptual placement

A direct precursor to the modern machine-learning use of the term is the question of whether symbolic rewriting can be learned by neural models at all. "Can Neural Networks Learn Symbolic Rewriting?" casts rewriting as a supervised translation problem in which a symbolic term is linearized as a token sequence and mapped either to the result of one rewrite step or to a normalized form [1911.04873]. That work uses standard neural machine translation architectures rather than a bespoke rewriting mechanism, evaluates both proof-derived and synthetic polynomial datasets, and concludes that neural networks can learn some symbolic rewriting tasks well, while also emphasizing limitations related to dataset simplicity, sequence linearization, data requirements, and generalization.

A more distant symbolic antecedent is "Algebraic Net Class Rewriting Systems, Syntax and Semantics for Knowledge Representation and Automated Problem Solving," which develops a fully symbolic and algebraic rewriting framework over generalized free algebra based nets, with explicit substitution relations, congruent classes, and parallel transducer paths [1305.5637]. That framework is not neural and contains no training, embeddings, or differentiable components, but it formalizes several motifs that remain relevant to later neural rewriting work: structured matching, rule application, interface preservation, and multi-path transformation.

Against that background, NRS can be read as a machine-learning formulation in which the rewriting loop becomes the model architecture itself rather than merely the supervision target. This suggests a shift from learning a direct input–output transduction to learning a decomposition of the rewriting procedure into specialized, interacting subproblems [2402.17407].

## 2. Formal problem setting and rewriting model

In the 2024 formulation, NRS is defined over formulas \(f \in F\) built recursively from operators \(o \in O\), atomic elements \(e \in E\), and arguments \(a_j \in F \cup E\). A leaf formula is a sub-expression whose arguments are all atomic elements, written \(F^L \subset F\), and the relevant rewrite rules are mappings

\[
r : F^L \rightarrow E,\quad \forall r \in R.
\]

The Selector is trained to identify the last leaf formula in the input expression that can be reduced [2402.17407]. The associated reduction target has the compact form

\[
f = o(a_1,\dots,a_n) = e,
\]

with the restriction that the reducible case is a leaf formula. For formulas with more arguments than seen in training, the Selector is trained to output only the smallest reducible fraction of the leaf formula, typically the operator plus the first two arguments.

The Solver is also trained to recognize a termination symbol \(\omega\), which marks that the expression is fully reduced; atomic values are mapped to \(\omega\) [2402.17407]. This makes the learned procedure an explicit rewrite-to-normal-form loop rather than a one-shot predictor.

The paper is explicit that the evaluated benchmark classes are constrained so that reduction is deterministic and always reaches the same final result [2402.17407]. A plausible implication is that NRS is defined, in its initial form, for tasks where “what to compute next” and “what the correct normal form is” are both unambiguous.

## 3. Modular architecture: Selector, Solver, and Combiner

NRS has three modules: Selector, Solver, and Combiner [2402.17407]. They work together iteratively until computation terminates.

**Selector.** The Selector identifies a reducible leaf sub-expression. It is implemented as a transformer sequence-to-sequence model with two architecture changes intended to improve length generalization. First, the encoder self-attention matrix is masked so that only positions within a diagonal window of width \(2k+1\) are allowed; all others are set to \(-\infty\). Second, the model uses label-based positional encodings rather than standard fixed positions: it samples \(L\) integers from \([0, N-1]\), sorts them, and adds the corresponding sinusoidal encodings to token embeddings [2402.17407].

The Selector can generate multiple candidate leaf formulas. For each input it samples \(M\) outputs,

\[
\hat F^L = \langle \hat f^{L,1}, \dots, \hat f^{L,M} \rangle,
\]

with candidate confidence defined by

\[
c(\hat f^{L,j}) = \prod_{i=1}^{N} p_i^j.
\]

A candidate is kept only if it is an exact match with the input, as judged by an agreement score \(a(\hat f^{L,j}, f) \in [0,1]\). The final selected leaf formula is the highest-confidence candidate with

\[
a(\hat f^{L,j}, f) = 1.
\]

**Solver.** The Solver takes the selected leaf formula \(f^L\) and predicts its reduction \(e\). It is a vanilla transformer seq2seq model, trained with teacher forcing on both atomic elements and leaf formulas [2402.17407]. Rather than consulting a hand-built dictionary of symbolic rules, the Solver learns the rewrite mappings from data.

**Combiner.** The Combiner takes the original formula \(f\), the selected leaf \(f^L\), and its reduction \(e\), and returns a simplified formula \(f'\) in which \(f^L\) has been replaced by \(e\). The paper implements this with a 2D CNN whose filter is dynamically set to the selected leaf formula, so that the Selector’s output acts like a HyperNetwork that configures the Combiner [2402.17407]. If \(f\) and \(f^L\) are represented as sequences of one-hot vectors, the best match position is

\[
\mathrm{pos}(f^L, f)=\mathrm{argmax}~\mathrm{CNN}_{f^L}(f),
\]

and the normalized agreement score is

\[
a(f^L,f)=\frac{\max~\mathrm{CNN}_{f^L}(f)}{|f^L|}.
\]

If no Selector output satisfies \(a(\hat f^L_j, f)=1\), computation stops and the model is considered to have failed [2402.17407].

## 4. Training regime and iterative execution

The Selector is trained with teacher forcing using syntactically correct formulas, and the Solver is trained with teacher forcing on atomic elements and leaf formulas [2402.17407]. The Selector training distribution includes top-level formulas, intermediate formulas encountered during reduction, and atomic elements. The Solver training distribution is restricted to atomic elements and leaf formulas with equal probability.

At inference time, NRS executes an iterative rewrite loop: the Selector identifies a reducible leaf sub-expression, the Solver computes its reduced value, the Combiner replaces the leaf in the original expression, the resulting formula is fed back into the system, and the process repeats until the Solver outputs \(\omega\) [2402.17407]. The architecture is therefore not merely modular at training time; modularity is the operational form of inference.

For very long inputs, the Selector applies dynamic windowing. If \(|f| < T\), it behaves normally; otherwise it creates multiple copies of the input and applies different truncation windows using

\[
w(f,k)=f_{k+1},\dots,f_N,
\]

with copies split into 10 groups according to

\[
k = \mathrm{floor}(|f^{(i)}| \cdot \frac{j}{10}) \quad \forall f^{(i)} \in F^{(j)},\ \forall j \in [1,10].
\]

The thresholds chosen from confidence analysis are \(T=60\) for ListOps, \(T=150\) for Arithmetic, and \(T=200\) for Algebra [2402.17407]. This is tied to a concrete failure mode reported in the paper: Selector confidence stays near training levels for sequences only moderately longer than training examples, but drops sharply for much longer sequences.

## 5. Benchmarks, baselines, and empirical behavior

The paper evaluates NRS on three formula simplification benchmarks: ListOps, Arithmetic, and Algebra [2402.17407]. In the modified ListOps setting, only min, max, and sum mod 10 are used, nesting points are fixed at two per level, and the number of arguments can be specified. Arithmetic includes addition, subtraction, and multiplication with integers sampled from \([-99, 99]\), with intermediate results computed modulo \(100\). Algebra is a deterministic algebraic simplification task involving sums and subtractions of two monomials, coefficients in \([-99, 99]\), and monomials with up to four variables from \(\{a,b,x,y\}\), again with intermediate numeric values taken modulo \(100\).

The in-distribution and out-of-distribution splits are defined by structural complexity. For Arithmetic and Algebra, in-distribution training uses nesting levels 1, 2, 3, while out-of-distribution validation uses nesting levels 4, 5, 6. For ListOps, in-distribution training uses nesting levels 1 and 2 with 2 or 3 arguments per operator, while out-of-distribution validation uses nesting levels 3 and 4 with 2, 3, or 4 arguments [2402.17407].

Baselines are Neural Data Router (NDR), trained end-to-end to output the final simplified form directly, and GPT-4, prompted with zero-shot chain-of-thought and self-consistency [2402.17407]. Evaluation uses sequence accuracy, meaning exact match between predicted and target output sequence; for Algebra, equivalent symbolic forms are also checked using SymPy, and each model is evaluated on 100 test samples per complexity level.

The reported pattern is consistent across tasks: all models perform better on simple splits and degrade as complexity increases. NDR performs worse than NRS overall and fails to generalize the learned process to more complex instances. GPT-4 achieves perfect or near-perfect results on the simplest splits, but its performance drops sharply on harder ones, especially deeply nested formulas and harder arithmetic or algebra cases [2402.17407]. NRS is described as the best-performing method on many medium-to-hard cases. With 1000 Selector outputs per input, it achieves better out-of-distribution generalization; it is consistently equal or superior to NDR on both simple and complex splits, comparable to GPT-4 on the easiest cases, and superior to GPT-4 on medium-difficulty cases such as Arithmetic nesting levels 4 and 5 and Algebra nesting levels 3 and 4. The same source also states that NRS drops dramatically on the hardest Arithmetic and Algebra instances [2402.17407].

Error analysis partitions NRS failures into selector/missing, selector/corrupted, and solver errors. On the hardest splits, the Selector is the main failure source. Multi-output generation helps especially by reducing missing-leaf errors, and dynamic windowing further helps on the most complex splits by mitigating length-induced Selector failures [2402.17407].

## 6. Scope, limitations, and terminological ambiguities

The limitations stated for NRS are structural rather than incidental. The model is tested on formulas with essentially one final form; the benchmark classes are constrained so that reduction is deterministic and always reaches the same final result; real algebraic expressions can be more ambiguous and may have multiple valid normal forms; and the current approach depends on task-specific assumptions, so it is not yet a general solution to arbitrary symbolic reasoning [2402.17407]. The paper also suggests that better methods may require learning rule selection strategies, possibly via reinforcement learning.

A bibliographic complication is that a later arXiv record, "Learning neuro-symbolic convergent term rewriting systems," claims to introduce a general framework for learning convergent term rewriting systems and two modular implementations, the Neural Rewriting System (NRS) and the Fast Neural Rewriting System (FastNRS), with strong out-of-distribution generalization and improvements in memory efficiency, training speed, and inference time. However, the supplied description of that record states that the corresponding document is a LaTeX template/sample manuscript and does not contain substantive material on NRS, FastNRS, training procedures, or experiments [2507.19372]. As a result, that record cannot presently be used to extend the technical description of NRS beyond the 2024 formulation.

There is also a terminological ambiguity outside machine learning. In recent mathematical literature, NRS\((m)\) denotes a higher-dimensional generalization of the Newton–Raphson–Simpson method for polynomial root-finding, with results on fixed points, Jacobians, and positivity properties of coefficient polynomials [2509.14176]. Related work on NRS(2) studies leading and penultimate leading coefficients in error terms for cubic polynomials and proves that these coefficients are positive-coefficient polynomials in \(u_1\) and \(u_2\) [2603.10728]. This usage is unrelated to the Neural Rewriting System of algorithmic formula simplification. The shared acronym is therefore a source of possible confusion in cross-disciplinary searches.

Taken together, the available literature defines Neural Rewriting System in the machine-learning sense as a modular, iterative neural architecture for learned symbolic reduction, grounded in formula simplification benchmarks and motivated by systematic generalization [2402.17407]. Earlier work established the feasibility of neural symbolic rewriting in sequence-to-sequence form [1911.04873]; NRS advances that line by building the rewriting loop into the architecture itself.

Source: https://www.emergentmind.com/topics/neural-rewriting-system-nrs