Modularity and Combination of Associative Commutative Congruence Closure Algorithms enriched with Semantic Properties

Algorithms for computing congruence closure of ground equations over uninterpreted symbols and interpreted symbols satisfying associativity and commutativity (AC) properties are proposed. The algorithms are based on a framework for computing a congruence closure by abstracting nonflat terms by constants as proposed first in Kapur's congruence closure algorithm (RTA97). The framework is general, flexible, and has been extended also to develop congruence closure algorithms for the cases when associative-commutative function symbols can have additional properties including idempotency, nilpotency, identities, cancellativity and group properties as well as their various combinations. Algorithms are modular; their correctness and termination proofs are simple, exploiting modularity. Unlike earlier algorithms, the proposed algorithms neither rely on complex AC compatible well-founded orderings on nonvariable terms nor need to use the associative-commutative unification and extension rules in completion for generating canonical rewrite systems for congruence closures. They are particularly suited for integrating into the Satisfiability modulo Theories (SMT) solvers. A new way to view Groebner basis algorithm for polynomial ideals with integer coefficients as a combination of the congruence closures over the AC symbol * with the identity 1 and the congruence closure over an Abelian group with + is outlined.


Introduction
Equality reasoning arises in many applications including compiler optimization, functional languages, and reasoning about data bases, most importantly, reasoning about different aspects of software and hardware.The significance of the congruence closure algorithms on ground equations in compiler optimization and verification applications was recognized in the mid 70's and early 80's, leading to a number of algorithms for computing the congruence closure of ground equations on uninterpreted function symbols [DST80,Sho78,NO80].Whereas congruence closure algorithms were implemented in earlier verification systems [Sho78,NO80,KZ95,Zha92], their role has become particularly critical in Satisfiability modulo Theories (SMT) solvers as a glue to combine different decision procedures for various theories.More recently, many new uses of the congruence closure are being explored in the egg project at the University of Washington [WNW + 21].
We present algorithms for the congruence closure of ground equations which in addition to uninterpreted function symbols, have symbols with the associative (A) and commutative (C) properties.Using these algorithms, it can be decided whether another ground equation follows from a finite set of ground equations with associative-commutative (AC) symbols as well as uninterpreted symbols.Canonical forms (unique normal forms) can be associated with congruence classes.Further, a unique reduced ground rewrite system serves as a presentation of the congruence closure of a finite set of ground equations, which allows checking whether two different finite sets of ground equations define the same congruence closure or if one is contained in the other.In the presence of disequations on ground terms with AC and uninterpreted symbols, a finite set of ground equations and disequations can be checked for satisfiability.
The main contributions of the paper are (i) a modular combination framework for the congruence closure of ground equations with multiple AC symbols, uninterpreted symbols, and constants, leading to (ii) modular and simple algorithms that can use flexible termination orderings on ground terms and do not need to use AC/E unification algorithms for generating canonical forms; (iii) the termination and correctness proofs of these algorithms are modular and easier.The key insights are based on extending the author's previous work presented in [Kap97,Kap19]: introduction of new constants for nested subterms, resulting in flat and constant equations, extended to purification of mixed subterms with many AC symbols; AC ground terms are flattened and new constants for pure AC terms in each AC symbol are introduced, resulting in disjoint subsets of ground equations on single AC symbols with shared constants.The result of this transformation is a finite union of disjoint subsets of ground equations with shared constants: (i) a finite set of constant equations, (ii) a finite set of flat equations with uninterpreted symbols, and (iii) for each AC symbol, a finite set of equations on pure flattened terms in a single AC symbol.
With the above decomposition, reduced canonical rewrite systems are generated for each of the subsystems using their respective termination orderings that extend a common total ordering on constants.A combination of the reduced canonical rewrite systems is achieved by propagating constant equalities among various rewrite systems; whenever new implied constant equalities are generated, each of the reduced canonical rewrite systems must be updated with additional computations to ensure their canonicity.Due to this modularity and factoring/decomposition, the termination and correctness proofs can be done independently of each subsystem, providing considerable flexibility in choosing termination orderings.
The combination algorithm terminates when no additional implied constant equalities are generated.Since there are only finitely many constants in the input and only finitely many constants are needed for purification, the termination of the combination algorithm is guaranteed.The result is a reduced canonical rewrite system corresponding to the AC congruence closure of the input ground equations, which is unique for a fixed family of total orderings on constants and different pure AC terms in each AC symbol.The reduced canonical rewrite system can be used to generate canonical signatures of ground terms with respect to the congruence closure.
The framework provides flexibility in choosing orderings on constants and terms with different AC symbols, enabling canonical forms suitable for applications instead of restrictions imposed due to the congruence closure algorithms.Interpreted AC symbols can be further enriched with properties including commutativity, idempotency, nilpotency, existence of 19:3 identities, cancelation and group properties, without restrictions on orderings on mixed terms.Of particular interest is a new algorithm for generating congruence closure of ground equations with a cancelative AC symbol; this is discussed in detail as a separate topic because of new kinds of critical pairs, called cancelative disjoint superposition, needed to generate a canonical rewrite system.Termination and correctness proofs of these congruence closure algorithms are modular and simple in contrast to complex arguments and proofs in [BTV03,NR91].These features of the proposed algorithms make them attractive for integration into SMT solvers as their implementation does not need heavy duty infrastructure including AC unification, extension rules, and AC compatible orderings.
The next subsection contrasts in detail the results of this paper with previous methods, discussing the advantages of the proposed framework and the resulting algorithms.Section 2 includes definitions of congruence closure with uninterpreted and interpreted symbols.This is followed by a review of key constructions used in the congruence closure algorithm over uninterpreted symbols as proposed in [Kap97].Section 3 introduces purification and flattening of ground terms with AC and uninterpreted symbols by extending the signature and introducing new constants.This is followed by an algorithm first reported in [KKN85] for computing the congruence closure and the associated canonical rewrite system from ground equations with a single AC symbol and constants.In section 4, it is shown how additional properties of AC symbols such as idempotency, nilpotency, identity and their combination can be integrated into the algorithm.Section 5 presents a new algorithm for generating a congruence closure algorithm for ground equations with a cancelative AC symbol; new kinds of superpositions and critical pairs are needed to generate a canonical rewrite system since unlike most congruence closure algorithms, it becomes necessary to explore terms larger than appearing in the input and/or a query to get congruences on terms using the cancelation inference rule.That section also presents a congruence closure algorithm for ground equations with an AC symbol satisfying group properties; it is shown to be related to Gaussian elimination.Section 6 discusses how the propagation of new constant equalities deduced from various algorithms update various kinds of ground canonical rewrite system.In Section 7, an algorithm for computing congruence closure of AC ground equations with multiple AC symbols and constants is presented.Section 8 generalizes to the case of combination of AC symbols and uninterpreted symbols.Section 9 shows how lexicographic orderings in which a constant can be bigger than a nonconstant ground term can be supported in the proposed framework.Section 10 discusses a variety of examples illustrating the proposed algorithms.Section 11 illustrates the power and elegance of the proposed framework by demonstrating how a congruence closure algorithm for two AC symbols with some additional properties, particularly distributivity, can be further generalized to formulate a Gröbner basis algorithm on polynomial ideals over the integers.Section 12 concludes with some ideas for further investigation.
1.1.Related Work.Congruence closure algorithms have been developed and analyzed for over four decades [DST80,Sho78,NO80].The algorithms presented here use the framework first informally proposed in [Kap97] for congruence closure in which the author separated the algorithm into three parts: (i) constant equivalence closure, and (ii) nonconstant flat terms related to constants by flattening nested terms by introducing new constants to stand for them, and (iii) updating of nonconstant rules as constant equivalence closure evolves and propagates new constant equalities.This simplified the presentation, the correctness argument as well as the complexity analysis, and made the framework easier to generalize to other settings including conditional congruence closure [Kap19] and semantic congruence closure [BK20].Further, it enables the generation of a unique reduced ground canonical rewrite system for a congruence closure, assuming a total ordering on constants; most importantly, the framework gives freedom in choosing orderings on ground terms, leading to desired canonical forms appropriate for applications.
To generate congruence closure in the presence of AC symbols, the proposed framework builds on the author and his collaborators' work dating back to 1985, where they demonstrated how an ideal-theoretic approach based on Gröbner basis algorithms could be employed for word problems and unification problems over commutative algebras [KKN85].
Congruence closure algorithms on ground equations with interpreted symbols can be viewed as special cases of the Knuth-Bendix completion procedure [KB70] on (nonground) equations with universal properties characterizing the semantics of the interpreted symbols.In case of equations with AC symbols, Peterson and Stickel's extension of the Knuth-Bendix completion [PS81] using extension rules, AC unification and AC compatible orderings can be used for congruence closure over AC symbols.For an arbitrary set E of universal axioms characterizing the semantics of interpreted symbols, E-completion with coherence check and E-unification along with E-compatible orderings need to be used.Most of the general purpose methods do not terminate in general.Even though the Knuth-Bendix procedure can be easily proved to terminate on ground equations of uninterpreted terms, that is not necessarily the case for its extensions for other ground formulas.
In [BL81], a generalization of the Knuth-Bendix completion procedure [KB70] to handle AC symbols [PS81] is adapted to develop decision algorithms for word problems over finitely presented commutative semigroups; this is equivalent to the congruence closure of ground equations with a single AC symbol on constants.Related methods using extension rules introduced to handle AC symbols and AC rewriting for solving word problems over other finite presented commutative algebras were subsequently reported in [LeC83].
In [NR91], the authors used the completion algorithm discussed in [KKN85] and a total AC-compatible polynomial reduction ordering on congruence classes of AC ground terms to establish the existence of a ground canonical AC system first with one AC symbol.To extend their method to multiple AC symbols, particularly the instances of distributivity property relating ground terms in two AC symbols * and +, the authors had to combine an ACcompatible total reduction ordering on terms along with complex polynomial interpretations with polynomial ranges, resulting in a complicated proof to orient the distributivity axiom from left to right.Using this highly specialized generalization of polynomial orderings, it was proved in [NR91] that every ground AC theory has a finite canonical system which also serves as its congruence closure.
The proposed approach, in contrast, is orthogonal to ordering arguments on AC ground terms; any total ordering on original constants and new constants is extended to one of many possible orderings on pure terms with a single AC symbol; this ordering on AC terms suffices to compute a canonical ground AC rewrite system.Different orderings on AC terms with different AC symbols can be used; for example, ground terms of an AC symbol + could be oriented in a completely different way than ground terms for another AC symbol * .Instances of the distributivity property expressed on different AC ground terms can also be oriented in different nonuniform ways.This leads to flexible ordering requirements on uninterpreted and interpreted symbols based on the properties desired of canonical forms.
In [Mar91], a different approach was taken for computing a finite canonical rewrite system for ground equations on AC symbols.Marche first proved a general result about AC proof methods not to mention arguments dealing with fairness of completion procedures.(ii) all require complex total AC compatible orderings.In contrast, ordering restrictions in the proposed algorithms are dictated by individual components; little restriction is imposed for the uninterpreted part; independent separate orderings on +-monomials for each AC symbol + that extend a common total ordering on constants can be used, thus giving considerable flexibility in choosing termination orderings overall.In most related approaches except for [NR91], critical pairs computed using expensive AC unification steps are needed, which are likely to make the algorithms inefficient; it is well-known that many superfluous critical pairs are generated due to AC unification.These advantages make us predict that the proposed algorithms can be easily integrated with SMT solvers since they do not require sophisticated machinery of AC-unification and AC-compatible orderings, extension rules and AC completion.
Since the proposed research addresses combination of congruence closure algorithms, a brief comparison with the extensive literature on the modular combination of decision procedures for theories with disjoint signatures but sharing constants, as well as combining matching and unification algorithms must be made.Combination problems are a lot easier to consider for ground theories.The reader would notice that much like the seminal work of Nelson and Oppen where they showed that for combining satisfiability procedures of theories under certain conditions, it suffices to share equalities on shared constants and variables, the proposed combination framework only shares constant equalities even though there are no additional restrictions such as that ground equational theories in this paper satisfy the stable finiteness condition (see [BT97] for a detailed discussion of implications of Nelson and Oppen's requirements for equational theories).More general combination results for decidable theories can be found in [ABRS09] in which a variable inactivity condition (disallowing literals of the form x = t in clauses thus prohibiting paramodulation on a variable), a kind of "pseudo" collapse-free equation, are imposed; such combination frameworks are likely to need more sophisticated machinery to consider AC symbols.

Preliminaries
Let F include a finite set C of constants, a finite set F U of uninterpreted symbols, and a finite set F AC of AC symbols.i.e., F = F AC ∪ F U ∪ C. Let GT (F ) be the ground terms constructed from F ; sometimes, we will write it as GT (F, C) to highlight the constants C of F .We will abuse the terminology by calling a k-ary function symbol as a function symbol if k > 0 and constant if k = 0.A function term is meant to be a nonconstant term with a nonconstant outermost symbol.Symbols in F are either uninterpreted (to mean no semantic property of such a function is assumed) or interpreted satisfying properties expressed as universally quantified equations (called universal equations).
Nothing else is in CC(S).19:7 CC(S) is thus the smallest relation that includes S and is closed under reflexivity, symmetry, transitivity, and under function application.It is easy to see that CC(S) is also the equational theory of S [BN98, BK20].

2.2.
A Congruence Closure Algorithm for Uninterpreted Symbols.The algorithm in [Kap97,Kap19] for computing congruence closure of a finite set S of ground equations over uninterpreted function symbols and constants serves as the main building block in this paper.The algorithm extends the input signature by introducing new constant symbols to recursively stand for each nonconstant subterm and generates two types of equations: (i) constant equations, and (ii) flat terms of the form h(c 1 , • • • , c k ) equal to constants (also called flat equations). 1 It can be proved that the congruence closure of ground equations on the extended signature when restricted to the original signature, is indeed the congruence closure of the original equations [BK20].A disequation on ground terms is converted to a disequation on constants by introducing new symbols for the ground terms.
As given in Section 3 of [BK20], assuming a total ordering on constants, the algorithm (i) computes a canonical rewrite system from constant equations, picking a canonical representative, which is the least constant among all constants in each congruence class, and (ii) replaces constants in the left side of each flat rule by their canonical representatives, and identifies flat rules with identical left sides, replacing them by a single rule with the least constant on its right side, thus possibly generating new constant equalities.These steps are repeated if at least one new constant equality is generated in (ii).
Using a total ordering on constants (typically with new constants introduced to extend the signature being smaller than constants from the input), the output of the algorithm in [Kap97, Kap19, BK20] is a reduced canonical rewrite system R S associated with CC(S) (as well as S) that includes function rules, also called flat rules, of the form h(c 1 , • • • , c k ) → d and constant rules c → d such that no two left sides of the rules are identical; further, all constants are in canonical forms.The following result is proved in [Kap97] (see also [NO07]).
Theorem 2.2 [Kap97].Given a set S of ground equations, a reduced canonical rewrite system R S on the extended signature, consisting of nonconstant flat rules h(c 1 , . . ., c k ) → d, and constant rules c → d, can be generated from S in O(n 2 ) steps.The complexity can be further reduced to O(n * log(n)) steps if all function symbols are binary or unary.For a given total ordering on constants, R S is unique for S, subject to the introduction of the same set of new constants for nonconstant subterms.
As shown in [DST80], function symbols of arity > 2 can be encoded using binary symbols using additional linearly many steps.
The canonical form of a ground term g using R S is denoted by ĝ and is its canonical signature (in the extended language).Ground terms g 1 , g 2 are congruent in CC(S) iff ĝ1 = ĝ2 .
The output of the above algorithm can also be viewed as consisting of disjoint rewrite systems corresponding to (i) a rewrite system on constants representing Union-Find algorithm in which the rewrite rules correspond to the edges in a forest of trees such that if there 1 This representation of ground equations can also be viewed as an equivalence relation on nodes, named as constants, in a DAG representation of ground terms in which nonleaf nodes are labeled with function symbols and represent subterms, with a edge from the function labeling the node to the nodes serving as its arguments.A DAG representation supports full sharing of ground subterms.
is an edge from a constant c i to c j toward a root (implying that c i > c j ), then there is a rewrite rule c i → c j , and (ii) for each nonconstant uninterpreted symbol h ∈ F U , the set of uninterpreted function symbols, there is a finite set of flat rewrite rules of the form h(c 1 , • • • , c k ) → d on root constants in the forest with the property that no two left sides of the rewrite rules are identical.However, if Union-Find algorithm is used for generating a canonical rewrite system on constant equations, ordering on constants cannot be chosen a priori and instead should be chosen dynamically based on how various equivalence classes of constants get merged to maintain the balanced trees representing each equivalence class.For simplicity, in the rest of the paper, a total ordering on constants a priori will be assumed for generating a canonical rewrite system R S to represent the congruence closure CC(S) of S.
2.3.AC Congruence Closure.The above definition of congruence closure CC(S) is extended to consider interpreted symbols.Let IE be a finite set of universally quantified equations with variables, specifying properties of interpreted function symbols in F .For example, the properties of an AC symbol f are: ∀x, y, z, f (x, y) = f (y, x) and f (x, f (y, z)) = f (f (x, y), z).An idempotent symbol g, for another example, is specified as ∀x, g(x, x) = x.To incorporate the semantics of these properties: (vi) from a universal axiom s = t ∈ IE, for all variables x i 's in s, t and any ground substitution σ of x i 's, σ(s) = σ(t) ∈ CC(S).
CC(S) is thus the smallest relation that includes S and is closed under reflexivity, symmetry, transitivity, function application, and the substitution of variables in IE by ground terms.
Given a finite set S of ground equations with uninterpreted and interpreted symbols, the congruence closure membership problem is to check whether another ground equation u = v ∈ CC(S) (meaning semantically that u = v follows from S, written as S |= u = v).A related problem is whether given two sets S 1 and S 2 of ground equations, CC(S 2 ) ⊆ CC(S 1 ), equivalently S 1 |= S 2 .Birkhoff's theorem relates the syntactic properties, the equational theory, and the semantics of S.
If S also includes ground disequations, then besides checking the unsatisfiability of a finite set of ground equations and disequations, new disequations can be derived in case S is satisfiable.The inference rule for deriving new disequations for an uninterpreted symbol is: In particular, if f is unary, then the disequation is immediately derived.
Disequations in case of interpreted symbols generate more interesting formulas.In case of a commutative symbol f , for example, the disequation For an AC symbol g, there are many possibilities; as an example, for the disequation g(a, g(b, c)) = g(a, g(a, g(a, c)) To emphasize the presence of AC symbols, let ACCC(S) stand for the AC congruence closure of S with AC symbols; we will interchangeably use ACCC(S) and CC(S).
2.4.Flattening and Purification.Following [Kap97], ground equations in GT (F ) with AC symbols are transformed into three kinds of equations by introducing new constants for subterms: (i) constant equations of the form c = d, (ii) flat equations with uninterpreted symbols of the form h(c 1 , , where c's, d's are constants in C, h ∈ F U , and every AC symbol f is viewed to be variadic (including f (c) standing for c).Nested subterms of every AC symbol f are repeatedly flattened: f (f (s 1 , s 2 ), s 3 ) to f (s 1 , s 2 , s 3 ) and f (s 1 , f (s 2 , s 3 )) to f (s 1 , s 2 , s 3 ) until all arguments to f are constants or nonconstant terms with outermost symbols different from f .2Nonconstant arguments of a mixed AC term where u i 's are new constants, with t i = u i if t i is not a constant.A subterm whose outermost function symbol is uninterpreted, is also flattened by introducing new constants for their nonconstant arguments.These transformations are recursively applied on the equations including those with new constants.
New constants are introduced only for nonconstant subterms and their number is minimized by introducing a single new constant for each distinct subterm irrespective of its number of occurrences (which is equivalent to representing terms by directed acyclic graphs (DAGs) with full sharing whose each non-leaf node is assigned a distinct constant).As an example, ((f (a, b) * g(a))+f (a+(a+b), (a * b)+b)) * ((g(a)+((f (a, b)+a)+a))+(g(a) * b)) = a is purified and flattened with new constants The arguments of an AC symbol are represented as a multiset since the order does not matter but multiplicity does.For an AC symbol f , if a flat term is In case f has its identity e, i.e., ∀x, f (x, e) = x, then e is written as is, or f ({ {} }).A singleton constant c is ambiguously written as is or equivalently f ({ {c} }).An f -monomial f (M 1 ) is equal to f (M 2 ) iff the multisets M 1 and M 2 are equal.
Without any loss of generality, the input to the algorithms below are assumed to be the above set of flat ground equations on constants, equivalently, equations of the form f (M i ) = f (M i ).

Congruence Closure with a single Associative-Commutative (AC) Symbol
The focus in this section is on interpreted symbols with the associative-commutative properties; uninterpreted symbols are considered later.
Checking whether a ground equation on AC terms is in the congruence closure of a finite set S of ground equations is the word problem over finitely presented commutative algebraic structures, presented by S characterizing their interpretations as discussed in [KKN85, LeC83,BL81].Another goal is to associate a reduced canonical rewrite system as a unique presentation of ACCC(S) and a canonical signature with every AC congruence class in the AC congruence closure of a satisfiable S.
For a single AC symbol f and a finite set S of monomial equations {f is the reflexive, symmetric and transitive closure of S closed under f .Section 2.3 gives a general definition of semantic congruence closure both in the presence of uninterpreted and interpreted symbols including AC symbols.For a single AC symbol f , ACCC(S) becomes: if As in [Kap97], we follow a rewrite-based approach for computing the AC congruence closure ACCC(S) by generating a canonical rewrite system from S. To make rewrite rules from equations in S, a total ordering on the set C of constants is extended to a total ordering on f -monomials and denoted as f .One of the main advantages of the proposed approach is the flexibility in using termination orderings on f -monomials, both from the literature on termination orderings on term rewriting systems as well as well-founded orderings (also called admissible orderings) from the literature on symbolic computation including Gröbner basis.
Using the terminology from the Gröbner basis literature, an ordering f on the set of f -monomials, is a proper subset of the multiset A (subterm property), and (ii) for any multiset B, f may or may not be included in GT (F ) depending upon an application.Two popular families of admissible orderings on monomials are degree ordering (also called degreelexicographic orderings).A degree ordering compares multisets f (A) and f (B) first on their size and in case of equal size, the largest constant in the difference In a lexicographic ordering.size does not matter: From S, a rewrite system R S is associated with S by orienting nontrivial equations in S (after deleting trivial equations t = t from S) using f : a ground equation f Given that f (A 1 ) f f (A 2 ), it follows that f (M ) f f (M ), implying the rewriting terminates.Standard notation and concepts from [BN98] are used to represent and study properties of the reflexive and transitive closure of → AC induced by R S ; the reflexive, symmetric and transitive closure of → AC is the AC congruence closure ACCC(S) of S. Below, the subscript AC is dropped from → AC and f is dropped both from S f and f whenever it is obvious from the context.
A rewrite relation → defined by R S is called terminating iff there are no infinite rewrite chains of the form → is canonical iff it is terminating and locally-confluent (and hence also terminating and confluent).A term t is in normal form iff there is no u such that t → u.
An f -monomial f (M ) is in normal form with respect to R S iff f (M ) cannot be rewritten using any rule in R S .
Define a nonstrict partial ordering on f -monomials, called the Dickson ordering, informally capturing when an f -monomial rewrites another f -monomial: It is easy to see that for any admissible ordering f , D ⊆ f .Observe that the strict subpart of this ordering, while well-founded, is not total; for example, two distinct singleton multisets (constants) { {a} } = { {b} } cannot be compared.This ordering is later used to show the termination of the completion algorithm using the Dickson's lemma, which states that any infinite subset of f -monomials on finitely many constants must include at least two f -monomials comparable by the Dickson ordering.The Dickson's lemma is a combinatorial property on k-tuples of natural numbers which states that any infinite subset A ⊆ N k must include at least two comparable k-tuples by component-wise ordering.Assuming an ordering on k constants, an f -monomial can be represented as a k-tuple corresponding to the number of times various constants occur in the f -monomial.
A rewrite system R S is called reduced iff neither the left side nor the right side of any rule in R S can be rewritten by any of the other rules in R S .
As in [KKN85], the local confluence of R S can be checked using the following constructions of superposition and critical pair.
is then the superposition of the two rules, and the critical pair is (f A rule can have a constant on its left side and a nonconstant on its right side.As stated before, a singleton constant stands for the multiset containing that constant. A critical pair is nontrivial iff the normal forms of its two components in → AC as multisets are not the same (i.e., they are not joinable).A nontrivial critical pair generates an implied equality relating distinct normal forms of its two components.
For the above two rewrite rules, normal forms of two sides are (f (a, c), a), respectively, indicating that the two rules are not locally confluent.A new derived equality is generated: It is easy to prove that if A 1 , B 1 are disjoint multisets, their critical pair is trivial.Many critical pair criteria to identify additional trivial critical pairs have been investigated and proposed in [BWK93, KMN88,BD88].
Proof.Consider a flat term f (C) rewritten in two different ways in one step using not necessarily distinct rules: ), all rules applicable to the critical pair to show its joinability, also apply, thus showing the joinability of the pair.The other direction is straightforward.The case of when at least one of the rules has a constant on its left side is trivially handled.
Using the above local confluence check, a completion procedure is designed in the classical manner; equivalently, a nondeterministic algorithm can be given as a set of inference rules [BN98].If a given rewrite system is not locally confluent, then new rules generated from nontrivial critical pairs (that are not joinable) are added until the resulting rewrite system is locally confluent.New rules can always be oriented since an ordering on f -monomials is assumed to be total.This completion algorithm is a special case of Gröbner basis algorithm on monomials built using a single AC symbol.The result of the completion algorithm is a locally confluent and terminating rewrite system for ACCC(S).
Applying the completion algorithm on the two rules in the above example, the derived equality is oriented into a new rule f (a, c) → a.The system {f (a, b) → a, f (b, c) → b, f (a, c) → a} is indeed locally-confluent.This canonical rewrite system is a presentation of the congruence closure of {f (a, b) = a, f (b, c) = b}.Using the rewrite system, membership in its congruence closure can be decided by rewriting: A simple completion algorithm is presented for the sake of completeness.It takes as input, a finite set S C of constant equations and a finite set S of equations on f -monomials, and a total ordering f on f -monomials extending a total ordering ordering on constants, and computes a reduced canonical rewrite system R f (interchangeably written as R S ) such that ACCC(S) = ACCC(S R f ), where S R f is the set of equations l = r for every l → r ∈ R f .
(1) Orient constant equations in S C into terminating rewrite rules R C using .Equivalently, using Tarjan's Union-Find data structure, for every constant c ∈ C, compute, from S C , the equivalence class [c] of constants containing c and make (2) Pick an f -monomial equation l = r ∈ T using some selection criterion (typically an equation of the smallest size) and remove it from T .Compute normal forms l, r using R f .If equal, then discard the equation, otherwise, orient into a terminating rewrite rule using f .Without any loss of generality, let the rule be l → r. (3) Generate critical pairs between l → r and every f -rule in R f , adding them to T . 3(4) Add the new rule l → r into R f ; interreduce other rules in R f using the new rule.
(i) For every rule l → r in R f whose left side l is reduced by l → r, remove l → r from R f and insert l = r in T .
(ii) If l cannot be reduced but r can be reduced, then reduce r by the new rule and generate a normal form r of the result.Replace l → r in R f by l → r .
(5) Repeat the previous three steps until the critical pairs among all pairs of rules in R f are joinable, and T becomes empty.(6) Output R f as the canonical rewrite system associated with S. Proof.By contradiction.A new rule l → r in Step 4 of the algorithm is added to R f only if no other rule can reduce it, i.e, for every rule l → r ∈ R f , l and l are noncomparable in the 3 Critical pair generation can be done incrementally using some selection criterion for pairs of rules to be considered next, instead of generating all critical pairs of the new rule with all rules in R f .Dickson ordering D .For R f to be infinite, implying the nontermination of the algorithm means that R f must include infinitely many noncomparable left sides in D , a contradiction to the Dickson's Lemma.This implies that there cannot be infinitely many noncomparable f -monomials serving as the left hand sides of rules in R f .In the interreduction step, new rules, if any, added to replace a deleted rule l → r if l can be reduced, are always smaller in f .Theorem 3.5.Given a finite set S of ground equations with a single AC symbol f and constants, and a total admissible ordering f on flattened AC terms and constants, a canonical rewrite system R f is generated by the above completion procedure, which serves as a decision procedure for ACCC(S).
The proof of the theorem is classical, typical of a correctness proof of a completion algorithm based on ensuring local confluence by adding new rules generated from superpositions whose critical pairs are not joinable.
Theorem 3.6.Given a total ordering f on f -monomials, there is a unique reduced canonical rewrite system associated with S f .Proof.By contradiction.Suppose there are two distinct reduced canonical rewrite systems R 1 and R 2 associated with S f for the same f .Pick the least rule l → r in f on which R 1 and R 2 differ; wlog, let l → r ∈ R 1 .Given that R 2 is a canonical rewrite system for S f and l = R ∈ ACCC(S f ), l and r must reduce using R 2 implying that there is a rule l → r ∈ R 2 such that l D l ; since R 1 has all the rules of R 2 smaller than l → r, l → r can be reduced in R 1 , contradicting the assumption that R 1 is reduced.If l → r ∈ R 2 where r = r but r f r, then r is not reduced implying that R 2 is not reduced.
The complexity of this specialized decision procedure has been proved to require exponential space and double exponential upper bound on time complexity [MM82].
The above completion algorithm generates a unique reduced canonical rewrite system R f for the congruence closure ACCC(S) because of interreduction of rules whenever a new rule is added to R f .R f thus serves as its unique presentation.Using the same ordering f on f -monomials; two sets S 1 , S 2 of AC ground equations have identical (modulo presentation of multisets as AC terms) reduced canonical rewrite systems R S 1 = R S 2 iff ACCC(S 1 ) = ACCC(S 2 ), thus generalizing the result for the uninterpreted case.

Congruence Closure of a Richer AC Theory with Idempotency, Nilpotency, Identity, and their combination
If an AC symbol f has additional properties such as nilpotency, idempotency and/or unit, the above completion algorithm can be easily extended by modifying the local confluence check.Along with the above discussed critical pairs from a distinct pair of rules, additional critical pairs must be considered from each rule in R f .This section explores such extensions in case of an AC symbol having idempotency, nilpotency, cancelativity and being an Abelian group.In each case, it is shown that the joinability of additional critical pairs suffices to ensure generation of a canonical rewrite system from ground equations on an AC symbol with additional semantic properties.
4.1.Idempotency.If an AC symbol f is also idempotent, implying ∀x, f (x, x) = x, the above algorithm SingleACCompletion is extended with minor modifications.In the presence of idempotency, multiple occurrences of the same constant as arguments to an idempotent AC symbol can be normalized to a single occurrence, implying that the arguments to an AC symbol can be represented as sets, instead of multisets.For any rule f (M ) → f (N ) where f is idempotent and M, N do not have duplicates, for every constant a ∈ M , a superposition f and check its joinability.This is in addition to critical pairs generated from pairs of distinct rules used in SingleACCompletion.With the addition of critical pairs generated from each rule in a rewrite system, the local confluence check becomes as follows: Lemma 4.1.An AC rewrite system R S with an idempotent AC symbol f (with f (x, x) = x) in which no rule in R S has f -monomials with duplicates, is locally confluent iff (i) the critical pair: Proof.Consider a flat term f (C), possibly with duplicates, rewritten in two different ways in one step using not necessarily distinct rules and/or f (x, x) → x.There are three cases: (ii) f (C) is rewritten in two different ways, with one step using f (x, x) → x and another using f (M ) → f (N ): An application of the idempotent rule implies that C includes a constant a, say, at least twice; the result of one step rewriting is: The proof of the third case is the same as that of Lemma 3.3 and is omitted.
The completion algorithm SingleACCompletion extends for an idempotent AC symbol by considering critical pairs for every rule in R f .Its termination proof is similar based on Dickson's lemma.Theorems 3.5 and 3.6 also extend to the idempotent case with similar related proofs.where e is a constant, typically standing for the identity of f satisfying the property that ∀x, f (x, e) = x.Below we do not assume that f (x, e) = x; that discussion is postponed to a later subsection where an AC symbol f has identity as well as is idempotent.
Lemma 4.2.An AC rewrite system R S with a nilpotent AC symbol f (with f (x, x) = e), such that no monomial in a rule in R S has duplicates, is locally confluent iff (i) the critical pair: , and (ii) for every rule f (M ) → f (N ) ∈ R S and for every constant a ∈ M , the critical pair, Proof.Consider a flat term f (C), possibly with duplicates, rewritten in two different ways in one step using not necessarily distinct rules and/or f (x, x) → e.As in the case of idempotency, there are three cases: After single step rewrites, the idempotent rule can be applied again on both sides giving f (C − { {a, a, b, b} } ∪ { {e, e} }).
(ii) f (C) is rewritten in two different ways, with one step using f (x, x) → e and another using f (M ) → f (N ): An application of the nilpotency rule implies that C includes a constant a, say, at least twice; the critical pair is: Consider two cases: a / ∈ M , implying that C still has { {a, a} } as a subset, so nilpotency can be applied to get: f (((C −M )−{ {a, a} })∪{ {e} }∪N ) from f ((C −M )∪N ); f ((C −{ {a, a} })∪{ {e} }) can be rewritten using f (M ) → f (N ) to get the same result.
The second case of a ∈ M implies there is a joinable critical pair: (f ((M − { {a} }) ∪ { {e} }), f (N )).Rewrite steps that make the above critical pair joinable, apply also on (f The third case is the same as that of Lemma 3.3 and is omitted.Lemma 4.3.An AC rewrite system R S in which an AC symbol f has an identity e (with f (x, e) = x) such that every f -monomial in R S is already normalized using f (x, e) → x, is locally confluent iff the critical pair:

19:16
Proof.Consider a flat term f (C), possibly with duplicates and the identity element e, rewritten in two different ways in one step using not necessarily distinct rules and/or f (x, e) → x.There are three cases: (i) f (C) is rewritten in two different ways in one step using f (x, e) → x to f (C − { {e} }) and f (C − { {e} }), which is trivially joinable.
(ii) f (C) is rewritten in two different ways, with one step using f (x, e) → x and another using f (M ) → f (N ): An application of the identity rule implies that C includes the identity e; the result of one step rewriting is: The first element in the critical pair can still be rewritten using The third case is the same as that of Lemma 3.3 and is omitted.
4.4.Idempotency and Identity.Consider a combination of idempotency and identity, namely a rewrite system in which an AC symbol f has identity e as well as is idempotent (with ∀x, f (x, x) → x, f (x, e) → x).In this case, it suffices to consider the additional critical pair due to idempotency since there is no additional critical pair to consider due to the identity.
Lemma 4.4.An AC rewrite system R S with an idempotent AC symbol f that also has identity e, is locally confluent iff (i) the critical pair: , and (ii) for every rule f (M ) → f (N ) ∈ R S and for every constant a ∈ M , the critical pair, (f (M ), f (N ∪ { {a} }), is joinable.
Proof.It is assumed that all monomials in R S are already normalized using f (x, x) → x, f (x, e) → x.The subpart of the proof when idempotency rule is used along with rules in R S , or the identity rule is used along with rules in R S is the same as in the proofs above for the idempotency and identity cases.The only case left is when idempotency and identity rules are both used.Consider a flat term f (C), possibly with duplicates and the identity element, rewritten in two different ways in one step using f (x, x) → x in one case and f (x, e) → x in the other case, giving the critical pair: (f (C − { {a} }), f (C − { {e} })) where wlog, a appears in duplicate in C which has also e.There are two cases: a = e, in which case, apply f (x, e) → x on the first component of the critical pair and f (x, x) → x on the second component with the result in both cases to be f (C − { {a, e} }).In case a = e, then if C has at least three e's, then the above case applies; if C has only two e's, then the critical pair is (f (C − { {e} }), f (C − { {e} })), which is trivially joinable.4.5.Nilpotency and Identity.Consider a combination of nilpotency and identity: ∀x, f (x, x) → e, f (x, e) → x.In this case, it suffices to consider the additional critical pair due to nilpotency since there is no additional critical pair to consider due to the identity.Lemma 4.5.An AC rewrite system R S with f (x, x) = e, f (x, e) = x, such that every rule in R S is normalized using f (x, x) → e, f (x, e) → x is locally confluent iff (i) the critical pair: (ii) for every rule f (M ) → f (N ) ∈ R S and for every constant a ∈ M , the critical pair, Proof.The subpart of the proof when nilpotency rule is used along with rules in R S , or the identity rule is used along with rules in R S is the same as in the proofs above for the nilpotency and identity cases.The only case left is when nilpotency and identity rules are both used.
Consider a flat term f (C), possibly with duplicates and the identity element, rewritten in two different ways in one step using f (x, x) → e in one case and f (x, e) → x in the other case, giving the critical pair: (f ((C − { {a, a} }) ∪ { {e} }), f (C − { {e} })), where wlog, a appears in duplicate in C which has also e.There are two cases: a = e, in which case, apply f (x, e) → x on the first component of the critical pair and f (x, x) → e on the second component with the result in both cases to be f (C − { {a, a, e} }).In case a = e, then if C has at least three e's, then the above case applies; if C has only two e's, then the critical pair is (f (C − { {e} }), f (C − { {e} })), which is trivially joinable.
Algorithm SingleACCompletion can be appropriately modified to include the joinability checks for additional critical pairs.The termination proof from the previous subsection extends to each of these cases and their combination.Theorems 3.5 and 3.6 generalize for each of the above cases as well.

An AC symbol with cancelation
An AC function symbols f has the cancelation property, equivalently is called cancelative iff ∀x, y, z, f (x, y) = f (x, z) =⇒ y = z.If f does not have a constant, say e serving as an identity of f (i.e., ∀x, f (x, e) = x), then y, z must be a nonempty multiset of constants for flat terms with f .In the presence of identity for f , y or z could be the empty subset, representing the identity e.
Congruence closure with cancelative function symbols can be subtle because it enables generating smaller equalities from larger equalities: from a cancelative AC f , for example, f (a, b) = f (a, c) =⇒ b = c.More interestingly, if a cancelative f does not have an identity, then the cancelative congruence closure of f (a, c) = a also includes f (b, c) = b for any constant b ∈ C; this is so because from f (a, c) = a, it follows that ∀b ∈ C, f (a, b, c) = f (a, b), giving f (b, c) = b by cancelation.This is a way to cancel a by including a common subterm on both sides so that the result after cancelation is not meaningless.
Given a finite set S of ground equations with a cancelative AC f , its congruence closure CACCC(S) is defined by the closure of the ACCC(S) with the above universal cancelative axiom, i.e., if Of course, if f has the identity e, then any of the above multisets can be the empty set representing e.
For example, the AC congruence closure of SC 1 = {f (a, a, b) = f (a, b, b)} includes all pairs of f -monomials that can be generated by adding f (a, a, b, X) = f (a, b, b, X) where X is any multiset of constants; assuming the degree ordering on f -monomials extending a > b, its with equal numbers of a and b.A canonical rewrite system associated with the cancelative congruence closure CACCC(SC 1 ) is R C = {a → b} using which each of the above pairs can be shown to be in the cancelative congruence closure; the canonical forms of the two sides in each pair above are identical.
Given a finite set S = {f after cancelation of common subterms on both sides, the cancelative congruence closure of S is contained in that of S in which f That motivates simplifying ground equations by canceling out common subterms from both sides.

Cancelativity Closed:
As a first step toward generating a cancelative congruence closure, equations are made cancelatively closed.An equation f (A) = f (B) is cancelatively closed for a cancelative AC f iff (i) if f has an identity e, then A ∩ B is the empty multiset, implying there is no subterm common among the two sides; (ii) if f does not have an identity, then A ∩ B is a singleton multiset with exactly one of A and B being a constant (i.e., singleton multiset); this captures the property that a constant can be common on both sides to avoid the meaningless term f ({ {} }).A set of equations is cancelatively closed iff every equation in the set is cancelatively closed.Similarly, a rewrite rule f (A) → f (B) is cancelatively closed if the corresponding equation f (A) = f (B) is cancelativity closed; a set of rules is cancelatively closed iff every rule in the set is cancelatively closed.5.2.Cancelative Closure of S: Given a system S of ground equations with a cancelative AC symbol f , an equivalent system S is generated from S that is cancelativity closed such that CACCC(S) = CACCC(S ) as follows: for every ground equation Running SingleACCompletion on a finite set of cancelatively closed ground equations as well as keeping new ground equations derived during the completion as cancelatively closed (such as cancelativitely closing rules before adding to the current basis in steps 2 and 3(ii)) is not sufficient to generate a canonical rewrite system for a cancelative congruence closure This is illustrated by the following example: Let Theorem 5.1.SingleACCompletion with steps 2 and 3(ii) modified to keep rules cancelativity closed does not generate a canonical rewrite system for an AC cancelative f symbol.
In a typical proof of local-confluence of rewrite rules, any term that includes both left sides of two distinct rules, are joinable when rewritten using these rules in two different ways.However, for a cancelative f , this step can generate a nontrivial cancelative superposition as follows: given two distinct rules f (A 1 ) → f (B 1 ) and f (A 2 ) → f (B 2 ), f (A 1 ∪ A 2 ) can be disjointly rewritten using the above rules and shown to be joinable; but

may not be cancelatively closed, possibly giving rise to new critical pairs (f (A
For example, from SC 2 above, joining the two equations gives a congruent pair (f (a, a, a, b, b, b), f (a, a, b, b)) that is not cancelatively closed.The pair is trivially joinable as the rules corresponding to SC 2 can be disjointly applied; however, a new congruence pair is generated because of cancelation.From f (a, a, a, b, b, b) = f (a, a, b, b), new congruences, f (a, b, b) = b and f (a, a, b) = a are generated because of cancelation and in the absence of f having an identity; in the presence of the identity e for f , only one congruence pair f (a, b) = e is generated.Consequently, orienting the two equations in SC 2 from left to right does not result in a canonical rewrite system for its cancelative congruence closure.It will be shown that with the cancelative closure of the disjoint superposition which was trivial in the absence of cancelativity, must be accounted for in the local confluence check of a rewrite system for the cancelative congruence closure.
is a canonical rewrite system assuming C = {a, b}.In case f has the identity e, then the third and fourth rules can be simplified to be f (a, b) → e.

Cancelative Disjoint Superposition: Given two distinct cancelativity closed rewrite rules
if f does not have an identity, then the terms in the critical pair cannot be f ({ {} }) and multiple critical pairs are generated by ensuring that neither term in a critical pair is f ({ {} }).Further, the cancelative closure of these critical pairs must be generated.This is illustrated above for SC 2 .In case of the example SC 3 , a cancelative disjoint superposition is generated since (f (a, b, a, c), f (c, d, b, d )) have the common subterm f (b, c) generating the critical pair (f (a, a), f (d, d )).
It is easy to see that new equations generated from cancelative disjoint superposition are in the cancelatively closed congruence closure.
and the critical pairs generated from cancelative disjoint superpositions of distinct pairs of rules in R are also joinable, then R is a canonical rewrite system for its cancelative congruence closure CACCC(S), where S is the finite set of equations corresponding to rewrite rules in R.
In a typical AC congruence relation, a sequence of derivations is of the form: In a cancelative congruence relation, however, from two congruent terms in the above sequence of derivations, say f (C j 1 ) and f (C j 2 ), by cancelation, f (C j 1 ) ↔ f (C j 2 ) can be derived by canceling a common subterm f (X) (i.e., C j 1 = C j 1 ∪X, C j 2 = C j 2 ∪X), from which another sequence of derivations is generated.Further, a cancellation free derivation of congruence of f (C j 1 ) and f (C j 2 ) is not a single step by some equation f (L) = f (R) ∈ S, but rather involves multiple steps by multiple equations in S. Without any loss of generality, a cancelation-free derivation can be rearranged so that cancelation is on two terms congruent by two different equations, say f Cancelative disjoint superposition and the associated critical pairs capture such interaction among equations.
To illustrate, consider a proof of congruence of f (a, a, b) In a proof below, it is shown that for any sequence of derivations in CACCC(S) possibly using cancelation, a new sequence of derivations in CACCC(R) can be constructed without any cancelation using additional rules generated from cancelative disjoint critical pairs.
To check whether f (A) = f (B) ∈ CACCC(R), both A and B may have to be enlarged to A , B respectively using some multiset C of constants such that A = A ∪ C, B = B ∪ C, and f (A ), f (B ) have the same canonical form using R, i.e., f (A ) ↔ f (B ) in ACCC(R).Determining how much to enlarge f (A), f (B) can however be a challenge; left-right superpositions address this challenge.
Proof.Sketch: Consider a sequence of inferences showing the congruence of f (C) ↔ * f (D) ∈ CACCC(S).In general, because of cancelation, this sequence cannot be f The following proof involves generating a cancelation-free sequence of derivations from an arbitrary sequence of derivations involving cancelation.When no cancelation is involved, then there is nothing new to construct.
Assume the sequence of inferences relating s ↔ * t employs k cancelation steps.Proof is by induction on k.
Basis k =1: s ↔ * t ∈ CACCC(S) can be decomposed into two subsequences s ↔ * s 1 without cancelation, followed by t 1 ↔ t 2 ↔ * t without cancelation.In other words, s ↔ * s 1 ∈ ACCC(S) = ACCC(R) and t 1 ↔ t 2 ↔ * t ∈ ACCC(S) = ACCC(R) where t 1 ↔ t 2 was generated by applying cancelation on two congruent terms s j 1 ↔ * s j 2 in a cancelation-free sequence of inferences s ↔ * s 1 .Without any loss of generality this sequence can be arranged so that the two congruent terms are at the end of the sequence as: s j 1 ↔ s j 3 ↔ sj 2 that includes a cancelative disjoint superposition.By assumption, the critical pairs corresponding to them are joinable, implying that there is a rewrite proof of the pair t 1 ↔ t 2 generated after cancelation.Since both cancelation-free sequences have rewrite proofs, they can be glued together using a rewrite proof of t 1 ↔ t 2 , resulting in a cancelation-free derivation.
Induction Step: The induction hypothesis is that any derivation with k cancelations can be converted into a cancelation free derivation.To prove that a derivation with k + 1 cancelations can also be converted into a cancelation free derivation, isolate the last cancelation step by breaking the original derivation with k + 1 cancelations into k + 1 subsequences.Since by the induction hypothesis, for the first k subsequences, there is a cancelation free derivation, that derivation can serve as a single cancelation-free subsequence and is linked to the k + 1 subsequence built using the (k + 1) th cancelation step.This case is the same as the k = 1 case.Using the same argument as for the k = 1 case, a cancelation free derivation is generated for these two new subsequences, which by induction hypothesis, gives a cancelation-free derivation for the original derivation with cancelation.
(1) Orient constant equations in S C into terminating rewrite rules R C using C and interreduce them.Equivalently, using a union-find data structure, for every constant c ∈ C, compute, from S C , the equivalence class [c] of constants containing c and make (3) If S f has any constant equalities, remove them from S f and update R C using them.(4) Initialize R f to be R C .
(5) Let T := S f .(6) Pick an f -monomial equation l = r ∈ T using some selection criterion (typically an equation of the smallest size) and remove it from T .Compute normal forms l, r using R f .If equal, then discard the equation.Otherwise, for each l = r ∈ CancelClose({ l = r}), (a) orient the result into a terminating rewrite rule using f ; abusing the notation and without any loss of generality, each is oriented from left to right.
(b) Generate both (classical) critical pair (similar to Step 3 in SingleACCompletion) and disjoint superposition critical pair between l → r and every rule in R f , adding them to T .5 (c) Add the new l → r ∈ into R f .(d) Interreduce other rules in R f using l → r (as in Step 4 in SingleACCompletion). (7) Repeat Step 6 until both types of critical pairs among all pairs of rules in R f are joinable, and T becomes empty.(8) Output R f as the canonical rewrite system associated with CACCC(S).
Using proofs similar to those for the correctness and termination of SingleACCompletion including using Dickson's lemma, the correctness and termination of the above algorithm can be established.Theorems 3.5 and 3.6 generalize for this case also.
Theorem 5.3.The algorithm CancelativeACCompletion terminates, i.e., in Step 4, rules to R f cannot be added infinitely often.
Example 4: Run the above algorithm on 5.4.An AC function symbol being a group operation.If an AC function symbol f has in addition to identity, a unique inverse for every element, then it belongs to an algebraic structure of an Abelian group.The completion procedure in that case becomes much simpler in contrast to the SingleACCompletion and cancelativeACCompletion discussed in the previous section, both in its behavior and complexity.Completion reduces to Gaussian elimination which can also be formulated in matrix form using Smith normal form or Hermite normal form.
Given a finite set S of ground equations with an AC f on constants satisfying the group axioms with the identity 0, its congruence closure AGCC(S) is defined by the closure of ACCC(S) with the universal group axioms, i.e., if , where −A stands for the multiset of the inverses of elements in A, i.e., if Assuming a total ordering on constants, because of the cancelation property and using properties of the inverse function, including −f (x, y) = f (−x, −y), a ground equation f (A) = f (B) can be standardized into f (A ) = f (B ) where A ∩ B = ∅ and furthermore, A consists of the positive occurrences of the largest constant in the ordering in A ∪ B whereas B has both negative and positive occurrences of constants smaller than the one in A .
From a standardized equation f (A ) = f (B ), a rewrite rule f (A ) → f (B ) is generated since A already has the largest constant on both sides of the equation.19:25 Note that the update U is implicitly used in Section 2.2 during the construction of a canonical rewrite system representing CC(S).The correctness of update U follows from the correctness of a congruence closure algorithm as given in [Kap97,BK20].Theorem 6.1.R U as defined above is a reduced canonical rewrite system for the congruence closure CC(S U ∪ {a i = b i | 1 ≤ i ≤ k}) using a total ordering C on constants, where S U is the set of equations obtained from the rewrite rules in R U .
Another update U could have been defined in which constant rewrite rules, instead of constant equations, are added to R U .
The second case is update AC when a finite set of constant rewrite rules are added to an AC canonical rewrite system R f consisting of rewrite rules on f -monomials.This case is more interesting since adding a constant equality not only changes the left side of the AC rewrite rules but due to this change, unlike in the uninterpreted case update U , the orientation of the updated rewrite rules can also change if the left side of an updated rule becomes smaller than its updated right side.This implies that new superpositions and critical pairs need to be considered; thus SingleACCompletion must be rerun.Heuristics and data structures can be developed so as to avoid repeating unnecessary work, especially if a pair of rules do not change.New constant rewrite rules generated during the update are kept track since they need to be propagated to other rewrite systems, if needed.
All rules in R f that get updated due to new constant rules are collected in the variable S. They are normalized, oriented and then their superpositions with other rules in R f as well as among themselves are recomputed (steps 7-18).
Variable T keeps track of critical pairs generated from superpositions as rules change; it also includes new equations generated from rewrite rules whose left sides are rewritten when a new rule is added; initially T is S. Variable N R C is the set of any new constant rules generated which may have to be propagated to other rewrite systems in a combination, leading to changes in them.Otherwise, if N R C remains empty, that indicates that even though R f may be different from R f , no new constant rewrite rules were generated; consequently, other rewrite systems involved in a combination are not affected.N F (l, R C ) computes a normal form of an f -monomial l using the constant rules in R C , and N F (l, R f ) computes a normal form of l using an AC rewrite system R f .N R C stores any new constant rewrite rules generated.
Updates due to new constant rules are repeated until no new constant rules are generated.
Observe that interreduction in Step 16 does not introduce any new constant rule, since if the left side of a rule already in R f gets reduced by the addition of a new rule l → r , then that rule is moved from R f to T ; if only the right side of a rule in R f gets reduced, then the original rule is not a constant rule.
The output of update AC is an updated canonical AC rewrite system R f generated from a canonical AC rewrite system R f due to constant rules in R C and the set N R C of new constant rewrite rules generated.
update AC can also be designed so that as soon as new constant equality is generated in Step 15 generating a constant rewrite rule c → d, the rewrite rule is eagerly used by moving to T , all those rules in R f whose left sides have occurrences of c.
Generation of additional constant equalities and additional critical pairs among AC rules terminates because of the Dickson's lemma, as in the case of SingleACCompletion, and the fact that there are only finitely many constants which can be possibly made equal.The correctness of update AC is patterned after the correctness of SingleACCompletion.
Input: R f : An AC canonical rewriting system on f -monomials, R C : A canonical rewriting system on constants, f : a monomial ordering on f -monomials extending C constants Output: An updated AC canonical rewrite system, new implied constant rules Interreduce other rules in R f using l → r as in step 4 of SingleACCompletion Theorem 6.2.R f as computed by the above algorithm is a canonical rewrite system for the congruence closure ACCCC(S f ∪ S C ) using a total ordering f on f -monomials extending C on constants, where S f is the set of equations obtained from the rewrite rules in R f and S C are constant equations obtained from constant rules in R C .
Proof.Sketch: If the left sides of rules in R f do not change due to R C , then R f is still a canonical rewrite system leading to R f ∪ R C being a canonical rewrite system for the congruence closure ACCCC(S f ∪ S C ).
Otherwise, all rewrite rules in R f whose left sides change due to R C are processed as equations and normalized, and critical pairs among them as well as with the rest of the rules in R f are generated as in SingleACCompletion.Completion is redone on all the modified rules, generating a new R f which may generate new constant equalities, leading to further propagation; this is kept track using a flag new.The process is repeated until R f is canonical and no new constant rules are generated.
As the reader would notice, update operations are used in the combination algorithms in Sections 7 and 8.

Computing Congruence Closure with Multiple AC symbols
The extension of the algorithms for computing congruence closure with a single AC symbol in Section 3 to multiple AC symbols is straightforward when constants are shared.Given a total ordering C on constants, for each AC symbol f , define a total well-founded admissible ordering f on f -monomials extending C .It is not necessary for nonconstant f -monomials to be comparable with nonconstant g-monomials for f = g, thus providing considerable flexibility in choosing termination orderings for computing AC ground congruence closure.
We will abuse the terminology and continue to call the AC congruence closure of a finite set S of ground equations with multiple AC symbols to be ACCC(S).Whereas the general definition of semantic congruence closure of ground equations for uninterpreted and interpreted symbols is given in Section 2.3, ACCC(S) can be obtained as follows: if . Further, for every AC symbol g = f , g(d 1 , e 1 ) = g(d 2 , e 2 ) ∈ ACCC(S), where d 1 , d 2 , e 1 , e 2 are new constants introduced for f (M 1 ), f (M 2 ), f (N 1 ), f (N 2 ), respectively, assuming they are already not constants; this purifies mixed AC terms.
It is possible to generate a combined reduced canonical rewrite system for multiple AC symbols in many different ways.One possibility is to independently generate a reduced canonical rewrite system for each f ∈ AC using the SingleACCompletion algorithm discussed above from a finite set S f of equations on f -monomials using a well-founded ordering f on f -monomials; combine the resulting reduced canonical rewrite systems for each f by propagating constant rewrite rules among them with update AC until no new constant rewrite rules are generated.
Another possibility is to successively use SingleACCompletion to generate a canonical rewrite system for each f ∈ AC; if any new constant rewrite rules are generated, propagate them first to every reduced canonical rewrite system generated so far, to obtain any new reduced canonical rewrite systems due to the propagation.This process is repeated until no new constant rewrite rules are generated, resulting in a combined reduced canonical rewrite system for all AC symbols considered so far.Only after that, S f for an AC symbol f not considered so far is processed.Below, the first option is employed as it is simpler and easier to understand as well as prove correct.
The algorithm below is divided into two parts: Steps 4-9 constitute the first part; using SingleACCompletion, a reduced canonical rewrite system R f for each AC symbol is generated after S f has been normalized using constant rules in R C .Any new constant rules generated are accumulated in the variable N R C .The new rules in N R C are then used to update R C .
If R C changes implying that new constant rules must be propagated to each R f , then the second part of the algorithm (steps 12-21) is executed.The propagation of new constant rewrite rules to an AC rewrite system R f is computed using the update AC operation presented in the previous section, possibly generating an updated canonical rewrite system R f with perhaps additional constant rules, which must be further propagated.Variable N N R C keeps track of the new constant rules during this phase.This process is repeated until N N R C becomes empty, implying no new constant rules get generated during updates.
Algorithm 2: CombinationMultAC(S, ) Input: S = S C ∪ f ∈F AC S f , a finite set of constant and ground equations over multiple AC symbols; = { C , f | f ∈ F AC }, a family of monomial orderings extending a total ordering C on constants Output: R, a canonical rewriting system representing AC congruence closure over multiple AC symbols 1 Let R C be the reduced canonical rewrite system generated from Replace constants in S f by their canonical forms using R C 6 Abusing the notation, call the normalized S f also as This repeated propagation of constant rules and subsequent recomputing of canonical AC rewrite systems eventually terminate because (i) recomputing of an updated canonical rewrite system terminates due to the Dickson's lemma, and (ii) there are only finitely many constants and no new constants are introduced during the combination; steps 11-21 in the algorithm compute this fixed point.
The termination and correctness of the combination algorithm follows from the termination and correctness of the algorithm for a single AC symbol, the fact there are finitely many new constant equalities that can be added, and update AC on each R f terminates when new constant equalities are added.The result of the combination algorithm is a finite canonical rewrite system R S = R C ∪ f ∈F AC R f , a disjoint union of sets of canonical rewrite rules on f -monomials for each AC symbol f , along with a canonical rewrite system R C consisting of constant rules such that the left sides of rules are distinct.to c + c → a + a, c + c → c + a, giving a new rule: c + a → a + a.The resulting combined reduced rewrite system is: {a * a * a * a → a, c + c → a + a, c + a → a + a, b → a}.
7.1.A Nondeterministic Version.The above combination algorithm can also be presented as an inference system; inference rules can be non-deterministically applied, dovetailing various steps in generating AC rules in different R f 's without generating a full canonical rewrite system for any R f one at a time.Constant rules can be eagerly propagated and applied everywhere as soon as they are generated, making the combination algorithm more efficient in practice, since the complexity of an AC congruence closure algorithm as well as the size of the associated canonical rewrite systems depend upon the number of constants used in the algorithm: fewer the number of constant, fewer the steps.A possible disadvantage of this view is that it becomes necessary to give correctness and termination arguments using complex proof and termination orderings (i.e., union of all f in this case) as a single object; consequently, proofs cannot be factored out across different AC symbols, sacrificing modularity.

Congruence Closure with Multiple AC and Uninterpreted symbols
The algorithm presented in the previous section to compute AC congruence closure with multiple AC symbols is combined with the congruence closure algorithm for uninterpreted symbols in Section 2.2.Similar to combining canonical rewrite systems for various AC congruence closures in the previous section, the key operation is to update various canonical rewrite systems when equalities on shared constants are generated and propagated.Since the algorithm for generating a rewrite system for congruence closure over uninterpreted symbols is of the least computational complexity in contrast to the complexity of AC congruence closure algorithms, it is always preferred to be run before running other AC congruence closure algorithms.The combination algorithm is thus centered around the congruence closure algorithm for the uninterpreted symbols.
In the combination algorithm below, CC stands for the congruence closure algorithm on constant equations S C and uninterpreted ground equations S U , using a total ordering C on constants and U , an ordering in which uninterpreted function symbols are bigger than constants in C. R U , the output of CC, is a reduced ground canonical rewrite system representing the congruence closure of S C ∪ S U .R C stands for the constant rules in R U .
For every f ∈ AC, a finite set S f of equations on f -monomials is successively picked; constants in the equations are replaced by their canonical forms using R C and the rewrite rules are made from the resulting equations using a total admissible ordering f on fmonomials.SingleACCompletion algorithm is used to generate a canonical AC rewrite system R f from S f using a monomial ordering f .Variable N R C accumulates the constant rules generated for each f in its respective reduced canonical rewrite system R f (steps 5-10).
The function update C is used to update the canonical constant rewrite system R C , using any new constant rules in N R C .If the update results in a new canonical constant rewrite system, then update U updates the ground canonical rewrite system for the congruence closure of uninterpreted equations, possibly leading to new constant equalities and associated rewrite rules.A flag variable new keeps track of whether any new constant rules have been generated which must be propagated.
Steps 14-26 perform the propagation of new constant rewrite rules to a reduced canonical rewrite system R f for each AC symbol f by invoking update AC .If new constant rewrite a finite set S f of f -monomial equations in which at least one f -monomial is not a constant, and total orderings U and f on f -monomials extending a total ordering C on constants in C.
The termination and correctness proofs of the above algorithm are factored: they follow from the termination and correctness of the algorithm for a single AC symbol, update U .update AC and the fact there are finitely many new constant equalities that can be added.Further the outputs in each case are reduced canonical rewrite systems.
The result is a modular combination, whose termination and correctness is established in terms of the termination and correctness of its various components: (i) the termination and correctness of algorithms for generating canonical rewrite systems from ground equations in a single AC symbol, for each AC symbol in F AC , and their combination together with each other, and (ii) the termination and correctness of congruence closure over uninterpreted symbols and its combination with the AC congruence closure for multiple AC symbols, and (iii) there are only finitely many constants being shared and finitely many possibly equalities on the shared constants.
The result of the above algorithm is a finite reduced canonical rewrite system from S, R S = R C ∪ R U ∪ f ∈F AC R f , a disjoint union of sets of reduced canonical rewrite rules on f -monomials for each AC symbol f , along with a canonical rewrite system R C consisting of constant rules and R U consisting of flat rules on uninterpreted symbols, such that the left sides of rules are distinct and the right sides are reduced.R S is unique in the extended signature assuming a family of total admissible orderings on f -monomials for every f ∈ F AC and making uninterpreted symbols h ∈ U extending a total ordering on constant if R C , R U are reduced, SingleACCompletion generates a reduced AC canonical rewrite system and update U as well as update AC ensure that the canonical rewrite system generated by them are also reduced.
Theorem 8.1.Given a set S of ground equations, the above algorithm generates a reduced canonical rewrite system R S on the extended signature such that R where each of R C , R U , R f is a reduced canonical rewrite system using a set of total admissible monomial orderings f on f -monomials, which extend orderings U on uninterpreted symbols and > on constants as defined above, and ACCC(R S ), with rules in R S viewed as equations, is ACCC(S) when restricted on the original signature.Further, for this given set of orderings, U and { f | f ∈ F AC }, R S is unique for S in the extended signature.
The proof follows from the respective proofs of each of the component algorithm and is routine.
As stated in the previous section on the combination algorithm for multiple AC symbols, a nondeterministic version can be formulated in which various inference steps are interleaved along with any new constant equalities generated to reduce constants appearing in other R f eagerly, instead of having to complete an AC rewrite system for each AC symbol.Correctness and termination proofs are however more complicated requiring complex orderings.
If any AC symbol f has additional properties such as idempotency, nilpotency, identity, cancelativity, or being a group operation, and various combinations (see discussion in Sections 4 and 5), the corresponding reduced canonical R f generated from the specialized extensions of SingleACCompletion algorithms discussed in Sections 4 and 5 can be used and the above results extend.9. Pure Lexicographic Orderings: Constants bigger than Nonconstant Terms So far, it is required that constant symbols are smaller in monomial orderings than nonconstant terms for any function symbol, be it AC or nonAC.This restriction can be relaxed.In case of uninterpreted (non-AC) symbols, this is achieved by introducing a new constant symbol as already done in Kapur's congruence closure [Kap97].A similar approach works in case of nonconstant terms with multiple AC symbols.
Using a monomial ordering in which a constant is bigger than a nonconstant monomial, the above combination algorithm for generating a canonical rewrite system in the presence of multiple AC symbols could produce at least two canonical rewrite subsystems for two different AC symbols f and g such that R f has a rule c → f (A) and R g has another rule c → g(B), with A and B of size > 1 (implying that the right sides are nonconstants).Then, c can possibly have either a canonical form with f as its outermost symbol or g as its outermost symbol.Call this case to be that of a shared constant possibly having multiple distinct normal forms in different AC symbols.This case must also be considered along with the propagation of constant rewrite rules.
One way to address the above case is by introducing a new constant u, making c > u; f and g are extended to include monomials in which u appears with the constraint that f → u in R g may violate the local confluence of R f and R g since reorientation of these equations may result in superpositions with the left sides of other rules.New superpositions are generated in R f as well as R g , possibly leading to new rules including new constant rules.After local confluence is restored, the result is new R f and R g with u being the canonical form of c.
To illustrate, consider S = {c = a + b, c = a * b} with AC +, * .For an ordering c > b > a with both + and * being pure lexicographic, R + = {c → a + b}, R * = {c → a * b}.These reduced canonical rewrite systems have a shared constant c with two different normal forms implying that R + ∪ R * is not canonical.Introduce a new constant u with c > b > a > u (other orderings including c > u > b > a or c > u > a > b are also possible); make R S = {a + b → u, a * b → u, c → u}, which is reduced canonical in the extended signature; however, it is not even locally confluent when expressed in the original signature.A choice about whether the canonical form of c is an f -monomial or a g-monomial is not made as a part of this algorithm since nonconstant f -monomials and g-monomials are noncomparable.
Other cases, for instance, the one in which c → f (A) in R f but g(B) → c in R g , can be considered in a similar way by introducing a new constant u, to preserve modularity by not including mixed rules on f monomials and g monomials.
Only finitely many new constants need to be introduced in this construction; their number depends upon the number of canonical forms a constant can have with different outermost AC symbols.

Examples
The proposed algorithms are illustrated using several examples which are mostly picked from the above cited literature with the goal of not only to show how the proposed algorithms work, but also contrast them with the algorithms reported in the literature.
Different total orderings on constants are used to illustrate how different canonical forms can be generated.Consider a total ordering f g a b u 2 u 1 .R C = {1.u 2 → u 1 } normalizes the uninterpreted equation and it is oriented as: R U = {2.g(u 1 ) → u 1 }.
To generate a reduced canonical rewrite system for AC f -terms, an admissible ordering on f -terms must be chosen.The degree-lexicographic ordering on monomials will be used for simplicity: includes a constant bigger than every constant in M 2 − M 1 .f -equations are normalized using rules 1 and 2, and are oriented as: {3.f (a, c) → a, 4. f (c, u 1 ) → b, 5. f (b, c) → u 1 }.
Applying the SingleACCompletion algorithm, the superposition between rules 3, 5 is f (a, b, c) with the critical pair: (f (a, b), f (a, u 1 )), leading to a rewrite rule 6. f (a, b) → f (a, u 1 ); the superposition between the rules 3, 4 is f (a, c, u 1 ) with the critical pair: (f (a, u 1 ), f (a, b)) which is trivial by rule 6.The superposition between the rules 4, 5 is f (b, c, u 1 ) with the critical pair: (f (b, b), f (u 1 , u 1 )) giving: 7. f (b, b) → f (u 1 , u 1 ).The rewrite system R f = {3, 4, 5, 6, 7} is a reduced canonical rewrite system for S f .R S = {1, 2} ∪ R f is a reduced canonical rewrite system associated with the AC congruence closure of the input and serves as its decision procedure.
In the original signature, the above rewrite system R S is: {g(f (b, c))) → f (b, c), f (a, c) → a, f (b, c, c) → b, f (a, b) → f (a, b, c), f (b, b) → f (b, b, c, c)} with 5 being trivial.The reader would observe this rewrite system is locally confluent but not terminating.
Example 10: This example illustrates interaction between congruence closures over uninterpreted symbols and AC symbols.symbol to a constant, and a set of equations on pure AC terms in a single AC symbol possibly with additional semantic properties.Such decomposition and factoring enable using congruence closure algorithms for each of the pure subproblems on a single AC symbol and/or uninterpreted symbols independently, which propagate equalities on shared constants.Once the propagation of constant equalities stabilizes (reaches a fixed point), the result is (i) a unique reduced canonical rewrite system for each subproblem and finally, (ii) a unique reduced canonical rewrite system for the congruence closure of a finite set of ground equations over multiple AC symbols and uninterpreted symbols.The algorithms extend easily when AC symbols have additional properties such as idempotency, identity, nilpotency, cancelativity as well as their combination, as well as an AC symbol satisfying the properties of a group.
Unlike previous proposals based on the Knuth-Bendix completion procedure and its generalizations to AC theories and other equational theories, the proposed algorithms do not need to use extensions rules, AC/E unification or AC/E compatible termination ordering on arbitrary terms.Instead, the proposed framework provides immense flexibility in using different termination orderings for terms in different AC symbols and uninterpreted symbols.
The modularity of the algorithms leads to easier and simpler correctness and termination proofs in contrast to those in [BTV03,Mar96].The complexity of the procedure is governed by the complexity of generating a canonical rewrite system for AC ground equations on constants.
The proposed algorithm is a direct generalization of Kapur's algorithm for the uninterpreted case, which has been shown to be efficiently integrated into SMT solvers including BarcelogicTools [NO07].We believe that the AC congruence closure can also be effectively integrated into SMT solvers.Unlike other proposals, the proposed algorithm neither uses specialized AC compatible orderings on nonground terms nor extension rules often needed in AC/E completion algorithms and AC/E-unification, thus avoiding explosion of possible critical pairs for consideration.
By-products of this research are new insights into combination algorithms for ground canonical rewrite systems-(i) making orderings on ground terms more flexible and general in which constants are allowed to be greater than nonconstant terms as in orderings for Gröbner basis algorithms, as well as (ii) a new kind of superpositions to incorporate semantic properties such as cancelativity, which can be viewed as a superposition between the left side of a rule with the right side of another rule.An instantiation of the proposed combination framework to an AC symbol with identity and another AC symbol enriched with the properties of an Abelian group, leads to a new way to view a Gröbner basis algorithm for polynomial ideals over integers, as a combination congruence closure algorithm.Canonical bases of polynomial ideals over the integers (and more general rings with zero divisors) on extended signature can be computed for which rewriting (simplification) of a polynomial by another polynomial, when viewed on the original signature, need not terminate, opening possible new research directions.
Integration of additional semantic properties of AC symbols is done on a case by case basis by modifying critical pair constructions but avoiding extension rules or complex AC termination orderings compatible with these semantic properties.Using the proposed framework, other types of combinations of congruence closure algorithms in the presence of other semantic properties relating different AC symbols may be possible as well.A general

2. 1 .
Congruence Relations.Definition 2.1.Given a finite set S = {a i = b i | 1 ≤ i ≤ m} of ground equations where a i , b i ∈ GT (F ), the congruence closure CC(S) is inductively defined as follows: (i) S ⊆ CC(S), (ii) for every a ∈ GT (F ), a = a ∈ CC(S), (iii) if a = b ∈ CC(S), b = a ∈ CC(S), (iv) if a = b and b = c ∈ CC(S), a = c ∈ CC(S), and (v) for every nonconstant The rewriting relation induced by this rewrite rule is defined below.Definition 3.1.A flattened term f (M ) is rewritten in one step, denoted by → AC (or simply →), using a rule f (A 1 ) → f (A 2 ) to f (M ) iff A 1 ⊆ M and M = (M − A 1 ) ∪ A 2 , where −, ∪ are operations on multisets.

Example 1 :
As a simple example, consider ground equations on an AC symbol * : 1. a * a * b = a * a, 2. a * b * b = b * b with the ordering a > b on constants.They are oriented from left to right as terminating rewrite rules (using either total degree ordering or pure lexicographic ordering).The overlap of the two left sides gives the superposition a * a * b * b, giving the critical pair: (a * a * b, a * b * b); their normal forms are:(a * a, b * b).The new rule is oriented as: 3. a * a → b * b.This rule simplifies rule 1 to 1 .b * b * b → b * b.The completion algorithm terminates with 1 , 2, 3 as the canonical rewrite system.Theorem 3.4.The algorithm SingleACCompletion terminates, i.e., in Step 4, rules to R f cannot be added infinitely often.
For an example, from f (a, b) → c with the idempotent f , the superpositions are f (a, a, b) and f (a, b, b), leading to the critical pairs: (f (a, c), f (a, b)) and (f (b, c), f (a, b)), respectively, which further reduce to (f (a, c), c) and (f (b, c), c), respectively.
(i) f (C) is rewritten in two different ways in one step using f (x, x) → x to f (C − { {a} }) and f (C − { {b} }) with a = b: The idempotent rule can be applied again on both sides giving f (C − { {a, b} }) since C − { {a} } includes { {b, b} } and C − { {b} } includes { {a, a} }.

Example 2 :
Revisiting Example 1 from the previous section with the additional assumption that * is idempotent, the equations simplify to: a * b = a, a * b = b.When oriented into terminating rewrite rules, a * b → a, a * b → b generating a superposition a * b with the associated critical pair: (a, b) leading to a new rule: a → b, assuming a > b.This rule simplifies all the other two rules, leading to a canonical rewrite system {a → b}.

Example 3 :
Revisiting Example 1 from the previous section and assuming * to be nilpotent, the above ground equations simplify to e * b = e, e * a = e.The superposition from the terminating rules corresponding to the above equations is: a * b * e leading to the critical pair: (a * e, b * e) whose two terms have the same normal form e. The rewrite system {e * a → e, e * b → e} is reduced canonical.4.3.Identity.If f has identity, say e satisfying f (x, e) = x, no additional critical pair is needed since from every rule f (M ) → f (N ), (f (N ∪ { {e} }), f (M )) are trivially joinable.
, then for any common nonempty multisubset C of A and B and assuming neither A − C nor B − C become empty causing f (A − C) or f (B − C) to be meaningless, f (A−C) = f (B −C) ∈ CACCC(S).It also follows that for any nonempty multiset D, given that f (A ∪ D) = f (B ∪ D) ∈ CACCC(S), every equation obtained after canceling every possible nonempty common multisubset G such that neither f canonical rewrite system is R = {f (a, a, b) → f (a, b, b)}.If f is assumed to be also cancelative, the cancelative congruence closure then includes a = b along with the above congruences, since f (a, f (a, b)) = f (b, f (a, b)) =⇒ a = b by cancelation; from a = b, one gets many other congruences including For examples, f (a, b) = f (c, d) is cancelativity closed irrespective of whether f has an identity or not; f (a, b) = a is not cancelativity closed if f has an identity, in which case a can be canceled from both sides of the equation resulting in b = e; however, f (a, b) = a is cancelativity closed in the absence of f having an identity, but f (a, b, b) = f (a, b) is not cancelatively closed since either a or b can be canceled without making the resulting equation meaningless.
one of the sides possibly being the identity; (iii) otherwise, if f does not have an identity and (a) neither B − A nor A − B are the empty sets, then f(A − B) = f (B − A) is included in S , (b) if A − B or B − A is the empty set, then for every constant c ∈ C, a new equation f ((A − B) ∪ {c}) = f ((B − A) ∪ {c}) is included in S .Clearly, CACCC(S) ⊆ CACCC(S ); using cancelativity, it also follows that CACCC(S ) ⊆ CASCC(S).Let CancelClose(S) be the set of cancelatively closed equations generated from S. For example, CancelClose({f (a, a, a) = f (b, b)}) = {f (a, a, a) = f (b, b)}, CancelClose({f (a, b, b) = f (a, b, a)}) = {b = a}, and CancelClose({f (a, a, a, b, b) = f (a, b, b, b)} = {f (a, a) = b} irrespective of whether f has the identity or not.If f has the identity e, then CancelClose({f (a, b) = a}) = {b = e}, but in the absence of f having an identity, CancelClose({f (a, b) = a}) = {f (b, c) = c | c ∈ C} which will include f (a, b) = a, f (b, b) = b and for any other constant c ∈ C, f (b, c) = c.
SC 2 = {f (a, a, a) = f (b, b), f (b, b, b) = f (a, a).}.They are cancelatively closed since the two sides of each equation do not have any common subterms.Orienting the above equations from left to right, generates a canonical rewrite system which is also cancelativity closed; however, the rewrite system does not represent a cancelative congruence closure of SC 2 since f (a, a, b) = a as well as f (a, b, b) = b are in the cancelative congruence closure (since f (a, a, a, b) = f (b, b, b) = f (a, a) as well as f (b, b, b, a) = f (a, a, a) = f (b, b)) but they have distinct normal forms with respect to the rules generated from SC 2 by orienting the equations in SC 2 from left to right.The rules obtained from orienting the equations in SC 2 from left to right are non-overlapping, so SingleACCompletion does not generate any new rule.
But instead it is broken into a chain of such subsequences where subsequences are connected using the cancelation inference rule.For illustration, for SC 3 , a possible inference sequence off (a, a, b) ↔ a is a chain of subsequence f (a, a, a, b) ↔ f (b, b, b) ↔ f (a,a) in which the first and second inferences are due to the first equation and second equation, respectively, but then there is another subsequence f (a, a, b) ↔ a, connected to the previous subsequence by cancelation on two congruent terms f (a, a, a, b) ↔ f (a, a), leading to a sequence of derivations: f (a, a, a, b) ↔ f (b, b, b) ↔ f (a, a), f (a, a, b) ↔ a.Using the rule f (a, a, b) → a generated from cancelative disjoint superposition from rules 1 and 2, a cancelative-free derivation of f (a, a, b) ↔ a can be generated.
where f is cancelative, using the degree ordering on f -terms extending the constant ordering a > b > c > d > d .Both the rules are cancelatively closed.Critical pairs among them are generated: the classical critical pair construction from the two rules is 3. f (b, b, d ) → f (c, c, d); cancelative disjointly superposition constructions gives: 4. f (a, a) → f (d, d .The resulting reduced canonical rewrite system for the AC cancelative congruence closure of SC 3 Let S = {g(b) = a, g(d) = c, a * c = c, b * c = b, a * b = d} where g is uninterpreted and * is AC.Let * Applying the steps of the algorithm, R U , the congruence closure over uninterpreted symbols, is {g(b) → a, g(d) → c}, Completion on the * -equations using degree lexicographic ordering, oriented as {a * c → c, b * c → b, a * b → d}, generates an implied constant equality b = d from the critical pair of a * c → c, b * c → b.Using the rewrite rule b → d, the AC rewrite system reduces to: R * = {a * c → c, c * d → d, a * d → d}, which is canonical.The implied constant rule b → d is added to R C : {b → d} and is also propagated to R U , which makes the left sides of g(b) → a and g(d) → c equal, generating another implied constant rule a → c which is added to R C : {a → c, b → d}.R U becomes {g(d) → c}.The implied constant rule is propagated to the AC rewrite system on * .R C normalizes R * to {c * c → c, c * d → d}.
Nilpotency.Consider a nilpotent AC symbol f with the property that ∀x, f (x, x) = e