Proving Non-termination Using Max-SMT

Transcription

1 Proving Non-termination Using Max-SMT Daniel Larraz 1, Kaustubh Nimkar 2, Albert Oliveras 1, Enric Rodríguez-Carbonell 1, and Albert Rubio 1 1 Universitat Politècnica de Catalunya, Barcelona 2 University College London Abstract. We show how Max-SMT-based invariant generation can be exploited for proving non-termination of programs. The construction of the proof of nontermination is guided by the generation of quasi-invariants properties such that if they hold at a location during execution once, then they will continue to hold at that location from then onwards. The check that quasi-invariants can indeed be reached is then performed separately. Our technique considers strongly connected subgraphs of a program s control flow graph for analysis and thus produces more generic witnesses of non-termination than existing methods. Moreover, it can handle programs with unbounded non-determinism and is more likely to converge than previous approaches. 1 Introduction While the problem of proving program termination has now been extensively studied [1 22], relatively less work has been done on proving non-termination of programs. In this paper we present a new method for proving non-termination of sequential non-deterministic programs that leverages Max-SMT-based invariant generation [23, 24]. Our method analyses each Strongly Connected SubGraph (SCSG) of a program s control flow graph and, by means of Max-SMT solving, tries to find a formula at every node of the SCSG that satisfies certain properties. First, the formula has to be a quasiinvariant, i.e, it must satisfy the consecution condition of inductive invariants, but not necessarily the initiation condition. Hence, if it holds at the node during execution once, then it continues to hold from then onwards. Second, the formula has to be edge-closing, meaning that it forbids taking any of the outgoing edges from that node that exit the SCSG. Now, once we have computed an edge-closing quasi-invariant for every node of the SCSG, if a state is reached that satisfies one of them, then program execution will remain within the SCSG from then onwards. The existence of such a state is tested with an off-the-shelf reachability checker. If it succeeds, we have proved non-termination of the original program, and the edge-closing quasi-invariants of the SCSG and the trace given by the reachability checker form the witness of non-termination. Our approach differs from previous methods in two major ways. First, edge-closing quasi-invariants are more generic properties than non-termination witnesses produced by other provers, and thus are likely to carry more information and be more useful in bug finding. Second, our non-termination witnesses include SCSGs, which are larger structures than, e.g., lassos. Note that the number of SCSGs present in any CFG is

3 variables represent the values of the variables before the transition, and the primed ones represent the values after the transition. By R τ (i, j) we denote the conditional part of τ, which only involves the pre-variables. Fig. 1(c) shows all SCSGs present in the CFG. For every SCSG, the dashed edges are those that exit the SCSG and hence are not part of it. Note that SCSG-1 is a maximal strongly connected subgraph, and thus is a strongly connected component of the CFG. Notice also that τ 3 is an additional exit edge for SCSG-2, and similarly τ 2 is an exit edge for SCSG-3. The non-termination of this example comes from SCSG-3. Our approach considers every SCSG of the graph one by one. In every iteration of our method, we try to find a formula at every node of the SCSG under consideration. This formula is originally represented as a template with unknown coefficients. We then form a system of constraints involving the template coefficients in the Max-SMT framework. In a Max-SMT problem, some of the constraints are hard, meaning that any solution to the system of constraints must satisfy them, and others are soft, which may or may not be satisfied. Soft constraints carry a weight, and the goal of the Max-SMT solver is to find a solution for the hard constraints such that the sum of the weights for the soft constraints violated by the solution is minimized. In our method, essentially the hard constraints encode that the formula should obey the consecution condition, and every soft constraint encodes that the formula will disable an exit edge. A solution to this system of constraints assigns values to template coefficients, thus giving us the required formula at every node. Consider the analysis of SCSG-3 (refer to Fig. 1(d)). Note that there is a single node l 1 and a single transition τ 3 in SCSG-3. We denote by E = {τ 2, τ 4, τ 5 } the set of exit edges for SCSG-3. By Q l1 (i, j) we denote the quasi-invariant at node l 1. Initially Q l1 (i, j) true. In the first iteration, for node l 1 we assign a template M l1 (i, j) : a.i + b.j c. We then form the Max-SMT problem consisting of the following system of hard and soft constraints: (Consecution) i, j, i, j. M l1 (i, j) Q l1 (i, j) R τ3 (i, j, i, j ) M l1 (i, j ) (Edge-Closing) For all τ E: i, j. M l1 (i, j) Q l1 (i, j) R τ (i, j) The consecution constraint is hard, while the edge-closing constraints are soft (with weight, say, 1). The edge-closing constraint for τ E encodes that, from any state satisfying M l1 (i, j) Q l1 (i, j), the transition τ is disabled and cannot be executed. In the first iteration, a solution for M l1 gives us the formula j 1. This formula satisfies the edge-closing constraints for τ 2 and τ 5. We conjoin this formula to Q l1, updating it to Q l1 (i, j) j 1. We also update E = {τ 4 } by removing τ 2 and τ 5, as these edges are now disabled. In the second iteration, we again consider the same template M l1 (i, j) and try to solve the Max-SMT problem above with updated Q l1 (i, j) and E. This time we get a solution that gives us the formula i 1, which satisfies the edge-closing constraint for τ 4. We again update Q l1 (i, j) j 1 i 1 by conjoining the new formula. We update E = by removing the disabled edge τ 4. Now all exit edges have been disabled, and thus the quasi-invariant Q l1 (i, j) is edge-closing. In the final step of our method, we use a reachability checker to determine if any state satisfying Q l1 (i, j) at location l 1 is reachable. This test succeeds, and a path l 0 3

