Deciding the Word Problem for Ground and Strongly Shallow Identities w.r.t. Extensional Symbols

The word problem for a finite set of ground identities is known to be decidable in polynomial time using congruence closure, and this is also the case if some of the function symbols are assumed to be commutative or defined by certain shallow identities, called strongly shallow. We show that decidability in P is preserved if we add the assumption that certain function symbols f are extensional in the sense that f(s1,…,sn)≈f(t1,…,tn)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$f(s_1,\ldots ,s_n) \mathrel {\approx }f(t_1,\ldots ,t_n)$$\end{document} implies s1≈t1,…,sn≈tn\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$s_1 \mathrel {\approx }t_1,\ldots ,s_n \mathrel {\approx }t_n$$\end{document}. 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.


Introduction
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 the generated rules using an additional ground rewrite system induced by the strongly shallow identities. This ground system is infinite, but finitely represented by an ordered rewrite system [17]. No other interaction between the ground identities and the strongly shallow identities is needed.
In [13] it was shown how to extend the commutative congruence closure algorithm developed there to deal also with (non-commutative) extensional symbols. In Sect. 4, we not only extend this approach from commutativity to strongly shallow identities. Instead, we exhibit general properties that the canonical rewrite system computed by a semantic congruence closure algorithm must satisfy such that extensionality for otherwise uninterpreted function symbols can be handled by a simple iterative algorithm that derives new identities between constants due to extensionality. As already observed in [13], it does not make sense to consider symbols that are both commutative and extensional since this makes the induced equational theory trivial. Instead, we introduce, in [13] and in Sect. 5 of the present paper, the notion of c-extensionality, which is more appropriate for commutative symbols, but increases the complexity of the word problem from polynomial to coNP-complete. Section 6 gives a more detailed description of related work.

Preliminaries
We assume that the reader is familiar with basic notions and results regarding equational theories, universal algebra, and term rewriting. In this section, we first recall the relevant notions and results regarding equational theories and term rewriting, but refer the readers to [5] for details. We will keep as close as possible to the notation introduced in [5]. In particular, we use ≈ to denote identities between terms and = to denote syntactic equality. Then, we introduce congruence closure, both without and with interpreted function symbols. Finally, we define our notion of strongly shallow identities, and show how such identities give rise to an ordered rewrite system that is canonical on ground terms.

Equational Theories and Term Rewriting
Terms are built as usual from variables, constants, and function symbols. A term of the form f (t 1 , . . . , t n ) for an n-ary function symbol f is said to have root symbol f . 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 (not necessarily ground) identities F, the equational theory induced by F is defined semantically as ≈ F := {s ≈ t | every model ofF is a model ofs ≈ t}. The notion of model used here is the usual one from first-order logic, where the equality symbol is interpreted as the equality relation on the domain and 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 (see Theorem 4.5.14 in [5]) provides us with an alternative syntactic characterization of ≈ F that is based on rewriting. A given set of identities F induces a binary relation → F on terms. Basically, we have s → F t if there is an identity ≈ r in F 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 ≈ F is identical to The normal form of a term s is an irreducible term s such that s * → F s, where * → F denotes the reflexive and transitive closure of → F and s is irreducible if there is no s with s → F s . If → F is canonical (i.e., terminating and confluent), then every term has a unique normal form, which we then called its canonical form. In addition, s * ↔ F t iff s and t have the same canonical forms. Termination ensures that the normal form exists and confluence that it is unique. The relation → F is confluent if s * → F t 1 and s * → F t 2 imply that the pair of terms t 1 , t 2 is joinable, i.e., there is a term t such that t 1 * → F t and t 2 * → F t. It is terminating if there is no infinite chain t 0 → F t 1 → F t 2 → F · · · . Termination can be proved using a reduction order, which is a well-founded order > on terms such that > r for all ≈ r ∈ F implies s > t for all terms s, t with s → F t. Since > is well-founded this then implies termination. If → F is terminating, then confluence can be tested by checking whether all critical pairs of F are joinable. Basically, critical pairs t 1 , t 2 consider the most general "forks" of the form s → F t 1 and s → F t 2 that are due to overlapping left-hand sides of identities. They can be obtained by computing the most general unifiers of left-hand sides of rules with subterms of renamed variants of left-hand sides of other or the same rule. To be more precise, if ≈ r and g ≈ d are identities (whose variables have been renamed apart) such that a non-variable subterm of unifies with g with most general unifier σ , then this overlap induces the critical pair t 1 , t 2 where t 1 = σ (r ) and t 2 is obtained from σ ( ) by replacing the subterm σ ( ) = σ (g) with σ (d). Such a critical pair t 1 , t 2 is joinable if there is a term t such that t 1 * → F t and t 2 * → F t. When considering the relation → F , one calls F a term rewriting system rather than a set of identities, and writes its elements (called rewrite rules) as → r instead of ≈ r . From a formal point of view, however, both rewrite rules and identities are (ordered) 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.

Congruence Closure
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 ground identities s ≈ t between terms s, t ∈ G(Σ, C 0 ), and ≈ E the equational theory induced by E on G(Σ, C 0 ).
The set CC(E) is usually infinite. To obtain a decision procedure for the word problem for E (i.e., for the relation ≈ E ), 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., [5], Theorem 4.3.5).

