New Generation Computing

, Volume 11, Issue 2, pp 125–157 | Cite as

Difference-list transformation for Prolog

  • Kim Marriott
  • Harald Søndergaard
Regular Papers


Difference-lists are terms that represent lists. The use of difference-lists can speed up most list-processing programs considerably. Prolog programmers routinely use “difference-list versions” of programs, but very little investigation has taken place into difference-list transformation. Thus, to most programmers it is either unknown that the use of difference-lists is far from safe in all contexts, or else this fact is known but attributed to Prolog’s infamous “occur check problem.” In this paper we study the transformation of list-processing programs into programs that use differencelists. In particular we are concerned with finding circumstances under which the transformation is safe. We show that dataflow analysis can be used to determine whether the transformation is applicable to a given program, thereby allowing for automatic transformation. We prove that our transformation preserves strong operational equivalence.


Program Optimization Program Analysis Logic Programs 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1).
    Bloch, C., “Source-to-Source Transformations of Logic Programs”,M. Sc. dissertation, Weizmann Institute of Science, Rehovot, Israel, 1984.Google Scholar
  2. 2).
    Bruynooghe, M., Janssens, G., Callebaut, A. and Demoen, B., “Abstract Interpretation: Towards the Global Optimization of Prolog Programs”, inProc. Fourth Int. Symp. Logic Programming, San Francisco, California, pp. 192–204, 1987.Google Scholar
  3. 3).
    Clark, K. and Tärnlund, S.-Å., “A First Order Theory of Data and Programs,” inInformation Processing (B. Gilchrist, ed.), North-Holland, pp. 939–944, 1977.Google Scholar
  4. 4).
    Colmerauer, A., “Metamorphosis Grammars,” inNatural Language Communication with Computers (Lecture Notes in Computer Science 63) (L. Bolc, ed.), Springer-Verlag, pp. 133–189, 1978.Google Scholar
  5. 5).
    Debray, S. K., “Static Inference of Modes and Data Dependencies in Logic Programs,”ACM Transactions on Programming Languages and Systems, 11, 3, pp. 418–450, 1989.CrossRefGoogle Scholar
  6. 6).
    Gardner, P. and Shepherdson, J., “Unfold/Fold Transformations of Logic Programs”, inComputational Logic: Essays in Honor of Alan Robinson (J.-L. Lassez and G. Plotkin, ed.), MIT Press, pp. 565–583, 1991.Google Scholar
  7. 7).
    Hansson, A. and Tärnlund, S.-Å., “Program Transformation by Data Structure Mapping,” inLogic Programming (K. Clark and S.-Å. Tärnlund, ed.) Academic Press, pp. 117–122, 1982.Google Scholar
  8. 8).
    Lassez, J.-L., Maher, M. J. and Marriott, K., “Unification Revisited”, inFoundations of Deductive Databases and Logic Programming (J. Minker, ed.), Morgan Kaufmann, pp. 587–625, 1988.Google Scholar
  9. 9).
    Marriott, K. and Søndergaard, H., “On Prolog and the Occur Check Problem,”SIGPLAN Notices, 24, 5, pp. 76–82, 1989.CrossRefGoogle Scholar
  10. 10).
    Marriott, K. and Søndergaard, H., “Prolog Program Transformation by Introduction of Difference-Lists,” inProc. Int. Computer Science Conf. 88, IEEE Computer Society, Hong Kong, pp. 206–213, 1988.Google Scholar
  11. 11).
    Søndergaard, H., “An Application of Abstract Interpretation of Logic Programs: Occur Check Reduction”, inProc. ESOP 86 (Lecture Notes in Computer Science 213) (B. Robinet and R. Wilhelm, ed.), Springer-Verlag, pp. 327–338, 1986.Google Scholar
  12. 12).
    Sterling, L. and Shapiro, E.,The Art of Prolog: Advanced Programming Techniques, MIT Press, 1986.Google Scholar
  13. 13).
    Tamaki, H. and Sato, T., “Unfold/Fold Transformation of Logic Programs,” inProc. Second Int. Conf. Logic Programming (S.-Å. Tärnlund, ed.), Uppsala, Sweden, pp. 127–138, 1984.Google Scholar
  14. 14).
    Tärnlund, S.-Å., “An Axiomatic Data Base Theory,” inLogic and Databases (H. Gallaire and J. Minker, ed.), Plenum Press, pp. 259–289, 1978.Google Scholar
  15. 15).
    Winsborough, W., “Automatic, Transparent Parallelization of Logic Programs at Compile Time”,Ph. D. thesis, University of Wisconsin-Madison, Wisconsin, 1988.Google Scholar
  16. 16).
    Zhang, J. and Grant, P., “An Automatic Difference-List Transformation Algorithm for Prolog”, inProc. 1988 EuropeanConf. Artificial Intelligence (Y. Kodratoff, ed.), Pitman, pp, 320–325, 1988.Google Scholar

Copyright information

© Ohmsha, Ltd. and Springer 1993

Authors and Affiliations

  • Kim Marriott
    • 1
  • Harald Søndergaard
    • 2
  1. 1.Department of Computer ScienceMonash UniversityClaytonAustralia
  2. 2.Department of Computer ScienceUniversity of MelbourneParkvilleAustralia

Personalised recommendations