English

Tail recursion transformation for invertible functions

Programming Languages 2023-09-12 v3

Abstract

Tail recursive functions allow for a wider range of optimisations than general recursive functions. For this reason, much research has gone into the transformation and optimisation of this family of functions, in particular those written in continuation passing style (CPS). Though the CPS transformation, capable of transforming any recursive function to an equivalent tail recursive one, is deeply problematic in the context of reversible programming (as it relies on troublesome features such as higher-order functions), we argue that relaxing (local) reversibility to (global) invertibility drastically improves the situation. On this basis, we present an algorithm for tail recursion conversion specifically for invertible functions. The key insight is that functions introduced by program transformations that preserve invertibility, need only be invertible in the context in which the functions subject of transformation calls them. We show how a bespoke data type, corresponding to such a context, can be used to transform invertible recursive functions into a pair of tail recursive function acting on this context, in a way where calls are highlighted, and from which a tail recursive inverse can be straightforwardly extracted.

Keywords

Cite

@article{arxiv.2302.10049,
  title  = {Tail recursion transformation for invertible functions},
  author = {Joachim Tilsted Kristensen and Robin Kaarsgaard and Michael Kirkedal Thomsen},
  journal= {arXiv preprint arXiv:2302.10049},
  year   = {2023}
}

Comments

Submitted to 15th Conference on Reversible Computation, 2023

R2 v1 2026-06-28T08:44:39.087Z