Higher-Order and Symbolic Computation

, Volume 18, Issue 1–2, pp 121–210 | Cite as

Derivation of Efficient Logic Programs by Specialization and Reduction of Nondeterminism

  • Alberto Pettorossi
  • Maurizio Proietti
  • Sophie Renault


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.


automatic program derivation program transformation program specialization logic programming transformation rules and strategies 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Apt, K.R. Introduction to logic programming. In Handbook of Theoretical Computer Science, J. van Leeuwen (Ed.), Elsevier, 1990, pp. 493–576.Google Scholar
  2. 2.
    Apt, K.R. From Logic Programming to Prolog. Prentice Hall, 1997.Google Scholar
  3. 3.
    Bird, R.S., Gibbons, J., and Jones, G. Formal derivation of a pattern matching algorithm. Science of Computer Programming, 12 (1989) 93–104.CrossRefGoogle Scholar
  4. 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.CrossRefGoogle Scholar
  5. 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.Google Scholar
  6. 6.
    Burstall, R.M. and Darlington, J. A transformation system for developing recursive programs. Journal of the ACM, 24(1) (1977) 44–67.CrossRefGoogle Scholar
  7. 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.Google Scholar
  8. 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.CrossRefGoogle Scholar
  9. 9.
    Debray, S.K. and Warren, D.S. Automatic mode inference for logic programs. Journal of Logic Programming, 5 (1988) 207–229.CrossRefGoogle Scholar
  10. 10.
    Deville, Y. Logic Programming: Systematic Program Development. Addison-Wesley, 1990.Google Scholar
  11. 11.
    Fujita, H. An algorithm for partial evaluation with constraints. Technical Memorandum TM-0367, ICOT, Tokyo, Japan, 1987.Google Scholar
  12. 12.
    Futamura, Y., Nogi, K., and Takano, A. Essence of generalized partial computation. Theoretical Computer Science, 90 (1991) 61–79.CrossRefGoogle Scholar
  13. 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.Google Scholar
  14. 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.Google Scholar
  15. 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.Google Scholar
  16. 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.Google Scholar
  17. 17.
    Gordon, M.J., Milner, A.J., and Wadsworth, C.P. Edinburgh LCF. Lecture Notes in Computer Science 78. Springer-Verlag, 1979.Google Scholar
  18. 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.Google Scholar
  19. 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.Google Scholar
  20. 20.
    Jaffar, J., Maher, M., Marriott, K., and Stuckey, P. The semantics of constraint logic programming. Journal of Logic Programming, 37 (1998) 1–46.CrossRefGoogle Scholar
  21. 21.
    Jones, N.D., Gomard, C.K., and Sestoft, P. Partial Evaluation and Automatic Program Generation. Prentice Hall, 1993.Google Scholar
  22. 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.CrossRefGoogle Scholar
  23. 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.Google Scholar
  24. 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. 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.CrossRefGoogle Scholar
  26. 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.Google Scholar
  27. 27.
    Liu, Y.A. Efficiency by incrementalization: An introduction. Higher-Order and Symbolic Computation, 13(4) (2000) 289–313.CrossRefGoogle Scholar
  28. 28.
    Lloyd, J.W. Foundations of Logic Programming, 2nd edition. Springer-Verlag, Berlin, 1987.Google Scholar
  29. 29.
    Lloyd, J.W. and Shepherdson, J.C. Partial evaluation in logic programming. Journal of Logic Programming, 11 (1991) 217–242.CrossRefGoogle Scholar
  30. 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.CrossRefGoogle Scholar
  31. 31.
    Mellish, C.S. Some global optimizations for a Prolog compiler. Journal of Logic Programming, 2(1) (1985) 43–66.CrossRefGoogle Scholar
  32. 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.Google Scholar
  33. 33.
    Paige, R. and Koenig, S. Finite differencing of computable expressions. ACM Transactions on Programming Languages and Systems, 4(3) (1982) 402–454.CrossRefGoogle Scholar
  34. 34.
    Pettorossi, A. Transformation of programs and use of tupling strategy. In Proceedings Informatica 77, Bled, Yugoslavia, 1977, pp. 1–6.Google Scholar
  35. 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.Google Scholar
  36. 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.Google Scholar
  37. 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.CrossRefGoogle Scholar
  38. 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.CrossRefGoogle Scholar
  39. 39.
    Renault, S. A system for transforming logic programs. R 97–04, Department of Computer Science, University of Rome Tor Vergata, Rome, Italy, 1997.Google Scholar
  40. 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.Google Scholar
  41. 41.
    Sahlin, D. Mixtus: An automatic partial evaluator for full Prolog. New Generation Computing, 12 (1993) 7–51.Google Scholar
  42. 42.
    Sato, T. An equivalence preserving first order unfold/fold transformation system. Theoretical Computer Science, 105 (1992) 57–84.CrossRefGoogle Scholar
  43. 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.Google Scholar
  44. 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.Google Scholar
  45. 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.CrossRefGoogle Scholar
  46. 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.Google Scholar
  47. 47.
    Turchin, V.F. The concept of a supercompiler. ACM TOPLAS, 8(3) (1986) 292–325.CrossRefGoogle Scholar
  48. 48.
    Wadler, P.L. Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73 (1990) 231–248.CrossRefGoogle Scholar
  49. 49.
    Warren, D.H.D. Implementing Prolog — Compiling predicate logic programs. Research Report 39 & 40, Department of Artificial Intelligence, University of Edinburgh, 1977.Google Scholar

Copyright information

© Springer Science + Business Media, Inc. 2005

Authors and Affiliations

  • Alberto Pettorossi
    • 1
  • Maurizio Proietti
    • 2
  • Sophie Renault
    • 3
  1. 1.DISPUniversity of Roma Tor VergataRomaItaly
  2. 2.IASI-CNRRomaItaly
  3. 3.European Patent OfficeRijswijkThe Netherlands

Personalised recommendations