The Generation of Optimal Code for Arithmetic Expressions

Ravi Sethi, J. D. Ullman

Research output: Contribution to journalArticlepeer-review

179 Scopus citations


The problem of evaluating arithmetic expressions on a machine with N ≥ 1 general purpose registers is considered. It is initially assumed that no algebraic laws apply to the operators and operands in the expression. An algorithm for evaluation of expressions under this assumption is proposed, and it is shown to take the shortest possible number of instructions. It is then assumed that certain operators are commutative or both commutative and associative. In this case a procedure is given for finding an expression equivalent to a given one and having the shortest possible evaluation sequence. It is then shown that the algorithms presented here also minimize the number of storage references in the evaluation.

Original languageEnglish (US)
Pages (from-to)715-728
Number of pages14
JournalJournal of the ACM (JACM)
Issue number4
StatePublished - Oct 1 1970

ASJC Scopus subject areas

  • Software
  • Control and Systems Engineering
  • Information Systems
  • Hardware and Architecture
  • Artificial Intelligence


Dive into the research topics of 'The Generation of Optimal Code for Arithmetic Expressions'. Together they form a unique fingerprint.

Cite this