4 l 1 l 1 is obtained. Notice that the path goes through the loop once before we reach the required state. At this point, we have proved non-termination of the original program. 2 Preliminaries 2.1 SMT and Max-SMT Let P be a finite set of propositional variables. If p P, then p and p are literals. The negation of a literal l, written l, denotes p if l is p, and p if l is p. A clause is a disjunction of literals. A propositional formula is a conjunction of clauses. The problem of propositional satisfiability (abbreviated as SAT) consists in, given a formula, to determine whether or not it is satisfiable, i.e., if it has a model: an assignment of Boolean values to variables that satisfies the formula. An extension of SAT is the satisfiability modulo theories (SMT) problem [26]: to decide the satisfiability of a given quantifier-free first-order formula with respect to a background theory. In this setting, a model (which we may also refer to as a solution) is an assignment of values from the theory to variables that satisfies the formula. Here we will consider the theories of linear real/integer arithmetic (LRA/LIA), where literals are linear inequalities over real and integer variables respectively, and the more general theories of non-linear real/integer arithmetic (NRA/NIA), where literals are polynomial inequalities over real and integer variables, respectively. Another generalization of SAT is the Max-SAT problem [26]: it consists in, given a weighted formula where each clause has a weight (a positive number or infinity), to find the assignment such that the cost, i.e., the sum of the weights of the falsified clauses, is minimized. Clauses with infinite weight are called hard, while the rest are called soft. Equivalently, the problem can be seen as finding the model of the hard clauses such that the sum of the weights of the falsified soft clauses is minimized. Finally, the problem of Max-SMT [27] merges Max-SAT and SMT, and is defined from SMT analogously to how Max-SAT is derived from SAT. Namely, the Max-SMT problem consists in, given a weighted formula, to find an assignment that minimizes the sum of the weights of the falsified clauses in the background theory. 2.2 Transition Systems Our technique is applicable to sequential non-deterministic programs with integer variables and commands whose transition relations can be expressed in linear (integer) arithmetic. By v we represent the tuple of program variables. For the sake of presentation, we assume that the non-determinism of programs can come only from nondeterministic assignments of the form i := nondet(), where i v is a program variable. Note that, however, this assumption still allows one to encode other kinds of nondeterminism. For instance, any non-deterministic branching of the form if( ){} else{} can be cast into this framework by introducing a new program variable k v and rewriting into the form k := nondet(); if(k 0){} else{}. We model programs with transition systems. A transition system S = (v, u, L, Θ, T ) consists of a tuple of program variables v, a tuple of non-deterministic variables u, a set 4

