Skip to main content
Log in

On the completeness of naive memoing in Prolog

  • Regular Papers
  • Published:
New Generation Computing Aims and scope Submit manuscript

Abstract

Memoing is often used in logic programming to avoid redundant evaluation of similar goals, often on programs that are inherently recursive in nature. The interaction between memoing and recursion, however, is quite complex. There are several top-down evaluation strategies for logic programs that utilize memoing to achieve completeness in the presence of recursion. This paper’s focus, however, is on the use ofnaive memoing in Prolog. Using memoingnaively in conjunction with recursion in Prolog may not produce expected results. For example, adding naive memoing to Prolog’s evaluation of a right-recursive transitive closure may be incomplete, whereas adding naive memoing to Prolog’s evaluation of a left-recursive transitive closure may be terminating and complete. This paper examines the completeness of naive memoing in linear-recursive, function-free logic programs evaluated with Prolog’s top-down evaluation strategy. In addition, we assume that the program is definite and safe, having finite base relations and exactly one recursive predicate. The goal of the paper is a theoretical study of the completeness of naive memoing and recursion in Prolog, illustrating the limitations imposed even for this simplified class of programs. The naive memoing approach utilized for this study is based on extension tables, which provide a memo mechanism with immediate update view semantics for Prolog programs, through a source transformation known as ET. We introduce the concept ofET-complete, which refers to the completeness of the evaluation of a query over a Prolog program that memos selected predicates through the ET transformation. We show that left-linear recursions defined by a single recursive rule are ET-complete. We generalize the class of left-linear recursions that are ET-complete by introducing pseudo-left-linear recursions, which are also defined by a single linear recursive rule. To add left-linear recursions defined bymultiple linear recursive rules to the class of ET-complete recursions, we present a left-factoring algorithm that converts left-linear recursions defined by multiple recusive rules into pseudo-left-linear recursions defined by a single recursive rule. Based on these results, the paper concludes by identifying research directions for expanding the class of Prolog programs to be examined in future work.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Bancilhon, F., Maier, D., Sagiv, Y., and Ullman, J., “Magic Sets and Other Strange Ways to Implement Logic Programs,”Symposium on Principles of Database Systems, ACM, pp. 1–15, 1986.

  2. Bancilhon, F. and Ramakrishnan, R., “An Amateur’s Introduction to Recursive Query Processing Strategies,”SIGMOD, ACM, pp. 1–15, 1986.

  3. Bird, R. S., “Tabulation Techniques for Recursive Programs,”Computing Surveys, 12, 4, pp. 403–417, 1980.

    Article  MATH  MathSciNet  Google Scholar 

  4. Bry, F., “Query Evaluation in Deductive Databases: Bottom-up and Top-down Reconciled,”Proceedings of the First International Conference on Deductive and Object-Oriented Databases, pp. 25–44, December 1989.

  5. Chen, W. and Warren, D. S., “Query Evaluation under the Well-Founded Semantics,”Symposium on Principles of Database Systems, ACM, pp. 168–179, 1993.

  6. Dietrich, S. W., “Extension Tables: Memo Relations in Logic Programming,”Symposium on Logic Programming, IEEE, pp. 264–272, 1987.

  7. Dietrich, S. W., “Shortest Path by Approximation in Logic Programming,”ACM Letters on Programming Languages and Systems, 1, 2, pp. 119–137, June 1992.

    Article  Google Scholar 

  8. Fagin, B. S. and Despain, A. M., “Goal Caching in Prolog,”Hawaiian International Conference on System Sciences, IEEE, pp. 277–281, 1986.

  9. Fan, C. and Dietrich, S. W., “Extension Table Built-ins for Prolog,”Software Practice and Experience, pp. 573–597, July 1992.

  10. Han, J., “Compilation-Based List Processing in Deductive Databases,”the International Conference on Extending Database Technology, pp. 104–119, March 1992.

  11. Keller, R. M., “Applicative Caching,”ACM Transactions on Programming Languages and Systems, 8, 1, pp. 88–108, January 1986.

    Article  MATH  Google Scholar 

  12. Kifer, M., “On Safety, Domain Independence and Capturability of Database Queries,”Proc. of the 3rd International Conference on Data and Knowledge Bases: Improving Usability and Responsiveness, IPA and ACM, pp. 405–415, June, 1988.

  13. Lindholm, T. G. and O’Keefe, R. A., “Efficient Implementation of a Defensible Semantics for Dynamic Prolog Cod,”Proc. of the International Conference on Logic Programming, ACM, pp. 21–39, 1987.

  14. Lloyd, J. W.,Foundations of Logic Programming, 2nd edition, Springer-Verlag, New York, NY, 1987.

    MATH  Google Scholar 

  15. Naughton, J. F., “One-Sided Recursion,”Symposium on Principles of Database Systems, ACM, pp. 340–348, 1987.

  16. Naughton, J. F., Ramakrishnan, R., Sagiv, Y., and Ullman, J. D., “Efficient Evaluation of Right-, Left-, and Multi-Linear Rules,”SIGMOD, ACM, pp. 235–242, 1989.

  17. Ramakrishnan R., Bancilhon, F., and Silberschatz, A., “Safety of Recursive Horn Clauses with Infinite Relations,”Symposium on Principles of Database Systems, ACM, pp. 328–339, 1987.

  18. Sagonas, K., Swift, T., and Warren, D. S., “XSB as an Efficient Deductive Database Engine,”Proc. of the 1994 ACM SIGMOD International Conference on the Management of Data, ACM, pp. 442–453, 1994.

  19. Tamaki, H. and Sato, T., “Unfold/Fold Transformation of Logic Programs,”Proc. of the International Conference on Logic Programming, ACM, pp. 127–138, July 1984.

  20. Tamaki, H. and Sato, T., “OLD Resolution with Tabulation,”Proc. of the International Conference on Logic Programming, ACM, pp. 84–98, July 1986.

  21. Ullman, J. D.,Principles of Database and Knowledge-Base Systems, Vol. 1. Computer Science Press, Rockville, Md, 1988.

    Google Scholar 

  22. Ullman, J. D.,Principles of Database and Knowledge-Base Systems, Vol. 2: The New Technologies, Computer Science Press, Rockville, Md, 1989.

    Google Scholar 

  23. Vieille, L., “A Database-Complete Proof Procedure Based on SLD-Resolution,”Proc. of the International Conference on Logic Programming, ACM, pp. 74–103, 1987.

  24. Warren, D. S., “The XWAM: A Machine that Integrates Prolog and Database Query Evaluation,”Architecture Workshop of the North American Conference on Logic Programming, ALP, 1990.

  25. Warren, D. S., “Memoing for Logic Programs,”Communications of the ACM, 35, 3, ACM, pp. 94–111, March 1992.

    Article  MathSciNet  Google Scholar 

  26. Zhang, W. and Yu, C. T., “A Necessary Condition for a Double Recursive Rule to Be Equivalent to a Linear Recursive Rule,”SIGMOD, ACM, pp. 345–356, 1987.

