Papers
Topics
Authors
Recent
Search
2000 character limit reached

Neural Rewriting System (NRS)

Updated 7 July 2026
  • Neural Rewriting System (NRS) is a modular neural architecture designed for iterative symbolic formula simplification by decomposing the rewriting process into Selector, Solver, and Combiner modules.
  • It replaces end-to-end prediction with a systematic rewrite loop that iteratively reduces nested mathematical expressions with high confidence through dynamic windowing.
  • The system shows strong generalization on medium-difficulty benchmarks but encounters challenges with highly nested or ambiguous algebraic expressions.

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 (Petruzzellis et al., 2024). 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 (Piotrowski et al., 2019), whereas NRS formulates the rewriting process itself as the organizing principle of the architecture (Petruzzellis et al., 2024).

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 (Piotrowski et al., 2019). 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 (Tirri, 2013). 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 (Petruzzellis et al., 2024).

2. Formal problem setting and rewriting model

In the 2024 formulation, NRS is defined over formulas fFf \in F built recursively from operators oOo \in O, atomic elements eEe \in E, and arguments ajFEa_j \in F \cup E. A leaf formula is a sub-expression whose arguments are all atomic elements, written FLFF^L \subset F, and the relevant rewrite rules are mappings

r:FLE,rR.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 (Petruzzellis et al., 2024). The associated reduction target has the compact form

f=o(a1,,an)=e,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 (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 2024). 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 oOo \in O0. Second, the model uses label-based positional encodings rather than standard fixed positions: it samples oOo \in O1 integers from oOo \in O2, sorts them, and adds the corresponding sinusoidal encodings to token embeddings (Petruzzellis et al., 2024).

The Selector can generate multiple candidate leaf formulas. For each input it samples oOo \in O3 outputs,

oOo \in O4

with candidate confidence defined by

oOo \in O5

A candidate is kept only if it is an exact match with the input, as judged by an agreement score oOo \in O6. The final selected leaf formula is the highest-confidence candidate with

oOo \in O7

Solver. The Solver takes the selected leaf formula oOo \in O8 and predicts its reduction oOo \in O9. It is a vanilla transformer seq2seq model, trained with teacher forcing on both atomic elements and leaf formulas (Petruzzellis et al., 2024). 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 eEe \in E0, the selected leaf eEe \in E1, and its reduction eEe \in E2, and returns a simplified formula eEe \in E3 in which eEe \in E4 has been replaced by eEe \in E5. 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 (Petruzzellis et al., 2024). If eEe \in E6 and eEe \in E7 are represented as sequences of one-hot vectors, the best match position is

eEe \in E8

and the normalized agreement score is

eEe \in E9

If no Selector output satisfies ajFEa_j \in F \cup E0, computation stops and the model is considered to have failed (Petruzzellis et al., 2024).

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 (Petruzzellis et al., 2024). 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 ajFEa_j \in F \cup E1 (Petruzzellis et al., 2024). 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 ajFEa_j \in F \cup E2, it behaves normally; otherwise it creates multiple copies of the input and applies different truncation windows using

ajFEa_j \in F \cup E3

with copies split into 10 groups according to

ajFEa_j \in F \cup E4

The thresholds chosen from confidence analysis are ajFEa_j \in F \cup E5 for ListOps, ajFEa_j \in F \cup E6 for Arithmetic, and ajFEa_j \in F \cup E7 for Algebra (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 2024). 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 ajFEa_j \in F \cup E8, with intermediate results computed modulo ajFEa_j \in F \cup E9. Algebra is a deterministic algebraic simplification task involving sums and subtractions of two monomials, coefficients in FLFF^L \subset F0, and monomials with up to four variables from FLFF^L \subset F1, again with intermediate numeric values taken modulo FLFF^L \subset F2.

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 (Petruzzellis et al., 2024).

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 (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 2024).

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 (Petruzzellis et al., 2024).

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 (Petruzzellis et al., 2024). 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 (Petruzzellis et al., 25 Jul 2025). 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, NRSFLFF^L \subset F3 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 (DeFranco, 17 Sep 2025). 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 FLFF^L \subset F4 and FLFF^L \subset F5 (DeFranco, 11 Mar 2026). 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 (Petruzzellis et al., 2024). Earlier work established the feasibility of neural symbolic rewriting in sequence-to-sequence form (Piotrowski et al., 2019); NRS advances that line by building the rewriting loop into the architecture itself.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Neural Rewriting System (NRS).