Non-leftmost Unfolding in Partial Evaluation of Logic Programs with Impure Predicates

  • Elvira Albert
  • Germán Puebla
  • John P. Gallagher
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3901)


Partial evaluation of logic programs which contain impure predicates poses non-trivial challenges. Impure predicates include those which produce side-effects, raise errors (or exceptions), and those whose truth value varies according to the degree of instantiation of arguments. In particular, non-leftmost unfolding steps can produce incorrect results since the independence of the computation rule no longer holds in the presence of impure predicates. Existing proposals allow non-leftmost unfolding steps, but at the cost of accuracy: bindings and failure are not propagated backwards to predicates which are potentially impure. In this work we propose a partial evaluation scheme which substantially reduces the situations in which such backpropagation has to be avoided. With this aim, our partial evaluator takes into account the information about purity of predicates expressed in terms of assertions. This allows some optimizations which are not feasible using existing partial evaluation techniques. We argue that our proposal goes beyond existing ones in that it is a) accurate, since the classification of pure vs impure is done at the level of atoms instead of predicates, b) extensible, as the information about purity can be added to programs using assertions without having to modify the partial evaluator itself, and c) automatic, since (backwards) analysis can be used to automatically infer the required assertions. Our approach has been implemented in the context of CiaoPP, the abstract interpretation-based preprocessor of the Ciao logic programming system.


Logic Program Partial Evaluation Derivation Step Computation Rule Partial Evaluator 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Albert, E., Hanus, M., Vidal, G.: A practical partial evaluation scheme for multi-paradigm declarative languages. Journal of Functional and Logic Programming 2002(1) (2002)Google Scholar
  2. 2.
    Etalle, S., Gabbrielli, M., Marchiori, E.: A Transformation System for CLP with Dynamic Scheduling and CCP. In: Proc. of the ACM Sigplan PEPM 1997, pp. 137–150. ACM Press, New York (1997)Google Scholar
  3. 3.
    Gallagher, J.: A Program Transformation for Backwards Analysis of Logic Programs. In: Bruynooghe, M. (ed.) LOPSTR 2004. LNCS, vol. 3018, pp. 92–105. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  4. 4.
    Gallagher, J.P.: Tutorial on specialisation of logic programs. In: Proceedings of PEPM 1993, the ACM Sigplan Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pp. 88–98. ACM Press, New York (1993)Google Scholar
  5. 5.
    Jacob, M., Howe, A.K., Lu, L.: Analysing Logic Programs by Reasoning Backwards. In: Program Development in Computational Logic. LNCS, pp. 380–393. Springer, Heidelberg (2004)Google Scholar
  6. 6.
    King, A., Lu, L.: A Backward Analysis for Constraint Logic Programs. Theory and Practice of Logic Programming 2(4–5), 32 (2002)MathSciNetzbMATHGoogle Scholar
  7. 7.
    Komorowski, J.: An Introduction to Partial Deduction. In: Pettorossi, A. (ed.) META 1992. LNCS, vol. 649, pp. 49–69. Springer, Heidelberg (1992)CrossRefGoogle Scholar
  8. 8.
    Leuschel, M., Bruynooghe, M.: Logic program specialisation through partial deduction: Control issues. Theory and Practice of Logic Programming 2(4, 5), 461–515 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  9. 9.
    Leuschel, M., Jørgensen, J., Vanhoof, W., Bruynooghe, M.: Offline specialisation in prolog using a hand-written compiler generator. TPLP 4(1–2), 139–191 (2004)zbMATHGoogle Scholar
  10. 10.
    Leuschel, M.: Partial evaluation of the real thing. In: Fribourg, L., Turini, F. (eds.) LOPSTR 1994 and META 1994. LNCS, vol. 883, pp. 122–137. Springer, Heidelberg (1994)CrossRefGoogle Scholar
  11. 11.
    Leuschel, M.: On the Power of Homeomorphic Embedding for Online Termination. In: Levi, G. (ed.) SAS 1998. LNCS, vol. 1503, pp. 230–245. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  12. 12.
    Lloyd, J.W., Shepherdson, J.C.: Partial evaluation in logic programming. The Journal of Logic Programming 11, 217–242 (1991)MathSciNetCrossRefzbMATHGoogle Scholar
  13. 13.
    Lloyd, J.W.: Foundations of Logic Programming, 2nd edn. Springer, Heidelberg (1987)CrossRefzbMATHGoogle Scholar
  14. 14.
    Puebla, G., Albert, E., Hermenegildo, M.: Efficient Local Unfolding with Ancestor Stacks for Full Prolog. In: Bruynooghe, M. (ed.) LOPSTR 2004. LNCS, vol. 3018, pp. 149–165. Springer, Heidelberg (2004)Google Scholar
  15. 15.
    Puebla, G., Bueno, F., Hermenegildo, M.: An Assertion Language for Constraint Logic Programs. In: Deransart, P., Małuszyński, J. (eds.) DiSCiPl 1999. LNCS, vol. 1870, pp. 23–61. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  16. 16.
    Sahlin, D.: Mixtus: An automatic partial evaluator for full Prolog. New Generation Computing 12(1), 7–51 (1993)CrossRefzbMATHGoogle Scholar
  17. 17.
    Venken, R., Demoen, B.: A partial evaluation system for prolog: some practical considerations. New Generation Computing 6, 279–290 (1988)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Elvira Albert
    • 1
  • Germán Puebla
    • 2
  • John P. Gallagher
    • 3
  1. 1.School of Computer ScienceComplutense U. of MadridSpain
  2. 2.School of Computer ScienceTechnical U. of MadridSpain
  3. 3.Department of Computer ScienceUniversity of RoskildeDenmark

Personalised recommendations