Optimizing equational programs
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.
- 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
- 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
- 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
- Ga85.Gabriel, R. P. Performance and Evaluation of Lisp Systems, MIT Press, Cambridge, Mass. (1985).Google Scholar
- HL79.Huet, G. and Lévy, J.-J. ”Computations in Non-ambiguous Linear Term Rewriting Systems”, INRIA Technical Report #359 (1979).Google Scholar
- HM76.Henderson, P. and Morris, J. H. ”A Lazy Evaluator”, 3rd ACM Symposium on Principles of Programming Languages pp. 95–103 (1976).Google Scholar
- HO82a.Hoffmann, C., O'Donnell, M. ”Pattern Matching in Trees”, Journal of the ACM, pp. 68–95 (1982).Google Scholar
- HO82b.Hoffmann, C., O'Donnell, M. ”Programming with Equations”, ACM Transactions on Programming Languages and Systems pp. 83–112 (1982).Google Scholar
- HOS85.Hoffmann, C., O'Donnell, M. and Strandh, R., ”Programming with Equations”, Software, Practice and Experience, (December 1985).Google Scholar
- Jo84.Johnsson, T. ”Efficient Compilation of Lazy Evaluation”, Proceedings of the ACM SIGPLAN 1984 Symposium on Compiler Construction, Montreal (1984).Google Scholar
- 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
- OD77.O'Donnell, M. J. Computing in Systems Described by Equations, Lecture Notes in Computer Science v. 58, Springer-Verlag (1977).Google Scholar
- OD85.O'Donnell, M. J. Equational Logic as a Programming Language, MIT Press, Cambridge, Mass. (1985).Google Scholar
- Th85.Thatte, S. ”On the Correspondence Between Two Classes of Reduction Systems” Information Processing Letters 20, pp. 83–85, (1985).Google Scholar