, , 1{19 ()
c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands.
How to determine the expressive power of constraints PETER JEAVONS AND DAVID COHEN
[email protected] Department of Computer Science, Royal Holloway, University of London, UK MARC GYSSENS
[email protected] Department WNI, University of Limburg, B-3590 Diepenbeek, Belgium
Abstract. Some constraint languages are more powerful than others because they allow us to express a larger collection of problems. In this paper, we give a precise meaning to this concept of expressive power for constraints over nite sets of values. The central result of the paper is that the expressive power of a given set of constraint types is determined by certain algebraic properties of the underlying relations. These algebraic properties can be calculated by solving a particular constraint satisfaction problem, which we call an `indicator problem'. We discuss the connection between expressive power and computational complexity, and show that indicator problems provide a simple method to test for tractability. Keywords: Constraint satisfaction problem, complexity, relational algebra, NP-completeness, indicator problem
1. Introduction Some constraint languages are more powerful than others because they allow us to express a larger collection of problems. For example, if we are dealing with applications involving real-valued variables, then it is possible to express more numerical relationships using arbitrary polynomial equations than if we were restricted to using just linear equations. Similarly, if we are dealing with applications involving Boolean variables, then it is possible to express more logical relationships using ternary clauses than if we were restricted to using just binary clauses. Of course, the penalty for increased expressive power is generally an increase in computational complexity. For example, the satis ability problem with ternary clauses is NP-complete [6], whereas the satis abiliy problem involving only binary clauses can be solved in polynomial time [6]. More generally, the nite constraint satisfaction problem with arbitrary constraints is known to be NP-complete [13], whereas many families of restricted constraints have been identi ed which give rise to tractable subproblems [3, 9, 10, 11, 14, 17, 18]. For any given application, it therefore pays to select a constraint system which has sucient expressive power to express the desired constraints, but is suciently restrictive to allow an ecient solution technique. In this paper, we focus on problems with nite sets of possible values and examine how the expressive power of a given set of constraint types may be de ned. The central result of the paper is that the expressive power of a given set of constraint types is determined by certain algebraic properties of the corresponding relations.
2
We also show how these algebraic properties can be calculated by solving a particular constraint satisfaction problem, which we call an `indicator problem'. Finally, we discuss the connection between expressive power and computational complexity, and show that indicator problems provide a simple method to test for tractability. The paper is organised as follows. In Section 2 we give the basic de nitions, and describe a general form of algebraic closure property for a set of relations. In Section 3 we describe how to calculate these closure properties and in Section 4 we establish the close link between closure properties and expressive power. In Section 5 we discuss the relationship between expressive power and tractability. Finally, we summarise the results presented and indicate some directions for future research.
2. De nitions 2.1. The constraint satisfaction problem
A central notion in the study of constraints and constraint satisfaction problems is the idea of a relation, so we will make extensive use of the following notation. Notation 1 For any set D and any natural number n, we denote the set of all n-tuples of elements of D by Dn . For any tuple t 2 Dn and any i in the range 1 to n, we denote the value in the ith coordinate position of t by t[i]. The tuple t will be written in the form ht[1]; t[2];: ::; t[n]i. De nition 1.
A subset of Dn is called an n-ary relation over D.
Example 1 We now describe four relations which will be used as examples throughout the paper. Each of these relations is a set of tuples of elements from the set D = f0; 1; 2g, as de ned below: R1 = f h0; 0i; h1; 2i; h0; 1i; h2; 1i g R3 = f h0; 1i; h0; 2i; h1; 0i; h1; 1i; h1; 2i; h2; 0i; h2; 1i; h2; 2i g
R2 = f h0; 1; 2i; h1; 2; 0i; h2; 0; 1i g R4 = f h0; 1i; h0; 2i; h1; 0i; h1; 2i; h2; 0i; h2; 1i g
2
3
In order to manipulate and combine relations, we will make use of the following standard operations from relational algebra [2]: We de ne the following operations on relations. Let R1 be an n-ary relation over a set D and let R2 be an m-ary relation over D. The Cartesian product R1 R2 is de ned to be the (n + m)-ary relation R1 R2 = fht[1]; t[2]; :: :; t[n + m]i j (ht[1]; t[2];: ::; t[n]i 2 R1) ^ (ht[n + 1]; t[n + 2]; : : :; t[n + m]i 2 R2)g:
De nition 2.
Let R be an n-ary relation over a set D. Let 1 i; j n. The equality selection i=j (R) is de ned to be the n-ary relation i=j (R) = ft 2 R j t[i] = t[j]g:
Let R be an n-ary relation over a set D. Let i1 ; : : :; ik be a sequence of indices chosen from the values 1; : : :; n. The projection i1;:::;ik (R) is de ned to be the k-ary relation i1 ;:::;ik (R) = fht[i1 ]; : : :; t[ik ]i j t 2 Rg: We now de ne the ( nite) constraint satisfaction problem which has been widely studied in the Arti cial Intelligence community [12, 13, 14]. An instance of a constraint satisfaction problem consists of a nite set of variables, V ; a nite set of values, D; a set of constraints fC1; C2; : : :; Cq g. Each constraint Ci is a pair (si ; Ri), where si is a list of variables of length mi , called the constraint scope, and Ri is an mi -ary relation over D, called the constraint relation. De nition 3.
The tuples of the constraint relation Ri indicate the allowed combinations of simultaneous values for the variables in the corresponding scope si . The length of these tuples will be called the arity of the constraint. In particular, unary constraints specify the allowed values for a single variable, and binary constraints specify the allowed combinations of values for a pair of variables. Notation 2 For any set of relations, ?, the class of all constraint satisfaction problem instances in which the constraint relations are elements of ? will be denoted CSP(?).
4
Example 2 Let ? be the set of four relations, fR1; R2; R3; R4g, as de ned in Example 1. One element of CSP(?) is the constraint satisfaction problem instance, P , which has 6 variables and 3 constraints, de ned as follows: The set of variables is V = fv1; v2; v3; v4 ; v5; v6g; The set of values is D = f0; 1; 2g; The set of constraints is fC1; C2; C3g, where { C1 = ((v1 ; v3; v4); R2); { C2 = ((v2 ; v5; v4); R2); { C3 = ((v4 ; v6); R1). The structure of this problem instance is illustrated in Figure 1.
'x & v3
' x$ $ x x & % % x C2
C1
v1
2
x
v2
v4
v5
C3
v6
Figure 1. The CSP instance de ned in Example 2
A solution to a constraint satisfaction problem is a function from the variables to the values such that the combination of values assigned to the variables in each constraint scope is allowed by the corresponding constraint. For any given problem instance we may wish to:
5
decide whether a solution exists; or nd one solution, if any exist; or count the number of solutions; or nd all solutions. Each of these tasks may have a dierent complexity, so it is important to be precise about which version of the problem we are trying to solve. It is often convenient to view the solutions to a constraint satisfaction problem as tuples in a relation, as illustrated in the next example. This relation is the largest relation, S, such that the projection of S onto each constraint scope is a subset of the corresponding constraint relation. Example 3 The solutions to the constraint satisfaction problem instance P de ned in Example 2 are functions from the set of variables V to the set of values D which satisfy all of the constraints. There are four such functions, which may be expressed in tabular form, as follows: Variables v1 v2 v3 v4 v5 v6 Solution 1 0 0 1 2 1 1 Solution 2 1 1 2 0 2 0 Solution 3 1 1 2 0 2 1 Solution 4 2 2 0 1 0 2 This set of solutions may also be viewed as a relation, S, of arity 6, which has four tuples, corresponding to the four rows in the table. 2 2.2. Expressive power of constraints
In any constraint satisfaction problem instance some of the constraints are explicit, whilst others are generally present only as implicit constraints. For any instance in CSP(?), the explicit constraint relations must be elements of ?, but there may be implicit constraints on some subsets of the variables for which the corresponding relations are not elements of ?. These implicit constraints result from the combined eects of the explicit constraints, and so are said to be `derived' from these explicit constraints. We now de ne exactly what it means to say that a constraint relation can be derived from other constraint relations, and what is meant by `expressive power'. A relation R can be derived from a set of relations ? if it is equal to some projection of the set of solutions to some constraint satisfaction problem instance in CSP(?).
De nition 4.
Example 4 Reconsider the set of solutions S for the constraint satisfaction problem instance P , de ned in Example 2, as described in Example 3.
6
Note that 1;2(S) = fh0; 0i; h1; 1i; h2; 2ig, so this binary relation can be derived from fR1; R2g. 2 One way to view De nition 4 is as follows. For any relation R of arity r, and any collection of r variables, R can be derived from ? if and only if it is possible to construct a constraint satisfaction problem instance in CSP(?) which imposes the relation R on the values of those variables. In other words, R can be derived from ? precisely when there is some combination of the relations in ? that can be used to `express' a constraint with relation R. De nition 5. The set of all relations that can be derived from ? will be called the expressive power of ?.
We now show that the notion of a derived relation corresponds precisely to the notion of a relation which may be obtained using the operations described in De nition 2. Lemma 1 Let ? be a set of relations over a nite set D. A relation R can be derived from ? if and only if R can be obtained from the elements of ? together with the unary relation D1 , using some nite sequence of Cartesian product, equality selection, and projection operations.
Proof: ()) We rst need to show that if R is a projection of the set of solutions to some instance1 in CSP(?), then R can be obtained from ? [ fD1 g using some nite
sequence of Cartesian product, equality selection, and projection operations. It is shown in [7] that the set of solutions to any constraint satisfaction problem instance can be obtained by performing a relational join operation on the constraint relations (see De nition 2.8 of [7]). For any instance in CSP(?) the relations to be joined will either be elements of ?, or the unary relation D1 (in the case of variables with no explicit constraint speci ed). Furthermore, it is a standard result of relational database theory [2] that the join operation can be calculated by performing a sequence of Cartesian product, equality selection and projection operations. Hence R can be obtained using the speci ed relational operations. (() Conversely, if R can be obtained from ? [fD1 g using some sequence of Cartesian product, equality selection, and projection operations, then we need to show that R is equal to some projection of the set of solutions to some instance in CSP(?). To establish this, we rst note that, for each of the speci ed operations, it is straightforward to construct an associated constraint satisfaction problem instance P in CSP(?) such that the result of that operation is equal to some projection of the set of solutions to P . (The eect of the equality selection operation is achieved by identifying the corresponding variables in P .) By combining these constructions we can derive R from ?.
7
In view of this result, it will be convenient to introduce the following notation. Notation 3 Let ? be a set of relations over a set D. The set of all relations which may be obtained from ?, together with the unary relation D1 , using some nite sequence of Cartesian product, equality selection, and projection operations, will be denoted ?+ . Lemma 1 states that the set of relations ?+ is precisely equal to the expressive power of ?, as de ned above. 2.3. Closure properties of relations
We will show in Section 4 that the set of relations ?+ is determined by certain algebraic properties of ?. In order to describe these properties, we need to consider arbitrary operations on a set D, in other words, arbitrary functions from Dk to D, for arbitrary values of k. Any such operation on D may be extended to an operation on tuples over D by applying the operation in each coordinate position separately (i.e., pointwise). Hence, any operation de ned on a set may be used to de ne an operation on the tuples in a relation over that set, as follows: Let R be an n-ary relation over a set D, and let : Dk ! D be any k-ary operation on D. For any collection of k tuples, t1 ; t2; : : :; tk 2 R, (not necessarily all distinct) the n-tuple (t1 ; t2; : : :; tk ) is de ned as follows:
(t1 ; t2; : : :; tk ) = h (t1 [1]; t2[1]; : : :; tk [1]); (t1[2]; t2[2]; : : :; tk [2]); : : :; (t1[n]; t2[n]; : : :; tk [n])i:
De nition 6.
Using this de nition, we now de ne the following closure property of relations. De nition 7.
Let R be a relation over a set D, and let : Dk ! D be a k-ary
operation on D. R is said to be closed under if, for all t1; t2 ; : : :; tk 2 R (not necessarily all distinct),
(t1 ; t2; : : :; tk) 2 R:
Example 5 Let 4 denote the ternary operation which returns the rst repeated value of its three arguments, or the rst value if they are all distinct. The relation R2, de ned in Example 1, is closed under 4, since applying the 4 operation to any 3 elements of R2 yields an element of R2 . For example,
8
4(h0; 1; 2i; h1; 2;0i; h1; 2;0i) = h1; 2; 0i 2 R2: The relation R1, de ned in Example 1, is not closed under 4, since applying the 4 operation to the last 3 elements of R1 yields a tuple which is not an element of R1 :
4(h1; 2i; h0; 1i; h2;1i) = h1; 1i 62 R1: 2 Example 6 For any positive integer m, and any positive integer i m, let @m;i : Dm ! D denote the operation of arity m which returns the value of its ith argument. In other words, for all d1 ; d2; : : :; dm , @m;i (d1 ; d2; : : :; dm ) = di . Every relation R over D is closed under @m;i for all values of m and i, since applying the @m;i operation to any m elements of R simply returns the ith one. 2 For any set of relations ?, and any operation , if every R 2 ? is closed under
, then we shall say that ? is closed under . The next lemma indicates that the property of being closed under some operation is preserved by each of the operations on relations described in De nition 2. Lemma 2 Let R and R0 be relations which are closed under , for some operation
. The following relations are also closed under : 1. the Cartesian product, R R0 ; 2. any projection of R or R0; 3. any equality selection from R or R0.
Proof: Follows immediately from the de nitions. Relations which are closed under the same operations have many common properties, so we introduce the following notation. Notation 4 Let ? be a set of relations over a set D. The set of all relations over D which are closed under all of the operations under which ? is closed will be denoted ?.
3. Calculating Closure Operations In view of the results presented later in this paper, it is important to be able to calculate the closure operations for a given set of relations. In this section, we show that it is possible to obtain these operations, for each possible arity, by obtaining all solutions to a single constraint satisfaction problem instance. First note that, for any set of relations ? over a set D, the operations under which ? is closed are simply mappings from Dk to D, for some k, which satisfy certain
9
conditions, as described in De nition 7. This suggests that it should be possible to de ne a constraint satisfaction problem in which the variables are the elements of Dk , and the constraints impose the necessary conditions to ensure that the solutions are closure operations. This is the motivation for the idea of an `indicator problem' which is de ned as follows. Let ? be a set of relations over a nite set D. For any natural number m > 0, the indicator problem for ? of order m is de ned to be the constraint satisfaction problem instance IP (?; m) with set of variables Dm ; set of values D; set of constraints fC1; C2; : : :; Cq g, such that for each R 2 ?, and for each sequence t1; t2 ; : : :; tm of tuples from R, there is a constraint Ci = (si ; R) with si = (v1 ; v2; : : :; vn) where n is the arity of R and vj = ht1 [j]; t2[j]; : : :; tm [j]i.
De nition 8.
Note for any set of relations ? over a set D, IP (?; m) has jDjm variables and PR2?that m jRj constraints. Example 7 Consider the relation R1 over D = f0; 1; 2g, de ned in Example 1. The indicator problem for fR1g of order 1, IP (fR1g; 1), has 3 variables and 4 constraints. The set of variables is fh0i; h1i; h2ig; and the set of constraints is f ((h0i; h0i); R1); ((h0i; h1i); R1); ((h1i; h2i); R1); ((h2i; h1i); R1) g: The indicator problem for fR1g of order 2, IP (fR1g; 2), has 9 variables and 16 constraints. The set of variables is fh0; 0i; h0; 1i; h0;2i; h1; 0i; h1; 1i; h1;2i; h2; 0i; h2; 1i; h2;2ig; and the set of constraints is f ((h0; 0i; h0; 0i); R1); ((h0; 0i; h0; 1i); R1); ((h0; 0i; h1; 0i); R1); ((h0; 0i; h1; 1i); R1); ((h0; 1i; h0; 2i); R1); ((h0; 1i; h1; 2i); R1); ((h0; 2i; h0; 1i); R1); ((h0; 2i; h1; 1i); R1); ((h1; 0i; h2; 0i); R1); ((h1; 0i; h2; 1i); R1); ((h1; 1i; h2; 2i); R1); ((h1; 2i; h2; 1i); R1); ((h2; 0i; h1; 0i); R1); ((h2; 0i; h1; 1i); R1); ((h2; 1i; h1; 2i); R1); ((h2; 2i; h1; 1i); R1) g: 2
10
Example 8 Consider the relation R2 over D = f0; 1; 2g, de ned in Example 1. The indicator problem for fR2g of order 1, IP (fR2g; 1), has 3 variables and 3
constraints. The set of variables is
fh0i; h1i; h2ig; and the set of constraints is f ((h0i; h1i; h2i); R2); ((h1i; h2i; h0i); R2); ((h2i; h0i; h1i); R2) g: The indicator problem for fR2g of order 2, IP (fR2 g; 2), has 9 variables and 9 constraints. The set of variables is
fh0; 0i; h0; 1i; h0;2i; h1; 0i; h1; 1i; h1;2i; h2; 0i; h2; 1i; h2;2ig; and the set of constraints is f ((h0; 0i; h1; 1i; h2; 2i); R2); ((h0; 1i; h1; 2i; h2; 0i); R2); ((h0; 2i; h1; 0i; h2; 1i); R2); ((h1; 0i; h2; 1i; h0; 2i); R2); ((h1; 1i; h2; 2i; h0; 0i); R2); ((h1; 2i; h2; 0i; h0; 1i); R2); ((h2; 0i; h0; 1i; h1; 2i); R2); ((h2; 1i; h0; 2i; h1; 0i); R2); ((h2; 2i; h0; 0i; h1; 1i); R2) g:
2
Example 9 Consider the relations R1 and R2 over D = f0; 1; 2g, de ned in Example 1. The indicator problem for fR1; R2g of order 1, IP (fR1 ; R2g; 1), has 3 variables and 7 constraints. The set of variables is
fh0i; h1i; h2ig; and the set of constraints is equal to the union of the set of constraints of IP (fR1g; 1), as de ned in Example 7, and the set of constraints of IP (fR2g; 1), as de ned in Example 8. The indicator problem for fR1; R2g of order 2, IP (fR1 ; R2g; 2), has 9 variables and 25 constraints. The set of variables is
fh0; 0i; h0; 1i; h0;2i; h1; 0i; h1; 1i; h1;2i; h2; 0i; h2; 1i; h2;2ig;
11
and the set of constraints is equal to the union of the set of constraints of IP (fR1g; 2), as de ned in Example 7, and the set of constraints of IP (fR2g; 2), as de ned in Example 8. 2 Solutions to the indicator problem for ? of order k are functions from Dk to D, or in other words, k-ary operations on D. We now show that they are precisely the k-ary operations under which ? is closed. Theorem 1 For any set of relations ? over a set D, the set of solutions to IP (?; k) is equal to the set of k-ary operations under which ? is closed. Proof: By De nition 7, we know that ? is closed under the k-ary operation
if and only if satis es the condition that (t1 ; t2; : : :; tk ) 2 R for each possible choice of R 2 ? and t1 ; t2; : : :; tk 2 R (not necessarily all distinct). By De nition 8, this is equivalent to saying that satis es all the constraints in IP (?; k), so the result follows.
Example 10 Consider the relation R1 over D = f0; 1; 2g, de ned in Example 1. The indicator problem for fR1g of order 1, de ned in Example 7, has 2 solutions,
which may be expressed in tabular form as follows: Variables h0i h1i h2i Solution 1 0 0 0 Solution 2 0 1 2 Hence, by Theorem 1, fR1g is closed under precisely two unary operations: the constant operation with value 0, and the identity operation. The indicator problem for fR1g of order 2, de ned in Example 7, has 4 solutions, which may be expressed in tabular form as follows: Variables 0 0i
h
;
0 1i
h
;
0 2i
h
;
1 0i
h
;
1 1i
h
;
1 2i
h
;
2 0i
h
;
2 1i
h
;
2 2i
h
;
Solution 1 0 0 0 0 0 0 0 0 0 Solution 2 0 1 2 0 1 2 0 1 2 Solution 3 0 0 0 1 1 1 2 2 2 Solution 4 0 0 0 0 1 0 0 0 2 Hence, by Theorem 1, fR1g is closed under precisely four binary operations. 2 Example 11 Consider the relation R2 over D = f0; 1; 2g, de ned in Example 1. The indicator problem for fR2g of order 1, de ned in Example 8, has 3 solutions, which may be expressed in tabular form as follows: Variables h0i h1i h2i Solution 1 0 1 2 Solution 2 1 2 0 Solution 3 2 0 1
12
Hence, by Theorem 1, fR2g is closed under precisely three unary operations. The indicator problem for fR2g of order 3, has a very large number of solutions, including the operation 4, de ned in Example 5. Hence fR2g is closed under this ternary operation, as well as a large number of others. 2
4. Closure Operations and Expressive Power We have so far de ned two sets of relations which are associated with a given set ?: the set of relations which can be derived from ?, denoted ?+ , and the set of relations which share the same closure operators as ?, denoted ?. In this section, we will show that these two sets of relations, which are de ned in very dierent ways, are actually identical. Theorem 2 For any set of relations, ?, over a nite set D, ?+ = ?.
Proof: By Lemma 2, we know that the property of being closed under any operation is preserved by Cartesian product, projection, and selection operations. It follows immediately that ?+ ?. To obtain the reverse inclusion, let R = ft1; t2; : : :; tm g be any relation in ?. Construct the indicator problem for ? of order m, IP (?; m), and let S be the set of solutions to IP (?; m), viewed as a relation. Since every constraint relation in IP (?; m) is an element of ?, we know that S can be derived from ?, and hence S 2 ?+ by Lemma 1. We claim that R can be obtained as a projection of S, and hence R also belongs to ?+ , which gives the result. To establish this claim, let r be the arity of R, and let cj = ht1 [j]; t2[j]; : : :; tm [j]i for j = 1; 2; : : :; r. Each cj is an element of Dm , and hence corresponds to some variable of IP (?; m), and hence to some coordinate position, pj , of S. Let T = p1 ;p2 ;:::;pr (S). By the construction of T, each tuple of T is equal to the result of applying one solution of IP (?; m) to the sequence of tuples t1 ; t2; : : :; tm . Since R belongs to ?, we know that R is closed under all solutions of IP (?; m), by Theorem 1, so each tuple in T must belong to R. Hence, T R. Conversely, it was shown in Example 6 that every relation is closed under the operations @m;i , for i = 1; 2; : : :; m. Hence, by Theorem 1, each @m;i is a solution of IP (?; m), and so gives rise to a tuple in T. By the construction of T, and the de nition of @m:i , this tuple is equal to ti . Hence, R T. Hence R = T, which establishes the claim. Combining this result with Lemma 1, we have shown that the expressive power of a set of relations is determined by the corresponding set of closure operations. Corollary 1 A relation R can be derived from a set of relations ? over a nite
set D if and only if R is closed under all of the operations under which ? is closed.
13
Example 12 Reconsider the relations R1 and R2 over D = f0; 1; 2g, de ned in Example 1. It was shown in Examples 10 and 11 that R1 is not closed under all the operations under which R2 is closed. Hence, by Corollary 1, R1 cannot be derived from R2. Similarly, the results given in Examples 10 and 11 also establish that R2 cannot be derived from R1. 2
5. Expressive Power and Complexity We have seen that the expressive power of a set of relations is determined by their closure operations. To illustrate one application of these results, we now examine how they can be used to obtain information about the complexity of the class of problem instances involving a given set of constraint types. Deciding whether or not a given constraint satisfaction problem instance has a solution is NP-complete in general [13] even when the constraints are restricted to binary constraints. In this section, we shall consider how restricting the allowed constraint relations to some xed subset of all the possible relations aects the complexity of this decision. We shall therefore regard CSP(?) as a decision problem in which the question to be decided in each instance is the existence of a solution. If there exists an algorithm which decides every instance in CSP(?) in polynomial time, then we shall say that ? is a tractable set of relations. Example 13 The binary inequality relation over a set D, denoted =D , is de ned as =D = fhd1 ; d2i 2 D2 j d1 6= d2 g: Note that CSP(f=D g) corresponds precisely to the Graph jDj-Colorability problem [6]. This problem is tractable when jDj 2 and NP-complete when jDj 3. The relation R4 , de ned in Example 1, is equal to the relation =D for D = f0; 1; 2g. Hence, CSP(?) is NP-complete for any set of relations ? which contains R4 . 2 It turns out that certain special operations play a major role in distinguishing tractable and intractable sets of relations. These operations are the `essentially unary operations', which are de ned as follows. 6
6
6
6
An operation : Dk ! D is called essentially unary if there exists some non-constant unary operation f : D ! D and some i in the range 1 to k such that (d1 ; d2; : : :; dk ) = f(di ) for all d1; d2; : : :; dk. If f is a permutation, then is called essentially permuting. De nition 9.
Example 14 The operations @m;i , de ned in Example 6, are all essentially unary
operations. 2 Note that constant functions are excluded from De nition 9, and so are not essentially unary.
14
Theorem 3 Let ? be a set of relations over a nite set D.
If every operation under which ? is closed is essentially unary, then CSP(?) is NP-complete.
Proof: Assume that ? is only closed under essentially unary operations.
First, we note that if ? is closed under some essentially unary operation , then it is also closed under the corresponding (non-constant) unary operation f. Let f0 be a unary operation under which ? is closed such that jf0(D)j is minimal. Set f0 (?) = fff0 (t) j t 2 Rg j R 2 ?g. By the choice of f0 , and the assumption about ?, it follows that f0 (?) is only closed under essentially permuting operations. Since ? is not closed under any constant operation (by assumption), we know that jf0(D)j > 1. There are 2 cases to consider. In the case where jf0(D)j = 2, we consider the ternary `not-all-equal' relation, N, over D, (i.e., the relation containing all 3-tuples over D in which the 3 values are not all equal). The relation N is closed under all essentially permuting operations on D, which means that N 2 f0 (?). By Theorem 2 and Lemma 1, this implies that N may be derived from f0 (?). Hence, CSP(fN g) may be reduced to CSP(f0 (?)) in polynomial time. Now, CSP(fN g) is equivalent to the Not-All-Equal Satisfiability problem, which is known to be NP-complete [6, 15], so it follows that CSP(f0 (?)) is also NP-complete. In the case where jf0(D)j > 2, we consider the binary disequality relation, =f0 (D), de ned in Example 13. The relation =f0(D) is closed under all essentially permuting operations on D, which means that =f0 (D) 2 f0 (?). By Theorem 2 and Lemma 1, this implies that =f0 (D) may be derived from f0 (?). Hence, CSP(f=f0 (D) g) may be reduced to CSP(f0 (?)) in polynomial time. Now, CSP(f=f0 (D) g) is equivalent to the jf0(D)j-Colorability problem, which is known to be NP-complete when jf0(D)j > 2 [6], so it follows that CSP(f0 (?)) is also NP-complete. Finally, any instance in CSP(f0 (?)) has a solution if and only if the corresponding instance in CSP(?) has a solution, because ? is closed under f0 . Hence CSP(f0 (?)) is reducible to CSP(?) in polynomial time, which establishes that CSP(?) is also NP-complete. 6
6
6
6
6
6
If we assume that NP-complete problems do not have polynomial-time algorithms, then this result provides a necessary condition for tractability: a tractable set of relations must be closed under some operation which is not essentially unary. In fact, it was shown in [9] that all the currently known examples of tractable constraint types can be characterised as sets of relations which are closed under particular non-unary operations, even in those cases where they were originally de ned using very dierent criteria. For example, the `0/1/all' relations2 , rst described in [3, 11], can be characterised as the set of all relations closed under the operation 4, de ned in Example 5. As a second example, the various sets of `max-closed' relations, rst described in [10], can each be characterised as the set
15
of relations closed under a particular binary associative, commutative, idempotent operation [9]. We may sharpen the result of Theorem 3 a little further by bounding the possible arity of the closure operations on ? which we need to consider, as the next result shows. Theorem 4 For any set of relations ? over a nite set D, if ? is closed under some operation which is not essentially unary, then it is also closed under some operation ^ of arity at most maxf3; jDjg, which is not essentially unary.
Proof: (This proof is adapted from the proof of Lemma 1.14 in [16]). Let ? be a set of relations which is closed under some operation which is not essentially unary. Let ^ be an operation of the smallest possible arity, such that ? is closed under ^ and ^ is not essentially unary, and let k be the arity of ^ . If k 3, then the result holds, so we only need to consider the case where k 4. Now consider the operations which are obtained from ^ by identifying two arguments (i.e., requiring them to have the same value). Since ? is closed under these operations, which have a lower arity than ^ , they must all be essentially unary. Hence, if we identify the rst two arguments we have
^ (xz 1}|; x1{; x3; x4; : : :; xk) = f12(xi )
for some non-constant unary operation f12 and some i 2 f1; 2; : : :; kg. Similarly, if we identify the third and fourth arguments we have
^ (x1; x2; zx3}|; x3{; x5; : : :; xk ) = f34 (xj )
for some non-constant unary operation f34 and some j 2 f1; 2; : : :; kg. This means that
^ (xz 1}|; x1{; zx3}|; x3{; x5; : : :; xk ) = f12 (xi ) = f34 (xj ) for all possible choices of x1; x3; x5; x6; : : :; xk , which implies that either i 62 f1; 2g or j 62 f3; 4g. It follows from this that we can permute the order of the arguments of ^ to obtain a function which satis es the identity
(x1; z}|{ x; x; x4; : : :; xk ) = f(x1 )
for some non-constant unary operation f. In particular, we have (x1 ; y; y; : : :; y) = f(x1 ). Now, for all distinct pairs of indices i; j in f2; 3 : : :; kg, we know that the (k ? 1)-ary function (x1; x2; : : :; xi?1; x; xi+1; : : :; xj ?1; x; xj +1; : : :; xk ) is an essentially unary function. Since we have just shown that for the case x2 = x3 = = xk the value of this function is equal to f(x1 ), we know that it must equal f(x1 ) in all cases. Similarly, for all indices i 2 f2; 3; : : :; kg, the (k ? 1)-ary function
16
(x; x2; : : :; xi?1; x; xi+1; : : :; xk) is an essentially unary function. When the remaining arguments all have the same value, then this function is equal to f(x), by the arguments above. Hence it must be equal to f(x) in all cases. Now, if k > jDj, then there are more arguments than values, so at least one argument value must be repeated somewhere, and in all such cases we have shown that (x1 ; x2; : : :; xk) = f(x1 ). Since is just ^ with the order of the arguments permuted, we have contradicted the fact that ^ is not essentially unary. This means that we must have k jDj, and the result follows. In order to use Theorem 3 to draw conclusions about the tractability of a set of constraints we need to be able to distinguish closure operations which are essentially unary from those which are not. By De nition 9, this means examining each solution to the appropriate indicator problem to check whether the value of the solution at each variable is determined by a single coordinate position in the tuple describing that variable. For an operation of arity m, this checking may be carried out in mjDjm steps. Alternatively, the next result shows that the number of solutions to certain indicator problems provides a sucient condition for establishing NP-completeness, without needing to examine the individual solutions in detail. Corollary 2 Let ? be a set of relations over a set D, let S1 be the set of nonconstant solutions to IP (?; 1), and let Sm be the set of solutions to IP (?; m), where m = maxf3; jDjg. If jSm j mjS1 j, then CSP(?) is NP-complete.
Proof: By Theorem 3 and Theorem 4, we know that either CSP(?) is NPcomplete, or ? is closed under some operation which is not essentially unary, and which has arity at most m. By Theorem 1, Sm is the set of all m-ary operations under which ? is closed. By De nition 9, the number of operations in Sm which are essentially unary is equal to the number of non-constant unary operations under which ? is closed, multiplied by m. By Theorem 1, this number is mjS1 j. Hence, jSm j mjS1 j in all cases. In the limiting case, when jSm j = mjS1 j, we know that every element of Sm is essentially unary, so ? is not closed under any m-ary operation which is not essentially unary. It follows that ? is not closed under any operation of arity lower than m which is not essentially unary, so CSP(?) must be NP-complete. Corollary 2 establishes NP-completeness for many sets of constraints without the need for individually constructed, ad-hoc reduction arguments, as the following examples illustrate.
Example 15 Consider the relations R1 and R2 over D = f0; 1; 2g, de ned in
Example 1.
17
The indicator problem for fR1; R2g of order 1, de ned in Example 9, has 1 solution, corresponding to the identity operation. The indicator problem for fR1; R2g of order 3, has 3 solutions (which are all essentially unary). Hence CSP(fR1; R2g) is NP-complete, by Corollary 2. On the other hand, it was shown in Example 10 that R1 is closed under a constant operation, so CSP(fR1g) is tractable, by Proposition 9 of [9]. In fact, any problem in CSP(fR1g) has the solution which assigns the value 0 to each variable, so this class of problems is trivial. Furthermore, it was shown in Example 11 that R2 is closed under the operation 4, de ned in Example 5. Hence, CSP(fR2 g) is tractable, by Theorem 13 of [9]. 2
Example 16 Consider the relations R1; R2; R3, and R4 over D = f0; 1; 2g, de ned in Example 1. By counting the solutions to the indicator problems of order 1 and order 3 for each relation and each pair of distinct relations in this set, we are able to complete the analysis of the complexity of CSP(?) for each possible subset ? of these relations. Relations ?
fR1g fR2g fR3g fR4g
fR1; R2g fR1; R3g fR1; R4g fR2; R3g fR2; R4g fR3; R4g
# Solutions # Solutions IP (?; 1) IP (?; 3) (non-constant) 1 12 3 19683 10 > 227 6 18 1 3 1 3 1 3 1 3 1 3 2 6
Complexity of CSP(?) Trivial Polynomial Trivial NP-complete NP-complete NP-complete NP-complete NP-complete NP-complete NP-complete
(Example 15) (Example 15) (Example 13) (Corollary 2) (Corollary 2) (Example 13) (Corollary 2) (Example 13) (Example 13)
For all larger sets of relations ? fR1; R2; R3; R4g, we have that ? contains at least one of the pairs of relations shown in the table, and so CSP(?) is NP-complete. 2 How practical is the test proposed here in general? For small values of jDj, the relevant indicator problems have very few variables, and the solutions may be found easily. This remains true even when the arity of the relations in ? is large. In the simplest case, when jDj = 2, the constraint satisfaction problem corresponds to the classical Satisfiability problem [6], for which all possible tractable sets of relations are known, and are fully described in [15]. The only non-trivial examples in this case are the sets of Boolean relations which can be expressed by Horn clauses, or the duals of Horn clauses, or clauses containing at most two literals, or
18
linear equations over the two-element eld [15]. It has been shown that any set of relations that is closed under an operation which is not essentially unary belongs to one of these tractable classes [8]. Hence the condition described in Corollary 2 is both necessary and sucient for NP-completeness in this case (assuming that P is not equal to NP). It follows from this that solving the indicator problems of order 1 and order 3 provides a simple and complete test for tractability of any set of relations over any set with 2 elements. This provides a very practical answer to a question posed by Schaefer in 1978 [15] concerning the existence of an ecient test for tractability in the Generalized Satisfiability problem. Note that carrying out the test requires nding the number of solutions to a constraint satisfaction problem with just 8 Boolean variables. As the size of D increases, the size of the relevant indicator problems increases rapidly, and it may become impractical to compute all solutions, or even to calculate the number of solutions, as required by Corollary 2. On the other hand, for cases of interest, it may be possible to establish from known properties of the constraints that the relevant indicator problems will have particular types of solution, without carrying out a complete solution algorithm. This question is currently being investigated.
6. Conclusion In this paper we have shown how the algebraic properties of relations can be used to determine the expressive power of a set of possible constraint types. Furthermore, we have proposed a method for determining these algebraic properties by solving a particular form of constraint satisfaction problem, which we have called an indicator problem. Finally, we have shown that there are simple algebraic properties which distinguish between sets of relations which give rise to tractable constraint satisfaction problems and those which give rise to NP-complete problems. We have used these results to obtain a sucient condition for NP-completeness, which we have shown is widely applicable and easy to test. For problems where the set of possible values contains just two elements these results provide a necessary and sucient condition for NP-completeness (assuming that P is not equal to NP), and an ecient test to distinguish the tractable sets of relations. We are now investigating the application of these results to particular problem types, such as temporal problems involving subsets of the interval algebra. We are also attempting to determine how the presence of particular algebraic closure properties in the constraints may be used to derive appropriate ecient algorithms for tractable problem classes.
Acknowledgments We are grateful to Victor Dalmau for helpful discussions which greatly simpli ed the proof of Theorem 2
19
Notes 1. Since is nite, and hence there are only nitely many possibilities for at each arity, we may assume, without loss of generality, that this instance contains only a nite number of constraints. 2. Also called `implicational' relations [11]. D
R
References 1. Bibel, W., \Constraint Satisfaction From a Deductive Viewpoint", Arti cial Intelligence 35 , (1988), pp. 401{413. 2. Codd, E.F., \A Relational Model of Data for Large Shared Databanks", Communications of the ACM 13 (1970), pp. 377{387. 3. Cooper, M.C., Cohen, D.A., Jeavons, P.G., \Characterizing tractable constraints", Arti cial Intelligence 65 , (1994), pp. 347{361. 4. Dechter, R., & Pearl, J., \Structure identi cation in relational data", Arti cial Intelligence 58 (1992) pp. 237{270. 5. Freuder, E.C., \A sucient condition for backtrack-bounded search", Journal of the ACM 32 (1985) pp. 755{761. 6. Garey, M.R., & Johnson, D.S., Computers and intractability: a guide to NP-completeness, Freeman, San Francisco, California, (1979). 7. Gyssens, M., Jeavons, P., Cohen, D., \Decomposing constraint satisfaction problems using database techniques", Arti cial Intelligence 66 , (1994), pp. 57{89. 8. Jeavons, P.G., Cohen, D.A., \An algebraic characterization of tractable constraints", Lecture Notes in Computer Science 959, (1995), pp. 633{642. 9. Jeavons, P., Cohen D., Gyssens, M., \A unifying framework for tractable constraints", In Proceedings 1st International Conference on Principles and Practice of Constraint Programming|CP '95 (Cassis, France, September 1995), Lecture Notes in Computer Science , 976, Springer-Verlag, Berlin/New York, 1995, pp. 276{291. 10. Jeavons, P.G., & Cooper, M.C., \Tractable constraints on ordered domains", Arti cial Intelligence 79 (1996), pp. 327{339. 11. Kirousis, L., \Fast parallelconstraint satisfaction", Arti cial Intelligence 64 , (1993), pp. 147{ 160. 12. Ladkin, P.B., & Maddux, R.D., \On binary constraint problems", Journal of the ACM 41 (1994), pp. 435{469. 13. Mackworth, A.K. \Consistency in networks of relations", Arti cial Intelligence 8 (1977) pp. 99{118. 14. Montanari, U., \Networks of constraints: fundamental properties and applications to picture processing", Information Sciences 7 (1974), pp. 95{132. 15. Schaefer, T.J., \The complexity of satis ability problems", Proc 10th ACM Symposium on Theory of Computing (STOC), (1978) pp. 216{226. 16. Szendrei, A., Clones in Universal Algebra, Seminaires de Mathematiques Superieures 99, University of Montreal, (1986). 17. van Beek, P., \On the Minimality and Decomposability of Row-Convex Constraint Networks", Proceedings of the Tenth National Conference on Arti cial Intelligence, AAAI-92, MIT Press, (1992) pp. 447{452. 18. Van Hentenryck, P., Deville, Y., Teng, C-M., \A generic arc-consistency algorithm and its specializations", Arti cial Intelligence 57 (1992), pp. 291{321.