5 of locations L, a map Θ from locations to formulas characterizing the initial values of the variables, and a set of transitions T. Each transition τ T is a triple (l, l, R), where l, l L are the pre and post locations respectively, and R is the transition relation: a formula over the non-deterministic variables u, the program variables v and their primed versions v, which represent the values of the variables after the transition. The transition relation of a non-deterministic assignment of the form i := nondet(), where i v, is represented by the formula i = u 1, where u 1 u is a fresh non-deterministic variable. Note that u 1 is not a program variable, i.e., u 1 v, and is added only to model the non-deterministic assignment. Thus, without loss of generality on the kind of non-deterministic programs we can model, we will assume that every non-deterministic variable appears in at most one transition relation. A transition that includes a nondeterministic variable in its transition relation is called non-deterministic (abbreviated as nondet). In what follows we will assume that transition relations are described as conjunctions of linear inequalities over program variables and non-deterministic variables. Given a transition relation R = R(v, u, v ), we will use R(v) to denote the conditional part of R, i.e., the conjunction of linear inequalities in R containing only variables in v. For a transition system modeling real programs, the following conditions are true: For τ = (l, l, R) T : v, u v. R(v) R(v, u, v ). (1) For l L : R(v) true. (2) (l,l,r) For τ 1 = (l, l 1, R 1 ), τ 2 = (l, l 2, R 2 ) T, τ 1 τ 2 : R 1 (v) R 2 (v) false. (3) Condition (1) guarantees that next values for the program variables always exist if the conditional part of the transition holds. Condition (2) expresses that, for any location, at least one of the outgoing transitions from that location can always be executed. Finally, condition (3) says that any two different transitions from the same location are mutually exclusive, i.e., conditional branching is always deterministic. Example 1. Let us consider the program shown in Figure 2. Note how the two nondeterministic assignments have been replaced in the CFG by assignments to fresh nondeterministic variables u 1 and u 2. Condition (2) is trivially satisfied for l 0 and l 2, since the conditional part of their outgoing transition relations is empty. Regarding l 1, clearly the formula x y x < y is a tautology. Condition (3) is also easy to check: the conditional parts of R τ2, R τ3 and R τ4 are pairwise unsatisfiable. Finally, condition (1) trivially holds since the primed parts of the transition relations consist of equalities whose left-hand side is always a different variable. A state is an assignment of a value to each of the variables in v and u. A configuration is a pair (l, σ) consisting of a location l L and a state σ. For any pair of configurations (l, σ) and (l, σ ), if there is a transition τ = (l, l, R) T such that (σ, σ ) = R, we write (l, σ) τ (l, σ ). A computation is a sequence of configurations (l 0, σ 0 ), (l 1, σ 1 ),... such that σ 0 = Θ(l 0 ), and for each pair of consecutive configurations there exists τ i T satisfying (l i, σ i ) τ i (l i+1, σ i+1 ). A configuration (l, σ) is 5

6 l 0 : int x, y; l 1 : while (x y) if (x 0) x := nondet(); y := y + 1; else y := nondet(); l 2 : τ 1 τ 2 l 0 l 1 l 2 τ 3 τ 4 R τ1 : x =x y =y R τ2 : x y x 0 x =u 1 y =y + 1 R τ3 : x y x < 0 x =x y =u 2 R τ4 : x < y x =x y =y Fig. 2. Program involving non-deterministic assignments, together with its CFG reachable if there exists a computation ending at (l, σ). A transition system is terminating if all its computations are finite, and non-terminating otherwise. The goal of this paper is, given a transition system, to prove that it is non-terminating. 3 Quasi-invariants and Non-termination Here we will introduce the core concept of this work, that of a quasi-invariant: a property such that, if it is satisfied at a location during execution once, then it continues to hold at that location from then onwards. The importance of this notion resides in the fact that it is a key ingredient in our witnesses of non-termination: if each location of an SCSG can be mapped to a quasi-invariant that is edge-closing, i.e., that forbids executing any of the outgoing transitions that leave the SCSG, and the SCSG can be reached at a configuration satisfying the corresponding quasi-invariant, then the program is nonterminating (if nondet transitions are present, additional properties are required, as will be seen below). A constructive proof of this claim is given at the end of this section. First of all, let us define basic notation. For a strongly connected subgraph (SCSG) C of a program s CFG, we denote by L C the set of locations of C, and by T C the set of edges of C. We define E C def = {τ = (l, l, R) l L C, τ T C } to be the set of exit edges of C. Consider a map Q that assigns a formula Q l (v) to each of the locations l L C. Consider also a map U that assigns a formula U τ (v, u) to each transition τ T C, which represents the restriction that the non-deterministic variables must obey. 3 The map Q is a quasi-invariant map on C with restriction U if: (Consecution) For τ = (l, l, R) T C : v, u, v. Q l (v) R(v, u, v ) U τ (v, u) Q l (v ) (4) Condition (4) says that, whenever a state at l L C satisfying Q l is reached and a transition from l to l can be executed, then the resulting state satisfies Q l. This condition corresponds to the consecution condition for inductive invariants. Since inductive 3 For the sake of presentation, we assume that U τ is defined for all transitions, whether they are deterministic or not. In the former case, by convention U τ is true. 6

