Skip to main content
Log in

Derivation of Efficient Logic Programs by Specialization and Reduction of Nondeterminism

  • Published:
Higher-Order and Symbolic Computation

Abstract

Program specialization is a program transformation methodology which improves program efficiency by exploiting the information about the input data which are available at compile time. We show that current techniques for program specialization based on partial evaluation do not perform well on nondeterministic logic programs. We then consider a set of transformation rules which extend the ones used for partial evaluation, and we propose a strategy for guiding the application of these extended rules so to derive very efficient specialized programs. The efficiency improvements which sometimes are exponential, are due to the reduction of nondeterminism and to the fact that the computations which are performed by the initial programs in different branches of the computation trees, are performed by the specialized programs within single branches. In order to reduce nondeterminism we also make use of mode information for guiding the unfolding process. To exemplify our technique, we show that we can automatically derive very efficient matching programs and parsers for regular languages. The derivations we have performed could not have been done by previously known partial evaluation techniques.

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.

Institutional subscriptions

Similar content being viewed by others

References

  1. Apt, K.R. Introduction to logic programming. In Handbook of Theoretical Computer Science, J. van Leeuwen (Ed.), Elsevier, 1990, pp. 493–576.

  2. Apt, K.R. From Logic Programming to Prolog. Prentice Hall, 1997.

  3. Bird, R.S., Gibbons, J., and Jones, G. Formal derivation of a pattern matching algorithm. Science of Computer Programming, 12 (1989) 93–104.

    Article  Google Scholar 

  4. Bossi, A., Cocco, N., and Dulli, S. A method for specializing logic programs. ACM Transactions on Programming Languages and Systems, 12(2) (1990) 253–302.

    Article  Google Scholar 

  5. Bossi, A., Cocco, N., and Etalle, S. Transforming left-terminating programs. In Proceedings of the Ninth International Workshop on Logic-based Program Synthesis, LOPSTR’99, A. Bossi (Ed.), Venezia, Italy, September 22–24, 1999, Lecture Notes in Computer Science 1817, Springer, 2000, 156–175.

  6. Burstall, R.M. and Darlington, J. A transformation system for developing recursive programs. Journal of the ACM, 24(1) (1977) 44–67.

    Article  Google Scholar 

  7. Danvy, O., Glück, R., and Thiemann, P. (Eds). Partial Evaluation. International Seminar, Dagstuhl Castle, Germany, vol. 1110 of Lecture Notes in Computer Science. Springer-Verlag, 1996.

  8. De Schreye, D., Glück, R., Jørgensen, J., Leuschel, M., Martens, B., and Sørensen, M.H. Conjunctive partial deduction: Foundations, control, algorithms, and experiments. Journal of Logic Programming, 41(2–3) (1999) 231–277.

    Article  Google Scholar 

  9. Debray, S.K. and Warren, D.S. Automatic mode inference for logic programs. Journal of Logic Programming, 5 (1988) 207–229.

    Article  Google Scholar 

  10. Deville, Y. Logic Programming: Systematic Program Development. Addison-Wesley, 1990.

  11. Fujita, H. An algorithm for partial evaluation with constraints. Technical Memorandum TM-0367, ICOT, Tokyo, Japan, 1987.

  12. Futamura, Y., Nogi, K., and Takano, A. Essence of generalized partial computation. Theoretical Computer Science, 90 (1991) 61–79.

    Article  Google Scholar 

  13. Gallagher, J.P. Tutorial on specialisation of logic programs. In Proceedings of ACM SIGPLAN Symposium on Partial Evaluation and Semantics Based Program Manipulation, PEPM ‘93, Copenhagen, Denmark, ACM Press, 1993, pp. 88–98.

  14. Gergatsoulis, M. and Katzouraki, M. Unfold/fold transformations for definite clause programs. In Proceedings Sixth International Symposium on Programming Language Implementation and Logic Programming (PLILP ‘94), M. Hermenegildo and J. Penjam (Eds.), Lecture Notes in Computer Science 844, Springer-Verlag, 1994, pp. 340–354.

  15. Glück, R. and Klimov, A.V. Occam’s razor in metacomputation: The notion of a perfect process tree. In 3rd International Workshop on Static Analysis, Padova, Italy, September 1993, P. Cousot, M. Falaschi, G. Filé, and A. Rauzy (Eds.), Lecture Notes in Computer Science 724, Springer-Verlag, 1993, pp. 112–123.

  16. Glück, R. and Sørensen, M.H. A roadmap to metacomputation by supercompilation. In Partial Evaluation, O. Danvy, R. Glück, and P. Thiemann (Eds.), Lecture Notes in Computer Science 1110, Springer, 1996, pp. 137–160.

  17. Gordon, M.J., Milner, A.J., and Wadsworth, C.P. Edinburgh LCF. Lecture Notes in Computer Science 78. Springer-Verlag, 1979.

  18. Henderson, F., Somogyi, Z., and Conway, T. Determinism analysis in the Mercury compiler. In Proceedings of the Australian Computer Science Conference, Melbourne, Australia, 1996, pp. 337–346.

  19. Hermenegildo, M.V., Bueno, F., Puebla, G., and López, P. Program analysis, debugging, and optimization using the CIAO system preprocessor. In Proceedings of the 1999 International Conference on Logic Programming, D. De Schreye (Ed.), Las Cruces, NM, USA, MIT Press, 1999, pp. 52–66.

  20. Jaffar, J., Maher, M., Marriott, K., and Stuckey, P. The semantics of constraint logic programming. Journal of Logic Programming, 37 (1998) 1–46.

    Article  Google Scholar 

  21. Jones, N.D., Gomard, C.K., and Sestoft, P. Partial Evaluation and Automatic Program Generation. Prentice Hall, 1993.

  22. Knuth, D.E., Morris, J.H., and Pratt, V.R. Fast pattern matching in strings. SIAM Journal on Computing, 6(2) (1977) 323–350.

    Article  Google Scholar 

  23. Leuschel, M. On the power of homeomorphic embedding for online termination. In Proceedings of the Fifth Static Analysis Symposium, SAS ‘98, G. Levi (Ed.) Pisa, Italy, Lecture Notes in Computer Science 1503, Springer-Verlag, 1998, pp. 230–245.

  24. Leuschel, M. The ECCE partial deduction system and the DPPD library of benchmarks, Release 3, Nov. 2000. Accessible via http://www.ecs.soton.ac.uk/mal.

  25. Leuschel, M., Martens, B., and De Schreye, D. Controlling generalization and polyvariance in partial deduction of normal logic programs. ACM Transactions on Programming Languages and Systems, 20(1) (1998) 208–258.

    Article  Google Scholar 

  26. Leuschel, M., Martens, B., and de Schreye, D. Some achievements and prospects in partial deduction. ACM Computing Surveys, 30 (Electronic Section) (3es) (1998) 4.

  27. Liu, Y.A. Efficiency by incrementalization: An introduction. Higher-Order and Symbolic Computation, 13(4) (2000) 289–313.

    Article  Google Scholar 

  28. Lloyd, J.W. Foundations of Logic Programming, 2nd edition. Springer-Verlag, Berlin, 1987.

    Google Scholar 

  29. Lloyd, J.W. and Shepherdson, J.C. Partial evaluation in logic programming. Journal of Logic Programming, 11 (1991) 217–242.

    Article  Google Scholar 

  30. Martens, B., De Schreye, D., and HorvÁth, T. Sound and complete partial deduction with unfolding based on well-founded measures. Theoretical Computer Science, 122 (1994) 97–117.

    Article  Google Scholar 

  31. Mellish, C.S. Some global optimizations for a Prolog compiler. Journal of Logic Programming, 2(1) (1985) 43–66.

    Article  Google Scholar 

  32. Mellish, C.S. Abstract interpretation of Prolog programs. In Abstract Interpretation of Declaratice Languages, In S. Abramsky and C. Hankin (Eds.), Chapter 8, Ellis Horwood, 1987, pp. 181–198.

  33. Paige, R. and Koenig, S. Finite differencing of computable expressions. ACM Transactions on Programming Languages and Systems, 4(3) (1982) 402–454.

    Article  Google Scholar 

  34. Pettorossi, A. Transformation of programs and use of tupling strategy. In Proceedings Informatica 77, Bled, Yugoslavia, 1977, pp. 1–6.

  35. Pettorossi, A., Proietti, M., and Renault, S. Reducing nondeterminism while specializing logic programs. In Proc. 24-th ACM Symposium on Principles of Programming Languages, Paris, France, ACM Press, 1997, pp. 414–427.

  36. Prestwich, S. Online partial deduction of large programs. In ACM Sigplan Symposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM ‘93, Copenhagen, Denmark, ACM Press, 1993, pp. 111–118.

  37. Proietti, M. and Pettorossi, A. The loop absorption and the generalization strategies for the development of logic programs and partial deduction. Journal of Logic Programming, 16(1–2) (1993) 123–161.

    Article  Google Scholar 

  38. Proietti, M. and Pettorossi, A. Unfolding-definition-folding, in this order, for avoiding unnecessary variables in logic programs. Theoretical Computer Science, 142(1) (1995) 89–124.

    Article  Google Scholar 

  39. Renault, S. A system for transforming logic programs. R 97–04, Department of Computer Science, University of Rome Tor Vergata, Rome, Italy, 1997.

  40. Roychoudhury, A., Narayan Kumar, K., Ramakrishnan, C.R., and Ramakrishnan, I.V. A parameterized unfold/fold transformation framework for definite logic programs. In Proceedings of Principles and Practice of Declarative Programming (PPDP), Lecture Notes in Computer Science 1702, pp. 396–413. Springer-Verlag, 1999.

  41. Sahlin, D. Mixtus: An automatic partial evaluator for full Prolog. New Generation Computing, 12 (1993) 7–51.

    Google Scholar 

  42. Sato, T. An equivalence preserving first order unfold/fold transformation system. Theoretical Computer Science, 105 (1992) 57–84.

    Article  Google Scholar 

  43. Sawamura, H. and Takeshima, T. Recursive unsolvability of determinacy, solvable cases of determinacy and their application to Prolog optimization. In Proceedings of the International Symposium on Logic Programming, Boston, IEEE Computer Society Press, 1985, pp. 200–207.

  44. Smith, D.A. Partial evaluation of pattern matching in constraint logic programming languages. In Proceedings ACM Symposium on Partial Evaluation and Semantics Based Program Manipulation, PEPM ‘91, New Haven, CT, USA, SIGPLAN Notices, 26(9), ACM Press, 1991, pp. 62–71.

  45. Somogyi, Z., Henderson, F., and Conway, T. The execution algorithm of Mercury: an efficient purely declarative logic programming language. Journal of Logic Programming, 29(1–3) (1996) 17–64.

    Article  Google Scholar 

  46. Tamaki, H. and Sato, T. Unfold/fold transformation of logic programs. In Proceedings of the Second International Conference on Logic Programming, S.-Å. Tärnlund (Ed.), Uppsala, Sweden, Uppsala University, 1984, pp. 127–138.

  47. Turchin, V.F. The concept of a supercompiler. ACM TOPLAS, 8(3) (1986) 292–325.

    Article  Google Scholar 

  48. Wadler, P.L. Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73 (1990) 231–248.

    Article  Google Scholar 

  49. Warren, D.H.D. Implementing Prolog — Compiling predicate logic programs. Research Report 39 & 40, Department of Artificial Intelligence, University of Edinburgh, 1977.

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Alberto Pettorossi.

Additional information

A preliminary version of this paper appears as: Reducing Nondeterminism while Specializing Logic Programs. Proceedings of the 24th Annual ACM Symposium on Principles of Programming Languages, Paris, France, January 15–17, 1997, ACM Press, 1997, pp. 414–427.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Pettorossi, A., Proietti, M. & Renault, S. Derivation of Efficient Logic Programs by Specialization and Reduction of Nondeterminism. Higher-Order Symb Comput 18, 121–210 (2005). https://doi.org/10.1007/s10990-005-7008-3

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-005-7008-3

Keywords

Navigation