Skip to main content

Derivation of Efficient Logic Programs by Specialization and Reduction of Nondeterminism

  • Chapter
  • 318 Accesses

Summary

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.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   84.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD   109.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

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

    Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  7. O. Danvy, R. Glück, and P. Thiemann, editors: Partial Evaluation. International Seminar, Dagstuhl Castle, Germany, February 1996, Lecture Notes in Computer Science 1110, Springer, 1996.

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Article  MATH  Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  23. M. Leuschel: On the power of homeomorphic embedding for online termination. In G. Levi, editor, Proceedings of the Fifth Static Analysis Symposium, SAS ’98, Pisa, Italy, Lecture Notes in Computer Science 1503, 230–245. Springer, 1998.

    Google Scholar 

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

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

    Article  Google Scholar 

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

    Article  Google Scholar 

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

    Article  MATH  Google Scholar 

  28. J. W. Lloyd: Foundations of Logic Programming. Springer, Berlin. Second Edition, 1987.

    MATH  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  MATH  Google Scholar 

  32. C. S. Mellish: Abstract interpretation of Prolog programs. In S. Abramsky and C. Hankin, editors, Abstract Interpretation of Declaratice Languages, chapter 8, 181–198. Ellis Horwood, 1987.

    Google Scholar 

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

    Article  MATH  Google Scholar 

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

    Google Scholar 

  35. A. Pettorossi, M. Proietti, and S. Renault: Derivation of efficient logic programs by specialization and reduction of nondeterminism. Higher-Order and Symbolic Computation, 18(1–2):121–210, 2005.

    Article  MATH  Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Google Scholar 

  40. A. Roychoudhury, K. Narayan Kumar, C. R. Ramakrishnan, and I. V. Ramakrishnan: 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, 396–413. Springer, 1999.

    Google Scholar 

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

    Article  MATH  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Google Scholar 

  44. D. A. Smith: 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, 62–71. ACM Press, 1991.

    Google Scholar 

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

    Article  MATH  Google Scholar 

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

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

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

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2008 Springer

About this chapter

Cite this chapter

Pettorossi, A., Proietti, M., Renault, S. (2008). Derivation of Efficient Logic Programs by Specialization and Reduction of Nondeterminism. In: Danvy, O., Mairson, H., Henglein, F., Pettorossi, A. (eds) Automatic Program Development. Springer, Dordrecht. https://doi.org/10.1007/978-1-4020-6585-9_12

Download citation

  • DOI: https://doi.org/10.1007/978-1-4020-6585-9_12

  • Publisher Name: Springer, Dordrecht

  • Print ISBN: 978-1-4020-6584-2

  • Online ISBN: 978-1-4020-6585-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics