key: cord-0046594-q0ymyyaz authors: Baader, Franz; Kapur, Deepak title: Deciding the Word Problem for Ground Identities with Commutative and Extensional Symbols date: 2020-05-30 journal: Automated Reasoning DOI: 10.1007/978-3-030-51074-9_10 sha: b9427552350364d734f350bfc8919d1f4b60a142 doc_id: 46594 cord_uid: q0ymyyaz The word problem for a finite set of ground identities is known to be decidable in polynomial time, and this is also the case if some of the function symbols are assumed to be commutative. We show that decidability in P is preserved if we also assume that certain function symbols f are extensional in the sense that [Formula: see text] implies [Formula: see text]. In addition, we investigate a variant of extensionality that is more appropriate for commutative function symbols, but which raises the complexity of the word problem to coNP. One motivation for this work stems from Description Logic (DL) [1] , where constant symbols (called individual names) are used within knowledge bases to denote objects or individuals in an application domain. If such objects are composed of other objects, it makes sense to represent them as (ground) terms rather than constants. For example, the couple consisting of individual a in the first component and individual b in the second component is more reasonably represented by the term f (a, b) (where f is a binary function symbol denoting the couple constructor) than by a third constant c that is unrelated to a and b. In fact, if we have two couples, one consisting of a and b and the other of a and b , and we learn (by DL reasoning or from external sources) that a is equal to a and b is equal to b , then this automatically implies that f (a, b) is equal to f (a , b ), i.e., that this is one and the same couple, whereas we would not obtain such a consequence if we had introduced constants c and c for the two couples. If we use terms to represent objects, and can learn (e.g., by DL reasoning) that two terms are supposed to be equal, we need to be able to decide which other identities between terms can be derived from the given ones. Fortunately, this problem (usually called the word problem for ground identities) is decidable in polynomial time. The standard approach for deciding this word problem is congruence closure [3, 5, 10, 12] . Basically, congruence closure starts with the given set of ground identities E, and then extends it using closure under reflexivity, symmetry, transitivity, and congruence. The set CC (E) obtained this way is usually infinite, and the main observation that yields decidability in polynomial time is that one can restrict it to the subterms of E and the subterms of the terms for which one wants to decide the word problem. An alternative approach for deciding the word problem for ground identities is based on term rewriting. Basically, in this approach one generates an appropriate canonical term rewriting system from E, and then decides whether two terms are equal modulo the theory E by computing their canonical forms and checking whether they are syntactically equal. This was implicit in [15] , and made explicit in [7] (see also [6, 16] for other rewriting-based approaches). In the motivating example from DL, but also in other settings where congruence closure is employed (such as SMT [13, 17] ), it sometimes makes sense to assume that certain function symbols satisfy additional properties that are not expressible by finitely many ground identities. For example, one may want to considered couples where the order of the components is irrelevant, which means that the couple constructor function is commutative. Another interesting property for (ordered) couples is extensionality: if two couples are equal then they must have the same first and second components, i.e., the couple constructor f must satisfy the extensionality rule f (x, y) ≈ f (x , y ) ⇒ x ≈ x ∧ y ≈ y . While it is known that adding commutativity does not increase the complexity (see, e.g., [5, 8] ), extensionality has, to the best of our knowledge, not been considered in this context before. The problem with extensionality is that it allows us to derive "small" identities from larger ones. Consequently, it is conceivable that one first needs to generate such large identities using congruence and applying other rules, before one can get back to a smaller one through the application of extensionality. Thus, it is not obvious that also with extensionality one can restrict congruence closure to a finite set of terms determined by the input. Here, we will tackle this problem using a rewriting-based approach. Our proofs imply that, also with extensional symbols, proofs of identities that detour through "large" terms can be replaced by proofs using only "small" terms, but it is not clear how this could be shown directly without the rewriting-based approach. In the next section, we show how the rewriting-based approach of [7] can be extended such that it can also handle commutative symbols. In contrast to approaches that deal with associative-commutative (AC) symbols [4, 11] using rewriting modulo AC, we treat commutativity by introducing an additional rewrite system consisting of appropriately ordered ground instances of commutativity. This sets the stage for our rewriting-based approach that works in the presence of commutative symbols and extensional symbols presented in Sect. 4. In this section, we do not consider symbols f that are both commutative and extensional since extensionality as defined until now is not appropriate for commutative symbols: for arbitrary terms s, t, commutativity yields f (s, t) ≈ f (t, s), and thus extensionality implies s ≈ t, which shows that the equational theory becomes trivial. In Sect. 5, we introduce the notion of c-extensionality, which is more appropriate for commutative symbols. Whereas the approaches developed in Sects. 3 and 4 yield polynomial time decision procedures for the word problem, c-extensionality makes the word problem coNP-complete. Due to space constraints not all proofs can be given here. Detailed proofs can be found in [2] . We assume that the reader is familiar with basic notions and results regarding equational theories, universal algebra, and term rewriting. Here, we briefly recall the most important notions and results and refer the readers to [3] for details. We will keep as close as possible to the notation introduced in [3] . In particular, we use ≈ to denote identities between terms and = to denote syntactic equality. Terms are built as usual from variables, constants, and function symbols. An identity is a pair of terms (s, t), which we usually write as s ≈ t. A ground term is a term not containing variables and a ground identity is a pair of ground terms. Given a set of identities E, the equational theory induced by E is defined (semantically) as ≈ E := {s ≈ t | every models of E is a model of s ≈ t}. The notion of model used here is the usual one from first-order logic, where we assume that identities are (implicitly) universally quantified. Since we consider signatures consisting only of constant and function symbols, we call first-order interpretations algebras. Birkhoff's theorem provides us with an alternative characterization of ≈ E that is based on rewriting. A given set of identities E induces a binary relation → E on terms. Basically, we have s → E t if there is an identity ≈ r in E such that s contains a substitution instance σ( ) of as subterm, and t is obtained from s by replacing this subterm with σ(r). Birkhoff's theorem says that ≈ E is identical to * ↔ E , where * ↔ E denotes the reflexive, transitive, and symmetric closure of → E . If → E is canonical (i.e., terminating and confluent), then we have s * ↔ E t iff s and t have the same canonical forms. The canonical form of a term s is an irreducible term s such that s * → E s, where * → E denotes the reflexive and transitive closure of → E and s is irreducible if there is no s with s → E s . Termination ensures that the canonical form exists and confluence that it is Termination can be proved using a so-called reduction order, which is a wellfounded order > on terms such that > r for all ≈ r ∈ E implies s > t for all terms s, t with s → E t. Since > is well-founded this then implies termination. If → E is terminating, then confluence can be tested by checking whether all critical pairs of E are joinable. Basically, critical pairs (t 1 , t 2 ) consider the most general forks of the form s → E t 1 and s → E t 2 that are due to overlapping left-hand sides of identities. Such a pair is joinable if there is a term t such that t 1 Usually, when considering the relation → E , one calls E a term rewriting system rather than a set of identities, and writes its elements (called rewrite rules) as → r rather than ≈ r. From a formal point of view, however, both rewrite rules and identities are pairs of terms. Given a set of such pairs, we can view it as a set of identities or a term rewriting system, and thus the notions introduced above apply to both. Let Σ be a finite set of function symbols of arity ≥ 1 and C 0 a finite set of constant symbols. We denote the set of ground terms built using symbols from Σ and C 0 with G(Σ, C 0 ). In the following, let E be a finite set of identities s ≈ t between terms s, t ∈ G(Σ, C 0 ), and ≈ E the equational theory induced by E on G(Σ, C 0 ), defined either semantically using algebras or (equivalently) syntactically through rewriting [3] . It is well-known (see, e.g., [3] , Lemma 4.3.3) that ≈ E (viewed as a subset of G(Σ, C 0 ) × G(Σ, C 0 )) can be generated using congruence closure, i.e., by exhaustively applying reflexivity, transitivity, symmetry, and congruence to E. To be more precise, CC (E) is the smallest subset of G(Σ, C 0 ) × G(Σ, C 0 ) that contains E and is closed under the following rules: ; -if f is an n-ary function symbol and s 1 ≈ t 1 , . . . , s n ≈ t n ∈ CC (E), then f (s 1 , . . . , s n ) ≈ f (t 1 , . . . , t n ) ∈ CC (E) (congruence). The set CC (E) is usually infinite. To obtain a decision procedure for the word problem, one can show that it is sufficient to restrict the application of the above rules to a finite subset of G(Σ, C 0 ), which consists of the subterms of terms occurring in E and of the subterms of the terms s 0 , t 0 for which one wants to decide whether s 0 ≈ E t 0 holds or not (see, e.g., [3] , Theorem 4.3.5). This actually also works if one adds commutativity of some binary function symbols to the theory. To be more precise, we assume that some of the binary function symbols in Σ are commutative, i.e., there is a set of binary function symbols Σ c ⊆ Σ whose elements we call commutative symbols. In addition to the identities in E, we assume that the identities f (x, y) ≈ f (y, x) are satisfied for all function symbols f ∈ Σ c . From a semantic point of view, this means that we consider algebras A that satisfy not only the identities in E, but also commutativity for the symbols in Σ c , i.e., for all f ∈ Σ c , and all elements a, b in all algebras that satisfy the identities in E and commutativity for the symbols in Σ c . The relation ≈ Σc E ⊆ G(Σ, C 0 ) × G(Σ, C 0 ) can also be generated by extending congruence closure by a commutativity rule. To be more precise, CC Σc (E) is the smallest subset of G(Σ, C 0 ) × G(Σ, C 0 ) that contains E and is closed under reflexivity, transitivity, symmetry, congruence, and the following commutativity rule: Lemma 3.5 .13 and Theorem 3.5.14 in [3] ). Again, it is not hard to show that the restriction of the commutative congruence closure to a polynomially large set of terms determined by the input E, s 0 , t 0 is complete, which yields decidability of ≈ Σc E [5] . Here, we follow a different approach, which is based on rewriting [7, 8] . Let S(E) denote the set of subterms of the terms occurring in E. In a first step, we introduce a new constant c s for every term s ∈ S(E) \ C 0 . To simplify notation, for a constant a ∈ C 0 we sometimes use c a to denote a. Let C 1 be the set of new constants introduced this way and C := C 0 ∪ C 1 . Given a term u ∈ G(Σ, C), we denote with u the term in G(Σ, C 0 ) obtained from u by replacing the occurrences of the constants c s ∈ C 1 in u with the corresponding terms s ∈ S(E). We fix an arbitrary linear order > on C, which will be used to orient identities between constants into rewrite rules. Note that this order does not take into account which terms the constants correspond to, and thus we may well have The initial rewrite system R(E) induced by E consists of the following rules: Obviously, the cardinality of C 1 is linear in the size of E, and R(E) can be constructed in time linear in the size of E. From the above construction, it follows that R(E) has two types of rules: constant rules of the form c → d for c > d and function rules of the form f (c 1 , . . . , c n ) → d. then we obtain the following rewrite system: The following lemma is an easy consequence of the definition of R(E). The first part can be shown by a simple induction on the structure of s. Using this lemma, we can show that the construction of R(E) is correct for consequence w.r.t. commutative symbols in the following sense: In this lemma, we use commutativity of the elements of Σ c as additional identities. Our goal is, however, to deal both with the ground identities in E and with commutativity by rewriting. For this reason, we consider the rewrite system 1 where > lpo denotes the lexicographic path order (see Definition 5.4.12 in [3] ) induced by a linear order on Σ ∪ C that extends > on C, makes each function symbol in Σ greater than each constant symbol in C, and linearly orders the function symbols in an arbitrary way. Note that > lpo is then a linear order on G(Σ, C) (see Exercise 5.20 in [3] ). Consequently, for every pair of distinct terms can easily be shown to terminate using this order. In fact, > lpo is a reduction order, and we have > lpo r for For the two rules with left-hand side The rules with left-hand sides different from g(b) are moved unchanged from F Σc 0 (E) to R Σc 1 (E) since their left-hand sides are unique. Thus, R Σc In the second iteration step, we now have the new non-trivial equivalence with representative c h(a) . The net effect of step (a) is, however, that the constant rules are moved unchanged from R Σc 1 (E) to R Σc 2 (E). The function rules in F Σc c h(a) . Consequently, no constant rules are added in step (b), and the construction terminates with output R Σc Our goal is now to show that R Σc (E)∪R(Σ c ) provides us with a polynomialtime decision procedure for the commutative word problem in E. Lemma 3. The system R Σc (E) can be computed from R(E) in polynomial time, and its construction is correct in the following sense: viewed as a set of identities, If we view R Σc (E) ∪ R(Σ c ) as a term rewriting system, then we obtain the following result. Proof. Termination of the term rewriting system R Σc (E) ∪ R(Σ c ) can be shown as for R(E) ∪ R(Σ c ), using the reduction order > lpo introduced in the definition of R(Σ c ). Confluence can thus be proved by showing that all non-trivial critical pairs of this system can be joined (see [2] for details). Since R Σc (E) ∪ R(Σ c ) is canonical, each term s ∈ G(Σ, C) has a unique normal form (i.e., irreducible term reachable from s) w.r.t. R Σc (E) ∪ R(Σ c ), which we call the canonical form of s. We can thus use the system R Σc (E) ∪ R(Σ c ) to decide whether terms s, t are equivalent w.r.t. E and commutativity of the symbols in Σ c , i.e., whether s ≈ t ∈ CC Σc (E), by computing the canonical forms of the terms s and t. Note that the construction of R Σc (E) is actually independent of the terms s 0 , t 0 for which we want to decide the word problem in E. This is in contrast to approaches that restrict the construction of the congruence closure to the subterms of E and the subterms of the terms s 0 , t 0 for which one wants to decide the word problem. This fact will turn out to be useful in the next section. Since it is easy to show that reduction to canonical forms requires only a polynomial number of rewrite steps, Theorem 1 thus yields the following complexity result. This complexity result has been shown before in [5] and [8] , but note that, in these papers, detailed proofs are given for the case without commutativity, and then it is only sketched how the respective approach can be extended to accommodate commutativity. Like the approach in this paper, the one employed in [8] is rewriting-based, but in contrast to ours it does not explicitly use the rewrite system R(Σ c ). Here, we additionally assume that some of the non-commutative 2 function symbols are extensional, i.e., there is a set of function symbols Σ e ⊆ Σ \ Σ c whose elements we call extensional symbols. In addition to the identities in E and commutativity for the symbols in Σ c , we now assume that also the following conditional identities are satisfied for every n-ary function symbol f ∈ Σ e : From a semantic point of view, this means that we now consider algebras A that satisfy not only the identities in E and commutativity for the symbols in Σ c , but also extensionality for the symbols in Σ e , i.e., for all f ∈ Σ e , all i, 1 ≤ i ≤ n, and all elements a 1 , . . . , a n , b 1 , . . . , b n of A we have that f A (a 1 , . . . , a n Let Σ e c = (Σ c , Σ e ) and s, t ∈ G(Σ, C 0 ). We say that s ≈ t follows from E w.r.t. the commutative symbols in Σ c and the extensional symbols in Σ e (written s ≈ Σ e c E t) if s A = t A holds in all algebras that satisfy the identities in E, commutativity for the symbols in Σ c , and extensionality for the symbols in Σ e . The relation ≈ can also be generated using the following extension of congruence closure by an extensionality rule. To be more precise, CC Σ e c (E) is the smallest subset of G(Σ, C 0 ) × G(Σ, C 0 ) that contains E and is closed under reflexivity, transitivity, symmetry, congruence, commutativity, and the following extensionality rule: Proof. This proposition is an easy consequence of Theorem 54 in [18] , which (adapted to our setting) says that ≈ Σ e c E is the least congruence containing E that is invariant under applying commutativity and extensionality. Clearly, this is exactly CC Σ e c (E). To obtain a decision procedure for ≈ Σ e c E , we extend the rewriting-based approach from the previous section. Let the term rewriting system R(E) be defined as in Sect. 3. Let the set C 1 of new constants and the linear order on all constants be defined as in Example 1. Now, we obtain the following rewrite system: c g(a) ) → c f (a,g(a)) , g(a) → c g(a) , g(b) → c g(b) , h(a) → c h(a) , c f (a,g(a) Lemma 5. The system R(E) is a conservative extension of E also w.r.t. the commutative symbols in Σ c and the extensional symbols in Σ e , i.e., for all terms We extend the construction of the confluent and terminating rewrite system corresponding to R(E) by adding a third step that takes care of extensionality. To be more precise, R Σ e c (E) is constructed by performing the following steps, starting with R (c 1 , . . . , c n ) → d 1 , . . . , f(c 1 , . . . , c n (c 1 , . . . , c n ) → d, f (c 1 , . . . , c n then f (a, c h(a) ) → c, g(a) → c h(a) , g(b) → c h(a) , h(a) → c h(a) . Since these rules have unique left-hand sides, no constant rule is added in step (b). Consequently, we proceed with step (c). Since g ∈ Σ e , the presence of the rules g(a) → c h(a) and g(b) → c h(a) then f (b, c h(a) ) → c, g(b) → c h(a) , h(b) → c h(a) . Consequently, no new constant rules are added in steps (b) and (c), and the construction terminates with output R Σ e c (E ) = {a → b, c f (a,g(a) ) → c, c g(a) → c h(a) , c g(b) → c h(a) , f(b, c h(a) ) → c, g(b) → c h(a) , h(b) → c h(a) }, which is identical to the system R Σc (E) computed for the set of identity E of Example 1. Our goal is now to show that R Σ e c (E) provides us with a polynomial-time decision procedure for the extensional word problem in E, i.e., it allows us to decide the relation ≈ Σ e c E . Let R(Σ c ) and > lpo be defined as in (1). Intuitively, R Σ e c (E) extends R Σc (E) by additional rules relating constants that are equated due to extensionality. However, to keep the system confluent, we need to re-apply the other steps once two constants have been equated. We are now ready to prove our main technical result, from which decidability of the commutative and extensional word problem immediately follows. Proof. Since the if-direction is easy to show, we concentrate here on the onlyif-direction. If s, t ∈ G(Σ, C 0 ) are such that s ≈ t ∈ CC Σ e c (E), then there is a sequence of identities s 1 ≈ t 1 , s 2 ≈ t 2 , . . . , s k ≈ t k such that s k = s, t k = t, and for all i, 1 ≤ i ≤ k, the identity s i ≈ t i belongs to E or can be derived from some of the identities s j ≈ t j with j < i by apply reflexivity, transitivity, symmetry, congruence, commutativity, or extensionality. We prove that s and t have the same canonical form w.r.t. R Σ e Corollary 2. The commutative and extensional word problem for finite sets of ground identities is decidable in polynomial time, i.e., given a finite set of ground identities E ⊆ G(Σ, C 0 )×G(Σ, C 0 ), finite sets Σ c ⊆ Σ of commutative and Σ e ⊆ Σ \ Σ c of non-commutative extensional symbols, and terms s 0 , t 0 ∈ G(Σ, C 0 ), we can decide in polynomial time whether s 0 ≈ Σ e c E t 0 holds or not. We have mentioned in the introduction that it is unclear how this polynomiality result could be obtained by a simple adaptation of the usual approach that restricts congruence closure to a polynomially large set of subterms determined by the input (informally called "small" terms in the following). The main problem is that one might have to generate identities between "large" terms before one can get back to a desired identity between "small" terms using extensionality. The question is now where our rewriting-based approach actually deals with this problem. The answer is: in Case 1 of the case distinction in the proof of Theorem 2. In fact, there we consider a derived identity s ≈ t such that the (syntactically identical) canonical forms of s = f (g 1 , . . . , g n ) and t = f (h 1 , . . . , h n ) are not a constant from C, but of the form f (g 1 , . . . , g n ) = f (h 1 , . . . , h n ). Basically, this means that s and t are terms that are not equivalent modulo E to subterms of terms occurring in E, since the latter terms have a constant representing them. Thus, s , t are "large" terms that potentially could cause a problem: an identity between them has been derived, and now extensionality applied to this identity yields a new identity g μ ≈ h μ between smaller terms. Our induction proof shows that this identity can nevertheless be derived from R Σ e c (E) ∪ R(Σ c ), and thus does not cause a problem. In the previous section, we have made the assumptions that the sets Σ c and Σ e are disjoint, i.e., we did not consider extensionality for commutative symbols. The reason is that the presence of a commutative and extensional symbol would trivialize the equational theory. In fact, as already mentioned in the introduction, if f is assumed to be commutative and extensional, then commutativity yields f (s, t) ≈ f (t, s) for all terms s, t ∈ G(Σ, C 0 ), and extensionality then s ≈ t. This shows that, in this case, the commutative and extensional congruence closure would be G(Σ, C 0 ) × G(Σ, C 0 ), independently of E, and thus even for E = ∅. In this section, we consider the following variant of extensionality for commutative function symbols f , which we call c-extensionality: For example, if f is a commutative couple constructor, and two couples turn out to be equal, then we want to infer that they consist of the same two persons, independently of the order in which they were put into the constructor. Unfortunately, adding such a rule makes the word problem coNP-hard, which can be shown by a reduction from validity of propositional formulae. We prove this proposition by a reduction from validity of propositional formulae. Thus, consider a propositional formula φ, and let p 1 , . . . , p n be the propositional variables occurring in φ. We take the constants 0 and 1, and for every i, 1 ≤ i ≤ n, we view p i as a constant symbol, and add a second constant symbol p i . In addition, we consider the function symbols f ∨ , f ∧ , f ¬ , f, and assume that f is commutative and satisfies (3). We then consider ground identities that axiomatize the truth tables for ∨, ∧, ¬, i.e., In addition, we consider, for every i, Let E φ be the set of these ground identities, and let t φ be the term obtained from φ by replacing the Boolean operations ∨, ∧, and ¬ by the corresponding function symbols f ∨ , f ∧ , and f ¬ . Proposition 2 is now an immediate consequence of the following lemma. Lemma 9. The identity t φ ≈ 1 holds in every algebra satisfying E φ together with (3) and commutativity of f iff φ is valid. To prove a complexity upper bound that matches the lower bound stated in Proposition 2, we consider a finite signature Σ, a finite set of ground identities E ⊆ G(Σ, C 0 ) × G(Σ, C 0 ) as well as sets Σ c ⊆ Σ and Σ e ⊆ Σ of commutative and extensional symbols, respectively, and assume that the non-commutative extensional symbols in Σ e \ Σ c satisfy extensionality (2), whereas the commutative extensional symbols in Σ e ∩Σ c satisfy c-extensionality (3) . We want to show that, in this setting, the problem of deciding, for given terms s 0 , t 0 ∈ G(Σ, C 0 ), whether s 0 is not equivalent to t 0 is in NP. For this purpose, we employ a nondeterministic variant of our construction of R Σ e c (E). In steps (a) and (b), this procedure works as described in the previous section. For extensional symbols f ∈ Σ e \ Σ c , step (c) is also performed as in the previous section. For an extensional symbol f ∈ Σ e ∩ Σ c , step (c) is modified as follows: for all pairs of distinct rules f (c 1 , c 2 ) → d, f (c 1 , c 2 ) → d in F This nondeterministic algorithm has different runs, depending on the choices made in the nondeterministic part of step (c). But each run r produces a rewrite system R Σ e c r (E). We have shown, using a rewriting-based approach, that adding commutativity and extensionality of certain function symbols to a finite set of ground identities leaves the complexity of the word problem in P. In contrast, adding cextensionality for commutative function symbols raises the complexity to coNP. For classical congruence closure, it is well-known that it can actually be computed in O(n log n) [12, 13] . Since this complexity upper bound can also be achieved using a rewriting-based approach [8, 16] , we believe that the approach developed here can also be used to obtain an O(n log n) upper bound for the word problem for ground identities in the presence of commutativity and extensionality, as in Sect. 4, but this question was not in the focus here. The rules specifying extensionality are simple kinds of Horn rules whose atoms are identities. The question arises which other such Horn rules can be added without increasing the complexity of the word problem. It is known that allowing for associative-commutative (AC) symbols leaves the word problem for finite sets of ground identities decidable [4, 11] . It would be interesting to see what happens if additionally (non-AC) extensional symbols are added. The approaches employed in [4, 11] are rewriting-based, but in contrast to our treatment of commutativity, they use rewriting modulo AC. It is thus not clear whether the approach developed in the present paper can be adapted to deal with AC symbols. Regarding the application motivation from DL, it should be easy to extend tableau-based algorithms for DLs to deal with individuals named by ground terms and identities between these terms. Basically, the tableau algorithm then works with the canonical forms of such terms, and if it identifies two terms (e.g., when applying a tableau-rule dealing with number restrictions), then the rewrite system and the canonical forms need to be updated. More challenging would be a setting where rules are added to the knowledge base that generate new terms if they find a certain constellation in the knowledge base (e.g., a married couple, for which the rule introduces a ground term denoting the couple and assertions that link the couple with its components). In the context of first-order logic and modal logics, the combination of tableau-based reasoning and congruence closure has respectively been investigated in [9] and [14] . Corollary 3. Consider a finite set of ground identities E ⊆ G(Σ, C 0 ) × C 0 ) as well as sets Σ c ⊆ Σ and Σ e ⊆ Σ of commutative and extensional symbols, respectively, and two terms s 0 , t 0 ∈ G(Σ, C 0 ). The problem of deciding whether the identity s 0 ≈ t 0 holds in every algebra that satisfies E, commutativity for every f ∈ Σ c Using the rewrite system generated by the run r 1 , we obtain the following rewrite sequence: f ∨ (p, f ¬ (p)) → f ∨ (1, f ¬ (p)) → f ∨ (1, f ¬ (1)) → f ∨ (1, 0) → 1. For the run r 2 , we obtain the sequence f ∨ (p, f ¬ (p)) → f ∨ (0, f ¬ (p)) An Introduction to Description Logic Deciding the word problem for ground identities with commutative and extensional symbols Term Rewriting and All That Congruence closure modulo associativity and commutativity Variations on the common subexpression problem An algorithm for finding canonical sets of ground rewrite rules in polynomial time Shostak's congruence closure as completion Conditional congruence closure over uninterpreted and interpreted symbols The theorem prover of the program verifier Tatzelwurm Complexity of finitely presented algebras Any ground associative-commutative theory has a finite canonical system Fast decision procedures based on congruence closure Fast congruence closure and extensions Modal Tableau systems with blocking and congruence closure An algorithm for reasoning about equality A fast algorithm for generating reduced ground rewriting systems from a set of ground equations A decision procedure for an extensional theory of arrays Universal Algebra for Computer Scientists Acknowledgements. The authors would like to thank the reviewers for their careful reading of the paper and their useful comments, which helped to improve the presentation of the paper. The first author thanks Barbara Morawska for helpful discussions. c (E)∪R(Σ c ) by induction on the number of applications of the extensionality rule used when creating this sequence.In the base case, no extensionality rule is used, and thus s ≈ t ∈ CC Σc (E). By Theorem 1, s and t have the same canonical form w.r.t. R Σc (E) ∪ R(Σ c ), and thus by Lemma 8 also w.r.t. R Σ e c (E) ∪ R(Σ c ). In the step case, we consider the last identity s m ≈ t m obtained by an application of the extensionality rule. Then, by induction, we know that, for each i, 1 ≤ i < m, the terms s i and t i have the same canonical form w.r.t.. Now, consider the application of extensionality to an identity s ≈ t ( < m) that produced s m ≈ t m . Thus, we have s = f (g 1 , . . . , g n ) and t = f (h 1 , . . . , h n ) for some n-ary function symbol f ∈ Σ e , and extensionality generates the new identity g μ ≈ h μ for some μ, 1 ≤ μ ≤ n, such that s m = g μ and t m = h μ . For ν = 1, . . . , n, let g ν be the canonical form of g ν w.We know that the canonical forms of s and t w.r.t. R Σ e c (E) ∪ R(Σ c ) are identical, and these canonical forms can be obtained by normalizing f (g 1 , . . . , g n ) and f (h 1 , . . . , h n ). Since the rules of R(Σ c ) are not applicable to these terms due to the fact that f ∈ Σ c , there are two possible cases for how the canonical forms of s and t can look like:1. s and t respectively have the canonical forms f (g 1 , . . . , g n ) and f (h 1 , . . . , h n ), and thus the corresponding arguments are syntactically equal, i.e., g ν = h ν for ν = 1, . . . , n. In this case, the identity s m ≈ t m added by the application of the extensionality rule satisfies2. s and t reduce to the same constant d. Then R Σ e c (E) must contain the rules f (g 1 , . . . , g n ) → d and f (h 1 , . . . , h n ) → d. By the construction of R Σ e c (E), we again have that g μ = h μ , i.e., the two terms are syntactically equal. In fact, otherwise a new constant rule g μ → h μ or h μ → g μ would have been added, and the construction would not have terminated yet. We thus have againSumming up, we have seen that we haveSince the identities s j ≈ t j for m < j ≤ k are generated from the identities s i ≈ t i for i = 1, . . . , m and E using only reflexivity, transitivity, symmetry, commutativity, and congruence, this implies that also these identities satisfyRecall that we have f (h(a), b) ≈ Σ e c E c for the set of identities E of Example 2. We have already seen that these two terms rewrite to the same canonical form w.r.t. R Σc (E) ∪ R(Σ c ) = R Σ e c (E ) ∪ R(Σ c ). Again, it is easy to show that the decision procedure obtained by applying Theorem 2 requires only polynomial time.Example 3. We illustrate the nondeterministic construction using the identities E φ for φ = p ∨¬p from our coNP-hardness proof. Then E φ consists of the identities in (4) together with the identity f (p, p) ≈ f (0, 1). Assuming an appropriate order on the constants, the system R(E φ ) contains, among others, the rules f ∨ (1, 0) → c f∨(1,0) , c f∨(1,0) In step (a) and (b) of the construction, these rules are transformed into the formSince no new constant rule is added, the construction proceeds with step (c). Due to the presence of the rules f (p, p) → c f (1,0) and f (1, 0) → c f (1,0) for f ∈ Σ c ∩ Σ e , it now nondeterministically chooses between identifying p with 1 or with 0. In the first case, the constant rules p → 1, p → 0 are added, and in the second p → 0, p → 1 are added. In the next iteration, no new constant rules are added, and thus the construction terminates. It has two runs r 1 and r 2 . The generated rewrite systems R Using the canonical rewrite systems R Σ e c r (E) ∪ R(Σ c ), we can now characterize when an identity follows from E w.r.t. commutativity of the symbols in Σ c , extensionality of the symbols in Σ e \ Σ c , and c-extensionality of the symbols in Σ e ∩ Σ c as follows.Theorem 3. Let s 0 , t 0 ∈ G(Σ, C 0 ). The identity s 0 ≈ t 0 holds in every algebra that satisfies E, commutativity for every f ∈ Σ c , extensionality for every f ∈ Σ e \ Σ c , and c-extensionality for every f ∈ Σ e ∩ Σ c iff s 0 , t 0 have the same canonical forms w.r.t. R The main ideas for how to deal with extensionality and c-extensionality in the proof of this theorem are very similar to how extensionality was dealt with in the proof of Theorem 2. As for all the other results stated without proof here, a detailed proof can be found in [2] . Together with Proposition 2, Theorem 3 yields the following complexity results.