J. Symbolic Computation (1994) 11, 1{43
Combining Symbolic Constraint Solvers on Algebraic Domains Helene Kirchner and Christophe Ringeissen y
CRIN-CNRS & INRIA-Lorraine BP 239 54506 Vanduvre-les-Nancy Cedex France e-mail: fHelene.Kirchner,
[email protected] (Received ) In the context of constraint logic programming and theorem proving, the development of constraint solvers on algebraic domains and their combination is of prime interest. As an example, a constraint solver in nite algebras is presented for a constraint language including for instance equations, disequations and inequations. By extending techniques used for the combination of uni cation in disjoint equational theories, we show how to combine constraint solvers on dierent algebraic domains that may share some constant symbols. We illustrate this technique by combining the constraint solver in nite algebras with other uni cation algorithms, and with another constraint solver on a dierent nite algebra.
1. Introduction
In the context of logic programming and deduction with constraints, the need for combining constraint solving in speci c theories frequently appears. For instance, in rst-order theorem proving, free constants and function symbols are generated during skolemization and it is known that uni cation with constants or general uni cation, where new constants or free function symbols are added to the signature, must be carefully distinguished from elementary uni cation (Burckert (1986)). Combination problems also appear in constraint logic programming, when dierent kinds of constraints coexist and must be solved in appropriate domains for which a constraint solving process is already available. We focus in this paper on the combination of symbolic constraint solvers that compute solutions which are substitutions de ned on an appropriate set of terms. Uni cation in an equational theory is a special case of symbolic constraint solving, for which the combination problem has already been addressed and can be stated as follows: given two uni cation algorithms in two (consistent) equational theories E1 y This work is partially supported by the Esprit Basic Research working group 6028, CCL. 0747{7171/90/000000 + 00 $03.00/0
c 1994 Academic Press Limited
2
Helene Kirchner and Christophe Ringeissen
on a set of terms T (F1; X ) and E2 on T (F2 ; X ), how to nd a uni cation procedure for E1 [ E2 on T (F1 [ F2; X )? Combining uni cation algorithms was initiated in Kirchner (1985), Herold (1986), Tiden (1986), Yelick (1987) where syntactic conditions on the axioms of the theories to be combined were assumed. Combination of arbitrary theories with disjoint sets of symbols is considered in Schmidt-Schau (1989), Boudet (1990) and in Baader & Schulz (1992). The general idea of uni cation in a combination of theories consists in rst breaking an equational problem into sub-problems that can be solved in one component of the combination. The main diculty is then to recombine the obtained solutions to get a complete set of solutions in the union of theories. In this paper which extends Ringeissen (1992), Kirchner & Ringeissen (1992), we generalize the uni cation technique to constraint solvers on algebraic domains possibly sharing some constant symbols. We provide for such combination the construction of a combined constraint language and a standard interpretation in which solving a pure constraint is equivalent to solving it in one component of the combination. Recombining solutions assumes that each constraint solver has the ability to compute a complete set of symbolic solutions for an extended constraint problem with a linear restriction, that is an ordering on variables. Shared constants in the signatures are taken into account through instantiations of variables by all shared constants. The technique is illustrated rst by the combination of a constraint solver in a nite algebra with another uni cation algorithm that may be a uni cation algorithm in any equational theory, including the empty theory, and second by the combination of two constraint solvers in dierent nite algebras. In this context, we are faced to several problems:
The nite algebras we want to consider are not in general quotient term algebras:
they are de ned by their carrier and some functions, but do not have an equational presentation. However a nite algebra can be embedded into a primal algebra presented, up to an isomorphism, by a nite set of equational axioms. A uni cation algorithm for primal algebras was proposed in (Buttner et al. 1990). We generalize its proof to a large class of constraints. Using this solver, a constraint is transformed into an equational problem with the same set of solutions. The existence, for any constraint, of a solved form expressed by equations is a crucial property for recombining the solutions. In order to combine this constraint solver in primal algebras with another one, it must be extended to solve constraints with free constants and a linear restriction on variables. This is performed using the notion of frozen variable and an algorithm for frozen variable elimination. Combining two constraint solvers in nite algebras with a non-empty intersection of values, needs to allow shared constants in their signatures and to use the combination techniques developed in the non-disjoint case. Moreover some improvements may be proposed to decrease the non-determinism of the algorithm in the context of primal algebras.
The paper is organized as follows: Section 2 is devoted to constraint languages; the constraints we want to solve are de ned together with their solutions. These notions are then illustrated by a constraint language in primal algebras and its solver in Section 3. Section 4 addresses the problem of combining constraint solvers. First, the notion of
Combining Symbolic Constraint Solvers on Algebraic Domains
3
combined constraint language is de ned. Second, the techniques used for combining uni cation algorithms are extended to combine constraint languages when they are disjoint, then sharing constants. In Section 5, we apply these results to the constraint solver in primal algebras and we show how it must be extended. Two applications are considered: the combination with a uni cation algorithm and the combination of two primal algebras constraint solvers.
2. Constraint languages
In this rst part of the paper, we adopt a general de nition of a constraint language and its solver, and we study the class of so-called primal languages where constraints are solved in primal algebras. Our notations are consistent with the surveys of Dershowitz & Jouannaud (1990) and Jouannaud & Kirchner (1991). A rst-order signature is given by a set of sorts S , a set of function symbols F and a set of predicate symbols P . Nullary function symbols in F are called constants. A rst-order algebraic -structure A is given by - a carrier A which is a union of non-empty sets (As )s2S - for each ranked function symbol f : s1 ; : : :; sm 7! s in F , a function fA de ned from As : : : Asm to As, - for each ranked predicate symbol p : s1 ; : : :; sm except = in P , a relation pA on As : : : Asm . Whenever contains the predicate symbol =, it is interpreted as the equality relation in A. When there is no other predicate than equality, a -structure is called a (S ; F )-algebra. An algebra is nite when its carrier and its set of functions are both nite. Given a set X of variables, T (S ; F ; X ) is the free (S ; F )-algebra over X , whose carrier is the set of terms T(S ; F ; X ). S may be omitted when reduced to one sort. The terms tj! , t[s]! and t[! - s] denote respectively the subterm of t at the position !, the term t with the subterm s at the position ! and the replacement in t of tj! by s. The symbol of t occurring at the position ! (resp. the top symbol of t) are written t(!) (resp. t()). V (t) denotes the set of variables occurring in the term t. T (S ; F ) is the initial (S ; F )-algebra of ground terms (i.e. terms t such that V (t) = ;). Given a set of equational axioms E and the generated congruence =E , the free quotient (S ; F )-algebra is denoted T (S ; F ; X )==E . An assignment is a mapping from X to A; it uniquely extends to an homomorphism from T (S ; F ; X ) to A. The restriction of an assignment to a set of variables V X is denoted by jV . This notation is extended to sets of assignments. The set of all assignments is denoted by ASSAX or ASSA , when X is clear from the context. A substitution is an assignment from X to T (S ; F ; X ) and uniquely extends to an endomorphism of T (S ; F ; X ). We use letters ; ; ; ; : : : to denote substitutions and do not distinguish and . We call domain of the substitution the set of variables Dom() = fxjx 2 X and (x) 6= xg that are not mapped to themselves, range of the set of terms Ran() = [x2Dom() (x) and variable range of the set of variables VRan() = [x2Dom() V ((x)). Composition of substitutions is denoted by . A substitution is idempotent if = . The set of substitutions is called SUBST. An equational axiom (t = t0) (resp. an atomic formula p(t1 ; : : :; tm )) holds in A if for any 2 ASSAX , (t) = (t0 ) (resp. pA ((t1); : : :; (tm ))). This is denoted A j= (t = t0 ) (resp. A j= p(t1; : : :; tm )) or simply t =A t0 . The equivalence relation =A on terms is called A-equality. To each -structure A, we can associate the set of equational axioms 1
1
4
Helene Kirchner and Christophe Ringeissen
T h(A) that hold in A. Given a set of axioms E, a -structure in which each axiom of E
holds, is a model of E. The de nition of constraint languages adopted in this paper is slightly restricted with respect to those given in Smolka (1989), (Kirchner et al. 1990). We do not allow negation in our languages, but instead consider disequality 6= as a predicate to construct atomic constraints. In the same way, any predicate p may have a negative form :p in the predicate set. Note that constraints are syntactically distinguished by a question mark exponent on predicates. Definition 2.1. Let = (S ; F ; P ) be a rst-order signature, a constraint language CLA[; X ] is given by:
A set of constraints C[; X ] de ned as the smallest set such that { T; F 2 C[; X ], { p (t ; : : :; tm ) 2 C[; X ] if p 2 P and t ; : : :; tm 2 T (S ; F ; X ), { c ^ c0 2 C[; X ] if c; c0 2 C[; X ]. { (9x : c) 2 C[; X ] if c 2 C[; X ]. The set V (c) of free variables of the constraint c is de ned as follows: { V (T) = V (F) = ;, { V (p (t ; : : :; tm )) = Smi V (ti ), { V (c ^ c0 ) = V (c) [ V (c0 ), { V (9x : c) = V (c)nfxg. An interpretation A, which is a -structure, and a solution mapping that associates ?
1
?
1
1
=1
to each constraint the set of assignments SolA (c) de ned as follows: { SolA (T) = ASSAX , SolA (F) = ;, { SolA (p? (t1 ; : : :; tm )) = f 2 ASSAX j pA ((t1 ); : : :; (tm ))g, { SolA (c ^ c0 ) = SolA (c) \ SolA (c0). { SolA (9x : c) = f 2 ASSAX j 9 2 ASSAX ; jXnfxg = jXnfxg ; 2 SolA (c)g. An assignment in SolA (c) is a solution of c in A. A constraint c is said valid in CLA [; X ], written A j= c, if any assignment is a solution of c in A.
Two constraints c and c0 are equivalent if SolA (c) = SolA (c0 ). Any constraint in CLA [; X ] is equivalent to (9~x : c) which is an abbreviation for (9x1 ; : : :; xm : c), where c is a quanti er-free constraint and ~x is a (possibly empty) set of variables, since we make no dierence between 9x1; x2 and 9x2 ; x1. In this paper, we focus our interest on some particular constraint languages in which the -structure A is term-generated, i.e. each element of its carrier is the interpretation of a term in T (S ; F ). In term-generated structures, it is sucient to deal with symbolic solutions that describe sets of solutions. Definition 2.2. The set of symbolic solutions of a CLA[; X ]-constraint c, denoted by SSA (c), is de ned as follows:
SSA (T) = SUBST, SSA (F) = ;,
Combining Symbolic Constraint Solvers on Algebraic Domains
5
SSA (p (t 0; : : :; tm )) = f 2 SUBST j A j= p((t ); : : :; (tm ))g, SSA (c ^ c ) = SSA (c) \ SSA (c0 ), SSA (9x : c) = f 2 SUBST j 9 2 SUBST; jXnfxg = jXnfxg and 2 SSA (c)g. ?
1
1
With this de nition, SSA (t 6=? t0) = f 2 SUBST j A j= (t) 6= (t0 )g contains all such that all instances of (t) and (t0 ) are dierent. If instead of considering disequality as an atomic constraint, we had introduced negation and a negated constraint :(t =? t0 ), with SSA (:(t =? t0 )) = SUBST nSSA (t =? t0), as for instance in Baader & Schulz (1993), we would have obtained a dierent set, containing all such that there is an assignment which maps (t) and (t0 ) onto two dierent elements in A. The approach adopted here is justi ed by the following properties: if A is a term-generated structure, then solutions and symbolic solutions are related. More precisely, SSA (c) represents SolA (c) for any constraint c 2 CLA [; X ], in the sense that SolA (c) = f j 2 ASSAX ; 2 SSA (c)g where denotes the assignment de ned as follows: 8x 2 X ; (x) = ((x)): Then, SolA (c) = ; if and only if SSA (c) = ;. These properties would not hold anymore if negation of constraints were allowed. Substitutions are partially ordered by subsumption ordering, as follows: a substitution is an CLA [; X ]-instance on V X of a substitution , written VA (and read as more general with respect to A than on V ), if there exists some substitution such that 8x 2 V; A j= (x) = ((x)). We take advantage of the fact that any instance of a symbolic solution is still a symbolic solution, to keep a set of symbolic solutions minimal with respect to instantiation. Definition 2.3. A set of substitutions is a complete set of solutions of the CLA [; X ]constraint c, denoted by CSSA (c), if
1. 8 2 CSSA (c); Dom() \ VRan() = ;. 2. CSSA (c) SSA (c). 3. 8 2 SSA (c); 9 2 CSSA (c) such that AV (c) . When two substitutions of CSSA (c) cannot be compared with AV (c) , the complete set of solutions CSSA (c) is minimal. If such a set is reduced to one element, this element is denoted mgsA (c). The set SSA (c) of symbolic solutions of the CLA [; X ]-constraint c is a complete set of solutions. V Given an idempotent substitution = fxk 7! tk gk2K , ^ denotes the tree-solved form ( k2K xk =? tk ) such that fg is a CSSA (^). Two examples of constraint languages are considered in this paper:
A mono-sorted equational presentation (S ; F ; E), where S = fs g and E is a set of equational axioms, de nes an equational constraint language CLE [fs g; F ; f=g; X ] where atomic constraints are equations over T (S ; F ; X ). The standard interpretation is the quotient algebra T (S ; F ; X )==E . A symbolic solution of a constraint c is an E -uni er. A complete set of solutions of a CLE [fsg; F ; f=g; X ]-constraint c is denoted CSSE (c) and called also a complete set of E -uni ers. For instance, if
6
Helene Kirchner and Christophe Ringeissen
F = fa; f g, X = fv; x; yg and E consists of the associativity and commutativity axioms for f, then (f(v; x) =? f(a; f(x; y))) is an equational constraint. A nite (S ; F )-algebra A, together with a set of relations PA on A, de nes a constraint language CLA [(S ; F ; P ); X ] where A is the interpretation of interest. For simplicity, we assume that the nite functions de ned on A are all de ned on the same set and so S is reduced to one sort s and may be omitted. We describe in the next subsections how constraints are solved in this language by embedding it a primal constraint language CLAF [; X ] whose interpretation A is isomorphic to a quotient term algebra.
3. A constraint solver in primal algebras
Finite algebras provide valuable domains for constraint logic programming. Uni cation in this context has attracted considerable interest for its applications: it is of practical relevance for manipulating hardware descriptions and solving formulas of propositional calculus; its implementation in constraint logic programming languages allows handling Boolean constraints (CHIP, Prolog III), sets constraints (CAL) and constraints on nite algebraic domains (Prolog-XT). A nite algebra can be given a richer structure of primal algebra, in which every nitary function on the carrier can be composed from basic operations. The 2-elements Boolean algebra is the simplest example of primal algebra, since every truth-function can be expressed in terms of the basic connectives, for instance ^ (and) and (not). Other examples are nite elds, in particular modular arithmetic, Post algebras or matrix rings over nite elds. The interesting feature of these algebras is that matching, uni cation and disuni cation are equivalent and unitary. A survey on Boolean uni cation can be found in Martin & Nipkow (1989) and the uni cation problem in the class of primal algebras and in their varieties is extensively studied in Nipkow (1990). Implementations are described in Ridoux & Tonneau (1990), Rauzy (1990) for Boolean uni cation (Buttner & Simonis (1987)), and in (Buttner et al. 1990), Ringeissen (1990) for uni cation in nite algebras. After describing how to extend a nite algebra into a primal algebra equationally presented and !-complete, constraint solving in primal algebras is studied. Some of the results presented in this section, especially the axiomatization of primal algebras and the constraint solver, have similarities with already published works. These relations are mentioned but our proofs have been done independently and are included here, so that the paper is self-contained. 3.1. From finite to primal algebras
In this section, we de ne the algebraic framework and consider the relationship between nite algebras, primal algebras and Boolean algebras. The main result is Theorem 3.2 that states an isomorphism between a primal algebra and an adequate term algebra. Given an F -algebra A, a term t built on a set of function symbols F and m variable symbols in an ordered set of variables X , de nes a function tA : Am ! A as follows: 8(a1 ; : : :; am ) 2 Am ; tA(a1 ; : : :; am ) = (t); where is an assignment such that 8i 2 [1 : : :m]; (xi) = ai (also denoted by (xi 7! ai )). A is primal if conversely, to every function corresponds a term:
Combining Symbolic Constraint Solvers on Algebraic Domains
7
Definition 3.1. (Nipkow (1990)) An F -algebra A is primal if any nitary function on its carrier A with an arity greater than 0 is equal to tA for some t in T (F ; X ).
Given a primal F -algebra A such that F is a nite set of nitary function symbols, its carrier A is necessarily nite. In the sequel, only nite primal algebras are considered. To any nite algebra, we can associate a primal algebra with the same carrier and an extended set of function symbols.
F -algebra A with the carrier A = f0; : : :; n ? 1g, the enriched nite algebra A is de ned by the carrier A, and the set of
Definition 3.2. (Buttner et al. 1990) Given the
function symbols
F = F [ f[0]; [1];: ::; [n ? 1]; C ; : : :; Cn? ; +; ?g 0
1
interpreted as follows:
8i 2 A; [i] = i 8i 2 A; 8x A2 A; CiA (x) = if x = i then n ? 1 else 0 8(x; y) 2 A ; x + y = max(x; y) 8(x; y) 2 A ; x ?AAy = min(x; y). ? and > are respective abbreviations for [0] and [n ? 1]. 2
2
Example 3.1. The algebra de ned by the carrier A = f0; 1g together with the set
of additional operators of De nition 3.2, is the 2-elements Boolean algebra where + corresponds to _ (or), ? to ^ (and), C0 to (not). The operator C1 is the identity.
The algebras A and A have the same carrier and functions in F are interpreted in the same way. So any constraint c built on the signature of A has the same set of solutions in A and A. But A has the great advantage to be a primal algebra isomorphic to a quotient term algebra. This property means that we can reason on terms and substitutions instead of values and solutions. We shall see in the next section that any constraint satis able in A has a most general symbolic solution in A that schematizes all solutions in A. We thus concentrate on properties of A and exhibit a nite set AF of equational axioms such that each term t 2 T (F ; X ), is equal modulo AF to a speci c canonical form. This equational presentation has strong similarities with the Post algebra presentations proposed in Traczyk (1964), Epstein (1973), although it has been independently discovered. In the given presentation, + and operaP ? are associative and commutative Q tors, which justi es to introduce notations for an iterated sum, and forPan iterated product, Q with the following conventions for the empty sum and product: x2; x = ? and x2; x = >. Definition 3.3. Let AF be the nite set of axioms on T (F ; X ):
x + (y + z) x+y x ? (y ? z) x?y x ? (y + z) x + (y ? z)
= = = = = =
(x + y) + z y+x (x ? y) ? z y?x x?y+x?z (x + y) ? (x + z)
(1) (2) (3) (4) (5) (6)
x+? x+> x?? x?> x+x x?x
= = = = = =
x
(7)
> (8) ? (9)
x (10) x (11) x (12)
8
Helene Kirchner and Christophe Ringeissen
X
8f 2 F ; 8i 2 A; Ci (f(x ; : : :; xk )) = Ci (x ) ? : : : ? Cik (xk ) fA i ;:::;ik i 8i 2 A; Ci([i]) = > 8(i; j) 2 A ; i =6 j; Ci (x) ? Cj (x) = ? nX ? Ci (x) = > 1
1
1
( 1
)=
2
1
nX ?1 i=0
i=0
Ci(x) ? [i] = x
(13) (14) (15) (16) (17)
Note that lines (13), (14) and (15) actually stand for nite sets of axioms, since F and A are nite. Example 3.2. If we consider the carrier size n = 2 and F = ;, the set of axioms given above generates the Boolean theory. Theorem 3.1. Any term t in T (F ; X ) is equal modulo AF to its canonical form:
X
Y
f:V (t)!Ag x2V (t)
C(x)(x) ? [(t)]:
Q Q In order to simplify notation, the product x2V C(x)(x) will be denoted by (V ) and called atom.y Proof. We rst prove by structural induction that
8i 2 A; 8t 2 T (F ; X ); Ci(t) =AF
This equality is true for variables: 8x 2 X ; Ci(x) =AF
Y
X
f:V (t)!Aj(t)=ig
X f:fxg!Aj(x)=ig
since it is a syntactic identity. For constants, we get X 8j 2 A; Ci([j]) =AF
(V (t)):
(CANi )
C(x)(x);
f:;!Aj([j ])=ig
>:
When j = i, then the sum is non-empty and therefore Ci ([i]) =AF >, else the sum is empty and Ci([j]) =AF ?. Let us now consider a term t = f(t1 ; : : :; tm ). We assume (CANi ) true for subterms t1 ; : : :; tm . Let us focus on product of \C-terms", for example Ci (t1 ) and Ci (t2 ). In this case, Ci (t1 ) ? Ci (t2 ) is equal modulo AF to the sum of products Y Y 1(V (t1 )) ? 2(V (t2 )); for any pair (1 ; 2) 2 f1 : V (t1 ) ! A j 1(t1 ) = i1 g f2 : V (t2 ) ! A j 2(t2 ) = i2 g 1
1
2
y The atom terminology comes from Boolean algebras.
2
Combining Symbolic Constraint Solvers on Algebraic Domains
such that
9
8x 2 V (t ) \ V (t ); (x) = (x):
(I) The assignments 1 [ 2 , only de ned when (1; 2) verify Condition (I), are assignments : V (t1 ) [V (t2 ) ! A such that (t1 ) = i1 and (t2) = i2 . The product Y (1 [ 2)(V (t1 ) [ V (t2 )) 1
is AF-equal to
Y
2
1(V (t1 )) ?
1
Y
2
2(V (t2 ));
since (?) is idempotent. The products associated to pairs which do not satisfy Condition (I) are AF-equal to ? by Axiom (15). Therefore Y X (V (t1 ) [ V (t2 )); Ci (t1 ) ? Ci (t2 ) =AF 2
1
f:V (t1 )[V (t2 )!Aj^2j=1 (tj )=ij g
and more generally, when the product is iterated, we obtain p Y p X Y ([j =1V (tj )): Cij (tj ) =AF f:[pj=1 V (tj )!Aj^pj=1 (tj )=ij g
j =1
By using now Axiom (13), we get that Ci(t) is AF-equal to the sum of products Q (V (t)) such that there exists (i1 ; : : :; im ) 2 Am verifying fA (i1 ; : : :; im ) = i and the conjunction ^mj=1(tj ) = ij : That is X Y Ci (t) =AF (V (t)): f:V (t)!Aj(t)=ig
Applying Axiom (17), we nd the announced canonical form for any term t: X Y t =AF (V (t)) ? [(t)]: f:V (t)!Ag
2
The algebra A is primal (Nipkow (1990)), since any function f : Am ! A is equal to the functional interpretation of the term X (POST) Ca (x1 ) ? : : : ? Cam (xm ) ? [f(a1 ; : : :; am )] a ;:::;am )2Am
1
( 1
where [f(a1 ; : : :; am )] denotes the constant corresponding to the value taken by the function f on (a1; : : :; am ). Intuitively, this term represents the truth table of the function f (Nipkow (1990)). The canonical form modulo AF of a term t 2 T (F ; X ) coincides with the (POST) decomposition of tA , where f corresponds to tA and f(a1 ; : : :; am ) to (t).
10
Helene Kirchner and Christophe Ringeissen
Remark:
This canonical form of a term t can be extended with a nite set V of variables such that V \ V (t) = ;, since: X Y Y X C(x) (x)) (V ) =AF ( x2V f:fxg!Ag f:V !Ag Y =AF > by (16) x2V
=AF >:
Then
t =AF =AF
X f:V (t)!Ag
>?
X
Y
Y
f:V (t)[V !Ag
(V (t)) ? [(t)]
(V (t) [ V ) ? [(t)]:
Theorem 3.1 leads to the next result, useful in the context of constraint solving in primal algebras, since it justi es to work at the level of terms instead of functions and values.
F -algebras A and T (F ; X )= =AF have the same equational theorems: for any equality (s = t), A j= (s = t) if and only if s =AF t.
Theorem 3.2. The
Proof. () : an identity valid in
rem 3.1 states that s =AF
and
t =AF
A is an AF-equality.) The remark following TheoX
Y
f:V (s)[V (t)!Ag
X f:V (t)[V (s)!Ag
Y
(V (s) [ V (t)) ? [(s)] (V (t) [ V (s)) ? [(t)]:
With the assumption that (s = t) holds in A, i.e. 8 2 ASSAX ; (s) = (t); we get s =AF t. (() One can verify easily that all axioms of the presentation AF hold in A. 2 Theorem 3.3. The F -algebras A and T (F )= =AF are isomorphic. Proof. Theorem 3.1 applies also to ground terms and according to the de nition of
empty product, we get:
8t 2 T (F ); t =AF [h(t)]; (II) where h denotes the unique homomorphism from T (F ) to A. It is a surjection. When T (F ) is quotiented by =AF , it becomes a bijection because: If h(s) = h(t) then s =AF t by (II).
Combining Symbolic Constraint Solvers on Algebraic Domains
2
11
If h(s) 6= h(t) then A 6j= [h(s)] = [h(t)] and [h(s)] 6=AF [h(t)], thanks to Theorem 3.2. So s = 6 AF t.
Corollary 3.1. The presentation (F ; AF) is !-complete, i.e. the algebras T (F ; X )==AF and T (F )==AF have the same equational theorems: for any equality (s = t), T (F )==AF j= (s = t) if and only if s =AF t.
A similar result is the existence of an !-complete presentation with hidden functions for any nite algebra, independently proved in Bergstra & Heering (1994). More general properties on the variety of primal algebras are given in Foster (1953). The F -algebra A (isomorphic to T (F )==AF ), together with a set of relations PA on A, is the standard interpretation of the primal constraint language CLAF [; X ]. In this constraint language, we show in the next section that a minimal complete set of solutions contains at most one element. Several predicates are interesting in practice for expressing constraints on nite algebras: these are equality, disequality and ordering predicates. For instance, if F = f0; 1; C0; +; ?g, P = f=; 6=; >g, X = fv; w; x; y; z g, (x =? z ? (z + 1)), (x+y 6=? v?w), (x?y >? z+1), are atomic constraints of this primal constraint language. 3.2. Constraint solving in primal algebras
Uni cation in primal algebras has been studied in Nipkow (1990) by generalizing algorithms for solving equations in nite Boolean algebras. These generalizations are based on extensions of Boole and Lowenheim's methods and dier from the solver presented here, which is derived from (Buttner et al. 1990), where a method is proposed for computing a most general uni er in a primal algebra whose carrier is of cardinality n. Our proof technique is dierent from the one in (Buttner et al. 1990) and we address below the problem of solving any constraint expressed in the previously de ned primal constraint language. Indeed, in the context of primal algebras, it is not really needed to consider other predicates than the equality predicate: to any m-ary predicate p can be associated a function fp such that fp (a1; : : :; am ) = > if and only if pA(a1 ; : : :; am ). In a primal algebra, a term tp is associated to this function fp and the constraint p?(x1 ; : : :; xm) can be expressed by the equation tp (x1; : : :; xm ) =? >. This is the reason why (Buttner et al. 1990) concentrates on equational constraints. But the term tp (x1; : : :; xm ) is most often very big and its complexity hides the intuitive interpretation of the predicate. Moreover, we found that our proof technique is really independent of the predicates of atomic constraints. This is why we consider here any atomic constraint and more generally conjunction of atomic constraints. For solving existentially quanti ed constraints, we simply use the fact that a CSSA (9x : c) can be obtained from a CSSA (c) just by restricting the domain of substitutions. The proposed method transforms any quanti er-free constraint, and thus any constraint in general, into a solved form which corresponds to a substitution. In the context of a nite algebra, the set SolA (c) of solutions of a constraint c is usually easy to compute since the carrier A is nite: just consider all assignments of variables to their possible values and check for each of them whether the constraint is satis ed. But we are rather interested in a more compact representation of the set of solutions, provided by a complete set of solutions, or even better by a most general solution. According to
12
Helene Kirchner and Christophe Ringeissen
Theorem 3.1, any substitution satis es X Y (x) =AF (V ((x))) ? [((x))]: f:V ((x))!Ag
When x is a variable of a given constraint c, V ((x)) V ((c)), so the remark following Theorem 3.1 leads to X Y (x) =AF (V ((c))) ? [((x))]: f:V ((c))!Ag
Let us try to nd a most general solution of this form. To analyze the problem, we rst characterize a most general solution of c thanks to a surjective mapping between assignments from ASSAV ((c)) to SolA (c). For a given c, a substitution de nes a mapping c : ASSAV ((c)) 7! ASSAV (c) , which maps any 2 ASSAV ((c)) to the assignment de ned by 8x 2 V (c); c ()(x) = ((x)). This relation extends by straightforward induction, to terms built on V (c). Let I (c ) denote the range of c : I (c ) = fc () j 2 ASSAV ((c)) g. Note that since c depends only on V (c) and not on c, the notation V (c) would be more appropriate. But we prefer to write c to avoid confusion with the restriction of to the set of variables V (c). Moreover, we also use the notation t instead of (t= t) when t is a term. ?
Example 3.3. In the 2-elements Boolean algebra, consider the equation c = (x =? x+y)
and the substitution = fy 7! xg; c maps the assignment (x 7! 0) onto (x 7! 0)(y 7! 0) and (x 7! 1) onto (x 7! 1)(y 7! 1). The next result reduces the symbolic constraint solving problem to a necessary and sucient condition on c. Proposition 3.1. A substitution is a symbolic solution of a quanti er-free constraint c if and only if I (c ) SolA (c)jV (c) . Proof. By structural induction. Let us rst assume that c = p? (t1 ; : : :; tm ), where p is
a predicate (in particular =). A substitution is a symbolic solution if and only if 8 2 ASSAV ((c)) ; pA (((t1 )); : : :; ((tm ))) () 8 2 ASSAV ((c)) ; pA (c ()(t1); : : :; c()(tm )) () I (c ) SolA (c)jV (c) Let us now consider a constraint c ^ c0 where the proposition holds for c and c0. A substitution is a symbolic solution of c ^ c0 if and only if it is a symbolic solution of both c and c0 if and only if I (c ) SolA (c)jV (c) and I (c0 ) SolA (c0 )jV (c0 ) , 0 or equivalently I (c^c0 ) SolA (c ^ c0 )jV (c^c0 ) since for any 2 ASSAV ((c^c )) , we have c^c0 ()jV (c) = c (jV ((c)) ) and c^c0 ()jV (c0 ) = c0 (jV ((c0 )) ). 2
Indeed, a quanti er-free constraint c has no symbolic solution if SolA (c) is empty. V (c) . Furthermore, there is a very simple way to compare two substitutions with AF
Combining Symbolic Constraint Solvers on Algebraic Domains
13
Proposition 3.2. Let and 0 be two substitutions and c a constraint. V (c) 0 if and only if I (0 ) I ( ): AF
c
c
Proof. An assignment from V (0 (c)) to A is denoted by 0 in this proof.
(() By assumption, we have 809; 8x 2 V (c); 0 (0 (x)) = c0 (0 )(x) = c ()(x) = ((x)): So there exists 0 u : ASSAV ( (c)) ! ASSAV ((c)) such that 80 8x 2 V (c); 0 (0 (x)) = u(0)((x)): Let be the substitution X Y 0 0 fx 7! (V ( (c))) ? [u(0)(x)]gx2V ((c)) : f0 :V (0 (c))!Ag
With this de nition, and according to the de nition of additional operators in F , 0 ((x)) = u(0)(x) for any x 2 V ((c)). Since 0((x)) = (c) (0)(x) for any x 2 V ((c)), the two assignments (c) (0 ) and u(0) coincide. Since this holds for any assignment 0 de ned on V ((c)), (c) = u. Then 80 8x 2 V (c); 0 (((x))) = (c) (0)((x)) = u(0 )((x)) = 0 (0 (x)): Or, in the equational theory AF: 8x 2 V (c); 0 (x) =AF ( )(x): V (c) 0, let us de ne such that =V (c) 0 , and assume without ()) Since AF AF loss of generality that V (((c))) V (0 (c)).
80 8x 2 V (c); c0 (0 )(x) = 0 (0 (x))
= 0 (((x))) = (c) (0 )((x)) = c ((c) (0 ))(x):
That is I (c0 ) I (c). 2 Corollary 3.2. If there exists a substitution such that I (c) = SolA (c)jV (c) , is a
(unique) most general solution of the quanti er-free constraint c.
Now the problem is to prove the existence of such a substitution . This is done by giving explicitly the construction of a mapping c from assignments of new variables Y (introduced to express all assignments : V ((c)) 7! A) to assignments of variables V (c). The number of new variables in Y , denoted by jY j, must be chosen as small as possible but satisfying the condition that njY j is greater than the number jSolA (c)jV (c) j of solutions. Indeed since c is a mapping, we necessarily have jASSAY j jI (c)j = jSolA (c)jV (c) j:
14
Helene Kirchner and Christophe Ringeissen
Moreover jASSAY j is equal to jAjjY j where jAj = n. In the worst case, jY j is equal to jV (c)j. Then any surjective mapping of ASSAY onto SolA (c)jV (c) can be used as the mapping c . Example 3.4. In the 2-elements Boolean algebra, consider the equation
e = (x + y ? z =? x ? y ? z). An assignment (for instance = (x 7! 0)(y 7! 0)(z 7! 0)) is next abusively denoted by its atom (x ? y ? z for )). The reader can check that Sol(e) = fx ? y ? z; x ? y ? z; x ? y ? z; x ? y ? z g. Since jSol(e)j = 4, the condition 2jY j 4 implies jY j = 2 as the smallest possibility. So let us consider two new variables y1 and y2 . Then the mapping e can be chosen as follows: e (y1 ? y2 ) = x ? y ? z e (y1 ? y2 ) = x ? y ? z e (y1 ? y2 ) = x ? y ? z e (y1 ? y2 ) = x ? y ? z We are now able to explicit a most general solution, thanks to the canonical form of (x) in the theory AF, for each x 2 V (c). Theorem 3.4. Let c be a quanti er-free constraint, Y a nite set of variables disjoint of V (c) and c a mapping from ASSAY to ASSAV (c) such that I (c ) = SolA (c)jV (c) . If SolA (c)jV (c) is empty, then c has no symbolic solution, else the substitution
= fx 7! is a most general solution of c.
X Y
f:Y !Ag
(Y ) ? [c()(x)]gx2V (c)
Proof. For any x 2 V (c), ((x)) = c()(x) by construction and the most general
solution is of the desired form. 2
Example 3.5. (Example 3.4 continued: e = (x + y ? z =? x ? y ? z)). With the previous choice for e , we get: e()(x) = 1 if is y1 ? y2 , e ()(y) = 1 if is y1 ? y2 or y1 ? y2 , e ()(z) = 1 if is y1 ? y2 or y1 ? y2 . After simpli cation, we get the most general uni er fx 7! y1 ? y2 ; y 7! y1 ; z 7! y2 g:
The same solving process can indeed be applied to non-equational constraints. Example 3.6. In the 2-elements Boolean algebra, consider the disequation
d = (x ? (y + z) 6=? x ? y). The reader can check that Sol(d) = fx ? y ? z; x ? y ? z; x ? y ? z g. Since jSol(d)j = 3, the condition 2jY j 3 implies jY j = 2 as the smallest possibility. So let us introduce two new variables y1 and y2 . The mapping d can be chosen as follows: d (y1 ? y2 ) = x ? y ? z d (y1 ? y2 ) = x ? y ? z d (y1 ? y2 ) = x ? y ? z d (y1 ? y2 ) = x ? y ? z and the related most general solution is fx 7! 1; y 7! y1 ? y2 + y1 ; z 7! y1 g:
Combining Symbolic Constraint Solvers on Algebraic Domains
15
Another most general solution is fx 7! 1; y 7! y2 + y1 ? y2 ; z 7! y1 g: and the reader can check that these two substitutions are equivalent.
4. Combination problem
Before considering the problem of combining constraint languages and their solvers, let us brie y recall how to combine uni cation procedures. The rst step of uni cation in a combination of theories consists in breaking an equational problem into sub-problems called pure in the sense that they can be solved in one component of the combination. Indeed a same variable could then be solved dierently in each theory. To avoid this problem, a variable is considered as a constant in one theory while solved in the other. This motivates the need, for each theory, of a uni cation algorithm taking into account additional free constants in the signature. In general, recombining the solutions obtained in each theory presents another diculty due to cycles that may occur, for instance if x1 is instantiated by f(x2 ) in the rst theory and x2 by g(x1) in the second. In Baader & Schulz (1992), this problem is solved thanks to a linear restriction, i.e. an ordering on variables that must also be taken into account by the uni cation algorithms. This provides a very elegant and powerful method but introduces in practice a large undeterminism, since all possible choices of linear ordering have to be tried for completeness. In Boudet (1990) instead, this source of non-determinism does not exist. When cycles are detected, they are solved by a special variable elimination procedure. The approach presented here is largely inspired by these previous works and attempts to take advantage of both. We adopt in this section the concept of linear restriction that makes proofs easier. In the next section, concerned with speci c combinations, we show how to delay as much as possible the non-deterministic choices. Considering now two constraint languages de ned on two dierent rst-order structures, we de ne a constraint language whose syntax is the union of both syntaxes and whose interpretation C preserves validity of atomic constraints in each component. Definition 4.1. Let 1 = (fs g; F1; P1) and 2 = (fs g; F2; P2) be two mono-sorted rst-order signatures and X be a set of variables of sort s . The combined constraint language CLC [1 [ 2; X ] of the constraint languages CLA1 [1 ; X ] and CLA2 [2; X ] is de ned by the quotient term algebra C = T (fs g; F1 [ F2 ; X )= =E1 [E2 with E1 = T h(A1 )
and E2 = T h(A2 ).
We do not de ne for the moment the interpretation of predicates on this quotient term algebra. In order to get a conservative extension of their interpretation in each component of the combination, we must rst nd a canonical form of the arguments and abstract some subterms to get pure terms in one component. The rst step is to provide an operational way to work in the equational theory E1 [ E2, by imposing directionality on the use of equations. We assume the reader familiar with rewriting concepts (Dershowitz & Jouannaud (1990)). The following construction was already used in Boudet (1990), Baader & Schulz (1992). Let us de ne F = F1 [ F2 and assume given a simpli cation ordering, denoted by >, total on terms of T (F [ X ). Writing T (F [ X ) means that variables are then considered as nullary function symbols. Both E1 and E2 can be turned into ordered rewrite systems with respect to >.
16
Helene Kirchner and Christophe Ringeissen
Let Ei> = f (g) ! (d) j g =Ei d; : X 7! T (F [X ); (g) > (d)g and R = E1> [ E2> . With this de nition, for any terms s and t in T (F[X ), s !R t if and only if s =E [E t. E1> and E2> are convergent on T (F[X ) by construction. We restrict hereafter to the cases where their union R is convergent too: this is the case if F1 and F2 are disjoint, because there is no critical pair between E1> and E2> . The other interesting case is when the two signatures share only a nite number of constants and we show later on in Section 4.2, how to keep the convergence property for R in this case. A third case worth considering would be the case where E1> and E2> share constructors (Domenjoud et al. 1994). Let us state more precisely these hypotheses and results. 1
2
4.1. Hypotheses
From now on, we assume the following hypotheses and notations. Hypotheses 4.1.
1) The rst-order signatures 1 = (fs g; F1; P1) and 2 = (fs g; F2; P2) are nite. 2) P1 \ P2 = f=g. 3) F1 \ F2 = SC is a set of constants called shared constants. 4) The 1-structure A1 and 2 -structure A2 are consistent. 5) In each structure Ai (i = 1; 2), two dierent constants cannot be interpreted by the same element 8a; b 2 Fi ; a 6= b; (a)Ai 6= (b)Ai :
A term t of T (F [ X ) is i-pure (for i = 1; 2) if t contains only function symbols from Fi and possibly variables of X . An equation (s = t) is i-pure if s and t are. An atomic constraint p (t ; : : :; tm ) is i-pure (for i = 1; 2) if p 2 Pi and t ; : : :; tm are i-pure. A term with its top symbol in Fi is called i-term. Alien subterms of a i-term t are non-variable subterms of t, with a top symbol in Fj , j = 6 i and such that every pre x symbol is in Fi . ?
?
1
1
AlienPos(t) denotes the set of positions of alien subterms in t. The theory height of t is de ned inductively by ht(t) = 1 + max!2AlienPos(t) ht(tj! ). Since a term in T (Fi [ X ) is i-pure, shared constants are the only non-variable terms both 1-pure and 2-pure. 4.2. Properties of the ordered rewrite system
In order to prove that solving a pure constraint in the related component of the combination is correct and complete, we need the con uence of the ordered system R built from E1> and E2> . Intuitively shared constants (when they exist) must be irreducible by R, which leads to require the following assumption on the precedence ordering. Hypothesis 4.2. > is a simpli cation ordering total on
symbols are less than other terms for >.
T (F [ X ) such that nullary
With these hypotheses and de ning R as E1> [ E2> , we can state: Proposition 4.1. There is no rule in R with a nullary symbol as left-hand side.
Combining Symbolic Constraint Solvers on Algebraic Domains
17
Proof. According to Hypothesis 4.2, if there exists a rule in Ei> with a nullary symbol
b = (g) as left-hand side, then its (smaller) right-hand side (d) is necessarily again a nullary symbol a. Assume b 2 Fi. If d is a constant, then d 2 Fj nSC according to Hypothesis 4.1.5, which is impossible since the rule b ! a is in Ei> . Otherwise d is equal to a variable x and we have g =Ei x, where g is either a variable y 6= x or the constant b. In both cases, Ei is not consistent, which yields a contradiction. Assume b 2 Fj [ X . Then g is a variable x and we have x =Ei d, where d is either a variable y 6= x or a constant. In both cases, Ei is not consistent which yields a contradiction. 2
Proposition 4.2. For any i = 1; 2, the left-hand side of a rule in Ei> has a non-nullary
top symbol in Fi .
Proof. If there exists a rule (g) ! (d) in Ei> such that the top symbol of (g) is
in Fj and g 2 T (Fi ; X ), then g is necessarily a variable x. Since Ei is consistent, the variable x occurs necessarily in d. Therefore (x) is a subterm of (d). Since > is a simpli cation ordering, which satis es the so-called subterm property, we have (g) = (x) < (d) which leads to a contradiction. 2
Proposition 4.3. R is convergent on T (F [ X ). Proof. Termination: Let s and t be ground terms in T (F [X ). If s !R t then s !E1> t
or s !E > t. In both cases, s > t where > is ntherian on T (F [ X ). Con uence: Since R is terminating, it is sucient to prove that R is locally con uent. The case of variable overlapping rule applications (i.e. one rule is applied in the substitution part of the other) and the case of non-overlapping rule applications can be handled as in the usual critical pair lemma. For an overlap, two cases must be considered: (1) both rules are in the same Ei> , and (2) rules are from dierent sets Ei> and Ej> . In the rst case, for a peak s Ei> t !Ei> u, (s; u) are instances of a critical pair (l; r), which is also a theorem of Ei . Hence s = (l); u = (r) and s ! u or u ! s is a rule in Ei> . In the second case, given a peak s Ei> t !Ej> u, let us assume without loss of generality that the rule in Ei> is applied at the position . Thus t = (g) and s = (d) where g =Ei d and g; d 2 T (Fi; X ). Also tj! = 0 (l), u = t[ 0 (r)]! where l =Ej r and l; r 2 T (Fj ; X ). According to Proposition 4.2, the rule in Ej> is necessarily applied at a position with a non-nullary symbol in Fj . Such a function symbol cannot occur in g, so we get a contradiction. 2 2
Corollary 4.1. Given two terms s and t in
s #R = t # R .
T (F [ X ), s =E [E t if and only if 1
2
Corollary 4.2. There is no (E1 [ E2)-equality between two distinct constants and
(E1 [ E2) is consistent.
18
Helene Kirchner and Christophe Ringeissen
A last point worth mentioning is that a rewrite rule (g) ! (d) 2 R may introduce new non-constant subterms which correspond to instantiation of variables occurring in d and not in g. Fortunately this kind of rule is irrelevant for normalization: Proposition 4.4. The normal form w.r.t R of any term t may be obtained by applying rules (g) ! (d) 2 R such that for any x 2 V (d)nV (g), (x) is a nullary symbol.
!E > t[ (d)]! such that variables in V (d)nV (g) do not satisfy the above assumption. iLet be the substitution equal to everywhere except for variables x 2 V (d)nV (g) for which (x) is necessarily a nullary symbol (a constant or a variable). Then (g) = (g). According to Hypothesis 4.2, (x) (x). So (g) = (g) > (d) (d) and (g) ! (d) 2 Ei> . Finally t = t[(g)]! !Ei> t[(d)]!. Then, by induction on !R, the R-normal form is obtained by applying such rules. 2
Proof. Consider t = t[ (g)]!
Coming back to the problem of solving a i-pure equation t =?E [E t0 in the combination, it is now possible to prove (t) =E [E (t0 ) by proving (t) #R = (t0 ) #R . The R-normal form of a term (t) where t is i-pure and is a R-normalized substitution, is obtained by applying only rewrite steps with rules from Ei> , so that alien subterms occur only in the substitution part. It is then possible to do a similar proof with axioms from Ei on terms where alien subterms have been replaced with new variables. Indeed equal subterms have to be replaced by the same variable. This is the purpose of variable abstraction described in the next section. 1
1
2
2
4.3. Abstraction
An atomic constraint p? (t1 ; : : :; tm ) is decomposed into a conjunction of pure atomic constraints by introducing new equations of the form (x =? t), where t is an alien subterm in the constraint and x is a variable that does not appear in p?(t1 ; : : :; tm ). This is formalized thanks to the notion of abstraction. Definition 4.2. Let T be a set of terms such that
8t 2 T ; 8u 2 X [ SC; t 6=E [E u: A variable abstraction of the set of terms T is a surjective mapping from T to a set of variables included in X such that 8s; t 2 T ; (s) = (t) if and only if s =E [E t: 1
2
1
2
?1 denotes any substitution (with possibly in nite domain) such that (?1 (x)) = x
for any variable x in the range of .
It is important to note that building a variable abstraction relies on the decidability of E1 [ E2 -equality in order to abstract equal alien subterms by the same variable. Let T = fu #R j u 2 T (F [ X ) and u #R 2 T (F [ X )n(X [ SC)g and be a variable abstraction of this set of R-normalized terms. This variable abstraction is a one-to-one mapping and so the substitution ?1 is the only mapping inverse of . The term ti , called i-abstraction of the term t in a constraint c, is inductively de ned as follows: if t = a 2 SC then ti = a,
Combining Symbolic Constraint Solvers on Algebraic Domains
19
if t = x 2 V (c) then ti = x, if t = f(s ; : : :; sm ) and f 2 Fi then ti = f(si ; : : :; smi ) else if t #R 2= (X [ SC) then ti = (t #R ) = y with y 2 XnV (c) else ti = t #R . Example 4.1. Let us consider E = fx > = xg , E = fx + > = >g and the heterogeneous term t = (y (y + >)) >. Its 1-abstraction t is (y >) > since (y + >) #R = >. Its 2-abstraction t is y since t #R = y. 1
1
1
2
1
2
Given a substitution , i denotes its i-abstraction de ned by i (x) = ((x))i for any variable x in Dom(). The next lemma states some useful and easy properties of i-abstraction. Lemma 4.1.
ti is a term in T (Fi ; X ). any substitution in T (F ; X ). If t is i-pure, then ((t))i = i?(t) for If t is R-normalized then t = (ti ). Consequently, if is R-normalized, then = (? i )jDom , which means i XT F ;X . 1
1
( )
(
)
4.4. Solving in one component
Let us rst consider the case of equational constraints. The method which consists in solving a quanti er-free i-pure equational constraint ci with respect to the equational theory Ei is obviously correct: we get substitutions which are uni ers since =Ei is included in =E . Care must be taken that this method is also complete: each uni er must be an instance of at least one of these substitutions. This method has been successively shown complete for the combination of disjoint regular and collapse-free equational theories (Yelick (1987)) and, later on, for disjoint equational theories (Schmidt-Schau (1989), Boudet (1990), Boudet (1993)). We prove next that it is also true when constants are shared. Lemma 4.2. Let s be a i-term such that alien subterms are R-normalized. Assume that
s is R-reducible. Then there exists a term t such that t is either a R-normalized j-term (j 6= i), or a i-term where all alien subterms are R-normalized. Moreover si =Ei ti .
Proof. By assumption, all alien subterms of s are R-normalized. Then, if a rule in R
is applicable and s !R t, s is necessarily reducible at a position with a non-nullary symbol in Fi . According to Proposition 4.2, this rule cannot be in Ej> , for j 6= i. According to Proposition 4.4, we can choose the rule in such a way that no new R-reducible alien subterm is introduced during the rewriting step s !R t. So if t is an i-term, all its alien subterms are R-normalized. If t is a j-term, then it is an alien subterm of s and so t is R-normalized. Since alien subterms always belong to instantiated parts of rules, the same proof holds, now with \replacement of equals for equals", when alien subterms are substituted with (new) variables. This step corresponds to the application of a variable abstraction. Hence si =Ei ti . 2
Corollary 4.3. Assume that s is a i-term whose alien subterms are R-normalized.
Then si =Ei (s #R )i .
20
Helene Kirchner and Christophe Ringeissen
Proof. Thanks to Lemma 4.2 and ntherian induction on !R . 2 Corollary 4.4. For any i-pure term s and any R-normalized substitution , we have
i (s) =Ei ((s) #R )i .
Proof. Alien subterms of (s) are R-normalized and i (s) = ((s))i . 2
We are now able to prove that any solution in C of a i-pure equation (s =? t) corresponds to a symbolic solution in Ai . Proposition 4.5. Let s and t be two i-pure terms and a R-normalized substitution.
Then
(s) =E [E (t) , i (s) =Ei i (t) , Ai j= i (s) = i (t): 1
2
Proof. The last equivalence is clear. Let us concentrate on the rst one. (() is obvious (correctness): i (s) =Ei i (t) ) ?1 (i (s)) =Ei ?1 (i (t)).
This equality is identical to (s) =Ei (t). Then, we just argue that a Ei-theorem is also a E-theorem. This is the only assertion we need for proving that, for a i-pure equational constraint, a Ei -uni er is also a E-uni er. Let us prove ()) (completeness). If (s) =E [E (t) then (s) #R = (t) #R and i (s) =Ei ((s) #R )i = ((t) #R )i =Ei i (t): 2 1
2
Note that i XE [E . Hence a complete set of Ei-uni ers of a quanti er-free i-pure equational constraint ci is a complete set of (E1 [ E2)-uni ers of ci. In other words, a CSSAi (ci ) provides a CSSC (ci). 1
2
4.5. Interpretation of predicates
In giving now interpretations to predicates in C , we want to extend their interpretation in each component in such a way that the solvability of i-pure atomic constraints is preserved in C . The interpretation of a predicate pi 2 Pi dierent from equality, is de ned as follows on T (F [ X ). Definition 4.3. Let p 2 Pi and t1 ; : : :; tm be terms in T (F [X ). The interpretation pC of p in C is the relation de ned by: pC (t1 ; : : :; tm ) if Ai j= p((t1 #R )i ; : : :; (tm #R )i ):
De nition 4.3 is compatible with equality in C : indeed if tk =E [E sk , their R-normal forms are equal so their abstractions are identical and (tk #R )i = (sk #R )i . At rst glance, interpretation of predicates depends on the choices of the rewrite system R and of the variable abstraction . Moreover, this de nition is not operational, since R is in nite and R-normal forms cannot be computed. We now introduce another reduced form that has the greatest advantage to be computable provided Ai -equality is decidable for i = 1; 2. 1
2
Combining Symbolic Constraint Solvers on Algebraic Domains
21
Definition 4.4. A layer-reduced form of a term t, denoted t+, is inductively de ned as
follows:
if t is a variable or a constant, then t+ = t, else let t0 = t[! - (tj! )+]!2AlienPos t , let be a variable abstraction of alien subterms of t0 to XnV (t0 ) and t00 = t0[! - (t0j! )]!2AlienPos t0 . Then if t00 () 2 Fi , and if there exists u 2 V (t00 ) [ SC such that t00 =Ai u, then t+ = ? (u), else t+ = t0 . ( )
( )
1
A layer-reduced form of a term t is obtained by erasing repeatedly, with an innermost strategy, those alien \layers" that would not appear in the normal form of t. Proposition 4.6. The respective top symbols of a layer-reduced form and of the R-
normal form of any term t are both in FinSC for some i = 1; 2, or are the same shared constant, or are the same variable. Proof. By induction on the theory height.
If t is i-pure and u 2 V (t) [ SC, then t =Ei u if and only if t #R = u. Assume now t is a i-term with some alien subterms. Let us consider t0 and t00 de ned as in De nition 4.4: If there exists u 2 V (t00 ) [ SC such that t00 =Ai u, then ?1(u) is either an alien subterm of t0, or a variable, or a shared constant. If ?1 (u) is an alien subterm of t0, then the proposition holds for t+ = ?1(u) thanks to the induction hypothesis, else ?1 (u) is a variable or a shared constant and so t+ = t #R since variables and constants are R-normalized. Otherwise, let us assume t #R () = t0 #R () 2= FinSC. Then t0i = (t0[! - t0j! #R ]!2AlienPos(t0 ) )i =Ei (t0 #R )i according to the induction hypothesis and Corollary 4.3. Since we can choose such that (s #R ) = (s) for any alien subterm s of t0 , we have t00 = t0i =Ei (t0 #R )i 2 V (t00 ) [ SC: This contradicts the assumption and so t #R () 2 Fi nSC when t+() 2 Fi nSC. 2
Proposition 4.7. Given any system R built from E1 [ E2 and any variable abstraction of the set of R-normalized terms, for any term t, (t+)i =Ai (t #R )i . Proof. If t is a shared constant a, (a+)i and (a #R )i are both equal to a. Otherwise, if t+() 2 Fi , then (t+)i = (t+[! - (t+j! ) #R ]!2AlienPos(t+))i =Ei (t #R )i ,
according to Corollary 4.3. If t+() 2= Fi, then (t+)i = (t #R )i 2 X . 2
Corollary 4.5. C -equality between two terms in layer-reduced form is decidable, pro-
vided Ai -equality is decidable for i = 1; 2.
Proof. Let s+ and t+ be two terms in layer-reduced form. Let us prove that
s+ =C t+ , (s+)i =Ai (t+)i :
22
Helene Kirchner and Christophe Ringeissen
s+ =C t+ , s #R = (s+) #R = (t+) #R = t #R and so (s #R )i = (t #R )i . But according to Proposition 4.7, we have (s #R )i =Ai (s+)i and (t #R )i =Ai (t+)i . The corollary is now proved by induction on the theory height: If s+ and t+ are i-pure terms, then s+ = (s+)i , t+ = (t+)i and so C -equality between s+ and t+ corresponds to Ai -equality. Otherwise, let us assume that the hypothesis holds for the set T of alien subterms of s+ and t+. Therefore, we are able to construct a variable abstraction of T and to choose such that (u #R ) = (u) for any u 2 T . Then s+00 = s+[! - (s+j! )]!2AlienPos(s+) = (s+)i t+00 = t+[! - (t+j! )]!2AlienPos(t+) = (t+)i where s+() and t+() are function symbols in Fi . So s+ =C t+ if and only if s+00 =Ai t+00. 2 Under the same assumptions, the construction of the term t00 in the de nition of a layer-reduced form is then possible and the test t00 =Ai u is decidable.
Ai -equality is decidable for i = 1; 2, then the construction of a layer-reduced form is always possible, and C -equality is decidable.
Corollary 4.6. If
The i-abstractions of R-normal forms in De nition 4.3 can now be replaced by the i-abstractions of layer-reduced forms. Corollary 4.7. The interpretation of predicates given in De nition 4.3 is independent
of R and .
0 0 Proof. First note that given two variable abstractions and 0, p((t1+)i0 ; : : :; (tm +)i0 )
is clearly a renaming of p((t1 +)i ; : : :; (tm +)i ) and thus p((t1+)i ; : : :; (tm +)i ) holds in Ai if and only if p((t1 +)i ; : : :; (tm +)i ) holds in Ai . Second, p(t1 #R )i ; : : :; (tm #R )i ) holds in Ai if and only if p((t1+)i ; : : :; (tm +)i ) holds in Ai and the de nition of pC is independent of R. 2
As expected, the interpretation of predicates in C coincides with validity of the corresponding atomic constraints. Proposition 4.8. Let p 2 P1 [ P2 and t1 ; : : :; tm be terms in T (F [ X ). Then pC (t1 ; : : :; tm ) if and only if C j= p(t1; : : :; tm ). Proof. By de nition of validity in C , this amounts to prove that pC (t1 ; : : :; tm ) if and only if pC ((t1 ); : : :; (tm )) for any R-normalized substitution on T (F [ X ).
The if-part is obvious since the identity is R-normalized. Conversely, we can assume without loss of generality that t1; : : :; tm are R-normalized. We rst prove that ti Ei ((t) #R )i if is a R-normalized substitution and t is a R-normalized term. Assume t is a i-term. Let us consider the term u obtained by replacing in (t), alien subterms with their normal forms: u = (t)[! - ((t)j! ) #R ]!2AlienPos((t)) :
Combining Symbolic Constraint Solvers on Algebraic Domains
23
According to Corollary 4.3, we have ui =Ei ((t) #R )i . The term ui is an instance of ti , i.e. there exists a substitution such that ui = (ti ), de ned as follows: { (si ) = ((s) #R )i if s is an alien subterm of t, abstracted by a variable si , { (x) = i (x) if x 2 V (t). Consequently, (ti ) = ui =Ei ((t) #R )i and only depends on . Assume t is not a i-term. Then, we can directly de ne as (ti ) = ((t) #R )i , since ti 2 X . Now, if pC (t1; : : :; tm ) then p(t1 i ; : : :; tmi ) holds in Ai by de nition, as well as each of its instances like p(((t1 ) #R )i ; : : :; ((tm ) #R )i ) and so pC ((t1 ); : : :; (tm )). 2 Corollary 4.8. Validity of atomic CLC [1 [ 2 ; X ]-constraints is decidable if validity of atomic CLAi [i; X ]-constraints is decidable for i = 1; 2. Example 4.2. Consider the combination of the 2-elements Boolean algebra with the
free function symbol f. The following constraints are valid in C : f(x) + f(x) 6=? 0, f(x) + 1 ? 1, f(f(x) + f(x)) =? f(f(x))
According to the chosen interpretation of predicates, validity of i-pure atomic constraints is preserved in the interpretation. Proposition 4.9. If ci is an atomic constraint i-pure in CLAi [i; X ], then
C j= ci , Ai j= ci :
Proof. Let ci = p? (t1 ; : : :; tm ). Since t1 ; : : :; tm are i-pure and according to Corollary 4.3, we have tk =Ai (tk #R)i for k = 1; : : :; m.
So, p(t1 ; : : :; tm ) holds in Ai if and only if p((t1 #R )i ; : : :; (tm #R )i ) holds in Ai . 2
Moreover, solvability of i-pure atomic constraints is preserved in the interpretation. In other words, if c is an i-pure atomic constraint, to any (R-normalized) solution in the combined language corresponds a symbolic solution in one of the component languages. Proposition 4.10. Let p?(t1 ; : : :; tm ) be a i-pure atomic constraint and a R-normalized
substitution. Then C j= p((t1 ); : : :; (tm )) , Ai j= p(i (t1 ); : : :; i (tm )):
Proof. According to Proposition 4.8, p((t1 ); : : :; (tm )) holds in C if and only if
p(((t1 ) #R )i ; : : :; ((tm ) #R )i ) holds in Ai . Thanks to Corollary 4.4, ((tk ) #R )i =Ai i (tk ) and so: p(((t1 ) #R )i ; : : :; ((tm ) #R )i ) holds in Ai if and only if p(i (t1); : : :; i (tm )) holds in Ai . 2
24
Helene Kirchner and Christophe Ringeissen
As a consequence, we yet have CSSAi (ci ) is a CSSC (ci ) if ci is a quanti er-free i-pure constraint. This result justi es the choice of CLC [1 [ 2; X ] as the combined language. 4.6. Combination of symbolic constraint solving with disjoint function sets
We assume in this section that A1 and A2 have disjoint sets of function symbols, that is F1 \ F2 = ;. Our goal is to extend the technique used in Baader & Schulz (1992) for combining two uni cation algorithms or procedures. With our choice of symbolic constraint solving made in Section 1, extending the combination technique beyond the class of equational constraints yet requires the existence of complete sets of symbolic solutions given by substitutions. Let us look for instance at the more speci c case of combining the primal constraint language CLAF [; X ] with another equational constraint language CLE [fs g; F2; f=g; X ]: so (F1 ; E1) = (F ; AF), P1 = P and P2 = f=g. The key idea is that solving any constraint in a primal algebra will result in a (unique) solved form, its most general solution, that can be considered as a conjunction of equational constraints. This enables us to extend the tools for combining uni cation problems. Let us look more closely at the dierent steps. Variable abstraction transforms an heterogeneous atomic constraint p? (t1 ; : : :; tm ) where at some position ! in the term tk , the function symbol tk (!) 2= F , into the constraint (9x : p? (t1 ; : : :; tk [! - x]; : : :; tm ) ^ x =? tk j! ) where x is a new variable. By repeatedly applying this transformation, an heterogeneous atomic constraint is transformed into the conjunction of a pure atomic primal constraint with equational constraints. The solving process applied on a pure primal \ denote the most general constraint c returns a most general solution of c. Let mgs(c) solution of the CLAF [; X ]-constraint c written as an equational constraint. Indeed, \ have the same set of solutions in both the primal constraint language c and mgs(c) and the combined constrained language. This property justi es to reuse the techniques from Schmidt-Schau (1989), Boudet (1990), Baader & Schulz (1992) for the combination of disjoint equational theories. Let us now more formally de ne the dierent steps of a constraint solving procedure in the union of two constraint languages with disjoint function sets. 2
4.6.1. Identification
Abstraction produces pure constraints in each language by introducing new variables to split terms. These new variables are shared by the two theories and may further be instantiated in both of them. So, all possible choices for instantiating a variable in a theory have to be considered. When a variable is instantiated in i, it is considered as a constant in j 6= i. The problem introduced by abstraction is that two distinct variables may be introduced that actually denote two equal or equivalent terms. So care must be taken that distinct variables could be identi ed with a solution as in the next example. Example 4.3. Let us consider the combination of the 2-elements Boolean algebra with two free symbols a; f. The equational constraint (x+y =? x) ^ (x =? f(z)) ^ (y =? f(a)); where x and y are free constants in the Boolean equation has no solution. But variables x and y may be equal to a same term in one theory. The equational constraint (x =? y) ^ (x + y =? x) ^ (x =? f(z)) ^ (y =? f(a));
Combining Symbolic Constraint Solvers on Algebraic Domains
25
where x; y are identi ed and only y is considered as a free constant in the Boolean equation, is equivalent to (x =? y) ^ (y + y =? y) ^ (y =? f(z)) ^ (y =? f(a)) and then to the tree-solved form (x =? f(a)) ^ (y =? f(a)) ^ (z =? a). Thus, for the sake of completeness, before solving a constraint in one of the constraint languages, the constraint must be rst split into a disjunction of constraints obtained by variable identi cation. A variable identi cation is just a substitution whose range is a set of variables. Definition 4.5. An identi cation on a set of variables V is an idempotent substitution
such that Dom() V and Ran() V . The set of all identi cations on V is denoted by IDV . 4.6.2. Combination of solved forms
Solving constraint in each component now needs more than the assumed constraint solving algorithm, since new free constant symbols of the signature have to be taken into account. It is known that uni cation and general uni cation (uni cation with additional free function symbols) are not equivalent. An additional problem occurs due to the fact that cycling equations between the two languages may appear and must be solved. For instance, if (x1 =? t1[x2]) is solved in the rst theory (where x2 is considered as a free constant symbol) and (x2 =? t2 [x1]) is solved in the second (where x1 is considered as a free constant symbol), their propagation yields a cycle. This problem is avoided by a priori choosing a linear ordering < on the set V [ C of all variables and constants introduced in the problem. Then to each constant a is associated a set of variables Va = fx j x 2 V and x < ag. Solving a problem of uni cation with linear restriction is nding uni ers s.t. 8x; a with x 2 Va , then a does not occur in (x). So in each theory a constraint solver with linear restriction is used to solve the constraint ci . Definition 4.6. Let < be a linear ordering on V1 V2 the disjoint union of two nite sets of variables and a quanti er-free constraint ci of CLAi [i; X ] such that V (ci ) V1 V2 . A symbolic solution with linear restriction of ci is a symbolic solution such that for fi; j g = f1; 2g and i 6= j
8xj 2 Vj ; (xj ) = xj , 8xj 2 Vj ; 8xi 2 Vi ; xj 2= V ((xi )) if xi < xj . The set of all these symbolic solutions is denoted by SSA