7 invariants are additionally required to satisfy initiation conditions [25], we refer to properties satisfying condition (4) as quasi-invariants, hence the name for Q. Example 2. In order to explain the roles of Q and U, consider the program in Figure 2. It is easy to see that if x y were a quasi-invariant at l 1, the program would be nonterminating (provided l 1 is reachable with a state such that x y). However, due to the non-deterministic assignments, the property is not a quasi-invariant. On the other hand, if we add the restrictions U τ2 := u 1 x + 1 and U τ3 := u 2 y, which constrain the nondeterministic choices in the assignments, the quasi-invariant holds and non-termination is proved. Additionally, our method also needs that Q and U are reachable and unblocking: (Reachability) l L C. σ s.t. (l, σ) is reachable and σ = Q l (v) (5) (Unblocking) For τ = (l, l, R) T C : v u. Q l (v) R(v) U τ (v, u) (6) Condition (5) says that there exists a computation reaching a configuration (l, σ) such that σ satisfies the quasi-invariant at location l. As for condition (6), consider a state σ at some l L C satisfying Q l (v). This condition says that, for any transition τ = (l, l, R) T C from l, if σ satisfies the conditional part R(v), then we can always make a choice for the non-deterministic assignment that obeys the restriction U τ (v, u). The last property we require from quasi-invariants is that they are edge-closing. Formally, the quasi-invariant map Q on C is edge-closing if it satisfies all of the following constraints: (Edge-Closing) For τ = (l, l, R) E C : v. Q l (v) R(v) (7) Condition (7) says that, from any state at l L C that satisfies Q l (v), all the exit transitions are disabled and cannot be executed. The following is the main result of this section: Theorem 1. Q, U that satisfy (4), (5), (6) and (7) for a certain SCSG C of a CFG P imply non-termination of P. In order to prove Theorem 1, we need the following lemma: Lemma 1. Let us assume that Q, U satisfy (4), (6) and (7) for a certain SCSG C. Let (l, σ) be a configuration such that l L C and σ = Q l (v). Then there exists a configuration (l, σ ) such that l L C, σ = Q l (v) and (l, σ) τ (l, σ ) for a certain τ T C. Proof. By condition (2) (which is implicitly assumed to hold), there is a transition τ of the form (l, l, R) for a certain l L such that σ = R(v). Now, by virtue of condition (7), since σ = Q l (v) we have that τ T C. Thus, l L C. Moreover, thanks to condition (6) and σ = Q l (v) and σ = R(v), we deduce that there exist values ν for the nondeterministic variables u such that (σ, ν) = U τ (v, u). Further, by condition (1) (which is again implicitly assumed), we have that there exists a state σ such that (σ, ν, σ ) = 7

9 construction is successful and eventually edge-closedness can be achieved, and moreover the quasi-invariants of C can be reached, then the synthesized Q, U satisfy the properties of Theorem 1, and therefore the program is guaranteed not to terminate. In a nutshell, the enumeration of SCSGs considers a strongly connected component (SCC) of the CFG at a time, and then generates all the SCSGs included in that SCC. More precisely, first of all the SCCs are considered according to a topological ordering in the CFG. Then, once an SCC S is fixed, the SCSGs included in S are heuristically enumerated starting from S itself (since taking a strictly smaller subgraph would imply discarding some transitions a priori arbitrarily), then simple cycles in S (as they are easier to deal with), and then the rest of SCSGs included in S. Then, once the SCSG C is fixed, our non-termination proving procedure Prove-NT (Fig. 3) is called. The procedure takes as input an SCSG C of the program s CFG, and the CFG itself. For every location l L C, we initially assign a quasi-invariant Q l (v) true. Similarly, for every transition τ T C, we initially assign a restriction U τ (v, u) true. The set E C keeps track of the exit edges of C that have not been discarded yet, and hence at the beginning we have E C = E C. Then we iterate in a loop in order to strengthen the quasi-invariants and restrictions till E C =, that is, all the exit edges of C are disabled. In every iteration we assign a template M l (v) m l,0 + v m l, 0 to each l L C. We also assign a template N τ (v, u) n τ,0 + v n τ, + u u n τ,u u 0 to each τ T C. 4 Then we form the Max-SMT problem consisting of the following system of constraints: 5 For τ = (l, l, R) T C : v, u, v. Q l (v) M l (v) R(v, u, v ) U τ (v, u) N τ (v, u) M l (v ) (8) For l L C : v. Q l (v) M l (v) R(v) (9) τ=(l,l,r) T C For τ = (l, l, R) T C : v u. Q l (v) M l (v) R(v) U τ (v, u) N τ (v, u) (10) For τ = (l, l, R) E C : v. Q l (v) M l (v) R(v) (11) The constraints (8), (9) and (10) are hard, while the constraints (11) are soft. The Max-SMT solver finds a solution M l (v) for every M l (v) for l L C and a solution N τ (v, u) for every N l (v, u) for τ T C. The solution satisfies the hard constraints and as many soft constraints as possible. In other words, it is the best solution for hard constraints that disables the maximum number of transitions. We then update Q l (v) for every l L C by strengthening it with M l (v), and update U τ (v, u) for every τ T C by strengthening it with N τ (v, u). We then remove all the disabled transitions from E C and continue the iterations of the loop with updated Q, U and E C. When all exit transitions are disabled, we exit the loop with the unblocking edgeclosing quasi-invariant map Q and the restriction map U. 4 Actually templates N τ (v, u) are only introduced for nondet transitions. To simplify the presentation, we assume that for other transitions, N τ (v, u) is true. 5 For the sake of clarity, leftmost existential quantifiers over the unknowns of the templates are implicit. 9