Semantic Congruence Closure
As mentioned in the introduction, it sometimes makes sense to assume that certain function symbols are interpreted in the sense that they satisfy additional semantic properties that are not expressible by ground identities. Thus, we now consider a setting where there is a subset Σ F of Σ and a set of (non-ground) identities F formulated using the function symbols in Σ F and variables. Given a finite set E of ground identities s ≈ t between terms s, t ∈ G(Σ, C 0 ), we assume that also the identities in F are satisfied. This means that we consider algebras A that satisfy not only the ground identities in E, but also the universal closure of the non-ground identities in F, i.e., algebras A that are models of E ∪ F.
E is the restriction of ≈ E∪F to the ground terms in G(Σ, C 0 ). By a slight abuse of notation, we will later use ≈ F E also to denote the restriction of ≈ E∪F to G(Σ, C) for a set of constants C containing C 0 .
The relation ≈ F E ⊆ G(Σ, C 0 ) × G(Σ, C 0 ) can again be generated by extending congruence closure by an additional rule that deals with the identities in F, i.e., CC F (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 rule: -if ≈ r ∈ F and σ is a substitution that maps the variables in , r to elements of We call CC F (E) the congruence closure of E w.r.t. F. Birkhoff's theorem again shows that CC F (E) coincides with ≈ F E . Without restrictions on the set of identities F, the word problem for E w.r.t. F (i.e., the relation ≈ F E ) need not be decidable. For example, if F axiomatizes associativity of a binary function symbol f , then this word problem corresponds to the word problem for finitely presented semigroups, which is known to be undecidable [18]. Thus, one needs to impose some restrictions on the set of identities F to guarantee decidability of the word problem.

Strongly Shallow Identities and Ordered Rewrite Systems
In [13], we considered the setting where Σ F (denoted as Σ c in [13]) contains only binary function symbols and F consists of the commutativity axioms f (x, y) ≈ f (y, x) for all f ∈ Σ F . In the present paper, we extend the results of [13] from commutativity to more general kinds of semantic properties of function symbols that can be expressed by strongly shallow identities. Note that the notion of strongly shallow identities introduced in this paper is more restrictive than what is often called "shallow" in the literature [16] (see Sect. 6 for more details).

Definition 1
Let Σ S ⊆ Σ be a set of function symbols and h ∈ Σ S a symbol in Σ S of arity n. A strongly shallow h-identity is of the form h(x 1 , . . . , x n ) ≈ h(y 1 , . . . , y n ) where x 1 , y 1 , . . . , x n , y n are not necessarily distinct variables such that {x 1 , . . . , x n } = {y 1 , . . . , y n }. The set of identities S is a set of strongly shallow identities for Σ S if S = h∈Σ S S h , where S h is a non-empty set of strongly shallow h-identities for all h ∈ Σ S . Example 1 Let f , g, h respectively be a binary, an n-ary, and a ternary function symbol (for n > 2), and a a constant symbol.
. . , x n and 1 ≤ i < n are strongly shallow g-identities. We call such an identity a g-transposition. 3. The identity h(x, x, y) ≈ h(x, y, y) is a strongly shallow h-identity. 4. The following identities are not strongly shallow according to our definition, though they are shallow according to the definition in [16]: The word problem for a finite set of strongly shallow identities (i.e., the relation ≈ S ) can easily be shown to be decidable using rewriting. However, the classical notion of a canonical rewrite system, as introduced above, cannot be used for this purpose. The reason is that strongly shallow identities, like commutativity or transposition identities, usually cannot be oriented into terminating rewrite rules. However, we can orient their ground instances into terminating rules using an appropriate reduction order. Given a finite set of constant symbols C ⊇ C 0 , we denote the set of ground terms built using symbols from Σ and C with G(Σ, C). Ground instances of terms are obtained by applying ground substitutions, which replace the variables in the given terms with elements of G(Σ, C). Definition 2 (Ordered rewrite system [17]) Given a finite set of (non-ground) identities F and a reduction order >, we call the pair (F, >) an ordered rewrite system. The ground rewrite system R(F, >) induced by (F, >) is defined as Since > is assumed to be a reduction order, R(F, >) is clearly terminating. The system R(F, >) is usually infinite. However, if F is finite and > decidable, then one can effectively decide whether some rule in R(F, >) applies to a given ground term, and compute a term resulting from the application of this rule. In particular, this implies that we can effectively compute a normal form of a given ground term w.r.t. the ground rewrite system R(F, >). Note, however, that this normal form need not be unique since there is no guarantee that this system is confluent. We say that the ordered rewrite system (F, >) is canonical on ground terms if R(F, >) is confluent.
As a first example, we consider commutativity, i.e., the setting where F c consists of the commutativity axioms for the (binary) function symbols in Σ c ⊆ Σ. Instead of Σ F and F we use the symbols Σ c and F c to indicate already in the notation that we now consider commutativity. Let > lpo be the lexicographic path order 1 induced by a linear order on Σ ∪C. Note that > lpo is then a linear order on G(Σ, C) (see Exercise 5.20 in [5]). The ground rewrite system induced by (F c , > lpo ) is of the form and it is easy to see that it is confluent (this is an instance of Lemma 4 in [13], and also follows from what we show for strongly shallow identities below). Thus, (F c , > lpo ) is canonical on ground terms. Now, assume Σ S ⊆ Σ and let S be a set of strongly shallow identities for Σ S . In general, the ground rewrite system R(S, > lpo ) is not confluent. For example, assume that h ∈ Σ S is ternary and S h = {h(x, y, z) ≈ h(x, z, y), h(x, x, y) ≈ h(x, y, y)}. If the linear order > on Σ ∪ C that induces > lpo satisfies a > b, then the ground term h(a, a, b) rewrites with R(S, > lpo ) both to h(a, b, b) and h(a, b, a). Since these terms are irreducible w.r.t. R(S, > lpo ), this shows that R(S, > lpo ) is not confluent.
To obtain an ordered rewrite system that is canonical on ground terms, we extend S by all implied strongly shallow identities, i.e., we consider the set Finiteness of this set (up to renaming of variables) is an easy consequence of the fact that such identities can contain at most n different variables. Thus, we can fix an arbitrary set V n of n different variables and assume without loss of generality that the variables x 1 , y 1 , . . . , x n , y n belong to V n . In addition, it is an easy consequence of the restricted form of strongly shallow identities that it is decidable whether an identity of this form follows from S: starting with h(x 1 , . . . , x n ) one can simply enumerate the finitely many terms that can be obtained by iterated application of the identities in S h .
Thus, (S * , > lpo ) is a finite ordered rewrite system that can effectively be computed. Due to the finiteness of S * and decidability of > lpo (Proposition 5.4.16 in [5]), checking whether a rule of R(S * , > lpo ) is applicable and actually applying it can effectively be done. The following lemma shows that (S * , > lpo ) is canonical on ground terms.

Lemma 1
The ground rewrite system R(S * , > lpo ) is canonical and equivalent to S on G(Σ, C), i.e., s ≈ S t iff s ≈ R(S * ,> lpo ) t holds for all terms s, t ∈ G(Σ, C).
Proof Termination of R(S * , > lpo ) is an immediate consequence of the fact that > lpo is a reduction order. Confluence is an easy consequence of the critical pair lemma for ordered rewrite systems in [17] (Lemma 2.1 and 2.2), but we prove it here explicitly for the sake of completeness.
A rewrite in the substitution part means that there is a rule of the form h(σ (x 1 ), . . . , σ (x n )) → h(σ (y 1 ), . . . , σ (y n )) in R(S * , > lpo ) and an i, 1 ≤ i ≤ n, such that σ (x i ) can be rewritten to a term r i using a rule from R(S * , > lpo ). The critical pair obtained this way is If we modify the substitution σ to σ by setting σ (x i ) = r i , then both the left and the right component of the critical pair can be rewritten to the common term h(σ (y 1 ), . . . , σ (y n )) by R(S * , > lpo ). This finishes the proof that R(S * , > lpo ) is canonical.
By the definition of R(S * , > lpo ), every rule → r in R(S * , > lpo ) satisfies ≈ S r , which shows that s ≈ R(S * ,> lpo ) t implies s ≈ S t for all terms s, t ∈ G(Σ, C). The other direction is an easy consequence of the fact that > lpo is a linear order since this implies that every nontrivial 2 substitution instance in G(Σ, C) of a non-trivial identity in S occurs (appropriately ordered) as a rule in R(S * , > lpo ).
Coming back to the example illustrating that R(S, > lpo ) need not be confluent, we note that, in this example, the identity h(x, y, y) ≈ h(x, y, x) belongs to S * , and thus the term h(a, b, a) rewrites to h(a, b, b) in R(S * , > lpo ).

Semantic Congruence Closure Based on Rewriting
Let Σ be a finite set of function symbols of arity ≥ 1 and C 0 a finite set of constant symbols. In the following, let E be a finite set of ground identities s ≈ t between terms s, t ∈ G(Σ, C 0 ). In addition, assume that Σ S ⊆ Σ and let S be a set of strongly shallow identities for Σ S . Below, we show how to construct a canonical rewrite system that can be used to decide the word problem for E w.r.t. S. This system will be the union of R(S * , > lpo ) with a finite ground rewrite system R S (E), whose construction is described below.

Construction of the Rewrite System R S (E)
Let Sub(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 ∈ Sub(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 . 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 c s > c f (s) . The initial rewrite system R(E) induced by E consists of the following rules: -If s ∈ Sub(E)\C 0 , then s is of the form f (s 1 , . . . , s n ) for an n-ary function symbol f and terms s 1 , . . . , s n for some n ≥ 1. For every such s we add the rule f (c 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). It can be shown by a simple induction on the structure of the term s.

Lemma 2 For all terms s ∈ Sub(E) it holds that s ≈ R(E) c s .
Using this lemma, we can show that the construction of R(E) is correct for consequence w.r.t. strongly shallow identities in the sense stated in the next lemma. Recall that E and ≈ S E are binary relations in

Lemma 3 Viewed as a set of identities, R(E) w.r.t. S is a conservative extension
, it is sufficient to show that A satisfies the identities in E ∪ S. For the identities in S, this is again trivially true. Thus, consider an identity s ≈ t ∈ E. Then R(E) contains the rule c s → c t or c t → c s . In addition, Lemma 2 In Lemma 3, we consider the relation ≈ S R(E) , where the elements of S h for h ∈ Σ S are used as additional identities. Our goal is, however, to deal both with the ground identities in E and with the strongly shallow identities in S by rewriting. This is where the ground rewrite system R(S * , > lpo ) comes into play. We assumed that > lpo is 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. This implies that > lpo r for all rules → r ∈ R(E). Consequently, termination of the rewrite system R(E) ∪ R(S * , > lpo ) can also easily be shown using > lpo .
However, in general R(E) ∪ R(S * , > lpo ) need not be confluent due to possible interactions of rules in R(E) with each other and of rules in R(E) with rules in R(S * , > lpo ). We turn R(E) ∪ R(S * , > lpo ) into a confluent and terminating system by modifying R(E) appropriately.

If at least one constant rule has been added in step (b), then set i
Let us illustrate the construction of R S (E) using Example 2. In step (a), the non-trivial equivalence classes are ), and thus in step (b1) this rule is replaced with f (b, c g(a) ) → c. In step (b2), there are two rules with left-hand side g(b). For these rules, we add c g(a) → c h(a) and In the second iteration step, we now have the new non-trivial equivalence class . The net effect of step (a) is, however, that the constant rules are moved unchanged from R S . Consequently, no reduction is possible in step (b1) and no constant rules are added in step (b2). The construction thus terminates

Proof of Correctness and Tractability
Our goal is now to show that R S (E) ∪ R(S * , > lpo ) provides us with a polynomial-time decision procedure for the word problem in E w.r.t. S. When looking at the complexity of the word problem, one needs to clarify what counts as input and what is assumed to be fixed. In our setting, where we want to know whether s 0 ≈ S E t 0 holds or not, one could on the one hand assume that S and E are fixed, and only the terms s 0 , t 0 are part of the input. On the other hand, one could assume that the input consists of S, E, and s 0 , t 0 . In this paper, we make the latter assumption, which makes our polynomiality result considerably stronger than if we had used the former one.
However, to obtain this result, we make the additional assumption that the maximal arity of the function symbols in Σ S is bounded by a constant. In this case we say that Σ S is arity-bounded. For the case of commutativity, this restriction is satisfied since then all the symbols in Σ S are binary. If we consider g-transpositions, but do not bound the arity n of the symbol g (i.e., the arities of the symbols satisfying transpositions is determined by the input rather than fixed from the outset), then the arity-boundedness condition is not satisfied. If S g consists of all g-transitions, then the set of identities {g(x 1 , . . . , where π is a permutation of the set {1, . . . , n}, and is thus exponential in n. If n is assumed to be a constant, then this set of identities is actually of constant size. In the following, we assume for our complexity results that Σ S is arity bounded. Note that, even if the maximal arity of the symbols in Σ S is bounded in this way, how many symbols of a certain allowed arity are present in Σ S and which strongly shallow identities they satisfy, can still be determined by the input. First, we prove that, under this assumption, the construction of R S (E) takes only polynomial time.

Lemma 4 If Σ S is arity-bounded, then the system R S (E) can be computed from R(E) in polynomial time.
Proof First, note that step (a) can clearly be performed in polynomial time since deciding ≈ R S i (E)| con amounts to performing reachability tests in an undirected graph. 3 Producing the original rules in F S i (E) can then clearly also be done in polynomial time. The canonical forms of left-hand sides of the form h(c 1 , . . . , c n ) for h ∈ Σ S required in step (b1) can also be computed in polynomial time. In fact, the terms obtained by a rewrite sequence in R(S * , > lpo ) that starts with h(c 1 , . . . , c n ) are all of the form h(d 1 , . . . , d n ) with {d 1 , . . . , d n } = {c 1 , . . . , c n }. The number of such terms is bounded by n n (which is a constant) and since R(S * , > lpo ) is terminating, there cannot be a repetition in this sequence. Consequently, at most n n (i.e., constantly many) rewrite steps are applied.
Grouping the rules in F S i (E) according to their left-hand sides in step (b2) is clearly also possible in polynomial time, as is adding the new rules to R S i+1 (E). In case the procedure does not terminate after step (b), the number of different equivalence classes of constants decreases by at least one. Thus, the iteration must terminate after at most |C| steps.
Next, we show that the construction of R S (E) is correct in the following sense.

Lemma 5 Viewed as a set of identities, R S
It is thus sufficient to show that the modifications performed when going from To show the inclusion from left to right, first consider step (a). If R S i (E) contains the constant rule c 1 → c 2 , then c 1 and c 2 belong to the same equivalence class w.r.t. R S i (E)| con and c 1 > c 2 . In case c 2 is the least element in this class, then R S i+1 (E) still contains the rule c 1 → c 2 . Otherwise, since we know that c 1 > c 2 , the least element e in the class is different from these two constants, and thus R S i+1 (E) contains the rules c 1 → e, c 2 → e, which shows Regarding step (b), note that the replacements performed in the construction of F S i (E) replace constants c occurring in function rules by constants e that are equivalent to c both w.r.t.
Thus, these replacements do not change the overall equational theory. In step (b1), rules of the form h( , which thus also does not change the overall equational theory. For step (b2), consider a function rule The inclusion from right to left can be shown similarly to the one from left to right.

terminating and confluent.
Proof Termination of the term rewriting system R S (E) ∪ R(S * , > lpo ) can be shown as for R(E) ∪ R(S * , > lpo ), by using the reduction order > lpo .
Regarding confluence, we first claim that there are no non-trivial critical pairs (see Sect. 6.2 in [5]) between the rules in R S (E). To see this, note that two function rules from R S (E) cannot overlap due to the fact that in step (b2)  Finally, assume that the rule from R S (E) is applied below the root position in the left-hand side of the rule in R(S * , > lpo ). Joinability of the critical pair obtained this way can be shown as in the case of a rewrite in the substitution part in the proof of Lemma 1.
Summing up, we have shown that all non-trivial critical pairs of R S (E) ∪ R(S * , > lpo ) can be joined, which proves confluence of R S (E) ∪ R(S * , > lpo ).
Since R S (E) ∪ R(S * , > lpo ) is canonical, each term s ∈ G(Σ, C) has a unique canonical form (i.e., irreducible term reachable from s) w.r.t. R S (E) ∪ R(S * , > lpo ). We can thus use the system R S (E) ∪ R(S * , > lpo ) to decide whether terms s 0 , t 0 are equivalent in E w.r.t. S, i.e., whether s 0 ≈ t 0 ∈ CC S (E), by computing the canonical forms of the terms s 0 and t 0 . Conversely, if s 0 and t 0 have the same canonical form w. C 0 ), we can now apply Lemma 3 to obtain s 0 ≈ S E t 0 , which is equivalent to s 0 ≈ t 0 ∈ CC S (E).
As an example, consider the rewrite system R S (E) that we have computed (above Lemma 4) from the set of ground identities E in Example 2, and recall that f (b, h(a)) ≈ S E c. The canonical form of c is clearly c, and the canonical form of f (b, h(a)) can be computed by the following rewrite sequence: In this example, no rule of R(S * , > lpo ) is used in the computation of the canonical forms, which is of course not the case in general. Also note that we have used R(S * , > lpo ) in the construction of R S (E).
The construction of R S (E) is actually independent of the terms s 0 , t 0 for which we want to decide the word problem in E w.r.t. S. 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.
It remains to show that the decision procedure obtained by applying Theorem 1 requires only polynomial time if Σ S is assumed to be arity-bounded. Proof Since we already know that R S (E) can be constructed in time polynomial in the size of E, and thus also has polynomial size, it is sufficient to show that the canonical form of a term s 0 ∈ G(Σ, C 0 ) w.r.t. the rewrite system R S (E) ∪ R(S * , > lpo ) can be computed in time polynomial in the size of s 0 and R S (E). This is clearly the case if only a polynomial number of rewrite steps are needed to produce the canonical form of s 0 , and each application of a rewrite step also takes only polynomial time. The latter is an easy consequence of the facts that the relevant part of the set of identities is of linear size if n is assumed to be a constant and > lpo is decidable in polynomial time (see Proposition 5.4.16 in [5]).
We show the former by induction on the structure of s 0 . If s 0 is a constant, then there are at most |C| − 1 rewrite steps starting with s 0 possible. This yields the desired polynomial bound since the cardinality of C is linear in the size of E. Now assume that s 0 = h(s 1 , . . . , s n ) for a function symbol h ∈ Σ. First, we compute the canonical forms t 1 , . . . , t n of s 1 , . . . , s n . By induction, we can assume that the number of rewrite steps required for these computations is bounded by polynomials p 1 , . . . , p n in the sizes of E and s 1 , . . . , s n , respectively. If h ∈ Σ S , then we rewrite h(t 1 , . . . , t n ) with the rules in R(S * , > lpo ). Note that the terms obtained by this rewrite sequence are all of the form h(u 1 , . . . , u n ) with {t 1 , . . . , t n } = {u 1 , . . . , u n }. Since the number of such terms is bounded by n n (which is a constant) and R(S * , > lpo ) is terminating, there cannot be a repetition in this sequence. Consequently, at most n n rewrite steps are applied. If the term h(v 1 , . . . , v n ) obtained by this rewrite sequence is the left-hand side of a rule in R S (E), then it rewrites to a constant d, from which at most |C| − 1 rewrite steps are possible. Overall, we thus need at most p 1 + . . . + p n + n n + |C| rewrite steps to compute the canonical form of s 0 = h(s 1 , . . . , s n ), which is clearly a polynomial bound in the size of s 0 and E.
Commutative function symbols all have arity 2, and thus Σ S = Σ c is clearly aritybounded. Given Σ c , we denote the set of commutativity axioms for the elements of Σ c as F c .

Corollary 2
The commutative 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 ), commutativity axioms F c for the symbols in Σ c ⊆ Σ, and terms s 0 , t 0 ∈ G(Σ, C 0 ), we can decide in polynomial time whether s 0 ≈ F c E t 0 holds or not.
Even if Σ S is not arity-bounded, we may still obtain polynomially decidable word problems. As an example, consider for all n > 2 function symbols g n that are assumed to satisfy the transposition identities In this case, it is not necessary to consider the (exponentially many) derived identities between strongly shallow g n -terms in S * g n to construct the ordered rewrite system. Using (S g n , > lpo ) instead is sufficient since this system is canonical on ground terms. In fact, using the rules in R(S g n , > lpo ) one can compute the canonical form of a ground term in polynomial time since this corresponds to applying bubble-sort. This observation can be used to show that the word problem for finite sets of ground identities w.r.t. function symbols satisfying transposition identities is decidable in polynomial time even without assuming arity-boundedness.

Semantic Congruence Closure with Extensionality
Here, we additionally assume that some of the function symbols are extensional, i.e., there is a set of function symbols Σ e ⊆ Σ whose elements we call extensional symbols. An extensional symbol f ∈ Σ e must satisfy the conditional identities In the present section, we assume that extensional symbols do not satisfy any other semantic properties. The reason for this restriction will be explained in the next section.
We have shown in [13] how to integrate extensional symbols into the rewriting-based commutative congruence closure algorithm developed there. It is not hard to see that this approach can be adapted to the integration of extensionality into congruence closure w.r.t. strongly shallow identities as developed in the previous section. Below, we describe this integration in the more general setting of a generic rewriting-based semantic congruence closure. In addition to making our result more general, this also has the advantage that it clarifies which properties of our rewriting-based congruence closure algorithm are vital for integrating extensional symbols.

Generic Semantic Congruence Closure
Abstracting from the specific form of the semantic properties, we now consider a setting where there is a subset Σ F of Σ and a set of identities F formulated using the function symbols in Σ F and variables (see Sect. 2.2.2). We assume that one can construct a canonical ground rewrite system R F that satisfies properties similar to the system R S (E)∪ R(S * , > lpo ) considered in the previous section.
We call a ground rewrite system R ⊆ G(Σ, C) × G(Σ, C) flat if it consists of constant rules of the form c → d and function rules of the form f (c 1 , . . . , c n ) → d, where  c, c 1 , . . . , c n , d ∈ C and f ∈ Σ is an n-ary function symbol.

Definition 3
We say that rewrite-based congruence closure is effective for Σ F and F if, for every finite flat ground rewrite system R ⊆ G(Σ, C) × G(Σ, C), there is a (possibly infinite) ground rewrite system R F ⊆ G(Σ, C) × G(Σ, C) that satisfies the following properties: 1. All rules containing a symbol in Σ F have left-hand sides whose root symbols belong to Σ F , 2. All rules containing a symbol f ∈ Σ \ Σ F as root symbol of the left-hand side are flat function rules of the form f (c 1 , . . . , c n ) → d, and the subset of these rules can effectively be computed, 3. R F is equivalent to R w.r.t. F on terms in G(Σ, C), 4. R F is canonical and canonical forms of terms in G(Σ, C) w.r.t. this term rewriting system can effectively be computed.
Note that we do not require that the canonical ground rewrite system R F itself is computable, but only that there is an algorithm for computing canonical forms w.r.t. this system. The reason is that R F may actually be infinite, and thus may not be computable in finite time. One may wonder how one can get a procedure for computing canonical forms w.r.t. R F if this system is infinite. One possibility is that one can compute a finite representation of this system that allows one to produce these normal forms. In the case of strongly shallow identities, this finite representation consists of the finite ground rewrite system R S (E) together with the ordered rewrite system (S * , > lpo ). It is easy to see that the system R S := R S (E) ∪ R(S * , > lpo ) induced by these two components satisfies the conditions required by Definition 3. Under the assumptions formulated in this definition, given two terms s 0 , t 0 in G(Σ, C 0 ), we can decide whether s 0 ≈ F R t 0 holds or not by computing their canonical forms w.r.t. R F and checking whether they are syntactically equal. In order to obtain a polynomial-time decision procedure, it is sufficient to assume that all the computations mentioned above can be performed in polynomial time. In this case we say that rewrite-based congruence closure is polynomial for Σ F and F. If S is a strongly shallow set of identities over an aritybounded signature Σ S , then R S = R S (E) ∪ R(S * , > lpo ) satisfies the conditions required for a polynomial rewrite-based congruence closure. However, as mentioned at the end of Sect. 3, polynomiality may be achieved even if Σ S is not arity-bounded.

Generic Semantic Congruence Closure with Extensionality
Let Σ F and F be as above, and assume that Σ e ⊆ Σ \ Σ F . In addition to the identities in E and the identities in F for the symbols in Σ F , we now assume that also the conditional identities in (2) are satisfied for the symbols f ∈ Σ e . From a semantic point of view, this means that we now consider algebras A that satisfy not only the identities in E ∪ F, 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 it holds that f A (a 1 , . . . , a n ) = f A (b 1 , . . . , b n ) implies a i = b i for all i, 1 ≤ i ≤ n. We say that s ≈ t follows from E w.r.t. F and the extensional symbols in Σ e (written s ≈ F,Σ e E t) if s A = t A holds in all algebras A that satisfy the identities in E ∪ F and extensionality for the symbols in Σ e .
The relation ≈ F,Σ e E ⊆ G(Σ, C 0 ) × G(Σ, C 0 ) can also be generated using the following extension of congruence closure by an extensionality rule.
To be more precise, CC F,Σ e (E) is the smallest subset of G(Σ, C 0 ) × G(Σ, C 0 ) that contains E and is closed under reflexivity, transitivity, symmetry, congruence, F-identities, and the following extensionality rule:

Proposition 1 For all terms s, t ∈ G(Σ, C 0 ) it holds that s ≈ F,Σ e E t iff s ≈ t ∈ CC F,Σ e (E).
Proof This proposition is an easy consequence of Theorem 54 in [19]. Adapted to our setting, this theorem says that ≈ F,Σ e E is the least congruence containing E that is invariant under applying F-identities and extensionality. Clearly, this is exactly CC F,Σ e (E).
To obtain a decision procedure for ≈ F,Σ e E , we assume that rewrite-based congruence closure is effective for Σ F and F. To apply this assumption, we first need to transform E into a flat rewrite system. Thus, let the flat term rewriting system R(E) be defined as in Sect. 3.

Example 3 Consider
Let the set C 1 of new constants and the linear order on all constants be defined as in Example 2. Then we obtain the following flat system: c g(a) , a) → c f (g(a),a) , g(a) → c g(a) , g(

Lemma 7 The system R(E) is a conservative extension of E also w.r.t. F and the extensional symbols in
Proof The proof of this lemma is basically identical to the proof of Lemma 3. One only needs to note, additionally, that going to the expansion and the reduct constructed in this proof does not change satisfaction of the extensionality axioms.
The confluent and terminating rewrite system for deciding ≈ F,Σ e E is now constructed by first applying the generic semantic congruence closure to R(E), then applying extensionality to derive new identities between constants, and iterating these two steps until no new identities are derived in the second step.  f (c 1 , . . . , c n ) → d, f (c 1 , . . . , c n ) → d in R F i , and all j, 1 ≤ j ≤ n, such that c j = c j , add c j → c j to R i+1 if c j > c j and otherwise add c j → c j to R i+1 . If at least one constant rule has been added in this step, then set i := i + 1 and continue with step (g). Otherwise, terminate with output R F,Σ e (E) := R F i .

Lemma 8 The construction of R F,Σ e (E) terminates after a linear number of iterations and produces a canonical rewriting system.
Proof Termination after linearly many iterations is an immediate consequence of the fact that, in each iteration of the construction (except the last one), the number of distinct equivalence classes of constants decreases, and the cardinality of the set of constants C is linear in the size of the input. The system R F,Σ e (E) is canonical since it is produced by an application of rewrite-based congruence closure to a finite flat ground rewrite system R i .
We illustrate the construction using Example 3. In step (g), we apply Algorithm 1 from the previous section. In step (a) of that algorithm, the non-trivial equivalence classes of constants are [c f (g(a) (c h(a) , a) In step (b1), the first rule is rewritten to f (a, c h(a) ) → c. Since the function rules obtained this way have unique left-hand sides, no constant rule is added in step (b2). Thus, the construction in step (g) terminates and yields the system that is the union of the generated flat rules with the ones in R(F, > lpo ) (with the strongly shallow identities F being commutativity of the symbols in Σ F ). Note that, for commutativity, F * = F.
Consequently, we now proceed with step (e). Since g ∈ Σ e , the presence of the rules g(a) → c h(a) and g(b) → c h(a) triggers the addition of a → b to R 1 .
In the second iteration step, we now have in step (a) of the construction applied in (g) the additional non-trivial equivalence class No new constant rules are added in step (b2). In step (e), the construction terminates with the set of flat rules computed for the set of identity E of Example 2. The system R F,Σ e (E) produced by this run of Algorithm 2 is R 1 ∪ R(F, > lpo ).
Our goal is now to show, for the general case, that R F,Σ e (E) provides us with a decision procedure for the extensional word problem for E ∪ F, i.e., it allows us to decide the relation ≈ F,Σ e E . This is an easy consequence of the following theorem.  , f (c 1 , . . . , c n (c 1 , . . . , c n ), and thus c j ≈ F,Σ e R i c j . Since these are the only identities added when going from R i to R i+1 , this completes the proof of the if-direction.
We show the only-if-direction by contraposition. Thus, assume that s 0 , t 0 have different canonical forms w.r.t. R F,Σ e (E). Let A be the initial algebra (i.e., the free algebra over the empty set of generators) for R F,Σ e (E) viewed as a set of identities over the signature Σ ∪ C. Recall that this algebra has the equivalence classes of terms in G(Σ, C) w.r.t. ≈ R F,Σ e (E) as its elements, and any term s ∈ G(Σ, C) is interpreted in A as the class of s. Since R F,Σ e (E) is canonical, we can represent such a class by the unique canonical form of its elements. Obviously, the fact that s 0 , t 0 have different canonical forms w.r.t.
Thus, if we can show that A satisfies E, the identities in F, and extensionality for every f ∈ Σ e , then s A 0 = t A 0 implies that s 0 ≈ F,Σ e E t 0 , and thus n t, and thus s ≈ R F,Σ e (E) t. Consequently, these two terms are evaluated to the same element of A, which shows that A satisfies the identities in E.
Let u ≈ v ∈ F and θ(u), θ (v) be ground instances of u, v. Then we know that θ(u) ≈ F R(E) θ(v). As above, this implies that the two terms θ(u) and θ(v) evaluated to the same element of A, which shows that A satisfies the identities in F. Let f ∈ Σ e be an n-ary function symbol and s 1 , t 1 , . . . , s n , t n ∈ G(Σ, C) be terms such that the terms f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) evaluate to the same element of A. Then  f (s 1 , . . . , s n (t 1 , . . . , t n ), and thus these terms have the same canonical forms w.r.t. R F,Σ e (E). Let s 1 , t 1 , . . . , s n , t n be the canonical forms of the terms s 1 , t 1 , . . . , s n , t n , respectively. Then the canonical forms of f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) are respectively identical to the canonical forms of f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ). Since f / ∈ Σ F , no rule with root symbol from Σ F on the left-hand side is applicable to the latter terms. Thus, the only possible rules applicable to these terms are flat function rules for f . Consequently, there are two possible cases for how the (identical) canonical forms of f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) can look like: 1. The terms f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) respectively have the canonical forms f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ), and the corresponding arguments are syntactically equal, i.e., s j = t j for j = 1, . . . , n. In this case, s j ≈ R F,Σ e (E) s j = t j ≈ R F,Σ e (E) t j for j = 1, . . . , n, and thus, for j = 1, . . . , n, the terms s j and t j evaluate to the same element of A. f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) reduce to the same constant d.

