A constraint solver in nite algebras and its combination with uni cation algorithms Helene Kirchner & Christophe Ringeissen
CRIN-CNRS & INRIA-Lorraine BP 239, 54506 Vanduvre-les-Nancy Cedex, France fhkirchner,
[email protected]
Abstract
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. A constraint solver in nite algebras is presented for a constraint language including equations, disequations and inequations on nite domains. The method takes advantage of the embedding of a nite algebra in a primal algebra that can be presented, up to an isomorphism, by an equational presentation. We also show how to combine this constraint solver in nite algebras with other uni cation algorithms, by extending the techniques used for the combination of uni cation.
1 Introduction 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 allowed the handling of Boolean constraints (CHIP, Prolog III), sets constraints (CAL) and constraints on nite 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 the 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, matrix rings over nite elds and nite simple nonabelian groups. 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 [11] and the uni cation problem in the class of primal algebras and in their varieties is extensively studied in [12]. Implementations are described in [14, 13] for Boolean uni cation, and in [4, 15] for uni cation in nite algebras. The need for combining constraint solving in speci c theories (as Booleans) with other function symbols appears in the context of programming
and deduction with constraints. For instance, in theorem proving with builtin theories, free constants and function symbols are generated during skolemization. But combination problems also appear in the context of a constraint logic programming language allowing dierent built-in theories. The approach developed here consists in extending the techniques used to combine uni cation algorithms. The combination problem for uni cation can be stated as follows: given two uni cation algorithms in two (consistent) equational theories E1 on 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 [6, 8, 19, 20] 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 [2, 17] and the case of theories sharing constants is studied in [16]. The general idea of uni cation in a combination of theories consists in breaking an equational problem into sub-problems that are pure in the sense that they can be solved in one component of the combination. In order to nd solutions for the combined uni cation problem, the following assumptions should be satis ed, for i = 1; 2: Ei has a complete uni cation algorithm with free constants, i.e. a uni cation algorithm for terms in T (Fi [ C ; X ) where C is an arbitrary set of free constants. A complete constant elimination algorithm for Ei is available. This is used for breaking cycles between equations, that appear during the occur-check process. The problem considered in this paper is 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. 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. The method we propose here is to embed a nite algebra into a primal algebra and to take advantage of the fact that any primal algebra can be presented, up to an isomorphism, by an equational presentation. A uni cation algorithm for primal algebras was proposed in [4]. We extend it and generalize its proof to a large class of constraints. Using this constraint solver, a constraint is transformed into an equational problem with the same set of solutions. In order to combine this constraint solver with another uni cation algorithm, we need to solve constraints with free constants and to deal with the constant elimination problem in primal algebras. Using the notion of frozen variable, we derive from the constraint solver in primal algebras, a solver for constraints with frozen variables and a complete frozen variable elimination algorithm. The paper is organized as follows: Section 2 is devoted to the de nition
and properties of nite and primal algebras and presents the embedding of a nite algebra into a primal algebra. In Section 3, the constraints we want to solve in primal algebras are de ned together with their solutions. In Section 4, a constraint solver in primal algebras is presented. Section 5 shows how to combine it with another uni cation algorithm. The constraint solver for the combination is illustrated on an example. For lack of space, all proofs are omitted but can be found in [10].
2 Finite and 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 2 that states an isomorphism between a primal algebra and an adequate term algebra. Let F be a set of function symbols, X a set of variables, and A an F algebra, whose carrier is denoted by A. An algebra is nite when its carrier and its set of functions are both nite. T (F ; X ) is the free F -algebra over X , whose carrier is the set of terms T (F ; X ). Given a set of equational axioms E and the generated congruence =E , the quotient F -algebra is denoted T (F ; X )= =E . An assignment is a mapping from X to A; it uniquely extends to an homomorphism from T (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 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(a ; : : :; am) 2 Am; tA (a ; : : :; am) = (t); where is an assignment such that 8i 2 [1 : : :m]; (xi ) = ai (also denoted by (xi 7! ai )). Conversely, De nition 1 [12] 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 1
1
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.
De nition 2 Given the 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 function symbols F = F [ f?; [1]; : : :; [n ? 2]; >; C0; : : :; Cn?1; +; g
interpreted as follows: ?A = 0 >A = n ? 1 8i 2 A n f0; n ? 1g; [i]A = i 8i 2 A; 8x 2 A; CiA(x) = if x = i then n ? 1 else 0 8(x; y) 2 A2; x +A y = max(x; y) 8(x; y) 2 A2; x A y = min(x; y).
Example 1 The algebra de ned by the carrier A = f0; 1g together with the set of additional operators of De nition 2 is the 2-elements Boolean algebra where + corresponds to _ (or), to ^ (and), C0 to (not). The operator C1 is the identity. The algebra A is primal [12], since any function f : Am ! A is equal to the functional interpretation of the term X Ca1 (x1) Cam (xm) [f (a1; : : :; am)] (POST ) a ;:::;am )2Am
( 1
where [f (a1; : : :; am )] denotes the operator corresponding to the value taken by the function f on (a1; : : :; am ). Intuitively, this term represents the truth table of the function f . We now 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, which is the (POST ) decomposition of tA .
De nition 3 Let AF be the nite set of axioms on T (F ; X ): x + (y + z) = (x + y) + z x+? = x x+y = y+x x+> = > x (y z) = (x y) z x? = ? xy = yx x> = x x (y + z) = x y + x z x+x = x x + (y z) = (x + y) (x + z) x x = x X Ci1 (x ) Cip (xp) 8f 2 F p; 8i 2 A; Ci(f (x ; : : :; xp)) = fA i1 ;:::;ip i 8i 2 A; Ci([i]) = > 8(i; j ) 2 A ; i =6 j; Ci(x) Cj (x) = ? nX ? Ci(x) = > 1
1
(
)=
2
1
nX ?1 i=0
i=0
Ci(x) [i] = x
Example 2 If we consider the domain size n = 2 and F = ;, the set of axioms given above generates the Boolean theory.
Theorem 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)]:
Proof: see [10]. 2 The canonical form of t must be compared to the previous decomposition (POST ) where f corresponds Qto tA and f (a1; : : :; am ) to (t). QIn order to simplify notation, the product x2V C(x)(x) will be denoted by (V ) and called atom.1 Theorem 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.
Theorem 2 The F -algebras A and T (F ; X )= =AF have the same equational theorems: for any universally quanti ed equality (t = t0 ), A j= (t = t0 ) i t =AF t0. Moreover, A and T (F )= =AF are isomorphic. Corollary 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 universally quanti ed equality (t = t0 ), T (F )= =AF j= (t = t0 ) i t =AF t0 . A direct proof of these results can be found in [10], but they could also be obtained as consequences of more general results on the variety of primal algebras given in [5].
3 Constraint languages We now de ne a constraint language for the class of constraints we want to solve in nite algebras. We also make precise the notions of solutions and complete sets of symbolic solutions for a given constraint. A substitution is an endomorphism of T (F ; X ). 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)). We use letters ; ; ; ; : : : to denote substitutions. Substitutions are partially ordered by subsumption ordering, as follows: Given a (possibly empty) set of equational axioms E and the generated congruence =E , a substitution is an E -instance on V X of a substitution , written VE (and read as is more general modulo E than on V ), if there exists some substitution such that 8x 2 V; (x) =E ( (x)).
De nition 4 [18, 9] Let F be a set of function symbols and P a set of predicates, a constraint language CL [F ; P ] is given by: 1
The atom terminology comes from Boolean algebras.
a set of constraints which are rst-order existentially quanti ed formulae built over T (F ; X ) and predicates P . V (c) the set of free variables of the constraint c. a non-empty set of interpretations K. Each interpretation K is given
by a domain K and a solution mapping that associates to each constraint the set of assignments SolK(c) de ned as follows: { SolK(p(t1; : : :; tj )) = f 2 ASSKX j ((t1); : : :; (tj )) 2 pKg. { SolK(c ^ c0) = SolK(c) \ SolK(c0). { SolK(:c) = ASSKX nSolK(c). { SolK(9x : c) = f 2 ASSKX j there exists 0 2 SolK(c) such that jV (c)nfxg = 0jV (c)nfxgg
An assignment in SolK(c) is a solution of c in K. A constraint c is valid in K, written K j= c, if any assignment is a solution of c in K. A constraint c is valid in CL [F ; P], written CL [F ; P] j= c, if c is valid in any interpretation K of .
As usual, we can also de ne abbreviations _; ); , to write more complex constraints. Two constraints c and c0 are equivalent if they have the same set of solutions in any interpretation. This is equivalent to write that CL [F ; P ] j= (c , c0 ). A symbolic solution of a CL [F ; P]-constraint c is a substitution such that CL [F ; P] j= (c). A substitution is an CL [F ; P ]-instance on V X of a substitution , written V , if there exists some substitution such that 8x 2 V; CL [F ; P] j= (x) = ( (x)).
De nition 5 A set of substitutions is a complete set of solutions of the CL [F ; P]-constraint c, denoted by CSS (c), if (1) 8 2 CSS (c); Dom( ) \ VRan( ) = ; and Dom( ) V (c).
(2) Each substitution in CSS (c) is a symbolic solution of c. (3) For any symbolic solution of c, there exists 2 CSS (c) such that V (c) . When two substitutions of CSS (c) cannot be compared with V (c), the complete set of solutions CSS (c) is minimal. If such a set is reduced to one element, this element is denoted mgs(c).
In this paper, we focus our interest on some particular constraint languages: An equational presentation (F ; E ) de nes an equational constraint language CLE [F ; f=?g] where constraints are equational constraints that is rst-order equational formulae built over T (F ; X ). The standard interpretation is the quotient algebra T (F ; X )= =E . A symbolic solution is a
E -uni er. A complete set of solutions of a CLE [F ; f=?g]-constraint c is denoted CSSE (c) or CSUE (c) since it is also a complete set of E -uni ers. For instance, if F = fa; f g, X = fv; x; y g and E consists of the associativity and commutativity axioms for f , then (f (v; x) =? f (a; f (x; y ))) is an equa-
tional constraint. 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 [F ; P ]. CSSAF (c) denotes a complete set of solutions of the CLAF [F ; P ]-constraint c. 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 domains: 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 =? v w), (x y >? z + 1), are elementary constraints of this primal constraint language.
4 Constraint solving in primal algebras Uni cation in primal algebras has been studied in [12] by generalizing algorithms for solving equations in nite Boolean algebras. We address here the more general problem of solving any constraint expressed in the previously de ned primal constraint language. Our proof technique is derived from [4], where a method is proposed for computing a most general uni er in a primal algebra whose domain is of cardinality n. In the context of a nite algebra, the set Sol(c) of solutions of a constraint c is usually easy to compute since the domain 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. To analyze the problem, let us rst characterize a most general solution of c thanks to a surjective mapping between assignments from ASSAV ((c)) to Sol(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. Example 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 solving problem to a necessary and sucient condition on c .
Proposition 1 A substitution is a symbolic solution of the constraint c if and only if I (c ) Sol(c)jV c . If there exists a substitution such that I (c) = Sol(c)jV c , is a most general solution of c. Proof: The proof (cf. [10]) uses an intermediate result: let and 0 be two substitutions and c a constraint; I (c0 ) I (c ) if and only if VAFc 0 . ( )
( )
( )
2
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 must be chosen as small as possible but satisfying the condition njY j jSol(c)jV (c)j. Indeed since c is a mapping, we necessarily have jASSAY j jI (c)j = jSol(c)jV (c)j: 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 Sol(c)jV (c) can be used as the mapping c . Example 4 In the 2-elements Boolean algebra, consider the equation c = (x + yz =? xyz ), where the symbol is omitted. An assignment (for instance = (x 7! 0)(y 7! 0)(z 7! 0)) is next abusively denoted by its atom (xyz for )). The reader can check that Sol(c) = fxyz; xyz; xy z; xyzg. We need two new variables y1 and y2 , since 2jY j 4 implies jY j = 2 as the smallest possibility. Then the mapping c can be chosen as follows: c (y1y2 ) = xyz c(y1 y2 ) = xyz c (y1y2 ) = xy z c (y1 y2 ) = xyz 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 Let c be a constraint, Y a nite set of variables disjoint of V (c) and c a mapping from ASSAY to ASSAV (c) such that I (c ) = Sol(c)jV (c). The substitution X Y = fx 7! (Y ) [c ()(x)]gx2V (c) f:Y !Ag
is a most general solution of c. Proof: According to Theorem 1, for any x 2 V (c), X Y (Y ) [((x))] (x) =AF f:Y !Ag
and ( (x)) = c ()(x) by construction. 2 Example 5 (Example 4 continued: c = (x + yz =? xyz)). c()(x) = 1 if corresponds to the atom y1 y2 , c ()(y ) = 1 if is y1 y2 or y1 y2 , c ()(z ) = 1 if is y1 y2 or y1 y2 . After simplication, we get mgs(c) = fx 7! y1y2; y 7! y1 ; z 7! y2 g.
5 Combination problem We now consider the problem of combining two constraint languages on disjoint signatures, by extending the de nition of the union of equational theories.
De nition 6 Let F and F be disjoint signatures: F \ F = ;. The combined constraint language CC of two constraint languages CL1 [F ; P ] and CL2 [F ; P ] is the constraint language CL [F [F ; P [P ] such that is the set of interpretations preserving the validity of CL1 [F ; P ]-constraints and CL2 [F ; P ]-constraints. 1
2
1
2
1
2
2
1
2
1
2
1
2
1
1
2
In the more speci c case of combining the primal constraint language
CLAF [F ; P ] with another equational constraint language CLE [F2; f=?g], (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. The combination of the two constraint solvers relies on three operations: abstraction that produces pure constraints in one language by replacing subterms by new variables existentially quanti ed; solving pure constraints with frozen variables in each language, to take into account that shared variables cannot be instantiated independently; frozen variable elimination for breaking cycles of the form x1 =? t1 [x2 ] ^ : : : ^ xq =? tq [x1 ] where t1 ; : : :; tq are non-variable terms pure alternately in each constraint language. The solving process applied on a pure primal constraint c returns a most d(c) denote the most general solution of the general solution of c. Let mgs CLAF [F ; P ]-constraint c written as an equational constraint. Indeed, since d(c), CC j= c , mgs d(c). In other words, c and CLAF [F ; P ] j= c , mgs d mgs(c) have the same set of solutions in both the primal constraint language and the combined constrained language CC . Variable abstraction transforms an heterogeneous atomic constraint p(t1 ; : : :; tj ) where at some position ! in the term ti , the function symbol ti (!) 2= F , into the constraint 9x : p(t1; : : :; ti[x]!; : : :; tj ) ^ x = ti 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. To summarize, for any CC -constraint c, there exists an equational constraint c0 such that CSSCC (c) = CSUAF [E (c0). This property justi es to reuse the same techniques for breaking cycles as in the equational theories combination [1, 17], once pure constraints have been solved.
5.1 Constraint solving w.r.t. frozen variables
The CLAF [F ; P ]-constraint solver is easily modi ed to avoid instantiation of frozen variables. A complete set of solutions CSS (c; M) of the constraint c w.r.t. frozen variables M V (c) is de ned from De nition 5 by modifying the point (1): 8 2 CSS (c; M); Dom() V (c)nM: When a minimal CSS (c; M) is at most a singleton, mgs(c; M) denotes this unique element. From now on, an assignment 2 ASSAM corresponds to a substitution , obtained by replacing the value (x) 2 A by the corresponding constant [ (x)] 2 F . The substitution mgs(c; M) is computed from the most general solutions of each constraint (c), thanks to the following remark that 2 CSS (c; M) if and only if for any instantiation of frozen variables, 2 CSS ((c); ;). Theorem 4 Let c be a constraint and M a set of variables included in V (c). The substitution XY fx 7! (M) mgs((c))(x)gx2V(c)nM
is a most general solution of c with frozen variables M. Example 6 (Example 4 continued: c = (x + yz =? xyz)). Assume M = fxg. We need to consider c0 = 0 + yz =? 0yz where Sol(c0) = fyz; yz; yzg and c1 = 1 + yz =? 1yz where Sol(c1) = fyz g. Hence mgs(c1) = fy 7! 1; z 7! 1g and the mapping c0 (y1 y2 ) = yz c0 (y1y2 ) = yz c0 (y1 y2) = yz c0 (y1y2 ) = yz yields mgs(c0) = fy 7! y1 ; z 7! y1 y2 g. The terms x mgs(c0)(y )+ x mgs(c1)(y ) and x mgs(c0)(z )+ x mgs(c1)(z ) are respectively associated to y and z : mgs(c; M) = fy 7! xy1 + x; z 7! xy1 y2 + xg.
5.2 Frozen variable elimination
Let us now consider the problem of cycles of the form x1 =? t1 [x2]^: : :^xq =? tq [x1] where t1 ; : : :; tq are non-variable terms pure alternately in each constraint language. Such cycles may have solutions in the combined constraint language. In order to nd them, we need to discover instantiations that transform this cycle into another system from which solutions can be computed. This is the purpose of variable elimination. De nition 7 A term u is eliminating x in t w.r.t. frozen variables M if xg u i.e. 9 s.t. (t) = u and Dom( ) \ x 2= u; x 2= M and t M[f AF AF (M [ fxg) = ;. The set of all such terms is denoted by STE (x; t; M). The substitution is an eliminator of x in t. The set of eliminators of x in t is denoted by SE (x; t; M).
Example 7 Let us consider the Boolean term t = x + y. The substitution = fy 7! xg is an eliminator of x in t. The term > is eliminating x in t. The substitution = fy 7! x + z g is also an eliminator but is more general than .
De nition 8 A set of terms is a complete set of terms eliminating x in t w.r.t frozen variables M, denoted by CSTE (x; t; M), if (1) CSTE (x; t; M) STE (x; t; M). xg u. (2) 8u 2 STE (x; t; M) 9s 2 CSTE (x; t; M); s M[f AF A CSTE (x; t; M) is minimal if two terms of CSTE (x; t; M) cannot be comxg pared with M[f AF . When such a set is at most a singleton, mgte(x; t; M) denotes this unique element.
A complete set of eliminators of x in t, denoted by CSE (x; t; M), is de ned just like for CSS . A term u eliminating x in t is built as follows: let Common(x; t) be the set of values of t independent of the value taken by x. Formally, Common(x; t) = \i2A V al(fx 7! [i]g(t)) where V al(t) = f(t) j 2 ASSAg. There is a strong connection between the inclusion on value sets and the subsumption quasiordering AF on terms: V al(u) V al(t) if and only if t AF u. If u does not contain x and t AF u then values of u are independent of those taken by x and are values of t. So V al(u) Common(x; t). Moreover, as shown next, there exists a term u satisfying V al(u) = Common(x; t): it is the most general term eliminating x in t.
Theorem 5 The problem of nding a complete set of most general terms eliminating x in t is unitary in (enriched) nite algebras.
If M = ; then mgte(x; t; ;) = Pi2A Ci(v) [S (i)]; where v is a new variable (v 2= V (t)) and S : A 7! Common(P x; t)Qis a surjective mapping. If M =6 ; then mgte(x; t; M) = (M) mgte(x; (t); ;). Again the computation of the most general eliminator with frozen variables is based on the remark that u 2 CSTE (x; t; M) if and only if for any instantiation of frozen variables, (u) 2 CSTE (x; (t); ;).
Example 8 If t is a Boolean term without frozen variable (M = ;) non equivalent to x, then we can choose mgte(x; t; ;) = v when Common(x; t) = f0; 1g, or mgte(x; t; ;) = 0 (resp. 1) when Common(x; t) = f0g (resp. f1g). Constraint solving w.r.t. frozen variables provides the most general eliminator: this is the most general solution of (t =? u) that does not instantiate x and v.
Theorem 6 The frozen variable elimination problem is unitary in (enriched) nite algebras. A unique most general eliminator of x in t is mgs(t =? mgte(x; t; M); M[ fx; vg) where M [ fvg are variables in mgte(x; t; M).
Example 9 Let t be the Boolean term x(y + yz)+ xyz. Since Common(x; t) = f0; 1g, we consider c = (t = v ) where x and v are frozen, that is: c00 = fx 7! 0; v 7! 0g(c) with Sol(c00) = fyzg. c01 = fx 7! 0; v 7! 1g(c) with Sol(c01) = fyz; yz; yzg. c10 = fx 7! 1; v 7! 0g(c) with Sol(c10) = fyz; yz; yzg. c11 = fx 7! 1; v 7! 1g(c) with Sol(c11) = fyzg. Hence mgs(c00) = mgs(c11) = fy 7! 1; z 7! 1g and mgs(c01) = mgs(c10) = fy 7! y ; z 7! y y g thanks to the mapping ?
1
1 2
c01(y1y2 ) = yz c01(y1 y2 ) = yz c01 (y1y2 ) = yz c01 (y1y2 ) = yz Finally, mgs(c; fx; v g) = fy 7! xv + xvy1 + xvy1 + xv; z 7! xv + xv y1 y2 + xvy1y2 + xvg.
5.3 Rules for combination
We adopt the methodology used in [7] to describe uni cation algorithms by sets of rules transforming conjunctions of equations. Rules for constraint solving in CC are given below. The parameters of these combination rules are: a constraint c: it is a conjunction of atomic constraints and equations. The constraint ci denotes the CLEi [Fi ; Pi]-constraint included in c, for i = 1; 2. two sets U1 and U2 of variables (initially empty) to "freeze", one for each equational theory Ei . U denotes the union U1 [ U2. two sets CV1 and CV2 of pairs of variables (initially empty) to record cycles, one for each equational theory Ei. CV denotes the union CV1 [ CV2.
The combination rules for constraint solving in CC
1. Solve c
c
^ ci; U; CV
^ ^l2Lxl =? sl ; U; CV
if fxl 7! sl gl2L 2 Solve(ci ; Ui; CVi ):
2. Variable Abstraction(Constraint) c ^ p(t1; : : : ; tj ); U; CV c ^ p(t1 ; : : : ; tl [x]! ; : : : ; tj ) ^ x =? tl j! ; U; CV 3. Variable Abstraction(Equation) c ^ s =? t; U; CV c ^ s =? t[x]! ^ x =? tj! ; U; CV 4. Impure Equation c ^ s =? t; U; CV c ^ x =? s ^ x =? t; U; CV 5. Variable Replacement
if
if
s x
if
( )2F is a new variable.
tl ! = x
( ) 2 Fi ; t() 2 Fj ; i 6= j is a new variable.
t ! x
2 T (F1; X )nX ; t 2 T (F2; X )nX is a new variable.
^ x =? y; U; CV fx 7! yg(c) ^ x =? y; fx 7! yg(U ); fx 7! yg(CV ) c
if x; y 2 V (c):
6. Freeze
c; Ui ; CV
c; Ui
[fxg; CV
if
x s
=? s, x =? t are equations in c 2 T (F1; X )nX ; t 2 T (F2; X )nX ;
2
x = U
i ; CVi Elim 2 c; Uc; [Uif;xCV 7. Elim 1 c; U [fyc;gU; CV g; CV i i [ f(y; x)g i if x =? t[y], where t 2 T (Fi; X )nX , is in a compound cycle in c. Rules Solve, Freeze and Elim introduce nondeterminism: one must try all branches to preserve a complete set of solutions. If E is a simple theory, that is a theory such that x =? t[x] has no solution, then rules Freeze and Elim may be deleted for this theory.
The rule Solve assumes the existence for each component of a "black-box" which transforms a pure constraint ci to its solved form. It performs the successive application of variable identi cation, solving with frozen variables and frozen variable elimination. De nition 9 Given ci a CLEi [Fi; Pi]-constraint, Ui a set of variables and CVi a set of pairs of variables, the set of restricted solutions of ci , denoted by Solve(ci; Ui; CVi), is the set of all substitutions 3 2 1 such that (1) 1 2 ID(Ui) = f jDom( ) Ui and Ran( ) Xg. (2) 2 2 CSS (1(ci ); VRan(1)). (3) 3 2 CSE (1(x); 2(y ); VRan(1)nf1(x)g) for all (x; y ) 2 CVi. The next completeness result can be derived from [1, 2]. Theorem 7 The process of applying the combination rules as long as possible starting from (c; ;; ;) terminates with any control and returns a complete set of solutions of c. Example 10 Let us consider the combination of the Commutative theory de ned by two function symbols fa; f g and the axiom C = ff (x; y ) = f (y; x)g, with the theory of the primal algebra 3 with function symbols f0; 1; 2; C0; C1; C2; +; g. The following equational constraint f (v; x) =? f (a; f (x; y)) ^y =? v w ^ x =? z (z + 1) where a is a free constant may be solved as follows: First, we solve the rst equation in the theory C . Then we obtain x =? a ^ v =? f (x; y) ^ y =? v w ^ x =? z (z + 1): The variable x is instantiated in both theories. So x must be frozen in 3 and the related equation solved. We obtain x =? a ^ v =? f (x; y ) ^ y =? v w ^ z =? x: There still exists a compound cycle v =? f (x; y ) ^ y =? v w which can be broken: At rst the variable v is frozen and two cases must be considered: (1) x and v are identi ed: it yields a =? f (x; y ) which has no solution. (2) v is eliminated in v w: it yields w =? C0(v ) z 0 and y =? 0. The new variable z 0 appears during the frozen variable elimination process. Finally we get the dag solved form x =? a ^ v =? f (x; y ) ^ y =? 0 ^ z =? x ^ w =? C0(v) z 0 and the corresponding solution fx 7! a; v 7! f (a; 0); y 7! 0; z 7! a; w 7! C0(f (a; 0)) z0g:
6 Conclusion A constraint solver for the combination of constraints on nite domains with AC -uni cation problems is being implemented in the software UNIF, developed at CRIN and INRIA-Lorraine. A feature to emphasize is that the implementation of the constraint solver on nite domains uses, as data structures, n-ary dags, a natural extension of binary decision graphs introduced by Bryant [3]. This data structure exactly re ects the set of assignments for a constraint and operations on these dags correspond to the constructions expressed by the uni cation algorithm in primal algebras. To conclude, let us mention some further ideas. The techniques used in this paper extend to pseudo-boolean constraints (equations and inequations between integer-valued functions f : f0; 1gn 7! Z ). Such constraint solvers can thus be combined with other uni cation algorithms with similar techniques. The combination of constraint solvers in two primal algebras is another application of the same techniques. It has interesting applications to hardware validation, for instance to mix speci cations of components using dierent primal algebras. As a more general goal, embedding in a constraint logic programming language a solver for combined theories is expected to lead to interesting applications when constraints must be solved in complex algebraic domains.
Acknowledgements: We sincerely thank the UNIF group in Nancy for fruitful
discussions.
References [1] A. Boudet. Uni cation dans les melanges de theories equationelles. Applica-
tion aux axiomes d'associativite, commutativite, identite et idempotence, aux anneaux Booleens, et aux groupes Abeliens. These de Doctorat d'Universite,
[2] [3] [4] [5] [6]
Universite de Paris-Sud, Orsay (France), February 1990. A. Boudet. Uni cation in a combination of equational theories: An ecient algorithm. In M. E. Stickel, editor, Proceedings 10th International Conference on Automated Deduction, Kaiserslautern (Germany), volume 449 of Lecture Notes in Computer Science. Springer-Verlag, July 1990. R. E. Bryant. Graph-based algorithms for boolean function manipulation. IEEE Transactions on computers, C-35(8):677{691, August 1986. W. Buttner, K. Estenfeld, R. Schmid, H.-A. Schneider, and E. Tiden. Symbolic constraint handling through uni cation in nite algebras. Applicable Algebra in Engineering, Communication and Computation, 1(2):97{118, 1990. A. L. Foster. Generalized "boolean" theory of universal algebras. Math. Zeitschr., Bd. 59:191{199, 1953. A. Herold. Combination of uni cation algorithms. In J. Siekmann, editor, Proceedings 8th International Conference on Automated Deduction, Oxford (UK), volume 230 of Lecture Notes in Computer Science, pages 450{469. SpringerVerlag, 1986.
[7] J.-P. Jouannaud and C. Kirchner. Solving equations in abstract algebras: a rule-based survey of uni cation. In J.-L. Lassez and G. Plotkin, editors, Computational Logic. Essays in honor of Alan Robinson, chapter 8, pages 257{321. MIT Press, Cambridge (MA, USA), 1991. [8] C. Kirchner. Methodes et outils de conception systematique d'algorithmes d'uni cation dans les theories equationnelles. These de Doctorat d'Etat, Universite de Nancy I, 1985. [9] C. Kirchner, H. Kirchner, and M. Rusinowitch. Deduction with symbolic constraints. Revue d'Intelligence Arti cielle, 4(3):9{52, 1990. Special issue on Automatic Deduction. [10] H. Kirchner and C. Ringeissen. Combining uni cation problems with constraint solving in nite algebras. Research Report 91-R-106, Centre de Recherche en Informatique de Nancy, 1991. [11] U. Martin and T. Nipkow. Boolean uni cation | the story so far. Journal of Symbolic Computation, 7(3 & 4):275{294, 1989. Special issue on uni cation. Part one. [12] T. Nipkow. Uni cation in primal algebras, their powers and their varieties. Journal of the Association for Computing Machinery, 37(1):742{776, October 1990. [13] A. Rauzy. Boolean uni cation: an ecient algorithm. Technical report, LABRI, University of Bordeaux 1, 1990. [14] O. Ridoux and H. Tonneau. Une mise en uvre de l'uni cation d'expressions booleennes. In Actes de SPLT'90, Tregastel. CNET, 1990. [15] C. Ringeissen. Etude et implantation d'un algorithme d'uni cation dans les algebres nies. Rapport de DEA, Universite de Nancy I, 1990. [16] C. Ringeissen. Uni cation in a combination of equational theories with shared constants and its application to primal algebras. In Proceedings of LPAR'92, Lecture Notes in Arti cial Intelligence. Springer-Verlag, 1992. [17] M. Schmidt-Schau. Combination of uni cation algorithms. Journal of Symbolic Computation, 8(1 & 2):51{100, 1989. Special issue on uni cation. Part two. [18] G. Smolka. Logic Programming over Polymorphically Order-Sorted Types. PhD thesis, FB Informatik, Universitat Kaiserslautern, Germany, 1989. [19] E. Tiden. Uni cation in combinations of collapse-free theories with disjoint sets of functions symbols. In J. Siekmann, editor, Proceedings 8th International Conference on Automated Deduction, Oxford (UK), volume 230 of Lecture Notes in Computer Science, pages 431{449. Springer-Verlag, 1986. [20] K. Yelick. Uni cation in combinations of collapse-free regular theories. Journal of Symbolic Computation, 3(1 & 2):153{182, April 1987.