Optimizing almost-tail-recursive prolog programs

  • Saumya K. Debray
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 201)


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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

7. References

  1. 1.
    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.Google Scholar
  2. 2.
    R. S. Bird, “The Promotion and Accumulation Strategies in Transformational Programming”, ACM Trans. Prog. Lang. and Systems, 6, 4 (Oct. 1984), 487–504.Google Scholar
  3. 3.
    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.Google Scholar
  4. 4.
    R. M. Burstall and J. Darlington, “A Transformation System for Developing Recursive Programs”, J. ACM, 24, 1 (January 1977), 44–67.Google Scholar
  5. 5.
    K. L. Clark and S. Sickel, “Predicate Logic: a calculus for deriving programs”, in Proc. IJCAI-77, Boston, 1977.Google Scholar
  6. 6.
    N. H. Cohen, “Source-to-Source Improvement of Recursive Programs”, Ph.D. Thesis, Harvard University, Cambridge, MA, May 1980.Google Scholar
  7. 7.
    J. Darlington and R. M. Burstall, “A System which Automatically Improves Programs”, Acta Informatica, 6, (1976), 41–60.Google Scholar
  8. 8.
    C. J. Hogger, “Derivation of Logic Programs”, J. ACM, 23, 4 (1976),.Google Scholar
  9. 9.
    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.Google Scholar
  10. 10.
    M. K. Srivas, personal communication, Nov. 1984.Google Scholar
  11. 11.
    E. St.-James, “Recursion is More Efficient than Iteration”, in Proc. 1984 ACM Symp. on LISP and Functional Programming, Austin, Texas, Aug. 1984.Google Scholar
  12. 12.
    H. Tamaki and T. Sato, “Unfold/Fold Transformations of Logic Programs”, in Proc. 2nd. Logic Programming Conference, Uppsala, Sweden, 1984.Google Scholar
  13. 13.
    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.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1985

Authors and Affiliations

  • Saumya K. Debray
    • 1
  1. 1.Department of Computer ScienceState University of New York at Stony BrookStony Brook

Personalised recommendations