11 Now, if the while loop terminates, it must be the case that E C =. Thus, on exit of the loop, condition (7) is fulfilled. Finally, if Non-Terminating is returned, then there is a location l L C and a state satisfying σ = Q l (v) such that configuration (l, σ) is reachable. That is, condition (5) is satisfied. Hence, all conditions of Theorem 1 are fulfilled. Therefore, P does not terminate. Moreover, the proof of Theorem 1 gives a constructive way of building an infinite computation by means of Q, U and π. Note that constraint (9): For l L C : v. Q l (v) M l (v) τ=(l,l,r) T C R(v) is not actually used in the proof of Theorem 2, and thus is not needed for the correctness of the approach. Its purpose is rather to help Prove-NT to avoid getting into deadends unnecessarily. Namely, without (9) it could be the case that for some location l L C, we computed a quasi-invariant that forbids all transitions τ T C from l. Since Prove-NT only strengthens quasi-invariants and does not backtrack, if this situation were reached the procedure would probably not succeed in proving non-termination. Now let us describe how constraints are effectively solved. First of all, constraints (8), (9), and (11) are universally quantified over integer variables. Following the same ideas of constraint-based linear invariant generation [25], these constraints are soundly transformed into an existentially quantified formula in NRA by abstracting program and non-deterministic variables and considering them as reals, and then applying Farkas Lemma [28]. As regards constraint (10), the alternation of quantifiers in v u. Q l (v) M l (v) R(v) U τ (v, u) N τ (v, u) is dealt with by introducing a template P u,τ (v) p u,τ,0 + v p u,τ, for each u u and skolemizing. This yields 6 the formula v. Q l (v) M l (v) R(v) U τ (v, P u,τ (v)) N τ (v, P u,τ (v)), which implies constraint (10), and to which the above transformation into NRA can be applied. Note that, since the Skolem function is not symbolic but an explicit linear function of the program variables, potentially one might lose solutions. Finally, once a weighted formula in NRA containing hard and soft clauses is obtained, (some of the) existentially quantified variables are forced to take integer values, and the resulting problem is handled by a Max-SMT(NIA) solver [27, 29]. In particular, the unknowns of the templates P u,τ (v) introduced for skolemizing non-deterministic variables are imposed to be integers. Since program variables have integer type, this guarantees that only integer values are assigned in the non-deterministic assignments of the infinite computation that proves non-termination. There are some other issues about our implementation of the procedure that are worth mentioning. Regarding how the weights of the soft clauses are determined, we 6 Again, existential quantifiers over template unknowns are implicit. 11

