Papers
Topics
Authors
Recent
Search
2000 character limit reached

Templates in Rewriting Induction

Published 29 Apr 2026 in cs.LO | (2604.26474v1)

Abstract: Rewriting Induction (RI) is a formal system in term rewriting to establish program equivalence. The recently defined Bounded RI for higher-order Logically Constrained Term Rewriting Systems (LCSTRSs) yields a convenient proof system for analyzing real programming code. A practical challenge in RI is the automatic generation of induction hypotheses, called lemmas. While various lemma generation techniques exist for plain term rewriting, there are much fewer that consider the intricacies brought on by calculations or constraints. Taking advantage of recent developments in higher-order RI, we here present a new approach based on templates, which operates by recognising typical programming constructs as instances of higher-order functions. While templates have been used as a stand-alone method to justify the correctness of program transformations, we here consider their integration in Bounded RI to obtain a complementary lemma generation heuristic. This allows us to prove equivalences that were previously out of reach.

Authors (2)

Summary

  • The paper presents a new method for template-based lemma generation that overcomes limitations of invariant-based techniques in Rewriting Induction.
  • It employs four generalized recursion templates to abstract common programming constructs, enabling both one-sided and two-sided matching strategies.
  • The approach scales to real-world programs by handling non-polynomial invariants and integrating bounded orderings for rigorous inductive reasoning.

Templates in Rewriting Induction: A Formal Approach to Lemma Generation in LCSTRS

Introduction

The paper "Templates in Rewriting Induction" (2604.26474) presents a methodological advance in the field of program equivalence proofs via term rewriting. Its main focus is addressing the systematic challenge of automatic lemma generation within Rewriting Induction (RI), particularly for higher-order Logically Constrained Term Rewriting Systems (LCSTRSs). The authors propose the integration of programming templates—generalized rewrite schemes reflecting common programming constructs—directly into Bounded RI as a lemma generation heuristic. This approach dramatically extends the scope and automation potential of equivalence proofs for real-world programs, especially when classical invariant-seeking lemma generation techniques become insufficient due to complex control flow or non-polynomial invariants.

Background

Rewriting Induction (RI) is a proof system designed for inductive reasoning about term rewriting systems (TRSs), leveraging ground convertibility to formalize program equivalence. Extensions to constrained and higher-order rewriting (notably LCSTRSs) accommodate reasoning about programs manipulating primitive data types (e.g., integers, booleans) and explicit control flow via logical constraints. These constraints, interpreted semantically, support direct modeling of program behaviors beyond what classical pattern-matching TRSs can capture.

Lemma generation, the automatic synthesis of induction hypotheses, is pivotal for enabling practical, scalable RI-based verification. Existing methods for lemma generation in classical (unconstrained) TRSs or lower-order constrained rewriting (e.g., [fuh:kop:nis:17], [hag:kop:23]) typically focus on invariant discovery, which may fail when loop constructs or control flow cannot be captured via polynomial invariants.

Template-Based Lemma Generation

The central innovation in this work is the introduction of templates—parametrized higher-order rewrite schemes capturing typical iterative programming patterns (such as upward/downward recursion and tail recursion). These templates are realized as higher-order recursor functions, allowing the generalization of loop structures rather than just variable invariants. By recognizing implementations as instantiations of such templates, the RI proof system can leverage powerful template-recursor and recursor equivalences as lemmas, facilitating proofs that were previously intractable.

The authors illustrate this approach using four canonical implementations of the factorial function (upward and downward, both recursive and iterative), showing that all can be precisely captured as instances of only four templates. These templates generalize over the shape of recursion and accumulation, abstracting away from low-level operational semantics.

Technical Highlights

  • Template Definitions: Four templates are introduced to generalize tail recursion and plain recursion (both upward and downward). Parameters include context functions, recursion bounds, and accumulators/base cases.
  • Recursor Equivalences: The templates are translated into higher-order recursor definitions, enabling equivalence proofs at the level of recursion structure rather than concrete values.
  • Bounded RI Integration: Templates are incorporated as lemma equations within the Bounded RI proof system. Bounded RI manipulates pairs of equations and induction hypotheses, enforcing well-founded orderings and symbolic reasoning about constraints.