Download references

Author information

Authors and Affiliations

Authors

Additional information

This work was partially supported by the National Science Foundation under Grant CCR-9008737.

Suzanne Wagner Dietrich, Ph.D.: She is an Associate Professor in the Department of Computer Science and Engineering at Arizona State University. Her research emphasis is on the evaluation of declarative logic programs especially in the context of deductive databases, including materialized view maintenance and condition monitoring in active deductive databases. More recently, her research interests include the integration of active, object-oriented and deductive databases as well as the application of this emerging database technology to various disciplines such as software engineering. She received the B. S. degree in computer science in 1983 from the State University of New York at Stony Brook, and as the recipient of an Office of Naval Research Graduate Fellowship, earned her Ph.D. degree in computer science at Stony Brook in 1987.

Changguan Fan, M.S.: He is a Ph.D. candidate in the Department of Computer Science and Engineering at Arizona State University and a software engineer at the Regenisys Corporation in Scottsdale, AZ. His research interests include the evaluation of logic programs, deductive database systems and database management systems. He received his B.S. in Computer Science from the Shanghai Institute of Railway Technology, Shanghai, China in 1982 and his M.S. in the Department of Computer Science and Engineering at Arizona State University in 1989.

About this article

Cite this article

Dietrich, S.W., Fan, C. On the completeness of naive memoing in Prolog. NGCO 15, 141–162 (1997). https://doi.org/10.1007/BF03037235

Download citation

  • Received:

  • Revised:

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF03037235

Keywords

Navigation