12 follow a heuristic aimed at discarding difficult transitions in E C as soon as possible. Namely, the edge-closing constraint (11) of transition τ = (l, l, R) E C is given a weight which is inversely proportional to the number of literals in R(v). Thus, transitions with few literals in their conditional part are associated with large weights, and therefore the Max-SMT solver prefers to discard them over others. The rationale is that for these transitions there may be more states that satisfy the conditional part, and hence they may be more difficult to rule out. Altogether, it is convenient to get rid of them before quasi-invariants become too constrained. Finally, as regards condition (3), our implementation can actually handle transition systems for which this condition does not hold. This may be interesting in situations where, e.g., non-determinism is present in conditional statements, and one does not want to introduce additional variables and locations as was done in Section 2.2 for presentation purposes. The only implication of overriding condition (3) is that, in this case, the properties that must be discarded in soft clauses of condition (11) are not the transitions leaving the SCSG under consideration, but rather the negation of the transitions staying within the SCSG. 5 Experiments In this section we evaluate the performance of a prototype implementation of the techniques proposed here in our termination analyzer CppInv, available at edu/ albert/cppinv-cav.tar.gz together with all of the benchmarks. This tool admits code written in (a subset of) C++ as well as in the language of T2 [20]. The system analyses programs with integer variables, linear expressions and function calls, as well as array accesses to some extent. As a reachability checker we use CPA [30]. Altogether, we compare CppInv with the following tools: T2 [20] version CAV 13 (henceforth, T2-CAV), which implements an algorithm that tightly integrates invariant generation and termination analysis [19]. T2 [20] version TACAS 14 (henceforth, T2-TACAS), which reduces the problem of proving non-termination to the search of an under-approximation of the program guided by a safety prover [31]. Julia [32], which implements a technique described by Payet and Spoto [33] that reduces non-termination to constraint logic programming. AProVE [11] with the Java Bytecode front-end, which uses the SMT-based nontermination analysis proposed in [34]. A reimplementation of TNT [35] by the authors of [31] that uses Z3 [36] as an SMT back-end. Unfortunately, because of the unavailability of some of the tools (T2-TACAS, T2-CAV, TNT) or the fact that they do not admit a common input language (Julia, AProVE), it was not possible to run all these systems on the same benchmarks on the same computer. For this reason, for each of the tables below we consider a different family of benchmarks taken from the literature and provide the results of executing our tool (on a 3.40 GHz Intel Core i7 with 16 GB of RAM) together with the data of competing 12

13 systems reported in the respective publications. Note that the results of third-party systems in those publications may have some inaccuracies, due to, e.g., the conversion of benchmarks in different formats. However, in those cases the distances between the tools seem to be significant enough to draw conclusions on their relative performance. Table 1 shows comparative results on benchmarks taken from [31]. In that paper, the tools T2-TACAS, AProVE, Julia and TNT are considered. The time limit is set to 60 seconds both in that work as well as in the executions of CppInv. The benchmarks are classified according to three categories: (a) all the examples in the benchmark suite known to be non-terminating previously to [31]; (b) all the examples in the benchmark suite known to be terminating previously to [31]; and (c) the rest of instances. Rows of the table correspond to non-termination provers. Columns are associated to each of these three categories of problems. Each column is split into three subcolumns reporting the number on non-terminating answers, the number of timed outs, and the number of other answers (which includes terminating and unknown answers), respectively. Even with the consideration that experiments were conducted on different machines, the results in columns (a) and (c) of Table 1 show the power of the proposed approach on these examples. As for column (b), we found out that instance 430.t2 was wrongly classified as terminating. Our witness of non-termination has been manually verified. Table 1. Experiments with benchmarks from [31] (a) (b) (c) Nonterm TO Other Nonterm TO Other Nonterm TO Other CppInv T2-TACAS AProVE Julia TNT Table 2 (a), which follows a similar format to Table 1, compares CppInv, T2-CAV and AProVE on benchmarks from [19] (all with a time limit of 300 seconds). Note that, in the results reported in [19], due to a wrong abstraction in the presence of division, T2 was giving two wrong non-termination answers (namely, for the instances rlft3.t2 and rlft3.c.i.rlft3.pl.t2.fixed.t2, for which the termination proofs produced by CppInv[24] have been checked by hand). For this reason we have discarded those two programs from the benchmark suite. In this case, the performance of our tool is slightly worse than that of T2-CAV. However, it has to be taken into account that T2- CAV was exploiting the cooperation between the termination and the non-termination provers, while we still do not apply this kind of optimizations. In Table 2 (b), CppInv is compared with the results of Julia and AProVE from [34] on Java programs coming from [37]. CppInv was run on C++ versions of these benchmarks, which admitted a direct translation from Java. The time limit was set to 60 seconds. Columns represent respectively the number of terminating instances (YES), non-terminating instances (NO), instances for which the construction of the proof failed before the time limit (MAYBE), and timeouts (TO). For these instances AProVE gets slightly better results than CppInv. However, it should be taken into account that four 13

