Abstract
There is a wide class of problems for which the natural Prolog specification, as a top-down, recursive computation, is significantly less efficient than an iterative bottom-up version. However, the transformation from the top-down specification to the bottom-up implementation is not always obvious, principally due to problems with nondeterminism and the order in which variables get bound — problems which do not arise in comparable situations in functional languages. This paper illustrates how these problems can be handled in certain cases, and the transformation mechanized, using algebraic properties of operators such as associativity and distributivity. The resulting programs are tail-recursive, and hence significantly more efficient in space usage, with no deterioration in execution speed.
This work was supported in part by the National Science Foundation under grant number DCR-8407688.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
7. References
J. Arsac and Y. Kodratoff, “Some Techniques for Recursion Removal from Recursive Functions”, ACM Trans. Prog. Lang. and Systems, 4, 2 (Apr. 1982), 295–322.
R. S. Bird, “The Promotion and Accumulation Strategies in Transformational Programming”, ACM Trans. Prog. Lang. and Systems, 6, 4 (Oct. 1984), 487–504.
M. Bruynooghe, “The Memory Management of PROLOG Implementations”, in Logic Programming, K. L. Clark and S. Tarnlund, (eds.), Academic Press, London, 1982. A.P.I.C. Studies in Data Processing No. 16.
R. M. Burstall and J. Darlington, “A Transformation System for Developing Recursive Programs”, J. ACM, 24, 1 (January 1977), 44–67.
K. L. Clark and S. Sickel, “Predicate Logic: a calculus for deriving programs”, in Proc. IJCAI-77, Boston, 1977.
N. H. Cohen, “Source-to-Source Improvement of Recursive Programs”, Ph.D. Thesis, Harvard University, Cambridge, MA, May 1980.
J. Darlington and R. M. Burstall, “A System which Automatically Improves Programs”, Acta Informatica, 6, (1976), 41–60.
C. J. Hogger, “Derivation of Logic Programs”, J. ACM, 23, 4 (1976),.
R. B. Kieburtz and J. Schultis, “Transformations of FP Program Schemes”, in Proc. 1981 Conf. Func. Prog. Langs. and Comp. Arch., ACM, Portsmouth, New Hampshire, Oct. 1981.
M. K. Srivas, personal communication, Nov. 1984.
E. St.-James, “Recursion is More Efficient than Iteration”, in Proc. 1984 ACM Symp. on LISP and Functional Programming, Austin, Texas, Aug. 1984.
H. Tamaki and T. Sato, “Unfold/Fold Transformations of Logic Programs”, in Proc. 2nd. Logic Programming Conference, Uppsala, Sweden, 1984.
D. H. D. Warren, “An improved Prolog implementation which optimises tail recursion”, Research Paper 156, Dept. of Artificial Intelligence, University of Edinburgh, Scotland, 1980. Presented at the 1980 Logic Programming Workshop, Debrecen, Hungary.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1985 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Debray, S.K. (1985). Optimizing almost-tail-recursive prolog programs. In: Jouannaud, JP. (eds) Functional Programming Languages and Computer Architecture. FPCA 1985. Lecture Notes in Computer Science, vol 201. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-15975-4_38
Download citation
DOI: https://doi.org/10.1007/3-540-15975-4_38
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-15975-9
Online ISBN: 978-3-540-39677-2
eBook Packages: Springer Book Archive