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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
K. R. Apt: Introduction to logic programming. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, 493–576. Elsevier, 1990.
K. R. Apt: From Logic Programming to Prolog. Prentice-Hall, London, 1997.
R. S. Bird, J. Gibbons, and G. Jones: Formal derivation of a pattern matching algorithm. Science of Computer Programming, 12:93–104, 1989.
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.
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.
R. M. Burstall and J. Darlington: A transformation system for developing recursive programs. Journal of the ACM, 24(1):44–67, January 1977.
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.
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.
S. K. Debray and D. S. Warren: Automatic mode inference for logic programs. Journal of Logic Programming, 5:207–229, 1988.
Y. Deville: Logic Programming: Systematic Program Development. Addison-Wesley, 1990.
H. Fujita: An algorithm for partial evaluation with constraints. Technical Memorandum TM-0367, ICOT, Tokyo, Japan, 1987.
Y. Futamura, K. Nogi, and A. Takano: Essence of generalized partial computation. Theoretical Computer Science, 90:61–79, 1991.
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.
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.
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.
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.
M. J. Gordon, A. J. Milner, and C. P. Wadsworth: Edinburgh LCF. Lecture Notes in Computer Science 78. Springer, 1979.
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.
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.
J. Jaffar, M. Maher, K. Marriott, and P. Stuckey: The semantics of constraint logic programming. Journal of Logic Programming, 37:1–46, 1998.
N. D. Jones, C. K. Gomard, and P. Sestoft: Partial Evaluation and Automatic Program Generation. Prentice-Hall, 1993.
D. E. Knuth, J. H. Morris, and V. R. Pratt: Fast pattern matching in strings. SIAM Journal on Computing, 6(2):323–350, 1977.
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.
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.
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.
M. Leuschel, B. Martens, and D. de Schreye: Some achievements and prospects in partial deduction. ACM Computing Surveys, 30 (Electronic Section)(3es):4, 1998.
Y. A. Liu: Efficiency by incrementalization: An introduction. Higher-Order and Symbolic Computation, 13(4):289–313, 2000.
J. W. Lloyd: Foundations of Logic Programming. Springer, Berlin. Second Edition, 1987.
J. W. Lloyd and J. C. Shepherdson: Partial evaluation in logic programming. Journal of Logic Programming, 11:217–242, 1991.
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.
C. S. Mellish: Some global optimizations for a Prolog compiler. Journal of Logic Programming, 2(1):43–66, 1985.
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.
R. Paige and S. Koenig: Finite differencing of computable expressions. ACM Transactions on Programming Languages and Systems, 4(3):402–454, 1982.
A. Pettorossi: Transformation of programs and use of tupling strategy. In Proceedings Informatica 77, Bled, Yugoslavia, 1–6, 1977.
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.
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.
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.
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.
S. Renault: A system for transforming logic programs. R 97–04, Department of Computer Science, University of Rome Tor Vergata, Rome, Italy, 1997.
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.
D. Sahlin: Mixtus: An automatic partial evaluator for full Prolog. New Generation Computing, 12:7–51, 1993.
T. Sato: An equivalence preserving first order unfold/fold transformation system. Theoretical Computer Science, 105:57–84, 1992.
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.
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.
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.
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.
V. F. Turchin: The concept of a supercompiler. ACM TOPLAS, 8(3):292–325, 1986.
P. L. Wadler: Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73:231–248, 1990.
D. H. D. Warren: Implementing Prolog – compiling predicate logic programs. Research Report 39 & 40, Department of Artificial Intelligence, University of Edinburgh, 1977.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)