Specifying and Verifying a Transformation of Recursive Functions into Tail-Recursive Functions

Axel Suárez Polo, José de Jesús Lavalle Martínez, Iván Molina Rebolledo


It is well known that some recursive functions admit a tail recursive counterpart which have a more efficient time-complexity behavior. This paper presents a formal specification and verification of such process. A monoid is used to generate a recursive function and its tail-recursive counterpart. Also, the monoid properties are used to prove extensional equality of both functions. In order to achieve this goal, the Agda programming language and proof assistant is used to generate a parametrized module with a monoid, via dependent types. This technique is exemplified with the length, reverse, and indices functions over lists.


Dependent types, formal specification and verification, tail recursion, accumulation, program transformation

Full Text: PDF