This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Author and institution omitted for double-blind review \ccsdesc[100]Theory of computation \CopyrightCopyright: omitted for double-blind review

Efficient Local Search for Nonlinear Real Arithmetic

Anonymous authors
Abstract

Local search has recently been applied to SMT problems over various arithmetic theories. Among these, nonlinear real arithmetic poses special challenges due to its uncountable solution space and potential need to solve higher-degree polynomials. As a consequence, existing work on local search only considered fragments of the theory. In this work, we analyze the difficulties and propose ways to address them, resulting in an efficient search algorithm that covers the full theory of nonlinear real arithmetic. In particular, we present incremental computation of variable scores, and temporary relaxation of equality constraints. We also discuss choice of candidate moves and a look-ahead mechanism in case when no critical moves are available. The implementation is competitive on satisfiable problem instances against complete methods such as MCSAT implemented in existing SMT solvers.

keywords:
Local search, Nonlinear arithmetic, SMT

1 Introduction

Satisfiability Modulo Theories (SMT) is the problem of determining the satisfiability of a formula containing both logical operators and functions interpreted in one or more custom theories [BarrettT18]. Commonly considered theories include equality, arithmetic, bit-vectors, arrays, and strings. After about two decades of development, SMT has gained widespread applications in program verification, model checking, planning, and many other areas.

The arithmetic theories can be divided according to the type of numbers involved into integer and real theories, and according to the operations allowed into difference logic, linear, and nonlinear theories. The case of (quantifier-free) nonlinear real arithmetic (NRA) considers satisfiability of equalities and inequalities involving polynomials of degree greater than one, and where the arithmetic variables take on real values. It has applications in the analysis of nonlinear hybrid automata [CimattiMT12], generating ranking functions for termination analysis [HeizmannHLP13, LeikeH15], constraint answer set programming [SusmanL16, ShenL18], and even analysis of biological networks [AkutsuHT08]. Problem instances from many of these applications are collected in the SMT-LIB benchmarks [BarFT-SMTLIB].

Similar to the SAT case, methods for solving SMT problems can be roughly divided into complete and incomplete methods. Complete methods are usually based on DPLL(TT) or close variants. They are able to both find solutions and prove unsatisfiability. Incomplete methods, such as those based on local search [HoosS2004], explores the solution space heuristically, usually by changing the assignment of one variable at a time, in an attempt to find a satisfying solution. Local search methods are not able to prove unsatisfiability, but can have an advantage over complete methods on some satisfiable instances.