The terms
must contain the rules f (s 1 , . . . , s n ) → d and f (t 1 , . . . , t n ) → d. By the construction of R F,Σ e (E), we thus have s j = t j for all j = 1, . . . , n since otherwise new constant rules would have been added in step (e) and the construction would not yet have terminated. This yields s j ≈ R F,Σ e (E) s j = t j ≈ R F,Σ e (E) t j for j = 1, . . . , n, and thus, for j = 1, . . . , n, the terms s j and t j evaluate to the same element of A.
Summing up, we have thus shown that A also satisfies extensionality for the symbols in Σ e , which completes the proof of the only-if-direction. f (b, h(a)) ≈ F,Σ e E c for the set of identities E of Example 3. We have already seen that these two terms rewrite to the same canonical form w.r.t.

Recall that
The following corollary is an easy consequence of the above theorem, the conditions satisfied if rewrite-based congruence closure is effective (polynomial), and Lemma 8.

Corollary 3
Let Σ F ⊆ Σ and Σ e ⊆ Σ \ Σ F , F be a set of identities formulated using the function symbols in Σ F and variables, and assume that rewrite-based congruence closure is effective (polynomial) for Σ F and F. Then the word problem for finite sets E of ground identities w.r.t. F and the extensional symbols in Σ e is decidable (in polynomial time), i.e., given terms s 0 , t 0 ∈ G(Σ, C 0 ), we can decide (in polynomial time) whether s 0 ≈ F,Σ e E t 0 holds or not.
In the case of a set of strongly shallow identities S for a signature Σ S that is arity bounded, the results shown in the previous section imply that rewrite-based congruence closure is polynomial for Σ S and S. Thus, we obtain the following instance of Corollary 3.

