Constraint Solving by Narrowing in Combined Algebraic Domains Helene Kirchner & Christophe Ringeissen
CRIN-CNRS & INRIA-Lorraine BP 239, 54506 Vanduvre-les-Nancy Cedex, France fHelene.Kirchner,
[email protected] Abstract Narrowing is a way to integrate function evaluation and equality de nition into logic programming. Here we show how this can be combined with the constraint paradigm. We propose a solver for goals with constraints in theories de ned by unconstrained equalities and rewrite rules with constraints expressed in an algebraic built-in structure. The narrowing method reduces the goal solving problem in the whole theory to rewriting and constraint solving in an adequate combined theory. The combined solver is obtained through the combination of a solver in the built-in structure and a solver for the unconstrained equalities. Sucient syntactic conditions are proposed to get a process that enumerates a complete set of solutions.
1 Introduction Narrowing provides integration of function evaluation and equality de nition into logic programming [6, 12, 8, 18, 10]. In this work, we show how this can be connected with the constraint paradigm to get a constraint solver on combined algebraic domains and to incorporate built-in structures like integers, booleans, nite elds, Post algebras, matrix rings over nite elds : : :. But in this context, it is needed to combine constraint solving in speci c theories with other function symbols that may be free or may have properties like commutativity and associativity. In [17, 20], we show how to combine a constraint solver in nite algebras with another uni cation algorithm by extending the techniques used to combine uni cation algorithms. Combination of matching algorithms can be derived in a similar way [21]. Matching and uni cation algorithms in the combination of built-in structures with abstract symbols satisfying equational properties are used to perform rewriting and narrowing with constrained rules, thus leading to a constraint solver in the theory associated to the rewrite system with constraints. In order to illustrate the kind of theories we want to deal with, let us consider an elementary example. Assume given a built-in algebra A of domain A with sort Nat, built-in functions F0 = f0; +g and predicates P0 = f=; >g. Declarations of functions are 0 :7! Nat; + : Nat; Nat 7! Nat. Declarations of predicates are >: Nat; Nat and =: Nat; Nat. This signature is then enriched by adding function symbols F1 = fgg where g a binary operation (g : Nat; Nat 7! Nat) is commutative i.e. satis es the set C of equalities fg(x; y) = g(y; x)g. In a model that combines these two signatures, the fonction g is axiomatized by a recursive de nition given This
work is partially supported by the Esprit Basic Research working group 6028, CCL.
by a set R of two rewrite rules with constraints g(x : Nat; 0) ! x : Nat g(x : Nat + y : Nat; y : Nat) ! g(x : Nat; y : Nat) k y : Nat > 0 This example illustrates the dierent problems to be solved. To compute with these rules, we need to combine constraint solving in the algebra A with uni cation or matching modulo a theory C axiomatically de ned. Here we build a congruence C that takes into account equality in A like 1 = 0 + 1 and commutativity of g. Then for instance, the value of g for arguments (1; 1) is computed as follows: g(1; 1)(C g(0 + 1; 1)) !R;C g(0; 1) !R;C 1: Note that the system does not terminate if the constraint is dropped. Indeed, since any natural x is equal to the natural x + 0, we would have the loop: g(x; 0) C g(x + 0; 0) ! g(x; 0): Then narrowing using R modulo C provides an abstract solver for this theory. But to be complete, termination and con uence in equivalence classes of the rewrite system with constraints must be checked. To achieve con uence, we require the constraints in the rules to be in the built-in language. This is naturally expressed within an order-sorted framework [7, 23] as in [1], where the built-in domain is a subsort of the whole domain of interest. Checking con uence modulo a congruence relation C requires C to be sort-preserving and !R sort-decreasing. Although these assumptions could be dropped as in [11, 4], they make proofs easier and are often satis ed in programming in a rewrite rule-based language like OBJ [9, 13]. To achieve termination, the argument is to nd a well-founded ordering compatible with C , but such an ordering does not always exist. In particular axiomatizations of integers or booleans involve collapse and non-regular axioms that prevent termination of rewriting in equivalence classes modulo C . To avoid any hypothesis on the axiomatisation of the built-in structure, the termination argument in our order-sorted context is based on the fact that a term is structured in levels with either built-in symbols or other function symbols. The number of levels must be preserved by C and must not increase by rewriting. The congruence C is closed under admissible substitutions that do not change the number of levels of a term and solutions for constraint are required to be admissible. So the paper is built as follows. - Section 2 state the de nition of constraint languages and introduces the three constraint solvers considered in this paper. - In Sections 3 and 4, an algebraic structure is de ned for making precise the domain in which constraint solving is performed. The proposed structure is a quotient algebra using a congruence relation generated by A-equality and equality modulo C. A constraint solver in this structure is built by adapting tools for combining uni cation algorithms. - Thanks to the restricted form of constraints in the original set of rules, the local con uence and coherence of the rewrite relation with constraints can be checked on critical pairs with constraints in Section 5. - Given a con uent and terminating rewrite relation in congruence classes, narrowing with constraints can be proved correct and complete for solving goals in the theory de ned by the constrained rewrite rules. We thus get another constraint solver based on narrowing which uses both rewrite rules and the previous combined solver. This is developed in Section 6. All proofs omitted in this paper can be found in [16].
2 Constraint languages We rst adopt a general de nition of a symbolic constraint language and its solver, and then introduce the dierent constraint languages used in this paper. Let (S ; ) be an ordered set of sort symbols, F be a set of function symbols, P a set of predicate symbols, D be a set of subsort declarations (DS = fs s0 j s; s0 2 Sg), function declarations (DF = ff : s1 : : :sn 7! s0 j s1 : : :sn ; s0 2 S ; f 2 Fg), and predicate declarations (DP = fp : s1 : : :sn j s1 : : :sn 2 S ; p 2 Pg). X denotes a set of sorted variables denoted (x : s). An order-sorted signature is given by an ordered set of sorts S , a set of function symbols F , a set of predicate symbols P , and a set of subsort, function and predicate declarations D. Let A be an (S ; F ; DS [ DF )-algebra, whose carrier is denoted by A. T (; X ) is the free (S ; F ; DS [ DF )-algebra over X , whose carrier is the set of terms. The set of variables occurring in a term t is denoted by V (t). An order-sorted equational theory (; E) is given by an order-sorted signature and a set of universally quanti ed equalities E. is a lowest-sorted signature if every -term t has a lowest sort ls(t). (; E) is sort-preserving if 8t; t0 2 T (; X ); t =E t0 =) ls(t) = ls(t0 ). An order-sorted rewrite system (; R) is given by an ordersorted signature and a set of universally quanti ed rewrite rules R. (; R) is sort-decreasing if 8t; t0 2 T (; X ); t !R t0 =) ls(t) ls(t0 ). These properties are easily decidable and sucient syntactic conditions on the signature are given for instance in [7]. A rst-order algebraic -structure A is given by - a carrier A which is a collection of non-empty sets (As )s2S , such that As As0 when (s s0 ) 2 S , - for each function symbol in F with a rank f : s1 ; : : :; sn 7! s, a function fA from As1 : : : Asn to As , - for each predicate symbol except = in P with a rank p : s1 ; : : :; sn , a relation pA on As1 : : : Asn . Whenever contains the predicate symbol =, it will be interpreted as the equality relation in A. An assignment is a mapping from X to A that assigns to a sorted variable (x : s) an element of As ; it uniquely extends to an order-sorted homomorphism from T (; 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 endomorphism of T (; X ) from a nite set of variables Dom() = f(x : s)j(x : s) 2 X and (x : s) 6= (x : s)g that are not mapped to themselves, such that 8(x : s) 2 Dom(), ls((x : s)) s. From now on, we assume that all substitutions are -substitutions. We use letters ; ; ; ; : : : to denote substitutions. We call range of the set of terms Ran() = [(x:s)2Dom() (x : s) and variable range of the set of variables VRan() = [(x:s)2Dom() V ((x : s)). A substitution is idempotent if = . The de nition of constraint languages adopted in this paper is an instance of those given in [22, 15].
De nition 1 Let = (S ; F ; P ; D) be an order-sorted signature, X a set of variables, a constraint language LK [; X ] (or LK for short) is given by: a set of constraints which are conjunctions of elementary constraints built over and variables X , the empty conjunction > and the unsatis able constraint ?. Constraints are syntactically distinguished by a question mark exponent on predicates. The set of free variables of the constraint c is denoted V (c).
An interpretation K is an order-sorted -structure 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 (>) = f 2 ASSKX g - SolK (?) = ; - SolK (t1 =? t2) = f 2 ASSKX j (t1 ) = (t2 )g - SolK (t1 6=? t2) = f 2 ASSKX j (t1 ) 6= (t2 )g - SolK (p? (t1 ; : : :; tm )) = f 2 ASSKX j ((t1 ); : : :; (tm )) 2 pK g for p 62 f=; 6=g - SolK (c ^ c0 ) = SolK (c) \ SolK (c0 ). An assignment in SolK (c) is a solution of c in LK . A constraint c is valid in LK , written LK j= c, if any assignment is a solution of c in LK . Two constraints c and c0 are equivalent (denoted by c K c0) if SolK (c) = SolK (c0). We also make precise the notions of symbolic solutions and complete sets of symbolic solutions for a given constraint. A symbolic solution of a LK [; X ]constraint c is a substitution such that LK j= (c). The set of all symbolic solutions of c is denoted SSK (c). A substitution is an instance on V X of a substitution , written VK , if there exists some substitution such that 8x : s 2 V; LK j= (x : s) = ((x : s)).
De nition 2 A set of substitutions is a complete set of symbolic solutions of the LK [; X ]-constraint c, denoted by CSSK (c), if (1) 8 2 CSSK (c); Dom() \ VRan() = ; (idempotency). (2) CSSK (c) SSK (c) (correctness). (3) 8 2 SSK (c); 9 2 CSSK (c); KV c (completeness). ( )
In this paper, three dierent constraint languages will be considered:
(1) LA denotes the built-in language, whose syntax is given by an order-sorted signature and a set of variables X . The interpretation is the -structure A. A built-in constraint solver is assumed given for LA . (2) A combined language LC is an enrichment of LA based on a signature and a set of variables X . Equalities C de ne properties, such as associativity and commutativity, satis ed by newly introduced symbols. The interpretation is a algebra which is a consistent enrichment of A. It is built as a quotient of the set of -terms by a congruence generated from C and theorems valid in A. Constraints in 0
0
0
0
LC involve constraints c in LA and equations to solve modulo C, but more generally they are conjunctions of constraints built with the same predicates as in LA and terms in the whole enriched signature and variables in X . A constraint solver for LC is built from the constraint solver in LA and from a uni cation algorithm for C by adapting the combination techniques for uni cation algorithms. (3) A constrained rule language LR;C is based on the same signature 0 and variables X . Additional properties of symbols from n0 are de ned using a set R of constrained rewrite rules. These rules are assumed to have constraints expressed only in LA . This restriction allows building the interpretation as a -algebra which is again a consistent enrichment of A. Constraints in LR;C are goals with constraints of the form (p? (t1 ; : : :; tn) k S) where p 2 0 , t1 ; : : :; tn are -terms and S is a conjunction of LC -constraints. A constraint solver for LR;C is based on constrained narrowing that reduces the constraint solving problem in LR;C to rule application and constraint solving in LC .
3 The built-in language In order to stay as general as possible, we consider built-in structures with several sorts and possible inclusions. De nition 3 Let 0 = (S0; F0; P0; D0) be an order-sorted signature, X0 a set of sorted variables and A a 0 -structure. A is said built-in if A is term-generated and there exists a biggest sort s which coincides with the carrier A. Built-in constraints will be built from this signature.
De nition 4 The built-in language denoted by LA is de ned by the order-sorted signature = (S ; F ; P ; D ), the set of sorted variables X , and the built-in -structure A. The set of all equalities that holds in A is denoted Th(A). Notation: Sort, function and predicate symbols from are said built-in. Terms and constraints built on LA are called built-in terms and built-in constraints. Variables of X are called built-in variables. 0
0
0
0
0
0
0
0
0
Typically useful built-in structures are integers, booleans and Post algebras.
4 The combined language The signature 0 is now enriched by new sort and function symbols into a signature = (S ; F ; P ; D) such that S S0 , F F0 and P = P0 . Let us de ne F1 = FnF0, S1 as the set of sorts in the rank of function symbols of F1, D1 = DnD0 , and 1 = (S1 ; F1; f=g; D1). Note that the signatures 0 and 1 have by construction disjoint function symbol sets but possibly non-disjoint sort symbol sets, and only share the equality predicate. The set of built-in variables X0 is also extended to a set of variables X thanks to a set of variables X1 of sorts S1 nS0 such that X = X0 [X1. De nition 5 A term t of T (; X ) is i-pure (for i = 0; 1) 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(t1; : : :; tn) is i-pure (for i = 0; 1) if p 2 Pi and t1 ; : : :; tn are i-pure. A term with its top symbol in Fi is called i-term. Alien subterms of a i-term are j-(sub)terms (i 6= j) such that each pre x symbol is in Fi . The set of alien subterms of t is denoted AST(t). De nition 6 The number of 1-levels in a term P t, denoted by nc1 (t) is inductively de ned by: nc 1 (x) = 0 if x 2 X , nc1 (t) = 1 + s2AST (t) nc1(s) if t() 2 F1 else P nc1(t) = s2AST (t) nc1(s).
4.1 Hypotheses
We assume that function symbols from F1 have properties expressed by a set of 1-equalities C, such as commutativity and (or) associativity. We now have to consider the combination of two order-sorted equational theories (0; E0) and (1 ; E1), where E0 is the set of equalities Th(A) valid in A, and E1 is a set of 1-axioms. Both are assumed consistent. Beyond the hypothesis of disjoint function symbols, we also need the hypothesis that new sorts of S1 are not lower than s and S0 \ S1 fs g. This is required to build a conservative extension. With respect to axioms (g = d) in E1, we also require several properties, namely to be regular
(V (g) = V (d)), collapse-free (g; d 2= X ) and sort-preserving. These hypotheses are needed to work with order-sorted rewriting modulo a congruence relation on terms built on the union of both signatures 0 [ 1. In order to de ne an interpretation for the combined language, we need to build a congruence relation on T (; X ) and to de ne the interpretation of predicates.
4.2 Congruence on combined terms
The problem is due to the fact that we do not want to put any syntactic hypothesis like regularity or non-collapsing on axioms in Th(A) since the built-in theory must be any theory. But in order to rewrite and perform narrowing modulo this congruence, we need to avoid cycles on equivalence classes. They could appear for instance by application of non-regular or collapse axioms in Th(A) to a term of basic sort but involving symbols from F1 . Example 1 In the example of the introduction, Th(A) contains the equality on natural numbers x 0 = 0 (non-regular), or x + 0 = x (collapse). The proposed solution is to restrict =E0 [E1 so that the top symbol theory and number of 1-levels are preserved in two equivalent terms. De nition 7 The relation C is de ned by: t C t0 if t =E0[E1 t0, t(); t0 () 2 Fi [ X and nc1(t) = nc1(t0 ). It is worth emphasizing that with this de nition no 1-term can be equivalent with C to a 0-term. Example 2 (Example 1 continued). We have g(x; y) + g(y; z) C g(y; z) + g(x; y), g(x + y; z) C g(y + x; z) but g(x; y) + 0 6C g(x; y), g(x; y) 0 6C 0.
4.3 Abstraction
Interpretation of predicates needs the notion of variable abstraction which consists of replacing alien subterms by new variables such that equivalent terms are replaced by the same variable. For this purpose, we introduce a convergent rewrite relation !Rc with the same expressivity as the union of both theories (0 [ 1 ; E0 [ E1). Let = 0 [1 and > be a simpli cation ordering total on T ([X ), such that variables are minimal. Let Ei> be the set of orientable instances, l = (g) ! (d) = r, where g; d 2 T (i ; X ) and g =Ei d. These rules are used to de ne a combined rewrite relation !Rc =!E0> [ !E1> which is convergent and simulates =E0 [E1 i.e. t =E0 [E1 t0 () t #Rc = t0 #Rc [16]. De nition 8 A variable abstraction is a one-to-one mapping from the set of non-variable terms in Rc -normal forms T #Rc = fu #Rc ju 2 T ( [ X ) and u #Rc 2 T ( [ X )nXg to a subset of variables of X such that (u #Rc ) = x : s . ?1 denotes the substitution with a possibly in nite domain which corresponds to the inverse of . Given a term t, the i-abstraction ti of a term t is a well-formed term, inductively de ned as follows: if t = x : s 2 X then ti = x : s, if t = f(s1 ; : : :; sp ) and f 2 Fi then ti = f(s1 i ; : : :; sp i ), else if t #Rc 2= X then ti = (t #Rc ) else ti = t #Rc . Given a substitution , i denotes its i-abstraction de ned by i (x) = ((x))i for any variable x 2 Dom().
Example 3 In the example of the introduction, g(x + 1; y)1 = g(v ; y) if (x + 1 #Rc ) = v and (g(x; y)+g(y; x)+1)0 = v +v +1 if (g(x; y) #Rc ) = (g(y; x) #Rc 0
1
0
) = v1 .
1
4.4 Extension of the built-in language
De nition 9 The combined language denoted LC is de ned by the order-sorted signature = [ , the set of sorted variables X , and the -structure C = T (; X )= C . If p 2 P then the interpretation of p in C is the relation pC de ned by pC (t ; : : :; tn) if LA j= p(t0 ; : : :; tn0 ). This de nition is compatible with equality in C : indeed if tk =E0 [E1 sk , their 0
1
0
1
1
abstractions verify tk0 =A sk0 . According to the chosen interpretation of predicates, validity of 0-pure atomic constraints is preserved in the interpretation.
Proposition 1 [16] LC is a conservative extension of LA i.e. LA j= c , LC j= c 0
if c0 is 0-pure.
0
The congruence C is not preserved under substitutions in general, but it is if we restrict to substitutions that do not change the number of 1-levels, which is achieved when terms in their range always have at most one 1-level. In particular built-in variables are instantiated by built-in terms.
De nition 10 The set of admissible -substitutions is SUBST = f = j Dom( ) X ; Ran( ) T ( ; X ); Dom( ) X ; Ran( ) T ( ; X )g. 0
1
1
1
1
0
0
0
1 0
0
0
Since E1 does not contain collapse axioms, two admissible substitutions are equivalent modulo C i they are equivalent modulo =E0 [E1 . For a given constraint c, we restrict our attention to the set of its admissible solutions SSC (c) = SSC (c) \ SUBST0 . A complete set of admissible solutions of a LC -constraint c is denoted CSSC (c). Our goal now is to build a constraint solver for LC from the built-in solver available for LA and from a uni cation algorithm for E1 . We rst transform a problem in LC into another one expressed with =E0 [E1 , and then extract admissible solutions. From the de nition of the congruence C , it is easy to check the following facts for two terms t; t0 and an admissible substitution : (1) If t(); t0() 2 Fi and nc1 (t) = nc1 (t0 ), then (t) C (t0 ) i (t) =E0 [E1 (t0 ). (2) If t 2 X and nc1(t0 ) 1, then (t) C (t0 ) i (t) =E0 [E1 (t0 ). (3) In all other (non-symmetric) cases, there is no admissible s.t. (t) C (t0). We are now left to solve constraints with respect to the equational theory =E0 [E1 .
4.5 Combination principles
We recall here what are the main steps for combining two uni cation algorithms or procedures, which requires more than a blind use of each algorithm. The technique [2] is based on the next built-in steps: (1) 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. To avoid this problem, all possible choices for instantiating a variable in a theory have to be considered. When a
variable is instantiated in Ei , it is considered as a constant in Ej , j 6= i. The second problem due to abstraction is that two distinct variables may be introduced that actually denote two equal or equivalent terms. This needs to perform all possible variable identi cations after the abstraction step. A variable identi cation is just a substitution whose range is a set of variables. De nition 11 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 . (2) Solving pure constraints in the related language is obviously correct. For the completeness part, we need the following result proved in [16]. Proposition 2 Let p(t1 ;: : :; tn) be a 0-pure atomic constraint and a Rc-normalized substitution. Then LC j= p((t1 ); : : :; (tn)) , LA j= p(0 (t1); : : :; 0 (tn )). As a consequence, we yet have that CSSA (c0) is a CSSC (c0 ) if c0 is a 0-pure constraint. (3) Recombining the solutions obtained in each component is performed by propagation of the values. But cycling equations between two theories 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. The problem is avoided by a priori choosing a linear ordering < on the set V [ C of all variables and constants occurring in the constraint. Then to each constant a is associated a set of variables Va = fx j x 2 V and x < ag. Solving a constraint w.r.t. a linear restriction < is nding symbolic solutions s.t. 8x; a with x 2 Va , then a does not occur in (x) and (a) = a. The set of symbolic solutions of a i-pure constraint ci w.r.t. a linear restriction < on V1 [ V2 is denoted SSE 0 which has no solution, and x0 =? y ^ x + y =? 0 ^ y > 0 which has no solution either.
Transition rules for checking local con uence and coherence modulo C are given below.
Deduce CE; CR [ f(g ! d k c0 ); (l ! r k c)g 7! 7! CE [ fg[r]! = d k c ^ c0 ^ (gj! =?C l)g; CR [ f(g ! d k c0 ); (l ! r k c)g if c ^ c0 ^ (gj! =?C l) satis able
Extend [ f(l ! r k c)g 7! 7! CE [ fg[r]! = d k c ^ (gj! =?C l)g; CR [ f(l ! r k c)g if (g = d) 2 C and c ^ (gj! =?C l) satis able
CE; CR
Propagate Delete Simplify CE [ f(p = q k S )g; CR CE [ f(g = d k S )g; CR CE [ f(p = q k S )g; CR 7! 7! 7! 7! 7! 7! CE [ f((p) = (q) k c)g; CR CE [ f(g0 = d k S )g; CR CE; CR if p C q or S unsatis able if S C c ^ ^ and c 2 LC if g !R;C g0 The correctness of these rules is stated in the next theorem proved in [16]. Theorem 2 If there exists a nite derivation (;; R)S7! 7!(CE1; R) 7! 7! : : : 7! 7!(CEi; R) such that CEi = ; and CCP(R) [ CCE(R) 0j i CEj , then R is locally con uent and coherent modulo C .
Theorem 3 Assume that R is a set of rewrite rules with built-in constraints. If the relation !R;C is convergent modulo C , M is a consistent enrichment of A. Proof: Consider two elements a; a0 of A equal modulo R;C . Then a ?! R;C w C w0 ?R;C a0 . But no rule in R and no equality in C can apply on a neither on a0 , so a A a0. 2
5.4 Interpretation of predicates
From now on, we assume that R is convergent modulo C . Validity modulo !R=C then corresponds to validity modulo C after normalization w.r.t. !R;C . This allows interpreting predicates of P0 in M.
De nition 19 The constraint language LR;C associated to the speci cation (; R; C; LA) is de ned by the signature , the interpretation M and the set of variables X . If p 2 P then the interpretation of p in M is the relation pM de ned by pM(t ; : : :; tn) if LC j= p(t #R;C ; : : :; tn #R;C ). This de nition of predicates is obviously compatible with R;C since !R;C is convergent modulo C . The following result states that a constraint valid in LC is 0
1
1
still valid in LR;C .
Proposition 5 [16] If LC j= p(t ; : : :; tn) then LR;C j= p(t ; : : :; tn). Proof: (Sketch) If LC j= p(t ; : : :; tn) then LA j= p(t0 ; : : :; tn0 ). According to our assumptions on R, we can prove that p((t #R;C )0 ; : : :; (tn #R;C )0 ) is an Ainstance of p(t0 ; : : :; tn0 ). So, LA j= p((t #R;C )0 ; : : :; (tn #R;C )0 ), LC j= p(t #R;C ; : : :; tn #R;C ) and LR;C j= p(t ; : : :; tn). 2 1
1
1
1
1
1
1
1
1
6 Constrained narrowing We now consider the constraint solving problem in the language LR;C . The idea is to de ne a process of constrained narrowing to enumerate solutions of goals expressed in this language. This provides an incremental way to build constraint solvers, since the method allows building a constraint solver in LR;C from a constraint solver in LC . Similar de nitions of constrained narrowing have been introduced in dierent contexts by [5, 3]. Constrained narrowing is de ned on formulas called goals with constraints and of the form (9X; p? (t1 ; : : :; tn) k S) where X denotes a set of existentially quanti ed variables, p? (t1; : : :; tn) is an atomic constraint such that p 2 P0 to solve in LR;C , and S is a constraint to solve in LC . V (G) denotes the set of all variables occurring in a goal G. De nition 20 The set of solutions modulo R;C of a goal G = (9X; p? (t1 ;: : :; tn)kS) is de ned by SOLR;C (G) = fjV (G)nX j 2 SSC (S) and LR;C j= p((t1 );: : :; (tn ))g. The set of solutions modulo C of a goal G = (9X; p? (t1; : : :; tn)kS) is de ned by SOLC (G) = fjV (G)nX j 2 SSC (S ^ p(t1;: : :; tn))g.
6.1 Correctness
From now on, for a better readability, we restrict to atomic constraints with a binary predicate like for example =; 6=; ) ; G1 ; : : : ; Gn = (9Xn ; p?(gn ; dn)kSn ); then SOLC (Gn) SOLR;C (G0).
6.2 Completeness
The aim is now to prove that given a goal G0 = (9;; p?(g0; d0)k>), for any solution 2 SOLR;C (G0), there exists a narrowing derivation G0 = (9;; p? (g0 ; d0)k>) ; G1 ; : : : ; Gn = (9Xn ; p?(gn; dn)kSn ) such that 2 SOLC (Gn ). Lemma 1 Let Gi = (9Xi ; p?(gi; di)kSi ) a goal and i a substitution de ned and normalized for !R;C on V (Gi ). If i 2 SSC (Si ) and i (p?(gi ; di)) is reducible with !R;C , then there exist a reduction i (p? (gi ; di)) !R;C p?(u; v), a narrowing step Gi = (9Xi ; p?(gi ; di)kSi ) ; Gi+1 = (9Xi+1 ; p?(gi+1 ; di+1)kSi+1 ) and a substitution i+1 de ned and normalized for !R;C on V (Gi+1 ), such that i+1 2 SSC (Si+1 ), i+1 (p? (gi+1; di+1)) C p? (u; v) and i+1 =V (Gi )nXi i
Proof: If i (p?(gi ; di)) !R;C p? (u; v), there exists a position ! say in i (gi ) (or i(di )), a rule (l ! rkc) 2 R, and a substitution such that i (gi )j! C (l), 2 SSC (c), u = i (gi)[(r)]! . Since i is normalized for !R;C , we have i (gi )j! = i(gij! ). So gij! and l are uni able modulo C and c ^ gij! =?C l is satis able modulo C . Since there exists an innermost normalizing reduction strategy, we can assume w.l.o.g. that is de ned and normalized for !R;C on V (l ! rkc), with (V (Gi ) [ VRan(i )) \ V (l ! rkc) = ;. The substitution i+1 de ned on V (Gi+1 ) by i+1 =V (Gi ) i, i+1 =V (l=rkc) is normalized for !R;C . Moreover i+1 = i 2 SSC (Si+1 ), i+1 (p? (gi+1 ; di+1)) = i+1 (p?(gi [r]! ; di)) C p?(u; v) and i+1 =V (Gi )nXi i . 2 Lemma 2 Let Gi = (9Xi ; p?(gi; di)kSi ) a goal and i a substitution de ned and normalized for !R;C on V (Gi ). If i 2 SSC (Si ) and i (p? (gi; di)) is reducible + for !R=C , then there exist a reduction i (p? (gi; di)) ?! R=C p? (s; t) where s; t are irreducible with !R=C , a narrowing derivation
Gi = (9Xi ; p? (gi; di)kSi ) ; Gi+1 ; : : : ; Gk = (9Xk ; p?(gk ; dk)kSk ) and a substitution k de ned and normalized for !R;C on V (Gk ), such that k 2 SSC (Sk ), k (p? (gk ; dk )) C p? (s; t) and k =V (Gi )nXi i . Proof: By ntherian induction on !R=C . If i (p? (gi ; di)) is reducible with !R=C then it is also reducible with !R;C since !R;C is coherent with C and !R=C terminates. So i (p? (gi; di)) is reducible with !R;C and according to Lemma 1, there exists a reduction i (p? (gi ; di)) !R;C p? (u; v), a narrowing step Gi ; Gi+1 and a substitution i+1 de ned and normalized for !R;C on V (Gi+1 ) such that i+1 2 SSC (Si+1 ), i+1 (p? (gi+1; di+1)) C p? (u; v) and i+1 =V (Gi )nXi i. If p?(u; v) is irreducible with !R=C then we take k=i+1. Otherwise i+1 (p?(gi+1 ; di+1)) is reducible with !R=C and by induction hypothesis, there exists a reduc+ tion i+1(p? (gi+1 ; di+1)) ?! R=C p? (s0 ; t0) where s0 ; t0 are irreducible with !R=C , a narrowing derivation Gi+1 ; : : : ; Gk = (9Xk ; p?(gk ; dk )kSk ); and a substitution k de ned and normalized for !R;C on V (Gk ) such that k 2 SSC (Sk ), k (p? (gk ; dk )) C p?(s; t) and k =V (Gi+1 )nXi+1 i+1 . Since V (Gi+1 )nXi+1 = V (Gi )nXi and i+1 =V (Gi )nXi i, we have k =V (Gi )nXi i . 2 Theorem 4 Let G0 = (9;; p?(g0 ; d0); >) be a goal and 0 be a substitution de ned and normalized for !R;C on V (G0 ). If 0 2 SOLR;C (G0 ) then there exists a narrowing derivation G0 = (9;; p?(g0 ; d0)k>) ; G1 ; : : : ; Gn = (9Xn ; p?(gn ; dn)kSn ) such that 0 2 SOLC (Gn). Proof: If 0(p? (g0 ; d0)) is irreducible with !R;C then LR;C j= 0 (p(g0 ; d0)) implies LC j= 0(p(g0 ; d0)) by de nition of LR;C . If 0(p? (g0 ; d0)) is reducible with !R;C then it is also reducible with !R=C . According to Lemma 2, there exist a reduction + 0(p? (g0; d0)) ?! R=C p? (s; t) where s; t are irreducible with !R=C , a narrowing derivation G0 = (9;; p?(g0 ; d0)k>) ; G1 ; : : : ; Gn = (9Xn ; p?(gn ; dn)kSn ) and a normalized substitution n such that n 2 SSC (Sn ), n (p?(gn ; dn)) C p?(s; t) and n =V (G0 ) 0 . The terms s and t are normalized for !R;C and LR;C j= p(s; t) by hypothesis on 0 . Consequently, LC j= p(s; t) C n (p(gn; dn)), 0 = njV (Gn )nXn 2 SOLC (Gn). 2 Example 6 Consider the constraint language LB with the 0 -structure B of booleans with 0 = (fBoolg; f^; _ : Bool; Bool ! Bool; : Bool ! Bool; 0; 1 :!
Boolg; f=; 6=; ) where s; t are built-in terms. By narrowing G0, one get G0 ; G1 = (9x; xor(0; 0) = 6 ? xor(1; v)kxor(s; t) =? xor(x; x)) ; G2 = (9x; y; 0 =6 ? xor(1; v)kxor(s; t)=? xor(x; x) ^ xor(0; 0)=? xor(y; y)) ; G3 = (9x; y; z; 0 =6 ? zkxor(s; t) =? xor(x; x) ^ xor(0; 0) =? xor(y; y) ^xor(1; v) =? xor(z; 1)) such that SOLC (G3 ) = SSC (9x; y; z; 0 = 6 ? z ^ xor(s; t) =? xor(x; x) ^ xor(0; 0) =? xor(y; y) ^xor(1; v) =? xor(z; 1)) = SSC (9x; y; z; 0 = 6 ? z ^ x =? s =? t ^ y =? 0 ^ v =? z ) = SSC (0 = 6 ? v ^ s =? t) = SSB (0 =6 ? v ^ s =? t)
7 Conclusion We have presented a strati ed approach of constraint solving in presence of built-in structures thanks to narrowing and combination techniques. As a particular case we get constrained narrowing modulo an equational theory if the built-in structure is empty. The diculty was to nd the adequate combined constraint solver able to integrate a built-in structure without any assumption on it. The proposed solution is to restrict the form of solutions, which may appear as a limitation, but actually simpli es the complexity of the solver. Constrained narrowing already incorporates a part of strategy in its de nition, since it is essentially another formulation of basic narrowing [19]. How to combine it with various strategies, like innermost or lazy ones, and with normalization is certainly possible and useful in practice. This is an interesting topic for future work.
References
[1] J. Avenhaus and K. Becker. Operational speci cations with built-ins. In P. Enjalbert, E.W. Mayr, and K.W. Wagner, editors, Proceedings of STACS-94, volume 775 of LNCS, pages 263{274, Caen, (France), February 1994. Springer-Verlag. [2] Franz Baader and Klaus Schulz. Uni cation in the union of disjoint equational theories: Combining decision procedures. In Proc. 11th CADE Conf., Saratoga Springs (N.Y., USA), pages 50{65, 1992. [3] Jacques Chabin. Uni cation Generale par Surreduction Ordonnee Contrainte et Surreduction Dirigee. Th. univ., Universite d'Orleans, January 1994. [4] H. Comon. Completion of rewrite systems with membership constraints. In W. Kuich, editor, Proceedings of ICALP 92, volume 623 of LNCS. Springer-Verlag, 1992. [5] M. Fernandez. Narrowing based procedures for equational disuni cation. Applicable Algebra in Engineering, Communication and Computation, 3:1{26, 1992. [6] L. Fribourg. SLOG: A logic programming language intepreter based on clausal superposition and rewriting. In Proceedings of the IEEE Symposium on Logic Programming, pages 172{184, Boston, MA, July 1985. [7] I. Gnaedig, Claude Kirchner, and Helene Kirchner. Equational completion in ordersorted algebras. TCS, 72:169{202, 1990.
[8] J. A. Goguen and J. Meseguer. EQLOG: Equality, types, and generic modules for logic programming. In Douglas De Groot and Gary Lindstrom, editors, Functional and Logic Programming, pages 295{363. Prentice-Hall, 1986. An earlier version appears in Journal of Logic Programming, Volume 1, Number 2, pages 179{210, September 1984. [9] J. A. Goguen and T. Winkler. Introducing OBJ3. Technical Report SRI-CSL-88-9, SRI International, 333, Ravenswood Ave., Menlo Park, CA 94025, August 1988. [10] M. Hanus. Incremental rewriting in narrowing derivations. In H. Kirchner and G. Levi, editors, Proceedings 3rd International Conference on Algebraic and Logic Programming, Volterra (Italy), volume 632 of LNCS, pages 228{243. Springer-Verlag, September 1992. [11] C. Hintermeier, C. Kirchner, and H. Kirchner. Dynamically-typed computations for order-sorted equational presentations. research report, INRIA, Inria Lorraine & Crin, November 1993. [12] S. Holldobler. Foundations of Equational Logic Programming, volume 353 of LNAI. Springer-Verlag, 1989. [13] J.-P. Jouannaud, Claude Kirchner, Helene Kirchner, and A. Megrelis. Programming with equalities, subsorts, overloading and parameterization in OBJ. JLP, 12(3):257{ 280, February 1992. [14] J.-P. Jouannaud and Helene Kirchner. Completion of a set of rules modulo a set of equations. SIAM J. of Computing, 15(4):1155{1194, 1986. Preliminary version in Proceedings 11th ACM Symposium on Principles of Programming Languages, Salt Lake City (USA), 1984. [15] Claude Kirchner, Helene Kirchner, and M. Rusinowitch. Deduction with symbolic constraints. Revue d'Intelligence Arti cielle, 4(3):9{52, 1990. Special issue on Automatic Deduction. [16] H. Kirchner and Ch. Ringeissen. Constraint solving by narrowing in combined algebraic domains (extended version). research report, CRIN-CNRS and INRIA-Lorraine, 1993. [17] Helene Kirchner and Ch. Ringeissen. A constraint solver in nite algebras and its combination with uni cation algorithms. In K. Apt, editor, Proc. Joint International Conference and Symposium on Logic Programming, pages 225{239. MIT Press, 1992. [18] J. Moreno-Navarro and M. Rodriguez-Artalejo. Logic programming with functions and predicates: the language BABEL. JLP, 12(3):191{223, February 1992. [19] W. Nutt, P. Rety, and G. Smolka. Basic narrowing revisited. JSC, 7(3 & 4):295{318, 1989. Special issue on uni cation. Part one. [20] Ch. Ringeissen. Uni cation in a combination of equational theories with shared constants and its application to primal algebras. In Proc. 1st LPAR Conf., St. Petersburg (Russia), volume 624 of LNAI, pages 261{272. Springer-Verlag, 1992. [21] Ch. Ringeissen. Combination of matching algorithms. In P. Enjalbert, E.W. Mayr, and K.W. Wagner, editors, Proceedings of STACS-94, volume 775 of LNCS, pages 187{198, Caen, (France), February 1994. Springer-Verlag. [22] G. Smolka. Logic Programming over Polymorphically Order-Sorted Types. PhD thesis, FB Informatik, Universitat Kaiserslautern, Germany, 1989. [23] G. Smolka, W. Nutt, J. A. Goguen, and J. Meseguer. Order-sorted equational computation. In H. At-Kaci and M. Nivat, editors, Resolution of Equations in Algebraic Structures, Volume 2: Rewriting Techniques, pages 297{367. Academic Press, 1989.