14 programs of this set of benchmarks include non-linear expressions, which we cannot handle. Moreover, when compared on third-party benchmarks (see Tables 1 and 2 (a)), our results are better. Finally, Table 2 (c) shows the results of running our tool on programs from the online programming learning environment Jutge.org [38] (see which is currently being used in several programming courses in the Universitat Politècnica de Catalunya. As a paradigmatic example in which it is easy to write wrong nonterminating code, we have considered the exercise Binary Search. The programs in this benchmark suite can be considered challenging since, having been written by students, their structure is often more complicated than necessary. In this case the time limit was 60 seconds. As can be seen from the results, for a ratio of 89% of the cases, CppInv is able to provably determine in less than one minute if the program is terminating or not. Table 2. Experiments with benchmarks from [19] (a), from [37] (b) and from Jutge.org (c) (a) (b) Nonterm TO Other CppInv T2-CAV AProVE (c) YES NO MAYBE TO CppInv AProVE Julia YES NO MAYBE TO Binary search All in all, the experimental results show that our technique, although it is general and is not tuned to particular problems, is competitive with the state of the art and performs reasonably and uniformly well on a wide variety of benchmarks. 6 Related work Several systems have been developed in recent years for proving non-termination. One of these is, e.g., the tool TNT [35], which proceeds in two phases. The first phase exhaustively generates candidate lassos. The second one checks each lasso for possible non-termination by seeking a recurrent set of states, i.e., a set of states that is visited infinitely often along the infinite path that results from unrolling the lasso. This is carried out by means of constraint solving, as in our approach. However, while there is an infinite number of lassos in a program, the SCSGs we consider can be finitely enumerated. Moreover, our approach can handle unbounded non-determinism, whereas TNT is only restricted to deterministic programs. Other methods for proving non-termination that use an off-the-shelf reachability checker like our technique have also been proposed [39, 31]. In [39], the reachability checker is used on instrumented code for inferring weakest preconditions, which give the most general characterization of the inputs under which the original program is 14

15 non-terminating. While in [39] non-determinism can be dealt with in a very restricted manner, the method in [31] can deal with unbounded non-determinism as we do. In the case of [31], the reachability checker is iteratively called to eliminate every terminating path through a loop by restricting the state space, and thus may diverge on many loops. Our method does not suffer from this kind of drawbacks. Some other approaches exploit theorem-proving techniques. For instance, the tool Invel [37] analyzes non-termination of Java programs using a combination of theorem proving and invariant generation. Invel is only applicable to deterministic programs. Another tool for proving non-termination of Java programs is AProVE [11], which uses SMT solving as an underlying reasoning engine. The main drawback of their method is that it is required that either recurrent sets are singletons (after program slicing) or loop conditions themselves are invariants. Our technique does not have such restrictions. Finally, the tool TRex [40] integrates existing non-termination proving approaches within a Terminator-like [41] iterative procedure. Unlike TRex, which is aimed at sequential code, Atig et al. [42] focus on concurrent programs: they describe a nontermination proving technique for multi-threaded programs, via a reduction to nontermination reasoning for sequential programs. Our work should complement both of these approaches, since we provide significant advantages over the underlying nontermination proving tools that were previously used. 7 Conclusions and Future Work In this paper we have presented a novel Max-SMT-based technique for proving that programs do not terminate. The key notion of the approach is that of a quasi-invariant, which is a property such that if it holds at a location during execution once, then it continues to hold at that location from then onwards. The method considers an SCSG of the control flow graph at a time, and thanks to Max-SMT solving generates a quasiinvariant for each location. Weights of soft constraints guide the solver towards quasiinvariants that are also edge-closing, i.e., that forbid any transition exiting the SCSG. If an SCSG with edge-closing quasi-invariants is reachable, then the program is nonterminating. This last check is performed with an off-the-shelf reachability checker. We have reported experiments with encouraging results that show that a prototypical implementation of the proposed approach has comparable and often better efficacy than state-of-the-art non-termination provers. As regards future research, a pending improvement is to couple the reachability checker with the quasi-invariant generator, so that the invariants synthesized by the former in unsuccessful attempts are reused by the latter when producing quasi-invariants. Another line for future work is to combine our termination [24] and non-termination techniques. Following a similar approach as that suggested in [19], if the termination analyzer fails, it can communicate to the non-termination tool the transitions that were proved not to belong to any infinite computation. Conversely, when a failed nontermination analysis ends with an unsuccessful reachability check, one can pass the computed invariants to the termination system, as done in [40]. Acknowledgments. We thank the Jutge.org team for providing us with benchmarks. 15

µz An Efficient Engine for Fixed points with Constraints Kryštof Hoder, Nikolaj Bjørner, and Leonardo de Moura Manchester University and Microsoft Research Abstract. The µz tool is a scalable, efficient

CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes

The Classes P and NP We now shift gears slightly and restrict our attention to the examination of two families of problems which are very important to computer scientists. These families constitute the

Mathematics for Computer Science/Software Engineering Notes for the course MSM1F3 Dr. R. A. Wilson October 1996 Chapter 1 Logic Lecture no. 1. We introduce the concept of a proposition, which is a statement

Static Program Transformations for Efficient Software Model Checking Shobha Vasudevan Jacob Abraham The University of Texas at Austin Dependable Systems Large and complex systems Software faults are major

WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT? introduction Many students seem to have trouble with the notion of a mathematical proof. People that come to a course like Math 216, who certainly

Non-Monotonic Program Analysis Daniel Schwartz-Narbonne Philipp Rümmer Martin Schäf Ashish Tiwari New York University Uppsala University SRI International SRI International Thomas Wies New York University

PROCEEDINGS OF THE YEREVAN STATE UNIVERSITY Physical and Mathematical Sciences 2012 1 p. 43 48 ON FUNCTIONAL SYMBOL-FREE LOGIC PROGRAMS I nf or m at i cs L. A. HAYKAZYAN * Chair of Programming and Information

Chapter II. Controlling Cars on a Bridge 1 Introduction The intent of this chapter is to introduce a complete example of a small system development. During this development, you will be made aware of the

Introduction to Logic in Computer Science: Autumn 2006 Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam Ulle Endriss 1 Plan for Today Now that we have a basic understanding

n colleges in a set C, m applicants in a set A, where m is much larger than n. each college c i C has a capacity q i - the maximum number of students it will admit each college c i has a strict order i

Chapter 3 Linear Codes In order to define codes that we can encode and decode efficiently, we add more structure to the codespace. We shall be mainly interested in linear codes. A linear code of length

Some N P problems Computer scientists have studied many N P problems, that is, problems that can be solved nondeterministically in polynomial time. Traditionally complexity question are studied as languages:

The General Approach Notes on Factoring MA 26 Kurt Bryan Suppose I hand you n, a 2 digit integer and tell you that n is composite, with smallest prime factor around 5 digits. Finding a nontrivial factor

Math 101 Rumbos Spring 2010 1 Handout #1: Mathematical Reasoning 1 Propositional Logic A proposition is a mathematical statement that it is either true or false; that is, a statement whose certainty or

A Propositional Dynamic Logic for CCS Programs Mario R. F. Benevides and L. Menasché Schechter {mario,luis}@cos.ufrj.br Abstract This work presents a Propositional Dynamic Logic in which the programs are

A simple algorithm with no simple verication Laszlo Csirmaz Central European University Abstract The correctness of a simple sorting algorithm is resented, which algorithm is \evidently wrong" at the rst

Towards a Framework for Generating Tests to Satisfy Complex Code Coverage in Java Pathfinder Matt Department of Computer Science and Engineering University of Minnesota staats@cs.umn.edu Abstract We present

Policy nalysis for dministrative Role Based ccess Control without Separate dministration Ping Yang Department of Computer Science, State University of New York at Binghamton, US Mikhail I. Gofman Department

Chapter 3 Sequences In this chapter, we discuss sequences. We say what it means for a sequence to converge, and define the limit of a convergent sequence. We begin with some preliminary results about the

How Not to Win a Million Dollars: A Counterexample to a Conjecture of L. Breiman Thomas P. Hayes arxiv:1112.0829v1 [math.pr] 5 Dec 2011 Abstract Consider a gambling game in which we are allowed to repeatedly

MA651 Topology. Lecture 6. Separation Axioms. This text is based on the following books: Fundamental concepts of topology by Peter O Neil Elements of Mathematics: General Topology by Nicolas Bourbaki Counterexamples

3.1 Algorithm complexity The algorithms A, B are given. The former has complexity O(n 2 ), the latter O(2 n ), where n is the size of the instance. Let n A 0 be the size of the largest instance that can