Corollary 4
Let Σ S ⊆ Σ and Σ e ⊆ Σ \ Σ S , S be a set of strongly shallow identities for Σ S , and assumed that Σ S is arity-bounded. Then the word problem for finite sets of ground identities w.r.t. S and the extensional symbols in Σ e is decidable in polynomial time, i.e., given a finite set of ground identities E ⊆ G(Σ, C 0 ) × G(Σ, C 0 ) and terms s 0 , t 0 ∈ G(Σ, C 0 ), we can decide in polynomial time whether s 0 ≈ S,Σ e E t 0 holds or not if we assume that the maximal arity of the symbols in Σ S is bounded by a constant.
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 proof actually deals with this problem. The answer is: in Case 1 of the case distinction in the proof of the only-if-direction of Theorem 2. In fact, there we consider a derived identity f (s 1 , . . . , s n ) ≈ f (t 1 , . . . , t n ) such that the (syntactically identical) canonical forms of f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) are not a constant from C, but of the form f (s 1 , . . . , s n ) = f (t 1 , . . . , t n ). Basically, this means that f (s 1 , . . . , s n ) and f (t 1 , . . . , t n ) 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, these terms are "large" terms that potentially could cause a problem: an identity between them has been derived, and now extensionality applied to this identity yields new identities s i ≈ t i between smaller terms. Our proof shows that these identities can nevertheless be derived from R F,Σ e (E), and thus do not cause a problem. For the proof of Theorem 2 to go through, it is important that the canonical rewrite system R F,Σ e (E) works for all ground terms in G(Σ, C), and not just for a finite set of "small" terms.

