Equational Reasoning using AC Constraints David A. Plaisted and Yunshan Zhu Computer Science Department University of North Carolina Chapel Hill, NC 27599-3175 {plaisted,zhu}@cs.unc.edu Fax: (919)962-1799 Abstract Unfailing completion is a commonly used tech- nique for equational reasoning. For equational problems with associative and commutative functions, unfailing completion often generates a large number of rewrite rules. By compar- ing it with a ground completion procedure, we show that many of the rewrite rules gen- erated are redundant. A set of consistency constraints is formulated to detect redundant rewrite rules. We propose a new completion algorithm, consistent unfailing completion, in which only consistent rewrite rules are used for critical pair generation and rewriting. Our ap- proach does not need to use flattened terms. Thus it avoids the double exponential worst case complexity of AC unification. It also al- lows the use of more flexible termination order- ings. We present some sufficient conditions for detecting inconsistent rewrite rules. The pro- posed algorithm is implemented in PROLOG. 1 Introduction Knuth-Bendix completion [Knuth and Bendix, 1970] and its extensions [Bachmair et a/., 1989] have been widely used for equational reasoning. One of the main bot- tlenecks of completion-based inference strategies is the large number of critical pairs generated. This is particu- larly evident when dealing with equational problems in- volving associative and commutative functions, i.e. AC equational problems. In this paper, we present a tech- nique for reducing redundant equational inferences using constraints. AC equational problems represent an important class of problems in theorem proving. Many mathematical functions of interest are associative and commutative. For example, the union and intersection operations in set theory and the addition operations in ring structures are all associative and commutative. Furthermore, addi- tion and multiplication in arithmetic are both AC. Some form of AC equational reasoning is necessary if a term rewriting system is used to perform integer arithmetic. AC equational reasoning is often difficult. One of the most recognized recent successes of automated reason- ing, perhaps of Al in general, is the solution of the Rob- bins Problem. The Robbins Problem is in fact formu- lated as an equational problem with AC functions [Mc- Cune, 1996]. Most term rewriting systems do inferences by generating rewrite rules using Knuth-Bendix comple- tion or unfailing completion. Associativity axioms and commutativity axioms often cause an explosion of new rewrite rules in the completion process. When over- lapped with the AC axioms, an existing rewrite rule can generate an exponential number of AC equivalent rewrite rules. Since commutativity axioms cannot be oriented in any termination ordering, many of these new rewrite rules generated from the AC axioms cannot be simplified. Special completion procedures are developed to han- dle AC equational problems [Lankford and Ballantyne, 1977; Peterson and Stickel, 1981]. Most of the ap- proaches in the literature use flattened terms. For exam- ple, +(a,+(6,c)) is represented as +(a,b,c), and terms +(a,c, b) and +(a,b, c) are considered identical. A flat- tened term represents all terms equivalent up to the AC axioms. Since flattening breaks the original term structure, special unification techniques are needed. AC unification algorithms [Stickel, 1981; Domenjoud, 1991; Boudet et a/., 1996] are developed to compute all possible most general unifiers of two terms up to associativity and commutativity axioms. Special AC termination order- ings are also needed to show termination of AC rewriting systems. Many commonly used orderings, such as recur- sive path ordering and lexicographic path ordering, are no longer well founded when flattened terms are used. Several AC termination ordering have been devised [Dershowitz et a/., 1983; Bachmair and Plaisted, 1985; Kapur et a/., 1990]. We study the problem of AC equational reasoning with a different approach. We propose a procedure called consistent unfailing completion in which only consistent rules and equations are used for critical pair generation and rewriting. A consistent unfailing completion proce- dure can be regarded as the lifted version of a ground completion procedure. In a standard unfailing comple- tion procedure, some rewrite rules do not correspond to 108 AUTOMATED REASONING