Constraint Satisfaction and Semilinear Expansions of Addition over the Rationals and the Reals
Abstract.
A semilinear relation is a finite union of finite intersections of open and closed halfspaces 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
1. Introduction
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 halfspaces in . Alternatively, is semilinear if it is firstorder definable in where [12]. 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 finitedomain CSPs has been studied for a long time and a powerful algebraic toolkit has gradually formed [7]. Much of this work has been devoted to the FederVardi conjecture [10, 11] which posits that every finitedomain CSP is either polynomialtime solvable or NPcomplete. Infinitedomain CSPs, on the other hand, constitute a much more diverse set of problems. In fact, every computational problem is polynomialtime equivalent to an infinitedomain CSP [1]. 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. [2]).
Let be a finite set of semilinear relations over or such that . Then,

CSP is polynomialtime solvable if is essentially convex, and NPcomplete otherwise; and

the problem of optimizing a linear polynomial over the solution set of CSP is polynomialtime solvable if and only if CSP is polynomialtime solvable (and NPhard 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 nonconvex 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 NPhardness results and the fact that CSP is always in NP for a semilinear constraint language (cf. Theorem 5.2 in Bodirsky et al. [2]) yields a dichotomy:
Theorem 2.
Let be a finite set of semilinear constraints that contains . Then, CSP is either in P or NPcomplete.
Our result immediately generalises the first part of Theorem 1. It also generalises another result by Bodirsky et al. [3] concerning expansions of with relations that are firstorder 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 firstorder theory of torsionfree divisible abelian groups admits quantifier elimination (see e.g. Theorem 3.1.9 in [18]). One may thus alternatively view relations that are firstorder 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 polynomialtime solvable if and only CSP is polynomialtime solvable (and NPhard 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 [16].
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 [17].
2. Preliminaries
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 nonempty and contain nonempty relations only.
A firstorder 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 ppformula. 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 ppformula , we let denote the set of variables appearing in . The atomic formulas in a ppformula are also called the constraints of .
The constraint satisfaction problem for a constraint language (CSP for short) is the following decision problem:
Problem: CSP, where is a finite set of relations over a domain . Input: A primitive positive sentence over . Output: ‘yes’ if is true in , ‘no’ otherwise.
The exact representation of the relations in is unessential since we exclusively study finite constraint languages.
A relation is ppdefinable from if there exists a quantifierfree ppformula over such that
The set of all relations that are ppdefinable 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 [15]).
Let be a constraint language and a finite subset. Then CSP is polynomialtime 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 lineartime 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 nonstrict) 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 ppdefinitions) 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. [2] 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 [14].
Lemma 2.
Let be a unary semilinear relation. Then, can be written as a finite union of open, halfopen, 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 firstorder definable in [12]. In particular, is closed under ppdefinitions. Consequently, Lemma 2 is applicable to all relations discussed in this article.
Lemma 3 (Lemma 4.3 in Bodirsky et al. [3]).
Let . The relation is ppdefinable in and it is ppdefinable in if . Furthermore, the ppformulas 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 ppdefinable 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, nonconstant, and unary) if it is bounded and contains more than one point.
Lemma 4.
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 nonempty bounded unary relation.
Proof.
(1) By Lemma 2, there exists an such that either

and ; or

and .
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 .
Example 1.
The set contains all unary relations such that .
Lemma 5.
Let be a bounded unary semilinear relation such that . Then, contains a relation , for every rational .
Proof.
Let and . By Lemma 2, there exist elements with and . The relation is ppdefinable in and satisfies: , , and . ∎
Lemma 6.
Let be a bounded unary semilinear relation such that for some and . Then, contains a relation , for every rational .
Proof.
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. [2]).
If is a finite set of essentially convex semilinear relations, then CSP is in P.
3. Tractability
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 nonempty, 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 nonempty 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 nonempty 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.
Lemma 7.
Let be two ary relations and linear sets. Assume that neither nor contains a bnu. If , then for some and .
Proof.
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 .
Lemma 8.
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 .
Proof.
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 nonempty 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 nonstrict 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 . ∎
Theorem 4.
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.
Proof.
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 polynomialtime 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 ppdefinable 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 fulldimensional holes. We follow up this by showing that we can remove certain lowerdimensional 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 .
Lemma 9.
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 .
Proof.
Let denote the convex hull of and let denote its dimension. The set is semilinear (see, for instance, Stengle et al. [21]). Let be a formula for and let be a formula for on quantifierfree 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 . ∎
Theorem 5.
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 .
Proof.
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 ppdefine a unary relation excluding an interval.
Let be an arbitrary instance of CSP over the variables and assume where is quantifierfree. 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 . ∎
4. NPhardness
We now derive a unified condition for all hard CSPs classified in this article. It is based on a polynomialtime reduction from the NPhard problem NotAllEqual 3SAT [19], i.e. the problem CSP where . The proof is divided into three different lemmas. First, we present a reduction from NotAllEqual 3SAT to a simple semilinear CSP. We then show that having a bnu that is bounded away from allows us to ppdefine 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 NPhard.
Lemma 10.
Let . Then, CSP is NPhard.
Proof.
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 . ∎
Lemma 11.
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 .