Symbols that are Commutative and Extensional
In the previous section, we have made the assumptions that the sets Σ F and Σ e are disjoint, i.e., we did not consider extensionality for symbols satisfying the identities in F. The reason is that, without this restriction, we might obtain more consequences than we bargained for. For example, it is easy to see that the presence of a commutative and extensional symbol would trivialize the equational theory. In fact, 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 yields 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 = ∅.
To avoid this problem, one can, however, look at appropriate variants of extensionality. In this section, we restrict the attention to commutativity, and 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.
-the domain of A is B; It is easy to see that A satisfies the identities in E φ . In addition, commutativity of f and (3) are satisfied since these properties hold in the free commutative algebra [20]. It is now easy to see that t A φ = v(φ) B = 0 B = 0 A , and thus A does not satisfy the identity t φ ≈ 1 since in B the class of the generator 0 is different from the class of the generator 1.
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 Algorithm 2. In step (g) this procedure applies Algorithm 1 for the special case where the set F c of strongly shallow identities axiomatize commutativity of the symbols in Σ c . We denote the canonical rewrite system produced by an application of this algorithm to the current flat system This nondeterministic algorithm has different runs, depending on the choices made in the nondeterministic part of step (e). But each run r produces a rewrite system R F c ,Σ e r (E).

Example 4
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 (1,0) .
In steps (a) and (b) of Algorithm 1, these rules are transformed into the form commutativity for every f ∈ Σ c , extensionality for every f ∈ Σ e \ Σ c , and c-extensionality for every f ∈ Σ e ∩ Σ c . Since the former three properties can be shown as in the proof of Theorem 2, we concentrate on the last one.
Thus, let f ∈ Σ e ∩ Σ c be a commutative and c-extensional function symbol and s 1 , t 1 , s 2 , t 2 ∈ G(Σ, C) be terms such that the terms f (s 1 , s 2 ) and f (t 1 , t 2 ) evaluate to the same element of A. Again, this implies that these terms have the same canonical forms w.r.t. R F c ,Σ e r (E). Let s 1 , t 1 , s 2 , t 2 be the canonical forms of the terms s 1 , t 1 , s 2 , t 2 , respectively. As before, we distinguish several cases, but since f is commutative we now also need to take the rules in R(F c , > lpo ), which are part of R F c ,Σ e r (E), into account: -First, assume that the canonical forms of f (s 1 , s 2 ) and f (t 1 , t 2 ) still have root symbol f .
We distinguish several subcases, depending on how the rules in R(F c , > lpo ) have been applied: -The terms f (s 1 , s 2 ) and f (t 1 , t 2 ) have the canonical forms f (s 1 , s 2 ) and f (t 1 , t 2 ), respectively, and the corresponding arguments are syntactically equal, i.e., s 1 = t 1 and s 2 = t 2 . As in the proof of Theorem 2, this implies that s 1 and t 1 as well as s 2 and t 2 respectively evaluate to the same elements of A. -The case where the terms f (s 1 , s 2 ) and f (t 1 , t 2 ) have the canonical forms f (s 2 , s 1 ) and f (t 2 , t 1 ), respectively, can be handled in the same way since then again s 1 = t 1 and s 2 = t 2 .
-The terms f (s 1 , s 2 ) and f (t 1 , t 2 ) have the canonical forms f (s 2 , s 1 ) and f (t 1 , t 2 ), respectively, and the corresponding arguments are syntactically equal, i.e., s 2 = t 1 and s 1 = t 2 . In this case we can derive that s 2 and t 1 as well as s 1 and t 2 respectively evaluate to the same elements of A. -The case where the terms f (s 1 , s 2 ) and f (t 1 , t 2 ) have the canonical forms f (s 1 , s 2 ) and f (t 2 , t 1 ), respectively, can be handled in the same way since then again s 2 = t 1 and s 1 = t 2 .
-Second, assume that the canonical forms of f (s 1 , s 2 ) and f (t 1 , t 2 ) are the same constant d. Again, we distinguish several subcases, depending on how the rules in R(F c , > lpo ) have been applied before the reduction to the constant d: -The term rewriting system R F c ,Σ e r (E) contains the rules f (s 1 , s 2 ) → d and By the construction of R F c ,Σ e r (E), we thus have s 1 = t 1 and s 2 = t 2 , or s 1 = t 2 and s 2 = t 1 since no new constant rules have been added. This implies that s 1 and t 1 as well as s 2 and t 2 respectively evaluate to the same elements of A, or s 1 and t 2 as well as s 2 and t 1 respectively evaluate to the same elements of A.
-The cases where the function rules reducing to d contain the arguments of f in other permutations can be treated in the same way.
Summing up, we have thus shown that A satisfies c-extensionality for the symbols in Σ e ∩Σ c , which completes the proof of the theorem.
Coming back to Example 4, we note that φ = p ∨ ¬p is valid, and thus (by Lemma 9), the identity f ∨ ( p, f ¬ ( p)) ≈ 1 holds in all algebras that satisfy E φ and interpret f as a commutative and c-extensional symbol. Using the rewrite system generated by the run r 1 , we obtain the following rewrite sequence: For the run r 2 , we obtain the sequence Thus, for both runs the terms f ∨ ( p, f ¬ ( p)) and 1 have the same canonical form 1.
Together with Proposition 2, Theorem 3 yields the following complexity results.

