Constraint Satisfaction and Semilinear Expansions of Addition over the Rationals and the Reals
A semilinear relation is a finite union of finite intersections of open and closed half-spaces over, for instance, the reals, the rationals, or the integers. Semilinear relations have been studied in connection with algebraic geometry, automata theory, and spatiotemporal reasoning. We consider semilinear relations over the rationals and the reals. Under this assumption, the computational complexity of the constraint satisfaction problem (CSP) is known for all finite sets containing , , and . These problems correspond to expansions of the linear programming feasibility problem. We generalise this result and fully determine the complexity for all finite sets of semilinear relations containing . This is accomplished in part by introducing an algorithm, based on computing affine hulls, which solves a new class of semilinear CSPs in polynomial time. We further analyse the complexity of linear optimisation over the solution set and the existence of integer solutions.
Keywords. Constraint satisfaction problems, Semilinear sets, Algorithms, Computational complexity
We work over a ground set (or domain) , which will either be the rationals, , or the reals, . We say that a relation is semilinear if it can be represented as a finite union of finite intersections of open and closed half-spaces in . Alternatively, is semilinear if it is first-order definable in where . Semilinear relations appear in many different contexts within mathematics and computer science: they are, for instance, frequently encountered in algebraic geometry, automata theory, spatiotemporal reasoning, and computer algebra. Semilinear relations have also attained a fair amount of attention in connection with constraint satisfaction problems (CSPs). In a CSP, we are given a set of variables, a (finite or infinite) domain of values, and a finite set of constraints. The question is whether or not we can assign values to the variables so that all constraints are satisfied. From a complexity theoretical viewpoint, solving general constraint satisfaction problems is obviously a hard problem. Various ways of refining the problem can be adopted to allow a more meaningful analysis. A common refinement is that of introducing a constraint language; a finite set of allowed relations. One then considers the problem CSP in which all constraint in the input must be members of . This parameterisation of constraint satisfaction problems has proved to be very fruitful for CSPs over both finite and infinite domains. Since is finite, the computational complexity of such a problem does not depend on the actual representation of the constraints.
The complexity of finite-domain CSPs has been studied for a long time and a powerful algebraic toolkit has gradually formed . Much of this work has been devoted to the Feder-Vardi conjecture [10, 11] which posits that every finite-domain CSP is either polynomial-time solvable or NP-complete. Infinite-domain CSPs, on the other hand, constitute a much more diverse set of problems. In fact, every computational problem is polynomial-time equivalent to an infinite-domain CSP . Obtaining a full understanding of their computational complexity is thus out of the question, and some further restriction is necessary. In this article, this restriction will be to study semilinear relations and constraint languages.
A relation is said to be essentially convex if for all there are only finitely many points on the line segment between and that are not in . A constraint language is said to be essentially convex if every relation in is essentially convex. The main motivation for this study is the following result:
Theorem 1 (Bodirsky et al. ).
Let be a finite set of semilinear relations over or such that . Then,
CSP is polynomial-time solvable if is essentially convex, and NP-complete otherwise; and
the problem of optimizing a linear polynomial over the solution set of CSP is polynomial-time solvable if and only if CSP is polynomial-time solvable (and NP-hard otherwise).
One may suspect that there are semilinear constraint languages such that CSP but is not essentially convex. This is indeed true and we identify two such cases. In the first case, we consider relations with large “cavities”. It is not surprising that the algorithm for essentially convex relations (and the ideas behind it) cannot be applied in the presence of such highly non-convex relations. Thus, we introduce a new algorithm which solves CSPs of this type in polynomial time. It is based on computing affine hulls and the idea of improving an easily representable upper bound on the solution space by looking at one constraint at a time; a form of “local consistency” method. In the second case, we consider relations that are not necessarily essentially convex, but look essentially convex when viewed form the origin. That is, any points and that witnesses a not essentially convex relation lie on a line that passes outside of the origin. We show that we can remove all such holes from to find an equivalent constraint language that is essentially convex, and thereby solve the problem in polynomial time.
Combining these algorithmic results with matching NP-hardness results and the fact that CSP is always in NP for a semilinear constraint language (cf. Theorem 5.2 in Bodirsky et al. ) yields a dichotomy:
Let be a finite set of semilinear constraints that contains . Then, CSP is either in P or NP-complete.
Our result immediately generalises the first part of Theorem 1. It also generalises another result by Bodirsky et al.  concerning expansions of with relations that are first-order definable in . One may note that this class of relations is a severely restricted subset of the semilinear relations since it admits quantifier elimination over the structure , where denotes the binary addition function. This follows from the more general fact that the first-order theory of torsion-free divisible abelian groups admits quantifier elimination (see e.g. Theorem 3.1.9 in ). One may thus alternatively view relations that are first-order definable in as finite unions of sets defined by homogeneous linear systems of equations.
We continue by generalising the second part of Theorem 1, too: if is semilinear and contains , then the problem of optimising a linear polynomial over the solution set of CSP is polynomial-time solvable if and only CSP is polynomial-time solvable (and NP-hard otherwise). We also study the problem of finding integer solutions to CSP for certain semilinear constraint languages . Here, we obtain some partial results but a full classification remains elusive. Our results shed some light on the scalability property introduced by Jonsson and Lööw .
This article has the following structure. We begin by formally defining constraint satisfaction problems and semilinear relations together with some terminology and minor results in Section 2. The algorithms and tractability results that are presented in Section 3 while the hardness results can be found in Section 4. By combining the results from Section 3 and 4, we prove Theorem 2 in Section 5. We partially generalise Theorem 2 to optimisation problems in Section 6, and we study the problem of finding integer solutions in Section 7. Finally, we discuss some obstacles to further generalisations in Section 8. This article is a revised and extended version of a conference paper .
2.1. Constraint satisfaction problems
Let be a finite set of finitary relations over some domain (which will usually be infinite). We refer to as a constraint language. In order to avoid some uninteresting trivial cases, we will assume that all constraint languages are non-empty and contain non-empty relations only.
A first-order formula is called primitive positive if it is of the form , where each is an atomic formula, i.e., either or with the relation symbol for a -ary relation from . We call such a formula a pp-formula. Note that all variables do not have to be existentially quantified; if they are, then we say that the formula is a sentence. Given a pp-formula , we let denote the set of variables appearing in . The atomic formulas in a pp-formula are also called the constraints of .
The constraint satisfaction problem for a constraint language (CSP for short) is the following decision problem:
The exact representation of the relations in is unessential since we exclusively study finite constraint languages.
A relation is pp-definable from if there exists a quantifier-free pp-formula over such that
The set of all relations that are pp-definable over is denoted by . The following easy but important result explains the role of primitive positive definability for studying the computational complexity of CSPs. We will use it extensively in the sequel without making explicit references.
Lemma 1 (Jeavons ).
Let be a constraint language and a finite subset. Then CSP is polynomial-time reducible to CSP.
Let and be two constraint languages such that and are relations of the same arity. Given an instance of CSP, let denote the instance where each occurrence of a relation is replaced by . We say that CSP is equivalent to CSP if is true in if and only if is true in . It is clear that if CSP and CSP are equivalent CSPs, then they have the same complexity (up to a trivial linear-time transformation).
2.2. Semilinear relations
The domain, , of every relation in this article will be the set of rationals, , or the set of reals, . In all cases, the set of coefficients, , will be the set of rationals, but in order to avoid confusion, we will still make this explicit in our notation. We define the following sets of relations.
denotes the set of linear equalities over with coefficients in .
denotes the set of (strict and non-strict) linear inequalities over with coefficients in .
Sets defined by finite conjunctions of inequalities from are called linear sets. The set of semilinear sets, , is defined to be the set of finite unions of linear sets. We will refer to and as semilinear relations over and , respectively. One should be aware of the representation of objects in and compared to . In and , we view the equalities and inequalities as syntactic objects which we can use for building logical formulas. Now, recall the definition of a linear set: it is defined by a conjunction of inequalities. However, a linear set is not a logical formula, it is a subset of . The same thing holds for semilinear sets: they are defined by unions of linear sets and should thus not be viewed as logical formulas. This distinction has certain advantages when it comes to terminology and notation but it also emphasise a difference in the way we view and use these objects. The objects in and are often used in a logical context (such as pp-definitions) while the semilinear relations are typically used in a geometric context.
Given a relation of arity , let and . We demonstrate that CSP and CSP are equivalent as constraint satisfaction problems whenever . Thus, we will exclusively concentrate on relations from in the sequel. Let and let be an instance of CSP. Construct an instance of CSP by replacing each occurrence of in by . If has a solution, then has a solution since for each . If has a solution, then it has a rational solution by Lemma 3.7 in Bodirsky et al.  so has a solution, too.
The following lemma is a direct consequence of our definitions: this particular property is often referred to as -minimality in the literature .
Let be a unary semilinear relation. Then, can be written as a finite union of open, half-open, and closed intervals with endpoints in together with a finite set of points in .
The set of semilinear relations can also be defined as those relations that are first-order definable in . In particular, is closed under pp-definitions. Consequently, Lemma 2 is applicable to all relations discussed in this article.
Lemma 3 (Lemma 4.3 in Bodirsky et al. ).
Let . The relation is pp-definable in and it is pp-definable in if . Furthermore, the pp-formulas that define the relations can be computed in polynomial time.
It follows that and . One may also note that every homogeneous linear equation (with coefficients from ) is pp-definable in .
2.3. Unary semilinear relations
For a rational , and a unary relation , let . When ‚ we will also write for .
Given a relation and two distinct points , we define
The relation is a parameterisation of the intersection between the relation and a line through the points and . Note that is a member of so, by Lemma 3, is a member of , too.
A -ary relation is bounded if there exists an such that . A unary relation is unbounded in one direction if is not bounded, but there exists an such that one of the following holds: ; or . A unary relation is called a bnu (for bounded, non-constant, and unary) if it is bounded and contains more than one point.
Let be a unary relation in that is unbounded in one direction. Then,
contains a bnu.
if, in addition, contains both positive and negative elements, then contains a non-empty bounded unary relation.
(1) By Lemma 2, there exists an such that either
and ; or
Assume that (i) holds. (The remaining case follows by considering .) By choosing a rational , it is not hard to see that the relation
is bounded and contains an interval. The result then follows from Lemma 3.
For a unary semilinear relation , and a rational , let denote the set of unary semilinear relations such that and for all , there exists a with .
The set contains all unary relations such that .
Let be a bounded unary semilinear relation such that . Then, contains a relation , for every rational .
Let and . By Lemma 2, there exist elements with and . The relation is pp-definable in and satisfies: , , and . ∎
Let be a bounded unary semilinear relation such that for some and . Then, contains a relation , for every rational .
Let . The proof then follows using a similar construction as in the proof of Lemma 5. ∎
2.4. Essential convexity
Let be a -ary relation over . The relation is convex if for all , contains all points on the line segment between and . We say that is essentially convex if for all there are only finitely many points on the line segment between and that are not in .
We say that excludes an interval if there are and real numbers such that whenever . Note that we can assume that are rational numbers, since we can choose any two distinct rational numbers between and instead of and .
If is not essentially convex, and if and are such that there are infinitely many points on the line segment between and that are not in , then we say that and witness that is not essentially convex. Due to Lemma 2, we conclude that a semilinear relation is essentially convex if and only if it does not exclude an interval. We say that a constraint language is essentially convex if all its relations are essentially convex.
Theorem 3 (Theorem 5.1 and 5.4 in Bodirsky et al. ).
If is a finite set of essentially convex semilinear relations, then CSP is in P.
In this section, we present our two main sources of tractability. Section 3.1 contains a new algorithm for semilinear constraint languages containing and such that does not contain a bnu. In Section 3.2, we extend the applicability of Theorem 3 from essentially convex semilinear constraint languages to a certain class of semilinear CSPs that are not essentially convex.
3.1. Affine consistency
Instead of computing the exact solution set to a CSP instance, our approach will be to reduce an upper bound on this set as far as possible. In particular, we will maintain a representation of an affine subspace that is guaranteed to contain the solution set, and repeatedly intersect this subspace with every constraint in order to attempt to reduce it further. This can be seen as a form of local consistency. If we manage to reduce the upper bound to an empty set, then we are certain that the instance is unsatisfiable. We will show that under certain conditions, the converse holds; if the upper bound is non-empty, then there are necessarily solutions. To formalise this idea, we will need some definitions.
For a subset , let denote the affine hull of in :
An affine subspace is a subset for which . The points are said to be affinely independent if with implies . The dimension, , of a set is defined to be one less than the maximum number of affinely independent points in .
We define a notion of consistency for sets of semilinear constraints which we call affine consistency. Let be a finite set of variables and let . A set of constraints with is affinely consistent with respect to a non-empty affine subspace if for all , where .
Algorithm 1 establishes affine consistency for a set of constraints and answers “yes” if the resulting affine subspace is non-empty and “no” otherwise. In the rest of this section, we show that this algorithm correctly solves CSP when is a semilinear constraint language such that does not contain a bnu. Furthermore, we show that the algorithm can be implemented to run in polynomial time when applied to constraint languages of this kind.
We begin by proving a technical lemma which is the basis for these results.
Let be two -ary relations and linear sets. Assume that neither nor contains a bnu. If , then for some and .
The proof is by induction on the dimension . For , both and consist of a single point . Clearly, for some and for some . Now assume that and that the lemma holds for all , with and . Let be affinely independent points in and let be affinely independent points in . For , consider the lines through and , and the lines through and . Let () be a hyperplane in through the origin that is not parallel to any of the lines or . Then, intersects each of the lines. Let and let .
Express the line as , for some . Let . Since contains and , it follows that is not a constant and hence unbounded. By Lemma 4(1), is unbounded in both directions. By Lemma 2, , for some positive constant . An analogous argument shows that that , for some positive constant . Let be a positive constant such that and let . This ensures that for any , intersects the lines in affinely independent points, and intersects the lines in affinely independent points.
Let , , , and . We now have with , for every . By induction on and , it follows that for some and . This holds for all , hence there exist distinct with and . Since , , and , it follows that strictly contains , so we have , and . Therefore we have the equality . The lemma follows. ∎
For a semilinear relation , we let denote the representation size of , i.e., the number of bits needed to describe the arities and coefficients of each inequality in some fixed definition of .
Let be a relation such that does not contain a bnu and let be an affine subspace. Algorithm 2 computes a set of linear inequalities defining in time polynomial in and with .
Let be the representation of as the union of linear sets . By Lemma 7, there exists an such that and since for all , the algorithm will find such an on line 1 by simply comparing the dimensions of these sets. If , then the algorithm returns , signalling that the affine hull is empty.
Otherwise, the affine hull of a non-empty polyhedron can always be obtained as a subset of its defining inequalities (cf. Schrijver [20, Section 8.2]). Here, some of the inequalities may be strict, but it is not hard to see that removing them does not change the affine hull. If is an inequality that cannot be removed without increasing the dimension of the affine hull, then it is clear that still cannot be removed after the loop. Hence, after the loop, no inequality in can be removed without increasing the dimension of the affine hull. It follows that itself defines an affine subspace, , and .
Using the ellipsoid method, we can determine the dimension of the affine hull of a polyhedron defined by a system of linear inequalities in time polynomial in the representation size of the inequalities [20, Corollary 14.1f]. To handle strict inequalities on line 1, we can perturb these by a small amount, while keeping the representation sizes polynomial, to obtain a system of non-strict inequalities with the same affine hull. The algorithm does at most affine hull calculations. The total time is thus polynomial in . Finally, the set is a subset of , so . ∎
Let be a finite constraint language. If there is no bnu in , then Algorithm 1 correctly solves CSP and can be implemented to run in polynomial time.
Assume that each relation is given as , where is a linear set for each . First, we show that the algorithm terminates with equal to the affine hull of the solution space of the constraints.
Assume that the input consists of the constraints over variables , . Let denote the solution space of the instance. It is clear that is contained in throughout the execution of the algorithm. Therefore, so it suffices to show that . We will show that for all . When the algorithm terminates, we have for every . In particular, the claim holds for . Now assume that the claim holds for . Then, and satisfy the requirements of Lemma 7 with . Therefore, we can use this lemma to conclude that .
Finally, we show that the algorithm can be implemented to run in polynomial time. The call to Algorithm 2 in the inner loop is carried out at most times, where . The size of is at most , so the size of never exceeds , where is a relation with maximal representation size. Therefore, each call to Algorithm 2 takes polynomial time and consequently, the entire algorithm runs in polynomial time. ∎
3.2. Essential convexity
We will now identify another family of polynomial-time solvable semilinear CSPs. This time, we base our result on essentially convex semilinear constraint languages (Theorem 3). We extend this result to the situation where we are only guaranteed that all unary relations that are pp-definable in the language are essentially convex. The idea is that even if we do not have the constant relation to help us identify excluded intervals, we are still able to see excluded full-dimensional holes. We follow up this by showing that we can remove certain lower-dimensional holes and thus recover an equivalent essentially convex constraint language. We remind the reader that the dimension of a set is defined with respect to its affine hull, as in Section 3.1.
For , we let denote the euclidean norm of , and the euclidean distance between and .
Let for some and assume that is a semilinear relation such that every unary relation in is essentially convex. Then, can be defined by a formula , where defines a convex semilinear set, and are conjunctions over that define convex sets of dimensions strictly lower than the dimension of the set defined by .
Let denote the convex hull of and let denote its dimension. The set is semilinear (see, for instance, Stengle et al. ). Let be a formula for and let be a formula for on quantifier-free DNF over . It remains to show that for each , the dimension of the convex set defined by is smaller than . To prove this, we show that for every point in , and every , there exists a point in such that . Since every -dimensional convex set contains a small -dimensional open ball around every point in its interior, it follows from this that none of the sets can be -dimensional.
Carathéodory’s theorem (cf. Schrijver [20, Section 7.7]) states that for every , we can find affinely independent points, , such that lies in . By induction over , we show that for every point , and every , there is a point such that . For , this statement follows trivially as each was chosen from . Now assume that and that the statement holds for all . By the induction hypothesis, the statement holds for the set . Every can be written as for some and . Let be a point in that is at distance at most from and let . Then,
Let be a small constant to be fixed later. By Lemma 5, there exists a unary relation . Consider the following relation:
Since , we also have . By assumption, does not exclude an interval, so there exists a such that and . Then, by the definition of , there exists a and a point such that:
where is a constant for a fixed , and the first inequality follows from the triangle inequality. The claim now follows for the point by taking since . ∎
Let be a constraint language. Assume that there exists a unary relation , for some , and that every unary relation in is essentially convex. Then, CSP is equivalent to CSP for an essentially convex constraint language .
If is essentially convex, then there is nothing to prove. Assume therefore that is not essentially convex. By Lemma 9, each can be defined by a formula , where , , …, are conjunction over , and , …, define sets whose affine hulls are of dimensions strictly lower than that of the set defined by . Assume additionally that the formulas are numbered so that the affine hulls of the sets defined by do not contain and that the affine hulls of the sets defined by do contain . Define by
where defines the affine hull of the set defined by . Then, the constraint language is essentially convex since witnesses of an excluded interval only occur inside an affine subspace not containing ; otherwise we could use such a witness to pp-define a unary relation excluding an interval.
Let be an arbitrary instance of CSP over the variables and assume where is quantifier-free. Construct an instance of CSP by replacing each occurrence of a relation in by . Clearly, if is satisfiable, then so is . Conversely, let be a solution to and assume that is not satisfiable. Let be the line in through and and let be the unary relation . All tuples in correspond to solutions of that are not solutions to .
Fix a constraint in and consider the points in that satisfy this constraint but not . These are the points on for which satisfies . For each , satisfies at most one point on since otherwise the affine hull of the relation defined by would contain . Hence, each constraint in can account for at most a finite number of points in , so is finite.
Assume first that . Then, is not essentially convex which contradicts the assumption that every unary relation in is essentially convex. Assume instead that , where the single point in corresponds to the solution . Recall that is not essentially convex. Let be a -ary relation that is not essentially convex and let witness this. The relation since . Then, is unary and not essentially convex which leads to a contradiction. It follows that if is satisfiable, then so is . ∎
We now derive a unified condition for all hard CSPs classified in this article. It is based on a polynomial-time reduction from the NP-hard problem Not-All-Equal 3SAT , i.e. the problem CSP where . The proof is divided into three different lemmas. First, we present a reduction from Not-All-Equal 3SAT to a simple semilinear CSP. We then show that having a bnu that is bounded away from allows us to pp-define unary relations that are, in a certain sense, close to being either the relation or . In the final step, we combine these two results and show that having a bnu that excludes an interval and that is bounded away from is a sufficient condition for CSP() to be NP-hard.
Let . Then, CSP is NP-hard.
The proof is by a polynomial time reduction from CSP. Let denote an arbitrary instance of CSP. Construct an instance of CSP as follows. Impose the constraint on each variable. For each constraint in , introduce the constraints and , where is a fresh variable.
Assume that has a solution. Consider a constraint in . If two of the variables are assigned the value , then the equation is satisfied by choosing . If two of the variables are assigned the value , then the equation is satisfied by choosing . Hence, is satisfiable.
Assume that has a solution . Then, has a solution defined by if and if . Assume to the contrary that for some variables with a constraint . Consider the equation in . By the assumption on , we have , and hence . But this is a contradiction as the constraint is also in . We can similarly rule out the case . This proves that is a solution to . ∎
Let be a bounded unary relation such that , for some . Then, either contains a unary relation for every ; or contains a unary relation , for every .