Proof Strategies

Two principal tactics for employing template-based lemma generation are discussed:

  • One-sided Matching: Lemma application on one side of the equivalence reduces the goal to a simpler one, often enabling classical induction. While effective for many cases, it may require further generalization or auxiliary lemmas when variable dependencies are complex.
  • Two-sided Matching: Simultaneous template matching on both sides enables RI reasoning entirely within the recursor abstraction. This often results in goals that are instances of recursor equivalences, simplifying proofs through immediate lemma application.

Additionally, the paper delineates between unconditional and conditional recursor equivalences. The latter handle cases where semantic properties (e.g., associativity, commutativity) of function symbols are required, integrating axioms as part of the conditional lemma set.

Numerical and Structural Results

Strong structural results are established:

  • The main templates and recursor equivalences are proved to be bounded inductive theorems within Bounded RI for a wide class of LCSTRSs, subject to mild ordering requirements.
  • Equivalences between different implementations of prototypical functions (factorial, summation) are proved, demonstrating the efficacy of templates where low-level, invariant-seeking methods fail.
  • The method is shown to scale to higher-order programming constructs and composite operators, e.g., generalizing from simple multiplication to higher-order folding patterns.

The authors highlight that, for practical programming equivalence, template-based lemma generation covers cases previously out of reach, such as iterative-to-recursive transformation or loop-construct generalization, especially when invariants cannot be expressed as closed-form polynomials.

Implications and Future Developments

Practical Implications

Integration of templates into Bounded RI yields a unified, high-level lemma generation heuristic complementary to low-level invariant-seeking approaches. Since LCSTRSs directly model primitive data and control flow, this approach makes RI-based verification more applicable to real programming languages with complex procedural structures—without requiring semantic encodings into unconstrained TRS or ad-hoc invariant guessing.

The approach is amenable to automation, as template recognition is largely syntactic, though optimal lemma application strategy (one-sided vs. two-sided matching) may require trial and error. The generality and modularity of template-based lemma generation suggest its suitability for implementation in verification tools (such as CORA [cora]) and wider adoption in program equivalence verification.

Theoretical Implications

Templates enable bounded RI to reason about program equivalence at the level of programming constructs, abstracting away from specific invariants. This opens prospects for further extension to non-classical data structures (e.g., lists via foldl/foldr, recurrence relations, or parameterized step sizes), and suggests a general framework for structural induction across higher-order, constrained rewriting formalisms.

Speculation on Future Directions

  • Template Library Expansion: Defining and cataloging a more comprehensive suite of templates covering advanced constructs (folds, recurrences, sorting algorithms) will improve coverage.
  • Automated Template Application Heuristics: Development of algorithms to select optimal lemma application strategies based on proof goals and term structure.
  • Integration with Confluence and Termination Proofs: Tighter coupling with static dependency pair and recursive path ordering methods to automatically discharge ordering requirements.
  • Extension to Other Theories: More expressive constraint domains (e.g., bitvectors, arrays) should be supported, further bridging RI with practical programming languages.

The paper builds on prior work on templates in unconstrained rewriting [chi:aot:toy:10], but surpasses previous frameworks by leveraging LCSTRSs and higher-order constructs. Unlike earlier template methods restricted to pattern matching on inductive types, the current approach accommodates control flow via logical constraints and supports program structures typical of imperative code (e.g., loops over integers). The formal integration of templates into RI, supported by bounded orderings and conditional lemma sets, enhances both rigor and applicability, and avoids the limitations of completeness and confluence assumptions required for transformation scheme correctness.

Conclusion

Templates in Rewriting Induction provide a robust and general methodology for lemma generation in program equivalence proofs, particularly in higher-order, constrained rewriting settings. By abstracting over programming constructs and loop structures, they enable the RI system to reason about equivalence of complex programs where classical invariant-based methods are inadequate. The technical framework developed here fundamentally broadens the expressivity and automation potential of RI-based verification, offering a scalable path toward formal reasoning in real programming languages.


Reference:

"Templates in Rewriting Induction" (2604.26474)

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

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

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.