Corollary 5
Consider 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 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 , extensionality for every f ∈ Σ e \ Σ c , and c-extensionality for every f ∈ Σ e ∩ Σ c is coNP-complete.
Proof Since Proposition 2 yields coNP-hardness, it is sufficient to show that the complement problem is in NP. This is an easy consequence of Theorem 3. In fact, to show that s 0 ≈ t 0 does not hold in all such algebras, it is sufficient to generate one run r of our nondeterministic construction, and then test whether s 0 and t 0 have different canonical forms w.r.t. R F c ,Σ e r (E). The system R F c ,Σ e r (E) can be generated in nondeterministic polynomial time, and the canonical forms can then be computed in polynomial time.

Related Work
As already mentioned in the introduction, several approaches for how to solve the word problem for finite sets of ground identities by constructing a canonical rewrite system have been developed in the literature [7][8][9]. Restricted to the case of uninterpreted function symbols, the approach employed in the present paper is similar to the rewriting-based congruence closure algorithm developed in [7]. In the presence of interpreted function symbols, i.e., ones that are must satisfy certain non-ground identities, our approach differs from previous ones [12,14,15] by the use of an ordered rewrite system. Basically, in our approach the ordered rewrite system deals with the semantic properties of the interpreted function symbols, and the only interaction with the construction of the rewrite system for the ground identities is through computing canonical forms of the left-hand sides of function rules using the ordered rewrite system. Otherwise, the construction is the same as for the case of uninterpreted function symbols. The papers [14,15], which consider symbols that are associativity and commutativity (AC), deal with the problem that AC does not allow for a terminating nonground rewrite system not by employing ordered rewriting, but by using rewriting modulo AC. This makes the computation of critical pairs more complicated and requires the use of completion modulo AC. One can actually use ordered rewriting to obtain a canonical ground rewrite system for AC [17], but since associativity is not shallow, the simple approach of combining this system with a rewrite system constructed from ground identities used in the present paper would not work. In fact, since it is known that the word problem for commutative semigroups is ExpSpace-complete [21], it is clear that some expensive additional computations are required. The approach in [12] treats, e.g., commutativity by dealing with it directly in the construction of the ground rewrite system, rather than by employing a separate ordered rewrite system. To the best of our knowledge, no other work than ours has dealt with extensionality in the context of ground identities.
Shallow identities have been investigated in term rewriting and unification theory as a class of identities with good computational properties before. Comon et al. [16] introduce a more general notion of shallow identities than the strongly shallow identities employed in the present paper. According to [16], an identity is shallow if every variable occurs at depth at most one in the left-and right-hand side of the identity. In particular, this notion of shallow also encompasses ground identities and identities like idempotency [i.e. f (x, x) = x]. It is shown in [16] that the word problem for shallow theories is decidable. The approach basically applies a completion procedure akin to unfailing completion [22] to obtain an ordered rewrite system whose ground instantiation is canonical. This yields decidability of the word problem as considered in our Corollary 1, but no complexity result is stated in [16]. Extensionality is not considered in that paper. Our restriction to sets of strongly shallow identities S allows us to obtain an ordered rewrite system (S * , > lpo ) whose ground instantiation R(S * , > lpo ) is canonical in a very simple way. For more general shallow identities, this simple construction would not work (e.g., idempotency would destroy finiteness of S * ). In particular, our polynomiality results depend of the fact that S * is of polynomial size if the signature Σ S is arity-bounded.
Lynch et al. [23,24] introduce a method called schematic saturation for automatically generating a ground satisfiability procedure for a given theory T by combining the axioms of T with ground clauses using paramodulation. Similar to Knuth-Bendix completion, schematic saturation need not terminate. However, if it does terminate, then the word problem for ground identities w.r.t. the theory T is decidable in polynomial time by superposition because superposition only generates polynomially many clauses. Similar to our complexity result for strongly shallow identities stated in Corollary 1, this polynomiality result needs the assumption that the signature used by the theory T is arity-bounded. If applied to commutativity and clauses specifying extensionality for non-commutative symbols, schematic saturation terminates, 4 which means that superposition can be used to decides the word problem for ground identities w.r.t. that theory in polynomial time. Schematic saturation does not terminate in the presence of commutative symbols that are c-extensional. But it can be extended by one more deletion rule, which then leads to termination. 5 If schematic saturation with the deletion rule halts on the clauses representing some theory, then the word problem for ground identities w.r.t. that theory is again decidable by superposition, but now it may generate exponentially many clauses. This appears to yield an ExpTime decision procedure for the coNP-complete word problem considered in Corollary 5. The problem with applying the results in [23,24] is that there are no criteria known that are both easy to check and that guarantee that schematic saturation (with or without the additional deletion rule) terminates. One must run the procedure and see what happens. Unfortunately, there is currently no publicly accessible implementation of this procedure available that could be used for doing this.
The paper [25] develops a procedure that can combine decision procedures for the word problem for equational theories that share only constants. To be more precise, the following result is shown there. [25]) Let E := E 1 ∪ E 2 , where, for i = 1, 2, E i is a nontrivial equational theory over Σ i . Furthermore, assume that Σ := Σ 1 ∩ Σ 2 is a finite set of constant symbols, and that E 1 and E 2 agree on Σ, that is, c = E 1 d iff c = E 2 d for all c, d ∈ Σ.

