Optimizing equational programs

  • Robert Strandh
Part of the Lecture Notes in Computer Science book series (LNCS, volume 256)


Equational programming [HO82b] involves replacing subterms in a term according to a set of equations or rewrite rules. Each time an equation is applied to the term, the subterm that matches the left hand side of the equation is replaced by the corresponding right hand side. In that process several nodes of the term tree are created. Some of these nodes may later turn out to be useless, and will be reclaimed.

This paper discusses important relationships between two equational programs. In particular we define the term mutual confluence and show that two equational programs with the mutual confluence property have the same output behavior with very general assumptions about the reduction strategy. As an application of our result, we discuss source-to-source transformations of an equational program E to an equational program F. Our transformations are used as a part of a compiler to improve execution time of E by avoiding the creation of too many nodes in the reduction process. We show that our transformations indeed give E and F the mutual confluence property, thus preserving the output behavior of E when transformed to F.

Preserving the output behavior is more general than preserving just normal forms, in that we allow for infinite computations where we output stable parts of the term, i.e., parts that can never change as a result of further reductions.

7. Bibliography

  1. AC75.
    Aho, A. V. and Corasick, M. J. ”Efficient String Matching: An Aid to Bibliographic Search”, Communications of the ACM 18:6 pp. 333–340 (1975).Google Scholar
  2. Ba78.
    Backus, J. ”Can Programming Be Liberated from the von Neumann Style? A Functional Style and its Algebra of Programs”, Communications of the ACM 21:8 pp. 613–641 (1978).Google Scholar
  3. FW76.
    Friedman, D. and Wise, D. ”Cons should not evaluate its arguments”, 3rd International Colloquium on Automata, Languages and Programming., Edinburgh University Press pp. 257–284 (1976).Google Scholar
  4. Ga85.
    Gabriel, R. P. Performance and Evaluation of Lisp Systems, MIT Press, Cambridge, Mass. (1985).Google Scholar
  5. HL79.
    Huet, G. and Lévy, J.-J. ”Computations in Non-ambiguous Linear Term Rewriting Systems”, INRIA Technical Report #359 (1979).Google Scholar
  6. HM76.
    Henderson, P. and Morris, J. H. ”A Lazy Evaluator”, 3rd ACM Symposium on Principles of Programming Languages pp. 95–103 (1976).Google Scholar
  7. HO82a.
    Hoffmann, C., O'Donnell, M. ”Pattern Matching in Trees”, Journal of the ACM, pp. 68–95 (1982).Google Scholar
  8. HO82b.
    Hoffmann, C., O'Donnell, M. ”Programming with Equations”, ACM Transactions on Programming Languages and Systems pp. 83–112 (1982).Google Scholar
  9. HOS85.
    Hoffmann, C., O'Donnell, M. and Strandh, R., ”Programming with Equations”, Software, Practice and Experience, (December 1985).Google Scholar
  10. Jo84.
    Johnsson, T. ”Efficient Compilation of Lazy Evaluation”, Proceedings of the ACM SIGPLAN 1984 Symposium on Compiler Construction, Montreal (1984).Google Scholar
  11. KMP77.
    Knuth, D. E., Morris, J. and Pratt, V. ”Fast Pattern Matching in Strings” SIAM Journal on Computing 6:2: pp. 323–350 (1977).Google Scholar
  12. OD77.
    O'Donnell, M. J. Computing in Systems Described by Equations, Lecture Notes in Computer Science v. 58, Springer-Verlag (1977).Google Scholar
  13. OD85.
    O'Donnell, M. J. Equational Logic as a Programming Language, MIT Press, Cambridge, Mass. (1985).Google Scholar
  14. Th85.
    Thatte, S. ”On the Correspondence Between Two Classes of Reduction Systems” Information Processing Letters 20, pp. 83–85, (1985).Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1987

Authors and Affiliations

  • Robert Strandh
    • 1
  1. 1.Department of Computer ScienceThe Johns Hopkins UniversityBaltimore

Personalised recommendations