Complete methods for the theory of nonlinear real arithmetic make crucial use of cylindrical algebraic decomposition (CAD) [Caviness2004QuantifierEA], which permits deciding the satisfiability of a conjunction of polynomial (in)equalities over real numbers. This can then serve as the theory solver in DPLL(TT[NieuwenhuisOT06]. An innovation over DPLL(TT) for arithmetic theories is the MCSAT algorithm [JovanovicM12, MouraJ13], which constructs models involving both boolean and arithmetic variables at the same time. A nice overview of DPLL(TT) and MCSAT for nonlinear real arithmetic can be found in Kremer’s thesis [Kremer20].

Exploration of applying local search to solve SMT problems over arithmetic theories began only recently. The work [CaiLZ22] applied local search to the theory of linear integer arithmetic. It introduced the concept of critical moves, a change in one arithmetic variable that satisfies a previously unsatisfied clause. The algorithm iteratively applies critical moves that most improves the score, a weighted count of unsatisfied clauses. The presence of both boolean and arithmetic variables are dealt with by alternately working in the integer mode and the boolean mode, when assignments to only integer or boolean variables are changed respectively. Switching between modes are performed after the number of non-improving steps reaches a certain threshold.

Compared to linear integer arithmetic, the problem of nonlinear real arithmetic held additional challenges for local search methods. Unlike integer theories, there is an uncountable number of possible assignments to choose from, including infinite number of choices in any finite interval. Unlike the linear case, there is potential need to solve polynomials of degree greater than one, which is both costly in time and may result in variable assignments that are irrational (e.g. algebraic) numbers, causing a slow-down of the ensuing search process. It is also possible that a nonlinear constraint cannot be satisfied by changing the value of one variable alone, resulting in the lack of critical moves, so that other heuristics are needed in such scenarios.

There has already been some work exploring local search for nonlinear real arithmetic. However, largely due to the challenges listed above, none of the existing work covers the entirety of the theory. The work [abs-2303-06676] considers the multilinear case, where each variable appears with degree at most one in each polynomial constraint. The work [LiXZ23] considers problems where all equality constraints contain at least one variable that is linear. In both of these works, the problem of variable assignments to irrational values is avoided by either assuming linearity in each variable, or by limiting higher-degree constraints to strict inequalities only.

1.1 Contributions

In this paper, we propose several improvements to the local search procedure, aimed at addressing the challenges posed by nonlinear real arithmetic. This results in an efficient local search algorithm for the entire NRA theory.

First, we present efficient data structures for caching and updating variable scores used to determine the next critical move. Existing work on local search for arithmetic theories can be thought of as an extension of the GSAT algorithm [SelmanLM92] with adaptive weighting. It is well-known that efficient implementations of GSAT involve caching and updating of variable scores [HoosS2004, Section 6.2]. For arithmetic theories, this is complicated by the fact that each variable is associated not with one score, but with different scores for changing its assignment to values in different intervals. Hence, current implementations of local search for arithmetic theories recompute the score information for each variable at every iteration, resulting in potential repeated computations. This is especially serious for nonlinear arithmetic, where computations may involve costly root-finding for higher-degree polynomials. We describe data structures maintaining boundaries of score changes for each pair of clause and variable appearing in the clause, which only need to be updated on an as-needed basis, and from which the full score information can be quickly recovered.

Second, we address the problem posed by nonlinear equality constraints between variables, which may force assignment to variables that are irrational numbers. Rather than making such assignments, we propose to temporarily relax such equalities into inequalities, e.g. changing the constraint p=0p=0 into p>ϵp<ϵp>-\epsilon\wedge p<\epsilon, and continue the local search process. If an (approximate) solution is found that satisfies the relaxed version of these constraints, we restore the equalities to their original form, and try to find an exact solution near the approximate solution. While it is not guaranteed theoretically (or in practice) that such an exact solution can be found every time, using this method means local search spends most of its time working with rational assignments, significantly improving its efficiency in particular types of problem instances.

Finally, we present alternative ways to deal with situations where no critical move is available to satisfy a certain literal (that is, when the literal is stuck). We first pick heuristically a variable appearing in the literal, and a set of candidate moves for that variable. For each candidate move, we look ahead to see whether that move will lead to the literal having critical moves on the next step. Such moves are then preferred over the others.

The above ideas are implemented as a local search algorithm on top of the Z3 prover [MouraB08]. The implementation relies on the existing library of polynomials and algebraic numbers in Z3, but is otherwise independent from its implementation of MCSAT for nonlinear real arithmetic. We perform thorough experiments on the SMT-LIB benchmarks, showing the effect of incremental computation of variable scores and relaxation of equalities, and that the resulting local search algorithm is competitive with complete algorithms in existing SMT solvers on the satisfiable instances.111Binary file of the program for Linux operating system is available at the anonymized repository https://anonymous.4open.science/r/z3_binary-1038/.

1.2 Related work

Our work builds upon existing work applying local search to SMT over arithmetic theories [CaiLZ22, abs-2303-06676, LiXZ23]. They will be reviewed in more detail in Section 2. Besides arithmetic theories, there have also been earlier work applying local search to the theory of bit-vectors [GriggioPST11, FrohlichBWH15, NiemetzPB16]. In particular, the work [FrohlichBWH15] generalized the scoring function to consider operators on bit-vectors, but the moves remain single-bit flips. Later works [Niemetz2015ImprovingLS, NiemetzPB16] introduced propagation-based move selection and essential inputs to prune the search.

The work of Gao et al. [GaoAC12IJCAR, GaoAC12LICS] introduced the framework of δ\delta-complete decision procedures, implemented in the dReal tool for solving SMT problems over nonlinear formulas [GaoKC13]. It can handle polynomials as well as trigonometric and exponential functions. The δ\delta-complete framework allows algorithms to either return δ\delta-𝗌𝖺𝗍\mathsf{sat} or 𝗎𝗇𝗌𝖺𝗍\mathsf{unsat}, where the δ\delta-𝗌𝖺𝗍\mathsf{sat} case returns a solution for a δ\delta-weakening of the input formulas. This permits efficient numerical algorithms to be used, as well as showing decidability for a wide range of problems. The concept of relaxation of constraints in our work is similar to δ\delta-weakening, and we also use it to increase efficiency of our algorithm. However, we still aim to return an exact answer, by restoring the constraints to their original form and try to find an exact solution near any approximate solution that is found.

1.3 Structure of the paper

We begin by defining the SMT problem over nonlinear real arithmetic, and reviewing existing local search algorithms in Section 2. Section 3 presents incremental computation of variable scores. Section 4 presents relaxation and restoring of equality constraints. Section 5 discusses implementation choices, including heuristic move selection and look-ahead mechanism for stuck literals. Section 6 compare with existing SMT solvers, and perform ablation study on each of the improvements. Finally, we conclude in Section 7 with a discussion of potential future directions.

2 Preliminaries

In this section, we formally define SMT problems over nonlinear real arithmetic, followed by a review of existing local search algorithms for arithmetic theories.

The syntax of a general SMT formula over nonlinear real arithmetic is as follows:

p\displaystyle p :=x|c|p+p|pp\displaystyle:=x\leavevmode\nobreak\ |\leavevmode\nobreak\ c\leavevmode\nobreak\ |\leavevmode\nobreak\ p+p\leavevmode\nobreak\ |\leavevmode\nobreak\ p\cdot p (polynomials)
a\displaystyle a :=b|p0|p0|p=0\displaystyle:=b\leavevmode\nobreak\ |\leavevmode\nobreak\ p\geq 0\leavevmode\nobreak\ |\leavevmode\nobreak\ p\leq 0\leavevmode\nobreak\ |\leavevmode\nobreak\ p=0 (atoms)
f\displaystyle f :=a|¬f|ff|ff\displaystyle:=a\leavevmode\nobreak\ |\leavevmode\nobreak\ \neg f\leavevmode\nobreak\ |\leavevmode\nobreak\ f\wedge f\leavevmode\nobreak\ |\leavevmode\nobreak\ f\vee f (formulas)

Here xx is an arithmetic variable, cc is a (rational) constant, bb is a boolean variable. A literal is either an atom or its negation. A clause is a disjunction of literals. In practice, we assume that input problem instances are given in conjunctive normal form (CNF), that is as a collection of clauses to be satisfied. Note that strict inequalities p0p\neq 0, p<0p<0 and p>0p>0 can be represented as ¬(p=0)\neg(p=0), ¬(p0)\neg(p\geq 0) and ¬(p0)\neg(p\leq 0), respectively. We allow problem instances to contain boolean and arithmetic variables at the same time. We define boolean literal and arithmetic literal to mean literal whose atom is a boolean variable and a polynomial inequality, respectively.

A polynomial pp is linear in some variable xx if all terms of the polynomial have degree at most one in xx. Alternatively, pp can be written in the form p1x+p2p_{1}\cdot x+p_{2}, where p1,p2p_{1},p_{2} do not contain xx. A polynomial is multilinear if it is linear in each of its variables.

Given a problem instance containing boolean variables bi(1im)b_{i}\leavevmode\nobreak\ (1\leq i\leq m) and arithmetic variables xj(1jn)x_{j}\leavevmode\nobreak\ (1\leq j\leq n), a complete assignment is a mapping from each bib_{i} to {,}\{\top,\bot\} and each xjx_{j} to \mathbb{R}. We will only deal with complete assignments in this paper, and hence sometimes call it assignment for short. A formula is satisfied under an assignment if it evaluates to true under the standard interpretation of boolean and arithmetic operators. An assignment is a solution to a problem instance if it satisfies all its clauses. The SMT problem for nonlinear real arithmetic is to determine whether a given problem instance is satisfiable by some assignment.

Local search algorithms attempt to determine satisfiability of a problem instance by searching in the space of complete assignments, usually by changing the value of one variable at a time. In the SAT case, each move in local search flips the assignment of one boolean variable. Which flip to make is determined by factors such as the number of clauses that become satisfied/unsatisfied as result of the flip, weight of the clauses, which variables are flipped recently, and so on. For SMT over arithmetic theories, the analogous move changes the value of one arithmetic variable, usually in order to make some clause become satisfied. Such moves, called critical moves, are introduced in [CaiLZ22] for linear integer arithmetic.

For nonlinear real arithmetic, the basic procedure used to determine possible moves is root isolation for polynomials. Given a polynomial pp in a single variable xx (where here we allow the coefficients of pp to be algebraic numbers), the procedure computes the roots of the equation p(x)=0p(x)=0, together with the sign of the polynomial in each interval separated by the roots. Algebraic numbers in the coefficients of pp and in the output of root isolation are represented by their minimal polynomials, together with intervals with rational endpoints that bracket a root of that polynomial.

Given a complete assignment, and an arithmetic literal ll involving variable xx, we can use root isolation to compute the set of values that assignment of xx may be moved to in order for ll to be satisfied. This is done by substituting in assignments to other variables in ll, resulting in a polynomial containing only variable xx, then perform root isolation and check the value of ll in each resulting interval. The answer is given in terms of a set of intervals (which may contain ±\pm\infty as one of the endpoints, and may be either open or closed at each endpoint). We state the definitions precisely as follows.

Definition 2.1.

Given a complete assignment, a literal ll and a variable xx, the feasible set (resp. infeasible set) is the collection of intervals that the value of xx can be moved to in order for ll to be satisfied (resp. unsatisfied). Likewise, we define the feasible set (resp. infeasible set) of a clause with respect to a variable. This is computed by taking the union (resp. intersection) of the feasible set (resp. infeasible set) for each literal in the clause.

A critical move is defined to be a change in the assignment of some variable xx to a value that satisfies some previously unsatisfied clause. The basic local search algorithm then performs critical moves at each iteration, using various scoring metrics to determine which move is chosen next. Such moves can also be interpreted as jumping between CAD cells as in [LiXZ23]. An innovation in [LiXZ23] is that when no critical moves are available for some literal, moves that change multiple variables at once along some straight line are also explored.

Scoring of critical moves is usually based on a weighted count of unsatisfied clauses. Adaptive weighting schemes assign a weight to each clause, reflecting its importance during the current search. Existing work on local search for arithmetic theories mostly use a probabilistic version of the PAWS weighting scheme [ThorntonPBF04]. This scheme is parameterized by a smoothing probability sp. Whenever there is no moves available that improves the score, with probability 1𝑠𝑝1-\mathit{sp} the weight of each unsatisfied clause is increased by 1, and with probability 𝑠𝑝\mathit{sp} the weight of each satisfied clause with weight greater than 1 is decreased by 1. Then, the make-break score of each critical move equals the total weight of clauses that become satisfied by the move, minus the total weight of clauses that become unsatisfied by the move. A move is improving if its score is greater than zero.

One key contribution of [abs-2303-06676] is the introduction of make-break intervals. The idea is that instead of considering only the (in)feasible intervals of a variable xx with respect to some clause, we combine the (in)feasible interval information of xx with respect to all clauses. This results in a partition of the real line into intervals, with each interval associated to the make-break score for moving the value of xx into that interval. We illustrate this idea with the following example.

Example 2.2.

Consider the set of clauses x2+y21x^{2}+y^{2}\leq 1, x+y<1x+y<1 and x+z>0x+z>0. The current assignment is x1,y1,z1x\mapsto 1,y\mapsto 1,z\mapsto 1, and the current weight of clauses are 1,3,21,3,2, respectively. The make-break score for variable xx with respect to each of the clauses are:

  • x2+y21x^{2}+y^{2}\leq 1 (unsatisfied): (,0)0(-\infty,0)\mapsto 0, [0,0]1[0,0]\mapsto 1, (0,)0(0,\infty)\mapsto 0.

  • x+y<1x+y<1 (unsatisfied): (,0)3(-\infty,0)\mapsto 3, [0,)0[0,\infty)\mapsto 0.

  • x+z>0x+z>0 (satisfied): (,1]2(-\infty,-1]\mapsto-2, (1,)0(-1,\infty)\mapsto 0.

Combining the above information, we obtain the following make-break intervals and scores for xx: (,1]1(-\infty,-1]\mapsto 1, (1,0)3(-1,0)\mapsto 3, [0,0]1[0,0]\mapsto 1, (0,)0(0,\infty)\mapsto 0. A preferred move would be to change the value of xx into the interval (1,0)(-1,0), satisfying the clause x+y<1x+y<1 and leaving the status of the other clauses unchanged, with a make-break score of 3.

If boolean variables are present, the make-break score of flipping each boolean variable is defined in a similar way, as the total weight of clauses that become satisfied by the flip, minus the total weight of clauses that become unsatisfied.

Algorithm 1 shows the structure of the basic local search procedure. Begin by initializing the assignments to all variables (line 1). At each iteration, first try to find a move with the largest make-break score. If the score is greater than 0 (the variable necessarily comes from an unsatisfied clause), then perform the corresponding move (line 9). If no move has score greater than 0, it indicates that we reached a local minimum. Update the clause weights according to the PAWS scheme (line 11), and then try to make a move that makes a randomly chosen clause satisfied (line 16). If that is also not possible after several tries, randomly change the assignment of some variable in some unsatisfied clause according to some heuristic (line 19). This continues until all clauses are satisfied (line 4) or the time or step limit is reached (line 6).

Input : A set of clauses FF
Output : An assignment of variables that satisfy FF, or failure
1 Initialize assignment to variables;
2 while \top do
3       if all clauses satisfied then
4             return success with assignment;
5            
6      if time or step limit reached then
7             return failure;
8            
9      𝑣𝑎𝑟,𝑛𝑒𝑤_𝑣𝑎𝑙𝑢𝑒,𝑠𝑐𝑜𝑟𝑒\mathit{var,new\_value,score}\leftarrow best move according to make-break score;
10       if score >> 0 then
11             Perform move, assigning 𝑣𝑎𝑟\mathit{var} to 𝑛𝑒𝑤_𝑣𝑎𝑙𝑢𝑒\mathit{new\_value};
12            
13      else
14             Update clause weight according to PAWS scheme;
15             repeat
16                   𝑐𝑙𝑠\mathit{cls}\leftarrow random unsatisfied clause;
17                   𝑣𝑎𝑟,𝑛𝑒𝑤_𝑣𝑎𝑙𝑢𝑒,𝑠𝑐𝑜𝑟𝑒\mathit{var,new\_value,score}\leftarrow critical move making 𝑐𝑙𝑠\mathit{cls} satisfied;
18                   if score \neq -\infty then
19                         Perform move, assigning 𝑣𝑎𝑟\mathit{var} to 𝑛𝑒𝑤_𝑣𝑎𝑙𝑢𝑒\mathit{new\_value};
20                        
21                  
22            until 3 times;
23            if no move performed in previous loop then
24                   Change assignment of some variable in some unsatisfied clause;
25                  
26            
27      
Algorithm 1 Basic local search algorithm

There are possible variations in the choice between boolean and arithmetic variables on line 7. In [CaiLZ22, abs-2303-06676], the search is separated into modes where only boolean or arithmetic variables are considered. Alternatively, we can combine the lists of moves and decide between them based purely on make-break scores. We take the latter approach in this paper. There are other aspects of the algorithm that are left unspecified, including how the best move is computed on line 7, and the heuristic choice of moves on line 19. These will be specified in more detail in the next sections.

3 Incremental computation of variable scores

One key step in Algorithm 1 is computing the move with the best make-break score. The computation for boolean variables is standard (and is in any case not the bottleneck here), hence we focus on critical moves for arithmetic variables. The default approach is to loop over all variables in all unsatisfied clauses. For each variable, compute its score with respect to each clause and then combine the results (as demonstrated in Example 2.2). However, it is clear that this may result in repeated computations across iterations. For example, the feasible set of some variable with respect to a clause may be recomputed, even though none of the variables in that clause are changed in the previous step. Following the idea of caching and updating scores in GSAT [SelmanLM92], we propose data structures for caching and updating score information for arithmetic variables.

We define a boundary to be a quadruple 𝑣𝑎𝑙,𝑖𝑠_𝑜𝑝𝑒𝑛,𝑖𝑠_𝑚𝑎𝑘𝑒,𝑐𝑖𝑑\langle\mathit{val},\mathit{is\_open},\mathit{is\_make},\mathit{cid}\rangle, where 𝑣𝑎𝑙\mathit{val} is a real number, 𝑖𝑠_𝑜𝑝𝑒𝑛\mathit{is\_open} and 𝑖𝑠_𝑚𝑎𝑘𝑒\mathit{is\_make} are boolean values, and 𝑐𝑖𝑑\mathit{cid} is a clause identifier. It indicates that there is a change in make-break score when moving from less than to greater than 𝑣𝑎𝑙\mathit{val} due to clause 𝑐𝑖𝑑\mathit{cid}. If 𝑖𝑠_𝑚𝑎𝑘𝑒\mathit{is\_make} is \top, the score is increased by the weight of clause 𝑐𝑖𝑑\mathit{cid}, otherwise it is decreased by the weight. If 𝑖𝑠_𝑜𝑝𝑒𝑛\mathit{is\_open} is \top, the change is not active at 𝑣𝑎𝑙\mathit{val}, otherwise it is already active at 𝑣𝑎𝑙\mathit{val}. There is a natural ordering among boundaries, first order by 𝑣𝑎𝑙\mathit{val} and then by 𝑖𝑠_𝑜𝑝𝑒𝑛\mathit{is\_open} (with <\bot<\top). The make-break score information of each variable with respect to each clause can be characterized by a starting score (indicating the make-break score of large negative values), together with a set of boundaries. The make-break information of each variable with respect to all clauses is formed by summing the starting score and taking the union of the sets of boundaries. We illustrate the computations in the following example.

Example 3.1.

Continuing from Example 2.2, the starting score and boundary information of variable xx with respect to each clause is as follows (we identify the three clauses as 1,2,3, respectively).

  • x2+y21x^{2}+y^{2}\leq 1: starting score 0, boundary set {(0,,,1),(0,,,1)}\{(0,\bot,\top,1),(0,\top,\bot,1)\}, indicating no change for large negative values, make at boundary [1,[1,\cdots, followed by break at boundary (1,(1,\cdots.

  • x+y<1x+y<1: starting score 3, boundary set {(0,,,2)}\{(0,\bot,\bot,2)\}, indicating make at large negative values, and break at boundary [0,[0,\dots.

  • x+z>0x+z>0: starting score 2-2, boundary set {(1,,,3)}\{(-1,\top,\top,3)\}, indicating break at large negative values, and make at boundary (1,(-1,\dots.

The combined make-break score information is: starting score 1, with the following (ordered) set of boundaries: {(1,,,3),(0,,,1),(0,,,2),(0,,,1)}\{(-1,\top,\top,3),(0,\bot,\top,1),(0,\bot,\bot,2),(0,\top,\bot,1)\}. Make-break score information in terms of intervals can be easily recovered from the above, by traversing the boundaries in order, increasing the score by the weight of the clause when encountering a boundary with 𝑖𝑠_𝑚𝑎𝑘𝑒=\mathit{is\_make}=\top, and decreasing the score by the weight otherwise.

During local search, after each move of variable vv to a new value, only those variables vv^{\prime} that shares a clause with vv need to have their make-break score information updated (this is analogous to the concept of dependent variables in the SAT case), and moreover boundary information need to be updated for the shared clauses only. This is summarized in Algorithm 2. The set SS collects the set of variables sharing a clause with vv. Line 5 recomputes starting score and boundary information. Line 7 recomputes best critical move and score for each updated variable.

Input : Variable vv that is modified
Update : Make-break score for all variables
S{}S\leftarrow\{\} ;
  // set of updated variables
1 for clause 𝑐𝑙𝑠\mathit{cls} that contains vv do
2       for variable vv^{\prime} appearing in 𝑐𝑙𝑠\mathit{cls} do
3             add vv^{\prime} to SS;
4             recompute starting score and boundary of vv^{\prime} with respect to 𝑐𝑙𝑠\mathit{cls};
5            
6      
7for variable vv^{\prime} in S do
8       recompute best critical move and score in terms of boundary information;
9      
Algorithm 2 Incremental computation of make-break scores
Example 3.2.

Continuing from Example 3.1, suppose the move y2y\mapsto-2 is made, making the clause x+y<1x+y<1 satisfied. Then the score information for variable zz does not need to be updated, as yy and zz do not share a clause. The score information for variable xx need to be updated for the first two clauses. For clause x2+y21x^{2}+y^{2}\leq 1 there is no longer any boundaries (no assignment of xx can make the clause true), and for clause x+y<1x+y<1 the new starting score and boundary set are 0 and {(3,,,2)}\{(3,\bot,\bot,2)\}, respectively. So the overall starting score and boundary set are 2-2 and {(1,,,3),(3,,,2)}\{(-1,\top,\top,3),(3,\bot,\bot,2)\}.

Remark 3.3.

Data structures such as arrays, linked lists, or binary trees can be used to maintain set of boundaries. If the total number of boundaries for each variable is small (as is the case for most of the problem instances in SMT-LIB), arrays or linked lists are sufficient. Otherwise the use of binary trees result in better asymptotic performance for the required operations.

Remark 3.4.

A further optimization can be made: it is not necessary to immediately recompute the boundary information for a variable vv^{\prime} that does not appear in any unsatisfied clause, as such variables will never be chosen either on line 7 or line 14 of Algorithm 1. Instead, flags can be used to mark that boundary information for certain clauses need to be updated for vv^{\prime}. When at least one of the clauses containing vv^{\prime} becomes unsatisfied, information for those flagged clauses (as well as other clauses that need to be updated for that step) are updated.

4 Relaxation of equalities

Equality constraints with degree greater than one pose special difficulty for local search, since it may force assignments of variables to irrational (e.g. algebraic) numbers. For example, for the constraint x2+y2+z2=1x^{2}+y^{2}+z^{2}=1, with most rational assignments to xx and yy, the assignment to zz would be forced to irrational in order for the constraint to be satisfied. While it is possible to represent and compute with algebraic numbers during local search, the time-cost of such computation is significantly increased. Even without considering algebraic numbers, numbers with increasingly large denominators are also problematic for slowing down the search process.

Both [abs-2303-06676] and [LiXZ23] avoid algebraic numbers by either limiting to the multilinear case, or considering only equality constraints with at least one linear variable (and solving only for those linear variables). The work [abs-2303-06676] further incorporated comparison of size of denominators (as well as absolute value) of potential assignments into the scoring heuristic, in order to keep the complexity of assigned values as low as possible.

We propose a novel approach to address the problem of assignments to irrational values and values with large denominators, that allow the algorithm to be applied efficiently to the full set of nonlinear arithmetic problem instances. The approach still relies on comparing complexity of assigned values, hence we first define it below.

Definition 4.1 (Complexity of values).

We define a preorder c\prec_{c} on algebraic numbers as follows. xcyx\prec_{c}y if xx is rational and yy is irrational, or if both xx and yy are rational numbers, and the denominator of xx is less than that of yy. We write xcyx\sim_{c}y if neither xcyx\prec_{c}y nor ycxy\prec_{c}x.

The relaxation mechanism can be described simply as follows: whenever some equality (or inequality) constraints force an assignment of some variable to a comparatively complex value, those constraints are relaxed before continuing the local search process, so that such assignments never actually occur. The implementation is parameterized by two thresholds. The parameter ϵv\epsilon_{v} (for variable threshold) specifies the complexity of assigned values (according to Definition 4.1) beyond which relaxation of constraints should be applied. The parameter ϵp\epsilon_{p} (for polynomial threshold) specifies the amount of relaxation of polynomial constraints. Both ϵv\epsilon_{v} and ϵp\epsilon_{p} are chosen to be 10410^{-4} in the implementation.

It should be noted that the constraints p0p\geq 0 and p0p\leq 0 together can also force the assignment of variables to irrational values. These constraints may appear as part of clauses with more than one literal, and hence are not equivalent to p=0p=0. This means in general we consider relaxation of non-strict inequalities, although we will still use the slightly imprecise (but more intuitive) description of relaxing equalities throughout the paper.

The detailed method for determining which constraints to relax is as follows. When computing the best make-break score of a variable vv, if that score comes from a one-point interval, the set of clause identifiers in the boundaries contributing to that interval are recorded. If the variable vv is chosen, and the new value of vv is more complex than both ϵv\epsilon_{v} and any other previously assigned value (according to Definition 4.1), all equalities and non-strict inequalities in the recorded clauses that contribute to the boundary are relaxed. The result of relaxation is as follows.

  • If the constraint is of the form p=0p=0, it is relaxed into the pair of inequalities p<ϵpp<\epsilon_{p} and p>ϵpp>-\epsilon_{p}.

  • If the constraint is of the form p0p\geq 0, it is relaxed into p>ϵpp>-\epsilon_{p}. Likewise, if the constraint is of the form p0p\leq 0, it is relaxed into p<ϵpp<\epsilon_{p}.

Note that strict inequality constraints cannot force a variable to a particular value. After relaxation, the local search process proceeds as before, but with all evaluation of literals and computation of make-break scores according to the relaxed interpretation of literals.

After local search finds a “solution” under the relaxation of some constraints, it is only an approximate solution. In fact, there is no guarantee that there is an exact solution nearby. Instead, we use local search itself to try to move the approximate solution to an exact solution. First, restore the relaxed constraints to their original forms, and then proceed with local search, until either an exact solution is found, or no improvement is made for a certain number of steps. In the latter case, the search continues with a minor restart (see Section 5.2) and with relaxation of constraints allowed as before.

The above description is summarized as a modification of the overall algorithm, shown in Algorithm 3. The main change is to add a boolean flag called 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘\mathit{use\_slack}, that specifies whether relaxation of constraints is active. If all clauses are satisfied and 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\top, then we may only have an approximate solution, so we restore the relaxed constraints and continue local search (line 4-5). If all clauses are satisfied and 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\bot, then we obtained an exact solution (line 7). If no improvement is made for T1T_{1} steps in the 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\bot mode, we assume that no exact solution is found nearby, so we assign 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\top and continue after minor restart (line 11-12).

Input : A set of clauses FF
Output : An assignment of variables that satisfy FF, or failure
1 Initialize assignment to variables; 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘\mathit{use\_slack}\leftarrow\top;
2 while \top do
3       if all clauses satisfied and 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\top then
4             Restore relaxed constraints to their original form;
5             𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘\mathit{use\_slack}\leftarrow\bot;
6            
7      if all clauses satisfied and 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\bot then
8             return success with assignment;
9            
10      if time or step limit reached then
11             return failure;
12            
13      if 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\bot and no improvement for T1T_{1} steps then
14             𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘\mathit{use\_slack}\leftarrow\top;
15             Perform minor restart;
16            
17      if 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\top then
18             Proceed as in line 7-19 of Algorithm 1, except constraints may be relaxed;
19            
20      else
21             Proceed as in line 7-19 of Algorithm 1 without modification;
22            
23      
Algorithm 3 Relaxation of equalities

5 Implementation

In this section, we describe the implementation in more detail. First, we explain our choice of heuristic move selection when encountering a literal without critical moves. Then, we describe some further details on preprocessing, restart mechanism, and other efficiency improvements.

5.1 Heuristic moves selection and look-ahead

One major difficulty for local search in nonlinear arithmetic is that it is not always possible to find single-variable moves to satisfy a particular constraint. For example, given constraint x2+y2<1x^{2}+y^{2}<1, and the current assignment x2,y3x\mapsto 2,y\mapsto 3, it is not possible to satisfy the constraint by moving only one of xx and yy. During local search, this is reflected by the situation that no critical move is available for a clause or literal.

Solving this problem in general would likely require complex algorithms such as CAD or polynomial optimization. Indeed, one category in the SMT-LIB benchmarks, Sturm-MBO, coming from analysis of biological networks [AkutsuHT08], consists exclusively of problems that require a very complex polynomial to evaluate to zero, subject to positivity constraints of the variables. When the problem has many variables (is high-dimensional), any approach based on heuristically searching for assignments would have difficulty finding the exact combination of assigned values required to satisfy the constraint.

One approach is given in [LiXZ23], which involves searching in directions other than those parallel to the coordinate axes to look for solutions. The use of gradient information, as well as scoring based on values of polynomials, increase the chance of finding a solution.

In this paper, we propose another approach that still involves moving only one variable at a time. We say a literal is stuck if it is currently unsatisfied and has no critical moves to make it satisfied. Given a literal ll that is stuck, we first choose a variable xx in ll whose coefficient is nonzero (according to the current assignment of the other variables), then heuristically pick a set of candidate values to move the assignment of xx to. For each candidate value, we compute whether ll is still stuck after making that move. We then prefer those moves that result in ll no longer being stuck.

Given the current assignment x0x_{0} and the feasible set II of variable xx (see Section 5.2), the heuristic move selection include the following:

  1. 1.

    rational numbers and integers close to the boundary inside each interval of II. The rational numbers are chosen to be within 10410^{-4} of the boundary.

  2. 2.

    the next integer smaller or larger than x0x_{0}.

  3. 3.

    three numbers chosen uniformly in the interval [x02,x0)[\frac{x_{0}}{2},x_{0}), and three numbers chosen uniformly in the interval (x0,2x0](x_{0},2x_{0}].

The first class reflects what we know about the constraints on xx. The second class attempts basic random walk, and prefers (simple) integer values. The third class is the most general, allowing search over large/small values as well as fractions.

The above ideas are summarized in Algorithm 4. The heuristic choice of candidate values are collected into set SS (line 2). Then each value in SS is tested in turn. If ll has critical move after assigning to any value, that value is returned (line 5). Otherwise a randomly chosen value from SS is returned (line 7).

Input : Literal ll without critical moves
Output : Candidate variable xx and new value x1x_{1}
1 xx\leftarrow variable in polynomial of ll with nonzero coefficient;
2 SS\leftarrow heuristic move selection for variable xx;
3 for value x1x_{1} in SS do
4       if ll has critical move after assigning xx to x1x_{1} then
5             return xx, x1x_{1}
6      
7x1x_{1}\leftarrow randomly chosen value in SS;
return xx, x1x_{1}
Algorithm 4 Heuristic choice of candidate values and look-ahead for critical moves

5.2 Implementation details

The algorithm is implemented on top of the Z3 prover, and makes use of its library for polynomials and algebraic numbers, as well as data structures for clauses and literals, but otherwise separate from its implementation of the MCSAT algorithm.

Preprocessing. The following preprocessing steps are used. Eliminate clauses with a single boolean variable and propagate assignments. Combine constraints p0p\geq 0 and p0p\leq 0 into equality p=0p=0. Eliminate variable xx in an equation of the form cx+q=0c\cdot x+q=0, where cc is a constant and qq is a polynomial with degree at most 1 and containing at most 2 variables. The conditions on qq are designed so that preprocessing does not significantly increase the complexity of the remaining clauses.

Restart mechanism. We use a two-level restart mechanism with two parameters T1T_{1} and T2T_{2} (both chosen to be 100 in our implementation). Perform a minor restart after T1T_{1} moves without improvements, which randomly changes one of the variables in one of the unsatisfied clauses (this coincides with detection of the end of 𝑢𝑠𝑒_𝑠𝑙𝑎𝑐𝑘=\mathit{use\_slack}=\bot mode). After T2T_{2} such minor restarts, a major restart is performed that resets the value of all variables.

Shortcut for linear equations. Root-isolation is done by calling the existing implementation in Z3, except when the variable to be solved is linear in the polynomial, in which case a direct (and more efficient) solution method is used.

Infeasible sets of variables. For each clause involving a single variable, derive infeasible set for that variable implied by the clause. Experience shows excluding assignments from the infeasible set during local search is beneficial for some problem instances but not others. Hence, we exclude such assignments on alternate turns of minor restarts.

Parameter settings. Values of tunable parameters used in the implementation are summarized in Table 1.

Symbol Explanation  Value
𝑠𝑝\mathit{sp} Probability 𝑠𝑝\mathit{sp} for PAWS scheme 0.006
T1T_{1} Number of non-improving steps before minor restart 100
T2T_{2} Number of minor restarts before major restart 100
ϵv\epsilon_{v} Threshold for relaxing equality 10410^{-4}
ϵp\epsilon_{p} Amount of relaxation 10410^{-4}
Table 1: Tunable parameters of the algorithm

6 Evaluation

In this section, we compare the implementation with those of complete procedures in existing SMT solvers Z3 [MouraB08], CVC5 [BarbosaBBKLMMMN22] and Yices [Dutertre14], as well as previous work on local search for (fragments of) nonlinear arithmetic. We also perform ablation study on the two improvements described in Section 3 and 4.

The benchmark used in the evaluation comes from SMT-LIB’s QF_NRA theory. The benchmark consists mostly of industrial problems from various applications of constraint solving in nonlinear real arithmetic. Among the benchmarks, we took those problem instances whose status is either satisfiable or unknown. This results in a total of 6604 instances. The experiments are run on a cluster of machines with Intel Xeon Platinum 8153 processor at 2.00GHz. Each experiment is run with a time limit of 20 minutes (as in the SMT competition) and memory limit of 30GB.

6.1 Overall result

Results of our implementation are compared against that of other SMT solvers in Table 2. One major advantage of our algorithm is in the Sturm-MBO category, which involves a single complicated polynomial that tripped up other solvers. However, we also showed good result across other categories, and solved most satisfiable instances overall (the other SMT solvers also decided some of the instances to be unsatisfiable, which is not shown in this table). Scatter plots comparing solution times against Z3 and CVC5 are shown in Figure 1. It shows there is significant amount of complementarity between our algorithm and both Z3 and CVC5. In fact, there are 293 (satisfiable) instances solved by local search but not Z3, and 362 instances solved by local search but not CVC5.

Category #inst Z3 CVC5 Yices Ours
20161105-Sturm-MBO 120 0 0 0 84
20161105-Sturm-MGC 2 2 0 0 0
20170501-Heizmann 69 3 1 0 6
20180501-Economics-Mulligan 93 93 89 91 87
2019-ezsmt 63 54 51 52 18
20200911-Pine 245 235 201 235 224
20211101-Geogebra 112 109 91 99 100
20220314-Uncu 74 73 66 74 73
LassoRanker 684 155 304 122 284
UltimateAtomizer 48 41 34 39 26
hycomp 525 311 216 227 272
kissing 42 33 17 10 33
meti-tarski 4391 4391 4345 4369 4356
zankl 136 70 61 58 99
Total 6604 5570 5476 5376 5662
Table 2: Comparison with other SMT solvers
Refer to captionRefer to caption
Figure 1: Scatter plots of running time vs. Z3 and CVC5.

We further compare our results against existing work on local search for fragments of nonlinear real arithmetic. Of the 979 instances that are multilinear considered by [abs-2303-06676], our implementation can solve 825 instances, compared to 891 solved instances there. The slightly weaker result is likely due to the more efficient implementation that is possible when only rational numbers need to be considered, and the parameter tuning that is specific to multilinear problems. Of the 2736 instances from SMT-LIB considered by [LiXZ23], our implementation can solve 2596 instances, compared to 2246 solved instances there. In fact, we solve not only more instances than the local search algorithm given in [LiXZ23], but also all other SMT solvers used in the comparison.

6.2 Effect of incremental computation of variable scores

To show the effect of speedup resulting from incremental computation of variable scores in Section 3, we compare three versions of the implementation: with incremental computation (Incremental), without incremental computation (Naive), and without incremental computation, but limiting the number of unsatisfied clauses considered at each turn to 45 (Limit-45). The results are shown in Table 3.

We see that while the difference in total number of problem instance solved is not large, a noticeable effect is still present in the LassoRanker category, whose instances usually require a long time to solve. A closer look at the running time shows that it usually takes 2-10 times longer to solve a particular instance using either (Naive) or (Limit-45) compared to (Incremental), with the exact ration depending strongly on the specific instance. For a time limit of 20 minutes the resulting number of solved problems is not large, but we expect a larger difference with shorter time limits, and especially when local search is incorporated into other methods such as DPLL [CaiZ21, CaiZFB22].

Category #inst Incremental Naive Limit-45
20161105-Sturm-MBO 120 84 84 84
20161105-Sturm-MGC 2 0 0 0
20170501-Heizmann 69 6 5 5
20180501-Economics-Mulligan 93 87 88 88
2019-ezsmt 63 18 19 19
20200911-Pine 245 224 221 221
20211101-Geogebra 112 100 99 99
20220314-Uncu 74 73 73 73
LassoRanker 684 284 271 272
UltimateAtomizer 48 26 26 26
hycomp 525 272 265 267
kissing 42 33 33 33
meti-tarski 4391 4356 4348 4348
zankl 136 99 99 99
Total 6604 5662 5631 5634
Table 3: Comparison showing effect of incremental computation

6.3 Effect of relaxation of equalities

We demonstrate the effect of relaxation of constraints by comparing three possible implementations: with relaxation of constraints (Relaxation), without relaxation of constraints, but preferring variable assignments that are less complex than ϵv\epsilon_{v} (Threshold), and without relaxation of constraints, with choosing variable assignments strictly according to complexity order (FullOrder). The results are shown in Table 4.

Category #inst Relaxation Threshold FullOrder
20161105-Sturm-MBO 120 84 85 85
20161105-Sturm-MGC 2 0 0 0
20170501-Heizmann 69 6 9 8
20180501-Economics-Mulligan 93 87 89 90
2019-ezsmt 63 18 18 18
20200911-Pine 245 224 220 196
20211101-Geogebra 112 100 100 99
20220314-Uncu 74 73 73 73
LassoRanker 684 284 283 274
UltimateAtomizer 48 26 24 24
hycomp 525 272 204 205
kissing 42 33 31 20
meti-tarski 4391 4356 4348 4334
zankl 136 99 99 98
Total 6604 5662 5583 5524
Table 4: Comparison showing effect of temporary relaxation of constraints

The results indicate that while taking complexity of assigned values into consideration, either using a threshold or according to a strict order, does have an effect in keeping the search efficient for most categories of problem instances (in particular LassoRanker), it is not sufficient for the hycomp category, which involves a large number of nonlinear equalities. In that category using relaxation of constraints have a significant effect, while also performing well in other categories.

6.4 Other techniques

We also tried other techniques commonly used in works on local search, including tabu search, phases for boolean and arithmetic variables, and incorporating random walk. However, none of these methods resulted in improvements on the tested benchmark. However, it remains to investigate whether they will be useful on other types of problems, or in combination with other changes to the algorithm.

7 Conclusion

In this paper, we presented improvements to the local search algorithm for solving SMT problems in nonlinear real arithmetic. Building upon the basic structure of local search, we presented incremental computation of variable scores and temporary relaxation of constraints. We also described heuristic move selection with look-ahead for dealing with literals without critical moves, and implementation details to improve efficiency. The resulting implementation is competitive against complete algorithms based on DPLL(TT) and MCSAT on satisfiable problem instances, as implemented in other SMT solvers. It is the first local search algorithm designed for the entirety of nonlinear real arithmetic, covering a wider range of problems than existing work [abs-2303-06676, LiXZ23].

While the methods proposed in this paper made progress in addressing challenges of local search for nonlinear real arithmetic, there are remaining problems that represent interesting directions of future work.

  • Look-ahead for critical moves presents another way to improve upon random search in cases when no critical move is available. On the other hand, methods based on CAD or polynomial optimization would give a more complete way for determining assignments to satisfy a certain literal. A major challenge is how to incorporate such algorithms into local search in an efficient way.

  • In the current work, after an approximate solution is found that satisfies the relaxed version of equalities, we use local search itself to attempt to find an exact solution nearby. While there may be more straightforward ways to find exact solutions for limited cases, e.g. when each relaxed clause has a unique variable that can be adjusted, the situations we found in actual benchmarks are usually more complicated. Designing a more general algorithm for finding exact solutions near approximate solutions (or determining that none exist) is an interesting problem that we leave to future work.

  • Finally, local search can be incorporated into complete methods such as DPLL, improving its performance even on unsatisfiable instances, as shown by the works [CaiZ21, CaiZFB22]. It is interesting to investigate this possibility for SMT problems over nonlinear real arithmetic. The improvements in efficiency in our work would be very helpful for such combination, as in those cases local search is only given very short running times.