Theorem 4 (Baader and Tinelli
If the word problem is decidable for E 1 and E 2 , then it is also decidable for E. Though it is not explicitly stated in [25], the combination procedure preserves polynomiality for the word problem, i.e., if the word problem is decidable in polynomial time for E 1 and E 2 , then it is also decidable in polynomial time for E (see the termination proof for the procedure in [26]).
This result can be applied in the setting of ground identities with interpreted function symbols considered in the present paper. Indeed, assume that F and G are equational theories over the disjoint signatures Σ F and Σ G such that the word problem for finite set of ground identities w.r.t. F is decidable, and the same is true for G. Then the word problem for finite sets of ground identities w.r.t. F ∪ G is decidable as well. In fact, while the original ground identities may then contain symbols from both Σ F and Σ G , flattening as in our construction of the rewrite system R(E) can be used to obtain a conservative extension of the input theory in which only constants are shared between the F and the G part. These theories may not yet agree on the shared constants, but this can be achieved by iteratedly adding identities between the shared constants derived from one theory to the other. This way, we can, for example, combine the decision procedure for the case of ground identities w.r.t. strongly shallow identities described in Sect. 3 with a decision procedure for ground identities w.r.t. AC symbols [14,15,27,28]. This kind of combination also works in the presence of extensional symbols. In fact, while extensionality is axiomatized by conditional identities rather than identities, our results in Sect. 4 show that we can represent its effect using the equational theory axiomatized by the computed canonical rewrite system, which allows us to apply the above combination result.

Conclusion
We have shown, using a rewriting-based approach, that adding strongly shallow identities (like commutativity) and extensionality for certain function symbols to a finite set of ground identities leaves the complexity of the word problem in P. In contrast, adding c-extensionality 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) [4,11]. Since this complexity upper bound can also be achieved using a rewriting-based approach [9,12], 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 maybe other kinds of strongly shallow identities) and extensionality, as in Sect. 4, but this question was not in the focus of the present paper.
Our result on adding extensionality is actually not restricted to the case of interpreted function symbols whose semantic properties are defined by strongly shallow identities. Instead, we exhibited general properties that the canonical rewrite system computed by semantic congruence closure for the equational theory under consideration must satisfy such that extensionality can be treated in the simple way described in Sect. 4. An important condition is that the system is canonical for all ground terms, and not just a finite set of "small" terms determined by the input. It would be interesting to see whether rewriting-based approaches to congruence closure for other theories produced rewrite systems that satisfy the conditions stated in Sect. 4. For the rewriting-based approaches that deal with associative-commutative symbols proposed in [14,15], this is not directly the case since they use rewriting modulo AC. However, our approach for adding extensional symbols in Sect. 4 can probably be extended to deal with rewriting modulo AC since the AC symbols are not extensional. We have mentioned in the previous section that extensionality in the presence of non-extensional AC symbols can be dealt with by the combination results in [25]. However, while this approach yields a decision procedure for the word problem, it does not provide us with a canonical ground rewrite system. Another, and more challenging question would be to come up with an appropriate notion of extensionality for AC symbols, and to show that adding it leaves the word problem decidable.
In our treatment of strongly shallow identities, we have used a rather brute-force way to obtain an ordered rewrite system that is canonical on ground terms, which basically adds all implied identities between strongly shallow h-terms (see the definition of the set S * in Sect. 2.3). Instead, one could use unfailing completion [22] to add only those consequences that are needed to achieve ground confluence. The results in [16] show that this always terminates on shallow (and thus also strongly shallow) identities. The interesting question would then be under what conditions on the strongly shallow identities this actually terminates in polynomial time without requiring arity-boundedness. As mentioned in the previous section, the approach used in [16] can actually deal with more general kinds of shallow identities than the strongly shallow ones considered here. It produces an ordered rewrite system that is canonical for ground terms, but it is not clear whether, with the more general notion of shallow identities employed in [16], this system satisfies the properties required in Sect. 4 for adding extensionality. For strongly shallow identities other than commutativity, it would also be interesting to come up with appropriate variants of c-extensionality.
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 [29] and [30].